dtcm: Resolve CID 87408
[oweals/cde.git] / cde / programs / dtcm / dtcm / select.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /*******************************************************************************
24 **
25 **  select.c
26 **
27 **  $TOG: select.c /main/4 1998/08/18 17:32:33 samborn $
28 **
29 **  RESTRICTED CONFIDENTIAL INFORMATION:
30 **
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
37 **  Sun's request.
38 **
39 **  Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
40 **
41 *******************************************************************************/
42
43 /*                                                                      *
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.                                *
48  */
49
50 #ifndef lint
51 static  char sccsid[] = "@(#)select.c 1.24 95/02/21 Copyr 1994 Sun Microsystems, Inc.";
52 #endif
53
54 #include <EUSCompat.h>
55 #include <stdio.h>
56 #include <Xm/Xm.h>
57 #include "util.h"
58 #include "select.h"
59 /*
60 #include "graphics.h"
61 */
62 #include "calendar.h"
63 #include "timeops.h"
64 #include "browser.h"
65 #include "todo.h"
66 #include "dayglance.h"
67 #include "weekglance.h"
68 #include "monthglance.h"
69 #include "yearglance.h"
70 #include "datefield.h"
71 #include "props.h"
72
73 static void select_weekhotbox();
74
75
76 extern int
77 selection_active (Selection *s)
78 {
79         return (s->active);
80 }
81
82 extern void
83 deactivate_selection (Selection *s)
84 {
85         s->active=0;
86 }
87
88 extern void
89 activate_selection (Selection *s)
90 {
91         s->active=1;
92 }
93
94 extern void
95 weekchart_deselect(Calendar *c)
96 {
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;
101         int     char_height;
102         Colormap cms;
103
104         CalFontExtents(w->font, &fontextents);
105         char_height = fontextents.max_ink_extent.height;
106
107         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
108
109         if (!selection_active (sel)) return;
110
111         j = sel->col;
112         k = sel->row;
113
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);
119
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;
124
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);
136                         else 
137                                 gr_make_grayshade(c->xcontext, x, y, wi+1, h, 
138                                                 LIGHTGREY);
139                 }
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, 
143                                         wi+1, h, 50);
144                         else
145                                 gr_make_rgbcolor(c->xcontext, cms, x, y, wi+1, h, 
146                                                 MIDGREY, MIDGREY, MIDGREY);
147                 }
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);
151                         else 
152                                 gr_make_grayshade(c->xcontext, x, y, wi+1, h, 
153                                                 DIMGREY);
154                 }
155                 /* compensate for grid line pixel */ 
156                 if (i == (index+BOX_SEG-2))
157                         y += (h-1);
158                 else
159                         y += h;
160         }
161         deactivate_selection (sel);
162 }
163
164 /* selects day in chart */
165 extern void
166 weekchart_select(Calendar *c)
167 {
168         int i, j, chart_x, chart_y;
169         Week *w = (Week *)c->view->week_info;
170         Selection *sel  = (Selection *) w->current_selection;
171         Colormap cms;
172         Pixel background_pixel;
173         XFontSetExtents fontextents;
174         int     char_height;
175
176         CalFontExtents(w->font, &fontextents);
177         char_height = fontextents.max_ink_extent.height;
178
179         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
180         /*
181         XtVaGetValues(c->frame, XmNbackground, &background_pixel, NULL);
182         */
183         background_pixel = c->xcontext->hilight_color;
184
185         i = sel->col;
186         j = sel->row;
187         if (j >= 0) {
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);
198                 }
199                 else  { 
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);
206
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);
211                 }
212                 sel->nunits = 1;
213                 activate_selection(sel);
214         }
215 }
216
217 /* selects day is main boxes: not chart */
218 static void
219 select_weekday(Calendar *c, Boolean select)
220 {
221         int     n, x, y;
222         new_XContext*xc     = c->xcontext;
223         Week    *w = (Week *)c->view->week_info;
224         Pixel foreground_pixel;
225
226
227         foreground_pixel = xc->hilight_color;
228
229         /* Draw selection feedback on week view */
230         (n = dow(c->view->date)) == 0 ? n = 6 : n--;
231
232         if (n < 5) {
233                 x = w->x + n * w->day_width + 2;
234                 y = w->y + w->label_height + 2;
235         } else {
236                 n -= (5 - 3);
237                 x = w->x + n * w->day_width + 2;
238                 y = w->y + w->day_height + w->label_height + 2;
239         }
240  
241         if (select) {
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);
245                 }
246                 else {
247                         Colormap cms;
248
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);
253                 }
254                 weekchart_select(c);
255         } else {
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);
261         }
262  
263 }
264
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.              */
270
271 extern void
272 calendar_select (Calendar *c, Selection_unit unit, caddr_t ref)
273 {
274         int i, j;
275         int xpos, boxw, boxh, margin, topoff, date;
276         Selection *sel;
277         new_XContext *xc;
278         Colormap cms;
279         Pixel foreground_pixel;
280         int dayname_height;
281
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;
288         xc      = c->xcontext;
289
290         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
291         /*
292         XtVaGetValues(c->canvas, XmNforeground, &foreground_pixel, NULL);
293         */
294         foreground_pixel = xc->hilight_color;
295         switch (unit) {
296                 /* day selection on month glance */
297                 case daySelect:
298                         dayname_height = ((Month *) c->view->month_info)->dayname_height;
299                         i=dow(date);
300                         j=wom(date);
301                         if (j >= 0) {
302                                 sel->row=j-1;
303                                 sel->col=i;
304                                 sel->nunits=1;
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);
309                                 else {
310                                         gr_draw_rgb_box(xc, (i*boxw)
311                                                 +margin, 
312                                                 (sel->row*boxh)+topoff+
313                                                 dayname_height, boxw, 
314                                                 boxh, 1,
315                                                 foreground_pixel, cms);
316                                 }
317                                 activate_selection (sel);
318
319                         }
320                         break;
321                 /* week selection on month glance view */
322                 case weekSelect:
323 #ifdef NEVER
324                         i=0; j=7;
325                         sel->row=(int)ref;
326                         sel->col=i;
327                         sel->nunits=j-i;
328                         while (i < j) {
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);
333                                 else {
334                                         gr_draw_rgb_box(xc, i*boxw+margin+2,
335                                         (int)ref*boxh+margin+topoff+2, 
336                                         boxw-4, boxh-4, 1,
337                                         foreground_pixel, cms);
338                                         gr_draw_rgb_box(xc, i*boxw+margin+1,
339                                         (int)ref*boxh+margin+topoff+1, 
340                                         boxw-2, boxh-2, 1,
341                                         foreground_pixel, cms);
342                                 }
343                                 i++;
344                         }
345                         activate_selection (sel);
346 #endif
347                         break;
348                 /* month selection on year glance view */
349                 case monthSelect:
350                         if (ref != NULL) {
351                                 i=((pr_pos *)ref)->x;
352                                 j=((pr_pos *)ref)->y;
353                         }
354                         else {
355                                 i = sel->col;
356                                 j = sel->row;
357                         }
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);
361                         else {
362                                 if (i == 0)
363                                        xpos = margin-5;
364                                 else if (i == 1)
365                                         xpos = i*(boxw-18);
366                                 else
367                                         xpos = i*(boxw-24);
368 /*
369                                 gr_draw_rgb_box(xc, xpos,
370                                         j*boxh+topoff+10, boxw-2, boxh-2, 1,
371                                         foreground_pixel, cms);
372 */
373                                 gr_draw_rgb_box(xc, xpos,
374                                         j*boxh+topoff+10, boxw-56, boxh+2, 1,
375                                         foreground_pixel, cms);
376                         }
377                         sel->row=j;
378                         sel->col=i;
379                         sel->nunits=1;
380                         activate_selection (sel);
381                         break;
382                 /* hour box selection day glance view */
383                 case hourSelect:
384                         if (ref != NULL)
385                                 j=((pr_pos *)ref)->y;
386                         else
387                                 j = sel->row;
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);
392                         else {
393                                 gr_draw_rgb_box(xc, MOBOX_AREA_WIDTH+3,
394                                         j*boxh+topoff, 
395                                         c->view->boxw - 2,
396                                         c->view->boxh,
397                                         1,
398                                         foreground_pixel, cms);
399                         }
400                         sel->row=j;
401                         sel->col=MOBOX_AREA_WIDTH+4;
402                         sel->nunits=1;
403                         activate_selection(sel);
404                         break;
405                 /* day selection on week glance */
406                 case weekdaySelect:
407                         select_weekday(c, True);
408                         activate_selection (sel);
409                         break;
410                 /* hotbox selection on week glance */
411                 case weekhotboxSelect:
412                         select_weekhotbox(c);
413                         activate_selection (sel);
414                         break;
415                 default:
416                         break;
417         }
418 /*
419         common_update_lists(c);
420 */
421 }
422         
423 extern void
424 calendar_deselect (Calendar *c)
425 {
426         int             i, j, k, xpos;
427         int             x, y;
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;
435         int             dayname_height;
436         int             nop;
437         Cal_Font        *pf = c->fonts->boldfont;
438         Props           *p = (Props*)c->properties;
439         DisplayType     disp_t = get_int_prop(p, CP_DEFAULTDISP);
440
441         if (selection_active(s)) {
442                 j=s->col;
443                 k=s->row;
444                 switch(c->view->glance) {
445                 case weekGlance:
446                         select_weekday(c, False);
447                         deactivate_selection (s);
448                         break;
449                 case dayGlance: {
450                         int     hrbox_margin;
451                         int     num_hrs = get_int_prop(p, CP_DAYEND) -
452                                           get_int_prop(p, CP_DAYBEGIN) + 1;
453
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;
459
460                                 gr_draw_line(xc, x, y, x + boxw, y,
461                                                 gr_solid, NULL);
462                                 y += boxh;
463                                 gr_draw_line(xc, x, y, x + boxw, y, 
464                                                 gr_solid, NULL);
465                         }
466
467                         if (disp_t == HOUR12)
468                                 CalTextExtents(pf, "12pm", 4, &nop, &nop, 
469                                                            &hrbox_margin, &nop);
470                         else
471                                 CalTextExtents(pf, "24 ", 3, &nop, &nop, 
472                                                            &hrbox_margin, &nop);
473
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, 
478                         gr_solid, NULL);
479                         break;
480                 }
481                 case monthGlance:
482                         dayname_height = 
483                                 ((Month *) c->view->month_info)->dayname_height;
484
485                         for (i=0; i<nunits; i++) {
486                                 gr_dissolve_box(xc,
487                                         (j * boxw) + margin + 1, 
488                                         (k * boxh) + topoff + dayname_height + 1,
489                                         boxw - 2, boxh - 2, 2);
490                                 gr_draw_box(xc,
491                                         (j * boxw) + margin, 
492                                         (k * boxh) + topoff + dayname_height,
493                                         boxw, boxh, NULL);
494                                 j++;
495                         }
496                         break;
497                 case yearGlance:
498                         for (i=0; i<nunits; i++) {
499                                 if (j == 0)
500                                        xpos = margin-5;
501                                 else if (j == 1)
502                                         xpos = j*(boxw-18);
503                                 else
504                                         xpos = j*(boxw-24);
505
506 /*
507                                 gr_dissolve_box(xc, (j*boxw)+margin+10,
508                                         k*boxh+topoff-5,
509                                         boxw-2, boxh-2, 1);
510 */
511                                 gr_dissolve_box(xc, xpos, 
512                                    k*boxh+topoff+10, boxw-56, boxh+2, 1);
513
514 /*
515                                 gr_dissolve_box(xc, (j*boxw)+margin+11,
516                                         k*boxh+topoff-4,
517                                         boxw-2, boxh-2, 1);
518 */
519                                 j++;
520                         }
521                         break;
522                 }
523                 deactivate_selection (s);
524         }
525 }
526 extern void
527 monthbox_deselect(Calendar *c)
528 {
529         char buf[3];
530         Day *day_info = (Day *)c->view->day_info;
531         int x, y;
532
533         if (day_info->day_selected == -1)
534                 return;
535
536         x = day_info->day_selected_x + 2;
537         y = day_info->day_selected_y + 2;
538
539         if (c->xcontext->screen_depth < 8)
540                 gr_make_gray(c->xcontext, 
541                         x,
542                         y,
543                         day_info->col_w+1,
544                         day_info->row_h-1, 25);
545         else
546                 gr_make_grayshade(c->xcontext, 
547                         x,
548                         y,
549                         day_info->col_w+1,
550                         day_info->row_h-1, LIGHTGREY);
551         buf [0] = '\0';
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);
556 }
557 extern void
558 monthbox_select(Calendar *c)
559 {
560         char buf[3];
561         Day *day_info = (Day *)c->view->day_info;
562         int x, y;
563
564         x = day_info->day_selected_x + 2;
565         y = day_info->day_selected_y + 2;
566
567         gr_clear_box(c->xcontext, 
568                         x,
569                         y,
570                         day_info->col_w,
571                         day_info->row_h-3);
572         gr_draw_box(c->xcontext,
573                         x,
574                         y,
575                         day_info->col_w,
576                         day_info->row_h-3, NULL);
577         buf [0] = '\0';
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);
582 }
583
584 extern void
585 browser_deselect (Calendar *c, Browser *b)
586 {
587         int h, i, j, k, index, w, x, y;
588         Selection *sel  = (Selection *) b->current_selection;
589         Colormap cms;
590
591         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
592         if (!selection_active (sel))
593                 return;
594         j = sel->col;
595         k = sel->row;
596         x =  (j*b->boxw) +  b->chart_x + 1;
597         y =  (k*b->boxh) + b->chart_y + 1;
598         h =  (b->boxh/BOX_SEG);
599         w =  b->boxw-2;
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, 
606                                                         h, 25);
607                         else 
608                                 gr_make_grayshade(b->xcontext, x, y, 
609                                         w+1, h, LIGHTGREY);
610                 }
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, 
614                                         w+1, h, 50);
615                         else
616                                 gr_make_rgbcolor(b->xcontext, cms, x, y, 
617                                         w+1, h, MIDGREY, MIDGREY, MIDGREY);
618                 }
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, 
622                                         w+1, h, 75);
623                         else 
624                                 gr_make_grayshade(b->xcontext, x, y, 
625                                         w+1, h, DIMGREY);
626                 }
627                 /* compensate for grid line pixel */ 
628                 if (i == (index+BOX_SEG-2))
629                         y += (h-1);
630                 else
631                         y += h;
632         }
633         deactivate_selection (sel);
634 }
635
636
637 extern void
638 browser_select(Calendar *c, Browser *b, pr_pos *xy)
639 {
640         int i, j;
641         Selection *sel  = (Selection *) b->current_selection;
642         Colormap cms;
643         Pixel pixel;
644
645         if (xy != NULL) {
646                 i = xy->x;
647                 j = xy->y;
648         }
649         else {
650                 i = sel->col;
651                 j = sel->row;
652         }
653         if (j >= 0) {
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);
658                 }
659                 else {
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,
665                                 pixel, cms);
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,
669                                 pixel, cms);
670                 }
671                 sel->row = j;
672                 sel->col = i;
673                 sel->nunits = 1;
674                 activate_selection(sel);
675         }
676 }
677
678 static void
679 select_weekhotbox(Calendar *c)
680 {
681         int     n, x, y;
682         new_XContext*xc     = c->xcontext;
683         Week *w = (Week *)c->view->week_info;
684         long    date    = c->view->date;
685         Colormap        cms;
686         Pixel background_pixel;
687
688         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
689         XtVaGetValues(c->frame, XmNbackground, &background_pixel, NULL);
690
691         /* Draw selection feedback on week view */
692         if ((n = dow(date)) == 0)
693                 n = 6;
694         else
695                 n--;
696
697         if (n < 5) {
698                 x = w->x + n * w->day_width + 2;
699                 y = w->y + 2;
700         }
701         else {
702                 n -= (5 - 3);
703                 x = w->x + n * w->day_width + 2;
704                 y = w->y + w->day_height + 2;
705         }
706  
707         if (c->xcontext->screen_depth < 8)
708                 gr_draw_box(xc, x, y, w->day_width - 4, w->label_height - 4, NULL);
709         else {
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);
716         }
717 }
718
719 extern void
720 paint_selection(Calendar *c)
721 {
722         Props  *p = (Props*)c->properties;
723         Selection *sel;
724         int d, mo, beg = get_int_prop(p, CP_DAYBEGIN);
725         Week *w = (Week *)c->view->week_info;
726         pr_pos xy;
727
728         switch ((Glance)c->view->glance) {
729                 case monthGlance:
730                         calendar_select(c, daySelect, (caddr_t)NULL);
731                         break;
732                 case dayGlance:
733                         sel = (Selection *) c->view->current_selection;
734                         sel->row = hour(c->view->date) - beg + 1;
735                         calendar_select(c, hourSelect, (caddr_t)NULL);
736                         break;
737                 case weekGlance:
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);
741                         break;
742                 case yearGlance:
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);
747                         break;
748         }
749 }