xdiary 4/5 (X based calendar and diary)
Jason Baietto
jason at gcx1.ssd.csd.harris.com
Thu Dec 13 10:28:41 AEST 1990
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 4 (of 5)."
# Contents: main.c
# Wrapped by jason at hcx2 on Thu Dec 6 12:49:23 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'main.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'main.c'\"
else
echo shar: Extracting \"'main.c'\" \(54415 characters\)
sed "s/^X//" >'main.c' <<'END_OF_FILE'
X/*
X * Author: Jason Baietto, jason at ssd.csd.harris.com
X * xdiary Copyright 1990 Harris Corporation
X *
X * Permission to use, copy, modify, and distribute, this software and its
X * documentation for any purpose is hereby granted without fee, provided that
X * the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of the copyright holder be used in
X * advertising or publicity pertaining to distribution of the software with
X * specific, written prior permission, and that no fee is charged for further
X * distribution of this software, or any modifications thereof. The copyright
X * holder makes no representations about the suitability of this software for
X * any purpose. It is provided "as is" without express or implied warranty.
X *
X * THE COPYRIGHT HOLDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND IN NO
X * EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY SPECIAL, INDIRECT OR
X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM ITS USE,
X * LOSS OF DATA, PROFITS, QPA OR GPA, WHETHER IN AN ACTION OF CONTRACT,
X * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
X * THE USE OR PERFORMANCE OF THIS SOFTWARE.
X */
X
X/*
X xdiary -- An X application which displays a calendar in one of two formats
X and/or an interactive daily dairy.
X
X Author: Jason Baietto (jason at ssd.csd.harris.com)
X Date: October 10, 1990
X*/
X
X/*==========================================================================*/
X/* Header Files: */
X/*==========================================================================*/
X#include <stdio.h>
X#include <ctype.h>
X#include <pwd.h>
X#include <X11/Xos.h>
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#include <X11/Shell.h>
X#include <X11/Xaw/Command.h>
X#include <X11/Xaw/Form.h>
X#include <X11/Xaw/Paned.h>
X#include <X11/Xaw/Box.h>
X#include <X11/Xaw/Dialog.h>
X#include <X11/Xaw/MenuButton.h>
X#include <X11/Xaw/SimpleMenu.h>
X#include <X11/Xaw/SmeBSB.h>
X#include <X11/Xaw/SmeLine.h>
X#include <X11/Xaw/AsciiText.h>
X#include "Calendar.h"
X#include "main.h"
X#include "diary.h"
X#include "template.h"
X#include "cal.icon"
X#include "diary.icon"
X#include "arrow_r.xbm"
X#include "arrow_l.xbm"
X#include "resource.h"
X#include "common.h"
X#include "patchlevel.h"
X
X
X/*==========================================================================*/
X/* Forward References: */
X/*==========================================================================*/
Xvoid quit();
Xvoid day_inc();
Xvoid day_dec();
Xvoid month_inc();
Xvoid month_dec();
Xvoid year_inc();
Xvoid year_dec();
Xvoid entry_inc();
Xvoid entry_dec();
Xvoid warp_to_dialog();
Xvoid warp_to_start();
Xvoid dialog_done();
Xvoid flip_calendar();
Xvoid set_the_date();
Xvoid init_bitmaps();
Xvoid init_dialog();
Xvoid init_button_box();
Xvoid init_menu();
Xvoid init_single_calendar();
Xvoid init_full_calendar();
Xvoid process_options();
XWidget make_inc_dec_button();
Xvoid change_to_full();
Xvoid change_to_single();
Xvoid initialize_diary_widgets();
Xvoid toggle_diary();
Xvoid save_diary_callback();
Xvoid calendar_callback();
Xvoid show_new_diary_entry();
Xvoid save_old_diary_entry();
Xchar * get_default_diary_file_name();
Xchar * get_default_template_file_name();
Xvoid flash();
Xvoid flash_back();
Xvoid show_pretty_date();
Xvoid sensitize();
Xvoid set_initial_time_interval();
X
X
X/*==========================================================================*/
X/* Globals: */
X/*==========================================================================*/
XWidget top_level_widget;
XWidget single_popup_shell_widget;
XWidget full_popup_shell_widget;
XWidget button_box_widget;
XWidget option_button_widget;
XWidget single_form_widget;
XWidget single_calendar_widget;
XWidget full_form_widget;
XWidget full_calendar_widgets[12];
XWidget dialog_popup_shell_widget;
XWidget dialog_widget;
XWidget text_widget;
XWidget menu_popup_shell_widget;
XWidget menu_today_widget;
XWidget menu_warp_widget;
XWidget menu_diary_widget;
XWidget menu_full_widget;
XWidget menu_single_widget;
XWidget menu_save_widget;
XWidget menu_quit_widget;
XWidget diary_popup_shell_widget;
XWidget diary_top_paned_widget;
XWidget diary_label_widget;
XWidget diary_form_widget;
XWidget diary_text_widget;
XWidget diary_text_source_widget;
X
XXtActionsRec xdiary_actions[] = {
X { "dialog_done", dialog_done },
X};
X
Xchar text_translation_table[] = "#override\n\
X <Key>Return: dialog_done()";
X
XXtTranslations text_translations;
X
XDate current_date;
X
XXrmOptionDescRec command_line_table[] =
X{
X { "-iconic", "*iconic", XrmoptionNoArg, "True" },
X { "-linewidth", "*Calendar*lineWidth", XrmoptionSepArg, NULL },
X { "-fullgeometry", "*full.geometry", XrmoptionSepArg, NULL },
X { "-singlegeometry", "*single.geometry", XrmoptionSepArg, NULL },
X { "-diarygeometry", "*diary.geometry", XrmoptionSepArg, NULL },
X { "-digitfont", "*single*digitFont", XrmoptionSepArg, NULL },
X { "-weekdayfont", "*single*weekdayFont", XrmoptionSepArg, NULL },
X { "-titlefont", "*single*titleFont", XrmoptionSepArg, NULL },
X { "-digitgravity", "*digitGravity", XrmoptionSepArg, NULL },
X { "-startingweekday", "*startingWeekday", XrmoptionSepArg, NULL },
X { "-language", "*language", XrmoptionSepArg, NULL },
X { "-diaryfile", "*diaryFile", XrmoptionSepArg, NULL },
X { "-templatefile", "*templateFile", XrmoptionSepArg, NULL },
X { "-nocalendar", "*noCalendar", XrmoptionNoArg, "True" },
X { "-nodiary", "*noDiary", XrmoptionNoArg, "True" },
X { "-long", "*long", XrmoptionNoArg, "True" },
X { "-abbrev", "*abbrev", XrmoptionSepArg, NULL },
X { "-fullyear", "*fullYear", XrmoptionNoArg, "True" },
X { "-singlemonth", "*singleMonth", XrmoptionNoArg, "True" }
X
X};
X
Xapp_data_type application_data;
X
Xchar help[] = "\n\
XUsage: xdiary [-linewidth <pixels>]\n\
X [-fullgeometry <geometry>]\n\
X [-singlegeometry <geometry>]\n\
X [-diarygeometry <geometry>]\n\
X [-digitfont <font_name>]\n\
X [-weekdayfont <font_name>]\n\
X [-titlefont <font_name>]\n\
X [-digitgravity <gravity>]\n\
X [-startingweekday <day_name>]\n\
X [-language <lang_name>]\n\
X [-diaryfile <diary_filename>]\n\
X [-templatefile <template_filename>]\n\
X [-nocalendar]\n\
X [-nodiary]\n\
X [-long]\n\
X [-abbrev <letter_count>]\n\
X [-fullyear]\n\
X [-singlemonth]\n\
X [<date_string>]\n\n";
X
X
X/* True after initialized. */
Xint full_initialized = FALSE;
Xint single_initialized = FALSE;
Xint diary_initialized = FALSE;
X
X/* True if any changes were made. */
Xint diary_changed = FALSE;
X
X/* True after flash, until flash_back */
Xint currently_flashing;
X
X
X/*==========================================================================*/
X/* Argument Processing: */
X/*==========================================================================*/
Xtypedef enum { none, single, full } mode;
Xmode display_mode = single;
Xint diary_showing = FALSE;
Xint lang_opt = ENGLISH;
Xint lang_specified = FALSE;
Xint date_opt = FALSE;
Xint long_opt = FALSE;
Xint abbrev_opt = 3;
Xint diary_opt = TRUE;
Xint fly_opt = FALSE;
Xint arg_error = FALSE;
Xint forward = TRUE;
Xint interval = 0;
Xint using_template = FALSE;
XXtIntervalId timeout_id;
Xchar * date_string = NULL;
Xchar * diary_file_name = NULL;
Xchar * template_file_name = NULL;
X
X/* Ignores case. Allows partial abbreviations or garbage at end. */
Xint check_option(string_ptr, option_ptr)
Xchar * string_ptr;
Xchar * option_ptr;
X{
X while (*string_ptr && *option_ptr) {
X if (DOWNCASE(*string_ptr) == *option_ptr) {
X /* Letters match */
X string_ptr++;
X option_ptr++;
X } else {
X /* Doesn't match. */
X return FALSE;
X }
X }
X return TRUE;
X}
X
X
X
X#define OPTION(opt) (check_option(argv[count],(opt)))
X#define ARG (argv[count])
X#define NEXT \
X if (++count == argc) { \
X fprintf(stderr, "xdiary: \"%s\" requires argument\n", argv[count-1]); \
X return FALSE; \
X }
X
X
X
Xint parse_args(argc, argv)
Xint argc;
Xchar *argv[];
X{
X int count;
X for (count=1; count < argc; count++) {
X
X /* Undocumented, used for testing. */
X if (OPTION("-flies")) {
X fly_opt = TRUE;
X NEXT;
X interval = atoi(ARG);
X if (interval < 0) {
X interval = abs(interval);
X forward = FALSE;
X }
X continue;
X }
X
X if (OPTION("-")) {
X fprintf(stderr, "xdiary: unknown option \"%s\"\n", ARG);
X arg_error = TRUE;
X continue;
X }
X
X if (!date_opt++) {
X date_string = ARG;
X continue;
X }
X
X /* No valid options match. */
X return FALSE;
X }
X
X /* All options present and accounted for. */
X return TRUE;
X}
X
X
X
X
X
X#define RESOURCE(field) (application_data.field)
X#define EQUAL(res, str) (check_option((res),(str)))
X
Xvoid process_resources()
X{
X if (RESOURCE(language)) {
X lang_specified = TRUE;
X if (EQUAL(RESOURCE(language), "english")) lang_opt = ENGLISH; else
X if (EQUAL(RESOURCE(language), "spanish")) lang_opt = SPANISH; else
X if (EQUAL(RESOURCE(language), "french")) lang_opt = FRENCH; else
X if (EQUAL(RESOURCE(language), "german")) lang_opt = GERMAN; else {
X lang_specified = FALSE;
X fprintf(
X stderr,
X "xdiary: unknown language \"%s\"\n",
X RESOURCE(language)
X );
X }
X }
X
X if (RESOURCE(diaryfile)) {
X diary_file_name = RESOURCE(diaryfile);
X }
X
X if (RESOURCE(templatefile)) {
X template_file_name = RESOURCE(templatefile);
X }
X
X if (RESOURCE(nocalendar)) {
X display_mode = none;
X }
X
X if (RESOURCE(nodiary)) {
X if (display_mode == none) {
X fprintf(
X stderr,
X "xdiary: nocalendar and nodiary can't both be specified.\n"
X );
X } else {
X diary_opt = FALSE;
X }
X }
X
X if (RESOURCE(long_opt)) {
X long_opt = TRUE;
X lang_specified = TRUE;
X }
X
X if (RESOURCE(abbrev)) {
X abbrev_opt = RESOURCE(abbrev);
X if (abbrev_opt < 0) {
X abbrev_opt = 0;
X }
X lang_specified = TRUE;
X }
X
X if (RESOURCE(fullyear)) {
X display_mode = full;
X }
X
X if (RESOURCE(singlemonth)) {
X display_mode = single;
X }
X
X}
X
X
X
X
Xvoid process_options()
X{
X int month;
X int weekday;
X
X /* Abbreviate the weekday names as specified. */
X if (lang_specified && !long_opt) {
X for (weekday=0; weekday < 7; weekday++) {
X if (strlen(weekday_names[lang_opt][weekday]) > abbrev_opt) {
X weekday_names[lang_opt][weekday][abbrev_opt] = NULL;
X }
X }
X }
X
X if (display_mode == full) {
X init_full_calendar();
X } else {
X init_single_calendar();
X }
X
X /* Realize a calendar. */
X if (display_mode == single) {
X XtPopup(single_popup_shell_widget, XtGrabNone);
X if (!diary_showing) {
X sensitize(menu_single_widget, False);
X }
X } else if (display_mode == full) {
X XtPopup(full_popup_shell_widget, XtGrabNone);
X if (!diary_showing) {
X sensitize(menu_full_widget, False);
X }
X } else {
X /* Realize it, but don't pop it up. */
X XtRealizeWidget(single_popup_shell_widget);
X sensitize(menu_diary_widget, False);
X }
X
X if (date_opt) {
X /* A date string was specified. */
X if (display_mode == full) {
X current_date = DateConverter(full_calendar_widgets[0], date_string);
X } else {
X current_date = DateConverter(single_calendar_widget, date_string);
X }
X }
X
X if (!date_opt || current_date.year == 0) {
X /* No date was specified or the specified date was bogus, */
X /* so calendar widget chose its own date. Get that date. */
X if (display_mode == full) {
X CalendarGetDate(full_calendar_widgets[0], ¤t_date);
X } else {
X CalendarGetDate(single_calendar_widget, ¤t_date);
X }
X }
X
X set_the_date(current_date);
X
X /* The undocumentd fly option -- used for testing. */
X if (fly_opt) {
X timeout_id = XtAddTimeOut(interval, flip_calendar, NULL);
X } else {
X /* Make calendar flip with the date. */
X set_initial_time_interval();
X timeout_id = XtAddTimeOut(interval, flip_calendar, NULL);
X interval = TWENTY_FOUR_HOURS;
X }
X
X if (!diary_file_name) {
X diary_file_name = get_default_diary_file_name();
X }
X
X if (template_file_name) {
X using_template = init_template(template_file_name);
X if (!using_template) {
X fprintf(stderr, "xdiary: unable to open template file\n");
X }
X } else {
X /* No template was specified. */
X template_file_name = get_default_template_file_name();
X using_template = init_template(template_file_name);
X }
X
X if (diary_opt) {
X toggle_diary();
X }
X
X}
X
X
X
X
X
X/*==========================================================================*/
X/* Main: */
X/*==========================================================================*/
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X /* Never Realized */
X top_level_widget = XtInitialize(
X argv[0], /* application name */
X "Xdiary", /* application class */
X command_line_table, /* resource manager options */
X XtNumber(command_line_table), /* number of resource manager options */
X &argc, /* number of command line args */
X argv /* array of command line args */
X );
X
X XtGetApplicationResources(
X top_level_widget,
X &application_data,
X application_resources,
X XtNumber(application_resources),
X NULL,
X 0
X );
X
X XtAddActions(xdiary_actions, XtNumber(xdiary_actions));
X
X process_resources();
X
X if (!parse_args(argc, argv) || arg_error) {
X fprintf(stderr, help);
X XtDestroyWidget(top_level_widget);
X exit(0);
X }
X
X init_bitmaps();
X
X init_dialog();
X
X init_menu();
X
X process_options();
X
X XtMainLoop();
X
X return(1);
X}
X
X
X
X
X/*==========================================================================*/
X/* Bitmaps: */
X/*==========================================================================*/
XPixmap calendar_icon;
XPixmap diary_icon;
XPixmap right_arrow;
XPixmap left_arrow;
Xvoid init_bitmaps()
X{
X calendar_icon = XCreateBitmapFromData(
X XtDisplay(top_level_widget),
X RootWindowOfScreen(XtScreen(top_level_widget)),
X calendar_bits,
X calendar_width,
X calendar_height
X );
X
X diary_icon = XCreateBitmapFromData(
X XtDisplay(top_level_widget),
X RootWindowOfScreen(XtScreen(top_level_widget)),
X diary_bits,
X diary_width,
X diary_height
X );
X
X left_arrow = XCreateBitmapFromData(
X XtDisplay(top_level_widget),
X RootWindowOfScreen(XtScreen(top_level_widget)),
X left_arrow_bits,
X left_arrow_width,
X left_arrow_height
X );
X
X right_arrow = XCreateBitmapFromData(
X XtDisplay(top_level_widget),
X RootWindowOfScreen(XtScreen(top_level_widget)),
X right_arrow_bits,
X right_arrow_width,
X right_arrow_height
X );
X}
X
X
X
X/*==========================================================================*/
X/* Buttonbox: */
X/*==========================================================================*/
Xvoid init_button_box(parent_widget, mask)
XWidget parent_widget;
Xint mask;
X{
X Widget widget_list[MAX_WIDGETS];
X int num_to_manage = 0;
X
X /*VARARGS0*/
X button_box_widget = XtVaCreateManagedWidget (
X "buttons", /* widget name */
X boxWidgetClass, /* widget class */
X parent_widget, /* parent widget */
X XtNorientation, XtEhorizontal,
X XtNborderWidth, 0,
X XtNshowGrip, False,
X XtNskipAdjust, True,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = option_button_widget = XtVaCreateWidget (
X "option", /* widget name */
X menuButtonWidgetClass, /* widget class */
X button_box_widget, /* parent widget */
X XtNlabel, option_label[lang_opt],
X XtNmenuName, "menu",
X NULL /* end args */
X );
X
X if (mask & DAY) {
X widget_list[num_to_manage++] = make_inc_dec_button (
X "day", /* widget name */
X button_box_widget, /* parent widget */
X day_label[lang_opt], /* label */
X day_dec, /* dec callback */
X day_inc /* inc callback */
X );
X }
X
X if (mask & MONTH) {
X widget_list[num_to_manage++] = make_inc_dec_button (
X "month", /* widget name */
X button_box_widget, /* parent widget */
X month_label[lang_opt], /* label */
X month_dec, /* dec callback */
X month_inc /* inc callback */
X );
X }
X
X if (mask & YEAR) {
X widget_list[num_to_manage++] = make_inc_dec_button (
X "year", /* widget name */
X button_box_widget, /* parent widget */
X year_label[lang_opt], /* label */
X year_dec, /* dec callback */
X year_inc /* inc callback */
X );
X }
X
X if (mask & ENTRY) {
X widget_list[num_to_manage++] = make_inc_dec_button (
X "entry", /* widget name */
X button_box_widget, /* parent widget */
X entry_label[lang_opt], /* label */
X entry_dec, /* dec callback */
X entry_inc /* inc callback */
X );
X }
X
X /* Manage the children of the top form widget defined above. */
X XtManageChildren(widget_list, num_to_manage);
X}
X
X
X
X
X/*==========================================================================*/
X/* Dialog: */
X/*==========================================================================*/
Xvoid init_dialog()
X{
X /*VARARGS0*/
X dialog_popup_shell_widget = XtVaCreatePopupShell(
X "dialog",
X transientShellWidgetClass,
X top_level_widget,
X NULL
X );
X
X /*VARARGS0*/
X dialog_widget = XtVaCreateManagedWidget (
X "dialog", /* widget name */
X dialogWidgetClass, /* widget class */
X dialog_popup_shell_widget, /* parent widget */
X XtNlabel, dialog_label[lang_opt],
X XtNvalue, "",
X NULL /* end args */
X );
X text_widget = XtNameToWidget(dialog_widget, "value");
X text_translations = XtParseTranslationTable(text_translation_table);
X XtOverrideTranslations(text_widget, text_translations);
X}
X
X
X
X
X
X/*==========================================================================*/
X/* Menu: */
X/*==========================================================================*/
Xvoid init_menu()
X{
X Widget widget_list[MAX_WIDGETS];
X int num_to_manage = 0;
X
X /*VARARGS0*/
X menu_popup_shell_widget = XtVaCreatePopupShell(
X "menu",
X simpleMenuWidgetClass,
X top_level_widget,
X NULL
X );
X
X /* TODAY */
X /*VARARGS0*/
X widget_list[num_to_manage++] = menu_today_widget = XtVaCreateWidget (
X "menu_today", /* widget name */
X smeBSBObjectClass, /* widget class */
X menu_popup_shell_widget, /* parent widget */
X XtNlabel, today_label[lang_opt],
X NULL /* end args */
X );
X XtAddCallback(menu_today_widget, XtNcallback, warp_to_start, 0);
X
X /* LINE */
X /*VARARGS0*/
X widget_list[num_to_manage++] = XtVaCreateWidget (
X "line", /* widget name */
X smeLineObjectClass, /* widget class */
X menu_popup_shell_widget, /* parent widget */
X NULL /* end args */
X );
X
X /* WARP */
X /*VARARGS0*/
X widget_list[num_to_manage++] = menu_warp_widget = XtVaCreateWidget (
X "menu_warp", /* widget name */
X smeBSBObjectClass, /* widget class */
X menu_popup_shell_widget, /* parent widget */
X XtNlabel, warp_label[lang_opt],
X NULL /* end args */
X );
X XtAddCallback(menu_warp_widget, XtNcallback, warp_to_dialog, 0);
X
X /* LINE */
X /*VARARGS0*/
X widget_list[num_to_manage++] = XtVaCreateWidget (
X "line", /* widget name */
X smeLineObjectClass, /* widget class */
X menu_popup_shell_widget, /* parent widget */
X NULL /* end args */
X );
X
X /* DIARY */
X /*VARARGS0*/
X widget_list[num_to_manage++] = menu_diary_widget = XtVaCreateWidget (
X "menu_diary", /* widget name */
X smeBSBObjectClass, /* widget class */
X menu_popup_shell_widget, /* parent widget */
X XtNlabel, diary_label[lang_opt],
X NULL /* end args */
X );
X XtAddCallback(menu_diary_widget, XtNcallback, toggle_diary, 0);
X
X /* LINE */
X /*VARARGS0*/
X widget_list[num_to_manage++] = XtVaCreateWidget (
X "line", /* widget name */
X smeLineObjectClass, /* widget class */
X menu_popup_shell_widget, /* parent widget */
X NULL /* end args */
X );
X
X /* FULL */
X /*VARARGS0*/
X widget_list[num_to_manage++] = menu_full_widget = XtVaCreateWidget (
X "menu_full", /* widget name */
X smeBSBObjectClass, /* widget class */
X menu_popup_shell_widget, /* parent widget */
X XtNlabel, full_label[lang_opt],
X NULL /* end args */
X );
X XtAddCallback(menu_full_widget, XtNcallback, change_to_full, 0);
X
X /* LINE */
X /*VARARGS0*/
X widget_list[num_to_manage++] = XtVaCreateWidget (
X "line", /* widget name */
X smeLineObjectClass, /* widget class */
X menu_popup_shell_widget, /* parent widget */
X NULL /* end args */
X );
X
X /* SINGLE */
X /*VARARGS0*/
X widget_list[num_to_manage++] = menu_single_widget = XtVaCreateWidget (
X "menu_single", /* widget name */
X smeBSBObjectClass, /* widget class */
X menu_popup_shell_widget, /* parent widget */
X XtNlabel, single_label[lang_opt],
X NULL /* end args */
X );
X XtAddCallback(menu_single_widget, XtNcallback, change_to_single, 0);
X
X /* LINE */
X /*VARARGS0*/
X widget_list[num_to_manage++] = XtVaCreateWidget (
X "line", /* widget name */
X smeLineObjectClass, /* widget class */
X menu_popup_shell_widget, /* parent widget */
X NULL /* end args */
X );
X
X /* SAVE */
X /*VARARGS0*/
X widget_list[num_to_manage++] = menu_save_widget = XtVaCreateWidget (
X "menu_save", /* widget name */
X smeBSBObjectClass, /* widget class */
X menu_popup_shell_widget, /* parent widget */
X XtNlabel, save_label[lang_opt],
X NULL /* end args */
X );
X XtAddCallback(menu_save_widget, XtNcallback, save_diary_callback, 0);
X
X /* LINE */
X /*VARARGS0*/
X widget_list[num_to_manage++] = XtVaCreateWidget (
X "line", /* widget name */
X smeLineObjectClass, /* widget class */
X menu_popup_shell_widget, /* parent widget */
X NULL /* end args */
X );
X
X /* QUIT */
X /*VARARGS0*/
X widget_list[num_to_manage++] = menu_quit_widget = XtVaCreateWidget (
X "menu_quit", /* widget name */
X smeBSBObjectClass, /* widget class */
X menu_popup_shell_widget, /* parent widget */
X XtNlabel, quit_label[lang_opt],
X NULL /* end args */
X );
X XtAddCallback(menu_quit_widget, XtNcallback, quit, 0);
X
X /* Manage the children of the top form widget defined above. */
X XtManageChildren(widget_list, num_to_manage);
X}
X
X
X
X
X/*==========================================================================*/
X/* Single Calendar: */
X/*==========================================================================*/
Xvoid init_single_calendar()
X{
X Widget single_paned_widget;
X int linewidth;
X
X if (single_initialized) return;
X single_initialized = TRUE;
X
X /*VARARGS0*/
X single_popup_shell_widget = XtVaCreatePopupShell(
X "single",
X topLevelShellWidgetClass,
X top_level_widget,
X XtNiconPixmap, calendar_icon,
X XtNiconName, "calendar",
X NULL
X );
X
X /*VARARGS0*/
X single_paned_widget = XtVaCreateManagedWidget (
X "paned", /* widget name */
X panedWidgetClass, /* widget class */
X single_popup_shell_widget, /* parent widget */
X NULL /* end args */
X );
X
X init_button_box(single_paned_widget, MONTH | YEAR);
X
X /*VARARGS0*/
X single_form_widget = XtVaCreateManagedWidget (
X "form", /* widget name */
X formWidgetClass, /* widget class */
X single_paned_widget, /* parent widget */
X XtNshowGrip, False,
X XtNborderWidth, 0,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X single_calendar_widget = XtVaCreateManagedWidget (
X "calendar", /* widget name */
X calendarWidgetClass, /* widget class */
X single_form_widget, /* parent widget */
X XtNtop, XtChainTop,
X XtNbottom, XtChainBottom,
X XtNright, XtChainRight,
X XtNleft, XtChainLeft,
X XtNborderWidth, 0,
X NULL /* end args */
X );
X XtAddCallback(single_calendar_widget, XtNcallback, calendar_callback, 0);
X
X /* Get the border and the grid to be the same thickness */
X /*VARARGS0*/
X XtVaGetValues(
X single_calendar_widget,
X XtNlineWidth, &linewidth,
X NULL
X );
X
X /*VARARGS0*/
X XtVaSetValues(
X single_calendar_widget,
X XtNborderWidth, linewidth/2,
X NULL
X );
X
X if (lang_specified) {
X /*VARARGS0*/
X XtVaSetValues(
X single_calendar_widget,
X XtNmonthNames, (XtPointer) month_names[lang_opt],
X XtNweekdayNames, (XtPointer) weekday_names[lang_opt],
X NULL
X );
X }
X}
X
X
X
X/*==========================================================================*/
X/* Full Calendar: */
X/*==========================================================================*/
Xvoid init_full_calendar()
X{
X Widget full_paned_widget;
X Widget widget_list[MAX_WIDGETS];
X int num_to_manage = 0;
X int month;
X int linewidth;
X
X if (full_initialized) return;
X full_initialized = TRUE;
X
X /*VARARGS0*/
X full_popup_shell_widget = XtVaCreatePopupShell (
X "full",
X topLevelShellWidgetClass,
X top_level_widget,
X XtNiconPixmap, calendar_icon,
X XtNiconName, "calendar",
X NULL
X );
X
X /*VARARGS0*/
X full_paned_widget = XtVaCreateManagedWidget (
X "paned", /* widget name */
X panedWidgetClass, /* widget class */
X full_popup_shell_widget, /* parent widget */
X NULL /* end args */
X );
X
X init_button_box(full_paned_widget, YEAR);
X
X /*VARARGS0*/
X full_form_widget = XtVaCreateManagedWidget (
X "form", /* widget name */
X formWidgetClass, /* widget class */
X full_paned_widget, /* parent widget */
X XtNshowGrip, False,
X XtNborderWidth, 1,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = full_calendar_widgets[0] = XtVaCreateWidget (
X "january", /* widget name */
X calendarWidgetClass, /* widget class */
X full_form_widget, /* parent widget */
X XtNtop, XtChainTop,
X XtNleft, XtChainLeft,
X XtNborderWidth, 0,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = full_calendar_widgets[1] = XtVaCreateWidget (
X "february", /* widget name */
X calendarWidgetClass, /* widget class */
X full_form_widget, /* parent widget */
X XtNfromHoriz, full_calendar_widgets[0],
X XtNtop, XtChainTop,
X XtNborderWidth, 0,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = full_calendar_widgets[2] = XtVaCreateWidget (
X "march", /* widget name */
X calendarWidgetClass, /* widget class */
X full_form_widget, /* parent widget */
X XtNfromHoriz, full_calendar_widgets[1],
X XtNtop, XtChainTop,
X XtNright, XtChainRight,
X XtNborderWidth, 0,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = full_calendar_widgets[3] = XtVaCreateWidget (
X "april", /* widget name */
X calendarWidgetClass, /* widget class */
X full_form_widget, /* parent widget */
X XtNfromVert, full_calendar_widgets[0],
X XtNleft, XtChainLeft,
X XtNborderWidth, 0,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = full_calendar_widgets[4] = XtVaCreateWidget (
X "may", /* widget name */
X calendarWidgetClass, /* widget class */
X full_form_widget, /* parent widget */
X XtNfromVert, full_calendar_widgets[0],
X XtNfromHoriz, full_calendar_widgets[3],
X XtNborderWidth, 0,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = full_calendar_widgets[5] = XtVaCreateWidget (
X "june", /* widget name */
X calendarWidgetClass, /* widget class */
X full_form_widget, /* parent widget */
X XtNfromVert, full_calendar_widgets[0],
X XtNfromHoriz, full_calendar_widgets[4],
X XtNright, XtChainRight,
X XtNborderWidth, 0,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = full_calendar_widgets[6] = XtVaCreateWidget (
X "july", /* widget name */
X calendarWidgetClass, /* widget class */
X full_form_widget, /* parent widget */
X XtNfromVert, full_calendar_widgets[3],
X XtNleft, XtChainLeft,
X XtNborderWidth, 0,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = full_calendar_widgets[7] = XtVaCreateWidget (
X "august", /* widget name */
X calendarWidgetClass, /* widget class */
X full_form_widget, /* parent widget */
X XtNfromVert, full_calendar_widgets[3],
X XtNfromHoriz, full_calendar_widgets[6],
X XtNborderWidth, 0,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = full_calendar_widgets[8] = XtVaCreateWidget (
X "september", /* widget name */
X calendarWidgetClass, /* widget class */
X full_form_widget, /* parent widget */
X XtNfromVert, full_calendar_widgets[3],
X XtNfromHoriz, full_calendar_widgets[7],
X XtNright, XtChainRight,
X XtNborderWidth, 0,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = full_calendar_widgets[9] = XtVaCreateWidget (
X "october", /* widget name */
X calendarWidgetClass, /* widget class */
X full_form_widget, /* parent widget */
X XtNfromVert, full_calendar_widgets[6],
X XtNbottom, XtChainBottom,
X XtNleft, XtChainLeft,
X XtNborderWidth, 0,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = full_calendar_widgets[10] = XtVaCreateWidget (
X "november", /* widget name */
X calendarWidgetClass, /* widget class */
X full_form_widget, /* parent widget */
X XtNfromVert, full_calendar_widgets[6],
X XtNfromHoriz, full_calendar_widgets[9],
X XtNbottom, XtChainBottom,
X XtNborderWidth, 0,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = full_calendar_widgets[11] = XtVaCreateWidget (
X "december", /* widget name */
X calendarWidgetClass, /* widget class */
X full_form_widget, /* parent widget */
X XtNfromVert, full_calendar_widgets[6],
X XtNfromHoriz, full_calendar_widgets[10],
X XtNbottom, XtChainBottom,
X XtNright, XtChainRight,
X XtNborderWidth, 0,
X NULL /* end args */
X );
X
X /* Get the border and the grid to be the same thickness */
X /*VARARGS0*/
X XtVaGetValues(
X full_calendar_widgets[0],
X XtNlineWidth, &linewidth,
X NULL
X );
X
X for (month=0; month < 12; month++) {
X XtAddCallback(
X full_calendar_widgets[month],
X XtNcallback,
X calendar_callback,
X 0
X );
X
X /*VARARGS0*/
X XtVaSetValues(
X full_calendar_widgets[month],
X XtNborderWidth, linewidth/2,
X NULL
X );
X
X if (lang_specified) {
X /*VARARGS0*/
X XtVaSetValues(
X full_calendar_widgets[month],
X XtNmonthNames, (XtPointer) month_names[lang_opt],
X XtNweekdayNames, (XtPointer) weekday_names[lang_opt],
X NULL
X );
X }
X }
X
X /* Manage all the children of the form widget */
X XtManageChildren(widget_list, num_to_manage);
X}
X
X
X
X/*==========================================================================*/
X/* Make Inc/Dec Button: */
X/*==========================================================================*/
XWidget make_inc_dec_button(name, parent_widget, label, callback1, callback2)
Xchar * name;
XWidget parent_widget;
Xchar * label;
Xvoid (*callback1)();
Xvoid (*callback2)();
X{
X Widget form_widget;
X Widget button1;
X Widget button2;
X Widget label_widget;
X Widget widget_list[MAX_WIDGETS];
X int num_to_manage = 0;
X
X /*VARARGS0*/
X form_widget = XtVaCreateManagedWidget (
X "form", /* widget name */
X formWidgetClass, /* widget class */
X parent_widget, /* parent widget */
X XtNtop, XtChainTop,
X XtNbottom, XtChainBottom,
X XtNleft, XtChainLeft,
X XtNright, XtChainRight,
X XtNdefaultDistance, 0,
X XtNborderWidth, 0,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = label_widget = XtVaCreateWidget (
X name, /* widget name */
X labelWidgetClass, /* widget class */
X form_widget, /* parent widget */
X XtNlabel, label,
X XtNtop, XtChainTop,
X XtNbottom, XtChainTop,
X XtNleft, XtChainLeft,
X XtNright, XtChainLeft,
X XtNborderWidth, 0,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = button1 = XtVaCreateWidget (
X "dec", /* widget name */
X commandWidgetClass, /* widget class */
X form_widget, /* parent widget */
X XtNfromHoriz, label_widget,
X XtNtop, XtChainTop,
X XtNbottom, XtChainTop,
X XtNleft, XtChainLeft,
X XtNright, XtChainLeft,
X XtNbitmap, left_arrow,
X XtNborderWidth, 1,
X NULL /* end args */
X );
X XtAddCallback(button1, XtNcallback, callback1, NULL);
X
X /*VARARGS0*/
X widget_list[num_to_manage++] = button2 = XtVaCreateWidget (
X "inc", /* widget name */
X commandWidgetClass, /* widget class */
X form_widget, /* parent widget */
X XtNfromHoriz, button1,
X XtNtop, XtChainTop,
X XtNbottom, XtChainTop,
X XtNleft, XtChainLeft,
X XtNright, XtChainLeft,
X XtNbitmap, right_arrow,
X XtNborderWidth, 1,
X NULL /* end args */
X );
X XtAddCallback(button2, XtNcallback, callback2, NULL);
X
X /* Manage all the children of the form widget */
X XtManageChildren(widget_list, num_to_manage);
X
X return (form_widget);
X}
X
X
X
X/*==========================================================================*/
X/* Miscellaneous Functions: */
X/*==========================================================================*/
Xvoid set_the_date(new_date)
XDate new_date;
X{
X int month;
X Date temp_date;
X
X if (display_mode == full) {
X
X temp_date.year = new_date.year;
X
X /* Only change the calendar date if a day was specified. */
X if (new_date.day) {
X for (month=0; month < 12; month ++) {
X /* Set date to highlight for each calendar. */
X CalendarSetDate(full_calendar_widgets[month], new_date);
X current_date = new_date;
X }
X }
X
X for (month=0; month < 12; month ++) {
X /* Set month to show for each calendar. */
X temp_date.month = month+1;
X CalendarShowMonth(full_calendar_widgets[month], temp_date);
X }
X
X } else if (display_mode == single) {
X
X /* Only change the calendar date if a day was specified. */
X if (new_date.day) {
X CalendarSetDate(single_calendar_widget, new_date);
X current_date = new_date;
X }
X CalendarShowMonth(single_calendar_widget, new_date);
X
X } else {
X
X /* No calendar is displayed. */
X if (new_date.day) {
X CalendarSetDate(single_calendar_widget, new_date);
X current_date = new_date;
X }
X }
X
X}
X
X
X
X
Xvoid flip_calendar()
X{
X if (fly_opt) {
X if (forward) {
X day_inc();
X } else {
X day_dec();
X }
X } else {
X warp_to_start(NULL, NULL, NULL);
X }
X timeout_id = XtAddTimeOut(interval, flip_calendar, NULL);
X}
X
X
X
X
Xchar * get_default_diary_file_name()
X{
X static char file_name[MAXPATHLEN];
X uid_t uid = getuid();
X struct passwd * pwent = getpwuid(uid);
X strcpy(file_name, pwent->pw_dir);
X strcat(file_name, DIARY_FILE);
X return(file_name);
X}
X
X
X
X
Xchar * get_default_template_file_name()
X{
X static char file_name[MAXPATHLEN];
X uid_t uid = getuid();
X struct passwd * pwent = getpwuid(uid);
X strcpy(file_name, pwent->pw_dir);
X strcat(file_name, TEMPLATE_FILE);
X return(file_name);
X}
X
X
X
X
X/* Determine micro seconds til midnight. */
Xvoid set_initial_time_interval()
X{
X time_t seconds = time(NULL);
X struct tm * tm_ptr = localtime(&seconds);
X int minutes = tm_ptr->tm_hour * 60 + tm_ptr->tm_min;
X
X /* Wait until 5 minutes after midnight and then flip */
X interval = TWENTY_FOUR_HOURS + FIVE_MINUTES - (1000 * 60 * minutes);
X}
X
X
X
X
X
X/*==========================================================================*/
X/* Callbacks: */
X/*==========================================================================*/
X/*ARGSUSED*/
Xvoid quit(widget, client_data, call_data)
XWidget widget;
XXtPointer client_data;
XXtPointer call_data;
X{
X save_old_diary_entry();
X XtDestroyWidget(top_level_widget);
X if (diary_changed) {
X save_diary(diary_file_name);
X diary_changed = FALSE;
X }
X XtRemoveTimeOut(timeout_id);
X exit(0);
X}
X
X
X
X/*ARGSUSED*/
Xvoid month_inc(widget, client_data, call_data)
XWidget widget;
XXtPointer client_data;
XXtPointer call_data;
X{
X /* Only called from single calendar mode. */
X CalendarIncMonth(single_calendar_widget);
X}
X
X
X
X
X/*ARGSUSED*/
Xvoid month_dec(widget, client_data, call_data)
XWidget widget;
XXtPointer client_data;
XXtPointer call_data;
X{
X /* Only called from single calendar mode. */
X CalendarDecMonth(single_calendar_widget);
X}
X
X
X
X
X/*ARGSUSED*/
Xvoid year_inc(widget, client_data, call_data)
XWidget widget;
XXtPointer client_data;
XXtPointer call_data;
X{
X int month;
X if (display_mode == full) {
X for (month=0; month < 12; month++) {
X CalendarIncYear(full_calendar_widgets[month]);
X }
X } else {
X CalendarIncYear(single_calendar_widget);
X }
X}
X
X
X
X/*ARGSUSED*/
Xvoid year_dec(widget, client_data, call_data)
XWidget widget;
XXtPointer client_data;
XXtPointer call_data;
X{
X int month;
X if (display_mode == full) {
X for (month=0; month < 12; month++) {
X CalendarDecYear(full_calendar_widgets[month]);
X }
X } else {
X CalendarDecYear(single_calendar_widget);
X }
X}
X
X
X
X
X/*ARGSUSED*/
Xvoid warp_to_dialog(widget, client_data, call_data)
XWidget widget;
XXtPointer client_data;
XXtPointer call_data;
X{
X Position x, y;
X
X XtTranslateCoords(
X widget,
X 0, 0,
X &x, &y
X );
X
X /*VARARGS0*/
X XtVaSetValues(
X dialog_popup_shell_widget,
X XtNx, x+6,
X XtNy, y-6,
X NULL
X );
X
X /*VARARGS0*/
X XtVaSetValues(
X dialog_widget,
X XtNvalue, "",
X NULL
X );
X XtPopup(dialog_popup_shell_widget, XtGrabExclusive);
X}
X
X
X
X
X/*ARGSUSED*/
Xvoid warp_to_start(widget, client_data, call_data)
XWidget widget;
XXtPointer client_data;
XXtPointer call_data;
X{
X Date todays_date;
X todays_date = GetTodaysDate();
X save_old_diary_entry();
X set_the_date(todays_date);
X show_new_diary_entry();
X}
X
X
X
X
X
X/*ARGSUSED*/
Xvoid day_inc(widget, client_data, call_data)
XWidget widget;
XXtPointer client_data;
XXtPointer call_data;
X{
X int month;
X Date temp_date;
X
X save_old_diary_entry();
X
X if (display_mode == full) {
X
X for (month=0; month < 12; month++) {
X CalendarIncDay(full_calendar_widgets[month], False);
X }
X
X CalendarGetDate(full_calendar_widgets[0], ¤t_date);
X
X temp_date.year = current_date.year;
X for (month=0; month < 12; month++) {
X temp_date.month = month+1;
X CalendarShowMonth(full_calendar_widgets[month], temp_date);
X }
X
X } else if (display_mode == single) {
X
X CalendarIncDay(single_calendar_widget, True);
X CalendarGetDate(single_calendar_widget, ¤t_date);
X CalendarShowMonth(single_calendar_widget, current_date);
X
X } else {
X
X /* No calendar is displayed. */
X CalendarIncDay(single_calendar_widget, True);
X CalendarGetDate(single_calendar_widget, ¤t_date);
X }
X
X show_new_diary_entry();
X}
X
X
X
X
X/*ARGSUSED*/
Xvoid day_dec(widget, client_data, call_data)
XWidget widget;
XXtPointer client_data;
XXtPointer call_data;
X{
X int month;
X Date temp_date;
X
X save_old_diary_entry();
X
X if (display_mode == full) {
X
X for (month=0; month < 12; month++) {
X CalendarDecDay(full_calendar_widgets[month], False);
X }
X
X CalendarGetDate(full_calendar_widgets[0], ¤t_date);
X
X temp_date.year = current_date.year;
X for (month=0; month < 12; month++) {
X temp_date.month = month+1;
X CalendarShowMonth(full_calendar_widgets[month], temp_date);
X }
X
X } else if (display_mode == single) {
X
X CalendarDecDay(single_calendar_widget, True);
X CalendarGetDate(single_calendar_widget, ¤t_date);
X CalendarShowMonth(single_calendar_widget, current_date);
X
X } else {
X
X /* No calendar is displayed. */
X CalendarDecDay(single_calendar_widget, True);
X CalendarGetDate(single_calendar_widget, ¤t_date);
X }
X
X show_new_diary_entry();
X}
X
X
X
X
X/*ARGSUSED*/
Xvoid change_to_full(widget, client_data, call_data)
XWidget widget;
XXtPointer client_data;
XXtPointer call_data;
X{
X if (display_mode == full) {
X if (diary_showing) {
X XtPopdown(full_popup_shell_widget);
X sensitize(menu_diary_widget, False);
X sensitize(menu_full_widget, True);
X sensitize(menu_single_widget, True);
X display_mode = none;
X } else {
X /* Can't hide full if no diary is showing. */
X }
X return;
X }
X
X if (display_mode == single) {
X XtPopdown(single_popup_shell_widget);
X }
X
X if (!full_initialized) {
X init_full_calendar();
X }
X
X if (!diary_showing) {
X sensitize(menu_full_widget, False);
X sensitize(menu_single_widget, True);
X } else {
X sensitize(menu_diary_widget, True);
X }
X
X XtPopup(full_popup_shell_widget, XtGrabNone);
X display_mode = full;
X set_the_date(current_date);
X}
X
X
X
X
X/*ARGSUSED*/
Xvoid change_to_single(widget, client_data, call_data)
XWidget widget;
XXtPointer client_data;
XXtPointer call_data;
X{
X if (display_mode == single) {
X if (diary_showing) {
X XtPopdown(single_popup_shell_widget);
X sensitize(menu_diary_widget, False);
X sensitize(menu_full_widget, True);
X sensitize(menu_single_widget, True);
X display_mode = none;
X } else {
X /* Can't hide single if no diary is showing. */
X }
X return;
X }
X
X if (display_mode == full) {
X XtPopdown(full_popup_shell_widget);
X }
X
X if (!single_initialized) {
X init_single_calendar();
X }
X
X if (!diary_showing) {
X sensitize(menu_single_widget, False);
X sensitize(menu_full_widget, True);
X } else {
X sensitize(menu_diary_widget, True);
X }
X
X XtPopup(single_popup_shell_widget, XtGrabNone);
X display_mode = single;
X set_the_date(current_date);
X}
X
X
X
X
X/*==========================================================================*/
X/* Actions: */
X/*==========================================================================*/
X/*ARGSUSED*/
Xvoid dialog_done(w, event, params, num_params)
XWidget w;
XXButtonEvent *event;
XString *params;
XCardinal *num_params;
X{
X char * string;
X Date new_date;
X
X XtPopdown(dialog_popup_shell_widget);
X string = XawDialogGetValueString(dialog_widget);
X if (!strcmp(string, "")) {
X return;
X }
X
X if (display_mode == full) {
X new_date = DateConverter(full_calendar_widgets[0], string);
X } else {
X new_date = DateConverter(single_calendar_widget, string);
X }
X
X if (new_date.year) {
X /* The date was valid. */
X if (diary_showing) {
X save_old_diary_entry();
X set_the_date(new_date);
X show_new_diary_entry();
X } else {
X set_the_date(new_date);
X }
X }
X}
X
X
X
X
X/*==========================================================================*/
X/* Diary: */
X/*==========================================================================*/
Xvoid initialize_diary_widgets()
X{
X diary_initialized = TRUE;
X
X init_diary(diary_file_name);
X
X /*VARARGS0*/
X diary_popup_shell_widget = XtVaCreatePopupShell(
X "diary",
X topLevelShellWidgetClass,
X top_level_widget,
X XtNiconPixmap, diary_icon,
X XtNiconName, "diary",
X XtNwaitForWm, False,
X NULL
X );
X
X /*VARARGS0*/
X diary_top_paned_widget = XtVaCreateManagedWidget (
X "paned", /* widget name */
X panedWidgetClass, /* widget class */
X diary_popup_shell_widget, /* parent widget */
X NULL /* end args */
X );
X
X init_button_box(diary_top_paned_widget, DAY | ENTRY);
X
X /*VARARGS0*/
X diary_label_widget = XtVaCreateManagedWidget (
X "label", /* widget name */
X labelWidgetClass, /* widget class */
X diary_top_paned_widget, /* parent widget */
X XtNlabel, "",
X XtNshowGrip, False,
X XtNskipAdjust, True,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X diary_form_widget = XtVaCreateManagedWidget (
X "form", /* widget name */
X formWidgetClass, /* widget class */
X diary_top_paned_widget, /* parent widget */
X XtNshowGrip, False,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X diary_text_widget = XtVaCreateManagedWidget(
X "text", /* widget name */
X asciiTextWidgetClass, /* widget class */
X diary_form_widget, /* parent widget */
X XtNeditType, XtEtextEdit,
X XtNtop, XtChainTop,
X XtNbottom, XtChainBottom,
X XtNright, XtChainRight,
X XtNleft, XtChainLeft,
X NULL /* end args */
X );
X
X /*VARARGS0*/
X XtVaGetValues(
X diary_text_widget,
X XtNtextSource, &diary_text_source_widget,
X NULL
X );
X}
X
X
X
X
Xvoid toggle_diary()
X{
X if (!diary_initialized) {
X initialize_diary_widgets();
X }
X
X if (!diary_showing) {
X /* Display the diary. */
X XtPopup(diary_popup_shell_widget, XtGrabNone);
X diary_showing = TRUE;
X sensitize(menu_diary_widget, True);
X if (display_mode != none) {
X sensitize(menu_full_widget, True);
X sensitize(menu_single_widget, True);
X } else {
X sensitize(menu_diary_widget, False);
X }
X show_new_diary_entry();
X } else if (display_mode != none) {
X /* Hide the diary. */
X XtPopdown(diary_popup_shell_widget);
X diary_showing = FALSE;
X if (display_mode == single) {
X sensitize(menu_single_widget, False);
X } else {
X sensitize(menu_full_widget, False);
X }
X save_old_diary_entry();
X }
X}
X
X
X
Xvoid show_new_diary_entry()
X{
X char * pretty_string;
X char * entry_text;
X
X if (!diary_showing) {
X return;
X }
X
X entry_text = retrieve(current_date);
X
X if (using_template && !entry_text[0]) {
X /* Initialize the entry to the template. */
X entry_text = template;
X }
X
X /*VARARGS0*/
X XtVaSetValues(
X diary_text_widget,
X XtNstring, entry_text,
X NULL
X );
X
X if (display_mode == full) {
X pretty_string = CalendarPrettyDate(full_calendar_widgets[0]);
X } else {
X pretty_string = CalendarPrettyDate(single_calendar_widget);
X }
X
X /*VARARGS0*/
X XtVaSetValues(
X diary_label_widget,
X XtNlabel, pretty_string,
X NULL /* end args */
X );
X}
X
X
X
Xvoid save_old_diary_entry()
X{
X char * old_text;
X char * copy;
X
X if (!diary_initialized) {
X return;
X }
X
X if (XawAsciiSourceChanged(diary_text_source_widget)) {
X
X diary_changed = TRUE;
X
X /*VARARGS0*/
X XtVaGetValues(
X diary_text_widget,
X XtNstring, &old_text,
X NULL
X );
X
X if (using_template) {
X if (entry_modified(old_text)) {
X copy = XtNewString(old_text);
X install(current_date, copy, TRUE);
X } else {
X /* Only whitespace changes were made to the template */
X install(current_date, "", FALSE);
X }
X } else {
X copy = XtNewString(old_text);
X install(current_date, copy, TRUE);
X }
X }
X}
X
X
X
X
Xvoid sensitize(widget, flag)
XWidget widget;
XBoolean flag;
X{
X /*VARARGS0*/
X XtVaSetValues(
X widget,
X XtNsensitive, flag,
X NULL
X );
X}
X
X
X
X
X/*==========================================================================*/
X/* Diary Callbacks: */
X/*==========================================================================*/
X/*ARGSUSED*/
Xvoid entry_inc(widget, client_data, call_data)
XWidget widget;
XXtPointer client_data;
XXtPointer call_data;
X{
X Date next_date;
X if (currently_flashing) {
X return;
X }
X next_date = next_entry(current_date);
X if (next_date.year) {
X save_old_diary_entry();
X set_the_date(next_date);
X show_new_diary_entry();
X } else {
X flash("No following diary entry exists");
X }
X}
X
X
X
X
X/*ARGSUSED*/
Xvoid entry_dec(widget, client_data, call_data)
XWidget widget;
XXtPointer client_data;
XXtPointer call_data;
X{
X Date prev_date;
X if (currently_flashing) {
X return;
X }
X prev_date = prev_entry(current_date);
X if (prev_date.year) {
X save_old_diary_entry();
X set_the_date(prev_date);
X show_new_diary_entry();
X } else {
X flash("No previous diary entry exists");
X }
X}
X
X
X
X
X/*ARGSUSED*/
Xvoid save_diary_callback(widget, client_data, call_data)
XWidget widget;
XXtPointer client_data;
XXtPointer call_data;
X{
X save_old_diary_entry();
X if (diary_changed) {
X save_diary(diary_file_name);
X diary_changed = FALSE;
X }
X}
X
X
X
X/*ARGSUSED*/
Xvoid calendar_callback(widget, client_data, call_data)
XWidget widget;
XXtPointer client_data;
XXtPointer call_data;
X{
X Date * date_ptr = (Date *) call_data;
X
X if (diary_showing) {
X save_old_diary_entry();
X set_the_date(*date_ptr);
X show_new_diary_entry();
X } else {
X set_the_date(*date_ptr);
X }
X}
X
X
X
X
Xvoid flash(string)
Xchar * string;
X{
X currently_flashing = TRUE;
X /*VARARGS0*/
X XtVaSetValues(
X diary_label_widget,
X XtNlabel, string,
X NULL /* end args */
X );
X XtAddTimeOut(ONE_SECOND, flash_back, NULL);
X}
X
X
X
X
Xvoid flash_back()
X{
X char * pretty_string;
X
X if (display_mode == full) {
X pretty_string = CalendarPrettyDate(full_calendar_widgets[0]);
X } else {
X pretty_string = CalendarPrettyDate(single_calendar_widget);
X }
X
X /*VARARGS0*/
X XtVaSetValues(
X diary_label_widget,
X XtNlabel, pretty_string,
X NULL /* end args */
X );
X currently_flashing = FALSE;
X}
END_OF_FILE
if test 54415 -ne `wc -c <'main.c'`; then
echo shar: \"'main.c'\" unpacked with wrong size!
fi
# end of 'main.c'
fi
echo shar: End of archive 4 \(of 5\).
cp /dev/null ark4isdone
MISSING=""
for I in 1 2 3 4 5 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 5 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
--
|===================================|===================================|
| Jason "Jasper" Baietto | otteiaB "repsaJ" nosaJ |
| Harris Computer Systems Division | noisiviD smetsyS retupmoC sirraH |
| Fort Lauderdale, Florida | adirolF ,eladreduaL troF |
| jason at hcx2.ssd.csd.harris.com | moc.sirrah.dsc.dss.2xch at nosaj |
|===================================|===================================|
More information about the Alt.sources
mailing list