1 /*******************************************************************************
5 ** $XConsortium: dayglance.c /main/10 1996/11/21 19:42:19 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[] = "@(#)dayglance.c 1.76 95/04/24 Copyr 1991 Sun Microsystems, Inc.";
32 #include <EUSCompat.h>
37 #include <Xm/ToggleBG.h>
38 #include <Dt/HourGlass.h>
43 #include "datefield.h"
46 #include "x_graphics.h"
48 #include "weekglance.h"
49 #include "monthglance.h"
50 #include "yearglance.h"
51 #include "MonthPanel.h"
54 #include "dayglance.h"
58 #include "group_editor.h"
60 #define XOS_USE_XT_LOCKING
61 #define X_INCLUDE_TIME_H
62 #include <X11/Xos_r.h>
67 /* private function prototypes */
68 static Boolean _print_day(Calendar*, int, void *,
69 Tick, Props*, Boolean);
70 static void day_btn_cb(Widget, XtPointer, XtPointer);
71 static void create_month_panels(Calendar *);
72 static void display_monthpanels(Calendar *);
73 static void update_quarter(Calendar *);
74 static Boolean in_moboxes(Calendar *, int, int);
76 #define INSIDE_MARGIN 6
79 paint_day_header(Calendar *c, Tick date, void *rect)
81 Props *p = (Props*)c->properties;
82 OrderingType ot = get_int_prop(p, CP_DATEORDERING);
85 Boolean inrange = False;
87 Pixel foreground_pixel;
88 XFontSetExtents fontextents;
90 _Xltimeparams localtime_buf;
92 tm = _XLocaltime(&date, localtime_buf);
94 CalFontExtents(c->fonts->labelfont, &fontextents);
95 pfy = fontextents.max_logical_extent.height;
96 XtVaGetValues(c->canvas, XmNcolormap, &cmap, NULL);
97 XtVaGetValues(c->canvas, XmNforeground, &foreground_pixel, NULL);
100 Attention Translator:
102 This string is used in the calendar day view. In the C locale
105 Monday, January 16, 1995
107 strftime conversion string: "%A, %B %e, %Y" is used.
109 Use the appropriate strftime conversion for your locale.
111 strftime(buf, 100, catgets(c->DT_catd, 1, 992, "%A, %B %e, %Y"), tm);
112 inrange = today_inrange(c, date);
113 x = gr_center(c->view->winw-(int)MOBOX_AREA_WIDTH, buf,
114 c->fonts->labelfont) + (int)MOBOX_AREA_WIDTH;
115 if (c->xcontext->screen_depth >= 8 && inrange)
116 gr_text_rgb(c->xcontext, x, c->view->topoffset - (pfy/2),
117 c->fonts->labelfont, buf, foreground_pixel,
120 gr_text(c->xcontext, x, c->view->topoffset - (pfy/2),
121 c->fonts->labelfont, buf, rect);
131 paint_dayview_appts(Calendar *c, Paint_cache *cache, int a_total, void *rect)
133 int w = c->view->boxw;
134 int h = c->view->boxh;
135 int begin_time, end_time;
136 int x, x2, y, y2, num_hrs, i, last_hr, hr, x_off;
137 Cal_Font *pf = c->fonts->boldfont;
138 Cal_Font *pf2 = c->fonts->viewfont;
139 XFontSetExtents fontextents;
140 XFontSetExtents fontextents2;
141 Props *p = (Props*)c->properties;
143 char buf[5], *appt_str;
144 int pfy, curr_line, maxlines;
145 Lines *lines = NULL, *headlines = NULL;
149 Tick start_tick, end_tick;
150 int nop, hrbox_margin;
152 CalFontExtents(pf, &fontextents);
153 CalFontExtents(pf2, &fontextents2);
156 XtVaGetValues(c->canvas, XmNcolormap, &cmap, XmNforeground, &fg, NULL);
158 /* draw horizontal lines */
159 begin_time = get_int_prop(p, CP_DAYBEGIN);
160 end_time = get_int_prop(p, CP_DAYEND);
161 disp_t = get_int_prop(p, CP_DEFAULTDISP);
162 num_hrs = end_time - begin_time + 1;
164 if (disp_t == HOUR12)
165 CalTextExtents(pf, "12pm", 4, &nop, &nop, &hrbox_margin, &nop);
167 CalTextExtents(pf, "24 ", 3, &nop, &nop, &hrbox_margin, &nop);
169 x = MOBOX_AREA_WIDTH+2;
171 y = c->view->topoffset;
172 for (i = 0; i <= num_hrs; i++) {
173 gr_draw_line(c->xcontext, x, y, x2, y, gr_solid, rect);
176 /* draw vertical line */
177 y = c->view->topoffset;
178 y2 = y + num_hrs * h;
180 gr_draw_line(c->xcontext, x, y, x, y2, gr_solid, rect);
182 x = MOBOX_AREA_WIDTH+3;
186 for (i = begin_time - 1; i < end_time; i++) {
189 (void) sprintf(buf, "");
190 else if (disp_t == HOUR12) {
191 am = adjust_hour(&hr);
192 (void) sprintf(buf, "%d%s", hr, am ? "a" : "p");
195 (void) sprintf(buf, "%02d", hr);
196 x_off = gr_center(hrbox_margin, buf, pf);
198 /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb]
199 if (c->xcontext->screen_depth >= 8)
200 gr_text_rgb(c->xcontext, x+x_off, y, pf,
201 buf, fg, cmap, rect);
204 gr_text(c->xcontext, x+x_off, y, pf, buf, rect);
209 /* draw in appointments */
211 x = MOBOX_AREA_WIDTH + hrbox_margin + 6;
212 pfy = fontextents2.max_logical_extent.height;
214 maxlines = (h - 6) / pfy;
215 curr_line = last_hr = 0;
217 /* loop thru, getting out the "no time" appointments */
219 for (i = 0; i < a_total; i++) {
223 if (cache[i].show_time == 0) {
224 if (last_hr != hr) curr_line = 0;
225 y = c->view->topoffset + 2 + pfy;
226 if (curr_line < maxlines) {
227 y += (curr_line * pfy) + h * (hr - begin_time);
228 headlines = lines = text_to_lines(cache[i].summary, 4);
230 start_tick = cache[i].start_time;
231 end_tick = cache[i].end_time;
232 if (lines != NULL && lines->s != NULL) {
233 appt_str = ckalloc(cm_strlen(lines->s)+18);
234 format_line(start_tick, lines->s,
236 cache[i].show_time, disp_t);
240 appt_str = ckalloc(15);
241 format_line(start_tick, (char*)NULL,
243 cache[i].show_time, disp_t);
245 appt_str[cm_strlen(appt_str)]=NULL;
247 /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb]
248 if (c->xcontext->screen_depth >= 8)
249 gr_text_rgb(c->xcontext, x, y,
250 pf2, appt_str, fg, cmap, rect);
253 gr_text(c->xcontext, x, y,
254 pf2, appt_str, rect);
256 free(appt_str); appt_str = NULL;
258 if (curr_line < maxlines && lines != NULL) {
259 appt_str = ckalloc(324);
260 cm_strcpy(appt_str, " ");
261 while (lines != NULL) {
262 if (lines->s != NULL)
263 cm_strcat(appt_str, lines->s);
265 if (lines != NULL && lines->s != NULL)
266 cm_strcat(appt_str, " - ");
270 /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb]
272 if (c->xcontext->screen_depth >= 8)
273 gr_text_rgb(c->xcontext, x, y,
278 gr_text(c->xcontext, x, y,
279 pf2, appt_str, rect);
282 free(appt_str); appt_str = NULL;
284 destroy_lines(headlines); lines=NULL;
289 for (i = 0; i < a_total; i++) {
293 start_tick = cache[i].start_time;
294 end_tick = cache[i].end_time;
295 hr = hour(start_tick);
296 if (hr >= begin_time && hr < end_time && (cache[i].show_time && !magic_time(start_tick))) {
297 if (last_hr != hr) curr_line = 0;
298 y = c->view->topoffset + 2 + pfy;
299 if (curr_line < maxlines) {
300 y += (curr_line * pfy) + h * (hr - begin_time + 1);
301 headlines = lines = text_to_lines(cache[i].summary, 4);
302 if (lines != NULL && lines->s != NULL) {
303 appt_str = ckalloc(cm_strlen(lines->s)+18);
304 format_line(start_tick, lines->s,
306 cache[i].show_time, disp_t);
310 appt_str = ckalloc(15);
311 format_line(start_tick, (char*)NULL,
313 cache[i].show_time, disp_t);
315 appt_str[cm_strlen(appt_str)]=NULL;
317 /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb]
318 if (c->xcontext->screen_depth >= 8)
319 gr_text_rgb(c->xcontext, x, y,
320 pf2, appt_str, fg, cmap, rect);
323 gr_text(c->xcontext, x, y,
324 pf2, appt_str, rect);
326 free(appt_str); appt_str = NULL;
328 if (curr_line < maxlines && lines != NULL) {
329 appt_str = ckalloc(324);
330 cm_strcpy(appt_str, " ");
331 while (lines != NULL) {
332 if (lines->s != NULL)
333 cm_strcat(appt_str, lines->s);
335 if (lines != NULL && lines->s != NULL)
336 cm_strcat(appt_str, " - ");
340 /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb]
342 if (c->xcontext->screen_depth >= 8)
343 gr_text_rgb(c->xcontext, x, y,
348 gr_text(c->xcontext, x, y,
349 pf2, appt_str, rect);
352 free(appt_str); appt_str = NULL;
354 destroy_lines(headlines); lines=NULL;
363 Day *day_info = (Day *)c->view->day_info;
364 day_info->month1 = previousmonth(c->view->date);
365 day_info->month2 = c->view->date;
366 day_info->month3 = nextmonth(c->view->date);
370 init_dayview(Calendar *c)
372 int tot_rows, wks_1, wks_2, wks_3;
374 Day *day_info = (Day *) c->view->day_info;
377 * Create month panels if they're not already there
379 if (day_info->month_panels == (Widget *) NULL) {
380 day_info->month_panels = (Widget *)ckalloc(3 * sizeof(Widget));
382 create_month_panels(c);
386 XtVaGetValues(c->canvas, XmNwidth, &w, XmNheight, &h, NULL);
387 (void)cache_dims(c, w, h);
389 day_info->day_selected = -1;
390 day_info->mobox_width = (int)MOBOX_AREA_WIDTH -
391 2*c->view->outside_margin;
392 /* col width of day number in month boxes */
394 (day_info->mobox_width-INSIDE_MARGIN*2)/7;
395 /* width of all of the month boxes */
396 day_info->mobox_width = 7 * day_info->col_w +
399 wks_1 = numwks(day_info->month1);
400 wks_2 = numwks(day_info->month2);
401 wks_3 = numwks(day_info->month3);
402 /* total rows in three months */
403 tot_rows = wks_1 + wks_2 + wks_3 + 3;
405 /* row height of day number in month boxes */
406 day_info->row_h = (c->view->winh - 3*c->view->topoffset-c->view->outside_margin)
409 /* height of 1st month */
410 day_info->mobox_height1 = day_info->row_h *
412 /* height of 2nd month */
413 day_info->mobox_height2 = day_info->row_h *
415 /* height of 2rd month */
416 day_info->mobox_height3 = day_info->row_h *
419 day_info->month1_y = c->view->topoffset;
420 day_info->month2_y = 2*c->view->topoffset +
421 day_info->mobox_height1;
422 day_info->month3_y = 3*c->view->topoffset +
423 day_info->mobox_height1 +
424 day_info->mobox_height2;
425 ((Selection*)(c->view->current_selection))->row = 0;
429 monthbox_xytodate(Calendar *c, int x, int y)
432 Day *day_info = (Day *)c->view->day_info;
433 XFontSetExtents fontextents;
435 int col_w = day_info->col_w;
436 int row_h = day_info->row_h;
438 int day_selected, tmpx;
440 CalFontExtents(c->fonts->labelfont, &fontextents);
441 pfy = fontextents.max_ink_extent.height;
443 col = (x-c->view->outside_margin-INSIDE_MARGIN) / col_w;
445 tmpx = c->view->outside_margin + INSIDE_MARGIN + col * col_w;
447 if (y < (day_info->month1_y +
448 day_info->mobox_height1)) {
449 row = (y-day_info->month1_y-row_h) / row_h;
450 day_selected = (7 * (row+1)) - fdom(day_info->month1)
452 if (day_selected <= 0 || day_selected >
453 monthlength(day_info->month1))
455 day_info->day_selected = day_selected;
456 day_info->day_selected_y =
457 day_info->month1_y + (row+1)*row_h;
458 c->view->olddate = c->view->date;
459 c->view->date = next_ndays(first_dom(day_info->month1),
460 day_info->day_selected);
462 else if (y < (day_info->month2_y +
463 day_info->mobox_height2)) {
464 row = (y-day_info->month2_y-row_h) / row_h;
465 day_selected = (7 * (row+1)) - fdom(day_info->month2)
467 if (day_selected <= 0 || day_selected >
468 monthlength(day_info->month2))
470 day_info->day_selected = day_selected;
471 day_info->day_selected_y =
472 day_info->month2_y + (row+1)*row_h;
473 c->view->olddate = c->view->date;
474 c->view->date = next_ndays(first_dom(day_info->month2),
475 day_info->day_selected);
477 else if (y < (day_info->month3_y +
478 day_info->mobox_height3)) {
479 row = (y-day_info->month3_y-row_h) / row_h;
480 day_selected = (7 * (row+1)) - fdom(day_info->month3)
482 if (day_selected <= 0 || day_selected >
483 monthlength(day_info->month3))
485 day_info->day_selected = day_selected;
486 day_info->day_selected_y =
487 day_info->month3_y + (row+1)*row_h;
488 c->view->olddate = c->view->date;
489 c->view->date = next_ndays(first_dom(day_info->month3),
490 day_info->day_selected);
492 day_info->day_selected_x = tmpx;
493 sprintf(str, "%d", day_info->day_selected);
494 x_off = gr_center(col_w, str, c->fonts->labelfont);
495 day_info->day_selected_x2 =
496 day_info->day_selected_x+x_off;
497 day_info->day_selected_y2 =
498 day_info->day_selected_y + pfy;
503 monthbox_datetoxy(Calendar *c)
506 int week, x_off, dayw, daym, mo;
507 Day *day_info = (Day *) c->view->day_info;
508 XFontSetExtents fontextents;
510 int col_w = day_info->col_w;
511 int row_h = day_info->row_h;
513 _Xltimeparams localtime_buf;
515 CalFontExtents(c->fonts->labelfont, &fontextents);
516 pfy = fontextents.max_logical_extent.height;
518 tm = *_XLocaltime(&c->view->date, localtime_buf);
522 week = (12+tm.tm_mday-tm.tm_wday)/7;
523 day_info->day_selected_x = c->view->outside_margin +
524 INSIDE_MARGIN + col_w*dayw;
526 if (mo == month(day_info->month1))
527 day_info->day_selected_y =
530 else if (mo == month(day_info->month2))
531 day_info->day_selected_y =
534 else if (mo == month(day_info->month3))
535 day_info->day_selected_y =
538 sprintf(str, "%d", daym);
539 x_off = gr_center(col_w, str, c->fonts->labelfont);
540 day_info->day_selected_x2 =
541 day_info->day_selected_x+x_off;
542 day_info->day_selected_y2 =
543 day_info->day_selected_y + pfy;
544 day_info->day_selected = daym;
548 in_moboxes(Calendar *c, int x, int y)
550 int margin = c->view->outside_margin;
551 int topoff = c->view->topoffset;
552 Boolean in_mobox = False;
553 Day *day_info = (Day *)c->view->day_info;
554 int row_h = day_info->row_h;
556 if (x < (MOBOX_AREA_WIDTH-margin-2*INSIDE_MARGIN) &&
557 x > margin && y > topoff &&
558 ( (y < (day_info->month3_y+
559 day_info->mobox_height3) &&
560 y > (day_info->month3_y+row_h)) ||
561 (y < (day_info->month2_y+
562 day_info->mobox_height2) &&
563 y > (day_info->month2_y+row_h)) ||
564 (y < (day_info->month1_y+
565 day_info->mobox_height1) &&
566 y > day_info->month1_y+row_h) ) )
573 paint_dayview(Calendar *c, Boolean repaint, XRectangle *rect, Boolean update_months)
575 Props *p = (Props*)c->properties;
577 int beg = get_int_prop(p, CP_DAYBEGIN);
578 int end = get_int_prop(p, CP_DAYEND);
580 CSA_attribute *range_attrs;
581 CSA_entry_handle *list;
585 int panel0_year, panel0_month;
586 int panel1_year, panel1_month;
587 int panel2_year, panel2_month;
588 int year_num, month_num;
589 Boolean day_not_on_panel = False;
590 Day *d = (Day *)c->view->day_info;
592 int bottom_panel = 2;
594 num_hrs = end - beg + 1;
595 if (c->paint_cache == NULL) {
596 start = (time_t) lower_bound(0, c->view->date);
597 stop = (time_t) next_nhours(start, end+1) - 1;
598 setup_range(&range_attrs, &ops, &j, start, stop, CSA_TYPE_EVENT, NULL,
599 B_FALSE, c->general->version);
600 csa_list_entries(c->cal_handle, j, range_attrs, ops, &a_total, &list, NULL);
602 free_range(&range_attrs, &ops, j);
603 allocate_paint_cache(list, a_total, &c->paint_cache);
604 c->paint_cache_size = a_total;
608 year_num = year(c->view->date);
609 month_num = month(c->view->date);
610 XtVaGetValues(d->month_panels[1],
611 XmNyear, &panel1_year,
612 XmNmonth, &panel1_month,
615 if ((panel1_year == year(get_bot())) && (panel1_month == 1))
617 else if ((panel1_year == year(get_eot())) && (panel1_month == 12))
620 XtVaGetValues(d->month_panels[top_panel],
621 XmNyear, &panel0_year,
622 XmNmonth, &panel0_month,
625 if ((year_num < panel0_year) ||
626 ((year_num == panel0_year) && (month_num < panel0_month)))
627 day_not_on_panel = True;
629 XtVaGetValues(d->month_panels[bottom_panel],
630 XmNyear, &panel2_year,
631 XmNmonth, &panel2_month,
634 if ((year_num > panel2_year) ||
635 ((year_num == panel2_year) && (month_num > panel2_month)))
636 day_not_on_panel = True;
638 /* set up month panels */
639 if (update_months || day_not_on_panel)
642 /* no need to do this on a damage event */
645 display_monthpanels(c);
647 /* repaint appointment area */
651 gr_clear_area(c->xcontext, 0, 0,
652 c->view->winw, c->view->winh);
653 line_length = c->view->topoffset +
654 ((end - beg + 1) * c->view->boxh);
655 /* draw line separating mo. boxes and appts. */
656 gr_draw_line(c->xcontext, (int)MOBOX_AREA_WIDTH+1,
657 0, (int)MOBOX_AREA_WIDTH+1,
658 line_length, gr_solid, rect);
659 gr_draw_line(c->xcontext, (int)MOBOX_AREA_WIDTH+2,
660 0, (int)MOBOX_AREA_WIDTH+2,
661 line_length, gr_solid, rect);
662 gr_draw_line(c->xcontext, (int)MOBOX_AREA_WIDTH+2,
663 c->view->topoffset-1, c->view->winw,
664 c->view->topoffset-1, gr_solid, rect);
665 gr_draw_line(c->xcontext, (int)MOBOX_AREA_WIDTH+2,
666 c->view->topoffset, c->view->winw,
667 c->view->topoffset, gr_solid, rect);
668 paint_dayview_appts(c, c->paint_cache, c->paint_cache_size, rect);
670 /* just repaint schedule area */
672 gr_clear_area(c->xcontext,
673 (int)MOBOX_AREA_WIDTH+4, 0,
674 c->view->winw - (int)MOBOX_AREA_WIDTH+4,
676 gr_draw_line(c->xcontext, (int)MOBOX_AREA_WIDTH+2,
677 c->view->topoffset, c->view->winw,
678 c->view->topoffset, gr_solid, rect);
679 gr_draw_line(c->xcontext, (int)MOBOX_AREA_WIDTH+2,
680 c->view->topoffset+1, c->view->winw,
681 c->view->topoffset+1, gr_solid, rect);
682 paint_dayview_appts(c, c->paint_cache, c->paint_cache_size, rect);
685 paint_day_header(c, c->view->date, rect);
689 paint_day(Calendar *c)
691 Day *day_info = (Day *) c->view->day_info;
693 c->view->glance = dayGlance;
694 XmToggleButtonGadgetSetState(c->day_scope, True, False);
695 gr_clear_area(c->xcontext, 0, 0, c->view->winw, c->view->winh);
696 if (day_info->month_panels == (Widget *) NULL)
697 (void)init_dayview(c);
698 paint_dayview(c, True, NULL, True);
699 calendar_select(c, hourSelect, (caddr_t)NULL);
703 * handler for button to switch to day view.
706 day_button (Widget widget, XtPointer data, XtPointer cbs)
708 Calendar *c = calendar;
710 if (c->view->glance == dayGlance)
713 XtUnmapWidget(c->canvas);
716 switch (c->view->glance) {
718 c->view->glance = dayGlance;
719 cleanup_after_weekview(c);
722 c->view->glance = dayGlance;
723 cleanup_after_yearview(c);
726 c->view->glance = dayGlance;
727 cleanup_after_monthview(c);
734 (void)init_dayview(c);
736 XtMapWidget(c->canvas);
740 print_day_range(Calendar *c, Tick start_tick, Tick end_tick)
743 register Tick first_date = start_tick;
744 Boolean done = False, first = True;
746 Props *pr = (Props*)c->properties;
747 void *xp = (void *)NULL;
749 n = (end_tick - start_tick)/daysec + 1;
753 if ((xp = x_open_file(c)) == (void *)NULL)
758 done = _print_day(c, num_page, xp,
759 first_date, pr, first);
771 count_day_pages(Calendar *c, int lines_per_page, Tick tick)
773 int n, i, j, timeslots, num_appts, pages, max = 0;
774 Props *p = (Props *)c->properties;
775 int daybegin = get_int_prop(p, CP_DAYBEGIN);
776 int dayend = get_int_prop(p, CP_DAYEND);
779 CSA_return_code stat;
780 CSA_entry_handle *list;
781 CSA_attribute *range_attrs;
785 for (i=daybegin; i < dayend; i++) {
786 start = (time_t) lower_bound(i, tick);
787 end = (time_t) next_nhours(start+1, 1) - 1;
788 setup_range(&range_attrs, &ops, &j, start, end,
789 CSA_TYPE_EVENT, NULL, B_FALSE, c->general->version);
790 csa_list_entries(c->cal_handle, j, range_attrs, ops, &a_total, &list, NULL);
791 free_range(&range_attrs, &ops, j);
793 num_appts = count_multi_appts(list, a_total, c);
801 pages = max / lines_per_page;
802 if ((max % lines_per_page) > 0)
809 _print_day(Calendar *c,
817 int n, i, j, timeslots, num_appts, pages;
819 int daybegin = get_int_prop(p, CP_DAYBEGIN);
820 int dayend = get_int_prop(p, CP_DAYEND);
821 OrderingType ord_t = get_int_prop(p, CP_DATEORDERING);
822 Boolean more, done = False, all_done = True;
824 CSA_return_code stat;
825 CSA_entry_handle *list;
826 CSA_attribute *range_attrs;
831 static Tick tick = 0;
832 static int total_pages = 0;
835 * Need to find the max number of timeslots which will be shown
836 * in one column, for later calculation of box height.
838 if ((!morning(daybegin)) || dayend <= 12)
839 timeslots = dayend - daybegin;
841 timeslots = ((12-daybegin) > (dayend-12)) ?
842 (12-daybegin) : (dayend-12);
844 x_init_printer(xp, PORTRAIT);
845 x_init_day(xp, timeslots);
846 lines_per_page = x_get_day_lines_per_page(xp);
852 tick = prevday(tick);
854 total_pages = (lines_per_page > 0) ?
855 count_day_pages(c, lines_per_page, tick) : 1;
857 format_date(tick, ord_t, buf, 1, 0, 0);
859 x_print_header(xp, buf, num_page, total_pages);
862 for (i=daybegin; i < dayend; i++) {
863 start = (time_t) lower_bound(i, tick);
864 stop = (time_t) next_nhours(start+1, 1) - 1;
865 setup_range(&range_attrs, &ops, &j, start, stop,
866 CSA_TYPE_EVENT, NULL, B_FALSE, c->general->version);
868 csa_list_entries(c->cal_handle, j, range_attrs,
869 ops, &a_total, &list, NULL);
870 free_range(&range_attrs, &ops, j);
872 num_appts = count_multi_appts(list, a_total, c);
874 if ((lines_per_page > 0) && (num_appts > (lines_per_page * num_page)))
879 x_day_timeslots (xp, i, more);
881 if (lines_per_page > 0)
882 done = x_print_multi_appts (xp, list, a_total,
883 num_page, dayGlance);
891 x_finish_printer(xp);
892 tick = nextday(tick);
898 day_xytoclock(Calendar *c, int x, int y, Tick t)
900 int daybegin, hr, val;
904 _Xltimeparams localtime_buf;
906 p = (Props *)c->properties;
907 daybegin = get_int_prop(p, CP_DAYBEGIN);
908 tm = *_XLocaltime(&t, localtime_buf);
910 hr = (x == 1) ? (12 + y) : (y + daybegin - 1);
913 * If y == 0 then the user is clicking on the no-time area. There
914 * is no hour associated with no-time events.
918 (void)sprintf(buf, "%d/%d/%d", tm.tm_mon+1, tm.tm_mday, tm.tm_year+1900);
919 val =cm_getdate(buf, NULL);
920 val = val+(hr*(int)hrsec);
926 day_event(XEvent *event)
928 static int lastcol, lastrow;
929 static XEvent lastevent;
932 int boxw, boxh, margin, id;
933 Calendar *c = calendar;
934 Tick date = c->view->date;
935 Boolean in_mbox = False; /* in month boxes ? */
936 Editor *e = (Editor*)c->editor;
937 ToDo *t = (ToDo*)c->todo;
938 GEditor *ge = (GEditor*)c->geditor;
939 Day *day_info = (Day *)c->view->day_info;
941 boxw = c->view->boxw;
942 boxh = c->view->boxh;
943 margin = c->view->outside_margin;
944 x = event->xbutton.x;
945 y = event->xbutton.y;
947 /* boundary conditions */
948 if ((!(in_mbox = in_moboxes(c, x, y)) && x < MOBOX_AREA_WIDTH+2)
950 (x > MOBOX_AREA_WIDTH+2 && y < c->view->topoffset)) {
951 lastcol=0; lastrow=0;
955 xy.x = (x - margin)/ day_info->col_w;
956 xy.y = (x - c->view->topoffset)/ day_info->row_h;
960 xy.y = (y - c->view->topoffset)/boxh;
962 switch(event->type) {
965 if (xy.x !=lastcol || xy.y !=lastrow) {
966 calendar_deselect(c);
967 j = day_xytoclock(c, xy.x, xy.y, date);
969 c->view->olddate = c->view->date; c->view->date = j;
970 calendar_select(c, hourSelect, (caddr_t)&xy);
978 if (ds_is_double_click(&lastevent, event)) {
979 _DtTurnOnHourGlass(c->frame);
980 j = day_xytoclock(c, xy.x, xy.y, date);
981 if (lastcol == xy.x && lastrow == xy.y)
982 show_editor(c, j, next_nhours(j, 1), xy.y == 0 ? True : False);
984 monthbox_deselect(c);
985 monthbox_xytodate(c, x, y);
988 show_editor(c, j, next_nhours(j, 1), xy.y == 0 ? True : False);
989 _DtTurnOffHourGlass(c->frame);
992 monthbox_deselect(c);
993 monthbox_xytodate(c, x, y);
994 paint_dayview(c, False, NULL, True);
995 calendar_select(c, hourSelect, (caddr_t)NULL);
997 j = day_xytoclock(c, xy.x, xy.y, date);
998 if (editor_showing(e)) {
999 set_editor_defaults(e, j,
1000 next_nhours(j, 1), False);
1003 if (todo_showing(t)) {
1004 set_todo_defaults(t);
1007 if (geditor_showing(ge)) {
1008 set_geditor_defaults(ge, j,
1013 calendar_deselect(c);
1014 j = day_xytoclock(c, xy.x, xy.y, date);
1016 c->view->olddate = c->view->date;
1018 calendar_select(c, hourSelect,
1020 if (editor_showing(e)) {
1021 set_editor_defaults(e, j,
1022 next_nhours(j, 1), xy.y == 0 ? True : False);
1025 if (todo_showing(t)) {
1026 set_todo_defaults(t);
1029 if (geditor_showing(ge)) {
1030 set_geditor_defaults(ge, j,
1047 display_monthpanels(Calendar *c)
1049 Day *d = (Day *)c->view->day_info;
1051 int lastyear = year(get_eot());
1052 int firstyear = year(get_bot());
1056 XtManageChild(d->panel_form);
1058 XtVaGetValues(d->month_panels[1],
1059 XmNyear, &panel_year,
1060 XmNmonth, &panel_month,
1063 if ((panel_year == firstyear) && (panel_month == 1)) {
1064 XtUnmapWidget(d->month_panels[0]);
1065 XtMapWidget(d->month_panels[2]);
1066 sprintf(buf, "%s", catgets(c->DT_catd, 1, 623, "Calendar does not display dates prior to January 1, 1970"));
1067 set_message(c->message_text, buf);
1069 else if ((panel_year == lastyear) && (panel_month == 12)) {
1070 XtMapWidget(d->month_panels[0]);
1071 XtUnmapWidget(d->month_panels[2]);
1072 sprintf(buf, "%s", catgets(c->DT_catd, 1, 624, "Calendar does not display dates after December 31, 2037"));
1073 set_message(c->message_text, buf);
1076 XtMapWidget(d->month_panels[0]);
1077 XtMapWidget(d->month_panels[2]);
1078 set_message(c->message_text, "");
1081 /* switch canvas to attach using its XmNleftPosition value */
1082 /* THIS IS THE RIGHT THIS TO DO, BUT ONLY AFTER REMOVING THE
1083 CODE THAT DRAWS THE OLD MO_BOXES. FOR NOW, WE JUST MANAGE THE
1084 MONTHPANELS ON TOP OF THAT PART OF THE CANVAS - dac
1085 XtVaSetValues(c->canvas,
1086 XmNleftAttachment, XmATTACH_POSITION,
1087 XmNleftPosition, 40,
1094 cleanup_after_dayview(Calendar *c)
1096 Day *d = (Day *)c->view->day_info;
1098 invalidate_cache(c);
1100 XtUnmanageChild(d->panel_form);
1102 XmToggleButtonGadgetSetState(c->day_scope, False, False);
1104 /* make canvas attach to form, and ignore its XmNleftPosition */
1105 /* DITTO ABOVE: THIS ISN'T NEEDED TILL WE ACTUALLY DO RESIZE THE
1106 CANVAS TO ADJOIN THE MONTHPANELS WHILE DAY VIEW IS UP
1107 XtVaSetValues(c->canvas, XmNleftAttachment, XmATTACH_FORM, NULL);
1110 gr_clear_area(calendar->xcontext, 0, 0, calendar->view->winw,
1111 calendar->view->winh);
1113 set_message(c->message_text, "");
1117 create_month_panels(Calendar *c)
1119 Day *d = (Day *)c->view->day_info;
1124 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); ac++;
1125 XtSetArg(al[ac], XmNtopWidget, c->canvas); ac++;
1126 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
1127 XtSetArg(al[ac], XmNrightPosition, 40); ac++;
1128 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
1129 XtSetArg(al[ac], XmNleftOffset, 2); ac++;
1130 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
1131 XtSetArg(al[ac], XmNbottomPosition, 95); ac++;
1132 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
1133 d->panel_form = XmCreateForm(c->form, "quarter", al, ac);
1137 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
1138 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
1139 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
1140 XtSetArg(al[ac], XmNbottomPosition, 33); ac++;
1141 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
1142 XtSetArg(al[ac], XmNmonth, month(previousmonth(c->view->date))); ac++;
1143 XtSetArg(al[ac], XmNyear, year(previousmonth(c->view->date))); ac++;
1144 d->month_panels[0] = XmCreateMonthPanel(d->panel_form, "lastMonth", al, ac);
1145 XtAddCallback(d->month_panels[0], XmNactivateCallback,
1146 day_btn_cb, (XtPointer) c);
1147 XtAddCallback(d->month_panels[0], XmNhelpCallback,
1148 (XtCallbackProc)help_view_cb, NULL);
1151 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_POSITION); ac++;
1152 XtSetArg(al[ac], XmNtopPosition, 33); ac++;
1153 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
1154 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
1155 XtSetArg(al[ac], XmNbottomPosition, 66); ac++;
1156 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
1157 XtSetArg(al[ac], XmNmonth, month(c->view->date)); ac++;
1158 XtSetArg(al[ac], XmNyear, year(c->view->date)); ac++;
1159 d->month_panels[1] = XmCreateMonthPanel(d->panel_form, "thisMonth", al, ac);
1160 XtAddCallback(d->month_panels[1], XmNactivateCallback,
1161 day_btn_cb, (XtPointer) c);
1162 XtAddCallback(d->month_panels[1], XmNhelpCallback,
1163 (XtCallbackProc)help_view_cb, NULL);
1166 XtSetArg(al[ac], XmNtopAttachment, XmATTACH_POSITION); ac++;
1167 XtSetArg(al[ac], XmNtopPosition, 66); ac++;
1168 XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
1169 XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
1170 XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
1171 XtSetArg(al[ac], XmNmonth, month(nextmonth(c->view->date))); ac++;
1172 XtSetArg(al[ac], XmNyear, year(nextmonth(c->view->date))); ac++;
1173 d->month_panels[2] = XmCreateMonthPanel(d->panel_form, "nextMonth", al, ac);
1174 XtAddCallback(d->month_panels[2], XmNactivateCallback,
1175 day_btn_cb, (XtPointer) c);
1176 XtAddCallback(d->month_panels[2], XmNhelpCallback,
1177 (XtCallbackProc)help_view_cb, NULL);
1179 ManageChildren(d->panel_form);
1184 * This redisplays the 3 month panels 2 show the correct 3-month
1185 * window, centred around the month containing the "current" date.
1188 update_quarter(Calendar *c)
1190 Day *d = (Day *)c->view->day_info;
1191 int year_num, month_num;
1193 /* previous month */
1194 year_num = year(previousmonth(c->view->date));
1195 month_num = month(previousmonth(c->view->date));
1196 XtVaSetValues(d->month_panels[0],
1198 XmNmonth, month_num,
1202 year_num = year(c->view->date);
1203 month_num = month(c->view->date);
1204 XtVaSetValues(d->month_panels[1],
1206 XmNmonth, month_num,
1210 year_num = year(nextmonth(c->view->date));
1211 month_num = month(nextmonth(c->view->date));
1212 XtVaSetValues(d->month_panels[2],
1214 XmNmonth, month_num,
1220 day_btn_cb(Widget w, XtPointer client, XtPointer call)
1222 XmMonthPanelCallbackStruct *cbs = (XmMonthPanelCallbackStruct *) call;
1223 Calendar *c = (Calendar *)client;
1225 int date = c->view->date;
1227 invalidate_cache(c);
1229 XtVaGetValues(w, XmNmonth, &monthno, XmNyear, &year, NULL);
1231 if (cbs->type == MONTH_SELECTION) {
1233 XtUnmapWidget(c->canvas);
1237 * if month chosen is not current month
1238 * set date to 1st of new month, otherwise
1239 * don't change date.
1241 if (month(c->view->date) != monthno) {
1242 calendar_deselect (c);
1243 c->view->olddate = c->view->date;
1244 c->view->date = monthdayyear(monthno, 1, year);
1245 c->view->nwks = numwks(c->view->date);
1246 calendar_select (c, monthSelect, NULL);
1249 /* switch to month view */
1250 c->view->glance = monthGlance;
1251 cleanup_after_dayview(c);
1252 prepare_to_paint_monthview(c, NULL);
1254 XtMapWidget(c->canvas);
1256 else { /* type == DAY_SELECTION */
1257 c->view->olddate = c->view->date;
1258 c->view->date = monthdayyear(monthno, cbs->day, year);
1259 gr_clear_area(c->xcontext, 0, 0, c->view->winw, c->view->winh);
1260 paint_dayview(c, True, NULL, False);
1261 calendar_select(c, hourSelect, (caddr_t)NULL);