1 /*******************************************************************************
5 ** $XConsortium: yearglance.c /main/8 1996/11/21 19:43:58 drk $
7 ** RESTRICTED CONFIDENTIAL INFORMATION:
9 ** The information in this document is subject to special
10 ** restrictions in a confidential disclosure agreement between
11 ** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
12 ** document outside HP, IBM, Sun, USL, SCO, or Univel without
13 ** Sun's specific written approval. This document and all copies
14 ** and derivative works thereof must be returned or destroyed at
17 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
19 *******************************************************************************/
22 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
23 * (c) Copyright 1993, 1994 International Business Machines Corp. *
24 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
25 * (c) Copyright 1993, 1994 Novell, Inc. *
29 static char sccsid[] = "@(#)yearglance.c 1.37 95/07/27 Copyr 1991 Sun Microsystems, Inc.";
32 #include <EUSCompat.h>
37 #include <sys/param.h> /* MAXPATHLEN defined here */
39 #include <sys/utsname.h> /* SYS_NMLN */
46 #include <sys/resource.h>
48 #include <netinet/in.h>
53 #include <Xm/ToggleBG.h>
54 #include "MonthPanel.h"
59 #include "x_graphics.h"
60 #include "dayglance.h"
61 #include "weekglance.h"
62 #include "monthglance.h"
63 #include "yearglance.h"
67 #define XOS_USE_XT_LOCKING
68 #define X_INCLUDE_TIME_H
69 #include <X11/Xos_r.h>
71 /* if positioning of months in year view changes this must change too!
72 This specifies row and col for easy selection in year view */
73 int month_row_col[12][2] =
89 extern int prolog_found;
91 extern char *months[];
92 extern char *months2[];
94 static void create_month_panels(Calendar *);
95 static void year_btn_cb(Widget , XtPointer , XtPointer );
96 static void update_year(Calendar *);
97 static void allocator(Calendar *);
98 static void deallocator(Calendar *);
99 static Boolean allocated(Calendar *);
103 * check whether year view is allocated yet
106 allocated(Calendar *c)
108 return (c->view->year_info != NULL);
113 * allocate memory used for year view
116 allocator(Calendar *c)
120 c->view->year_info = (caddr_t) ckalloc(sizeof(Year));
122 y = (Year *)c->view->year_info;
124 (Widget *) ckalloc(12 * sizeof(Widget));
126 /* create the month panel widgets */
127 create_month_panels(c);
132 * release memory used for year view
135 deallocator(Calendar *c)
137 Year *y = (Year *)c->view->year_info;
142 XtDestroyWidget(y->form);
143 XtDestroyWidget(y->label_form);
145 /* Destroy Monthpanels and free space for caching them */
148 XtDestroyWidget(y->month_panels[i]);
151 free(y->month_panels);
153 /* free memory stored in calendar for year stuff */
155 c->view->year_info = NULL;
159 extern CSA_return_code
160 paint_year(Calendar *c)
162 Year *y; /* can't initialize this - may not be alloc'd yet! */
165 return(CSA_E_INVALID_PARAMETER);
167 XmToggleButtonGadgetSetState(c->year_scope, True, False);
170 * Do memory allocation if necessary
175 y = (Year *)c->view->year_info;
177 * update year displayed if it's not 'current'
179 if (y->year_shown != year(c->view->date))
183 * swap in year form if it's not already there
185 XtUnmapWidget(c->canvas);
186 XtManageChild(y->label_form);
187 XtMapWidget(y->label_form);
188 XtManageChild(y->form);
189 XtMapWidget(y->form);
195 * handler for button to switch to year view.
198 year_button (Widget widget, XtPointer data, XtPointer cbs)
200 Calendar *c = calendar;
202 if (c->view->glance == yearGlance)
205 XtUnmapWidget(c->canvas);
207 switch (c->view->glance) {
209 c->view->glance = yearGlance;
210 cleanup_after_dayview(c);
213 c->view->glance = yearGlance;
214 cleanup_after_weekview(c);
217 c->view->glance = yearGlance;
218 cleanup_after_monthview(c);
228 print_std_year_range(int start_year, int end_year)
232 Calendar *c = calendar;
234 if ((xp = x_open_file(c)) == (void *)NULL)
237 n = end_year - start_year + 1;
245 x_init_printer(xp, PORTRAIT);
248 /* print the year at top */
249 x_std_year_name(xp, year);
251 x_print_year(xp, year);
252 x_finish_printer(xp);
260 * Set the panels to the right year/month display
263 update_year(Calendar *c)
267 Year *y = (Year *)c->view->year_info;
268 int year_num = year(c->view->date);
270 _Xltimeparams localtime_buf;
272 /* change year label in yearview */
274 Attention Translator:
276 This string is used in the calendar year view. In the C locale
281 strftime conversion string: "%Y" is used.
283 Use the appropriate strftime conversion for your locale.
285 strftime(buf, 100, catgets(c->DT_catd, 1, 1092, "%Y"),
286 _XLocaltime(&c->view->date, localtime_buf));
287 XtVaGetValues(y->year_label, XmNlabelString, &str, NULL);
289 str = XmStringCreateLocalized(buf);
290 XtVaSetValues(y->year_label, XmNlabelString, str, NULL);
292 /* update each panel */
293 for (i=0; i<12; i++) {
294 XtVaSetValues(y->month_panels[i], XmNyear, year_num,
295 XmNmonth, i+1, NULL);
298 /* record the year that's been displayed */
299 y->year_shown = year_num;
304 * this creates the 3x4 grid of MonthPanel widgets that
305 * make up the year view.
308 create_month_panels(Calendar *c) {
309 Year *y = (Year *)c->view->year_info;
314 * This array holds the relative positioning for panels
315 * in the year view. Each row below is a set of 4 numbers:
316 * top, right, bottom, left. The numbers are used as the
317 * appropriate <side>Position constraints on the MonthPanel
318 * children of the Form. Relies on Form's fractionBase resource
319 * being set up as 100, which is is at create time.
321 static int anchors[] = {
336 static int anchors[] = {
353 * Create a container to replace the old canvas
356 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
357 XtSetArg(al[ac], XmNtopWidget, c->previous); ac++;
358 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
359 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
360 XtSetArg(al[ac], XmNleftOffset, 1); ac++;
361 y->label_form = XmCreateForm(c->form, "labelForm", al, ac);
364 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
365 XtSetArg(al[ac], XmNtopWidget, y->label_form); ac++;
366 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
367 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
368 XtSetArg(al[ac], XmNleftOffset, 1); ac++;
369 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
370 XtSetArg(al[ac], XmNbottomPosition, 95); ac++;
371 y->form = XmCreateForm(c->form, "yearForm", al, ac);
372 XtVaSetValues(c->message_text, XmNtopWidget, y->form, NULL);
373 XtManageChild(y->label_form);
374 XtUnmapWidget(y->label_form);
375 XtManageChild(y->form);
376 XtUnmapWidget(y->form);
378 XtAddCallback(y->form, XmNhelpCallback, (XtCallbackProc)help_cb,
379 (XtPointer) CALENDAR_HELP_YEAR_WINDOW);
382 * Label displaying year for this view
385 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
386 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
387 y->year_label = XmCreateLabel(y->label_form, "yearLabel", al, ac);
388 XtManageChild(y->year_label);
391 * Create 12 monthPanels
393 /* fixed part of arglist */
395 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_POSITION); ac++;
396 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
397 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
398 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION);
400 for (i=0; i<12; i++) {
403 sprintf(name, "panel%d", i+1);
404 ac=4; /* start adding after fixed part */
405 XtSetArg(al[ac], XmNtopPosition, anchors[4*i]); ac++;
406 XtSetArg(al[ac], XmNrightPosition, anchors[4*i+1]); ac++;
407 XtSetArg(al[ac], XmNbottomPosition, anchors[4*i+2]); ac++;
408 XtSetArg(al[ac], XmNleftPosition, anchors[4*i+3]); ac++;
409 XtSetArg(al[ac], XmNwidth, 150); ac++;
410 XtSetArg(al[ac], XmNheight, 100); ac++;
411 y->month_panels[i] = XmCreateMonthPanel(y->form, name, al, ac);
412 XtAddCallback(y->month_panels[i], XmNactivateCallback,
413 year_btn_cb, (XtPointer) c);
415 XtManageChildren(y->month_panels, 12);
419 * This is the callback for all the buttons on the month
420 * panels. It figures out what was pressed, and invokes
421 * the appropriate function.
424 year_btn_cb(Widget w, XtPointer client, XtPointer call)
426 XmMonthPanelCallbackStruct *cbs = (XmMonthPanelCallbackStruct *) call;
427 Calendar *c = (Calendar *)client;
430 XtVaGetValues(w, XmNmonth, &monthno, XmNyear, &year, NULL);
432 if (cbs->type == MONTH_SELECTION) {
435 * if month chosen is not current month
436 * set date to 1st of new month, otherwise
439 if (month(c->view->date) != monthno) {
440 calendar_deselect (c);
441 c->view->olddate = c->view->date;
442 c->view->date = monthdayyear(monthno, 1, year);
443 c->view->nwks = numwks(c->view->date);
444 calendar_select (c, monthSelect, NULL);
448 /* switch to month view */
449 cleanup_after_yearview(c);
450 c->view->glance = monthGlance;
451 prepare_to_paint_monthview(c, NULL);
452 XtMapWidget(c->canvas);
454 else { /* type == DAY_SELECTION */
455 c->view->olddate = c->view->date;
456 c->view->date = monthdayyear(monthno, cbs->day, year);
457 cleanup_after_yearview(c);
459 c->view->glance = dayGlance;
461 (void)init_dayview(c);
463 XtMapWidget(c->canvas);
469 cleanup_after_yearview(Calendar *c)
471 Year *y = (Year *)c->view->year_info;
475 XtUnmapWidget(y->form);
476 XtUnmapWidget(y->label_form);
478 /* Unmanaging the form is necessary to keep the stupid
479 traversal order right */
481 XtUnmanageChild(y->form);
482 XtUnmanageChild(y->label_form);
483 XmProcessTraversal(c->appt_btn, XmTRAVERSE_CURRENT);
485 XmToggleButtonGadgetSetState(c->year_scope, False, False);
488 * Reclaim year view memory. You should comment this out
489 * if rendering performance is more important than
490 * minimizing memory usage. It saves 400 *dget instances
491 * lying around when they may never be needed again, but
492 * at the expense of recreating them if they are needed.