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
91 #include <X11/Xos_r.h>
93 /* if positioning of months in year view changes this must change too!
94 This specifies row and col for easy selection in year view */
95 int month_row_col[12][2] =
111 extern int prolog_found;
113 extern char *months[];
114 extern char *months2[];
116 static void create_month_panels(Calendar *);
117 static void year_btn_cb(Widget , XtPointer , XtPointer );
118 static void update_year(Calendar *);
119 static void allocator(Calendar *);
120 static void deallocator(Calendar *);
121 static Boolean allocated(Calendar *);
125 * check whether year view is allocated yet
128 allocated(Calendar *c)
130 return (c->view->year_info != NULL);
135 * allocate memory used for year view
138 allocator(Calendar *c)
142 c->view->year_info = (caddr_t) ckalloc(sizeof(Year));
144 y = (Year *)c->view->year_info;
146 (Widget *) ckalloc(12 * sizeof(Widget));
148 /* create the month panel widgets */
149 create_month_panels(c);
154 * release memory used for year view
157 deallocator(Calendar *c)
159 Year *y = (Year *)c->view->year_info;
164 XtDestroyWidget(y->form);
165 XtDestroyWidget(y->label_form);
167 /* Destroy Monthpanels and free space for caching them */
170 XtDestroyWidget(y->month_panels[i]);
173 free(y->month_panels);
175 /* free memory stored in calendar for year stuff */
177 c->view->year_info = NULL;
181 extern CSA_return_code
182 paint_year(Calendar *c)
184 Year *y; /* can't initialize this - may not be alloc'd yet! */
187 return(CSA_E_INVALID_PARAMETER);
189 XmToggleButtonGadgetSetState(c->year_scope, True, False);
192 * Do memory allocation if necessary
197 y = (Year *)c->view->year_info;
199 * update year displayed if it's not 'current'
201 if (y->year_shown != year(c->view->date))
205 * swap in year form if it's not already there
207 XtUnmapWidget(c->canvas);
208 XtManageChild(y->label_form);
209 XtMapWidget(y->label_form);
210 XtManageChild(y->form);
211 XtMapWidget(y->form);
217 * handler for button to switch to year view.
220 year_button (Widget widget, XtPointer data, XtPointer cbs)
222 Calendar *c = calendar;
224 if (c->view->glance == yearGlance)
227 XtUnmapWidget(c->canvas);
229 switch (c->view->glance) {
231 c->view->glance = yearGlance;
232 cleanup_after_dayview(c);
235 c->view->glance = yearGlance;
236 cleanup_after_weekview(c);
239 c->view->glance = yearGlance;
240 cleanup_after_monthview(c);
250 print_std_year_range(int start_year, int end_year)
254 Calendar *c = calendar;
256 if ((xp = x_open_file(c)) == (void *)NULL)
259 n = end_year - start_year + 1;
267 x_init_printer(xp, PORTRAIT);
270 /* print the year at top */
271 x_std_year_name(xp, year);
273 x_print_year(xp, year);
274 x_finish_printer(xp);
282 * Set the panels to the right year/month display
285 update_year(Calendar *c)
289 Year *y = (Year *)c->view->year_info;
290 int year_num = year(c->view->date);
292 _Xltimeparams localtime_buf;
294 /* change year label in yearview */
296 Attention Translator:
298 This string is used in the calendar year view. In the C locale
303 strftime conversion string: "%Y" is used.
305 Use the appropriate strftime conversion for your locale.
307 strftime(buf, 100, catgets(c->DT_catd, 1, 1092, "%Y"),
308 _XLocaltime(&c->view->date, localtime_buf));
309 XtVaGetValues(y->year_label, XmNlabelString, &str, NULL);
311 str = XmStringCreateLocalized(buf);
312 XtVaSetValues(y->year_label, XmNlabelString, str, NULL);
314 /* update each panel */
315 for (i=0; i<12; i++) {
316 XtVaSetValues(y->month_panels[i], XmNyear, year_num,
317 XmNmonth, i+1, NULL);
320 /* record the year that's been displayed */
321 y->year_shown = year_num;
326 * this creates the 3x4 grid of MonthPanel widgets that
327 * make up the year view.
330 create_month_panels(Calendar *c) {
331 Year *y = (Year *)c->view->year_info;
336 * This array holds the relative positioning for panels
337 * in the year view. Each row below is a set of 4 numbers:
338 * top, right, bottom, left. The numbers are used as the
339 * appropriate <side>Position constraints on the MonthPanel
340 * children of the Form. Relies on Form's fractionBase resource
341 * being set up as 100, which is is at create time.
343 static int anchors[] = {
358 static int anchors[] = {
375 * Create a container to replace the old canvas
378 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
379 XtSetArg(al[ac], XmNtopWidget, c->previous); ac++;
380 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
381 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
382 XtSetArg(al[ac], XmNleftOffset, 1); ac++;
383 y->label_form = XmCreateForm(c->form, "labelForm", al, ac);
386 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
387 XtSetArg(al[ac], XmNtopWidget, y->label_form); ac++;
388 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
389 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
390 XtSetArg(al[ac], XmNleftOffset, 1); ac++;
391 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
392 XtSetArg(al[ac], XmNbottomPosition, 95); ac++;
393 y->form = XmCreateForm(c->form, "yearForm", al, ac);
394 XtVaSetValues(c->message_text, XmNtopWidget, y->form, NULL);
395 XtManageChild(y->label_form);
396 XtUnmapWidget(y->label_form);
397 XtManageChild(y->form);
398 XtUnmapWidget(y->form);
400 XtAddCallback(y->form, XmNhelpCallback, (XtCallbackProc)help_cb,
401 (XtPointer) CALENDAR_HELP_YEAR_WINDOW);
404 * Label displaying year for this view
407 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
408 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
409 y->year_label = XmCreateLabel(y->label_form, "yearLabel", al, ac);
410 XtManageChild(y->year_label);
413 * Create 12 monthPanels
415 /* fixed part of arglist */
417 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_POSITION); ac++;
418 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
419 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
420 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION);
422 for (i=0; i<12; i++) {
425 sprintf(name, "panel%d", i+1);
426 ac=4; /* start adding after fixed part */
427 XtSetArg(al[ac], XmNtopPosition, anchors[4*i]); ac++;
428 XtSetArg(al[ac], XmNrightPosition, anchors[4*i+1]); ac++;
429 XtSetArg(al[ac], XmNbottomPosition, anchors[4*i+2]); ac++;
430 XtSetArg(al[ac], XmNleftPosition, anchors[4*i+3]); ac++;
431 XtSetArg(al[ac], XmNwidth, 150); ac++;
432 XtSetArg(al[ac], XmNheight, 100); ac++;
433 y->month_panels[i] = XmCreateMonthPanel(y->form, name, al, ac);
434 XtAddCallback(y->month_panels[i], XmNactivateCallback,
435 year_btn_cb, (XtPointer) c);
437 XtManageChildren(y->month_panels, 12);
441 * This is the callback for all the buttons on the month
442 * panels. It figures out what was pressed, and invokes
443 * the appropriate function.
446 year_btn_cb(Widget w, XtPointer client, XtPointer call)
448 XmMonthPanelCallbackStruct *cbs = (XmMonthPanelCallbackStruct *) call;
449 Calendar *c = (Calendar *)client;
452 XtVaGetValues(w, XmNmonth, &monthno, XmNyear, &year, NULL);
454 if (cbs->type == MONTH_SELECTION) {
457 * if month chosen is not current month
458 * set date to 1st of new month, otherwise
461 if (month(c->view->date) != monthno) {
462 calendar_deselect (c);
463 c->view->olddate = c->view->date;
464 c->view->date = monthdayyear(monthno, 1, year);
465 c->view->nwks = numwks(c->view->date);
466 calendar_select (c, monthSelect, NULL);
470 /* switch to month view */
471 cleanup_after_yearview(c);
472 c->view->glance = monthGlance;
473 prepare_to_paint_monthview(c, NULL);
474 XtMapWidget(c->canvas);
476 else { /* type == DAY_SELECTION */
477 c->view->olddate = c->view->date;
478 c->view->date = monthdayyear(monthno, cbs->day, year);
479 cleanup_after_yearview(c);
481 c->view->glance = dayGlance;
483 (void)init_dayview(c);
485 XtMapWidget(c->canvas);
491 cleanup_after_yearview(Calendar *c)
493 Year *y = (Year *)c->view->year_info;
497 XtUnmapWidget(y->form);
498 XtUnmapWidget(y->label_form);
500 /* Unmanaging the form is necessary to keep the stupid
501 traversal order right */
503 XtUnmanageChild(y->form);
504 XtUnmanageChild(y->label_form);
505 XmProcessTraversal(c->appt_btn, XmTRAVERSE_CURRENT);
507 XmToggleButtonGadgetSetState(c->year_scope, False, False);
510 * Reclaim year view memory. You should comment this out
511 * if rendering performance is more important than
512 * minimizing memory usage. It saves 400 *dget instances
513 * lying around when they may never be needed again, but
514 * at the expense of recreating them if they are needed.