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 ** $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();
77 selection_active (Selection *s)
83 deactivate_selection (Selection *s)
89 activate_selection (Selection *s)
95 weekchart_deselect(Calendar *c)
97 int h, i, j, k, index, wi, x, y, chart_x, chart_y;
98 Week *w = (Week *)c->view->week_info;
99 Selection *sel = (Selection *) w->current_selection;
100 XFontSetExtents fontextents;
104 CalFontExtents(w->font, &fontextents);
105 char_height = fontextents.max_ink_extent.height;
107 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
109 if (!selection_active (sel)) return;
114 /* dissolves box around weekday letter over chart */
115 chart_x = w->chart_x + (j * w->chart_day_width);
116 chart_y = w->chart_y - char_height - 4;
117 gr_dissolve_box(c->xcontext, chart_x, chart_y - 6,
118 w->chart_day_width, char_height + 6, 2);
120 x = (j*w->chart_day_width) + w->chart_x + 1;
121 y = (k * (w->chart_hour_height + w->add_pixels)) + w->chart_y + 1;
122 h = (w->chart_hour_height/BOX_SEG);
123 wi = w->chart_day_width-2;
125 gr_clear_area(c->xcontext, x, y, w->chart_day_width-1,
126 w->chart_hour_height-1 + w->add_pixels);
127 gr_draw_box(c->xcontext, x - 1, y - 1, w->chart_day_width,
128 w->chart_hour_height + w->add_pixels, NULL);
129 index = j * (w->segs_in_array / 7) + (BOX_SEG * k);
130 for (i = index; i < (index + BOX_SEG); i++) {
131 /* compensate for the added pixel for displaying chart */
132 if ((i+1) == (index + BOX_SEG)) h += w->add_pixels;
133 if (w->time_array[i] == 1) {
134 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
135 gr_make_gray(c->xcontext, x, y, wi+1, h, 25);
137 gr_make_grayshade(c->xcontext, x, y, wi+1, h,
140 else if (w->time_array[i] == 2) {
141 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
142 gr_make_gray(c->xcontext, x, y,
145 gr_make_rgbcolor(c->xcontext, cms, x, y, wi+1, h,
146 MIDGREY, MIDGREY, MIDGREY);
148 else if (w->time_array[i] >= 3) {
149 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
150 gr_make_gray(c->xcontext, x, y, wi+1, h, 75);
152 gr_make_grayshade(c->xcontext, x, y, wi+1, h,
155 /* compensate for grid line pixel */
156 if (i == (index+BOX_SEG-2))
161 deactivate_selection (sel);
164 /* selects day in chart */
166 weekchart_select(Calendar *c)
168 int i, j, chart_x, chart_y;
169 Week *w = (Week *)c->view->week_info;
170 Selection *sel = (Selection *) w->current_selection;
172 Pixel background_pixel;
173 XFontSetExtents fontextents;
176 CalFontExtents(w->font, &fontextents);
177 char_height = fontextents.max_ink_extent.height;
179 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
181 XtVaGetValues(c->frame, XmNbackground, &background_pixel, NULL);
183 background_pixel = c->xcontext->hilight_color;
188 chart_x = w->chart_x + (i * w->chart_day_width);
189 chart_y = w->chart_y - char_height - 4;
190 if (c->xcontext->screen_depth < 8) {
191 gr_draw_box(c->xcontext, (i * w->chart_day_width) +
192 w->chart_x + 1, (j * w->chart_hour_height) +
193 (j * w->add_pixels) + w->chart_y + 1,
194 w->chart_day_width - 2,
195 w->chart_hour_height - 2 + w->add_pixels, NULL);
196 gr_draw_box(c->xcontext, chart_x, chart_y,
197 w->chart_day_width, char_height + 1, NULL);
200 /* Select time slot */
201 gr_draw_rgb_box(c->xcontext, (i * w->chart_day_width)
202 + w->chart_x, (j * w->chart_hour_height)
203 + (j * w->add_pixels) + w->chart_y,
204 w->chart_day_width, w->chart_hour_height
205 + w->add_pixels, 1, background_pixel, cms);
207 /* Select weekday letter over chart */
208 gr_draw_rgb_box(c->xcontext, chart_x, chart_y - 6,
209 w->chart_day_width, char_height + 6, 1,
210 background_pixel, cms);
213 activate_selection(sel);
217 /* selects day is main boxes: not chart */
219 select_weekday(Calendar *c, Boolean select)
222 new_XContext*xc = c->xcontext;
223 Week *w = (Week *)c->view->week_info;
224 Pixel foreground_pixel;
227 foreground_pixel = xc->hilight_color;
229 /* Draw selection feedback on week view */
230 (n = dow(c->view->date)) == 0 ? n = 6 : n--;
233 x = w->x + n * w->day_width + 2;
234 y = w->y + w->label_height + 2;
237 x = w->x + n * w->day_width + 2;
238 y = w->y + w->day_height + w->label_height + 2;
242 if (c->xcontext->screen_depth < 8) {
243 gr_draw_box(xc, x, y, w->day_width - 2,
244 w->day_height - w->label_height - 2, NULL);
249 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
250 gr_draw_rgb_box(xc, x - 2, y - 2, w->day_width,
251 w->day_height - w->label_height, 1,
252 foreground_pixel, cms);
256 gr_draw_box(xc, x - 2, y - 2, w->day_width,
257 w->day_height - w->label_height, NULL);
258 gr_dissolve_box(xc, x - 1, y - 1, w->day_width - 2,
259 w->day_height - w->label_height - 2, 2);
260 weekchart_deselect(c);
265 /* selection service for all views. ref is a client_data
266 field which is cast depending on the selection unit. if
267 it's a daySelect, ref contains the number of weeks in the
268 month. if it's a monthSelect, ref contains a point to x,y
269 coordinates. ref is NULL on a weekSelect. */
272 calendar_select (Calendar *c, Selection_unit unit, caddr_t ref)
275 int xpos, boxw, boxh, margin, topoff, date;
279 Pixel foreground_pixel;
282 date = c->view->date;
283 sel = (Selection *) c->view->current_selection;
284 boxw = c->view->boxw;
285 boxh = c->view->boxh;
286 margin = c->view->outside_margin;
287 topoff = c->view->topoffset;
290 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
292 XtVaGetValues(c->canvas, XmNforeground, &foreground_pixel, NULL);
294 foreground_pixel = xc->hilight_color;
296 /* day selection on month glance */
298 dayname_height = ((Month *) c->view->month_info)->dayname_height;
305 if (c->xcontext->screen_depth < 8)
306 gr_draw_box(xc, (i*boxw)+margin+
307 1, (sel->row*boxh)+topoff+
308 dayname_height+1, boxw-2, boxh-2, NULL);
310 gr_draw_rgb_box(xc, (i*boxw)
312 (sel->row*boxh)+topoff+
313 dayname_height, boxw,
315 foreground_pixel, cms);
317 activate_selection (sel);
321 /* week selection on month glance view */
329 if (c->xcontext->screen_depth < 8)
330 gr_draw_box(xc, i*boxw+margin+1,
331 (int)ref*boxh+margin+topoff+1,
332 boxw-2, boxh-2, NULL);
334 gr_draw_rgb_box(xc, i*boxw+margin+2,
335 (int)ref*boxh+margin+topoff+2,
337 foreground_pixel, cms);
338 gr_draw_rgb_box(xc, i*boxw+margin+1,
339 (int)ref*boxh+margin+topoff+1,
341 foreground_pixel, cms);
345 activate_selection (sel);
348 /* month selection on year glance view */
351 i=((pr_pos *)ref)->x;
352 j=((pr_pos *)ref)->y;
358 if (c->xcontext->screen_depth < 8)
359 gr_draw_box(xc, i*boxw+margin+10,
360 j*boxh+topoff-4, boxw-4, boxh-4, NULL);
369 gr_draw_rgb_box(xc, xpos,
370 j*boxh+topoff+10, boxw-2, boxh-2, 1,
371 foreground_pixel, cms);
373 gr_draw_rgb_box(xc, xpos,
374 j*boxh+topoff+10, boxw-56, boxh+2, 1,
375 foreground_pixel, cms);
380 activate_selection (sel);
382 /* hour box selection day glance view */
385 j=((pr_pos *)ref)->y;
388 if (c->xcontext->screen_depth < 8)
389 gr_draw_box(xc, MOBOX_AREA_WIDTH+5,
390 j*boxh+topoff+1, c->view->boxw-4,
391 c->view->boxh-2, NULL);
393 gr_draw_rgb_box(xc, MOBOX_AREA_WIDTH+3,
398 foreground_pixel, cms);
401 sel->col=MOBOX_AREA_WIDTH+4;
403 activate_selection(sel);
405 /* day selection on week glance */
407 select_weekday(c, True);
408 activate_selection (sel);
410 /* hotbox selection on week glance */
411 case weekhotboxSelect:
412 select_weekhotbox(c);
413 activate_selection (sel);
419 common_update_lists(c);
424 calendar_deselect (Calendar *c)
428 int boxh = c->view->boxh;
429 int boxw = c->view->boxw;
430 int margin = c->view->outside_margin;
431 int topoff = c->view->topoffset;
432 Selection *s = (Selection *) c->view->current_selection;
433 int nunits = s->nunits;
434 new_XContext *xc = c->xcontext;
437 Cal_Font *pf = c->fonts->boldfont;
438 Props *p = (Props*)c->properties;
439 DisplayType disp_t = get_int_prop(p, CP_DEFAULTDISP);
441 if (selection_active(s)) {
444 switch(c->view->glance) {
446 select_weekday(c, False);
447 deactivate_selection (s);
451 int num_hrs = get_int_prop(p, CP_DAYEND) -
452 get_int_prop(p, CP_DAYBEGIN) + 1;
454 for (i=0; i < nunits; i++) {
455 gr_dissolve_box(xc, MOBOX_AREA_WIDTH+3,
456 k*boxh+topoff + 1, boxw-3, boxh-2, 3);
457 x = MOBOX_AREA_WIDTH + 2;
458 y = k * boxh + topoff;
460 gr_draw_line(xc, x, y, x + boxw, y,
463 gr_draw_line(xc, x, y, x + boxw, y,
467 if (disp_t == HOUR12)
468 CalTextExtents(pf, "12pm", 4, &nop, &nop,
469 &hrbox_margin, &nop);
471 CalTextExtents(pf, "24 ", 3, &nop, &nop,
472 &hrbox_margin, &nop);
474 /* draw vertical line */
475 gr_draw_line(xc, MOBOX_AREA_WIDTH+2+hrbox_margin,
476 c->view->topoffset, MOBOX_AREA_WIDTH+2+hrbox_margin,
477 c->view->topoffset + num_hrs * c->view->boxh,
483 ((Month *) c->view->month_info)->dayname_height;
485 for (i=0; i<nunits; i++) {
487 (j * boxw) + margin + 1,
488 (k * boxh) + topoff + dayname_height + 1,
489 boxw - 2, boxh - 2, 2);
492 (k * boxh) + topoff + dayname_height,
498 for (i=0; i<nunits; i++) {
507 gr_dissolve_box(xc, (j*boxw)+margin+10,
511 gr_dissolve_box(xc, xpos,
512 k*boxh+topoff+10, boxw-56, boxh+2, 1);
515 gr_dissolve_box(xc, (j*boxw)+margin+11,
523 deactivate_selection (s);
527 monthbox_deselect(Calendar *c)
530 Day *day_info = (Day *)c->view->day_info;
533 if (day_info->day_selected == -1)
536 x = day_info->day_selected_x + 2;
537 y = day_info->day_selected_y + 2;
539 if (c->xcontext->screen_depth < 8)
540 gr_make_gray(c->xcontext,
544 day_info->row_h-1, 25);
546 gr_make_grayshade(c->xcontext,
550 day_info->row_h-1, LIGHTGREY);
552 sprintf(buf, "%d", day_info->day_selected);
553 gr_text(c->xcontext, day_info->day_selected_x2+2,
554 day_info->day_selected_y2,
555 c->fonts->viewfont, buf, NULL);
558 monthbox_select(Calendar *c)
561 Day *day_info = (Day *)c->view->day_info;
564 x = day_info->day_selected_x + 2;
565 y = day_info->day_selected_y + 2;
567 gr_clear_box(c->xcontext,
572 gr_draw_box(c->xcontext,
576 day_info->row_h-3, NULL);
578 sprintf(buf, "%d", day_info->day_selected);
579 gr_text(c->xcontext, day_info->day_selected_x2+2,
580 day_info->day_selected_y2,
581 c->fonts->viewfont, buf, NULL);
585 browser_deselect (Calendar *c, Browser *b)
587 int h, i, j, k, index, w, x, y;
588 Selection *sel = (Selection *) b->current_selection;
591 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
592 if (!selection_active (sel))
596 x = (j*b->boxw) + b->chart_x + 1;
597 y = (k*b->boxh) + b->chart_y + 1;
598 h = (b->boxh/BOX_SEG);
600 gr_clear_area(b->xcontext, x, y, b->boxw-1, b->boxh-1);
601 index = j * (b->segs_in_array / 7) + (BOX_SEG * k);
602 for (i = index; i < (index + BOX_SEG); i++) {
603 if (b->multi_array[i] == 1) {
604 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
605 gr_make_gray(b->xcontext, x, y, w+1,
608 gr_make_grayshade(b->xcontext, x, y,
611 else if (b->multi_array[i] == 2) {
612 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
613 gr_make_gray(b->xcontext, x, y,
616 gr_make_rgbcolor(b->xcontext, cms, x, y,
617 w+1, h, MIDGREY, MIDGREY, MIDGREY);
619 else if (b->multi_array[i] >= 3) {
620 if ((c->xcontext->screen_depth < 8) || FAKE_MONOCHROME)
621 gr_make_gray(b->xcontext, x, y,
624 gr_make_grayshade(b->xcontext, x, y,
627 /* compensate for grid line pixel */
628 if (i == (index+BOX_SEG-2))
633 deactivate_selection (sel);
638 browser_select(Calendar *c, Browser *b, pr_pos *xy)
641 Selection *sel = (Selection *) b->current_selection;
654 if (c->xcontext->screen_depth < 8) {
655 gr_draw_box(b->xcontext, (i * b->boxw) +
656 b->chart_x + 2, (j * b->boxh) + b->chart_y
657 + 2, b->boxw - 4, b->boxh - 4, NULL);
660 pixel = c->xcontext->hilight_color;
661 XtVaGetValues(b->canvas, XmNcolormap, &cms, NULL);
662 gr_draw_rgb_box(b->xcontext, (i * b->boxw) +
663 b->chart_x + 2, (j * b->boxh) + b->chart_y
664 + 2, b->boxw - 4, b->boxh - 4, 1,
666 gr_draw_rgb_box(b->xcontext, (i * b->boxw) +
667 b->chart_x + 1, (j * b->boxh) + b->chart_y
668 + 1, b->boxw - 2, b->boxh - 2, 1,
674 activate_selection(sel);
679 select_weekhotbox(Calendar *c)
682 new_XContext*xc = c->xcontext;
683 Week *w = (Week *)c->view->week_info;
684 long date = c->view->date;
686 Pixel background_pixel;
688 XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
689 XtVaGetValues(c->frame, XmNbackground, &background_pixel, NULL);
691 /* Draw selection feedback on week view */
692 if ((n = dow(date)) == 0)
698 x = w->x + n * w->day_width + 2;
703 x = w->x + n * w->day_width + 2;
704 y = w->y + w->day_height + 2;
707 if (c->xcontext->screen_depth < 8)
708 gr_draw_box(xc, x, y, w->day_width - 4, w->label_height - 4, NULL);
710 gr_draw_rgb_box(xc, x, y,
711 w->day_width - 4, w->label_height - 4, 1,
712 background_pixel, cms);
713 gr_draw_rgb_box(xc, x-1, y-1,
714 w->day_width-2, w->label_height - 2, 1,
715 background_pixel, cms);
720 paint_selection(Calendar *c)
722 Props *p = (Props*)c->properties;
724 int d, mo, beg = get_int_prop(p, CP_DAYBEGIN);
725 Week *w = (Week *)c->view->week_info;
728 switch ((Glance)c->view->glance) {
730 calendar_select(c, daySelect, (caddr_t)NULL);
733 sel = (Selection *) c->view->current_selection;
734 sel->row = hour(c->view->date) - beg + 1;
735 calendar_select(c, hourSelect, (caddr_t)NULL);
738 sel = (Selection*)w->current_selection;
739 sel->row = hour(c->view->date) - beg;
740 sel->col = (d = dow(c->view->date)) == 0 ? 6 : --d; calendar_select(c, weekdaySelect, (caddr_t)NULL);
743 mo = month(c->view->date);
744 xy.y = month_row_col[mo-1][ROW];
745 xy.x = month_row_col[mo-1][COL];
746 calendar_select(c, monthSelect, (caddr_t)&xy);