예제 #1
0
파일: weekglance.c 프로젝트: juddy/edcde
static int
week_xytoclock(Week *w, int x, int y)
{
    int     dow;

    /*
     * Convert the x and y location on the week view to a date
     */
    if (inchart(w, x, y)) {
        dow = (double)(x - w->chart_x)/(double)w->chart_day_width;
    } else if (inweek(w, x, y)) {
        if (y < w->y + w->day_height)
            dow = (x - w->x)/w->day_width;
        else
            dow = (x - w->x - 3 * w->day_width)/w->day_width
                  + 5;
    } else
        return(0);

    if (w->start_date == get_bot()) {
        if (dow < 3)
            return(-1);
        else
            dow = dow - 3;
    }
    else if (w->start_date == (time_t)last_ndays(get_eot(), 3)) {
        if (dow > 3) {
            return(-1);
        }
    }

    return(w->start_date + dow * daysec);
}
예제 #2
0
static void
display_monthpanels(Calendar *c)
{
	Day 	*d = (Day *)c->view->day_info;
	char 	buf[BUFSIZ];
	int	lastyear = year(get_eot());
	int	firstyear = year(get_bot());
	int	panel_year;
	int	panel_month;

	XtManageChild(d->panel_form);

	XtVaGetValues(d->month_panels[1],
		XmNyear, &panel_year,
		XmNmonth, &panel_month,
		NULL);

	if ((panel_year == firstyear) && (panel_month == 1)) {
		XtUnmapWidget(d->month_panels[0]);
		XtMapWidget(d->month_panels[2]);
		sprintf(buf, "%s", catgets(c->DT_catd, 1, 623, "Calendar does not display dates prior to January 1, 1970"));
		set_message(c->message_text, buf);
	}
	else if ((panel_year == lastyear) && (panel_month == 12)) {
		XtMapWidget(d->month_panels[0]);
		XtUnmapWidget(d->month_panels[2]);
		sprintf(buf, "%s", catgets(c->DT_catd, 1, 624, "Calendar does not display dates after December 31, 2037"));
		set_message(c->message_text, buf);
	}
	else {
		XtMapWidget(d->month_panels[0]);
		XtMapWidget(d->month_panels[2]);
		set_message(c->message_text, "");
	}

	/* switch canvas to attach using its XmNleftPosition value */
/* THIS IS THE RIGHT THIS TO DO, BUT ONLY AFTER REMOVING THE
   CODE THAT DRAWS THE OLD MO_BOXES.  FOR NOW, WE JUST MANAGE THE
   MONTHPANELS ON TOP OF THAT PART OF THE CANVAS - dac
	XtVaSetValues(c->canvas,
		XmNleftAttachment, XmATTACH_POSITION,
		XmNleftPosition, 40,
		NULL);
*/

}
예제 #3
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);
}
예제 #4
0
파일: weekglance.c 프로젝트: juddy/edcde
/*
 * Set up data needed to draw this particular week
 */
static void
init_week(Calendar *c, Boundary *boundary)
{
    Week *w = (Week *)c->view->week_info;
    int     char_width, char_height;
    Props   *p;
    int     num_hrs,        day_of_week;
    int     empty_space, day_box;
    int	skip_days = 0;
    XFontSetExtents regfontextents, boldfontextents;

    *boundary = okay;

    /*
     * The week view starts on Monday.  Map Sunday to the last day of the
     * week
     */
    if ((day_of_week = dow(c->view->date)) == 0)
        day_of_week = 6;
    else
        day_of_week--;

    ((Selection*)w->current_selection)->col = day_of_week;

    w->start_date = lowerbound(c->view->date - (day_of_week * daysec));
    /* make sure date is within bounds */
    if (w->start_date == -1) {
        if (year(c->view->date) == year(get_bot())) {
            w->start_date = get_bot();
            *boundary = lower;
        }
    }
    else if (year(next_ndays(w->start_date, 7)) > year(get_eot())) {
        *boundary = upper;
    }

    /*
     * Set up a bunch of variables which are needed to draw and fill
     * the week at a glance screen
     */
    XtVaGetValues(c->canvas,
                  XmNwidth, &w->canvas_w,
                  XmNheight, &w->canvas_h,
                  NULL);

    w->font = c->fonts->labelfont;
    w->small_font = c->fonts->viewfont;
    w->small_bold_font = c->fonts->boldfont;
    CalFontExtents(w->font, &regfontextents);
    CalFontExtents(w->small_bold_font, &boldfontextents);

    w->x = c->view->outside_margin;
    w->y = 2 * (int) boldfontextents.max_logical_extent.height;

    char_height = regfontextents.max_logical_extent.height;
    char_width = regfontextents.max_logical_extent.width;
    w->label_height = char_height * 2;
    w->day_width = ((int) (w->canvas_w - 2 * w->x)) / 5;
    /* height of box with label */
    w->day_height = ((int) (w->canvas_h - 2 * w->y)) / 2;
    /*
     * We compute week dimensions from day dimensions to remove rounding
     * errors
     */
    w->width = w->day_width * 5;
    /* height from top of box to bottom of weekend boxes */
    w->height = w->day_height * 2;

    p = (Props *)c->properties;
    w->begin_hour = get_int_prop(p, CP_DAYBEGIN);
    w->end_hour = get_int_prop(p, CP_DAYEND);

    /* width of a column in chart */
    w->chart_day_width = (3 * w->day_width - 3 * char_width) / 7;
    /* width of chart */
    w->chart_width = w->chart_day_width * 7;
    num_hrs = w->end_hour - w->begin_hour;

    /* height of box without label */
    day_box = w->day_height - w->label_height;

    /* height of an hour in chart */
    w->chart_hour_height = day_box / num_hrs;
    /* chart_hour_height must be evenly divisble by BOX_SEG */
    w->chart_hour_height -= (w->chart_hour_height % BOX_SEG);
    w->chart_height = w->chart_hour_height * num_hrs;

    /* x point of upper left corner of chart */
    w->chart_x = w->x + 2 * boldfontextents.max_logical_extent.width;
    /* y point of upper left corner of chart */
    w->chart_y = w->y + w->height - w->chart_height;

    /* left over empty space above chart after round off error */
    empty_space = day_box - w->chart_height;
    /* add pixels to the height of each hour box in chart to fill gap*/
    if (w->add_pixels = ((double)empty_space / (double)num_hrs)) {
        w->chart_y -= w->add_pixels * num_hrs;
        w->chart_height += w->add_pixels * num_hrs;
    }

    w->segs_in_array = BOX_SEG * num_hrs * 7;
    if (w->time_array != NULL)
        free(w->time_array);
    w->time_array = (char*)ckalloc(w->segs_in_array);

    c->view->outside_margin = w->x;
    c->view->topoffset = w->y;
}