2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*******************************************************************************
27 ** $XConsortium: yearglance.c /main/8 1996/11/21 19:43:58 drk $
29 ** RESTRICTED CONFIDENTIAL INFORMATION:
31 ** The information in this document is subject to special
32 ** restrictions in a confidential disclosure agreement between
33 ** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 ** document outside HP, IBM, Sun, USL, SCO, or Univel without
35 ** Sun's specific written approval. This document and all copies
36 ** and derivative works thereof must be returned or destroyed at
39 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
41 *******************************************************************************/
44 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
45 * (c) Copyright 1993, 1994 International Business Machines Corp. *
46 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
47 * (c) Copyright 1993, 1994 Novell, Inc. *
51 static char sccsid[] = "@(#)yearglance.c 1.37 95/07/27 Copyr 1991 Sun Microsystems, Inc.";
54 #include <EUSCompat.h>
59 #include <sys/param.h> /* MAXPATHLEN defined here */
61 #include <sys/utsname.h> /* SYS_NMLN */
68 #include <sys/resource.h>
70 #include <netinet/in.h>
75 #include <Xm/ToggleBG.h>
76 #include "MonthPanel.h"
81 #include "x_graphics.h"
82 #include "dayglance.h"
83 #include "weekglance.h"
84 #include "monthglance.h"
85 #include "yearglance.h"
89 #define XOS_USE_XT_LOCKING
90 #define X_INCLUDE_TIME_H
94 #include <X11/Xos_r.h>
96 /* if positioning of months in year view changes this must change too!
97 This specifies row and col for easy selection in year view */
98 int month_row_col[12][2] =
114 extern int prolog_found;
116 extern char *months[];
117 extern char *months2[];
119 static void create_month_panels(Calendar *);
120 static void year_btn_cb(Widget , XtPointer , XtPointer );
121 static void update_year(Calendar *);
122 static void allocator(Calendar *);
123 static void deallocator(Calendar *);
124 static Boolean allocated(Calendar *);
128 * check whether year view is allocated yet
131 allocated(Calendar *c)
133 return (c->view->year_info != NULL);
138 * allocate memory used for year view
141 allocator(Calendar *c)
145 c->view->year_info = (caddr_t) ckalloc(sizeof(Year));
147 y = (Year *)c->view->year_info;
149 (Widget *) ckalloc(12 * sizeof(Widget));
151 /* create the month panel widgets */
152 create_month_panels(c);
157 * release memory used for year view
160 deallocator(Calendar *c)
162 Year *y = (Year *)c->view->year_info;
167 XtDestroyWidget(y->form);
168 XtDestroyWidget(y->label_form);
170 /* Destroy Monthpanels and free space for caching them */
173 XtDestroyWidget(y->month_panels[i]);
176 free(y->month_panels);
178 /* free memory stored in calendar for year stuff */
180 c->view->year_info = NULL;
184 extern CSA_return_code
185 paint_year(Calendar *c)
187 Year *y; /* can't initialize this - may not be alloc'd yet! */
190 return(CSA_E_INVALID_PARAMETER);
192 XmToggleButtonGadgetSetState(c->year_scope, True, False);
195 * Do memory allocation if necessary
200 y = (Year *)c->view->year_info;
202 * update year displayed if it's not 'current'
204 if (y->year_shown != year(c->view->date))
208 * swap in year form if it's not already there
210 XtUnmapWidget(c->canvas);
211 XtManageChild(y->label_form);
212 XtMapWidget(y->label_form);
213 XtManageChild(y->form);
214 XtMapWidget(y->form);
220 * handler for button to switch to year view.
223 year_button (Widget widget, XtPointer data, XtPointer cbs)
225 Calendar *c = calendar;
227 if (c->view->glance == yearGlance)
230 XtUnmapWidget(c->canvas);
232 switch (c->view->glance) {
234 c->view->glance = yearGlance;
235 cleanup_after_dayview(c);
238 c->view->glance = yearGlance;
239 cleanup_after_weekview(c);
242 c->view->glance = yearGlance;
243 cleanup_after_monthview(c);
253 print_std_year_range(int start_year, int end_year)
257 Calendar *c = calendar;
259 if ((xp = x_open_file(c)) == (void *)NULL)
262 n = end_year - start_year + 1;
270 x_init_printer(xp, PORTRAIT);
273 /* print the year at top */
274 x_std_year_name(xp, year);
276 x_print_year(xp, year);
277 x_finish_printer(xp);
285 * Set the panels to the right year/month display
288 update_year(Calendar *c)
292 Year *y = (Year *)c->view->year_info;
293 int year_num = year(c->view->date);
295 _Xltimeparams localtime_buf;
297 /* change year label in yearview */
299 Attention Translator:
301 This string is used in the calendar year view. In the C locale
306 strftime conversion string: "%Y" is used.
308 Use the appropriate strftime conversion for your locale.
310 strftime(buf, 100, catgets(c->DT_catd, 1, 1092, "%Y"),
311 _XLocaltime(&c->view->date, localtime_buf));
312 XtVaGetValues(y->year_label, XmNlabelString, &str, NULL);
314 str = XmStringCreateLocalized(buf);
315 XtVaSetValues(y->year_label, XmNlabelString, str, NULL);
317 /* update each panel */
318 for (i=0; i<12; i++) {
319 XtVaSetValues(y->month_panels[i], XmNyear, year_num,
320 XmNmonth, i+1, NULL);
323 /* record the year that's been displayed */
324 y->year_shown = year_num;
329 * this creates the 3x4 grid of MonthPanel widgets that
330 * make up the year view.
333 create_month_panels(Calendar *c) {
334 Year *y = (Year *)c->view->year_info;
339 * This array holds the relative positioning for panels
340 * in the year view. Each row below is a set of 4 numbers:
341 * top, right, bottom, left. The numbers are used as the
342 * appropriate <side>Position constraints on the MonthPanel
343 * children of the Form. Relies on Form's fractionBase resource
344 * being set up as 100, which is is at create time.
346 static int anchors[] = {
361 static int anchors[] = {
378 * Create a container to replace the old canvas
381 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
382 XtSetArg(al[ac], XmNtopWidget, c->previous); ac++;
383 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
384 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
385 XtSetArg(al[ac], XmNleftOffset, 1); ac++;
386 y->label_form = XmCreateForm(c->form, "labelForm", al, ac);
389 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
390 XtSetArg(al[ac], XmNtopWidget, y->label_form); ac++;
391 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
392 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
393 XtSetArg(al[ac], XmNleftOffset, 1); ac++;
394 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
395 XtSetArg(al[ac], XmNbottomPosition, 95); ac++;
396 y->form = XmCreateForm(c->form, "yearForm", al, ac);
397 XtVaSetValues(c->message_text, XmNtopWidget, y->form, NULL);
398 XtManageChild(y->label_form);
399 XtUnmapWidget(y->label_form);
400 XtManageChild(y->form);
401 XtUnmapWidget(y->form);
403 XtAddCallback(y->form, XmNhelpCallback, (XtCallbackProc)help_cb,
404 (XtPointer) CALENDAR_HELP_YEAR_WINDOW);
407 * Label displaying year for this view
410 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
411 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
412 y->year_label = XmCreateLabel(y->label_form, "yearLabel", al, ac);
413 XtManageChild(y->year_label);
416 * Create 12 monthPanels
418 /* fixed part of arglist */
420 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_POSITION); ac++;
421 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
422 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
423 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION);
425 for (i=0; i<12; i++) {
428 sprintf(name, "panel%d", i+1);
429 ac=4; /* start adding after fixed part */
430 XtSetArg(al[ac], XmNtopPosition, anchors[4*i]); ac++;
431 XtSetArg(al[ac], XmNrightPosition, anchors[4*i+1]); ac++;
432 XtSetArg(al[ac], XmNbottomPosition, anchors[4*i+2]); ac++;
433 XtSetArg(al[ac], XmNleftPosition, anchors[4*i+3]); ac++;
434 XtSetArg(al[ac], XmNwidth, 150); ac++;
435 XtSetArg(al[ac], XmNheight, 100); ac++;
436 y->month_panels[i] = XmCreateMonthPanel(y->form, name, al, ac);
437 XtAddCallback(y->month_panels[i], XmNactivateCallback,
438 year_btn_cb, (XtPointer) c);
440 XtManageChildren(y->month_panels, 12);
444 * This is the callback for all the buttons on the month
445 * panels. It figures out what was pressed, and invokes
446 * the appropriate function.
449 year_btn_cb(Widget w, XtPointer client, XtPointer call)
451 XmMonthPanelCallbackStruct *cbs = (XmMonthPanelCallbackStruct *) call;
452 Calendar *c = (Calendar *)client;
455 XtVaGetValues(w, XmNmonth, &monthno, XmNyear, &year, NULL);
457 if (cbs->type == MONTH_SELECTION) {
460 * if month chosen is not current month
461 * set date to 1st of new month, otherwise
464 if (month(c->view->date) != monthno) {
465 calendar_deselect (c);
466 c->view->olddate = c->view->date;
467 c->view->date = monthdayyear(monthno, 1, year);
468 c->view->nwks = numwks(c->view->date);
469 calendar_select (c, monthSelect, NULL);
473 /* switch to month view */
474 cleanup_after_yearview(c);
475 c->view->glance = monthGlance;
476 prepare_to_paint_monthview(c, NULL);
477 XtMapWidget(c->canvas);
479 else { /* type == DAY_SELECTION */
480 c->view->olddate = c->view->date;
481 c->view->date = monthdayyear(monthno, cbs->day, year);
482 cleanup_after_yearview(c);
484 c->view->glance = dayGlance;
486 (void)init_dayview(c);
488 XtMapWidget(c->canvas);
494 cleanup_after_yearview(Calendar *c)
496 Year *y = (Year *)c->view->year_info;
500 XtUnmapWidget(y->form);
501 XtUnmapWidget(y->label_form);
503 /* Unmanaging the form is necessary to keep the stupid
504 traversal order right */
506 XtUnmanageChild(y->form);
507 XtUnmanageChild(y->label_form);
508 XmProcessTraversal(c->appt_btn, XmTRAVERSE_CURRENT);
510 XmToggleButtonGadgetSetState(c->year_scope, False, False);
513 * Reclaim year view memory. You should comment this out
514 * if rendering performance is more important than
515 * minimizing memory usage. It saves 400 *dget instances
516 * lying around when they may never be needed again, but
517 * at the expense of recreating them if they are needed.