home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
misc
/
volume17
/
calentool
/
part13
/
wpaint.c
< prev
Wrap
C/C++ Source or Header
|
1991-04-06
|
11KB
|
381 lines
/*
* $Header: wpaint.c,v 2.5 91/03/27 16:46:49 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, 1991 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;
extern void fix_current_day();
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 */
if (monday_first) {
if (current.tm_wday == SUN)
current.tm_mday -= 7;
if (nr_weekdays == 7)
current.tm_mday++; /* start on Monday */
}
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);
/*
(void)win_post_id(canvas, WIN_REPAINT, NOTIFY_SAFE);
*/
free_week_appts();
current = Save;
(void)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[8];
First = current;
for (i=0; i<nr_weekdays; i++) {
x = startx + i*weekslot_width + (weekslot_width - 2*(font->pf_defaultsize.x+2))/2;
if (monday_first && i == 6)
sprintf(c, "%3.3s", daynames[SUN]);
else
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) {
if (hour24)
sprintf(c, "%2d:%s",
start_hour+(i/2),
i%2 == 0 ? "00" : "30");
else
sprintf(c, "%2d:%s%s",
(start_hour+(i/2))%12 == 0 ? 12 : (start_hour+(i/2))%12,
i%2 == 0 ? "00" : "30", (start_hour+(i/2) < 12 ? "am" : "pm"));
} else if (i == n_tslots) {
sprintf(c, (hour24 ? "Notes" : " Notes"));
} else {
sprintf(c, " ");
}
if (hour24) {
pw_text(main_pixwin, startx-7*font->pf_defaultsize.x, y, PIX_SRC, font, c);
pw_text(main_pixwin, rightx, y, PIX_SRC, font, c);
} else {
pw_text(main_pixwin, startx-8*font->pf_defaultsize.x, y, PIX_SRC, font, c);
pw_text(main_pixwin, rightx-font->pf_defaultsize.x, 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-3*font->pf_defaultsize.x,
y+weekslot_height, PIX_SRC, font, c);
sprintf(c, "Week: %d", week_number());
pw_text(main_pixwin, startx+nr_weekdays*weekslot_width-2*font->pf_defaultsize.x,
y+weekslot_height, PIX_SRC, font, c);
/* display week dates (month, day) */
for (i=0; i<nr_weekdays; i++) {
if (day_first)
sprintf(c, "%2d %3.3s",
current.tm_mday, monthnames[current.tm_mon]);
else
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, offset, i;
int narrows, pixoffset;
struct dayslot *slptr;
for (index=0; index<nr_weekdays; index++) {
/* clear all arrow position information */
for (slotno=0; slotno<n_slots; slotno++)
week_boxes[index].weekslots[slotno].arrow_pos = 0;
week_boxes[index].more = 0;
for (slotno=0; slotno<n_slots; slotno++) {
slptr = &week_boxes[index].weekslots[slotno];
if (slptr->active) {
x_coord = week_boxes[index].wday_pos.left;
y_coord = week_boxes[index].wday_pos.top +
slotno*weekslot_height;
write_week_str(index, slotno);
if ((narrows = slptr->cur_appt->arrows) > 0) {
/* find first free position for arrow */
offset = 0;
while (slptr->arrow_pos & 1<<offset)
offset++;
slptr->arrow_pos |= 1<<offset;
i = slotno + narrows;
week_boxes[index].weekslots[i].arrow_pos |= 1<<offset;
draw_weekarrowhead(index, i, offset, FALSE);
while (--narrows > 0) {
week_boxes[index].weekslots[--i].arrow_pos
|= 1<<offset;
draw_weekarrowshaft(index, i, offset, FALSE);
}
}
wmore_check(index, slotno);
}
}
}
}
draw_weekarrowshaft(day, bi, offset, gray)
int day, bi;
int offset, gray;
{
int x, y;
int pixoffset;
/* mark this position as used */
week_boxes[day].weekslots[bi].arrow_pos |= 1<<offset;
pixoffset = (offset + 1) * 16;
if (pixoffset > weekslot_width - 16)
pixoffset = weekslot_width - 16;
y = week_boxes[day].wday_pos.top + bi*weekslot_height;
x = week_boxes[day].wday_pos.left;
pw_write(main_pixwin, x+1+pixoffset, y, 14, weekslot_height,
PIX_SRC|PIX_DST, (gray ? gr_weekarrowshaft_pr : weekarrowshaft_pr), 0, 0);
}
draw_weekarrowhead(day, bi, offset, gray)
int day, bi;
int offset, gray;
{
int x, y;
int pixoffset;
/* mark this position as used */
week_boxes[day].weekslots[bi].arrow_pos |= 1<<offset;
pixoffset = (offset + 1) * 16;
if (pixoffset > weekslot_width - 16)
pixoffset = weekslot_width - 16;
y = week_boxes[day].wday_pos.top + bi*weekslot_height;
x = week_boxes[day].wday_pos.left;
pw_write(main_pixwin, x+1+pixoffset, y, 14, weekslot_height,
PIX_SRC|PIX_DST, (gray ? gr_weekarrowhead_pr : weekarrowhead_pr), 0, 0);
}
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);
}
/* free memory alloc'd for appts */
free_week_appts()
{
int index, slotno;
struct appt_entry *aptr, *optr;
for (index=0; index<nr_weekdays; index++) {
for (slotno=0; slotno<n_slots; slotno++) {
if (week_boxes[index].weekslots[slotno].first)
for (aptr=week_boxes[index].weekslots[slotno].first; aptr; ) {
optr = aptr;
aptr = aptr->next;
free(optr);
}
}
}
}
/* display "more" button if necessary */
wmore_check(day, bi)
int day, bi;
{
int i, narrows, offset;
int x, y;
struct appt_entry *aptr;
struct dayslot *slptr;
slptr = &week_boxes[day].weekslots[bi];
if (slptr->active > 1) {
for (aptr=slptr->first; aptr; aptr=aptr->next) {
if (aptr == slptr->cur_appt)
continue; /* already did this one */
if (chk_deleted(slptr, aptr))
continue;
if ((narrows = aptr->arrows) > 0) {
/* find first free position for arrow */
offset = 0;
while (slptr->arrow_pos & 1<<offset)
offset++;
slptr->arrow_pos |= 1<<offset;
i = bi + narrows;
week_boxes[day].weekslots[i].arrow_pos |= 1<<offset;
draw_weekarrowhead(day, i, offset, TRUE);
while (--narrows > 0) {
week_boxes[day].weekslots[--i].arrow_pos
|= 1<<offset;
draw_weekarrowshaft(day, i, offset, TRUE);
}
}
}
x = morebutton->pr_size.x;
y = morebutton->pr_size.y;
week_boxes[day].more = 1;
/* display more button at 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);
}
}