1 /*******************************************************************************
5 ** $TOG: select.c /main/4 1998/08/18 17:32:33 samborn $
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[] = "@(#)select.c 1.24 95/02/21 Copyr 1994 Sun Microsystems, Inc.";
32 #include <EUSCompat.h>
44 #include "dayglance.h"
45 #include "weekglance.h"
46 #include "monthglance.h"
47 #include "yearglance.h"
48 #include "datefield.h"
51 static void select_weekhotbox();
55 selection_active (Selection *s)
61 deactivate_selection (Selection *s)
67 activate_selection (Selection *s)
73 weekchart_deselect(Calendar *c)
75 int h, i, j, k, index, wi, x, y, chart_x, chart_y;
76 Week *w = (Week *)c->view->week_info;
77 Selection *sel = (Selection *) w->current_selection;
78 XFontSetExtents fontextents;
82 CalFontExtents(w->font, &fontextents);
83 char_height = fontextents.max_ink_extent.height;
85 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
87 if (!selection_active (sel)) return;
92 /* dissolves box around weekday letter over chart */
93 chart_x = w->chart_x + (j * w->chart_day_width);
94 chart_y = w->chart_y - char_height - 4;
95 gr_dissolve_box(c->xcontext, chart_x, chart_y - 6,
96 w->chart_day_width, char_height + 6, 2);
98 x = (j*w->chart_day_width) + w->chart_x + 1;
99 y = (k * (w->chart_hour_height + w->add_pixels)) + w->chart_y + 1;
100 h = (w->chart_hour_height/BOX_SEG);
101 wi = w->chart_day_width-2;
103 gr_clear_area(c->xcontext, x, y, w->chart_day_width-1,
104 w->chart_hour_height-1 + w->add_pixels);
105 gr_draw_box(c->xcontext, x - 1, y - 1, w->chart_day_width,
106 w->chart_hour_height + w->add_pixels, NULL);
107 index = j * (w->segs_in_array / 7) + (BOX_SEG * k);
108 for (i = index; i < (index + BOX_SEG); i++) {
109 /* compensate for the added pixel for displaying chart */
110 if ((i+1) == (index + BOX_SEG)) h += w->add_pixels;
111 if (w->time_array[i] == 1) {
112 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
113 gr_make_gray(c->xcontext, x, y, wi+1, h, 25);
115 gr_make_grayshade(c->xcontext, x, y, wi+1, h,
118 else if (w->time_array[i] == 2) {
119 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
120 gr_make_gray(c->xcontext, x, y,
123 gr_make_rgbcolor(c->xcontext, cms, x, y, wi+1, h,
124 MIDGREY, MIDGREY, MIDGREY);
126 else if (w->time_array[i] >= 3) {
127 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
128 gr_make_gray(c->xcontext, x, y, wi+1, h, 75);
130 gr_make_grayshade(c->xcontext, x, y, wi+1, h,
133 /* compensate for grid line pixel */
134 if (i == (index+BOX_SEG-2))
139 deactivate_selection (sel);
142 /* selects day in chart */
144 weekchart_select(Calendar *c)
146 int i, j, chart_x, chart_y;
147 Week *w = (Week *)c->view->week_info;
148 Selection *sel = (Selection *) w->current_selection;
150 Pixel background_pixel;
151 XFontSetExtents fontextents;
154 CalFontExtents(w->font, &fontextents);
155 char_height = fontextents.max_ink_extent.height;
157 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
159 XtVaGetValues(c->frame, XmNbackground, &background_pixel, NULL);
161 background_pixel = c->xcontext->hilight_color;
166 chart_x = w->chart_x + (i * w->chart_day_width);
167 chart_y = w->chart_y - char_height - 4;
168 if (c->xcontext->screen_depth < 8) {
169 gr_draw_box(c->xcontext, (i * w->chart_day_width) +
170 w->chart_x + 1, (j * w->chart_hour_height) +
171 (j * w->add_pixels) + w->chart_y + 1,
172 w->chart_day_width - 2,
173 w->chart_hour_height - 2 + w->add_pixels, NULL);
174 gr_draw_box(c->xcontext, chart_x, chart_y,
175 w->chart_day_width, char_height + 1, NULL);
178 /* Select time slot */
179 gr_draw_rgb_box(c->xcontext, (i * w->chart_day_width)
180 + w->chart_x, (j * w->chart_hour_height)
181 + (j * w->add_pixels) + w->chart_y,
182 w->chart_day_width, w->chart_hour_height
183 + w->add_pixels, 1, background_pixel, cms);
185 /* Select weekday letter over chart */
186 gr_draw_rgb_box(c->xcontext, chart_x, chart_y - 6,
187 w->chart_day_width, char_height + 6, 1,
188 background_pixel, cms);
191 activate_selection(sel);
195 /* selects day is main boxes: not chart */
197 select_weekday(Calendar *c, Boolean select)
200 new_XContext*xc = c->xcontext;
201 Week *w = (Week *)c->view->week_info;
202 Pixel foreground_pixel;
205 foreground_pixel = xc->hilight_color;
207 /* Draw selection feedback on week view */
208 (n = dow(c->view->date)) == 0 ? n = 6 : n--;
211 x = w->x + n * w->day_width + 2;
212 y = w->y + w->label_height + 2;
215 x = w->x + n * w->day_width + 2;
216 y = w->y + w->day_height + w->label_height + 2;
220 if (c->xcontext->screen_depth < 8) {
221 gr_draw_box(xc, x, y, w->day_width - 2,
222 w->day_height - w->label_height - 2, NULL);
227 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
228 gr_draw_rgb_box(xc, x - 2, y - 2, w->day_width,
229 w->day_height - w->label_height, 1,
230 foreground_pixel, cms);
234 gr_draw_box(xc, x - 2, y - 2, w->day_width,
235 w->day_height - w->label_height, NULL);
236 gr_dissolve_box(xc, x - 1, y - 1, w->day_width - 2,
237 w->day_height - w->label_height - 2, 2);
238 weekchart_deselect(c);
243 /* selection service for all views. ref is a client_data
244 field which is cast depending on the selection unit. if
245 it's a daySelect, ref contains the number of weeks in the
246 month. if it's a monthSelect, ref contains a point to x,y
247 coordinates. ref is NULL on a weekSelect. */
250 calendar_select (Calendar *c, Selection_unit unit, caddr_t ref)
253 int xpos, boxw, boxh, margin, topoff, date;
257 Pixel foreground_pixel;
260 date = c->view->date;
261 sel = (Selection *) c->view->current_selection;
262 boxw = c->view->boxw;
263 boxh = c->view->boxh;
264 margin = c->view->outside_margin;
265 topoff = c->view->topoffset;
268 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
270 XtVaGetValues(c->canvas, XmNforeground, &foreground_pixel, NULL);
272 foreground_pixel = xc->hilight_color;
274 /* day selection on month glance */
276 dayname_height = ((Month *) c->view->month_info)->dayname_height;
283 if (c->xcontext->screen_depth < 8)
284 gr_draw_box(xc, (i*boxw)+margin+
285 1, (sel->row*boxh)+topoff+
286 dayname_height+1, boxw-2, boxh-2, NULL);
288 gr_draw_rgb_box(xc, (i*boxw)
290 (sel->row*boxh)+topoff+
291 dayname_height, boxw,
293 foreground_pixel, cms);
295 activate_selection (sel);
299 /* week selection on month glance view */
307 if (c->xcontext->screen_depth < 8)
308 gr_draw_box(xc, i*boxw+margin+1,
309 (int)ref*boxh+margin+topoff+1,
310 boxw-2, boxh-2, NULL);
312 gr_draw_rgb_box(xc, i*boxw+margin+2,
313 (int)ref*boxh+margin+topoff+2,
315 foreground_pixel, cms);
316 gr_draw_rgb_box(xc, i*boxw+margin+1,
317 (int)ref*boxh+margin+topoff+1,
319 foreground_pixel, cms);
323 activate_selection (sel);
326 /* month selection on year glance view */
329 i=((pr_pos *)ref)->x;
330 j=((pr_pos *)ref)->y;
336 if (c->xcontext->screen_depth < 8)
337 gr_draw_box(xc, i*boxw+margin+10,
338 j*boxh+topoff-4, boxw-4, boxh-4, NULL);
347 gr_draw_rgb_box(xc, xpos,
348 j*boxh+topoff+10, boxw-2, boxh-2, 1,
349 foreground_pixel, cms);
351 gr_draw_rgb_box(xc, xpos,
352 j*boxh+topoff+10, boxw-56, boxh+2, 1,
353 foreground_pixel, cms);
358 activate_selection (sel);
360 /* hour box selection day glance view */
363 j=((pr_pos *)ref)->y;
366 if (c->xcontext->screen_depth < 8)
367 gr_draw_box(xc, MOBOX_AREA_WIDTH+5,
368 j*boxh+topoff+1, c->view->boxw-4,
369 c->view->boxh-2, NULL);
371 gr_draw_rgb_box(xc, MOBOX_AREA_WIDTH+3,
376 foreground_pixel, cms);
379 sel->col=MOBOX_AREA_WIDTH+4;
381 activate_selection(sel);
383 /* day selection on week glance */
385 select_weekday(c, True);
386 activate_selection (sel);
388 /* hotbox selection on week glance */
389 case weekhotboxSelect:
390 select_weekhotbox(c);
391 activate_selection (sel);
397 common_update_lists(c);
402 calendar_deselect (Calendar *c)
406 int boxh = c->view->boxh;
407 int boxw = c->view->boxw;
408 int margin = c->view->outside_margin;
409 int topoff = c->view->topoffset;
410 Selection *s = (Selection *) c->view->current_selection;
411 int nunits = s->nunits;
412 new_XContext *xc = c->xcontext;
415 Cal_Font *pf = c->fonts->boldfont;
416 Props *p = (Props*)c->properties;
417 DisplayType disp_t = get_int_prop(p, CP_DEFAULTDISP);
419 if (selection_active(s)) {
422 switch(c->view->glance) {
424 select_weekday(c, False);
425 deactivate_selection (s);
429 int num_hrs = get_int_prop(p, CP_DAYEND) -
430 get_int_prop(p, CP_DAYBEGIN) + 1;
432 for (i=0; i < nunits; i++) {
433 gr_dissolve_box(xc, MOBOX_AREA_WIDTH+3,
434 k*boxh+topoff + 1, boxw-3, boxh-2, 3);
435 x = MOBOX_AREA_WIDTH + 2;
436 y = k * boxh + topoff;
438 gr_draw_line(xc, x, y, x + boxw, y,
441 gr_draw_line(xc, x, y, x + boxw, y,
445 if (disp_t == HOUR12)
446 CalTextExtents(pf, "12pm", 4, &nop, &nop,
447 &hrbox_margin, &nop);
449 CalTextExtents(pf, "24 ", 3, &nop, &nop,
450 &hrbox_margin, &nop);
452 /* draw vertical line */
453 gr_draw_line(xc, MOBOX_AREA_WIDTH+2+hrbox_margin,
454 c->view->topoffset, MOBOX_AREA_WIDTH+2+hrbox_margin,
455 c->view->topoffset + num_hrs * c->view->boxh,
461 ((Month *) c->view->month_info)->dayname_height;
463 for (i=0; i<nunits; i++) {
465 (j * boxw) + margin + 1,
466 (k * boxh) + topoff + dayname_height + 1,
467 boxw - 2, boxh - 2, 2);
470 (k * boxh) + topoff + dayname_height,
476 for (i=0; i<nunits; i++) {
485 gr_dissolve_box(xc, (j*boxw)+margin+10,
489 gr_dissolve_box(xc, xpos,
490 k*boxh+topoff+10, boxw-56, boxh+2, 1);
493 gr_dissolve_box(xc, (j*boxw)+margin+11,
501 deactivate_selection (s);
505 monthbox_deselect(Calendar *c)
508 Day *day_info = (Day *)c->view->day_info;
511 if (day_info->day_selected == -1)
514 x = day_info->day_selected_x + 2;
515 y = day_info->day_selected_y + 2;
517 if (c->xcontext->screen_depth < 8)
518 gr_make_gray(c->xcontext,
522 day_info->row_h-1, 25);
524 gr_make_grayshade(c->xcontext,
528 day_info->row_h-1, LIGHTGREY);
530 sprintf(buf, "%d", day_info->day_selected);
531 gr_text(c->xcontext, day_info->day_selected_x2+2,
532 day_info->day_selected_y2,
533 c->fonts->viewfont, buf, NULL);
536 monthbox_select(Calendar *c)
539 Day *day_info = (Day *)c->view->day_info;
542 x = day_info->day_selected_x + 2;
543 y = day_info->day_selected_y + 2;
545 gr_clear_box(c->xcontext,
550 gr_draw_box(c->xcontext,
554 day_info->row_h-3, NULL);
556 sprintf(buf, "%d", day_info->day_selected);
557 gr_text(c->xcontext, day_info->day_selected_x2+2,
558 day_info->day_selected_y2,
559 c->fonts->viewfont, buf, NULL);
563 browser_deselect (Calendar *c, Browser *b)
565 int h, i, j, k, index, w, x, y;
566 Selection *sel = (Selection *) b->current_selection;
569 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
570 if (!selection_active (sel))
574 x = (j*b->boxw) + b->chart_x + 1;
575 y = (k*b->boxh) + b->chart_y + 1;
576 h = (b->boxh/BOX_SEG);
578 gr_clear_area(b->xcontext, x, y, b->boxw-1, b->boxh-1);
579 index = j * (b->segs_in_array / 7) + (BOX_SEG * k);
580 for (i = index; i < (index + BOX_SEG); i++) {
581 if (b->multi_array[i] == 1) {
582 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
583 gr_make_gray(b->xcontext, x, y, w+1,
586 gr_make_grayshade(b->xcontext, x, y,
589 else if (b->multi_array[i] == 2) {
590 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
591 gr_make_gray(b->xcontext, x, y,
594 gr_make_rgbcolor(b->xcontext, cms, x, y,
595 w+1, h, MIDGREY, MIDGREY, MIDGREY);
597 else if (b->multi_array[i] >= 3) {
598 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
599 gr_make_gray(b->xcontext, x, y,
602 gr_make_grayshade(b->xcontext, x, y,
605 /* compensate for grid line pixel */
606 if (i == (index+BOX_SEG-2))
611 deactivate_selection (sel);
616 browser_select(Calendar *c, Browser *b, pr_pos *xy)
619 Selection *sel = (Selection *) b->current_selection;
632 if (c->xcontext->screen_depth < 8) {
633 gr_draw_box(b->xcontext, (i * b->boxw) +
634 b->chart_x + 2, (j * b->boxh) + b->chart_y
635 + 2, b->boxw - 4, b->boxh - 4, NULL);
638 pixel = c->xcontext->hilight_color;
639 XtVaGetValues(b->canvas, XmNcolormap, &cms, NULL);
640 gr_draw_rgb_box(b->xcontext, (i * b->boxw) +
641 b->chart_x + 2, (j * b->boxh) + b->chart_y
642 + 2, b->boxw - 4, b->boxh - 4, 1,
644 gr_draw_rgb_box(b->xcontext, (i * b->boxw) +
645 b->chart_x + 1, (j * b->boxh) + b->chart_y
646 + 1, b->boxw - 2, b->boxh - 2, 1,
652 activate_selection(sel);
657 select_weekhotbox(Calendar *c)
660 new_XContext*xc = c->xcontext;
661 Week *w = (Week *)c->view->week_info;
662 long date = c->view->date;
664 Pixel background_pixel;
666 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
667 XtVaGetValues(c->frame, XmNbackground, &background_pixel, NULL);
669 /* Draw selection feedback on week view */
670 if ((n = dow(date)) == 0)
676 x = w->x + n * w->day_width + 2;
681 x = w->x + n * w->day_width + 2;
682 y = w->y + w->day_height + 2;
685 if (c->xcontext->screen_depth < 8)
686 gr_draw_box(xc, x, y, w->day_width - 4, w->label_height - 4, NULL);
688 gr_draw_rgb_box(xc, x, y,
689 w->day_width - 4, w->label_height - 4, 1,
690 background_pixel, cms);
691 gr_draw_rgb_box(xc, x-1, y-1,
692 w->day_width-2, w->label_height - 2, 1,
693 background_pixel, cms);
698 paint_selection(Calendar *c)
700 Props *p = (Props*)c->properties;
702 int d, mo, beg = get_int_prop(p, CP_DAYBEGIN);
703 Week *w = (Week *)c->view->week_info;
706 switch ((Glance)c->view->glance) {
708 calendar_select(c, daySelect, (caddr_t)NULL);
711 sel = (Selection *) c->view->current_selection;
712 sel->row = hour(c->view->date) - beg + 1;
713 calendar_select(c, hourSelect, (caddr_t)NULL);
716 sel = (Selection*)w->current_selection;
717 sel->row = hour(c->view->date) - beg;
718 sel->col = (d = dow(c->view->date)) == 0 ? 6 : --d; calendar_select(c, weekdaySelect, (caddr_t)NULL);
721 mo = month(c->view->date);
722 xy.y = month_row_col[mo-1][ROW];
723 xy.x = month_row_col[mo-1][COL];
724 calendar_select(c, monthSelect, (caddr_t)&xy);