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 libraries 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 ** $TOG: select.c /main/4 1998/08/18 17:32:33 samborn $
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[] = "@(#)select.c 1.24 95/02/21 Copyr 1994 Sun Microsystems, Inc.";
54 #include <EUSCompat.h>
66 #include "dayglance.h"
67 #include "weekglance.h"
68 #include "monthglance.h"
69 #include "yearglance.h"
70 #include "datefield.h"
73 static void select_weekhotbox();
75 /* Highlight thickness - mghis */
76 #define STDTTT 3 /* default */
77 #define WEEKLTTT 2 /* of hour slots in week glance view */
80 selection_active (Selection *s)
86 deactivate_selection (Selection *s)
92 activate_selection (Selection *s)
98 weekchart_deselect(Calendar *c)
100 int h, i, j, k, index, wi, x, y, chart_x, chart_y;
101 Week *w = (Week *)c->view->week_info;
102 Selection *sel = (Selection *) w->current_selection;
103 XFontSetExtents fontextents;
107 CalFontExtents(w->font, &fontextents);
108 char_height = fontextents.max_ink_extent.height;
110 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
112 if (!selection_active (sel)) return;
117 /* dissolves box around weekday letter over chart */
118 chart_x = w->chart_x + (j * w->chart_day_width);
119 chart_y = w->chart_y - char_height - 4;
120 gr_dissolve_box(c->xcontext, chart_x, chart_y - 6,
121 w->chart_day_width, char_height + 6, 2);
123 x = (j*w->chart_day_width) + w->chart_x + 1;
124 y = (k * (w->chart_hour_height + w->add_pixels)) + w->chart_y + 1;
125 h = (w->chart_hour_height/BOX_SEG);
126 wi = w->chart_day_width-2;
128 gr_clear_area(c->xcontext, x, y, w->chart_day_width-1,
129 w->chart_hour_height-1 + w->add_pixels);
130 gr_draw_box(c->xcontext, x - 1, y - 1, w->chart_day_width,
131 w->chart_hour_height + w->add_pixels, NULL);
132 index = j * (w->segs_in_array / 7) + (BOX_SEG * k);
133 for (i = index; i < (index + BOX_SEG); i++) {
134 /* compensate for the added pixel for displaying chart */
135 if ((i+1) == (index + BOX_SEG)) h += w->add_pixels;
136 if (w->time_array[i] == 1) {
137 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
138 gr_make_gray(c->xcontext, x, y, wi+1, h, 25);
140 gr_make_grayshade(c->xcontext, x, y, wi+1, h,
143 else if (w->time_array[i] == 2) {
144 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
145 gr_make_gray(c->xcontext, x, y,
148 gr_make_rgbcolor(c->xcontext, cms, x, y, wi+1, h,
149 MIDGREY, MIDGREY, MIDGREY);
151 else if (w->time_array[i] >= 3) {
152 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
153 gr_make_gray(c->xcontext, x, y, wi+1, h, 75);
155 gr_make_grayshade(c->xcontext, x, y, wi+1, h,
158 /* compensate for grid line pixel */
159 if (i == (index+BOX_SEG-2))
164 deactivate_selection (sel);
167 /* selects day in chart */
169 weekchart_select(Calendar *c)
171 int i, j, chart_x, chart_y;
172 Week *w = (Week *)c->view->week_info;
173 Selection *sel = (Selection *) w->current_selection;
175 Pixel background_pixel;
176 XFontSetExtents fontextents;
179 CalFontExtents(w->font, &fontextents);
180 char_height = fontextents.max_ink_extent.height;
182 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
184 XtVaGetValues(c->frame, XmNbackground, &background_pixel, NULL);
186 background_pixel = c->xcontext->hilight_color;
191 chart_x = w->chart_x + (i * w->chart_day_width);
192 chart_y = w->chart_y - char_height - 4;
193 if (c->xcontext->screen_depth < 8) {
194 gr_draw_box(c->xcontext, (i * w->chart_day_width) +
195 w->chart_x + 1, (j * w->chart_hour_height) +
196 (j * w->add_pixels) + w->chart_y + 1,
197 w->chart_day_width - 2,
198 w->chart_hour_height - 2 + w->add_pixels, NULL);
199 gr_draw_box(c->xcontext, chart_x, chart_y,
200 w->chart_day_width, char_height + 1, NULL);
203 /* Select time slot */
204 gr_draw_rgb_box(c->xcontext, (i * w->chart_day_width)
205 + w->chart_x, (j * w->chart_hour_height)
206 + (j * w->add_pixels) + w->chart_y,
207 w->chart_day_width, w->chart_hour_height
208 + w->add_pixels, WEEKLTTT, background_pixel,
211 /* Select weekday letter over chart */
212 gr_draw_rgb_box(c->xcontext, chart_x, chart_y - 6,
213 w->chart_day_width, char_height + 6, WEEKLTTT,
214 background_pixel, cms);
217 activate_selection(sel);
221 /* selects day is main boxes: not chart */
223 select_weekday(Calendar *c, Boolean select)
226 new_XContext*xc = c->xcontext;
227 Week *w = (Week *)c->view->week_info;
228 Pixel foreground_pixel;
231 foreground_pixel = xc->hilight_color;
233 /* Draw selection feedback on week view */
234 (n = dow(c->view->date)) == 0 ? n = 6 : n--;
237 x = w->x + n * w->day_width + 2;
238 y = w->y + w->label_height + 2;
241 x = w->x + n * w->day_width + 2;
242 y = w->y + w->day_height + w->label_height + 2;
246 if (c->xcontext->screen_depth < 8) {
247 gr_draw_box(xc, x, y, w->day_width - 2,
248 w->day_height - w->label_height - 2, NULL);
253 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
254 gr_draw_rgb_box(xc, x - 2, y - 2, w->day_width,
255 w->day_height - w->label_height, STDTTT,
256 foreground_pixel, cms);
260 gr_draw_box(xc, x - 2, y - 2, w->day_width,
261 w->day_height - w->label_height, NULL);
262 gr_dissolve_box(xc, x - 1, y - 1, w->day_width - 2,
263 w->day_height - w->label_height - 2, 2);
264 weekchart_deselect(c);
269 /* selection service for all views. ref is a client_data
270 field which is cast depending on the selection unit. if
271 it's a daySelect, ref contains the number of weeks in the
272 month. if it's a monthSelect, ref contains a point to x,y
273 coordinates. ref is NULL on a weekSelect. */
276 calendar_select (Calendar *c, Selection_unit unit, caddr_t ref)
279 int xpos, boxw, boxh, margin, topoff, date;
283 Pixel foreground_pixel;
286 date = c->view->date;
287 sel = (Selection *) c->view->current_selection;
288 boxw = c->view->boxw;
289 boxh = c->view->boxh;
290 margin = c->view->outside_margin;
291 topoff = c->view->topoffset;
294 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
296 XtVaGetValues(c->canvas, XmNforeground, &foreground_pixel, NULL);
298 foreground_pixel = xc->hilight_color;
300 /* day selection on month glance */
302 dayname_height = ((Month *) c->view->month_info)->dayname_height;
309 if (c->xcontext->screen_depth < 8)
310 gr_draw_box(xc, (i*boxw)+margin+
311 1, (sel->row*boxh)+topoff+
312 dayname_height+1, boxw-2, boxh-2, NULL);
314 gr_draw_rgb_box(xc, (i*boxw)
316 (sel->row*boxh)+topoff+
317 dayname_height, boxw,
319 foreground_pixel, cms);
321 activate_selection (sel);
325 /* week selection on month glance view */
333 if (c->xcontext->screen_depth < 8)
334 gr_draw_box(xc, i*boxw+margin+1,
335 (int)ref*boxh+margin+topoff+1,
336 boxw-2, boxh-2, NULL);
338 gr_draw_rgb_box(xc, i*boxw+margin+2,
339 (int)ref*boxh+margin+topoff+2,
340 boxw-4, boxh-4, STDTTT,
341 foreground_pixel, cms);
342 gr_draw_rgb_box(xc, i*boxw+margin+1,
343 (int)ref*boxh+margin+topoff+1,
345 foreground_pixel, cms);
349 activate_selection (sel);
352 /* month selection on year glance view */
355 i=((pr_pos *)ref)->x;
356 j=((pr_pos *)ref)->y;
362 if (c->xcontext->screen_depth < 8)
363 gr_draw_box(xc, i*boxw+margin+10,
364 j*boxh+topoff-4, boxw-4, boxh-4, NULL);
373 gr_draw_rgb_box(xc, xpos,
374 j*boxh+topoff+10, boxw-2, boxh-2, 1,
375 foreground_pixel, cms);
377 gr_draw_rgb_box(xc, xpos,
378 j*boxh+topoff+10, boxw-56, boxh+2, STDTTT,
379 foreground_pixel, cms);
384 activate_selection (sel);
386 /* hour box selection day glance view */
389 j=((pr_pos *)ref)->y;
392 if (c->xcontext->screen_depth < 8)
393 gr_draw_box(xc, MOBOX_AREA_WIDTH+5,
394 j*boxh+topoff+1, c->view->boxw-4,
395 c->view->boxh-2, NULL);
397 gr_draw_rgb_box(xc, MOBOX_AREA_WIDTH+3,
402 foreground_pixel, cms);
405 sel->col=MOBOX_AREA_WIDTH+4;
407 activate_selection(sel);
409 /* day selection on week glance */
411 select_weekday(c, True);
412 activate_selection (sel);
414 /* hotbox selection on week glance */
415 case weekhotboxSelect:
416 select_weekhotbox(c);
417 activate_selection (sel);
423 common_update_lists(c);
428 calendar_deselect (Calendar *c)
432 int boxh = c->view->boxh;
433 int boxw = c->view->boxw;
434 int margin = c->view->outside_margin;
435 int topoff = c->view->topoffset;
436 Selection *s = (Selection *) c->view->current_selection;
437 int nunits = s->nunits;
438 new_XContext *xc = c->xcontext;
441 Cal_Font *pf = c->fonts->boldfont;
442 Props *p = (Props*)c->properties;
443 DisplayType disp_t = get_int_prop(p, CP_DEFAULTDISP);
445 if (selection_active(s)) {
448 switch(c->view->glance) {
450 select_weekday(c, False);
451 deactivate_selection (s);
455 int num_hrs = get_int_prop(p, CP_DAYEND) -
456 get_int_prop(p, CP_DAYBEGIN) + 1;
458 for (i=0; i < nunits; i++) {
459 gr_dissolve_box(xc, MOBOX_AREA_WIDTH+3,
460 k*boxh+topoff + 1, boxw-3, boxh-2, 3);
461 x = MOBOX_AREA_WIDTH + 2;
462 y = k * boxh + topoff;
464 gr_draw_line(xc, x, y, x + boxw, y,
467 gr_draw_line(xc, x, y, x + boxw, y,
471 if (disp_t == HOUR12)
472 CalTextExtents(pf, "12pm", 4, &nop, &nop,
473 &hrbox_margin, &nop);
475 CalTextExtents(pf, "24 ", 3, &nop, &nop,
476 &hrbox_margin, &nop);
478 /* draw vertical line */
479 gr_draw_line(xc, MOBOX_AREA_WIDTH+2+hrbox_margin,
480 c->view->topoffset, MOBOX_AREA_WIDTH+2+hrbox_margin,
481 c->view->topoffset + num_hrs * c->view->boxh,
487 ((Month *) c->view->month_info)->dayname_height;
489 for (i=0; i<nunits; i++) {
491 (j * boxw) + margin + 1,
492 (k * boxh) + topoff + dayname_height + 1,
493 boxw - 2, boxh - 2, 2);
496 (k * boxh) + topoff + dayname_height,
502 for (i=0; i<nunits; i++) {
511 gr_dissolve_box(xc, (j*boxw)+margin+10,
515 gr_dissolve_box(xc, xpos,
516 k*boxh+topoff+10, boxw-56, boxh+2, 1);
519 gr_dissolve_box(xc, (j*boxw)+margin+11,
527 deactivate_selection (s);
531 monthbox_deselect(Calendar *c)
534 Day *day_info = (Day *)c->view->day_info;
537 if (day_info->day_selected == -1)
540 x = day_info->day_selected_x + 2;
541 y = day_info->day_selected_y + 2;
543 if (c->xcontext->screen_depth < 8)
544 gr_make_gray(c->xcontext,
548 day_info->row_h-1, 25);
550 gr_make_grayshade(c->xcontext,
554 day_info->row_h-1, LIGHTGREY);
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);
562 monthbox_select(Calendar *c)
565 Day *day_info = (Day *)c->view->day_info;
568 x = day_info->day_selected_x + 2;
569 y = day_info->day_selected_y + 2;
571 gr_clear_box(c->xcontext,
576 gr_draw_box(c->xcontext,
580 day_info->row_h-3, NULL);
582 sprintf(buf, "%d", day_info->day_selected);
583 gr_text(c->xcontext, day_info->day_selected_x2+2,
584 day_info->day_selected_y2,
585 c->fonts->viewfont, buf, NULL);
589 browser_deselect (Calendar *c, Browser *b)
591 int h, i, j, k, index, w, x, y;
592 Selection *sel = (Selection *) b->current_selection;
595 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
596 if (!selection_active (sel))
600 x = (j*b->boxw) + b->chart_x + 1;
601 y = (k*b->boxh) + b->chart_y + 1;
602 h = (b->boxh/BOX_SEG);
604 gr_clear_area(b->xcontext, x, y, b->boxw-1, b->boxh-1);
605 index = j * (b->segs_in_array / 7) + (BOX_SEG * k);
606 for (i = index; i < (index + BOX_SEG); i++) {
607 if (b->multi_array[i] == 1) {
608 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
609 gr_make_gray(b->xcontext, x, y, w+1,
612 gr_make_grayshade(b->xcontext, x, y,
615 else if (b->multi_array[i] == 2) {
616 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
617 gr_make_gray(b->xcontext, x, y,
620 gr_make_rgbcolor(b->xcontext, cms, x, y,
621 w+1, h, MIDGREY, MIDGREY, MIDGREY);
623 else if (b->multi_array[i] >= 3) {
624 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
625 gr_make_gray(b->xcontext, x, y,
628 gr_make_grayshade(b->xcontext, x, y,
631 /* compensate for grid line pixel */
632 if (i == (index+BOX_SEG-2))
637 deactivate_selection (sel);
642 browser_select(Calendar *c, Browser *b, pr_pos *xy)
645 Selection *sel = (Selection *) b->current_selection;
658 if (c->xcontext->screen_depth < 8) {
659 gr_draw_box(b->xcontext, (i * b->boxw) +
660 b->chart_x + 2, (j * b->boxh) + b->chart_y
661 + 2, b->boxw - 4, b->boxh - 4, NULL);
664 pixel = c->xcontext->hilight_color;
665 XtVaGetValues(b->canvas, XmNcolormap, &cms, NULL);
666 gr_draw_rgb_box(b->xcontext, (i * b->boxw) +
667 b->chart_x + 2, (j * b->boxh) + b->chart_y
668 + 2, b->boxw - 4, b->boxh - 4, STDTTT,
670 gr_draw_rgb_box(b->xcontext, (i * b->boxw) +
671 b->chart_x + 1, (j * b->boxh) + b->chart_y
672 + 1, b->boxw - 2, b->boxh - 2, STDTTT,
678 activate_selection(sel);
683 select_weekhotbox(Calendar *c)
686 new_XContext*xc = c->xcontext;
687 Week *w = (Week *)c->view->week_info;
688 long date = c->view->date;
690 Pixel background_pixel;
692 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
693 XtVaGetValues(c->frame, XmNbackground, &background_pixel, NULL);
695 /* Draw selection feedback on week view */
696 if ((n = dow(date)) == 0)
702 x = w->x + n * w->day_width + 2;
707 x = w->x + n * w->day_width + 2;
708 y = w->y + w->day_height + 2;
711 if (c->xcontext->screen_depth < 8)
712 gr_draw_box(xc, x, y, w->day_width - 4, w->label_height - 4, NULL);
714 gr_draw_rgb_box(xc, x, y,
715 w->day_width - 4, w->label_height - 4, STDTTT,
716 background_pixel, cms);
717 gr_draw_rgb_box(xc, x-1, y-1,
718 w->day_width-2, w->label_height - 2, STDTTT,
719 background_pixel, cms);
724 paint_selection(Calendar *c)
726 Props *p = (Props*)c->properties;
728 int d, mo, beg = get_int_prop(p, CP_DAYBEGIN);
729 Week *w = (Week *)c->view->week_info;
732 switch ((Glance)c->view->glance) {
734 calendar_select(c, daySelect, (caddr_t)NULL);
737 sel = (Selection *) c->view->current_selection;
738 sel->row = hour(c->view->date) - beg + 1;
739 calendar_select(c, hourSelect, (caddr_t)NULL);
742 sel = (Selection*)w->current_selection;
743 sel->row = hour(c->view->date) - beg;
744 sel->col = (d = dow(c->view->date)) == 0 ? 6 : --d; calendar_select(c, weekdaySelect, (caddr_t)NULL);
747 mo = month(c->view->date);
748 xy.y = month_row_col[mo-1][ROW];
749 xy.x = month_row_col[mo-1][COL];
750 calendar_select(c, monthSelect, (caddr_t)&xy);