home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Id: handler 1.17 2003-09-20 12:45:04+01 erikgrnh Exp $
- *
- * $Source: /ADFS::Csite.\044/C/User/!Calendar/Demo/!Datum/c/_RCS/handler $
- */
-
- /* include standard C definitions */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
-
- #include "strings.h"
- #include "swis.h"
-
- /* include event lib declarations */
-
- #include "event.h"
- #include "wimplib.h"
-
- /* include toolbox lib declarations */
-
- #include "toolbox.h"
- #include "window.h"
- #include "gadgets.h"
- #include "menu.h"
- #include "scale.h"
- #include "quit.h"
- #include "proginfo.h"
- #include "printdbox.h"
- #include "iconbar.h"
-
- /* Private includes */
-
- #define os_error _kernel_oserror
- #include "CalLib:calendar.h"
-
- /* include application definitions */
-
- #include "main.h"
-
- /* Support for this source */
-
- #include "handler.h"
-
- char const handler_c_ID[] =
- "$Id: handler 1.17 2003-09-20 12:45:04+01 erikgrnh Exp $";
-
- /* Names for the gadget numbers */
- enum gadget_numbers {
- G_type = 0x100, /* StringSet: Calender type */
- G_day = 0x101, /* NumRange: Day of the month */
- G_month = 0x102, /* NumRange: Month number */
- G_mname = 0x103, /* StringSet: Month name */
- G_year = 0x104, /* NumRange: Year */
- G_dow = 0x105, /* StringSet: Day of the week */
- G_week = 0x106, /* NumRange: Week number */
- G_totweek = 0x107, /* Display: Total weeks in the year */
- G_doy = 0x108, /* NumRange: Day of the year */
- G_totday = 0x109, /* Display: Total days in the year */
- G_julday = 0x10a, /* NumRange: Julian Day number */
- G_nothing
- };
-
-
- /* Set all values in accordance with the Julian Day number */
- static int set_all(int jday) {
- int cal;
- int year, month, day;
- int jday1st;
- int next1st;
-
- /* Find out which calendar type is selected */
- ERROR(stringset_get_selected(1, mainwindow, G_type, &cal));
- cal++;
-
- /* Calculate year/month/day */
- errp = xcalendar_jday_to_date(cal, jday, &year, &month, &day);
- if (errp != NULL) {
- wimp_report_error(errp,0,"Datum");
- return 1;
- }
-
- /* Set year/month/day displays */
- ERROR(numberrange_set_value(0, mainwindow, G_day , day));
- ERROR(numberrange_set_value(0, mainwindow, G_month , month));
- ERROR(stringset_set_selected(1, mainwindow, G_mname, (char *)month-1 ));
- ERROR(numberrange_set_value(0, mainwindow, G_year , year));
-
- ERROR(numberrange_set_value(0, mainwindow, G_julday, jday));
-
- /* Find day of the year: is diff with 1st Jan */
- errp = xcalendar_date_to_jday(cal, year, 1, 1, &jday1st);
- if (errp != NULL) {
- wimp_report_error(errp,0,"Datum");
- return 1;
- }
- ERROR(numberrange_set_value(0, mainwindow, G_doy, jday-jday1st+1));
-
- /* Find nr of days in the year: is diff 1st Jan this year and next year */
- errp = xcalendar_date_to_jday(cal, year+1, 1, 1, &next1st);
- if (errp != NULL) {
- wimp_report_error(errp,0,"Datum");
- return 1;
- }
- ERROR(numberrange_set_value(0, mainwindow, G_totday, next1st-jday1st));
-
- return 0;
- }
-
-
- /* Initialise the values in the window */
- static int init_window(void) {
- int jday = 12345;
- time_t now;
- struct tm *today;
-
- /* Set calendar type to Gregorian */
- ERROR(stringset_set_selected(1, mainwindow, G_type,
- (char *)calendar_GREGORIAN-1 ));
-
- /* Find the date of today */
- now = time(NULL);
- today = localtime(&now);
- errp = xcalendar_date_to_jday(calendar_GREGORIAN, today->tm_year+1900,
- today->tm_mon+1, today->tm_mday, &jday);
- if (errp != NULL) {
- wimp_report_error(errp,0,"Datum");
- return 1;
- }
-
- /* Set Julian Day number */
- ERROR(numberrange_set_value(0, mainwindow, G_julday, jday));
-
- /* Adjust all values */
- (void) set_all(jday);
-
- return 0;
- }
-
- /* handlers...*/
-
- int tbquit_handler(int event_code, ToolboxEvent *event, IdBlock *id_block,
- void *handle)
- {
- IGNORE(event_code);
- IGNORE(event);
- IGNORE(id_block);
- IGNORE(handle);
-
- quit =1;
- return 1;
- }
-
- int quit_handler(WimpMessage *message, void *handle)
- {
- IGNORE(message);
- IGNORE(handle);
-
- quit =1;
- return 1;
- }
-
- int proginfo_show(int event_code, ToolboxEvent *event, IdBlock *id_block,
- void *handle)
- {
- char version[32];
- char *p, *q;
-
- IGNORE(handle);
- IGNORE(event);
- IGNORE(event_code);
-
- /* Find the first space in version */
- p = strchr(version_c_REV, ' ');
- if(p == NULL) return 1; /* No change if no value */
- p++;
- /* Find the next space */
- q = strchr(p,' ');
- strncpy(version,p,q-p); /* Copy to string */
- version[q-p]='\0'; /* Terminate (strncpy does not do this) */
-
- /* Find the first space in date */
- p = strchr(version_c_DATE, ' ');
- if(p != NULL) { /* No change if no value */
- p++;
- /* Find the next space */
- q = strchr(p,' ');
- q++;
- strcat(version," (");
- strncat(version, p, q-p);
- strcat(version,")");
- } else {
- strcat(version," (yyyy-mm-dd)");
- }
- proginfo_set_version(0,id_block->self_id,version);
-
- return 1;
- }
-
- int toolbox_create_handler(int event_code, ToolboxEvent *event,
- IdBlock *id_block, void *handle )
- {
- ToolboxObjectAutoCreatedEvent *creat =
- (ToolboxObjectAutoCreatedEvent *) event;
-
- IGNORE(event_code);
- IGNORE(handle);
-
- if(strcmp(creat->template_name, "Window") == 0) {
- mainwindow = id_block->self_id;
- init_window();
- }
-
- return 1;
- }
-
- int value_changed_handler(int event_code, ToolboxEvent *event,
- IdBlock *id_block, void *handle )
- {
- ComponentId gadget = id_block->self_component;
- int cal;
- int year, month, day;
- int jday;
- int doy;
-
- IGNORE(event);
- IGNORE(event_code);
- IGNORE(handle);
-
- /* Ignore event if it is not for our window */
- if(id_block->self_id != mainwindow) {
- return 0;
- }
-
- /* Find out which calendar type is selected */
- ERROR(stringset_get_selected(1, mainwindow, G_type, &cal)); cal++;
-
- switch(gadget) {
- case G_type : /* StringSet: Calender type */
- ERROR(numberrange_get_value(0, mainwindow, G_julday, &jday));
- set_all(jday);
- break;
- case G_day : /* NumRange: Day of the month */
- case G_month : /* NumRange: Month number */
- case G_year : /* NumRange: Year */
- ERROR(numberrange_get_value(0, mainwindow, G_day, &day));
- ERROR(numberrange_get_value(0, mainwindow, G_month, &month));
- ERROR(numberrange_get_value(0, mainwindow, G_year, &year));
- xcalendar_date_to_jday(cal, year, month, day, &jday);
- set_all(jday);
- break;
- case G_mname : /* StringSet: Month name */
- ERROR(numberrange_get_value(0, mainwindow, G_day, &day));
- ERROR(stringset_get_selected(1, mainwindow, G_mname, &month)); month++;
- ERROR(numberrange_get_value(0, mainwindow, G_year, &year));
- xcalendar_date_to_jday(cal, year, month, day, &jday);
- set_all(jday);
- break;
- case G_dow : /* StringSet: Day of the week */
- break;
- case G_week : /* NumRange: Week number */
- break;
- case G_doy : /* NumRange: Day of the year */
- ERROR(numberrange_get_value(0, mainwindow, G_doy, &doy));
- ERROR(numberrange_get_value(0, mainwindow, G_year, &year));
- xcalendar_date_to_jday(cal, year, 1, 1, &jday);
- set_all(jday+doy-1);
- break;
- case G_julday : /* NumRange: Julian Day number */
- ERROR(numberrange_get_value(0, mainwindow, G_julday, &jday));
- set_all(jday);
- break;
- default:
- return 0;
- }
-
- return 1;
- }
-
-