static int count_day_pages(Calendar *c, int lines_per_page, Tick tick) { int n, i, j, timeslots, num_appts, pages, max = 0; Props *p = (Props *)c->properties; int daybegin = get_int_prop(p, CP_DAYBEGIN); int dayend = get_int_prop(p, CP_DAYEND); char *location; time_t start, end; CSA_return_code stat; CSA_entry_handle *list; CSA_attribute *range_attrs; CSA_enum *ops; CSA_uint32 a_total; for (i=daybegin; i < dayend; i++) { start = (time_t) lower_bound(i, tick); end = (time_t) next_nhours(start+1, 1) - 1; setup_range(&range_attrs, &ops, &j, start, end, 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); num_appts = count_multi_appts(list, a_total, c); if (num_appts > max) max = num_appts; csa_free(list); } pages = max / lines_per_page; if ((max % lines_per_page) > 0) pages++; return(pages); }
extern void day_event(XEvent *event) { static int lastcol, lastrow; static XEvent lastevent; pr_pos xy; int x, y, i, j; int boxw, boxh, margin, id; Calendar *c = calendar; Tick date = c->view->date; Boolean in_mbox = False; /* in month boxes ? */ Editor *e = (Editor*)c->editor; ToDo *t = (ToDo*)c->todo; GEditor *ge = (GEditor*)c->geditor; Day *day_info = (Day *)c->view->day_info; boxw = c->view->boxw; boxh = c->view->boxh; margin = c->view->outside_margin; x = event->xbutton.x; y = event->xbutton.y; /* boundary conditions */ if ((!(in_mbox = in_moboxes(c, x, y)) && x < MOBOX_AREA_WIDTH+2) || (x > MOBOX_AREA_WIDTH+2 && y < c->view->topoffset)) { lastcol=0; lastrow=0; return; } if (in_mbox) { xy.x = (x - margin)/ day_info->col_w; xy.y = (x - c->view->topoffset)/ day_info->row_h; } else { xy.x = boxw; xy.y = (y - c->view->topoffset)/boxh; } switch(event->type) { case MotionNotify: if (!in_mbox) { if (xy.x !=lastcol || xy.y !=lastrow) { calendar_deselect(c); j = day_xytoclock(c, xy.x, xy.y, date); if (j >= 0) { c->view->olddate = c->view->date; c->view->date = j; calendar_select(c, hourSelect, (caddr_t)&xy); } lastcol=xy.x; lastrow=xy.y; } } break; case ButtonPress: if (ds_is_double_click(&lastevent, event)) { _DtTurnOnHourGlass(c->frame); j = day_xytoclock(c, xy.x, xy.y, date); if (lastcol == xy.x && lastrow == xy.y) show_editor(c, j, next_nhours(j, 1), xy.y == 0 ? True : False); if (in_mbox) { monthbox_deselect(c); monthbox_xytodate(c, x, y); monthbox_select(c); } else show_editor(c, j, next_nhours(j, 1), xy.y == 0 ? True : False); _DtTurnOffHourGlass(c->frame); } else { if (in_mbox) { monthbox_deselect(c); monthbox_xytodate(c, x, y); paint_dayview(c, False, NULL, True); calendar_select(c, hourSelect, (caddr_t)NULL); monthbox_select(c); j = day_xytoclock(c, xy.x, xy.y, date); if (editor_showing(e)) { set_editor_defaults(e, j, next_nhours(j, 1), False); add_all_appt(e); } if (todo_showing(t)) { set_todo_defaults(t); add_all_todo(t); } if (geditor_showing(ge)) { set_geditor_defaults(ge, j, next_nhours(j, 1)); add_all_gappt(ge); } } else { calendar_deselect(c); j = day_xytoclock(c, xy.x, xy.y, date); if (j >= 0) { c->view->olddate = c->view->date; c->view->date = j; calendar_select(c, hourSelect, (caddr_t)&xy); if (editor_showing(e)) { set_editor_defaults(e, j, next_nhours(j, 1), xy.y == 0 ? True : False); add_all_appt(e); } if (todo_showing(t)) { set_todo_defaults(t); add_all_todo(t); } if (geditor_showing(ge)) { set_geditor_defaults(ge, j, next_nhours(j, 1)); add_all_gappt(ge); } } } } lastcol=xy.x; lastrow=xy.y; break; default: break; }; /* switch */ lastevent = *event; }
static Boolean _print_day(Calendar *c, int num_page, void *xp, Tick first_date, Props *p, Boolean first) { char buf[100]; int n, i, j, timeslots, num_appts, pages; int max = 0; int daybegin = get_int_prop(p, CP_DAYBEGIN); int dayend = get_int_prop(p, CP_DAYEND); OrderingType ord_t = get_int_prop(p, CP_DATEORDERING); Boolean more, done = False, all_done = True; char *location; CSA_return_code stat; CSA_entry_handle *list; CSA_attribute *range_attrs; CSA_enum *ops; CSA_uint32 a_total; time_t start, stop; int lines_per_page; static Tick tick = 0; static int total_pages = 0; /* * Need to find the max number of timeslots which will be shown * in one column, for later calculation of box height. */ if ((!morning(daybegin)) || dayend <= 12) timeslots = dayend - daybegin; else timeslots = ((12-daybegin) > (dayend-12)) ? (12-daybegin) : (dayend-12); x_init_printer(xp, PORTRAIT); x_init_day(xp, timeslots); lines_per_page = x_get_day_lines_per_page(xp); if (first) tick = first_date; if (num_page > 1) tick = prevday(tick); else total_pages = (lines_per_page > 0) ? count_day_pages(c, lines_per_page, tick) : 1; format_date(tick, ord_t, buf, 1, 0, 0); x_print_header(xp, buf, num_page, total_pages); x_day_header(xp); for (i=daybegin; i < dayend; i++) { start = (time_t) lower_bound(i, tick); stop = (time_t) next_nhours(start+1, 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); num_appts = count_multi_appts(list, a_total, c); if ((lines_per_page > 0) && (num_appts > (lines_per_page * num_page))) more = True; else more = False; x_day_timeslots (xp, i, more); if (lines_per_page > 0) done = x_print_multi_appts (xp, list, a_total, num_page, dayGlance); else done = True; if (!done) all_done = False; csa_free(list); } x_finish_printer(xp); tick = nextday(tick); return(all_done); }
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); }
extern void week_event(XEvent *event) { Calendar *c = calendar; Props *p = (Props*)c->properties; static int lastdate; static XEvent lastevent; int x, y, i, j, hr, id; Week *w = (Week *)c->view->week_info; Selection *wsel; Editor *e = (Editor *)c->editor; ToDo *t = (ToDo*)c->todo; GEditor *ge = (GEditor*)c->geditor; static int lastrow, lastcol; int row, col; x = event->xbutton.x; y = event->xbutton.y; wsel = (Selection *)w->current_selection; switch(event->type) { case MotionNotify: j = week_xytoclock(w, x, y); (col = dow(j)) == 0 ? col = 6 : col--; if (inchart(w, x, y)) row = (double)(y - w->chart_y) / (double)(w->chart_hour_height+ w->add_pixels); else row = wsel->row; if (j != lastdate || lastcol != col || lastrow != row) { calendar_deselect(c); wsel->row = row; wsel->col = col; if (j > 0) { c->view->olddate = c->view->date; c->view->date = j; calendar_select(c, weekdaySelect, NULL); } } lastcol = wsel->col; lastrow = wsel->row; lastdate = c->view->date; break; case ButtonPress: j = week_xytoclock(w, x, y); if (j == -1) return; hr = (inchart(w, x, y)) ? week_xytohour(w, x, y) : (wsel->row + w->begin_hour); if (ds_is_double_click(&lastevent, event)) { _DtTurnOnHourGlass(c->frame); if (j == lastdate) { show_editor(c, next_nhours(j, hr), next_nhours(j, hr + 1), False); } else if (editor_showing(e)) { set_editor_defaults(e, next_nhours(j, hr), next_nhours(j, hr + 1), False); add_all_appt(e); } _DtTurnOffHourGlass(c->frame); } else { calendar_deselect(c); (wsel->col = dow(j)) == 0 ? wsel->col = 6 : wsel->col--; if (inchart(w, x, y)) wsel->row = (double)(y - w->chart_y) / (double)(w->chart_hour_height + w->add_pixels); if (j > 0) { c->view->olddate = c->view->date; c->view->date = j; calendar_select(c, weekdaySelect, NULL); } if (editor_showing(e)) { set_editor_defaults(e, next_nhours(j, hr), next_nhours(j, hr + 1), False); add_all_appt(e); } if (todo_showing(t)) { set_todo_defaults(t); add_all_todo(t); } if (geditor_showing(ge)) { set_geditor_defaults(ge, 0, 0); add_all_gappt(ge); } } lastdate = c->view->date; lastcol = wsel->col; lastrow = wsel->row; break; default: break; }; /* switch */ lastevent = *event; }