extern void paint_day_header(Calendar *c, Tick date, void *rect) { Props *p = (Props*)c->properties; OrderingType ot = get_int_prop(p, CP_DATEORDERING); int pfy, x; char buf[100]; Boolean inrange = False; Colormap cmap; Pixel foreground_pixel; XFontSetExtents fontextents; struct tm *tm; _Xltimeparams localtime_buf; tm = _XLocaltime(&date, localtime_buf); CalFontExtents(c->fonts->labelfont, &fontextents); pfy = fontextents.max_logical_extent.height; XtVaGetValues(c->canvas, XmNcolormap, &cmap, NULL); XtVaGetValues(c->canvas, XmNforeground, &foreground_pixel, NULL); buf [0] = '\0'; /* NL_COMMENT Attention Translator: This string is used in the calendar day view. In the C locale it has the form: Monday, January 16, 1995 strftime conversion string: "%A, %B %e, %Y" is used. Use the appropriate strftime conversion for your locale. */ strftime(buf, 100, catgets(c->DT_catd, 1, 992, "%A, %B %e, %Y"), tm); inrange = today_inrange(c, date); x = gr_center(c->view->winw-(int)MOBOX_AREA_WIDTH, buf, c->fonts->labelfont) + (int)MOBOX_AREA_WIDTH; if (c->xcontext->screen_depth >= 8 && inrange) gr_text_rgb(c->xcontext, x, c->view->topoffset - (pfy/2), c->fonts->labelfont, buf, foreground_pixel, cmap, rect); else gr_text(c->xcontext, x, c->view->topoffset - (pfy/2), c->fonts->labelfont, buf, rect); }
extern void monthbox_datetoxy(Calendar *c) { char str[5]; int week, x_off, dayw, daym, mo; Day *day_info = (Day *) c->view->day_info; XFontSetExtents fontextents; int pfy; int col_w = day_info->col_w; int row_h = day_info->row_h; struct tm tm; _Xltimeparams localtime_buf; CalFontExtents(c->fonts->labelfont, &fontextents); pfy = fontextents.max_logical_extent.height; tm = *_XLocaltime(&c->view->date, localtime_buf); mo = tm.tm_mon+1; dayw = tm.tm_wday; daym = tm.tm_mday; week = (12+tm.tm_mday-tm.tm_wday)/7; day_info->day_selected_x = c->view->outside_margin + INSIDE_MARGIN + col_w*dayw; if (mo == month(day_info->month1)) day_info->day_selected_y = day_info->month1_y + row_h*week; else if (mo == month(day_info->month2)) day_info->day_selected_y = day_info->month2_y + row_h*week; else if (mo == month(day_info->month3)) day_info->day_selected_y = day_info->month3_y + row_h*week; sprintf(str, "%d", daym); x_off = gr_center(col_w, str, c->fonts->labelfont); day_info->day_selected_x2 = day_info->day_selected_x+x_off; day_info->day_selected_y2 = day_info->day_selected_y + pfy; day_info->day_selected = daym; }
extern void monthbox_xytodate(Calendar *c, int x, int y) { char str[5]; Day *day_info = (Day *)c->view->day_info; XFontSetExtents fontextents; int pfy; int col_w = day_info->col_w; int row_h = day_info->row_h; int row, col, x_off; int day_selected, tmpx; CalFontExtents(c->fonts->labelfont, &fontextents); pfy = fontextents.max_ink_extent.height; col = (x-c->view->outside_margin-INSIDE_MARGIN) / col_w; if (col < 0) return; tmpx = c->view->outside_margin + INSIDE_MARGIN + col * col_w; if (y < (day_info->month1_y + day_info->mobox_height1)) { row = (y-day_info->month1_y-row_h) / row_h; day_selected = (7 * (row+1)) - fdom(day_info->month1) - (6 - col); if (day_selected <= 0 || day_selected > monthlength(day_info->month1)) return; day_info->day_selected = day_selected; day_info->day_selected_y = day_info->month1_y + (row+1)*row_h; c->view->olddate = c->view->date; c->view->date = next_ndays(first_dom(day_info->month1), day_info->day_selected); } else if (y < (day_info->month2_y + day_info->mobox_height2)) { row = (y-day_info->month2_y-row_h) / row_h; day_selected = (7 * (row+1)) - fdom(day_info->month2) - (6 - col); if (day_selected <= 0 || day_selected > monthlength(day_info->month2)) return; day_info->day_selected = day_selected; day_info->day_selected_y = day_info->month2_y + (row+1)*row_h; c->view->olddate = c->view->date; c->view->date = next_ndays(first_dom(day_info->month2), day_info->day_selected); } else if (y < (day_info->month3_y + day_info->mobox_height3)) { row = (y-day_info->month3_y-row_h) / row_h; day_selected = (7 * (row+1)) - fdom(day_info->month3) - (6 - col); if (day_selected <= 0 || day_selected > monthlength(day_info->month3)) return; day_info->day_selected = day_selected; day_info->day_selected_y = day_info->month3_y + (row+1)*row_h; c->view->olddate = c->view->date; c->view->date = next_ndays(first_dom(day_info->month3), day_info->day_selected); } day_info->day_selected_x = tmpx; sprintf(str, "%d", day_info->day_selected); x_off = gr_center(col_w, str, c->fonts->labelfont); day_info->day_selected_x2 = day_info->day_selected_x+x_off; day_info->day_selected_y2 = day_info->day_selected_y + pfy; }
static void paint_dayview_appts(Calendar *c, Paint_cache *cache, int a_total, void *rect) { int w = c->view->boxw; int h = c->view->boxh; int begin_time, end_time; int x, x2, y, y2, num_hrs, i, last_hr, hr, x_off; Cal_Font *pf = c->fonts->boldfont; Cal_Font *pf2 = c->fonts->viewfont; XFontSetExtents fontextents; XFontSetExtents fontextents2; Props *p = (Props*)c->properties; Boolean am = True; char buf[5], *appt_str; int pfy, curr_line, maxlines; Lines *lines = NULL, *headlines = NULL; DisplayType disp_t; Colormap cmap; Pixel fg; Tick start_tick, end_tick; int nop, hrbox_margin; CalFontExtents(pf, &fontextents); CalFontExtents(pf2, &fontextents2); XtVaGetValues(c->canvas, XmNcolormap, &cmap, XmNforeground, &fg, NULL); /* draw horizontal lines */ begin_time = get_int_prop(p, CP_DAYBEGIN); end_time = get_int_prop(p, CP_DAYEND); disp_t = get_int_prop(p, CP_DEFAULTDISP); num_hrs = end_time - begin_time + 1; if (disp_t == HOUR12) CalTextExtents(pf, "12pm", 4, &nop, &nop, &hrbox_margin, &nop); else CalTextExtents(pf, "24 ", 3, &nop, &nop, &hrbox_margin, &nop); x = MOBOX_AREA_WIDTH+2; x2 = x + w; y = c->view->topoffset; for (i = 0; i <= num_hrs; i++) { gr_draw_line(c->xcontext, x, y, x2, y, gr_solid, rect); y += h; } /* draw vertical line */ y = c->view->topoffset; y2 = y + num_hrs * h; x += hrbox_margin; gr_draw_line(c->xcontext, x, y, x, y2, gr_solid, rect); x = MOBOX_AREA_WIDTH+3; y += h/2+4; /* draw in hours */ for (i = begin_time - 1; i < end_time; i++) { hr = i; if (i < begin_time) (void) sprintf(buf, ""); else if (disp_t == HOUR12) { am = adjust_hour(&hr); (void) sprintf(buf, "%d%s", hr, am ? "a" : "p"); } else (void) sprintf(buf, "%02d", hr); x_off = gr_center(hrbox_margin, buf, pf); /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x+x_off, y, pf, buf, fg, cmap, rect); else */ gr_text(c->xcontext, x+x_off, y, pf, buf, rect); y += h; } /* draw in appointments */ x = MOBOX_AREA_WIDTH + hrbox_margin + 6; pfy = fontextents2.max_logical_extent.height; maxlines = (h - 6) / pfy; curr_line = last_hr = 0; /* loop thru, getting out the "no time" appointments */ for (i = 0; i < a_total; i++) { if (i != a_total) last_hr = hr; hr = begin_time; if (cache[i].show_time == 0) { if (last_hr != hr) curr_line = 0; y = c->view->topoffset + 2 + pfy; if (curr_line < maxlines) { y += (curr_line * pfy) + h * (hr - begin_time); headlines = lines = text_to_lines(cache[i].summary, 4); start_tick = cache[i].start_time; end_tick = cache[i].end_time; if (lines != NULL && lines->s != NULL) { appt_str = ckalloc(cm_strlen(lines->s)+18); format_line(start_tick, lines->s, appt_str, end_tick, cache[i].show_time, disp_t); lines = lines->next; } else { appt_str = ckalloc(15); format_line(start_tick, (char*)NULL, appt_str, end_tick, cache[i].show_time, disp_t); } appt_str[cm_strlen(appt_str)]=NULL; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); free(appt_str); appt_str = NULL; curr_line++; if (curr_line < maxlines && lines != NULL) { appt_str = ckalloc(324); cm_strcpy(appt_str, " "); while (lines != NULL) { if (lines->s != NULL) cm_strcat(appt_str, lines->s); lines = lines->next; if (lines != NULL && lines->s != NULL) cm_strcat(appt_str, " - "); } y += pfy; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); curr_line++; free(appt_str); appt_str = NULL; } destroy_lines(headlines); lines=NULL; } } } for (i = 0; i < a_total; i++) { if (i != a_total) last_hr = hr; start_tick = cache[i].start_time; end_tick = cache[i].end_time; hr = hour(start_tick); if (hr >= begin_time && hr < end_time && (cache[i].show_time && !magic_time(start_tick))) { if (last_hr != hr) curr_line = 0; y = c->view->topoffset + 2 + pfy; if (curr_line < maxlines) { y += (curr_line * pfy) + h * (hr - begin_time + 1); headlines = lines = text_to_lines(cache[i].summary, 4); if (lines != NULL && lines->s != NULL) { appt_str = ckalloc(cm_strlen(lines->s)+18); format_line(start_tick, lines->s, appt_str, end_tick, cache[i].show_time, disp_t); lines = lines->next; } else { appt_str = ckalloc(15); format_line(start_tick, (char*)NULL, appt_str, end_tick, cache[i].show_time, disp_t); } appt_str[cm_strlen(appt_str)]=NULL; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); free(appt_str); appt_str = NULL; curr_line++; if (curr_line < maxlines && lines != NULL) { appt_str = ckalloc(324); cm_strcpy(appt_str, " "); while (lines != NULL) { if (lines->s != NULL) cm_strcat(appt_str, lines->s); lines = lines->next; if (lines != NULL && lines->s != NULL) cm_strcat(appt_str, " - "); } y += pfy; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); curr_line++; free(appt_str); appt_str = NULL; } destroy_lines(headlines); lines=NULL; } } } }
static void draw_chart(Calendar *c, register Week *w, XRectangle *rect) { register int x, y; int n; XFontSetExtents fontextents; int char_height; char label[5]; new_XContext *xc = c->xcontext; Props *p = (Props*)c->properties; DisplayType dt = get_int_prop(p, CP_DEFAULTDISP); CalFontExtents(w->font, &fontextents); char_height = fontextents.max_logical_extent.height; /* * Draw chart. We first draw all the lines, then the labels * so that Xlib can batch the lines into 1 X request */ /* Draw horizontal lines for time */ x = w->chart_x; y = w->chart_y; for (n = w->begin_hour; n <= w->end_hour; n++) { gr_draw_line(xc, x, y, x + w->chart_width, y, gr_solid, rect); y += w->chart_hour_height + w->add_pixels; } /* Draw vertical lines for days */ y = w->chart_y; for (n = 0; n < 7; n++) { gr_draw_line(xc, w->chart_x + (w->chart_day_width * n), y, w->chart_x + (w->chart_day_width * n), y + w->chart_height, gr_solid, rect); } /* * Draw box around the whole thing. */ gr_draw_box(xc, w->chart_x, w->chart_y, w->chart_width, w->chart_height, rect); gr_draw_box(xc, w->chart_x - 1, w->chart_y - 1, w->chart_width + 2, w->chart_height + 2, rect); /* Label horizontal lines with time of day */ x = w->chart_x; y = w->chart_y; for (n = w->begin_hour; n <= w->end_hour; n++) { if (dt == HOUR12) sprintf(label, "%2d", n > 12 ? n - 12 : n); else sprintf(label, "%2d", n); gr_text(xc, w->x - 8, y+3, w->small_bold_font, label, rect); y += w->chart_hour_height + w->add_pixels; } /* Label vertical lines with day labels */ y = w->chart_y; for (n = 0; n < 7; n++) { x = gr_center(w->chart_day_width, days3[n+1], w->font); gr_text(xc, w->chart_x + (w->chart_day_width * n) + x, y - char_height / 2, w->font, days3[n+1], rect); } }