home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / calentool / part08 / wpaint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-27  |  7.7 KB  |  277 lines

  1. /*
  2.  * $Header: wpaint.c,v 2.1 89/05/09 14:20:03 billr Exp $
  3.  */
  4. /*
  5.  * wpaint.c
  6.  *
  7.  * Author: Philip Heller, Sun Microsystems. Inc. <terrapin!heller@sun.com>
  8.  *
  9.  * Original source Copyright (C) 1987, Sun Microsystems, Inc.
  10.  *    All Rights Reserved
  11.  * Permission is hereby granted to use and modify this program in source
  12.  * or binary form as long as it is not sold for profit and this copyright
  13.  * notice remains intact.
  14.  *
  15.  *
  16.  * Changes/additions by: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
  17.  *
  18.  * Changes and additions Copyright (C) 1988, 1989 Tektronix, Inc.
  19.  *    All Rights Reserved
  20.  * Permission is hereby granted to use and modify the modifications in source
  21.  * or binary form as long as they are not sold for profit and this copyright
  22.  * notice remains intact.
  23.  */
  24. /***************************************************
  25.  *                           *
  26.  *    Artistic routines that draw in the main    *
  27.  * subwindow for the week display.           *
  28.  *                           *
  29.  ***************************************************/
  30.  
  31. #include <suntool/sunview.h>
  32. #include <suntool/canvas.h>
  33. #include <ctype.h>
  34. #include <stdio.h>
  35. #include "ct.h"
  36. #include "paint.h"
  37.  
  38. extern int week_message_size;
  39.  
  40. /*
  41.  * Routine to draw "Week-at-a-Glance".
  42.  */
  43.  
  44. draw_week()
  45. {
  46.     struct tm Save;
  47.  
  48.     lock_cursors();
  49.     /* destory future appts popup, if it exists */
  50.     if (fframe) {
  51.         window_destroy(fframe);
  52.         fframe = 0;
  53.     }
  54.     fix_current_day();
  55.     Save = current;
  56.     current.tm_mday -= current.tm_wday; /* Sunday of this week */
  57.     fix_current_day();
  58.     if (nr_weekdays < 7) {
  59.         current.tm_mday++;
  60.         fix_current_day();
  61.     }
  62.     working(TRUE);
  63.     get_week_appts();
  64.     working(FALSE);
  65.     pw_batch_on(main_pixwin);
  66.     paint_week_outline();
  67.     paint_week_trim();
  68.     working(TRUE);
  69.     draw_week_appts();
  70.     pw_batch_off(main_pixwin);
  71.     current = Save;
  72.     get_day_appts();
  73.     working(FALSE);
  74.     unlock_cursors();
  75. }
  76.  
  77.  
  78. /* Paint the outline for "Week-at-a-Glance". */
  79. paint_week_outline()
  80. {
  81.     Rect *rect;
  82.         int x, y, i, j, colx;
  83.  
  84.         rect = (Rect *) window_get(canvas, WIN_RECT);
  85.         pw_writebackground(main_pixwin,0,0,rect->r_width,rect->r_height,PIX_CLR);
  86.         startx = (rect->r_width - nr_weekdays*weekslot_width) / 2;
  87.     starty = 10 + (rect->r_height - (N_SLOTS*(weekslot_height+1))) / 2;
  88.  
  89.     First = current;
  90.         for (i=0; i<nr_weekdays; i++) {
  91.                 x = startx + i*weekslot_width;
  92.         y = starty;
  93.                 week_boxes[i].wday_pos.left = x;
  94.                 week_boxes[i].wday_pos.top = y;
  95.                 week_boxes[i].wday_pos.right = x + weekslot_width;
  96.                 week_boxes[i].wday_pos.bottom = starty + N_SLOTS*weekslot_height;
  97.         week_boxes[i].moreb_pos.left = x + (weekslot_width - morebutton->pr_size.x) / 2;
  98.         week_boxes[i].moreb_pos.top = week_boxes[i].wday_pos.bottom + font->pf_defaultsize.y + font->pf_defaultsize.y/2;
  99.         week_boxes[i].moreb_pos.right = week_boxes[i].moreb_pos.left + morebutton->pr_size.x;
  100.         week_boxes[i].moreb_pos.bottom = week_boxes[i].moreb_pos.top + morebutton->pr_size.y;
  101.                 for (j=0; j<N_SLOTS; j++) {
  102.             if (ymd_compare(today, current) == 0)
  103.                 pw_write(main_pixwin,x,y,weekslot_width,
  104.                   weekslot_height,PIX_SRC,weekslot_td_pr,0,0);
  105.             else
  106.                 pw_write(main_pixwin,x,y,weekslot_width,
  107.                   weekslot_height,PIX_SRC,weekslot_pr,0,0);
  108.                         y += weekslot_height;
  109.         }
  110.         current.tm_mday++;
  111.         fix_current_day();
  112.         }
  113.     pw_vector(main_pixwin,startx,starty,startx+nr_weekdays*weekslot_width,starty,PIX_SET,1);
  114.         pw_vector(main_pixwin,startx,y-1,startx+nr_weekdays*weekslot_width,y-1,PIX_SET,1);
  115.     current = First;
  116.     sun_moon_buttons(FALSE);
  117.     print_button(TRUE);
  118. }
  119.  
  120.  
  121. paint_week_trim()
  122. {
  123.     int i, j, x, y, month, day, rightx;
  124.         char c[7];
  125.         
  126.     First = current;
  127.         c[3] = '\0';            /* Mon Tue Wed Thu Fri */
  128.         for (i=0; i<nr_weekdays; i++) {
  129.                 x = startx + i*weekslot_width + (weekslot_width - 2*(font->pf_defaultsize.x+2))/2;
  130.         sprintf(c, "%3.3s", daynames[First.tm_wday + i]);
  131.                 pw_text(main_pixwin, x, starty-5, PIX_SRC, font, c);
  132.         }
  133.         
  134.         y = starty + weekslot_height - 4;
  135.         rightx = startx + nr_weekdays*weekslot_width + 10;
  136.     for (i=0; i<N_SLOTS; i++) {
  137.         if (i < n_tslots) {
  138.             sprintf(c, "%2d:%s",
  139.                 (START_HOUR+(i/2))%12 == 0 ? 12 : (START_HOUR+(i/2))%12,
  140.                 i%2 == 0 ? "00" : "30");
  141.         } else if (i == n_tslots) {
  142.             sprintf(c, "Notes");
  143.         } else {
  144.             sprintf(c, "     ");
  145.         }
  146.                 pw_text(main_pixwin, startx-6*font->pf_defaultsize.x, y, PIX_SRC, font, c);
  147.                 pw_text(main_pixwin, rightx, y, PIX_SRC, font, c);
  148.                 y += weekslot_height;
  149.     }
  150.  
  151.         x = startx + (weekslot_width - 7*(font->pf_defaultsize.x+2))/2 + font->pf_defaultsize.x+7;
  152.  
  153.     sprintf(c, "%d", 1900 + current.tm_year);
  154.     pw_text(main_pixwin, startx-2*font->pf_defaultsize.x, y+weekslot_height, PIX_SRC, font, c);
  155.  
  156.     /* display week dates (month, day) */
  157.         for (i=0; i<nr_weekdays; i++) {
  158.         sprintf(c, "%3.3s %2d",
  159.             monthnames[current.tm_mon], current.tm_mday);
  160.         pw_text(main_pixwin, x, y, PIX_SRC, font, c);
  161.                 x += weekslot_width;
  162.         current.tm_mday++;
  163.         fix_current_day();
  164.         }
  165.     current = First;
  166.     fix_current_day();
  167. }       
  168.  
  169.  
  170. get_week_appts()
  171. {
  172.     int i, j, save_read;
  173.     struct tm Current;
  174.  
  175.     save_read = read_only;
  176.     read_only = 1;
  177.     Current = current;
  178.     for (i=0; i<nr_weekdays; i++) {
  179.         get_day_appts();    /* fills in slots[] array */
  180.         for (j=0; j<N_SLOTS; j++)
  181.             week_boxes[i].weekslots[j] = slots[j];
  182.         current.tm_mday++;
  183.         fix_current_day();
  184.     }
  185.     read_only = save_read;
  186.     current = Current;
  187.     fix_current_day();
  188. }                       
  189.  
  190. /* draw in week appointments */
  191. draw_week_appts()
  192. {
  193.     int index, slotno;
  194.     struct appt_entry *aptr, *optr;
  195.  
  196.     for (index=0; index<nr_weekdays; index++) {
  197.         x_coord = week_boxes[index].wday_pos.left;
  198.         for (slotno=0; slotno<N_SLOTS; slotno++) {
  199.             y_coord = week_boxes[index].wday_pos.top + slotno*weekslot_height;
  200.             if (week_boxes[index].weekslots[slotno].count > 0) {
  201.                 switch (week_boxes[index].weekslots[slotno].active) {
  202.                     case ACTIVE:
  203.                         write_week_str(index, slotno);
  204.                         break;
  205.                     case ARROW_SHAFT:
  206.                         pw_write(main_pixwin, x_coord+1, y_coord+1,
  207.                           weekslot_width-2, weekslot_height-2, PIX_SRC|PIX_DST,
  208.                         weekarrowshaft_pr, 0, 0);
  209.                         break;
  210.                     case ARROW_HEAD:
  211.                         pw_write(main_pixwin, x_coord+1, y_coord+1, weekslot_width-2,
  212.                           weekslot_height-2, PIX_SRC|PIX_DST, weekarrowhead_pr, 0, 0);
  213.                         break;
  214.                     case INACTIVE:
  215.                         break;
  216.                 }
  217.             }
  218.             /* free memory alloc'd for appts */
  219.             if (week_boxes[index].weekslots[slotno].first)
  220.                 for (aptr=week_boxes[index].weekslots[slotno].first; aptr; ) {
  221.                     optr = aptr;
  222.                     aptr = aptr->next;
  223.                     free(optr);
  224.                 }
  225.         }
  226.         wmore_check(index);
  227.     }
  228. }
  229.  
  230. write_week_str(day, bi)
  231. int day;
  232. int bi;
  233. {
  234.     char slot_str[MAX_STRLEN];
  235.     char *ptr;
  236.     int strl;
  237.  
  238.     strl = strlen(week_boxes[day].weekslots[bi].cur_appt->str);
  239.     if (strl <= week_message_size)
  240.         strcpy(slot_str, week_boxes[day].weekslots[bi].cur_appt->str);
  241.     else {
  242.         /* show leading part */
  243.         
  244.         strncpy(slot_str, week_boxes[day].weekslots[bi].cur_appt->str, week_message_size);
  245.         slot_str[week_message_size+1] = '\0';
  246.     }
  247.     pw_write(main_pixwin, x_coord+1, y_coord+1, weekslot_width-2,
  248.         weekslot_height-2, PIX_SET, NULL, 0, 0);
  249.     pw_text(main_pixwin, x_coord+4, y_coord+font->pf_defaultsize.y, PIX_NOT(PIX_SRC),
  250.         font, slot_str);
  251. }
  252.  
  253. /* display "more" button if necessary */
  254. wmore_check(day)
  255. int day;
  256. {
  257.     int i, more = 0;
  258.     int x, y;
  259.  
  260.     x = morebutton->pr_size.x;
  261.     y = morebutton->pr_size.y;
  262.     for (i=0; i<N_SLOTS; i++)
  263.         if (week_boxes[day].weekslots[i].count > 1) {
  264.             more = 1;
  265.             break;
  266.         }
  267.     if (more) {
  268.         week_boxes[day].more = 1;
  269.         /* display more button to bottom of slot */
  270.         pw_write(main_pixwin, week_boxes[day].moreb_pos.left,
  271.             week_boxes[day].moreb_pos.top,
  272.             x, y, PIX_SRC, morebutton, 0, 0);
  273.     } else
  274.         week_boxes[day].more = 0;
  275. }
  276.  
  277.