Beispiel #1
0
extern void
paint_dayview(Calendar *c, Boolean repaint, XRectangle *rect, Boolean update_months)
{
	Props 		*p = (Props*)c->properties;
	int 		num_hrs;
	int 		beg = get_int_prop(p, CP_DAYBEGIN);
	int 		end = get_int_prop(p, CP_DAYEND);
	time_t 		start, stop;
	CSA_attribute 		*range_attrs;
        CSA_entry_handle 	*list;
	CSA_enum 	*ops;
	int 		i, j;
	CSA_uint32 	a_total;
	int		panel0_year, panel0_month;
	int		panel1_year, panel1_month;
	int		panel2_year, panel2_month;
	int		year_num, month_num;
	Boolean		day_not_on_panel = False;
	Day 		*d = (Day *)c->view->day_info;
	int		top_panel = 0;
	int		bottom_panel = 2;

	num_hrs = end - beg + 1;
	if (c->paint_cache == NULL) {
		start = (time_t) lower_bound(0, c->view->date);
        	stop = (time_t) next_nhours(start, end+1) - 1;
		setup_range(&range_attrs, &ops, &j, start, stop, CSA_TYPE_EVENT, NULL,
		    	B_FALSE, c->general->version);
        	csa_list_entries(c->cal_handle, j, range_attrs, ops, &a_total, &list, NULL);
	
		free_range(&range_attrs, &ops, j);
		allocate_paint_cache(list, a_total, &c->paint_cache);
		c->paint_cache_size = a_total;
		csa_free(list);
	}

	year_num = year(c->view->date);
	month_num = month(c->view->date);
	XtVaGetValues(d->month_panels[1],
		XmNyear, &panel1_year,
		XmNmonth, &panel1_month,
		NULL);

	if ((panel1_year == year(get_bot())) && (panel1_month == 1))
		top_panel = 1;
	else if ((panel1_year == year(get_eot())) && (panel1_month == 12))
		bottom_panel = 1;

	XtVaGetValues(d->month_panels[top_panel],
		XmNyear, &panel0_year,
		XmNmonth, &panel0_month,
		NULL);

	if ((year_num < panel0_year) || 
	    ((year_num == panel0_year) && (month_num < panel0_month)))
		day_not_on_panel = True;
	
	XtVaGetValues(d->month_panels[bottom_panel],
		XmNyear, &panel2_year,
		XmNmonth, &panel2_month,
		NULL);

	if ((year_num > panel2_year) || 
	    ((year_num == panel2_year) && (month_num > panel2_month)))
		day_not_on_panel = True;

	/* set up month panels */
	if (update_months || day_not_on_panel)
		update_quarter(c);

	/* no need to do this on a damage event */

	if (!rect)
		display_monthpanels(c);

	/* repaint appointment area */
	if (repaint) {
		int	line_length;

		gr_clear_area(c->xcontext, 0, 0, 
			c->view->winw, c->view->winh);
		line_length = c->view->topoffset + 
			      ((end - beg + 1) * c->view->boxh);
		/* draw line separating mo. boxes and appts. */
        	gr_draw_line(c->xcontext, (int)MOBOX_AREA_WIDTH+1,
			 0, (int)MOBOX_AREA_WIDTH+1,
                         line_length, gr_solid, rect);
        	gr_draw_line(c->xcontext, (int)MOBOX_AREA_WIDTH+2, 
			 0, (int)MOBOX_AREA_WIDTH+2,
                         line_length, gr_solid, rect);
        	gr_draw_line(c->xcontext, (int)MOBOX_AREA_WIDTH+2, 
			 c->view->topoffset-1, c->view->winw,
                         c->view->topoffset-1,  gr_solid, rect);
        	gr_draw_line(c->xcontext, (int)MOBOX_AREA_WIDTH+2, 
			 c->view->topoffset, c->view->winw,
                         c->view->topoffset, gr_solid, rect);
		paint_dayview_appts(c, c->paint_cache, c->paint_cache_size, rect);
	}
	/* just repaint schedule area */
	else {
		gr_clear_area(c->xcontext, 
				(int)MOBOX_AREA_WIDTH+4, 0, 
				c->view->winw - (int)MOBOX_AREA_WIDTH+4,
				c->view->winh);
        	gr_draw_line(c->xcontext, (int)MOBOX_AREA_WIDTH+2, 
			 c->view->topoffset, c->view->winw,
                         c->view->topoffset,  gr_solid, rect);
        	gr_draw_line(c->xcontext, (int)MOBOX_AREA_WIDTH+2, 
			 c->view->topoffset+1, c->view->winw,
                         c->view->topoffset+1, gr_solid, rect);
		paint_dayview_appts(c, c->paint_cache, c->paint_cache_size, rect);
	}

	paint_day_header(c, c->view->date, rect);
}
Beispiel #2
0
static void
draw_week(Calendar *c, XRectangle *rect, Boundary boundary)
{
    Week *w = (Week *)c->view->week_info;
    register int    current_day;
    register int    n;
    register int    x, y;
    int             char_height;
    int             start_date;
    char            **day_names;
    char            label[80];
    char		buf[MAXNAMELEN];
    char		*footer_message = NULL;
    int             start_ind, end_ind;
    int             today_dom, day_om;
    new_XContext        *xc;
    Props           *p = (Props*)c->properties;
    XRectangle      chartrect;
    OrderingType	ot = get_int_prop(p, CP_DATEORDERING);
    Tick		start_tick, end_tick;
    time_t start, stop;
    CSA_return_code stat;
    CSA_entry_handle *list;
    CSA_attribute *range_attrs;
    CSA_enum *ops;
    CSA_uint32 a_total;
    int i, lower_bound = 0, upper_bound = 0;
    XFontSetExtents regfontextents, boldfontextents;
    int	notused, width1, width2, width3;

    CalFontExtents(w->font, &regfontextents);
    char_height = regfontextents.max_logical_extent.height;
    start_date      = w->start_date;
    xc              = c->xcontext;

    start = (time_t) lowerbound(start_date);
    stop = (time_t) next_ndays(start, 7) - 1;

    if (c->paint_cache == NULL) {
        setup_range(&range_attrs, &ops, &i, start, stop, CSA_TYPE_EVENT,
                    0, B_FALSE, c->general->version);
        csa_list_entries(c->cal_handle, i, range_attrs, ops,
                         &a_total, &list, NULL);
        free_range(&range_attrs, &ops, i);
        allocate_paint_cache(list, a_total, &c->paint_cache);
        c->paint_cache_size = a_total;
        csa_free(list);
    }


    gr_clear_box(xc, 0, 0, w->canvas_w, w->canvas_h);

    CalTextExtents(w->font, days2[3], cm_strlen(days2[3]),
                   &notused, &notused, &width1, &notused);
    CalTextExtents(w->font, "  00", cm_strlen("  00"),
                   &notused, &notused, &width2, &notused);
    CalTextExtents(w->font, "Wed 00", cm_strlen("Wed 00"),
                   &notused, &notused, &width3, &notused);
    if (width1 + width2 <= w->day_width - 2)
        day_names = days2;
    else if (width3 <= w->day_width - 2)
        day_names = days;
    else
        day_names = days3;
    x = w->x;
    y = w->y;

    format_week_header(start_date, ot, label);
    gr_text(xc, x, y - char_height / 2, w->font, label, rect);

    /*
     * Draw bold box around first 5 days
     */
    gr_draw_box(xc, x, y, w->width, w->day_height, rect);
    gr_draw_box(xc, x - 1, y - 1, w->width + 2, w->day_height + 2, rect);
    gr_draw_line(xc, x, y + w->label_height, x + w->width,
                 y + w->label_height, gr_solid, rect);

    /*
     * Draw bold box around last 2 days
     */
    x += 3 * w->day_width;
    y += w->day_height;

    gr_draw_box(xc, x, y, 2 * w->day_width, w->day_height, rect);
    gr_draw_box(xc, x - 1, y, 2 * w->day_width + 2, w->day_height + 1,rect);
    gr_draw_line(xc, x, y + w->label_height, x + 2 * w->day_width,
                 y + w->label_height, gr_solid, rect);
    y = w->y;
    x = w->x + w->day_width;
    for (n = 0; n < 4; n++) {
        if (n < 3) {
            gr_draw_line(xc, x, y, x, y + w->day_height,
                         gr_solid, rect);
        } else {
            gr_draw_line(xc, x, y, x, y + 2 * w->day_height,
                         gr_solid, rect);
        }
        x += w->day_width;
    }
    /*
      * Fill in week with appointments
      */
    x = w->x;
    y = w->y;
    current_day = start_date;
    today_dom = dom(time(0));

    /* Crock alert!!!!  The obscure code below is doing something
       really nasty.  The variable boundary indicates whether the
       week being displayed falls across a boundary with the
       beginning or the end of time.  In the case of the beginning
       of time, the code then assumes that the first 2 days in the
       week need to be unbuttoned, and the rest buttoned and painted.
       Likewise, with the end of time case, the code assumes the last
       3 days of the week need similar treatment. */

    for (n = 0; n < 7; n++)  {

        if (n == 5) {
            y += w->day_height;
            x = w->x + 3 * w->day_width;
        }

        if (boundary == okay) {
            day_om = dom(current_day);
            display_hot_btn(c, n, day_om);
            fill_day(c, w, x, y, current_day,
                     c->paint_cache, c->paint_cache_size, rect);
            current_day += daysec;
            if (lower_bound > 0) {
                sprintf(buf, "%s", catgets(c->DT_catd, 1, 623, "Calendar does not display dates prior to January 1, 1970"));
                footer_message = buf;
            }
            else
                footer_message = NULL;
        }
        else if (boundary == lower) {
            /* skip days before Jan 1, 1970 */
            clear_hot_btn(c, n);
            if (lower_bound++ == 2)
                boundary = okay;
        }
        else if (boundary == upper) {
            day_om = dom(current_day);
            if (++upper_bound <= 4)
                display_hot_btn(c, n, day_om);
            fill_day(c, w, x, y, current_day,
                     c->paint_cache, c->paint_cache_size, rect);
            current_day += daysec;
            sprintf(buf, "%s", catgets(c->DT_catd, 1, 624, "Calendar does not display dates after December 31, 2037"));
            footer_message = buf;
            if (upper_bound > 4)
                clear_hot_btn(c, n);
        }
        x += w->day_width;
    }
    if (rect != NULL) {
        CalFontExtents(w->small_bold_font, &boldfontextents);

        chartrect.x = w->x;
        chartrect.y = w->chart_y - w->label_height;
        chartrect.width = w->chart_width +
                          3*boldfontextents.max_logical_extent.width;
        chartrect.height = w->chart_height + 2*w->label_height;
    }

    if (rect == NULL || myrect_intersectsrect(rect,  &chartrect)) {
        for (i = 0; i < c->paint_cache_size; i++) {
            start_tick = (c->paint_cache)[i].start_time;
            end_tick = (c->paint_cache)[i].end_time;
            cm_update_segs(w, start_tick,
                           (end_tick ? (end_tick - start_tick) : 0),
                           &start_ind, &end_ind, True);
        }
        chart_draw_appts(w, 0, w->segs_in_array);
        draw_chart(c, w, NULL);
    }

    /* do not repaint the footer message in a damage display.
       For some reason this causes the damage routine to get called
       again, resulting in a recursive dsaster. */

    if (footer_message && !rect)
        set_message(c->message_text, footer_message);
}
Beispiel #3
0
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;
			}
		}
	}
}
Beispiel #4
0
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);
    }

}