home *** CD-ROM | disk | FTP | other *** search
- /*
- * month.c : Widget creation and action binding for the month
- * forms, and it's sub-widgets.
- *
- * George Ferguson (ferguson@cs.rochester.edu), 27 Oct 1990.
- *
- * $Id: month.c,v 1.1 90/11/07 11:22:57 ferguson Exp $
- */
- #include <X11/Intrinsic.h>
- #include <X11/Shell.h>
- #include <X11/StringDefs.h>
- #include <X11/Xaw/Form.h>
- #include <X11/Xaw/Command.h>
- #include <X11/Xaw/Toggle.h>
- #include <X11/Xaw/Label.h>
- #include <X11/Xaw/AsciiText.h>
- #include <X11/Xaw/Cardinals.h>
- #include "app-resources.h"
- #include "widgets.h"
- #include "month.h"
- #include "day.h"
- #include "db.h"
- #include "date-strings.h"
-
- extern int numMonths;
-
- /*
- * Functions defined in this file
- */
- MonthFormData *createMonthFormData();
- void setMonthFormData();
- void selectDay();
- void shadeButton();
-
- static void dayButtonCallbackProc();
- static void getGCAndXY();
-
- /*
- * Data defined in this file
- */
- static int dayAppointsChanged;
- static Widget radioGroup;
-
- /* - - - - - - - - */
- /* returns an unmanaged form */
-
- MonthFormData *
- createMonthFormData(parent,name,num)
- Widget parent;
- char *name;
- int num; /* 1,3,12 */
- {
- MonthFormData *m;
- DayButtonData *d;
- Widget widget;
- Arg args[3];
- char text[16];
- int row,col;
- int w,h;
-
- m = XtNew(MonthFormData);
- m->form = XtCreateWidget(name,formWidgetClass,parent,NULL,ZERO);
- switch (num) {
- case 1: w = appResources.dateWidth1;
- h = appResources.dateHeight1;
- break;
- case 3: w = appResources.dateWidth3;
- h = appResources.dateHeight3;
- break;
- case 12: w = appResources.dateWidth12;
- h = appResources.dateHeight12;
- break;
- }
- sprintf(text,"monthLabel%d",num);
- m->label = XtCreateManagedWidget(text,labelWidgetClass,m->form,NULL,ZERO);
- if (appResources.dowLabels) {
- sprintf(text,"dowLabel%d",num);
- XtSetArg(args[0],XtNfromVert,m->label);
- XtSetArg(args[1],XtNfromHoriz,NULL);
- for (col=0; col < 7; col++) {
- XtSetArg(args[2],XtNlabel,shortDayStr[col]);
- widget = XtCreateManagedWidget(text,labelWidgetClass,m->form,
- args,THREE);
- XtSetArg(args[1],XtNfromHoriz,widget);
- }
- XtSetArg(args[0],XtNfromVert,widget);
- } else {
- XtSetArg(args[0],XtNfromVert,m->label);
- }
- sprintf(text,"dayButton%d",num);
- for (row=0; row < 6; row++) {
- XtSetArg(args[1],XtNfromHoriz,NULL);
- for (col=0; col < 7; col++) {
- d = m->days[row*7+col] = XtNew(DayButtonData);
- d->button = XtCreateManagedWidget(text,toggleWidgetClass,
- m->form,args,TWO);
- XtAddCallback(d->button,"callback",dayButtonCallbackProc,d);
- XtSetArg(args[2],XtNradioData,d->button);
- XtSetValues(d->button,args+2,ONE);
- if (radioGroup == NULL)
- radioGroup = d->button;
- XawToggleChangeRadioGroup(d->button,radioGroup);
- d->pixmap = XCreatePixmap(display,root,w,h,
- DefaultDepthOfScreen(screen));
-
- XtSetArg(args[1],XtNfromHoriz,d->button);
- }
- XtSetArg(args[0],XtNfromVert,d->button);
- }
- return(m);
- }
-
- void
- setMonthFormData(m,num,month,year)
- MonthFormData *m;
- int num,month,year;
- {
- DayButtonData *d;
- Arg args[1];
- GC gc;
- char text[16];
- int first,numDays;
- int i,x,y,n;
-
- first = firstDOW(month,year);
- numDays = lastDay(month,year);
- getGCAndXY(num,&gc,&x,&y);
- XawFormDoLayout(m->form,False);
- XawToggleUnsetCurrent(radioGroup);
- sprintf(text,"%s %d",longMonStr[month],year+1900);
- XtSetArg(args[0],XtNlabel,text);
- XtSetValues(m->label,args,ONE);
- for (i=0; i < 42; i++) {
- d = m->days[i];
- if (i < first || i >= first+numDays) {
- d->day = 0;
- XFillRectangle(display,d->pixmap,emptyGC,0,0,50,50);
- XtSetArg(args[0],XtNbitmap,d->pixmap);
- XtSetValues(d->button,args,ONE);
- } else {
- d->day = i-first+1;
- d->month = month;
- d->year = year;
- shadeButton(d,gc,x,y);
- }
- }
- XawFormDoLayout(m->form,True);
- m->month = month;
- m->year = year;
- }
-
- /* This function is here so it can be outside the loop in setMonthFormData(),
- but really belongs in shadeButton. */
- static void
- getGCAndXY(num,gcp,xp,yp)
- GC *gcp;
- int *xp,*yp;
- {
- int w,h;
-
- switch (num) {
- case 1: XParseGeometry(appResources.datePosition1,xp,yp,&w,&h);
- *gcp = dateGC1;
- break;
- case 3: XParseGeometry(appResources.datePosition3,xp,yp,&w,&h);
- *gcp = dateGC3;
- break;
- case 12: XParseGeometry(appResources.datePosition12,xp,yp,&w,&h);
- *gcp = dateGC12;
- break;
- }
- }
-
- /* Global so can be called after appointments have changed */
- void
- shadeButton(d,gc,x,y)
- DayButtonData *d;
- GC gc;
- int x,y;
- {
- Arg args[1];
- char text[4];
- int n;
-
- if (gc == (GC)NULL)
- getGCAndXY(numMonths,&gc,&x,&y);
- n = countAppoints(d->day,d->month,d->year);
- XFillRectangle(display,d->pixmap,shadeGC[n],0,0,50,50);
- sprintf(text,"%d",d->day);
- if (appResources.opaqueDates)
- XDrawImageString(display,d->pixmap,gc,x,y,text,strlen(text));
- else
- XDrawString(display,d->pixmap,gc,x,y,text,strlen(text));
- XtSetArg(args[0],XtNbitmap,d->pixmap);
- XtSetValues(d->button,args,ONE);
- }
-
- void
- selectDay(m,day,mon,year)
- MonthFormData *m;
- int day,mon,year;
- {
- int first,i;
-
- first = firstDOW(mon,year);
- for (i=0; i < 42; i++)
- if (i == first+day-1) {
- XawToggleSetCurrent(radioGroup,m->days[i]->button);
- break;
- }
- }
-
- static void
- dayButtonCallbackProc(w,client_data,call_data)
- Widget w;
- caddr_t client_data,call_data;
- {
- DayButtonData *d = (DayButtonData *)client_data;
-
- if (d->day == 0)
- return;
- if (currentDayFormData == NULL)
- currentDayFormData = createPopupDayFormData();
- else
- checkpointAppoints(currentDayFormData);
- currentDayFormData->buttonData = d;
- setDayFormData(currentDayFormData,d->day,d->month,d->year);
- }
-