Convert uses of XKeycodeToKeysym (deprecated) to XkbKeycodeToKeysym
[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 libraries 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 /* Highlight thickness  - mghis */
76 #define STDTTT          3       /* default */
77 #define WEEKLTTT        2       /* of hour slots in week glance view */
78
79 extern int
80 selection_active (Selection *s)
81 {
82         return (s->active);
83 }
84
85 extern void
86 deactivate_selection (Selection *s)
87 {
88         s->active=0;
89 }
90
91 extern void
92 activate_selection (Selection *s)
93 {
94         s->active=1;
95 }
96
97 extern void
98 weekchart_deselect(Calendar *c)
99 {
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;
104         int     char_height;
105         Colormap cms;
106
107         CalFontExtents(w->font, &fontextents);
108         char_height = fontextents.max_ink_extent.height;
109
110         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
111
112         if (!selection_active (sel)) return;
113
114         j = sel->col;
115         k = sel->row;
116
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);
122
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;
127
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);
139                         else 
140                                 gr_make_grayshade(c->xcontext, x, y, wi+1, h, 
141                                                 LIGHTGREY);
142                 }
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, 
146                                         wi+1, h, 50);
147                         else
148                                 gr_make_rgbcolor(c->xcontext, cms, x, y, wi+1, h, 
149                                                 MIDGREY, MIDGREY, MIDGREY);
150                 }
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);
154                         else 
155                                 gr_make_grayshade(c->xcontext, x, y, wi+1, h, 
156                                                 DIMGREY);
157                 }
158                 /* compensate for grid line pixel */ 
159                 if (i == (index+BOX_SEG-2))
160                         y += (h-1);
161                 else
162                         y += h;
163         }
164         deactivate_selection (sel);
165 }
166
167 /* selects day in chart */
168 extern void
169 weekchart_select(Calendar *c)
170 {
171         int i, j, chart_x, chart_y;
172         Week *w = (Week *)c->view->week_info;
173         Selection *sel  = (Selection *) w->current_selection;
174         Colormap cms;
175         Pixel background_pixel;
176         XFontSetExtents fontextents;
177         int     char_height;
178
179         CalFontExtents(w->font, &fontextents);
180         char_height = fontextents.max_ink_extent.height;
181
182         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
183         /*
184         XtVaGetValues(c->frame, XmNbackground, &background_pixel, NULL);
185         */
186         background_pixel = c->xcontext->hilight_color;
187
188         i = sel->col;
189         j = sel->row;
190         if (j >= 0) {
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);
201                 }
202                 else  { 
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,
209                                 cms);
210
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);
215                 }
216                 sel->nunits = 1;
217                 activate_selection(sel);
218         }
219 }
220
221 /* selects day is main boxes: not chart */
222 static void
223 select_weekday(Calendar *c, Boolean select)
224 {
225         int     n, x, y;
226         new_XContext*xc     = c->xcontext;
227         Week    *w = (Week *)c->view->week_info;
228         Pixel foreground_pixel;
229
230
231         foreground_pixel = xc->hilight_color;
232
233         /* Draw selection feedback on week view */
234         (n = dow(c->view->date)) == 0 ? n = 6 : n--;
235
236         if (n < 5) {
237                 x = w->x + n * w->day_width + 2;
238                 y = w->y + w->label_height + 2;
239         } else {
240                 n -= (5 - 3);
241                 x = w->x + n * w->day_width + 2;
242                 y = w->y + w->day_height + w->label_height + 2;
243         }
244  
245         if (select) {
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);
249                 }
250                 else {
251                         Colormap cms;
252
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);
257                 }
258                 weekchart_select(c);
259         } else {
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);
265         }
266  
267 }
268
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.              */
274
275 extern void
276 calendar_select (Calendar *c, Selection_unit unit, caddr_t ref)
277 {
278         int i, j;
279         int xpos, boxw, boxh, margin, topoff, date;
280         Selection *sel;
281         new_XContext *xc;
282         Colormap cms;
283         Pixel foreground_pixel;
284         int dayname_height;
285
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;
292         xc      = c->xcontext;
293
294         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
295         /*
296         XtVaGetValues(c->canvas, XmNforeground, &foreground_pixel, NULL);
297         */
298         foreground_pixel = xc->hilight_color;
299         switch (unit) {
300                 /* day selection on month glance */
301                 case daySelect:
302                         dayname_height = ((Month *) c->view->month_info)->dayname_height;
303                         i=dow(date);
304                         j=wom(date);
305                         if (j >= 0) {
306                                 sel->row=j-1;
307                                 sel->col=i;
308                                 sel->nunits=1;
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);
313                                 else {
314                                         gr_draw_rgb_box(xc, (i*boxw)
315                                                 +margin, 
316                                                 (sel->row*boxh)+topoff+
317                                                 dayname_height, boxw, 
318                                                 boxh, STDTTT,
319                                                 foreground_pixel, cms);
320                                 }
321                                 activate_selection (sel);
322
323                         }
324                         break;
325                 /* week selection on month glance view */
326                 case weekSelect:
327 #ifdef NEVER
328                         i=0; j=7;
329                         sel->row=(int)ref;
330                         sel->col=i;
331                         sel->nunits=j-i;
332                         while (i < j) {
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);
337                                 else {
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, 
344                                         boxw-2, boxh-2, 1,
345                                         foreground_pixel, cms);
346                                 }
347                                 i++;
348                         }
349                         activate_selection (sel);
350 #endif
351                         break;
352                 /* month selection on year glance view */
353                 case monthSelect:
354                         if (ref != NULL) {
355                                 i=((pr_pos *)ref)->x;
356                                 j=((pr_pos *)ref)->y;
357                         }
358                         else {
359                                 i = sel->col;
360                                 j = sel->row;
361                         }
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);
365                         else {
366                                 if (i == 0)
367                                        xpos = margin-5;
368                                 else if (i == 1)
369                                         xpos = i*(boxw-18);
370                                 else
371                                         xpos = i*(boxw-24);
372 /*
373                                 gr_draw_rgb_box(xc, xpos,
374                                         j*boxh+topoff+10, boxw-2, boxh-2, 1,
375                                         foreground_pixel, cms);
376 */
377                                 gr_draw_rgb_box(xc, xpos,
378                                         j*boxh+topoff+10, boxw-56, boxh+2, STDTTT,
379                                         foreground_pixel, cms);
380                         }
381                         sel->row=j;
382                         sel->col=i;
383                         sel->nunits=1;
384                         activate_selection (sel);
385                         break;
386                 /* hour box selection day glance view */
387                 case hourSelect:
388                         if (ref != NULL)
389                                 j=((pr_pos *)ref)->y;
390                         else
391                                 j = sel->row;
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);
396                         else {
397                                 gr_draw_rgb_box(xc, MOBOX_AREA_WIDTH+3,
398                                         j*boxh+topoff, 
399                                         c->view->boxw - 2,
400                                         c->view->boxh,
401                                         STDTTT,
402                                         foreground_pixel, cms);
403                         }
404                         sel->row=j;
405                         sel->col=MOBOX_AREA_WIDTH+4;
406                         sel->nunits=1;
407                         activate_selection(sel);
408                         break;
409                 /* day selection on week glance */
410                 case weekdaySelect:
411                         select_weekday(c, True);
412                         activate_selection (sel);
413                         break;
414                 /* hotbox selection on week glance */
415                 case weekhotboxSelect:
416                         select_weekhotbox(c);
417                         activate_selection (sel);
418                         break;
419                 default:
420                         break;
421         }
422 /*
423         common_update_lists(c);
424 */
425 }
426         
427 extern void
428 calendar_deselect (Calendar *c)
429 {
430         int             i, j, k, xpos;
431         int             x, y;
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;
439         int             dayname_height;
440         int             nop;
441         Cal_Font        *pf = c->fonts->boldfont;
442         Props           *p = (Props*)c->properties;
443         DisplayType     disp_t = get_int_prop(p, CP_DEFAULTDISP);
444
445         if (selection_active(s)) {
446                 j=s->col;
447                 k=s->row;
448                 switch(c->view->glance) {
449                 case weekGlance:
450                         select_weekday(c, False);
451                         deactivate_selection (s);
452                         break;
453                 case dayGlance: {
454                         int     hrbox_margin;
455                         int     num_hrs = get_int_prop(p, CP_DAYEND) -
456                                           get_int_prop(p, CP_DAYBEGIN) + 1;
457
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;
463
464                                 gr_draw_line(xc, x, y, x + boxw, y,
465                                                 gr_solid, NULL);
466                                 y += boxh;
467                                 gr_draw_line(xc, x, y, x + boxw, y, 
468                                                 gr_solid, NULL);
469                         }
470
471                         if (disp_t == HOUR12)
472                                 CalTextExtents(pf, "12pm", 4, &nop, &nop, 
473                                                            &hrbox_margin, &nop);
474                         else
475                                 CalTextExtents(pf, "24 ", 3, &nop, &nop, 
476                                                            &hrbox_margin, &nop);
477
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, 
482                         gr_solid, NULL);
483                         break;
484                 }
485                 case monthGlance:
486                         dayname_height = 
487                                 ((Month *) c->view->month_info)->dayname_height;
488
489                         for (i=0; i<nunits; i++) {
490                                 gr_dissolve_box(xc,
491                                         (j * boxw) + margin + 1, 
492                                         (k * boxh) + topoff + dayname_height + 1,
493                                         boxw - 2, boxh - 2, 2);
494                                 gr_draw_box(xc,
495                                         (j * boxw) + margin, 
496                                         (k * boxh) + topoff + dayname_height,
497                                         boxw, boxh, NULL);
498                                 j++;
499                         }
500                         break;
501                 case yearGlance:
502                         for (i=0; i<nunits; i++) {
503                                 if (j == 0)
504                                        xpos = margin-5;
505                                 else if (j == 1)
506                                         xpos = j*(boxw-18);
507                                 else
508                                         xpos = j*(boxw-24);
509
510 /*
511                                 gr_dissolve_box(xc, (j*boxw)+margin+10,
512                                         k*boxh+topoff-5,
513                                         boxw-2, boxh-2, 1);
514 */
515                                 gr_dissolve_box(xc, xpos, 
516                                    k*boxh+topoff+10, boxw-56, boxh+2, 1);
517
518 /*
519                                 gr_dissolve_box(xc, (j*boxw)+margin+11,
520                                         k*boxh+topoff-4,
521                                         boxw-2, boxh-2, 1);
522 */
523                                 j++;
524                         }
525                         break;
526                 }
527                 deactivate_selection (s);
528         }
529 }
530 extern void
531 monthbox_deselect(Calendar *c)
532 {
533         char buf[3];
534         Day *day_info = (Day *)c->view->day_info;
535         int x, y;
536
537         if (day_info->day_selected == -1)
538                 return;
539
540         x = day_info->day_selected_x + 2;
541         y = day_info->day_selected_y + 2;
542
543         if (c->xcontext->screen_depth < 8)
544                 gr_make_gray(c->xcontext, 
545                         x,
546                         y,
547                         day_info->col_w+1,
548                         day_info->row_h-1, 25);
549         else
550                 gr_make_grayshade(c->xcontext, 
551                         x,
552                         y,
553                         day_info->col_w+1,
554                         day_info->row_h-1, LIGHTGREY);
555         buf [0] = '\0';
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);
560 }
561 extern void
562 monthbox_select(Calendar *c)
563 {
564         char buf[3];
565         Day *day_info = (Day *)c->view->day_info;
566         int x, y;
567
568         x = day_info->day_selected_x + 2;
569         y = day_info->day_selected_y + 2;
570
571         gr_clear_box(c->xcontext, 
572                         x,
573                         y,
574                         day_info->col_w,
575                         day_info->row_h-3);
576         gr_draw_box(c->xcontext,
577                         x,
578                         y,
579                         day_info->col_w,
580                         day_info->row_h-3, NULL);
581         buf [0] = '\0';
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);
586 }
587
588 extern void
589 browser_deselect (Calendar *c, Browser *b)
590 {
591         int h, i, j, k, index, w, x, y;
592         Selection *sel  = (Selection *) b->current_selection;
593         Colormap cms;
594
595         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
596         if (!selection_active (sel))
597                 return;
598         j = sel->col;
599         k = sel->row;
600         x =  (j*b->boxw) +  b->chart_x + 1;
601         y =  (k*b->boxh) + b->chart_y + 1;
602         h =  (b->boxh/BOX_SEG);
603         w =  b->boxw-2;
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, 
610                                                         h, 25);
611                         else 
612                                 gr_make_grayshade(b->xcontext, x, y, 
613                                         w+1, h, LIGHTGREY);
614                 }
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, 
618                                         w+1, h, 50);
619                         else
620                                 gr_make_rgbcolor(b->xcontext, cms, x, y, 
621                                         w+1, h, MIDGREY, MIDGREY, MIDGREY);
622                 }
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, 
626                                         w+1, h, 75);
627                         else 
628                                 gr_make_grayshade(b->xcontext, x, y, 
629                                         w+1, h, DIMGREY);
630                 }
631                 /* compensate for grid line pixel */ 
632                 if (i == (index+BOX_SEG-2))
633                         y += (h-1);
634                 else
635                         y += h;
636         }
637         deactivate_selection (sel);
638 }
639
640
641 extern void
642 browser_select(Calendar *c, Browser *b, pr_pos *xy)
643 {
644         int i, j;
645         Selection *sel  = (Selection *) b->current_selection;
646         Colormap cms;
647         Pixel pixel;
648
649         if (xy != NULL) {
650                 i = xy->x;
651                 j = xy->y;
652         }
653         else {
654                 i = sel->col;
655                 j = sel->row;
656         }
657         if (j >= 0) {
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);
662                 }
663                 else {
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,
669                                 pixel, cms);
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,
673                                 pixel, cms);
674                 }
675                 sel->row = j;
676                 sel->col = i;
677                 sel->nunits = 1;
678                 activate_selection(sel);
679         }
680 }
681
682 static void
683 select_weekhotbox(Calendar *c)
684 {
685         int     n, x, y;
686         new_XContext*xc     = c->xcontext;
687         Week *w = (Week *)c->view->week_info;
688         long    date    = c->view->date;
689         Colormap        cms;
690         Pixel background_pixel;
691
692         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
693         XtVaGetValues(c->frame, XmNbackground, &background_pixel, NULL);
694
695         /* Draw selection feedback on week view */
696         if ((n = dow(date)) == 0)
697                 n = 6;
698         else
699                 n--;
700
701         if (n < 5) {
702                 x = w->x + n * w->day_width + 2;
703                 y = w->y + 2;
704         }
705         else {
706                 n -= (5 - 3);
707                 x = w->x + n * w->day_width + 2;
708                 y = w->y + w->day_height + 2;
709         }
710  
711         if (c->xcontext->screen_depth < 8)
712                 gr_draw_box(xc, x, y, w->day_width - 4, w->label_height - 4, NULL);
713         else {
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);
720         }
721 }
722
723 extern void
724 paint_selection(Calendar *c)
725 {
726         Props  *p = (Props*)c->properties;
727         Selection *sel;
728         int d, mo, beg = get_int_prop(p, CP_DAYBEGIN);
729         Week *w = (Week *)c->view->week_info;
730         pr_pos xy;
731
732         switch ((Glance)c->view->glance) {
733                 case monthGlance:
734                         calendar_select(c, daySelect, (caddr_t)NULL);
735                         break;
736                 case dayGlance:
737                         sel = (Selection *) c->view->current_selection;
738                         sel->row = hour(c->view->date) - beg + 1;
739                         calendar_select(c, hourSelect, (caddr_t)NULL);
740                         break;
741                 case weekGlance:
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);
745                         break;
746                 case yearGlance:
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);
751                         break;
752         }
753 }