home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Header: wpaint.c,v 2.1 89/05/09 14:20:03 billr Exp $
- */
- /*
- * wpaint.c
- *
- * Author: Philip Heller, Sun Microsystems. Inc. <terrapin!heller@sun.com>
- *
- * Original source Copyright (C) 1987, Sun Microsystems, Inc.
- * All Rights Reserved
- * Permission is hereby granted to use and modify this program in source
- * or binary form as long as it is not sold for profit and this copyright
- * notice remains intact.
- *
- *
- * Changes/additions by: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
- *
- * Changes and additions Copyright (C) 1988, 1989 Tektronix, Inc.
- * All Rights Reserved
- * Permission is hereby granted to use and modify the modifications in source
- * or binary form as long as they are not sold for profit and this copyright
- * notice remains intact.
- */
- /***************************************************
- * *
- * Artistic routines that draw in the main *
- * subwindow for the week display. *
- * *
- ***************************************************/
-
- #include <suntool/sunview.h>
- #include <suntool/canvas.h>
- #include <ctype.h>
- #include <stdio.h>
- #include "ct.h"
- #include "paint.h"
-
- extern int week_message_size;
-
- /*
- * Routine to draw "Week-at-a-Glance".
- */
-
- draw_week()
- {
- struct tm Save;
-
- lock_cursors();
- /* destory future appts popup, if it exists */
- if (fframe) {
- window_destroy(fframe);
- fframe = 0;
- }
- fix_current_day();
- Save = current;
- current.tm_mday -= current.tm_wday; /* Sunday of this week */
- fix_current_day();
- if (nr_weekdays < 7) {
- current.tm_mday++;
- fix_current_day();
- }
- working(TRUE);
- get_week_appts();
- working(FALSE);
- pw_batch_on(main_pixwin);
- paint_week_outline();
- paint_week_trim();
- working(TRUE);
- draw_week_appts();
- pw_batch_off(main_pixwin);
- current = Save;
- get_day_appts();
- working(FALSE);
- unlock_cursors();
- }
-
-
- /* Paint the outline for "Week-at-a-Glance". */
- paint_week_outline()
- {
- Rect *rect;
- int x, y, i, j, colx;
-
- rect = (Rect *) window_get(canvas, WIN_RECT);
- pw_writebackground(main_pixwin,0,0,rect->r_width,rect->r_height,PIX_CLR);
- startx = (rect->r_width - nr_weekdays*weekslot_width) / 2;
- starty = 10 + (rect->r_height - (N_SLOTS*(weekslot_height+1))) / 2;
-
- First = current;
- for (i=0; i<nr_weekdays; i++) {
- x = startx + i*weekslot_width;
- y = starty;
- week_boxes[i].wday_pos.left = x;
- week_boxes[i].wday_pos.top = y;
- week_boxes[i].wday_pos.right = x + weekslot_width;
- week_boxes[i].wday_pos.bottom = starty + N_SLOTS*weekslot_height;
- week_boxes[i].moreb_pos.left = x + (weekslot_width - morebutton->pr_size.x) / 2;
- week_boxes[i].moreb_pos.top = week_boxes[i].wday_pos.bottom + font->pf_defaultsize.y + font->pf_defaultsize.y/2;
- week_boxes[i].moreb_pos.right = week_boxes[i].moreb_pos.left + morebutton->pr_size.x;
- week_boxes[i].moreb_pos.bottom = week_boxes[i].moreb_pos.top + morebutton->pr_size.y;
- for (j=0; j<N_SLOTS; j++) {
- if (ymd_compare(today, current) == 0)
- pw_write(main_pixwin,x,y,weekslot_width,
- weekslot_height,PIX_SRC,weekslot_td_pr,0,0);
- else
- pw_write(main_pixwin,x,y,weekslot_width,
- weekslot_height,PIX_SRC,weekslot_pr,0,0);
- y += weekslot_height;
- }
- current.tm_mday++;
- fix_current_day();
- }
- pw_vector(main_pixwin,startx,starty,startx+nr_weekdays*weekslot_width,starty,PIX_SET,1);
- pw_vector(main_pixwin,startx,y-1,startx+nr_weekdays*weekslot_width,y-1,PIX_SET,1);
- current = First;
- sun_moon_buttons(FALSE);
- print_button(TRUE);
- }
-
-
- paint_week_trim()
- {
- int i, j, x, y, month, day, rightx;
- char c[7];
-
- First = current;
- c[3] = '\0'; /* Mon Tue Wed Thu Fri */
- for (i=0; i<nr_weekdays; i++) {
- x = startx + i*weekslot_width + (weekslot_width - 2*(font->pf_defaultsize.x+2))/2;
- sprintf(c, "%3.3s", daynames[First.tm_wday + i]);
- pw_text(main_pixwin, x, starty-5, PIX_SRC, font, c);
- }
-
- y = starty + weekslot_height - 4;
- rightx = startx + nr_weekdays*weekslot_width + 10;
- for (i=0; i<N_SLOTS; i++) {
- if (i < n_tslots) {
- sprintf(c, "%2d:%s",
- (START_HOUR+(i/2))%12 == 0 ? 12 : (START_HOUR+(i/2))%12,
- i%2 == 0 ? "00" : "30");
- } else if (i == n_tslots) {
- sprintf(c, "Notes");
- } else {
- sprintf(c, " ");
- }
- pw_text(main_pixwin, startx-6*font->pf_defaultsize.x, y, PIX_SRC, font, c);
- pw_text(main_pixwin, rightx, y, PIX_SRC, font, c);
- y += weekslot_height;
- }
-
- x = startx + (weekslot_width - 7*(font->pf_defaultsize.x+2))/2 + font->pf_defaultsize.x+7;
-
- sprintf(c, "%d", 1900 + current.tm_year);
- pw_text(main_pixwin, startx-2*font->pf_defaultsize.x, y+weekslot_height, PIX_SRC, font, c);
-
- /* display week dates (month, day) */
- for (i=0; i<nr_weekdays; i++) {
- sprintf(c, "%3.3s %2d",
- monthnames[current.tm_mon], current.tm_mday);
- pw_text(main_pixwin, x, y, PIX_SRC, font, c);
- x += weekslot_width;
- current.tm_mday++;
- fix_current_day();
- }
- current = First;
- fix_current_day();
- }
-
-
- get_week_appts()
- {
- int i, j, save_read;
- struct tm Current;
-
- save_read = read_only;
- read_only = 1;
- Current = current;
- for (i=0; i<nr_weekdays; i++) {
- get_day_appts(); /* fills in slots[] array */
- for (j=0; j<N_SLOTS; j++)
- week_boxes[i].weekslots[j] = slots[j];
- current.tm_mday++;
- fix_current_day();
- }
- read_only = save_read;
- current = Current;
- fix_current_day();
- }
-
- /* draw in week appointments */
- draw_week_appts()
- {
- int index, slotno;
- struct appt_entry *aptr, *optr;
-
- for (index=0; index<nr_weekdays; index++) {
- x_coord = week_boxes[index].wday_pos.left;
- for (slotno=0; slotno<N_SLOTS; slotno++) {
- y_coord = week_boxes[index].wday_pos.top + slotno*weekslot_height;
- if (week_boxes[index].weekslots[slotno].count > 0) {
- switch (week_boxes[index].weekslots[slotno].active) {
- case ACTIVE:
- write_week_str(index, slotno);
- break;
- case ARROW_SHAFT:
- pw_write(main_pixwin, x_coord+1, y_coord+1,
- weekslot_width-2, weekslot_height-2, PIX_SRC|PIX_DST,
- weekarrowshaft_pr, 0, 0);
- break;
- case ARROW_HEAD:
- pw_write(main_pixwin, x_coord+1, y_coord+1, weekslot_width-2,
- weekslot_height-2, PIX_SRC|PIX_DST, weekarrowhead_pr, 0, 0);
- break;
- case INACTIVE:
- break;
- }
- }
- /* free memory alloc'd for appts */
- if (week_boxes[index].weekslots[slotno].first)
- for (aptr=week_boxes[index].weekslots[slotno].first; aptr; ) {
- optr = aptr;
- aptr = aptr->next;
- free(optr);
- }
- }
- wmore_check(index);
- }
- }
-
- write_week_str(day, bi)
- int day;
- int bi;
- {
- char slot_str[MAX_STRLEN];
- char *ptr;
- int strl;
-
- strl = strlen(week_boxes[day].weekslots[bi].cur_appt->str);
- if (strl <= week_message_size)
- strcpy(slot_str, week_boxes[day].weekslots[bi].cur_appt->str);
- else {
- /* show leading part */
-
- strncpy(slot_str, week_boxes[day].weekslots[bi].cur_appt->str, week_message_size);
- slot_str[week_message_size+1] = '\0';
- }
- pw_write(main_pixwin, x_coord+1, y_coord+1, weekslot_width-2,
- weekslot_height-2, PIX_SET, NULL, 0, 0);
- pw_text(main_pixwin, x_coord+4, y_coord+font->pf_defaultsize.y, PIX_NOT(PIX_SRC),
- font, slot_str);
- }
-
- /* display "more" button if necessary */
- wmore_check(day)
- int day;
- {
- int i, more = 0;
- int x, y;
-
- x = morebutton->pr_size.x;
- y = morebutton->pr_size.y;
- for (i=0; i<N_SLOTS; i++)
- if (week_boxes[day].weekslots[i].count > 1) {
- more = 1;
- break;
- }
- if (more) {
- week_boxes[day].more = 1;
- /* display more button to bottom of slot */
- pw_write(main_pixwin, week_boxes[day].moreb_pos.left,
- week_boxes[day].moreb_pos.top,
- x, y, PIX_SRC, morebutton, 0, 0);
- } else
- week_boxes[day].more = 0;
- }
-
-