home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Header: dpaint.c,v 2.2 89/05/10 10:06:20 billr Exp $
- */
- /*
- * dpaint.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 day display. *
- * *
- ***************************************************/
-
- #include <suntool/sunview.h>
- #include <suntool/canvas.h>
- #include <ctype.h>
- #include <sys/time.h>
- #include <stdio.h>
- #include "ct.h"
- #include "paint.h"
- #include "riseset.h"
- #define J1970 2440587.5 /* VAX clock Epoch 1970 Jan 1 (0h UT) */
-
- #ifndef NO_SUN_MOON
- extern Frame mframe, sframe;
- extern Canvas mcanvas, scanvas;
- extern Panel_item mdate_pi, sdate_pi;
- #endif
- extern Pixrect *leftarrow, *rightarrow;
- extern Pixrect *arrowshaft_pr, *arrowhead_pr;
- extern int day_message_size;
- extern char riseset_buf[][64];
- extern int old_slot;
- extern int show_future;
- extern char *index();
-
- struct tm save_day;
- struct appt_entry future[MAX_FUTURE_ENTRIES];
- int findex = 0; /* index into struct future array */
-
- /*
- * This one draws the current selected day in the
- * main subwindow.
- */
-
- draw_day()
- {
- draw_day1();
- draw_future_appts();
- #ifndef NO_SUN_MOON
- if (sframe)
- write_sun_data();
- if (mframe)
- write_moon_data();
- #endif
- }
-
- /*
- * Draw main day page without future appts or Sun/Moon data
- */
- draw_day1()
- {
- lock_cursors();
- fix_current_day();
- working(TRUE);
- pw_batch_on(main_pixwin);
- draw_day_outline();
- pw_batch_off(main_pixwin);
- get_day_appts();
- working(FALSE);
- pw_batch_on(main_pixwin);
- draw_day_appts();
- pw_batch_off(main_pixwin);
- day_is_open = TRUE;
- unlock_cursors();
- }
-
- /*
- * Utility for draw_day ... draws the outline of a day.
- */
- draw_day_outline()
- {
- char timestring[6], daystring[31], buf[64], *src;
- int x, y, starty, i, d;
- Rect *rect;
-
- /* First erase the window. */
- rect = (Rect *) window_get(canvas, WIN_RECT);
- pw_writebackground(main_pixwin, 0, 0,
- rect->r_width, rect->r_height, PIX_CLR);
- old_slot = -1; /* text cursor no longer displayed */
-
- /* Calculate coords of top-left corner of big box. */
- x = (rect->r_width - dayslot_width) / 2;
- starty = y = (rect->r_height - (N_SLOTS * dayslot_height)) / 2;
-
- /* Format daystring to say, for example, */
- /* Tuesday, March 12, 1985 */
- sprintf(daystring, "%s %s %d, %d",
- daynames[current.tm_wday], monthnames[current.tm_mon],
- current.tm_mday, 1900 + current.tm_year);
- pw_text(main_pixwin, (rect->r_width - bigfont->pf_defaultsize.x*strlen(daystring))/2, starty/2 + 7,
- PIX_SRC, bigfont, daystring);
-
- for (i=0; i<N_SLOTS; i++) { /* Init and draw each 30 minute slot. */
- slots[i].slot_pos.top = y;
- slots[i].slot_pos.left = x;
- slots[i].slot_pos.bottom = y + dayslot_height + 1;
- slots[i].slot_pos.right = x + dayslot_width + 1;
- slots[i].moreb_pos.top = y;
- slots[i].moreb_pos.left = rect->r_width - 8 - morebutton->pr_size.x;
- slots[i].moreb_pos.bottom = y + morebutton->pr_size.y;
- slots[i].moreb_pos.right = rect->r_width - 8;
- slots[i].larrow_pos.top = slots[i].slot_pos.top+(dayslot_height-leftarrow->pr_size.y)/2;
- slots[i].larrow_pos.left = slots[i].slot_pos.right + 8;
- slots[i].larrow_pos.bottom = slots[i].larrow_pos.top + leftarrow->pr_size.y;
- slots[i].larrow_pos.right = slots[i].larrow_pos.left + leftarrow->pr_size.x;
- slots[i].rarrow_pos.top = slots[i].larrow_pos.top;
- slots[i].rarrow_pos.left = slots[i].larrow_pos.right + 8;
- slots[i].rarrow_pos.bottom = slots[i].larrow_pos.bottom;
- slots[i].rarrow_pos.right = slots[i].rarrow_pos.left + rightarrow->pr_size.x;
- if (!ymd_compare(current, today))
- pw_write(main_pixwin,x,y,dayslot_width,dayslot_height,PIX_SRC,timeslot_td_pr,0,0);
- else
- pw_write(main_pixwin,x,y,dayslot_width,dayslot_height,PIX_SRC,timeslot_pr,0,0);
- if (i < n_tslots) {
- /* display time */
- sprintf(timestring, "%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(timestring, "Notes");
- } else {
- sprintf(timestring, " ");
- }
- pw_text(main_pixwin,x-8*font->pf_defaultsize.x,y+font->pf_defaultsize.y,PIX_SRC,font,timestring);
- y += dayslot_height - 1;
- }
-
- pw_vector(main_pixwin,x,starty,x+dayslot_width-1,starty,PIX_SET,1);
- pw_vector(main_pixwin,x,y,x+dayslot_width-1,y,PIX_SET,1);
- y += (dayslot_height - 1) * 2;
- sprintf(buf, "Day of year: %d -- %d days remaining",
- day_of_year((double)current.tm_mday, current.tm_mon+1, current.tm_year),
- days_remaining_in_year((double)current.tm_mday, current.tm_mon+1, current.tm_year));
- pw_text(main_pixwin, x, y, PIX_SRC, font, buf);
- sun_moon_buttons(TRUE);
- print_button(TRUE);
- }
-
-
- /*
- * Fills in appointments for the day.
- * The ".tmp.aptsXXXXX" file is filled out
- * with all the lines from the ".appointments" file
- * which do not pertain to the current day.
- */
- get_day_appts()
- {
- FILE *apts, *temp_apts;
- int slotno, n_arrows, i;
- int read_stat;
- struct appt_entry appt;
- struct appt_entry *nappt, *aptr;
- char buf[MAX_STRLEN], *sptr;
-
- if ((apts = fopen(apts_pathname, "r")) == NULL)
- err_rpt("can't open appointments file", FATAL);
-
- if (!read_only)
- if ((temp_apts = fopen(tmpapts_pathname, "w")) == NULL)
- err_rpt("can't open temp file for writing", FATAL);
-
- for (i=0; i<N_SLOTS; i++) { /* init each slot */
- slots[i].active = INACTIVE;
- slots[i].count = 0;
- slots[i].cur_appt = NULL;
- slots[i].first = NULL;
- }
- First = current;
- findex = 0;
-
- #ifndef NO_HOLIDAYS
- /*
- * First check to see if the user has selected any holiday
- * options and add them in.
- */
- if (a_dates(&appt, holiday_a))
- add_note(&appt);
- if (c_dates(&appt, holiday_c))
- add_note(&appt);
- working(FALSE);
- if (i = i_dates(&appt, holiday_i))
- if (i == 2) {
- /* two notes in one */
- strcpy(buf, appt.str);
- /* look for \n */
- sptr = index(appt.str, '\n');
- *sptr = '\0';
- add_note(&appt);
- /* now second half of string in the next note */
- strcpy(appt.str, &buf[(int)(sptr-appt.str)+1]);
- add_note(&appt);
- } else
- add_note(&appt);
- working(TRUE);
- if (j_dates(&appt, holiday_j))
- add_note(&appt);
- if (s_dates(&appt, holiday_s))
- add_note(&appt);
- #endif
-
- /*
- * now go thru the appointments file
- */
- while ((read_stat=get_aentry(apts, &appt)) != EOF) {
- if (read_stat)
- continue; /* read error (ignore) */
- if (appt.flags & A_COMMENT) {
- if (put_aentry(temp_apts, &appt)) {
- /* write error */
- break;
- }
- continue;
- }
- current.tm_year = appt.year;
- current.tm_mon = appt.month;
- current.tm_mday = appt.day;
- if (appt.flags & ALL_YEARS)
- current.tm_year = First.tm_year;
- if (appt.flags & ALL_MONTHS)
- current.tm_mon = First.tm_mon;
- if (appt.flags & ALL_DAYS)
- current.tm_mday = First.tm_mday;
- else if (appt.flags & EVERY_SOMEDAY) {
- if (Pickday(appt.flags) == First.tm_wday) {
- if (chk_week(appt.repeat, First.tm_mday))
- current.tm_mday = First.tm_mday;
- }
- } else if (appt.flags & REPEAT) {
- while (ymd_compare(current, First) < 0) {
- current.tm_mday += appt.repeat;
- fix_current_day();
- }
- }
- if (ymd_compare(current, First) == 0) {
- /* if it's for this day, fill in slot info */
- if (appt.flags & A_NOTE)
- /* notes section */
- add_note(&appt);
- else {
- /* regular appointment */
- slotno = (appt.hour-START_HOUR) * 2 + appt.minute / 30;
- if (slotno < 0)
- slotno = 0;
- if (slotno >= n_tslots)
- slotno = n_tslots - 1;
- /* add this appt to the list of appts for the slot */
- /* and update all the reference counts */
- add_to_slot(slotno, &appt, FALSE);
- }
- } else if (appt.flags & LOOKAHEAD) {
- /* This lookahead appt was not for today, so
- * put it in the temp file.
- */
- if (put_aentry(temp_apts, &appt)) {
- /* write error */
- break;
- }
- if (appt.flags & EVERY_SOMEDAY) {
- /* find next occurance of this appt */
- /* starting from the current day */
- current.tm_mday = First.tm_mday;
- fix_current_day();
- find_date(&appt); /* may modify current */
- }
- if (ymd_compare(current, First) > 0) {
- /* this appt is happening in
- * the future, so remind us of it if
- * it is within the lookahead window.
- */
- save_day = current;
- current.tm_mday -= appt.lookahead;
- fix_current_day();
- if (ymd_compare(current, First) <=0) {
- /* save this one for the future popup window */
- if (findex > MAX_FUTURE_ENTRIES-1) {
- err_rpt("Too many future reminders", NON_FATAL);
- continue;
- }
- future[findex] = appt;
- /* fix up ymd */
- future[findex].year = save_day.tm_year;
- future[findex].month = save_day.tm_mon;
- future[findex].day = save_day.tm_mday;
- ++findex;
- }
- }
- } else { /* line is not for today */
- /* copy it to temp file */
- if (put_aentry(temp_apts, &appt)) {
- /* write error */
- break;
- }
- }
- }
- if (!read_only) {
- if (ferror(temp_apts))
- err_rpt("write on temp file failed", FATAL);
- fclose(temp_apts);
- }
- fclose(apts);
- current = First;
- fix_current_day();
- }
-
-
- /* check for match on weekly re-ocurring appts */
- chk_week(repeat, curday)
- int repeat, curday;
- {
- int weeknr = 0;
-
- if ((repeat & ALL_WEEKS) == ALL_WEEKS)
- return(1); /* every week */
- if ((repeat & LAST_WEEK) && ((curday+7) > monthlength(current.tm_mon)))
- return(1); /* last week in month */
-
- while (curday > 7) {
- /* find which week this day is in */
- curday -= 7;
- weeknr++;
- }
- if (repeat & (0x1<<weeknr))
- return(1);
-
- return(0); /* no match */
- }
-
-
- /*
- * get date of next occurrance of a weekly repeated appt
- * (it may bridge into next week, month or year)
- */
- find_date(appt)
- struct appt_entry *appt;
- {
- struct tm save;
-
- save = current;
- /* set current to match dow of repeated appt */
- current.tm_mday += Pickday(appt->flags) - current.tm_wday;
- fix_current_day();
- if (ymd_compare(current, save) < 0) {
- /* already happened, so start looking next week */
- current.tm_mday += 7;
- fix_current_day();
- }
- /* search for first matching week */
- while (!chk_week(appt->repeat, current.tm_mday)) {
- current.tm_mday += 7;
- fix_current_day();
- }
- /* now check to make sure this is legal, i.e. there
- * were no month or year restrictions
- */
- if ((!(appt->flags & ALL_YEARS) && current.tm_year != save.tm_year)
- || (!(appt->flags & ALL_MONTHS) && current.tm_mon != save.tm_mon))
- /* invalid date, due to month or year wrap */
- current = save;
- }
-
-
- /* add a note to the current day */
- add_note(appt)
- struct appt_entry *appt;
- {
- int slotno;
-
- /* auto-hunt for free note slot */
- for (slotno=n_tslots; slotno<N_SLOTS; slotno++)
- if (slots[slotno].active == INACTIVE)
- break;
- if (slotno == N_SLOTS) {
- /* overflow of notes field, so
- * add to last note field list
- */
- slotno = N_SLOTS - 1;
- }
- add_to_slot(slotno, appt, FALSE);
- }
-
- /* draw in todays appointments */
- draw_day_appts()
- {
- int slotno = 0;
-
- while (slotno < N_SLOTS) {
- if (slots[slotno].count > 0) {
- switch (slots[slotno].active) {
- case ACTIVE:
- rewrite_string(slotno, JUSTIFY_LEFT);
- break;
- case ARROW_SHAFT:
- draw_arrowshaft(slotno);
- break;
- case ARROW_HEAD:
- draw_arrowhead(slotno);
- break;
- case INACTIVE:
- break;
- }
- more_check(slotno);
- }
- ++slotno;
- }
- }
-
- /* Blacks out day-slot and then re-writes string. */
- rewrite_string(bi, justify)
- int bi, justify;
- {
- char slot_str[MAX_STRLEN];
- char *ptr;
- int strl, *iptr;
-
- strl = strlen(slots[bi].cur_appt->str);
- iptr = &slots[bi].cur_appt->sindex;
- if (strl < day_message_size) {
- *iptr = 0; /* just in case */
- strcpy(slot_str, slots[bi].cur_appt->str);
- /* erase any previously existing scroll arrows */
- pw_writebackground(main_pixwin, slots[bi].larrow_pos.left,
- slots[bi].larrow_pos.top, slots[bi].rarrow_pos.right-slots[bi].larrow_pos.left,
- slots[bi].larrow_pos.bottom-slots[bi].larrow_pos.top,
- PIX_CLR);
- } else {
- if (justify == JUSTIFY_RIGHT) {
- /* show trailing part */
- ptr = &slots[bi].cur_appt->str[strl - day_message_size + 1];
- *iptr = strl - day_message_size + 1;
- strcpy(slot_str, ptr);
- } else {
- /* show leading or indexed part */
- if (justify == JUSTIFY_LEFT)
- *iptr = 0;
- if (*iptr > (strl - day_message_size + 1))
- *iptr = strl - day_message_size + 1;
- if (strlen(&slots[bi].cur_appt->str[*iptr]) >= day_message_size-1) {
- strncpy(slot_str, &slots[bi].cur_appt->str[*iptr], day_message_size-1);
- slot_str[day_message_size-1] = '\0';
- } else
- strcpy(slot_str, &slots[bi].cur_appt->str[*iptr]);
- }
- /* display scroll arrows */
- pw_write(main_pixwin, slots[bi].larrow_pos.left,
- slots[bi].larrow_pos.top, leftarrow->pr_size.x,
- leftarrow->pr_size.y, PIX_SRC, leftarrow, 0, 0);
- pw_write(main_pixwin, slots[bi].rarrow_pos.left,
- slots[bi].rarrow_pos.top, rightarrow->pr_size.x,
- rightarrow->pr_size.y, PIX_SRC, rightarrow, 0, 0);
- }
- pw_write(main_pixwin, slots[bi].slot_pos.left+1, slots[bi].slot_pos.top+1,
- dayslot_width-2, dayslot_height-2, PIX_SET, NULL, 0, 0);
- pw_text(main_pixwin, slots[bi].slot_pos.left+5, slots[bi].slot_pos.top+font->pf_defaultsize.y,
- PIX_NOT(PIX_SRC), font, slot_str);
- }
-
- /* display "more" button if necessary */
- more_check(slotno)
- int slotno;
- {
- int x, y, w;
-
- x = morebutton->pr_size.x;
- y = morebutton->pr_size.y;
-
- /* clear any previous button that may be there */
- pw_write(main_pixwin, slots[slotno].moreb_pos.left, slots[slotno].moreb_pos.top,
- x, y, PIX_CLR, NULL, 0, 0);
- /* button displayed when more than 1 reference
- * and at least one real appt for this slot.
- */
- if (slots[slotno].count > 1 && slots[slotno].first)
- /* display more button to right of slot */
- pw_write(main_pixwin, slots[slotno].moreb_pos.left, slots[slotno].moreb_pos.top,
- x, y, PIX_SRC, morebutton, 0, 0);
- }
-
- draw_arrowshaft(i)
- int i;
- {
- pw_rop(main_pixwin, slots[i].slot_pos.left+1, slots[i].slot_pos.top+1,
- dayslot_width-2, dayslot_height-2, PIX_SRC|PIX_DST, arrowshaft_pr, 0, 0);
- slots[i].active = ARROW_SHAFT;
- }
-
-
-
- draw_arrowhead(i)
- int i;
- {
- pw_rop(main_pixwin, slots[i].slot_pos.left+1, slots[i].slot_pos.top+1,
- dayslot_width-2, dayslot_height-2, PIX_SRC|PIX_DST, arrowhead_pr, 0, 0);
- slots[i].active = ARROW_HEAD;
- }
-
- /*
- * Routine to create popup window with future appts shown in it
- */
- draw_future_appts()
- {
- if (show_future && findex && (ymd_compare(current, today) == 0)) {
- create_future_popup();
- } else {
- /* nothing to show */
- /* destroy future appts popup, if it exists */
- if (fframe) {
- window_destroy(fframe);
- fframe = 0;
- }
- }
- }
-
- /*
- * Add an appointment entry pointed to by aptr to the day slot
- * specified by slotno. This routine is also used by paste()
- * when copying an entry off the save shelf. If dpyflag is true,
- * then any deactivated slots are cleared on the display (used by
- * paste). Also used to add a deleted entry for a specific day.
- */
- add_to_slot(slotno, aptr, dpyflag)
- int slotno;
- struct appt_entry *aptr;
- int dpyflag;
- {
- struct appt_entry *nappt, *optr;
- int n_arrows, n, nbi, found = 0, i;
- int deactivate_lower_arrows();
-
- if ((nappt = (struct appt_entry *)malloc(sizeof(struct appt_entry))) == NULL)
- err_rpt("out of memory", FATAL);
- if (aptr == NULL) {
- /* fill in some needed fields */
- nappt->arrows = nappt->flags = 0;
- nappt->sindex = 0;
- nappt->str[0] = '\0';
- } else
- *nappt = *aptr;
- nappt->next = NULL;
- /* add appt to list of appts for this slot */
- if (slots[slotno].first == NULL) {
- slots[slotno].first = nappt;
- slots[slotno].cur_appt = nappt;
- } else {
- /* search for end of list */
- for (optr=slots[slotno].first;optr->next;optr=optr->next)
- ;
- optr->next = nappt;
- }
- /* make sure it doesn't extend too far and truncate if neccessary */
- if (slotno >= n_tslots)
- nappt->arrows = 0; /* force notes to have no arrows */
- else if ((slotno + nappt->arrows) >= n_tslots)
- nappt->arrows = n_tslots - slotno - 1; /* truncate */
- n_arrows = nappt->arrows;
- if (nappt->flags & DELETED) {
- /* look for matching non-deleted appt in list */
- for (optr=slots[slotno].first;optr;optr=optr->next)
- if (!strcmp(nappt->str, optr->str) && !(optr->flags & DELETED)) {
- found = 1;
- break;
- }
- if (found && slots[slotno].cur_appt == optr) {
- /* the deleted appt is the current one */
- /* if it's active, undisplay it and display
- * next one in list (if any)
- */
- if (slots[slotno].active == ACTIVE) {
- if (slots[slotno].count > 1)
- /* there's another one here */
- next_appt(slotno, dpyflag);
- else {
- deactivate_slot(slotno, dpyflag);
- if (slots[slotno].cur_appt->arrows > 0)
- (void)deactivate_lower_arrows(slotno, dpyflag);
- }
- /* adjust reference counts */
- slots[slotno].count--;
- i = 1;
- while (i <= n_arrows) {
- if (--(slots[slotno+i].count) > 0)
- /* try to activate any hidden ones */
- (void)activate_slot(slotno+i, dpyflag);
- ++i;
- }
- } else {
- /* currently inactive */
- /* set current to next one in the list */
- if (optr->next)
- slots[slotno].cur_appt = optr->next;
- else
- slots[slotno].cur_appt = slots[slotno].first;
- while (n_arrows >= 0)
- slots[slotno+(n_arrows--)].count--;
- }
- } else {
- /* just adjust the counts */
- while (n_arrows >= 0)
- slots[slotno+(n_arrows--)].count--;
- }
- } else {
- /* look for matching deleted appt in list */
- for (optr=slots[slotno].first;optr;optr=optr->next)
- if (!strcmp(nappt->str, optr->str) && optr->flags & DELETED) {
- found = 1;
- break;
- }
- if (found) {
- /* just adjust reference counts and return */
- while (n_arrows >= 0)
- slots[slotno+(n_arrows--)].count++;
- return;
- }
- /*
- * Make sure there are no overlaps with the appt we
- * are adding. If there are, hide the overlapping appt.
- */
- nbi = slotno;
- do {
- if (slots[nbi].active == ACTIVE) {
- deactivate_slot(nbi, dpyflag);
- if (slots[nbi].cur_appt->arrows > 0)
- nbi = deactivate_lower_arrows(nbi, dpyflag);
- } else if (slots[nbi].active != INACTIVE)
- nbi = deactivate_lower_arrows(nbi, dpyflag);
- while (++nbi <= slotno+n_arrows)
- if (slots[nbi].active == ACTIVE)
- break;
- } while (nbi <= slotno + n_arrows);
- /* set current one to the new one */
- slots[slotno].cur_appt = nappt;
- /* now go back and put in the info for the appt we're inserting */
- slots[slotno].active = ACTIVE;
- slots[slotno].count++;
- if (n_arrows > 0) {
- slots[slotno+n_arrows].count++;
- slots[slotno+n_arrows].active = ARROW_HEAD;
- while (--n_arrows > 0) {
- slots[slotno+n_arrows].count++;
- slots[slotno+n_arrows].active = ARROW_SHAFT;
- }
- }
- }
- if (dpyflag)
- draw_day_appts(); /* redraw display */
- }
-
-
- #ifndef NO_SUN_MOON
- /*
- * write sun data to the popup canvas
- */
- write_sun_data()
- {
- int x, y, height;
- char buf[64];
- Pixwin *spixwin;
- Rect *rect;
- struct timeval tp;
- double jdays, secs, offset;
- double julian_day();
-
- /* first erase the window. */
- spixwin = (Pixwin *)canvas_pixwin(scanvas);
- rect = (Rect *) window_get(scanvas, WIN_RECT);
- pw_writebackground(spixwin, 0, 0,
- rect->r_width, rect->r_height, PIX_CLR);
-
- x = font->pf_defaultsize.x;
- height = y = font->pf_defaultsize.y;
-
- gettimeofday(&tp, 0);
- if (ymd_compare(current, today) == 0) {
- /* use current time */
- write_times();
- panel_set(sdate_pi, PANEL_LABEL_STRING, riseset_buf[B_DMY], 0);
- y += 11 * height;
- } else {
- /* convert today's date to approx. seconds from 1-1-1970 */
- jdays = julian_day((double)today.tm_mday, today.tm_mon+1, today.tm_year+1900) - J1970;
- /* seconds from 00:00 GMT to now */
- offset = tp.tv_sec - (jdays * 24. * 3600.);
- /* convert this date to approx. seconds from 1-1-1970 */
- jdays = julian_day((double)current.tm_mday, current.tm_mon+1, current.tm_year+1900) - J1970;
- /* seconds to the same time on selected day */
- secs = (jdays * 24.0 * 3600.) + offset;
- riseset((long)secs);
- panel_set(sdate_pi, PANEL_LABEL_STRING, riseset_buf[B_DMY], 0);
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_JLD]);
- y += height;
- }
- sprintf(buf, "Sun Rise (today): %s", riseset_buf[B_SRD]);
- pw_text(spixwin, x, y, PIX_SRC, font, buf);
- y += height;
- sprintf(buf, "Sun Set (today): %s", riseset_buf[B_SSD]);
- pw_text(spixwin, x, y, PIX_SRC, font, buf);
- y += height;
- sprintf(buf, "Sun Rise (tomorrow): %s", riseset_buf[B_SRT]);
- pw_text(spixwin, x, y, PIX_SRC, font, buf);
- y += height;
- sprintf(buf, "Sun Set (tomorrow): %s", riseset_buf[B_SST]);
- pw_text(spixwin, x, y, PIX_SRC, font, buf);
- }
-
- /*
- * write sun time data to the popup canvas
- */
- write_times()
- {
- int x, y, height;
- Pixwin *spixwin;
- struct timeval tp;
-
- /* only update these if displaying today's page */
- if (ymd_compare(current, today) != 0)
- return;
-
- spixwin = (Pixwin *)canvas_pixwin(scanvas);
-
- x = font->pf_defaultsize.x;
- y = height = font->pf_defaultsize.y;
-
- gettimeofday(&tp, 0);
- riseset(tp.tv_sec);
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_GMT]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_TDT]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_LCT]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_LMT]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_GST]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_LST]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_JLD]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_LHA]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_SDE]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_SAZ]);
- y += height;
- pw_text(spixwin, x, y, PIX_SRC, font, riseset_buf[B_SEL]);
- }
-
- /*
- * write moon data to the popup canvas
- */
- write_moon_data()
- {
- int x, y, height;
- char buf[64];
- Pixwin *mpixwin;
- Rect *rect;
- struct timeval tp;
- double jdays, secs, offset;
- double julian_day();
-
- /* first erase the window. */
- mpixwin = (Pixwin *)canvas_pixwin(mcanvas);
- rect = (Rect *) window_get(mcanvas, WIN_RECT);
- pw_writebackground(mpixwin, 0, 0,
- rect->r_width, rect->r_height, PIX_CLR);
-
- x = font->pf_defaultsize.x;
- y = height = font->pf_defaultsize.y;
-
- gettimeofday(&tp, 0);
- if (ymd_compare(current, today) == 0) {
- /* use current time */
- riseset(tp.tv_sec);
- moon_data(tp.tv_sec);
- } else {
- /* convert today's date to approx. seconds from 1-1-1970 */
- jdays = julian_day((double)today.tm_mday, today.tm_mon+1, today.tm_year+1900) - J1970;
- /* seconds from 00:00 GMT to now */
- offset = tp.tv_sec - (jdays * 24. * 3600.);
- /* convert this date to seconds from 1-1-1970 */
- jdays = julian_day((double)current.tm_mday, current.tm_mon+1, current.tm_year+1900) - J1970;
- /* seconds to the same time on selected day */
- secs = (jdays * 24.0 * 3600.) + offset;
- riseset((long)secs);
- moon_data((long)secs);
- }
- panel_set(mdate_pi, PANEL_LABEL_STRING, riseset_buf[B_DMY], 0);
- y = 6 * height;
- sprintf(buf, "Moon Rise (today): %s", riseset_buf[B_MRD]);
- pw_text(mpixwin, x, y, PIX_SRC, font, buf);
- y += height;
- sprintf(buf, "Moon Set (today): %s", riseset_buf[B_MSD]);
- pw_text(mpixwin, x, y, PIX_SRC, font, buf);
- y += height;
- sprintf(buf, "Moon Rise (tomorrow): %s", riseset_buf[B_MRT]);
- pw_text(mpixwin, x, y, PIX_SRC, font, buf);
- y += height;
- sprintf(buf, "Moon Set (tomorrow): %s", riseset_buf[B_MST]);
- pw_text(mpixwin, x, y, PIX_SRC, font, buf);
- }
- #endif /* NO_SUN_MOON */
-