Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtcm / dtcm / select.c
1 /*******************************************************************************
2 **
3 **  select.c
4 **
5 **  $TOG: select.c /main/4 1998/08/18 17:32:33 samborn $
6 **
7 **  RESTRICTED CONFIDENTIAL INFORMATION:
8 **
9 **  The information in this document is subject to special
10 **  restrictions in a confidential disclosure agreement between
11 **  HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
12 **  document outside HP, IBM, Sun, USL, SCO, or Univel without
13 **  Sun's specific written approval.  This document and all copies
14 **  and derivative works thereof must be returned or destroyed at
15 **  Sun's request.
16 **
17 **  Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
18 **
19 *******************************************************************************/
20
21 /*                                                                      *
22  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
23  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
24  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
25  * (c) Copyright 1993, 1994 Novell, Inc.                                *
26  */
27
28 #ifndef lint
29 static  char sccsid[] = "@(#)select.c 1.24 95/02/21 Copyr 1994 Sun Microsystems, Inc.";
30 #endif
31
32 #include <EUSCompat.h>
33 #include <stdio.h>
34 #include <Xm/Xm.h>
35 #include "util.h"
36 #include "select.h"
37 /*
38 #include "graphics.h"
39 */
40 #include "calendar.h"
41 #include "timeops.h"
42 #include "browser.h"
43 #include "todo.h"
44 #include "dayglance.h"
45 #include "weekglance.h"
46 #include "monthglance.h"
47 #include "yearglance.h"
48 #include "datefield.h"
49 #include "props.h"
50
51 static void select_weekhotbox();
52
53
54 extern int
55 selection_active (Selection *s)
56 {
57         return (s->active);
58 }
59
60 extern void
61 deactivate_selection (Selection *s)
62 {
63         s->active=0;
64 }
65
66 extern void
67 activate_selection (Selection *s)
68 {
69         s->active=1;
70 }
71
72 extern void
73 weekchart_deselect(Calendar *c)
74 {
75         int h, i, j, k, index, wi, x, y, chart_x, chart_y;
76         Week *w = (Week *)c->view->week_info;
77         Selection *sel  = (Selection *) w->current_selection;
78         XFontSetExtents fontextents;
79         int     char_height;
80         Colormap cms;
81
82         CalFontExtents(w->font, &fontextents);
83         char_height = fontextents.max_ink_extent.height;
84
85         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
86
87         if (!selection_active (sel)) return;
88
89         j = sel->col;
90         k = sel->row;
91
92         /* dissolves box around weekday letter over chart */
93         chart_x = w->chart_x + (j * w->chart_day_width);
94         chart_y = w->chart_y - char_height - 4;
95         gr_dissolve_box(c->xcontext, chart_x, chart_y - 6,
96                                 w->chart_day_width, char_height + 6, 2);
97
98         x =  (j*w->chart_day_width) +  w->chart_x + 1;
99         y =  (k * (w->chart_hour_height + w->add_pixels)) +  w->chart_y + 1;
100         h =  (w->chart_hour_height/BOX_SEG);
101         wi =  w->chart_day_width-2;
102
103         gr_clear_area(c->xcontext, x, y, w->chart_day_width-1, 
104                         w->chart_hour_height-1 + w->add_pixels);
105         gr_draw_box(c->xcontext, x - 1, y - 1, w->chart_day_width, 
106                         w->chart_hour_height + w->add_pixels, NULL);
107         index = j * (w->segs_in_array / 7) + (BOX_SEG * k);
108         for (i = index;  i < (index + BOX_SEG); i++) {
109                 /* compensate for the added pixel for displaying chart */
110                 if ((i+1) == (index + BOX_SEG)) h += w->add_pixels;
111                 if (w->time_array[i] == 1) {
112                         if ((c->xcontext->screen_depth < 8)  || FAKE_MONOCHROME)
113                                 gr_make_gray(c->xcontext, x, y, wi+1, h, 25);
114                         else 
115                                 gr_make_grayshade(c->xcontext, x, y, wi+1, h, 
116                                                 LIGHTGREY);
117                 }
118                 else if (w->time_array[i] == 2) {
119                         if ((c->xcontext->screen_depth < 8)  || FAKE_MONOCHROME)
120                                 gr_make_gray(c->xcontext, x, y, 
121                                         wi+1, h, 50);
122                         else
123                                 gr_make_rgbcolor(c->xcontext, cms, x, y, wi+1, h, 
124                                                 MIDGREY, MIDGREY, MIDGREY);
125                 }
126                 else if (w->time_array[i] >= 3) {
127                         if ((c->xcontext->screen_depth < 8)  || FAKE_MONOCHROME)
128                                 gr_make_gray(c->xcontext, x, y, wi+1, h, 75);
129                         else 
130                                 gr_make_grayshade(c->xcontext, x, y, wi+1, h, 
131                                                 DIMGREY);
132                 }
133                 /* compensate for grid line pixel */ 
134                 if (i == (index+BOX_SEG-2))
135                         y += (h-1);
136                 else
137                         y += h;
138         }
139         deactivate_selection (sel);
140 }
141
142 /* selects day in chart */
143 extern void
144 weekchart_select(Calendar *c)
145 {
146         int i, j, chart_x, chart_y;
147         Week *w = (Week *)c->view->week_info;
148         Selection *sel  = (Selection *) w->current_selection;
149         Colormap cms;
150         Pixel background_pixel;
151         XFontSetExtents fontextents;
152         int     char_height;
153
154         CalFontExtents(w->font, &fontextents);
155         char_height = fontextents.max_ink_extent.height;
156
157         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
158         /*
159         XtVaGetValues(c->frame, XmNbackground, &background_pixel, NULL);
160         */
161         background_pixel = c->xcontext->hilight_color;
162
163         i = sel->col;
164         j = sel->row;
165         if (j >= 0) {
166                 chart_x = w->chart_x + (i * w->chart_day_width);
167                 chart_y = w->chart_y - char_height - 4;
168                 if (c->xcontext->screen_depth < 8) {
169                         gr_draw_box(c->xcontext, (i * w->chart_day_width) +
170                                 w->chart_x + 1, (j * w->chart_hour_height) + 
171                                 (j * w->add_pixels) + w->chart_y + 1, 
172                                 w->chart_day_width - 2, 
173                                 w->chart_hour_height - 2 + w->add_pixels, NULL);
174                         gr_draw_box(c->xcontext, chart_x, chart_y, 
175                                 w->chart_day_width, char_height + 1, NULL);
176                 }
177                 else  { 
178                         /* Select time slot */
179                         gr_draw_rgb_box(c->xcontext, (i * w->chart_day_width)
180                                 + w->chart_x, (j * w->chart_hour_height) 
181                                 + (j * w->add_pixels) + w->chart_y, 
182                                 w->chart_day_width, w->chart_hour_height
183                                 + w->add_pixels, 1,  background_pixel, cms);
184
185                         /* Select weekday letter over chart */
186                         gr_draw_rgb_box(c->xcontext, chart_x, chart_y - 6,
187                                 w->chart_day_width, char_height + 6, 1,
188                                 background_pixel, cms);
189                 }
190                 sel->nunits = 1;
191                 activate_selection(sel);
192         }
193 }
194
195 /* selects day is main boxes: not chart */
196 static void
197 select_weekday(Calendar *c, Boolean select)
198 {
199         int     n, x, y;
200         new_XContext*xc     = c->xcontext;
201         Week    *w = (Week *)c->view->week_info;
202         Pixel foreground_pixel;
203
204
205         foreground_pixel = xc->hilight_color;
206
207         /* Draw selection feedback on week view */
208         (n = dow(c->view->date)) == 0 ? n = 6 : n--;
209
210         if (n < 5) {
211                 x = w->x + n * w->day_width + 2;
212                 y = w->y + w->label_height + 2;
213         } else {
214                 n -= (5 - 3);
215                 x = w->x + n * w->day_width + 2;
216                 y = w->y + w->day_height + w->label_height + 2;
217         }
218  
219         if (select) {
220                 if (c->xcontext->screen_depth < 8) {
221                         gr_draw_box(xc, x, y, w->day_width - 2,
222                         w->day_height - w->label_height - 2, NULL);
223                 }
224                 else {
225                         Colormap cms;
226
227                         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
228                         gr_draw_rgb_box(xc, x - 2, y - 2, w->day_width,
229                                         w->day_height - w->label_height, 1,
230                                         foreground_pixel, cms);
231                 }
232                 weekchart_select(c);
233         } else {
234                 gr_draw_box(xc, x - 2, y - 2, w->day_width,
235                             w->day_height - w->label_height, NULL);
236                 gr_dissolve_box(xc, x - 1, y - 1, w->day_width - 2,
237                                  w->day_height - w->label_height - 2, 2);
238                 weekchart_deselect(c);
239         }
240  
241 }
242
243 /*      selection service for all views.  ref is a client_data
244         field which is cast depending on the selection unit.  if
245         it's a daySelect, ref contains the number of weeks in the
246         month.  if it's a monthSelect, ref contains a point to x,y
247         coordinates.  ref is NULL on a weekSelect.              */
248
249 extern void
250 calendar_select (Calendar *c, Selection_unit unit, caddr_t ref)
251 {
252         int i, j;
253         int xpos, boxw, boxh, margin, topoff, date;
254         Selection *sel;
255         new_XContext *xc;
256         Colormap cms;
257         Pixel foreground_pixel;
258         int dayname_height;
259
260         date    = c->view->date;
261         sel     = (Selection *) c->view->current_selection;
262         boxw    = c->view->boxw;
263         boxh    = c->view->boxh;
264         margin  = c->view->outside_margin;
265         topoff  = c->view->topoffset;
266         xc      = c->xcontext;
267
268         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
269         /*
270         XtVaGetValues(c->canvas, XmNforeground, &foreground_pixel, NULL);
271         */
272         foreground_pixel = xc->hilight_color;
273         switch (unit) {
274                 /* day selection on month glance */
275                 case daySelect:
276                         dayname_height = ((Month *) c->view->month_info)->dayname_height;
277                         i=dow(date);
278                         j=wom(date);
279                         if (j >= 0) {
280                                 sel->row=j-1;
281                                 sel->col=i;
282                                 sel->nunits=1;
283                                 if (c->xcontext->screen_depth < 8) 
284                                         gr_draw_box(xc, (i*boxw)+margin+
285                                         1, (sel->row*boxh)+topoff+
286                                         dayname_height+1, boxw-2, boxh-2, NULL);
287                                 else {
288                                         gr_draw_rgb_box(xc, (i*boxw)
289                                                 +margin, 
290                                                 (sel->row*boxh)+topoff+
291                                                 dayname_height, boxw, 
292                                                 boxh, 1,
293                                                 foreground_pixel, cms);
294                                 }
295                                 activate_selection (sel);
296
297                         }
298                         break;
299                 /* week selection on month glance view */
300                 case weekSelect:
301 #ifdef NEVER
302                         i=0; j=7;
303                         sel->row=(int)ref;
304                         sel->col=i;
305                         sel->nunits=j-i;
306                         while (i < j) {
307                                 if (c->xcontext->screen_depth < 8) 
308                                         gr_draw_box(xc, i*boxw+margin+1,
309                                         (int)ref*boxh+margin+topoff+1, 
310                                         boxw-2, boxh-2, NULL);
311                                 else {
312                                         gr_draw_rgb_box(xc, i*boxw+margin+2,
313                                         (int)ref*boxh+margin+topoff+2, 
314                                         boxw-4, boxh-4, 1,
315                                         foreground_pixel, cms);
316                                         gr_draw_rgb_box(xc, i*boxw+margin+1,
317                                         (int)ref*boxh+margin+topoff+1, 
318                                         boxw-2, boxh-2, 1,
319                                         foreground_pixel, cms);
320                                 }
321                                 i++;
322                         }
323                         activate_selection (sel);
324 #endif
325                         break;
326                 /* month selection on year glance view */
327                 case monthSelect:
328                         if (ref != NULL) {
329                                 i=((pr_pos *)ref)->x;
330                                 j=((pr_pos *)ref)->y;
331                         }
332                         else {
333                                 i = sel->col;
334                                 j = sel->row;
335                         }
336                         if (c->xcontext->screen_depth < 8) 
337                                 gr_draw_box(xc, i*boxw+margin+10,
338                                         j*boxh+topoff-4, boxw-4, boxh-4, NULL);
339                         else {
340                                 if (i == 0)
341                                        xpos = margin-5;
342                                 else if (i == 1)
343                                         xpos = i*(boxw-18);
344                                 else
345                                         xpos = i*(boxw-24);
346 /*
347                                 gr_draw_rgb_box(xc, xpos,
348                                         j*boxh+topoff+10, boxw-2, boxh-2, 1,
349                                         foreground_pixel, cms);
350 */
351                                 gr_draw_rgb_box(xc, xpos,
352                                         j*boxh+topoff+10, boxw-56, boxh+2, 1,
353                                         foreground_pixel, cms);
354                         }
355                         sel->row=j;
356                         sel->col=i;
357                         sel->nunits=1;
358                         activate_selection (sel);
359                         break;
360                 /* hour box selection day glance view */
361                 case hourSelect:
362                         if (ref != NULL)
363                                 j=((pr_pos *)ref)->y;
364                         else
365                                 j = sel->row;
366                         if (c->xcontext->screen_depth < 8) 
367                                 gr_draw_box(xc, MOBOX_AREA_WIDTH+5,
368                                         j*boxh+topoff+1, c->view->boxw-4,
369                                         c->view->boxh-2, NULL);
370                         else {
371                                 gr_draw_rgb_box(xc, MOBOX_AREA_WIDTH+3,
372                                         j*boxh+topoff, 
373                                         c->view->boxw - 2,
374                                         c->view->boxh,
375                                         1,
376                                         foreground_pixel, cms);
377                         }
378                         sel->row=j;
379                         sel->col=MOBOX_AREA_WIDTH+4;
380                         sel->nunits=1;
381                         activate_selection(sel);
382                         break;
383                 /* day selection on week glance */
384                 case weekdaySelect:
385                         select_weekday(c, True);
386                         activate_selection (sel);
387                         break;
388                 /* hotbox selection on week glance */
389                 case weekhotboxSelect:
390                         select_weekhotbox(c);
391                         activate_selection (sel);
392                         break;
393                 default:
394                         break;
395         }
396 /*
397         common_update_lists(c);
398 */
399 }
400         
401 extern void
402 calendar_deselect (Calendar *c)
403 {
404         int             i, j, k, xpos;
405         int             x, y;
406         int             boxh = c->view->boxh;
407         int             boxw = c->view->boxw;
408         int             margin = c->view->outside_margin;
409         int             topoff = c->view->topoffset;
410         Selection       *s = (Selection *) c->view->current_selection;
411         int             nunits = s->nunits;
412         new_XContext    *xc = c->xcontext;
413         int             dayname_height;
414         int             nop;
415         Cal_Font        *pf = c->fonts->boldfont;
416         Props           *p = (Props*)c->properties;
417         DisplayType     disp_t = get_int_prop(p, CP_DEFAULTDISP);
418
419         if (selection_active(s)) {
420                 j=s->col;
421                 k=s->row;
422                 switch(c->view->glance) {
423                 case weekGlance:
424                         select_weekday(c, False);
425                         deactivate_selection (s);
426                         break;
427                 case dayGlance: {
428                         int     hrbox_margin;
429                         int     num_hrs = get_int_prop(p, CP_DAYEND) -
430                                           get_int_prop(p, CP_DAYBEGIN) + 1;
431
432                         for (i=0; i < nunits; i++) {
433                                 gr_dissolve_box(xc, MOBOX_AREA_WIDTH+3,
434                                          k*boxh+topoff + 1, boxw-3, boxh-2, 3);
435                                 x = MOBOX_AREA_WIDTH + 2;
436                                 y = k * boxh + topoff;
437
438                                 gr_draw_line(xc, x, y, x + boxw, y,
439                                                 gr_solid, NULL);
440                                 y += boxh;
441                                 gr_draw_line(xc, x, y, x + boxw, y, 
442                                                 gr_solid, NULL);
443                         }
444
445                         if (disp_t == HOUR12)
446                                 CalTextExtents(pf, "12pm", 4, &nop, &nop, 
447                                                            &hrbox_margin, &nop);
448                         else
449                                 CalTextExtents(pf, "24 ", 3, &nop, &nop, 
450                                                            &hrbox_margin, &nop);
451
452                         /* draw vertical line */
453                         gr_draw_line(xc, MOBOX_AREA_WIDTH+2+hrbox_margin,
454                         c->view->topoffset, MOBOX_AREA_WIDTH+2+hrbox_margin,
455                         c->view->topoffset + num_hrs * c->view->boxh, 
456                         gr_solid, NULL);
457                         break;
458                 }
459                 case monthGlance:
460                         dayname_height = 
461                                 ((Month *) c->view->month_info)->dayname_height;
462
463                         for (i=0; i<nunits; i++) {
464                                 gr_dissolve_box(xc,
465                                         (j * boxw) + margin + 1, 
466                                         (k * boxh) + topoff + dayname_height + 1,
467                                         boxw - 2, boxh - 2, 2);
468                                 gr_draw_box(xc,
469                                         (j * boxw) + margin, 
470                                         (k * boxh) + topoff + dayname_height,
471                                         boxw, boxh, NULL);
472                                 j++;
473                         }
474                         break;
475                 case yearGlance:
476                         for (i=0; i<nunits; i++) {
477                                 if (j == 0)
478                                        xpos = margin-5;
479                                 else if (j == 1)
480                                         xpos = j*(boxw-18);
481                                 else
482                                         xpos = j*(boxw-24);
483
484 /*
485                                 gr_dissolve_box(xc, (j*boxw)+margin+10,
486                                         k*boxh+topoff-5,
487                                         boxw-2, boxh-2, 1);
488 */
489                                 gr_dissolve_box(xc, xpos, 
490                                    k*boxh+topoff+10, boxw-56, boxh+2, 1);
491
492 /*
493                                 gr_dissolve_box(xc, (j*boxw)+margin+11,
494                                         k*boxh+topoff-4,
495                                         boxw-2, boxh-2, 1);
496 */
497                                 j++;
498                         }
499                         break;
500                 }
501                 deactivate_selection (s);
502         }
503 }
504 extern void
505 monthbox_deselect(Calendar *c)
506 {
507         char buf[3];
508         Day *day_info = (Day *)c->view->day_info;
509         int x, y;
510
511         if (day_info->day_selected == -1)
512                 return;
513
514         x = day_info->day_selected_x + 2;
515         y = day_info->day_selected_y + 2;
516
517         if (c->xcontext->screen_depth < 8)
518                 gr_make_gray(c->xcontext, 
519                         x,
520                         y,
521                         day_info->col_w+1,
522                         day_info->row_h-1, 25);
523         else
524                 gr_make_grayshade(c->xcontext, 
525                         x,
526                         y,
527                         day_info->col_w+1,
528                         day_info->row_h-1, LIGHTGREY);
529         buf [0] = '\0';
530         sprintf(buf, "%d", day_info->day_selected);
531         gr_text(c->xcontext, day_info->day_selected_x2+2, 
532                         day_info->day_selected_y2, 
533                         c->fonts->viewfont, buf, NULL);
534 }
535 extern void
536 monthbox_select(Calendar *c)
537 {
538         char buf[3];
539         Day *day_info = (Day *)c->view->day_info;
540         int x, y;
541
542         x = day_info->day_selected_x + 2;
543         y = day_info->day_selected_y + 2;
544
545         gr_clear_box(c->xcontext, 
546                         x,
547                         y,
548                         day_info->col_w,
549                         day_info->row_h-3);
550         gr_draw_box(c->xcontext,
551                         x,
552                         y,
553                         day_info->col_w,
554                         day_info->row_h-3, NULL);
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
562 extern void
563 browser_deselect (Calendar *c, Browser *b)
564 {
565         int h, i, j, k, index, w, x, y;
566         Selection *sel  = (Selection *) b->current_selection;
567         Colormap cms;
568
569         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
570         if (!selection_active (sel))
571                 return;
572         j = sel->col;
573         k = sel->row;
574         x =  (j*b->boxw) +  b->chart_x + 1;
575         y =  (k*b->boxh) + b->chart_y + 1;
576         h =  (b->boxh/BOX_SEG);
577         w =  b->boxw-2;
578         gr_clear_area(b->xcontext, x, y, b->boxw-1, b->boxh-1);
579         index = j * (b->segs_in_array / 7) + (BOX_SEG * k);
580         for (i = index;  i < (index + BOX_SEG); i++) {
581                 if (b->multi_array[i] == 1) {
582                         if ((c->xcontext->screen_depth < 8)  || FAKE_MONOCHROME)
583                                 gr_make_gray(b->xcontext, x, y, w+1, 
584                                                         h, 25);
585                         else 
586                                 gr_make_grayshade(b->xcontext, x, y, 
587                                         w+1, h, LIGHTGREY);
588                 }
589                 else if (b->multi_array[i] == 2) {
590                         if ((c->xcontext->screen_depth < 8)  || FAKE_MONOCHROME)
591                                 gr_make_gray(b->xcontext, x, y, 
592                                         w+1, h, 50);
593                         else
594                                 gr_make_rgbcolor(b->xcontext, cms, x, y, 
595                                         w+1, h, MIDGREY, MIDGREY, MIDGREY);
596                 }
597                 else if (b->multi_array[i] >= 3) {
598                         if ((c->xcontext->screen_depth < 8)  || FAKE_MONOCHROME)
599                                 gr_make_gray(b->xcontext, x, y, 
600                                         w+1, h, 75);
601                         else 
602                                 gr_make_grayshade(b->xcontext, x, y, 
603                                         w+1, h, DIMGREY);
604                 }
605                 /* compensate for grid line pixel */ 
606                 if (i == (index+BOX_SEG-2))
607                         y += (h-1);
608                 else
609                         y += h;
610         }
611         deactivate_selection (sel);
612 }
613
614
615 extern void
616 browser_select(Calendar *c, Browser *b, pr_pos *xy)
617 {
618         int i, j;
619         Selection *sel  = (Selection *) b->current_selection;
620         Colormap cms;
621         Pixel pixel;
622
623         if (xy != NULL) {
624                 i = xy->x;
625                 j = xy->y;
626         }
627         else {
628                 i = sel->col;
629                 j = sel->row;
630         }
631         if (j >= 0) {
632                 if (c->xcontext->screen_depth < 8) {
633                         gr_draw_box(b->xcontext, (i * b->boxw) + 
634                                 b->chart_x + 2, (j * b->boxh) + b->chart_y 
635                                 + 2, b->boxw - 4, b->boxh - 4, NULL);
636                 }
637                 else {
638                         pixel = c->xcontext->hilight_color;
639                         XtVaGetValues(b->canvas, XmNcolormap, &cms, NULL);
640                         gr_draw_rgb_box(b->xcontext, (i * b->boxw) + 
641                                 b->chart_x + 2, (j * b->boxh) + b->chart_y 
642                                 + 2, b->boxw - 4, b->boxh - 4, 1,
643                                 pixel, cms);
644                         gr_draw_rgb_box(b->xcontext, (i * b->boxw) + 
645                                 b->chart_x + 1, (j * b->boxh) + b->chart_y 
646                                 + 1, b->boxw - 2, b->boxh - 2, 1,
647                                 pixel, cms);
648                 }
649                 sel->row = j;
650                 sel->col = i;
651                 sel->nunits = 1;
652                 activate_selection(sel);
653         }
654 }
655
656 static void
657 select_weekhotbox(Calendar *c)
658 {
659         int     n, x, y;
660         new_XContext*xc     = c->xcontext;
661         Week *w = (Week *)c->view->week_info;
662         long    date    = c->view->date;
663         Colormap        cms;
664         Pixel background_pixel;
665
666         XtVaGetValues(c->canvas, XmNcolormap, &cms, NULL);
667         XtVaGetValues(c->frame, XmNbackground, &background_pixel, NULL);
668
669         /* Draw selection feedback on week view */
670         if ((n = dow(date)) == 0)
671                 n = 6;
672         else
673                 n--;
674
675         if (n < 5) {
676                 x = w->x + n * w->day_width + 2;
677                 y = w->y + 2;
678         }
679         else {
680                 n -= (5 - 3);
681                 x = w->x + n * w->day_width + 2;
682                 y = w->y + w->day_height + 2;
683         }
684  
685         if (c->xcontext->screen_depth < 8)
686                 gr_draw_box(xc, x, y, w->day_width - 4, w->label_height - 4, NULL);
687         else {
688                 gr_draw_rgb_box(xc, x, y,
689                                 w->day_width - 4, w->label_height - 4, 1,
690                                 background_pixel, cms);
691                 gr_draw_rgb_box(xc, x-1, y-1,
692                                 w->day_width-2, w->label_height - 2, 1,
693                                 background_pixel, cms);
694         }
695 }
696
697 extern void
698 paint_selection(Calendar *c)
699 {
700         Props  *p = (Props*)c->properties;
701         Selection *sel;
702         int d, mo, beg = get_int_prop(p, CP_DAYBEGIN);
703         Week *w = (Week *)c->view->week_info;
704         pr_pos xy;
705
706         switch ((Glance)c->view->glance) {
707                 case monthGlance:
708                         calendar_select(c, daySelect, (caddr_t)NULL);
709                         break;
710                 case dayGlance:
711                         sel = (Selection *) c->view->current_selection;
712                         sel->row = hour(c->view->date) - beg + 1;
713                         calendar_select(c, hourSelect, (caddr_t)NULL);
714                         break;
715                 case weekGlance:
716                         sel = (Selection*)w->current_selection;
717                         sel->row = hour(c->view->date) - beg;
718                         sel->col =  (d = dow(c->view->date)) == 0 ? 6 : --d;                            calendar_select(c, weekdaySelect, (caddr_t)NULL);
719                         break;
720                 case yearGlance:
721                         mo = month(c->view->date);
722                         xy.y = month_row_col[mo-1][ROW];
723                         xy.x = month_row_col[mo-1][COL];
724                         calendar_select(c, monthSelect, (caddr_t)&xy);
725                         break;
726         }
727 }