diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2009-09-22 07:25:41 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2009-09-22 22:34:26 +0800 |
commit | 7be192643685acdc081332fc9177417d67870c53 (patch) | |
tree | 1c04a080735ed962b6dd89594e16efbf62ed5123 /calendar/gui | |
parent | 5a80f92d37e7e8a814f70f826b7b33f5d21b0f72 (diff) | |
download | gsoc2013-evolution-7be192643685acdc081332fc9177417d67870c53.tar.gz gsoc2013-evolution-7be192643685acdc081332fc9177417d67870c53.tar.zst gsoc2013-evolution-7be192643685acdc081332fc9177417d67870c53.zip |
Calendar canvas item cleanup.
Diffstat (limited to 'calendar/gui')
-rw-r--r-- | calendar/gui/e-day-view-main-item.c | 1000 | ||||
-rw-r--r-- | calendar/gui/e-day-view-main-item.h | 64 | ||||
-rw-r--r-- | calendar/gui/e-day-view-time-item.c | 460 | ||||
-rw-r--r-- | calendar/gui/e-day-view-time-item.h | 76 | ||||
-rw-r--r-- | calendar/gui/e-day-view-top-item.c | 819 | ||||
-rw-r--r-- | calendar/gui/e-day-view-top-item.h | 75 | ||||
-rw-r--r-- | calendar/gui/e-day-view.c | 2 | ||||
-rw-r--r-- | calendar/gui/e-week-view-event-item.c | 1321 | ||||
-rw-r--r-- | calendar/gui/e-week-view-event-item.h | 70 | ||||
-rw-r--r-- | calendar/gui/e-week-view-main-item.c | 395 | ||||
-rw-r--r-- | calendar/gui/e-week-view-main-item.h | 65 | ||||
-rw-r--r-- | calendar/gui/e-week-view-titles-item.c | 242 | ||||
-rw-r--r-- | calendar/gui/e-week-view-titles-item.h | 64 | ||||
-rw-r--r-- | calendar/gui/e-week-view.c | 9 | ||||
-rw-r--r-- | calendar/gui/ea-day-view-main-item.c | 66 | ||||
-rw-r--r-- | calendar/gui/ea-week-view-main-item.c | 58 |
16 files changed, 2671 insertions, 2115 deletions
diff --git a/calendar/gui/e-day-view-main-item.c b/calendar/gui/e-day-view-main-item.c index a3f951b276..6b34018fe7 100644 --- a/calendar/gui/e-day-view-main-item.c +++ b/calendar/gui/e-day-view-main-item.c @@ -29,6 +29,9 @@ #include <config.h> #endif +#include <libecal/e-cal-time-util.h> +#include <e-calendar-view.h> + #include "e-util/e-categories-config.h" #include "e-day-view-layout.h" #include "e-day-view-main-item.h" @@ -36,125 +39,21 @@ #include "e-calendar-view.h" #include "comp-util.h" #include "calendar-config.h" -#include <libecal/e-cal-time-util.h> -#include <e-calendar-view.h> -static void e_day_view_main_item_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void e_day_view_main_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, gint flags); -static void e_day_view_main_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - gint x, gint y, - gint width, gint height); -static double e_day_view_main_item_point (GnomeCanvasItem *item, - double x, double y, - gint cx, gint cy, - GnomeCanvasItem **actual_item); -static gint e_day_view_main_item_event (GnomeCanvasItem *item, - GdkEvent *event); - -static void e_day_view_main_item_draw_long_events_in_vbars (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height, GdkRegion *draw_region); -static void e_day_view_main_item_draw_events_in_vbars (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - gint x, gint y, - gint width, gint height, - gint day, GdkRegion *draw_region); -static void e_day_view_main_item_draw_day_events (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - gint x, gint y, - gint width, gint height, - gint day, GdkRegion *draw_region); -static void e_day_view_main_item_draw_day_event (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - gint x, gint y, - gint width, gint height, - gint day, gint event_num, GdkRegion *draw_region); - -/* The arguments we take */ +#define E_DAY_VIEW_MAIN_ITEM_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_DAY_VIEW_MAIN_ITEM, EDayViewMainItemPrivate)) + +struct _EDayViewMainItemPrivate { + EDayView *day_view; +}; + enum { PROP_0, PROP_DAY_VIEW }; -G_DEFINE_TYPE (EDayViewMainItem, e_day_view_main_item, GNOME_TYPE_CANVAS_ITEM) - -static void -e_day_view_main_item_class_init (EDayViewMainItemClass *class) -{ - GObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = G_OBJECT_CLASS (class); - object_class->set_property = e_day_view_main_item_set_property; - - item_class = GNOME_CANVAS_ITEM_CLASS (class); - item_class->update = e_day_view_main_item_update; - item_class->draw = e_day_view_main_item_draw; - item_class->point = e_day_view_main_item_point; - item_class->event = e_day_view_main_item_event; - - g_object_class_install_property ( - object_class, - PROP_DAY_VIEW, - g_param_spec_pointer ( - "day_view", - NULL, - NULL, - G_PARAM_WRITABLE)); - - /* init the accessibility support for e_day_view */ - e_day_view_main_item_a11y_init (); -} - -static void -e_day_view_main_item_init (EDayViewMainItem *dvtitem) -{ - dvtitem->day_view = NULL; -} - -static void -e_day_view_main_item_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - EDayViewMainItem *dvmitem; - - dvmitem = E_DAY_VIEW_MAIN_ITEM (object); - - switch (property_id) { - case PROP_DAY_VIEW: - dvmitem->day_view = g_value_get_pointer (value); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -e_day_view_main_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - gint flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (e_day_view_main_item_parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (e_day_view_main_item_parent_class)->update) (item, affine, clip_path, flags); - - /* The item covers the entire canvas area. */ - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; -} +static gpointer parent_class; static gboolean can_draw_in_region (GdkRegion *draw_region, gint x, gint y, gint width, gint height) @@ -186,326 +85,14 @@ icalcomp_is_transparent (icalcomponent *icalcomp) return transp_prop && (ical_transp == ICAL_TRANSP_TRANSPARENT || ical_transp == ICAL_TRANSP_TRANSPARENTNOCONFLICT); } -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ -static void -e_day_view_main_item_draw (GnomeCanvasItem *canvas_item, GdkDrawable *drawable, - gint x, gint y, gint width, gint height) -{ - EDayViewMainItem *dvmitem; - EDayView *day_view; - GtkStyle *style; - GdkGC *gc; - gint row, row_y, grid_x1, grid_x2; - gint day, grid_y1, grid_y2; - gint work_day_start_y, work_day_end_y; - gint day_x, day_w, work_day; - gint start_row, end_row, rect_x, rect_y, rect_width, rect_height; - struct icaltimetype day_start_tt, today_tt; - gint weekday; - cairo_t *cr; - gboolean today = FALSE; - GdkRegion *draw_region; - GdkRectangle rect; - - cr = gdk_cairo_create (drawable); - -#if 0 - g_print ("In e_day_view_main_item_draw %i,%i %ix%i\n", - x, y, width, height); -#endif - - dvmitem = E_DAY_VIEW_MAIN_ITEM (canvas_item); - day_view = dvmitem->day_view; - g_return_if_fail (day_view != NULL); - - style = gtk_widget_get_style (GTK_WIDGET (day_view)); - rect.x = 0; - rect.y = 0; - rect.width = width; - rect.height = height; - draw_region = gdk_region_rectangle (&rect); - - /* Paint the background colors. */ - work_day_start_y = e_day_view_convert_time_to_position (day_view, day_view->work_day_start_hour, day_view->work_day_start_minute) - y; - gc = day_view->main_gc; - work_day_end_y = e_day_view_convert_time_to_position (day_view, day_view->work_day_end_hour, day_view->work_day_end_minute) - y; - - today_tt = icaltime_from_timet_with_zone (time (NULL), FALSE, - e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view))); - - for (day = 0; day < day_view->days_shown; day++) { - day_start_tt = icaltime_from_timet_with_zone (day_view->day_starts[day], FALSE, - e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view))); - weekday = icaltime_day_of_week (day_start_tt) - 1; - - work_day = day_view->working_days & (1 << weekday); - - day_x = day_view->day_offsets[day] - x; - day_w = day_view->day_widths[day]; - - if (work_day) { - if (can_draw_in_region (draw_region, day_x, 0 - y, day_w, work_day_start_y - (0 - y))) { - cairo_save (cr); - gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_NOT_WORKING]); - cairo_rectangle (cr, day_x, 0 - y, day_w, work_day_start_y - (0 - y)); - cairo_fill (cr); - cairo_restore (cr); - } - - if (day_view->days_shown > 1) { - /* Check if we are drawing today */ - today = day_start_tt.year == today_tt.year - && day_start_tt.month == today_tt.month - && day_start_tt.day == today_tt.day; - } else { - today = FALSE; - } - - if (can_draw_in_region (draw_region, day_x, work_day_start_y, day_w, work_day_end_y - work_day_start_y)) { - cairo_save (cr); - gdk_cairo_set_source_color (cr, &day_view->colors[today ? E_DAY_VIEW_COLOR_BG_MULTIDAY_TODAY : E_DAY_VIEW_COLOR_BG_WORKING]); - cairo_rectangle (cr, day_x, work_day_start_y, day_w, work_day_end_y - work_day_start_y); - cairo_fill (cr); - cairo_restore (cr); - } - - if (can_draw_in_region (draw_region, day_x, work_day_end_y, day_w, height - work_day_end_y)) { - cairo_save (cr); - gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_NOT_WORKING]); - cairo_rectangle (cr, day_x, work_day_end_y, day_w, height - work_day_end_y); - cairo_fill (cr); - cairo_restore (cr); - } - } else if (can_draw_in_region (draw_region, day_x, 0, day_w, height)) { - cairo_save (cr); - gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_NOT_WORKING]); - cairo_rectangle (cr, day_x, 0, day_w, height); - cairo_fill (cr); - cairo_restore (cr); - } - } - - /* Paint the selection background. */ - if (day_view->selection_start_day != -1 - && !day_view->selection_in_top_canvas) { - for (day = day_view->selection_start_day; - day <= day_view->selection_end_day; - day++) { - if (day == day_view->selection_start_day - && day_view->selection_start_row != -1) - start_row = day_view->selection_start_row; - else - start_row = 0; - if (day == day_view->selection_end_day - && day_view->selection_end_row != -1) - end_row = day_view->selection_end_row; - else - end_row = day_view->rows - 1; - - rect_x = day_view->day_offsets[day] - x; - rect_width = day_view->day_widths[day]; - rect_y = start_row * day_view->row_height - y; - rect_height = (end_row - start_row + 1) * day_view->row_height; - - if (can_draw_in_region (draw_region, rect_x, rect_y, rect_width, rect_height)) { - cairo_save (cr); - gdk_cairo_set_source_color (cr, &day_view->colors[GTK_WIDGET_HAS_FOCUS(day_view) ? E_DAY_VIEW_COLOR_BG_SELECTED : E_DAY_VIEW_COLOR_BG_SELECTED_UNFOCUSSED]); - cairo_rectangle (cr, rect_x, rect_y, rect_width, rect_height); - cairo_fill (cr); - cairo_restore (cr); - } - } - } - - /* Drawing the horizontal grid lines. */ - grid_x1 = day_view->day_offsets[0] - x; - grid_x2 = day_view->day_offsets[day_view->days_shown] - x; - - cairo_save(cr); - gdk_cairo_set_source_color (cr, - &day_view->colors[E_DAY_VIEW_COLOR_BG_GRID]); - - for (row = 0, row_y = 0 - y; - row < day_view->rows && row_y < height; - row++, row_y += day_view->row_height) { - if (row_y >= 0 && row_y < height) { - cairo_set_line_width (cr, 0.7); - cairo_move_to (cr, grid_x1, row_y); - cairo_line_to (cr, grid_x2, row_y); - cairo_stroke (cr); - } - } - cairo_restore (cr); - - /* Draw the vertical bars down the left of each column. */ - grid_y1 = 0; - grid_y2 = height; - for (day = 0; day < day_view->days_shown; day++) { - grid_x1 = day_view->day_offsets[day] - x; - - /* Skip if it isn't visible. */ - if (grid_x1 >= width || grid_x1 + E_DAY_VIEW_BAR_WIDTH <= 0) - continue; - cairo_save (cr); - - gdk_cairo_set_source_color (cr, - &day_view->colors[E_DAY_VIEW_COLOR_BG_GRID]); - cairo_move_to (cr, grid_x1, grid_y1); - cairo_line_to (cr, grid_x1, grid_y2); - cairo_stroke (cr); - - gdk_cairo_set_source_color (cr, - &day_view->colors[E_DAY_VIEW_COLOR_BG_GRID]); - - cairo_move_to (cr, grid_x1 + E_DAY_VIEW_BAR_WIDTH - 1, grid_y1); - cairo_line_to (cr, grid_x1 + E_DAY_VIEW_BAR_WIDTH - 1, grid_y2); - cairo_stroke (cr); - - cairo_set_source_rgb (cr, 1, 1, 1); - - cairo_rectangle (cr, grid_x1 + 1, grid_y1, - E_DAY_VIEW_BAR_WIDTH - 2, grid_y2 - grid_y1); - - cairo_fill (cr); - - cairo_restore (cr); - - /* Fill in the bars when the user is busy. */ - e_day_view_main_item_draw_events_in_vbars (dvmitem, drawable, - x, y, - width, height, - day, draw_region); - } - - /* Fill in the vertical bars corresponding to the busy times from the - long events. */ - e_day_view_main_item_draw_long_events_in_vbars (dvmitem, drawable, - x, y, width, height, draw_region); - - /* Draw the event borders and backgrounds, and the vertical bars - down the left edges. */ - for (day = 0; day < day_view->days_shown; day++) { - e_day_view_main_item_draw_day_events (dvmitem, drawable, - x, y, width, height, - day, draw_region); - } - - if (e_day_view_marcus_bains_get_show_line (day_view)) { - icaltimezone *zone; - struct icaltimetype time_now, day_start; - gint marcus_bains_y; - GdkColor mb_color; - - cairo_save (cr); - gdk_cairo_set_source_color (cr, - &day_view->colors[E_DAY_VIEW_COLOR_MARCUS_BAINS_LINE]); - - if (day_view->marcus_bains_day_view_color && gdk_color_parse (day_view->marcus_bains_day_view_color, &mb_color)) { - GdkColormap *colormap; - - colormap = gtk_widget_get_colormap (GTK_WIDGET (day_view)); - if (gdk_colormap_alloc_color (colormap, &mb_color, TRUE, TRUE)) - gdk_cairo_set_source_color (cr, &mb_color); - } - zone = e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)); - time_now = icaltime_current_time_with_zone (zone); - - for (day = 0; day < day_view->days_shown; day++) { - day_start = icaltime_from_timet_with_zone (day_view->day_starts[day], FALSE, zone); - - if ((day_start.year == time_now.year) && - (day_start.month == time_now.month) && - (day_start.day == time_now.day)) { - - grid_x1 = day_view->day_offsets[day] - x + E_DAY_VIEW_BAR_WIDTH; - grid_x2 = day_view->day_offsets[day + 1] - x - 1; - marcus_bains_y = (time_now.hour * 60 + time_now.minute) * day_view->row_height / day_view->mins_per_row - y; - cairo_set_line_width (cr, 1.5); - cairo_move_to (cr, grid_x1, marcus_bains_y); - cairo_line_to (cr, grid_x2, marcus_bains_y); - cairo_stroke (cr); - } - } - cairo_restore (cr); - } - cairo_destroy (cr); - gdk_region_destroy (draw_region); -} - static void -e_day_view_main_item_draw_events_in_vbars (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - gint x, gint y, - gint width, gint height, - gint day, GdkRegion *draw_region) -{ - EDayView *day_view; - EDayViewEvent *event; - gint grid_x, event_num, bar_y, bar_h; - cairo_t *cr = NULL; - GdkColor bg_color; - day_view = dvmitem->day_view; - - grid_x = day_view->day_offsets[day] + 1 - x; - - /* Draw the busy times corresponding to the events in the day. */ - for (event_num = 0; event_num < day_view->events[day]->len; event_num++) { - event = &g_array_index (day_view->events[day], EDayViewEvent, event_num); - - /* We can skip the events in the first column since they will - draw over this anyway. */ - if (event->num_columns > 0 && event->start_row_or_col == 0) { - continue; - } - - bar_y = event->start_minute * day_view->row_height / day_view->mins_per_row; - bar_h = event->end_minute * day_view->row_height / day_view->mins_per_row - bar_y; - bar_y -= y; - - /* Skip it if it isn't visible. */ - if (bar_y >= height || bar_y + bar_h <= 0 || !can_draw_in_region (draw_region, grid_x, bar_y, E_DAY_VIEW_BAR_WIDTH - 2, bar_h)) { - continue; - } - - /* If the event is TRANSPARENT, skip it. */ - if (icalcomp_is_transparent (event->comp_data->icalcomp)) { - continue; - } - - if (!cr) { - cr = gdk_cairo_create (drawable); - cairo_save (cr); - - gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND]); - } - - if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)), event->comp_data), &bg_color)) { - GdkColormap *colormap; - - colormap = gtk_widget_get_colormap (GTK_WIDGET (day_view)); - if (gdk_colormap_alloc_color (colormap, &bg_color, TRUE, TRUE)) { - gdk_cairo_set_source_color (cr, &bg_color); - } - } - - cairo_rectangle (cr, grid_x, bar_y, E_DAY_VIEW_BAR_WIDTH - 2, bar_h); - - cairo_fill (cr); - } - - if (cr) { - cairo_restore (cr); - cairo_destroy (cr); - } -} - -static void -e_day_view_main_item_draw_long_events_in_vbars (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - gint x, gint y, - gint width, gint height, GdkRegion *draw_region) +day_view_main_item_draw_long_events_in_vbars (EDayViewMainItem *main_item, + GdkDrawable *drawable, + gint x, + gint y, + gint width, + gint height, + GdkRegion *draw_region) { EDayView *day_view; EDayViewEvent *event; @@ -513,7 +100,7 @@ e_day_view_main_item_draw_long_events_in_vbars (EDayViewMainItem *dvmitem, cairo_t *cr = NULL; GdkColor bg_color; - day_view = dvmitem->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); for (event_num = 0; event_num < day_view->long_events->len; event_num++) { gboolean first = TRUE; @@ -584,29 +171,15 @@ e_day_view_main_item_draw_long_events_in_vbars (EDayViewMainItem *dvmitem, } static void -e_day_view_main_item_draw_day_events (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - gint x, gint y, gint width, gint height, - gint day, GdkRegion *draw_region) -{ - EDayView *day_view; - gint event_num; - - day_view = dvmitem->day_view; - - for (event_num = 0; event_num < day_view->events[day]->len; - event_num++) { - e_day_view_main_item_draw_day_event (dvmitem, drawable, - x, y, width, height, - day, event_num, draw_region); - } -} - -static void -e_day_view_main_item_draw_day_event (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - gint x, gint y, gint width, gint height, - gint day, gint event_num, GdkRegion *draw_region) +day_view_main_item_draw_day_event (EDayViewMainItem *main_item, + GdkDrawable *drawable, + gint x, + gint y, + gint width, + gint height, + gint day, + gint event_num, + GdkRegion *draw_region) { EDayView *day_view; EDayViewEvent *event; @@ -643,7 +216,7 @@ e_day_view_main_item_draw_day_event (EDayViewMainItem *dvmitem, gint scroll_flag = 0; gint row_y; - day_view = dvmitem->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); model = e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)); /* If the event is currently being dragged, don't draw it. It will @@ -1245,32 +818,513 @@ e_day_view_main_item_draw_day_event (EDayViewMainItem *dvmitem, cairo_destroy (cr); } -/* This is supposed to return the nearest item to the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ -static double -e_day_view_main_item_point (GnomeCanvasItem *item, double x, double y, - gint cx, gint cy, - GnomeCanvasItem **actual_item) +static void +day_view_main_item_draw_day_events (EDayViewMainItem *main_item, + GdkDrawable *drawable, + gint x, + gint y, + gint width, + gint height, + gint day, + GdkRegion *draw_region) { + EDayView *day_view; + gint event_num; + + day_view = e_day_view_main_item_get_day_view (main_item); + + for (event_num = 0; event_num < day_view->events[day]->len; + event_num++) { + day_view_main_item_draw_day_event ( + main_item, drawable, x, y, width, height, + day, event_num, draw_region); + } +} + +static void +day_view_main_item_draw_events_in_vbars (EDayViewMainItem *main_item, + GdkDrawable *drawable, + gint x, + gint y, + gint width, + gint height, + gint day, + GdkRegion *draw_region) +{ + EDayView *day_view; + EDayViewEvent *event; + gint grid_x, event_num, bar_y, bar_h; + cairo_t *cr = NULL; + GdkColor bg_color; + + day_view = e_day_view_main_item_get_day_view (main_item); + + grid_x = day_view->day_offsets[day] + 1 - x; + + /* Draw the busy times corresponding to the events in the day. */ + for (event_num = 0; event_num < day_view->events[day]->len; event_num++) { + event = &g_array_index (day_view->events[day], EDayViewEvent, event_num); + + /* We can skip the events in the first column since they will + draw over this anyway. */ + if (event->num_columns > 0 && event->start_row_or_col == 0) { + continue; + } + + bar_y = event->start_minute * day_view->row_height / day_view->mins_per_row; + bar_h = event->end_minute * day_view->row_height / day_view->mins_per_row - bar_y; + bar_y -= y; + + /* Skip it if it isn't visible. */ + if (bar_y >= height || bar_y + bar_h <= 0 || !can_draw_in_region (draw_region, grid_x, bar_y, E_DAY_VIEW_BAR_WIDTH - 2, bar_h)) { + continue; + } + + /* If the event is TRANSPARENT, skip it. */ + if (icalcomp_is_transparent (event->comp_data->icalcomp)) { + continue; + } + + if (!cr) { + cr = gdk_cairo_create (drawable); + cairo_save (cr); + + gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND]); + } + + if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)), event->comp_data), &bg_color)) { + GdkColormap *colormap; + + colormap = gtk_widget_get_colormap (GTK_WIDGET (day_view)); + if (gdk_colormap_alloc_color (colormap, &bg_color, TRUE, TRUE)) { + gdk_cairo_set_source_color (cr, &bg_color); + } + } + + cairo_rectangle (cr, grid_x, bar_y, E_DAY_VIEW_BAR_WIDTH - 2, bar_h); + + cairo_fill (cr); + } + + if (cr) { + cairo_restore (cr); + cairo_destroy (cr); + } +} + +static void +day_view_main_item_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_DAY_VIEW: + e_day_view_main_item_set_day_view ( + E_DAY_VIEW_MAIN_ITEM (object), + g_value_get_object (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +day_view_main_item_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_DAY_VIEW: + g_value_set_object ( + value, e_day_view_main_item_get_day_view ( + E_DAY_VIEW_MAIN_ITEM (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +day_view_main_item_dispose (GObject *object) +{ + EDayViewMainItemPrivate *priv; + + priv = E_DAY_VIEW_MAIN_ITEM_GET_PRIVATE (object); + + if (priv->day_view != NULL) { + g_object_unref (priv->day_view); + priv->day_view = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +day_view_main_item_update (GnomeCanvasItem *item, + gdouble *affine, + ArtSVP *clip_path, + gint flags) +{ + GnomeCanvasItemClass *canvas_item_class; + + /* Chain up to parent's update() method. */ + canvas_item_class = GNOME_CANVAS_ITEM_CLASS (parent_class); + canvas_item_class->update (item, affine, clip_path, flags); + + /* The item covers the entire canvas area. */ + item->x1 = 0; + item->y1 = 0; + item->x2 = INT_MAX; + item->y2 = INT_MAX; +} + +static void +day_view_main_item_draw (GnomeCanvasItem *canvas_item, + GdkDrawable *drawable, + gint x, + gint y, + gint width, + gint height) +{ + EDayViewMainItem *main_item; + EDayView *day_view; + GtkStyle *style; + GdkGC *gc; + gint row, row_y, grid_x1, grid_x2; + gint day, grid_y1, grid_y2; + gint work_day_start_y, work_day_end_y; + gint day_x, day_w, work_day; + gint start_row, end_row, rect_x, rect_y, rect_width, rect_height; + struct icaltimetype day_start_tt, today_tt; + gint weekday; + cairo_t *cr; + gboolean today = FALSE; + GdkRegion *draw_region; + GdkRectangle rect; + + cr = gdk_cairo_create (drawable); + + main_item = E_DAY_VIEW_MAIN_ITEM (canvas_item); + day_view = e_day_view_main_item_get_day_view (main_item); + g_return_if_fail (day_view != NULL); + + style = gtk_widget_get_style (GTK_WIDGET (day_view)); + rect.x = 0; + rect.y = 0; + rect.width = width; + rect.height = height; + draw_region = gdk_region_rectangle (&rect); + + /* Paint the background colors. */ + work_day_start_y = e_day_view_convert_time_to_position (day_view, day_view->work_day_start_hour, day_view->work_day_start_minute) - y; + gc = day_view->main_gc; + work_day_end_y = e_day_view_convert_time_to_position (day_view, day_view->work_day_end_hour, day_view->work_day_end_minute) - y; + + today_tt = icaltime_from_timet_with_zone (time (NULL), FALSE, + e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view))); + + for (day = 0; day < day_view->days_shown; day++) { + day_start_tt = icaltime_from_timet_with_zone (day_view->day_starts[day], FALSE, + e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view))); + weekday = icaltime_day_of_week (day_start_tt) - 1; + + work_day = day_view->working_days & (1 << weekday); + + day_x = day_view->day_offsets[day] - x; + day_w = day_view->day_widths[day]; + + if (work_day) { + if (can_draw_in_region (draw_region, day_x, 0 - y, day_w, work_day_start_y - (0 - y))) { + cairo_save (cr); + gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_NOT_WORKING]); + cairo_rectangle (cr, day_x, 0 - y, day_w, work_day_start_y - (0 - y)); + cairo_fill (cr); + cairo_restore (cr); + } + + if (day_view->days_shown > 1) { + /* Check if we are drawing today */ + today = day_start_tt.year == today_tt.year + && day_start_tt.month == today_tt.month + && day_start_tt.day == today_tt.day; + } else { + today = FALSE; + } + + if (can_draw_in_region (draw_region, day_x, work_day_start_y, day_w, work_day_end_y - work_day_start_y)) { + cairo_save (cr); + gdk_cairo_set_source_color (cr, &day_view->colors[today ? E_DAY_VIEW_COLOR_BG_MULTIDAY_TODAY : E_DAY_VIEW_COLOR_BG_WORKING]); + cairo_rectangle (cr, day_x, work_day_start_y, day_w, work_day_end_y - work_day_start_y); + cairo_fill (cr); + cairo_restore (cr); + } + + if (can_draw_in_region (draw_region, day_x, work_day_end_y, day_w, height - work_day_end_y)) { + cairo_save (cr); + gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_NOT_WORKING]); + cairo_rectangle (cr, day_x, work_day_end_y, day_w, height - work_day_end_y); + cairo_fill (cr); + cairo_restore (cr); + } + } else if (can_draw_in_region (draw_region, day_x, 0, day_w, height)) { + cairo_save (cr); + gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_NOT_WORKING]); + cairo_rectangle (cr, day_x, 0, day_w, height); + cairo_fill (cr); + cairo_restore (cr); + } + } + + /* Paint the selection background. */ + if (day_view->selection_start_day != -1 + && !day_view->selection_in_top_canvas) { + for (day = day_view->selection_start_day; + day <= day_view->selection_end_day; + day++) { + if (day == day_view->selection_start_day + && day_view->selection_start_row != -1) + start_row = day_view->selection_start_row; + else + start_row = 0; + if (day == day_view->selection_end_day + && day_view->selection_end_row != -1) + end_row = day_view->selection_end_row; + else + end_row = day_view->rows - 1; + + rect_x = day_view->day_offsets[day] - x; + rect_width = day_view->day_widths[day]; + rect_y = start_row * day_view->row_height - y; + rect_height = (end_row - start_row + 1) * day_view->row_height; + + if (can_draw_in_region (draw_region, rect_x, rect_y, rect_width, rect_height)) { + cairo_save (cr); + gdk_cairo_set_source_color (cr, &day_view->colors[GTK_WIDGET_HAS_FOCUS(day_view) ? E_DAY_VIEW_COLOR_BG_SELECTED : E_DAY_VIEW_COLOR_BG_SELECTED_UNFOCUSSED]); + cairo_rectangle (cr, rect_x, rect_y, rect_width, rect_height); + cairo_fill (cr); + cairo_restore (cr); + } + } + } + + /* Drawing the horizontal grid lines. */ + grid_x1 = day_view->day_offsets[0] - x; + grid_x2 = day_view->day_offsets[day_view->days_shown] - x; + + cairo_save(cr); + gdk_cairo_set_source_color (cr, + &day_view->colors[E_DAY_VIEW_COLOR_BG_GRID]); + + for (row = 0, row_y = 0 - y; + row < day_view->rows && row_y < height; + row++, row_y += day_view->row_height) { + if (row_y >= 0 && row_y < height) { + cairo_set_line_width (cr, 0.7); + cairo_move_to (cr, grid_x1, row_y); + cairo_line_to (cr, grid_x2, row_y); + cairo_stroke (cr); + } + } + cairo_restore (cr); + + /* Draw the vertical bars down the left of each column. */ + grid_y1 = 0; + grid_y2 = height; + for (day = 0; day < day_view->days_shown; day++) { + grid_x1 = day_view->day_offsets[day] - x; + + /* Skip if it isn't visible. */ + if (grid_x1 >= width || grid_x1 + E_DAY_VIEW_BAR_WIDTH <= 0) + continue; + cairo_save (cr); + + gdk_cairo_set_source_color (cr, + &day_view->colors[E_DAY_VIEW_COLOR_BG_GRID]); + cairo_move_to (cr, grid_x1, grid_y1); + cairo_line_to (cr, grid_x1, grid_y2); + cairo_stroke (cr); + + gdk_cairo_set_source_color (cr, + &day_view->colors[E_DAY_VIEW_COLOR_BG_GRID]); + + cairo_move_to (cr, grid_x1 + E_DAY_VIEW_BAR_WIDTH - 1, grid_y1); + cairo_line_to (cr, grid_x1 + E_DAY_VIEW_BAR_WIDTH - 1, grid_y2); + cairo_stroke (cr); + + cairo_set_source_rgb (cr, 1, 1, 1); + + cairo_rectangle (cr, grid_x1 + 1, grid_y1, + E_DAY_VIEW_BAR_WIDTH - 2, grid_y2 - grid_y1); + + cairo_fill (cr); + + cairo_restore (cr); + + /* Fill in the bars when the user is busy. */ + day_view_main_item_draw_events_in_vbars ( + main_item, drawable, x, y, + width, height, day, draw_region); + } + + /* Fill in the vertical bars corresponding to the busy times from the + long events. */ + day_view_main_item_draw_long_events_in_vbars ( + main_item, drawable, x, y, width, height, draw_region); + + /* Draw the event borders and backgrounds, and the vertical bars + down the left edges. */ + for (day = 0; day < day_view->days_shown; day++) + day_view_main_item_draw_day_events ( + main_item, drawable, x, y, + width, height, day, draw_region); + + if (e_day_view_marcus_bains_get_show_line (day_view)) { + icaltimezone *zone; + struct icaltimetype time_now, day_start; + gint marcus_bains_y; + GdkColor mb_color; + + cairo_save (cr); + gdk_cairo_set_source_color (cr, + &day_view->colors[E_DAY_VIEW_COLOR_MARCUS_BAINS_LINE]); + + if (day_view->marcus_bains_day_view_color && gdk_color_parse (day_view->marcus_bains_day_view_color, &mb_color)) { + GdkColormap *colormap; + + colormap = gtk_widget_get_colormap (GTK_WIDGET (day_view)); + if (gdk_colormap_alloc_color (colormap, &mb_color, TRUE, TRUE)) + gdk_cairo_set_source_color (cr, &mb_color); + } + zone = e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)); + time_now = icaltime_current_time_with_zone (zone); + + for (day = 0; day < day_view->days_shown; day++) { + day_start = icaltime_from_timet_with_zone (day_view->day_starts[day], FALSE, zone); + + if ((day_start.year == time_now.year) && + (day_start.month == time_now.month) && + (day_start.day == time_now.day)) { + + grid_x1 = day_view->day_offsets[day] - x + E_DAY_VIEW_BAR_WIDTH; + grid_x2 = day_view->day_offsets[day + 1] - x - 1; + marcus_bains_y = (time_now.hour * 60 + time_now.minute) * day_view->row_height / day_view->mins_per_row - y; + cairo_set_line_width (cr, 1.5); + cairo_move_to (cr, grid_x1, marcus_bains_y); + cairo_line_to (cr, grid_x2, marcus_bains_y); + cairo_stroke (cr); + } + } + cairo_restore (cr); + } + cairo_destroy (cr); + gdk_region_destroy (draw_region); +} + +static gdouble +day_view_main_item_point (GnomeCanvasItem *item, + gdouble x, + gdouble y, + gint cx, + gint cy, + GnomeCanvasItem **actual_item) +{ + /* This is supposed to return the nearest item to the point + * and the distance. Since we are the only item we just return + * ourself and 0 for the distance. This is needed so that we + * get button/motion events. */ *actual_item = item; + return 0.0; } -static gint -e_day_view_main_item_event (GnomeCanvasItem *item, GdkEvent *event) +static void +day_view_main_item_class_init (EDayViewMainItemClass *class) { - switch (event->type) { - case GDK_BUTTON_PRESS: + GObjectClass *object_class; + GnomeCanvasItemClass *item_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EDayViewMainItemPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = day_view_main_item_set_property; + object_class->get_property = day_view_main_item_get_property; + object_class->dispose = day_view_main_item_dispose; + + item_class = GNOME_CANVAS_ITEM_CLASS (class); + item_class->update = day_view_main_item_update; + item_class->draw = day_view_main_item_draw; + item_class->point = day_view_main_item_point; - case GDK_BUTTON_RELEASE: + g_object_class_install_property ( + object_class, + PROP_DAY_VIEW, + g_param_spec_object ( + "day-view", + "Day View", + NULL, + E_TYPE_DAY_VIEW, + G_PARAM_READWRITE)); - case GDK_MOTION_NOTIFY: + /* init the accessibility support for e_day_view */ + e_day_view_main_item_a11y_init (); +} + +static void +day_view_main_item_init (EDayViewMainItem *main_item) +{ + main_item->priv = E_DAY_VIEW_MAIN_ITEM_GET_PRIVATE (main_item); +} - default: - break; +GType +e_day_view_main_item_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + const GTypeInfo type_info = { + sizeof (EDayViewMainItemClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) day_view_main_item_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EDayViewMainItem), + 0, /* n_preallocs */ + (GInstanceInitFunc) day_view_main_item_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GNOME_TYPE_CANVAS_ITEM, "EDayViewMainItem", + &type_info, 0); } - return FALSE; + return type; +} + +EDayView * +e_day_view_main_item_get_day_view (EDayViewMainItem *main_item) +{ + g_return_val_if_fail (E_IS_DAY_VIEW_MAIN_ITEM (main_item), NULL); + + return main_item->priv->day_view; } +void +e_day_view_main_item_set_day_view (EDayViewMainItem *main_item, + EDayView *day_view) +{ + g_return_if_fail (E_IS_DAY_VIEW_MAIN_ITEM (main_item)); + g_return_if_fail (E_IS_DAY_VIEW (day_view)); + + if (main_item->priv->day_view != NULL) + g_object_unref (main_item->priv->day_view); + + main_item->priv->day_view = g_object_ref (day_view); + + g_object_notify (G_OBJECT (main_item), "day-view"); +} diff --git a/calendar/gui/e-day-view-main-item.h b/calendar/gui/e-day-view-main-item.h index 5204115e88..567565bfc0 100644 --- a/calendar/gui/e-day-view-main-item.h +++ b/calendar/gui/e-day-view-main-item.h @@ -20,39 +20,57 @@ * */ -#ifndef _E_DAY_VIEW_MAIN_ITEM_H_ -#define _E_DAY_VIEW_MAIN_ITEM_H_ - -#include "e-day-view.h" - -G_BEGIN_DECLS - /* * EDayViewMainItem - canvas item which displays most of the appointment * data in the main Day/Work Week display. */ -#define E_DAY_VIEW_MAIN_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - e_day_view_main_item_get_type (), EDayViewMainItem)) -#define E_DAY_VIEW_MAIN_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k),\ - e_day_view_main_item_get_type ())) -#define E_IS_DAY_VIEW_MAIN_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), \ - e_day_view_main_item_get_type ())) +#ifndef E_DAY_VIEW_MAIN_ITEM_H +#define E_DAY_VIEW_MAIN_ITEM_H -typedef struct { - GnomeCanvasItem canvas_item; +#include "e-day-view.h" - /* The parent EDayView widget. */ - EDayView *day_view; -} EDayViewMainItem; +/* Standard GObject macros */ +#define E_TYPE_DAY_VIEW_MAIN_ITEM \ + (e_day_view_main_item_get_type ()) +#define E_DAY_VIEW_MAIN_ITEM(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_DAY_VIEW_MAIN_ITEM, EDayViewMainItem)) +#define E_DAY_VIEW_MAIN_ITEM_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_DAY_VIEW_MAIN_ITEM, EDayViewMainItemClass)) +#define E_IS_DAY_VIEW_MAIN_ITEM(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_DAY_VIEW_MAIN_ITEM)) +#define E_IS_DAY_VIEW_MAIN_ITEM_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_DAY_VIEW_MAIN_ITEM)) +#define E_DAY_VIEW_MAIN_ITEM_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_TYPE \ + ((obj), E_TYPE_DAY_VIEW_MAIN_ITEM, EDayViewMainItemClass)) -typedef struct { - GnomeCanvasItemClass parent_class; +G_BEGIN_DECLS + +typedef struct _EDayViewMainItem EDayViewMainItem; +typedef struct _EDayViewMainItemClass EDayViewMainItemClass; +typedef struct _EDayViewMainItemPrivate EDayViewMainItemPrivate; -} EDayViewMainItemClass; +struct _EDayViewMainItem { + GnomeCanvasItem parent; + EDayViewMainItemPrivate *priv; +}; + +struct _EDayViewMainItemClass { + GnomeCanvasItemClass parent_class; +}; -GType e_day_view_main_item_get_type (void); +GType e_day_view_main_item_get_type (void); +EDayView * e_day_view_main_item_get_day_view + (EDayViewMainItem *main_item); +void e_day_view_main_item_set_day_view + (EDayViewMainItem *main_item, + EDayView *day_view); G_END_DECLS -#endif /* _E_DAY_VIEW_MAIN_ITEM_H_ */ +#endif /* E_DAY_VIEW_MAIN_ITEM_H */ diff --git a/calendar/gui/e-day-view-time-item.c b/calendar/gui/e-day-view-time-item.c index 8c4a2fdf07..5068ed47e0 100644 --- a/calendar/gui/e-day-view-time-item.c +++ b/calendar/gui/e-day-view-time-item.c @@ -55,12 +55,24 @@ #define E_DVTMI_LARGE_HOUR_Y_PAD 1 #define E_DVTMI_SMALL_FONT_Y_PAD 1 -static void e_day_view_time_item_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); +#define E_DAY_VIEW_TIME_ITEM_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_DAY_VIEW_TIME_ITEM, EDayViewTimeItemPrivate)) -static void e_day_view_time_item_finalize (GObject *object); +struct _EDayViewTimeItemPrivate { + /* The parent EDayView widget. */ + EDayView *day_view; + + /* The width of the time column. */ + gint column_width; + + /* TRUE if we are currently dragging the selection times. */ + gboolean dragging_selection; + + /* The second timezone if shown, or else NULL. */ + guint second_zone_changed_id; + icaltimezone *second_zone; +}; static void e_day_view_time_item_update (GnomeCanvasItem *item, double *affine, @@ -78,37 +90,107 @@ static gint e_day_view_time_item_event (GnomeCanvasItem *item, static void e_day_view_time_item_increment_time (gint *hour, gint *minute, gint mins_per_row); -static void e_day_view_time_item_show_popup_menu (EDayViewTimeItem *dvtmitem, +static void e_day_view_time_item_show_popup_menu (EDayViewTimeItem *time_item, GdkEvent *event); static void e_day_view_time_item_on_set_divisions (GtkWidget *item, - EDayViewTimeItem *dvtmitem); -static void e_day_view_time_item_on_button_press (EDayViewTimeItem *dvtmitem, + EDayViewTimeItem *time_item); +static void e_day_view_time_item_on_button_press (EDayViewTimeItem *time_item, GdkEvent *event); -static void e_day_view_time_item_on_button_release (EDayViewTimeItem *dvtmitem, +static void e_day_view_time_item_on_button_release (EDayViewTimeItem *time_item, GdkEvent *event); -static void e_day_view_time_item_on_motion_notify (EDayViewTimeItem *dvtmitem, +static void e_day_view_time_item_on_motion_notify (EDayViewTimeItem *time_item, GdkEvent *event); -static gint e_day_view_time_item_convert_position_to_row (EDayViewTimeItem *dvtmitem, +static gint e_day_view_time_item_convert_position_to_row (EDayViewTimeItem *time_item, gint y); static void edvti_second_zone_changed_cb (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data); -/* The arguments we take */ + enum { PROP_0, PROP_DAY_VIEW }; -G_DEFINE_TYPE (EDayViewTimeItem, e_day_view_time_item, GNOME_TYPE_CANVAS_ITEM) +static gpointer parent_class; + +static void +day_view_time_item_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_DAY_VIEW: + e_day_view_time_item_set_day_view ( + E_DAY_VIEW_TIME_ITEM (object), + g_value_get_object (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +day_view_time_item_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_DAY_VIEW: + g_value_set_object ( + value, e_day_view_time_item_get_day_view ( + E_DAY_VIEW_TIME_ITEM (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +day_view_time_item_dispose (GObject *object) +{ + EDayViewTimeItemPrivate *priv; + + priv = E_DAY_VIEW_TIME_ITEM_GET_PRIVATE (object); + + if (priv->day_view != NULL) { + g_object_unref (priv->day_view); + priv->day_view = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +day_view_time_item_finalize (GObject *object) +{ + EDayViewTimeItem *time_item; + + time_item = E_DAY_VIEW_TIME_ITEM (object); + + if (time_item->priv->second_zone_changed_id) + calendar_config_remove_notification (time_item->priv->second_zone_changed_id); + time_item->priv->second_zone_changed_id = 0; + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->finalize (object); +} static void -e_day_view_time_item_class_init (EDayViewTimeItemClass *class) +day_view_time_item_class_init (EDayViewTimeItemClass *class) { - GObjectClass *object_class; + GObjectClass *object_class; GnomeCanvasItemClass *item_class; + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EDayViewTimeItemPrivate)); + object_class = G_OBJECT_CLASS (class); - object_class->set_property = e_day_view_time_item_set_property; - object_class->finalize = e_day_view_time_item_finalize; + object_class->set_property = day_view_time_item_set_property; + object_class->get_property = day_view_time_item_get_property; + object_class->dispose = day_view_time_item_dispose; + object_class->finalize = day_view_time_item_finalize; item_class = GNOME_CANVAS_ITEM_CLASS (class); item_class->update = e_day_view_time_item_update; @@ -119,64 +201,60 @@ e_day_view_time_item_class_init (EDayViewTimeItemClass *class) g_object_class_install_property ( object_class, PROP_DAY_VIEW, - g_param_spec_pointer ( - "day_view", - NULL, + g_param_spec_object ( + "day-view", + "Day View", NULL, - G_PARAM_WRITABLE)); + E_TYPE_DAY_VIEW, + G_PARAM_READWRITE)); } static void -e_day_view_time_item_init (EDayViewTimeItem *dvtmitem) +day_view_time_item_init (EDayViewTimeItem *time_item) { gchar *last; - dvtmitem->dragging_selection = FALSE; - dvtmitem->second_zone = NULL; + time_item->priv = E_DAY_VIEW_TIME_ITEM_GET_PRIVATE (time_item); + + time_item->priv->dragging_selection = FALSE; + time_item->priv->second_zone = NULL; last = calendar_config_get_day_second_zone (); if (last) { if (*last) - dvtmitem->second_zone = icaltimezone_get_builtin_timezone (last); + time_item->priv->second_zone = icaltimezone_get_builtin_timezone (last); g_free (last); } - dvtmitem->second_zone_changed_id = calendar_config_add_notification_day_second_zone (edvti_second_zone_changed_cb, dvtmitem); + time_item->priv->second_zone_changed_id = calendar_config_add_notification_day_second_zone (edvti_second_zone_changed_cb, time_item); } -static void -e_day_view_time_item_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) +GType +e_day_view_time_item_get_type (void) { - EDayViewTimeItem *dvtmitem; - - dvtmitem = E_DAY_VIEW_TIME_ITEM (object); - - switch (property_id) { - case PROP_DAY_VIEW: - dvtmitem->day_view = g_value_get_pointer (value); - return; + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + const GTypeInfo type_info = { + sizeof (EDayViewTimeItemClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) day_view_time_item_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EDayViewTimeItem), + 0, /* n_preallocs */ + (GInstanceInitFunc) day_view_time_item_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GNOME_TYPE_CANVAS_ITEM, "EDayViewTimeItem", + &type_info, 0); } - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -e_day_view_time_item_finalize (GObject *object) -{ - EDayViewTimeItem *dvtmitem; - - dvtmitem = E_DAY_VIEW_TIME_ITEM (object); - - if (dvtmitem->second_zone_changed_id) - calendar_config_remove_notification (dvtmitem->second_zone_changed_id); - dvtmitem->second_zone_changed_id = 0; - - if (G_OBJECT_CLASS (e_day_view_time_item_parent_class)->finalize) - G_OBJECT_CLASS (e_day_view_time_item_parent_class)->finalize (object); + return type; } static void @@ -185,8 +263,8 @@ e_day_view_time_item_update (GnomeCanvasItem *item, ArtSVP *clip_path, gint flags) { - if (GNOME_CANVAS_ITEM_CLASS (e_day_view_time_item_parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (e_day_view_time_item_parent_class)->update) (item, affine, clip_path, flags); + if (GNOME_CANVAS_ITEM_CLASS (parent_class)->update) + (* GNOME_CANVAS_ITEM_CLASS (parent_class)->update) (item, affine, clip_path, flags); /* The item covers the entire canvas area. */ item->x1 = 0; @@ -195,75 +273,6 @@ e_day_view_time_item_update (GnomeCanvasItem *item, item->y2 = INT_MAX; } -/* Returns the minimum width needed for the column, by adding up all the - maximum widths of the strings. The string widths are all calculated in - the style_set handlers of EDayView and EDayViewTimeCanvas. */ -gint -e_day_view_time_item_get_column_width (EDayViewTimeItem *dvtmitem) -{ - EDayView *day_view; - GtkStyle *style; - gint digit, large_digit_width, max_large_digit_width = 0; - gint max_suffix_width, max_minute_or_suffix_width; - gint column_width_default, column_width_60_min_rows; - - day_view = dvtmitem->day_view; - g_return_val_if_fail (day_view != NULL, 0); - - style = gtk_widget_get_style (GTK_WIDGET (day_view)); - g_return_val_if_fail (style != NULL, 0); - - /* Find the maximum width a digit can have. FIXME: We could use pango's - * approximation function, but I worry it won't be precise enough. Also - * it needs a language tag that I don't know where to get. */ - for (digit = '0'; digit <= '9'; digit++) { - PangoLayout *layout; - gchar digit_str [2]; - - digit_str [0] = digit; - digit_str [1] = '\0'; - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), digit_str); - pango_layout_set_font_description (layout, day_view->large_font_desc); - pango_layout_get_pixel_size (layout, &large_digit_width, NULL); - - g_object_unref (layout); - - max_large_digit_width = MAX (max_large_digit_width, - large_digit_width); - } - - /* Calculate the width of each time column, using the maximum of the - default format with large hour numbers, and the 60-min divisions - format which uses small text. */ - max_suffix_width = MAX (day_view->am_string_width, - day_view->pm_string_width); - - max_minute_or_suffix_width = MAX (max_suffix_width, - day_view->max_minute_width); - - column_width_default = max_large_digit_width * 2 - + max_minute_or_suffix_width - + E_DVTMI_MIN_X_PAD * 2 - + E_DVTMI_HOUR_L_PAD - + E_DVTMI_HOUR_R_PAD - + E_DVTMI_TIME_GRID_X_PAD * 2; - - column_width_60_min_rows = day_view->max_small_hour_width - + day_view->colon_width - + max_minute_or_suffix_width - + E_DVTMI_60_MIN_X_PAD * 2 - + E_DVTMI_TIME_GRID_X_PAD * 2; - - dvtmitem->column_width = MAX (column_width_default, - column_width_60_min_rows); - - if (dvtmitem->second_zone) - return (2 * dvtmitem->column_width) - E_DVTMI_TIME_GRID_X_PAD; - - return dvtmitem->column_width; -} - /* * DRAWING ROUTINES - functions to paint the canvas item. */ @@ -278,7 +287,7 @@ edvti_draw_zone (GnomeCanvasItem *canvas_item, icaltimezone *use_zone) { EDayView *day_view; - EDayViewTimeItem *dvtmitem; + EDayViewTimeItem *time_item; ECalModel *model; GtkStyle *style; const gchar *suffix; @@ -299,8 +308,8 @@ edvti_draw_zone (GnomeCanvasItem *canvas_item, cr = gdk_cairo_create (drawable); - dvtmitem = E_DAY_VIEW_TIME_ITEM (canvas_item); - day_view = dvtmitem->day_view; + time_item = E_DAY_VIEW_TIME_ITEM (canvas_item); + day_view = e_day_view_time_item_get_day_view (time_item); g_return_if_fail (day_view != NULL); model = e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)); @@ -319,7 +328,7 @@ edvti_draw_zone (GnomeCanvasItem *canvas_item, /* The start and end of the long horizontal line between hours. */ long_line_x1 = (use_zone ? 0 : E_DVTMI_TIME_GRID_X_PAD) - x + x_offset; - long_line_x2 = dvtmitem->column_width - E_DVTMI_TIME_GRID_X_PAD - x - (use_zone ? E_DVTMI_TIME_GRID_X_PAD : 0) + x_offset; + long_line_x2 = time_item->priv->column_width - E_DVTMI_TIME_GRID_X_PAD - x - (use_zone ? E_DVTMI_TIME_GRID_X_PAD : 0) + x_offset; if (day_view->mins_per_row == 60) { /* The right edge of the complete time string in 60-min @@ -613,15 +622,15 @@ e_day_view_time_item_draw (GnomeCanvasItem *canvas_item, gint width, gint height) { - EDayViewTimeItem *dvtmitem; + EDayViewTimeItem *time_item; - dvtmitem = E_DAY_VIEW_TIME_ITEM (canvas_item); - g_return_if_fail (dvtmitem != NULL); + time_item = E_DAY_VIEW_TIME_ITEM (canvas_item); + g_return_if_fail (time_item != NULL); edvti_draw_zone (canvas_item, drawable, x, y, width, height, 0, NULL); - if (dvtmitem->second_zone) - edvti_draw_zone (canvas_item, drawable, x, y, width, height, dvtmitem->column_width, dvtmitem->second_zone); + if (time_item->priv->second_zone) + edvti_draw_zone (canvas_item, drawable, x, y, width, height, time_item->priv->column_width, time_item->priv->second_zone); } /* Increment the time by the 5/10/15/30/60 minute interval. @@ -654,27 +663,27 @@ static gint e_day_view_time_item_event (GnomeCanvasItem *item, GdkEvent *event) { - EDayViewTimeItem *dvtmitem; + EDayViewTimeItem *time_item; - dvtmitem = E_DAY_VIEW_TIME_ITEM (item); + time_item = E_DAY_VIEW_TIME_ITEM (item); switch (event->type) { case GDK_BUTTON_PRESS: if (event->button.button == 1) { - e_day_view_time_item_on_button_press (dvtmitem, event); + e_day_view_time_item_on_button_press (time_item, event); } else if (event->button.button == 3) { - e_day_view_time_item_show_popup_menu (dvtmitem, event); + e_day_view_time_item_show_popup_menu (time_item, event); return TRUE; } break; case GDK_BUTTON_RELEASE: if (event->button.button == 1) - e_day_view_time_item_on_button_release (dvtmitem, + e_day_view_time_item_on_button_release (time_item, event); break; case GDK_MOTION_NOTIFY: - e_day_view_time_item_on_motion_notify (dvtmitem, event); + e_day_view_time_item_on_motion_notify (time_item, event); break; default: @@ -687,28 +696,30 @@ e_day_view_time_item_event (GnomeCanvasItem *item, static void edvti_second_zone_changed_cb (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data) { - EDayViewTimeItem *dvtmitem = user_data; + EDayViewTimeItem *time_item = user_data; + EDayView *day_view; gchar *location; g_return_if_fail (user_data != NULL); - g_return_if_fail (E_IS_DAY_VIEW_TIME_ITEM (dvtmitem)); + g_return_if_fail (E_IS_DAY_VIEW_TIME_ITEM (time_item)); location = calendar_config_get_day_second_zone (); - dvtmitem->second_zone = location ? icaltimezone_get_builtin_timezone (location) : NULL; + time_item->priv->second_zone = location ? icaltimezone_get_builtin_timezone (location) : NULL; g_free (location); - gtk_widget_set_size_request (dvtmitem->day_view->time_canvas, e_day_view_time_item_get_column_width (dvtmitem), -1); - gtk_widget_queue_draw (dvtmitem->day_view->time_canvas); + day_view = e_day_view_time_item_get_day_view (time_item); + gtk_widget_set_size_request (day_view->time_canvas, e_day_view_time_item_get_column_width (time_item), -1); + gtk_widget_queue_draw (day_view->time_canvas); } static void -edvti_on_select_zone (GtkWidget *item, EDayViewTimeItem *dvtmitem) +edvti_on_select_zone (GtkWidget *item, EDayViewTimeItem *time_item) { calendar_config_select_day_second_zone (); } static void -edvti_on_set_zone (GtkWidget *item, EDayViewTimeItem *dvtmitem) +edvti_on_set_zone (GtkWidget *item, EDayViewTimeItem *time_item) { if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item))) return; @@ -717,7 +728,7 @@ edvti_on_set_zone (GtkWidget *item, EDayViewTimeItem *dvtmitem) } static void -e_day_view_time_item_show_popup_menu (EDayViewTimeItem *dvtmitem, +e_day_view_time_item_show_popup_menu (EDayViewTimeItem *time_item, GdkEvent *event) { static gint divisions[] = { 60, 30, 15, 10, 5 }; @@ -729,7 +740,7 @@ e_day_view_time_item_show_popup_menu (EDayViewTimeItem *dvtmitem, gint current_divisions, i; icaltimezone *zone; - day_view = dvtmitem->day_view; + day_view = e_day_view_time_item_get_day_view (time_item); g_return_if_fail (day_view != NULL); current_divisions = e_day_view_get_mins_per_row (day_view); @@ -760,7 +771,7 @@ e_day_view_time_item_show_popup_menu (EDayViewTimeItem *dvtmitem, GINT_TO_POINTER (divisions[i])); g_signal_connect (item, "toggled", - G_CALLBACK (e_day_view_time_item_on_set_divisions), dvtmitem); + G_CALLBACK (e_day_view_time_item_on_set_divisions), time_item); } item = gtk_separator_menu_item_new (); @@ -787,10 +798,10 @@ e_day_view_time_item_show_popup_menu (EDayViewTimeItem *dvtmitem, group = NULL; item = gtk_radio_menu_item_new_with_label (group, _("None")); group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item)); - if (!dvtmitem->second_zone) + if (!time_item->priv->second_zone) gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE); gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item); - g_signal_connect (item, "toggled", G_CALLBACK (edvti_on_set_zone), dvtmitem); + g_signal_connect (item, "toggled", G_CALLBACK (edvti_on_set_zone), time_item); recent_zones = calendar_config_get_day_second_zones (); for (s = recent_zones; s != NULL; s = s->next) { @@ -801,11 +812,11 @@ e_day_view_time_item_show_popup_menu (EDayViewTimeItem *dvtmitem, item = gtk_radio_menu_item_new_with_label (group, icaltimezone_get_display_name (zone)); group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item)); /* both comes from builtin, thus no problem to compare pointers */ - if (zone == dvtmitem->second_zone) + if (zone == time_item->priv->second_zone) gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE); gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item); g_object_set_data_full (G_OBJECT (item), "timezone", g_strdup (s->data), g_free); - g_signal_connect (item, "toggled", G_CALLBACK (edvti_on_set_zone), dvtmitem); + g_signal_connect (item, "toggled", G_CALLBACK (edvti_on_set_zone), time_item); } calendar_config_free_day_second_zones (recent_zones); @@ -813,7 +824,7 @@ e_day_view_time_item_show_popup_menu (EDayViewTimeItem *dvtmitem, gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item); item = gtk_menu_item_new_with_label (_("Select...")); - g_signal_connect (item, "activate", G_CALLBACK (edvti_on_select_zone), dvtmitem); + g_signal_connect (item, "activate", G_CALLBACK (edvti_on_select_zone), time_item); gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item); gtk_widget_show_all (submenu); @@ -824,12 +835,12 @@ e_day_view_time_item_show_popup_menu (EDayViewTimeItem *dvtmitem, static void e_day_view_time_item_on_set_divisions (GtkWidget *item, - EDayViewTimeItem *dvtmitem) + EDayViewTimeItem *time_item) { EDayView *day_view; gint divisions; - day_view = dvtmitem->day_view; + day_view = e_day_view_time_item_get_day_view (time_item); g_return_if_fail (day_view != NULL); if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item))) @@ -841,19 +852,19 @@ e_day_view_time_item_on_set_divisions (GtkWidget *item, } static void -e_day_view_time_item_on_button_press (EDayViewTimeItem *dvtmitem, +e_day_view_time_item_on_button_press (EDayViewTimeItem *time_item, GdkEvent *event) { EDayView *day_view; GnomeCanvas *canvas; gint row; - day_view = dvtmitem->day_view; + day_view = e_day_view_time_item_get_day_view (time_item); g_return_if_fail (day_view != NULL); - canvas = GNOME_CANVAS_ITEM (dvtmitem)->canvas; + canvas = GNOME_CANVAS_ITEM (time_item)->canvas; - row = e_day_view_time_item_convert_position_to_row (dvtmitem, + row = e_day_view_time_item_convert_position_to_row (time_item, event->button.y); if (row == -1) @@ -867,30 +878,30 @@ e_day_view_time_item_on_button_press (EDayViewTimeItem *dvtmitem, | GDK_BUTTON_RELEASE_MASK, NULL, NULL, event->button.time) == 0) { e_day_view_start_selection (day_view, -1, row); - dvtmitem->dragging_selection = TRUE; + time_item->priv->dragging_selection = TRUE; } } static void -e_day_view_time_item_on_button_release (EDayViewTimeItem *dvtmitem, +e_day_view_time_item_on_button_release (EDayViewTimeItem *time_item, GdkEvent *event) { EDayView *day_view; - day_view = dvtmitem->day_view; + day_view = e_day_view_time_item_get_day_view (time_item); g_return_if_fail (day_view != NULL); - if (dvtmitem->dragging_selection) { + if (time_item->priv->dragging_selection) { gdk_pointer_ungrab (event->button.time); e_day_view_finish_selection (day_view); e_day_view_stop_auto_scroll (day_view); } - dvtmitem->dragging_selection = FALSE; + time_item->priv->dragging_selection = FALSE; } static void -e_day_view_time_item_on_motion_notify (EDayViewTimeItem *dvtmitem, +e_day_view_time_item_on_motion_notify (EDayViewTimeItem *time_item, GdkEvent *event) { EDayView *day_view; @@ -898,16 +909,16 @@ e_day_view_time_item_on_motion_notify (EDayViewTimeItem *dvtmitem, gdouble window_y; gint y, row; - if (!dvtmitem->dragging_selection) + if (!time_item->priv->dragging_selection) return; - day_view = dvtmitem->day_view; + day_view = e_day_view_time_item_get_day_view (time_item); g_return_if_fail (day_view != NULL); - canvas = GNOME_CANVAS_ITEM (dvtmitem)->canvas; + canvas = GNOME_CANVAS_ITEM (time_item)->canvas; y = event->motion.y; - row = e_day_view_time_item_convert_position_to_row (dvtmitem, y); + row = e_day_view_time_item_convert_position_to_row (time_item, y); if (row != -1) { gnome_canvas_world_to_window (canvas, 0, event->motion.y, @@ -919,13 +930,13 @@ e_day_view_time_item_on_motion_notify (EDayViewTimeItem *dvtmitem, /* Returns the row corresponding to the y position, or -1. */ static gint -e_day_view_time_item_convert_position_to_row (EDayViewTimeItem *dvtmitem, +e_day_view_time_item_convert_position_to_row (EDayViewTimeItem *time_item, gint y) { EDayView *day_view; gint row; - day_view = dvtmitem->day_view; + day_view = e_day_view_time_item_get_day_view (time_item); g_return_val_if_fail (day_view != NULL, -1); if (y < 0) @@ -937,3 +948,104 @@ e_day_view_time_item_convert_position_to_row (EDayViewTimeItem *dvtmitem, return row; } + +EDayView * +e_day_view_time_item_get_day_view (EDayViewTimeItem *time_item) +{ + g_return_val_if_fail (E_IS_DAY_VIEW_TIME_ITEM (time_item), NULL); + + return time_item->priv->day_view; +} + +void +e_day_view_time_item_set_day_view (EDayViewTimeItem *time_item, + EDayView *day_view) +{ + g_return_if_fail (E_IS_DAY_VIEW_TIME_ITEM (time_item)); + g_return_if_fail (E_IS_DAY_VIEW (day_view)); + + if (time_item->priv->day_view != NULL) + g_object_unref (time_item->priv->day_view); + + time_item->priv->day_view = g_object_ref (day_view); + + g_object_notify (G_OBJECT (time_item), "day-view"); +} + +/* Returns the minimum width needed for the column, by adding up all the + maximum widths of the strings. The string widths are all calculated in + the style_set handlers of EDayView and EDayViewTimeCanvas. */ +gint +e_day_view_time_item_get_column_width (EDayViewTimeItem *time_item) +{ + EDayView *day_view; + GtkStyle *style; + gint digit, large_digit_width, max_large_digit_width = 0; + gint max_suffix_width, max_minute_or_suffix_width; + gint column_width_default, column_width_60_min_rows; + + day_view = e_day_view_time_item_get_day_view (time_item); + g_return_val_if_fail (day_view != NULL, 0); + + style = gtk_widget_get_style (GTK_WIDGET (day_view)); + g_return_val_if_fail (style != NULL, 0); + + /* Find the maximum width a digit can have. FIXME: We could use pango's + * approximation function, but I worry it won't be precise enough. Also + * it needs a language tag that I don't know where to get. */ + for (digit = '0'; digit <= '9'; digit++) { + PangoLayout *layout; + gchar digit_str [2]; + + digit_str [0] = digit; + digit_str [1] = '\0'; + + layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), digit_str); + pango_layout_set_font_description (layout, day_view->large_font_desc); + pango_layout_get_pixel_size (layout, &large_digit_width, NULL); + + g_object_unref (layout); + + max_large_digit_width = MAX (max_large_digit_width, + large_digit_width); + } + + /* Calculate the width of each time column, using the maximum of the + default format with large hour numbers, and the 60-min divisions + format which uses small text. */ + max_suffix_width = MAX (day_view->am_string_width, + day_view->pm_string_width); + + max_minute_or_suffix_width = MAX (max_suffix_width, + day_view->max_minute_width); + + column_width_default = max_large_digit_width * 2 + + max_minute_or_suffix_width + + E_DVTMI_MIN_X_PAD * 2 + + E_DVTMI_HOUR_L_PAD + + E_DVTMI_HOUR_R_PAD + + E_DVTMI_TIME_GRID_X_PAD * 2; + + column_width_60_min_rows = day_view->max_small_hour_width + + day_view->colon_width + + max_minute_or_suffix_width + + E_DVTMI_60_MIN_X_PAD * 2 + + E_DVTMI_TIME_GRID_X_PAD * 2; + + time_item->priv->column_width = + MAX (column_width_default, column_width_60_min_rows); + + if (time_item->priv->second_zone) + return (2 * time_item->priv->column_width) - + E_DVTMI_TIME_GRID_X_PAD; + + return time_item->priv->column_width; +} + +icaltimezone * +e_day_view_time_item_get_second_zone (EDayViewTimeItem *time_item) +{ + g_return_val_if_fail (E_IS_DAY_VIEW_TIME_ITEM (time_item), NULL); + + return time_item->priv->second_zone; +} diff --git a/calendar/gui/e-day-view-time-item.h b/calendar/gui/e-day-view-time-item.h index 802ca50c3b..354a3701b5 100644 --- a/calendar/gui/e-day-view-time-item.h +++ b/calendar/gui/e-day-view-time-item.h @@ -21,51 +21,61 @@ * */ -#ifndef _E_DAY_VIEW_TIME_ITEM_H_ -#define _E_DAY_VIEW_TIME_ITEM_H_ - -#include "e-day-view.h" - -G_BEGIN_DECLS - /* * EDayViewTimeItem - canvas item which displays the times down the left of * the EDayView. */ -#define E_DAY_VIEW_TIME_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - e_day_view_time_item_get_type (), EDayViewTimeItem)) -#define E_DAY_VIEW_TIME_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k),\ - e_day_view_time_item_get_type ())) -#define E_IS_DAY_VIEW_TIME_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), \ - e_day_view_time_item_get_type ())) +#ifndef E_DAY_VIEW_TIME_ITEM_H +#define E_DAY_VIEW_TIME_ITEM_H -typedef struct { - GnomeCanvasItem canvas_item; +#include "e-day-view.h" - /* The parent EDayView widget. */ - EDayView *day_view; +/* Standard GObject macros */ +#define E_TYPE_DAY_VIEW_TIME_ITEM \ + (e_day_view_time_item_get_type ()) +#define E_DAY_VIEW_TIME_ITEM(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_DAY_VIEW_TIME_ITEM, EDayViewTimeItem)) +#define E_DAY_VIEW_TIME_ITEM_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_DAY_VIEW_TIME_ITEM, EDayViewTimeItemClass)) +#define E_IS_DAY_VIEW_TIME_ITEM(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_DAY_VIEW_TIME_ITEM)) +#define E_IS_DAY_VIEW_TIME_ITEM_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_DAY_VIEW_TIME_ITEM)) +#define E_DAY_VIEW_TIME_ITEM_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_DAY_VIEW_TIME_ITEM, EDayViewTimeItemClass)) - /* The width of the time column. */ - gint column_width; +G_BEGIN_DECLS - /* TRUE if we are currently dragging the selection times. */ - gboolean dragging_selection; +typedef struct _EDayViewTimeItem EDayViewTimeItem; +typedef struct _EDayViewTimeItemClass EDayViewTimeItemClass; +typedef struct _EDayViewTimeItemPrivate EDayViewTimeItemPrivate; - /* the second timezone shown here; NULL if none; do not free it, it's from the builtin zones */ - guint second_zone_changed_id; - icaltimezone *second_zone; -} EDayViewTimeItem; +struct _EDayViewTimeItem { + GnomeCanvasItem parent; + EDayViewTimeItemPrivate *priv; +}; -typedef struct { +struct _EDayViewTimeItemClass { GnomeCanvasItemClass parent_class; - -} EDayViewTimeItemClass; - -GType e_day_view_time_item_get_type (void); - -gint e_day_view_time_item_get_column_width (EDayViewTimeItem *dvtmitem); +}; + +GType e_day_view_time_item_get_type (void); +EDayView * e_day_view_time_item_get_day_view + (EDayViewTimeItem *time_item); +void e_day_view_time_item_set_day_view + (EDayViewTimeItem *time_item, + EDayView *day_view); +gint e_day_view_time_item_get_column_width + (EDayViewTimeItem *time_item); +icaltimezone * e_day_view_time_item_get_second_zone + (EDayViewTimeItem *time_item); G_END_DECLS -#endif /* _E_DAY_VIEW_TIME_ITEM_H_ */ +#endif /* E_DAY_VIEW_TIME_ITEM_H */ diff --git a/calendar/gui/e-day-view-top-item.c b/calendar/gui/e-day-view-top-item.c index a1f083e1b8..211faa5ec8 100644 --- a/calendar/gui/e-day-view-top-item.c +++ b/calendar/gui/e-day-view-top-item.c @@ -38,329 +38,111 @@ #include "e-calendar-view.h" #include "e-day-view-top-item.h" -static void e_day_view_top_item_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void e_day_view_top_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - gint flags); -static void e_day_view_top_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height); -static void e_day_view_top_item_draw_long_event (EDayViewTopItem *dvtitem, - gint event_num, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height); -static void e_day_view_top_item_draw_triangle (EDayViewTopItem *dvtitem, - GdkDrawable *drawable, - gint x, - gint y, - gint w, - gint h, - gint event_num); -static double e_day_view_top_item_point (GnomeCanvasItem *item, - double x, - double y, - gint cx, - gint cy, - GnomeCanvasItem **actual_item); -static gint e_day_view_top_item_event (GnomeCanvasItem *item, - GdkEvent *event); - -/* The arguments we take */ +#define E_DAY_VIEW_TOP_ITEM_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_DAY_VIEW_TOP_ITEM, EDayViewTopItemPrivate)) + +struct _EDayViewTopItemPrivate { + /* The parent EDayView widget. */ + EDayView *day_view; + + /* Show dates or events. */ + gboolean show_dates; +}; + enum { PROP_0, PROP_DAY_VIEW, PROP_SHOW_DATES }; -G_DEFINE_TYPE (EDayViewTopItem, e_day_view_top_item, GNOME_TYPE_CANVAS_ITEM) - -static void -e_day_view_top_item_class_init (EDayViewTopItemClass *class) -{ - GObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = G_OBJECT_CLASS (class); - object_class->set_property = e_day_view_top_item_set_property; - - item_class = GNOME_CANVAS_ITEM_CLASS (class); - item_class->update = e_day_view_top_item_update; - item_class->draw = e_day_view_top_item_draw; - item_class->point = e_day_view_top_item_point; - item_class->event = e_day_view_top_item_event; - - g_object_class_install_property ( - object_class, - PROP_DAY_VIEW, - g_param_spec_pointer ( - "day_view", - NULL, - NULL, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_SHOW_DATES, - g_param_spec_boolean ( - "show_dates", - NULL, - NULL, - TRUE, - G_PARAM_WRITABLE)); -} +static gpointer parent_class; +/* This draws a little triangle to indicate that an event extends past + the days visible on screen. */ static void -e_day_view_top_item_init (EDayViewTopItem *dvtitem) -{ - dvtitem->day_view = NULL; - dvtitem->show_dates = FALSE; -} - -static void -e_day_view_top_item_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - EDayViewTopItem *dvtitem; - - dvtitem = E_DAY_VIEW_TOP_ITEM (object); - - switch (property_id) { - case PROP_DAY_VIEW: - dvtitem->day_view = g_value_get_pointer (value); - return; - case PROP_SHOW_DATES: - dvtitem->show_dates = g_value_get_boolean (value); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -e_day_view_top_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - gint flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (e_day_view_top_item_parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (e_day_view_top_item_parent_class)->update) (item, affine, clip_path, flags); - - /* The item covers the entire canvas area. */ - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; -} - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ -static void -e_day_view_top_item_draw (GnomeCanvasItem *canvas_item, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height) +day_view_top_item_draw_triangle (EDayViewTopItem *top_item, + GdkDrawable *drawable, + gint x, + gint y, + gint w, + gint h, + gint event_num) { - EDayViewTopItem *dvtitem; EDayView *day_view; - GtkStyle *style; - GdkGC *gc, *fg_gc, *bg_gc, *light_gc, *dark_gc; - gchar buffer[128]; - GdkRectangle clip_rect; - gint canvas_width, canvas_height, left_edge, day, date_width, date_x; - gint item_height, event_num; - PangoLayout *layout; + EDayViewEvent *event; + GdkGC *gc; + GdkColor bg_color; + GdkPoint points[3]; + gint c1, c2; cairo_t *cr; - GdkColor fg, bg, light, dark; - gboolean show_dates; - -#if 0 - g_print ("In e_day_view_top_item_draw %i,%i %ix%i\n", - x, y, width, height); -#endif - dvtitem = E_DAY_VIEW_TOP_ITEM (canvas_item); - day_view = dvtitem->day_view; - g_return_if_fail (day_view != NULL); - show_dates = dvtitem->show_dates; cr = gdk_cairo_create (drawable); - style = gtk_widget_get_style (GTK_WIDGET (day_view)); - gc = day_view->main_gc; - fg_gc = style->fg_gc[GTK_STATE_NORMAL]; - bg_gc = style->bg_gc[GTK_STATE_NORMAL]; - light_gc = style->light_gc[GTK_STATE_NORMAL]; - dark_gc = style->dark_gc[GTK_STATE_NORMAL]; - canvas_width = GTK_WIDGET (canvas_item->canvas)->allocation.width; - canvas_height = (show_dates ? 1 : (MAX (1, day_view->rows_in_top_display) + 1)) * day_view->top_row_height; - left_edge = 0; - item_height = day_view->top_row_height - E_DAY_VIEW_TOP_CANVAS_Y_GAP; - - fg = style->fg[GTK_STATE_NORMAL]; - bg = style->bg[GTK_STATE_NORMAL]; - light = style->light[GTK_STATE_NORMAL]; - dark = style->dark[GTK_STATE_NORMAL]; + day_view = e_day_view_top_item_get_day_view (top_item); - if (show_dates) { - /* Draw the shadow around the dates. */ - cairo_save (cr); - gdk_cairo_set_source_color (cr, &light); - cairo_move_to (cr, left_edge - x, 1 - y); - cairo_line_to (cr, canvas_width - 2 - x, 1 - y); - cairo_move_to (cr, left_edge - x, 2 - y); - cairo_line_to (cr, left_edge - x, item_height - 2 - y); - cairo_stroke (cr); - cairo_restore (cr); - - cairo_save (cr); - gdk_cairo_set_source_color (cr, &dark); - cairo_move_to (cr, left_edge - x, item_height - 1 - y); - cairo_line_to (cr, canvas_width - 1 - x, item_height - 1 - y); - cairo_move_to (cr, canvas_width - 1 - x, 1 - y); - cairo_line_to (cr, canvas_width - 1 - x, item_height - 1 - y); - cairo_stroke (cr); - cairo_restore (cr); - - /* Draw the background for the dates. */ - cairo_save (cr); - gdk_cairo_set_source_color (cr, &bg); - cairo_rectangle (cr, left_edge + 2 - x, 2 - y, - canvas_width - left_edge - 3, - item_height - 3); - cairo_fill (cr); - cairo_restore (cr); - } - - if (!show_dates) { - /* Clear the main area background. */ - cairo_save (cr); - gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS]); - cairo_rectangle (cr, left_edge - x, - y, - canvas_width - left_edge, - canvas_height); - cairo_fill (cr); - cairo_restore (cr); + gc = day_view->main_gc; - /* Draw the selection background. */ - if (GTK_WIDGET_HAS_FOCUS (day_view) - && day_view->selection_start_day != -1) { - gint start_col, end_col, rect_x, rect_y, rect_w, rect_h; + points[0].x = x; + points[0].y = y; + points[1].x = x + w; + points[1].y = y + (h / 2); + points[2].x = x; + points[2].y = y + h - 1; - start_col = day_view->selection_start_day; - end_col = day_view->selection_end_day; + /* If the height is odd we can use the same central point for both + lines. If it is even we use different end-points. */ + c1 = c2 = y + (h / 2); + if (h % 2 == 0) + c1--; - if (end_col > start_col - || day_view->selection_start_row == -1 - || day_view->selection_end_row == -1) { - rect_x = day_view->day_offsets[start_col]; - rect_y = 0; - rect_w = day_view->day_offsets[end_col + 1] - rect_x; - rect_h = canvas_height - 1 - rect_y; + event = &g_array_index (day_view->long_events, EDayViewEvent, + event_num); + cairo_save (cr); + /* Fill it in. */ + if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)), + event->comp_data), + &bg_color)) { + GdkColormap *colormap; - cairo_save (cr); - gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_SELECTED]); - cairo_rectangle (cr, rect_x - x, rect_y - y, - rect_w, rect_h); - cairo_fill (cr); - cairo_restore (cr); - } + colormap = gtk_widget_get_colormap (GTK_WIDGET (day_view)); + if (gdk_colormap_alloc_color (colormap, &bg_color, TRUE, TRUE)) { + gdk_cairo_set_source_color (cr, &bg_color); + } else { + gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND]); } + } else { + gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND]); } - if (show_dates) { - /* Draw the date. Set a clipping rectangle so we don't draw over the - next day. */ - for (day = 0; day < day_view->days_shown; day++) { - e_day_view_top_item_get_day_label (day_view, day, buffer, sizeof (buffer)); - clip_rect.x = day_view->day_offsets[day] - x; - clip_rect.y = 2 - y; - if (day_view->days_shown == 1) - clip_rect.width = day_view->top_canvas->allocation.width - day_view->day_offsets[day]; - else - clip_rect.width = day_view->day_widths[day]; - clip_rect.height = item_height - 2; - - gdk_gc_set_clip_rectangle (fg_gc, &clip_rect); - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer); - pango_layout_get_pixel_size (layout, &date_width, NULL); - date_x = day_view->day_offsets[day] + (clip_rect.width - date_width) / 2; - - gdk_draw_layout (drawable, fg_gc, - date_x - x, - 3 - y, - layout); - g_object_unref (layout); - - gdk_gc_set_clip_rectangle (fg_gc, NULL); - - /* Draw the lines down the left and right of the date cols. */ - if (day != 0) { - cairo_save (cr); - gdk_cairo_set_source_color (cr, &light); - cairo_move_to (cr, day_view->day_offsets[day] - x, - 4 - y); - cairo_line_to (cr, day_view->day_offsets[day] - x, - item_height - 4 - y); - cairo_stroke (cr); - gdk_cairo_set_source_color (cr, &dark); - cairo_move_to (cr, day_view->day_offsets[day] - 1 - x, - 4 - y); - cairo_line_to (cr, day_view->day_offsets[day] - 1 - x, - item_height - 4 - y); - cairo_stroke (cr); - cairo_restore (cr); - } - - /* Draw the lines between each column. */ - if (day != 0) { - cairo_save (cr); - gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_GRID]); - cairo_move_to (cr, day_view->day_offsets[day] - x, - item_height - y); - cairo_line_to (cr, day_view->day_offsets[day] - x, - canvas_height - y); - cairo_stroke (cr); - cairo_restore (cr); - } - } - } + cairo_move_to (cr, points[0].x, points[0].y); + cairo_line_to (cr, points[1].x, points[1].y); + cairo_line_to (cr, points[2].x, points[2].y); + cairo_line_to (cr, points[0].x, points[0].y); + cairo_fill (cr); + cairo_restore (cr); - if (!show_dates) { - /* Draw the long events. */ - for (event_num = 0; event_num < day_view->long_events->len; event_num++) { - e_day_view_top_item_draw_long_event (dvtitem, event_num, - drawable, - x, y, width, height); - } - } + cairo_save (cr); + gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BORDER]); + cairo_move_to (cr, x, y); + cairo_line_to (cr, x + w, c1); + cairo_move_to (cr, x, y + h - 1); + cairo_line_to (cr, x + w, c2); + cairo_stroke (cr); + cairo_restore (cr); cairo_destroy (cr); } /* This draws one event in the top canvas. */ static void -e_day_view_top_item_draw_long_event (EDayViewTopItem *dvtitem, - gint event_num, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height) +day_view_top_item_draw_long_event (EDayViewTopItem *top_item, + gint event_num, + GdkDrawable *drawable, + gint x, + gint y, + gint width, + gint height) { EDayView *day_view; EDayViewEvent *event; @@ -389,7 +171,7 @@ e_day_view_top_item_draw_long_event (EDayViewTopItem *dvtitem, gfloat alpha; gdouble x0, y0, rect_height, rect_width, radius; - day_view = dvtitem->day_view; + day_view = e_day_view_top_item_get_day_view (top_item); model = e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)); cr = gdk_cairo_create (drawable); @@ -519,20 +301,18 @@ e_day_view_top_item_draw_long_event (EDayViewTopItem *dvtitem, /* If the event starts before the first day shown, draw a triangle */ if (draw_start_triangle && event->start < day_view->day_starts[start_day]) { - e_day_view_top_item_draw_triangle (dvtitem, drawable, - item_x - x + 4, item_y - y, - -E_DAY_VIEW_BAR_WIDTH, - item_h, event_num); + day_view_top_item_draw_triangle ( + top_item, drawable, item_x - x + 4, item_y - y, + -E_DAY_VIEW_BAR_WIDTH, item_h, event_num); } /* Similar for the event end. */ if (draw_end_triangle && event->end > day_view->day_starts[end_day + 1]) { - e_day_view_top_item_draw_triangle (dvtitem, drawable, - item_x + item_w - 4 - x, - item_y - y, - E_DAY_VIEW_BAR_WIDTH, - item_h, event_num); + day_view_top_item_draw_triangle ( + top_item, drawable, item_x + item_w - 4 - x, + item_y - y, E_DAY_VIEW_BAR_WIDTH, item_h, + event_num); } /* If we are editing the event we don't show the icons or the start @@ -712,109 +492,356 @@ e_day_view_top_item_draw_long_event (EDayViewTopItem *dvtitem, gdk_gc_set_clip_mask (gc, NULL); } -/* This draws a little triangle to indicate that an event extends past - the days visible on screen. */ static void -e_day_view_top_item_draw_triangle (EDayViewTopItem *dvtitem, - GdkDrawable *drawable, - gint x, - gint y, - gint w, - gint h, - gint event_num) +day_view_top_item_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_DAY_VIEW: + e_day_view_top_item_set_day_view ( + E_DAY_VIEW_TOP_ITEM (object), + g_value_get_object (value)); + return; + + case PROP_SHOW_DATES: + e_day_view_top_item_set_show_dates ( + E_DAY_VIEW_TOP_ITEM (object), + g_value_get_boolean (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +day_view_top_item_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_DAY_VIEW: + g_value_set_object ( + value, e_day_view_top_item_get_day_view ( + E_DAY_VIEW_TOP_ITEM (object))); + return; + + case PROP_SHOW_DATES: + g_value_set_boolean ( + value, e_day_view_top_item_get_show_dates ( + E_DAY_VIEW_TOP_ITEM (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +day_view_top_item_dispose (GObject *object) +{ + EDayViewTopItemPrivate *priv; + + priv = E_DAY_VIEW_TOP_ITEM_GET_PRIVATE (object); + + if (priv->day_view != NULL) { + g_object_unref (priv->day_view); + priv->day_view = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +day_view_top_item_update (GnomeCanvasItem *item, + gdouble *affine, + ArtSVP *clip_path, + gint flags) +{ + GnomeCanvasItemClass *canvas_item_class; + + /* Chain up to parent's update() method. */ + canvas_item_class = GNOME_CANVAS_ITEM_CLASS (parent_class); + canvas_item_class->update (item, affine, clip_path, flags); + + /* The item covers the entire canvas area. */ + item->x1 = 0; + item->y1 = 0; + item->x2 = INT_MAX; + item->y2 = INT_MAX; +} + +static void +day_view_top_item_draw (GnomeCanvasItem *canvas_item, + GdkDrawable *drawable, + gint x, + gint y, + gint width, + gint height) { + EDayViewTopItem *top_item; EDayView *day_view; - EDayViewEvent *event; - GdkGC *gc; - GdkColor bg_color; - GdkPoint points[3]; - gint c1, c2; + GtkStyle *style; + GdkGC *gc, *fg_gc, *bg_gc, *light_gc, *dark_gc; + gchar buffer[128]; + GdkRectangle clip_rect; + gint canvas_width, canvas_height, left_edge, day, date_width, date_x; + gint item_height, event_num; + PangoLayout *layout; cairo_t *cr; + GdkColor fg, bg, light, dark; + gboolean show_dates; - cr = gdk_cairo_create (drawable); + top_item = E_DAY_VIEW_TOP_ITEM (canvas_item); + day_view = e_day_view_top_item_get_day_view (top_item); + g_return_if_fail (day_view != NULL); + show_dates = top_item->priv->show_dates; - day_view = dvtitem->day_view; + cr = gdk_cairo_create (drawable); + style = gtk_widget_get_style (GTK_WIDGET (day_view)); gc = day_view->main_gc; + fg_gc = style->fg_gc[GTK_STATE_NORMAL]; + bg_gc = style->bg_gc[GTK_STATE_NORMAL]; + light_gc = style->light_gc[GTK_STATE_NORMAL]; + dark_gc = style->dark_gc[GTK_STATE_NORMAL]; + canvas_width = GTK_WIDGET (canvas_item->canvas)->allocation.width; + canvas_height = (show_dates ? 1 : (MAX (1, day_view->rows_in_top_display) + 1)) * day_view->top_row_height; + left_edge = 0; + item_height = day_view->top_row_height - E_DAY_VIEW_TOP_CANVAS_Y_GAP; - points[0].x = x; - points[0].y = y; - points[1].x = x + w; - points[1].y = y + (h / 2); - points[2].x = x; - points[2].y = y + h - 1; + fg = style->fg[GTK_STATE_NORMAL]; + bg = style->bg[GTK_STATE_NORMAL]; + light = style->light[GTK_STATE_NORMAL]; + dark = style->dark[GTK_STATE_NORMAL]; - /* If the height is odd we can use the same central point for both - lines. If it is even we use different end-points. */ - c1 = c2 = y + (h / 2); - if (h % 2 == 0) - c1--; + if (show_dates) { + /* Draw the shadow around the dates. */ + cairo_save (cr); + gdk_cairo_set_source_color (cr, &light); + cairo_move_to (cr, left_edge - x, 1 - y); + cairo_line_to (cr, canvas_width - 2 - x, 1 - y); + cairo_move_to (cr, left_edge - x, 2 - y); + cairo_line_to (cr, left_edge - x, item_height - 2 - y); + cairo_stroke (cr); + cairo_restore (cr); - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - cairo_save (cr); - /* Fill it in. */ - if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)), - event->comp_data), - &bg_color)) { - GdkColormap *colormap; + cairo_save (cr); + gdk_cairo_set_source_color (cr, &dark); + cairo_move_to (cr, left_edge - x, item_height - 1 - y); + cairo_line_to (cr, canvas_width - 1 - x, item_height - 1 - y); + cairo_move_to (cr, canvas_width - 1 - x, 1 - y); + cairo_line_to (cr, canvas_width - 1 - x, item_height - 1 - y); + cairo_stroke (cr); + cairo_restore (cr); - colormap = gtk_widget_get_colormap (GTK_WIDGET (day_view)); - if (gdk_colormap_alloc_color (colormap, &bg_color, TRUE, TRUE)) { - gdk_cairo_set_source_color (cr, &bg_color); - } else { - gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND]); + /* Draw the background for the dates. */ + cairo_save (cr); + gdk_cairo_set_source_color (cr, &bg); + cairo_rectangle (cr, left_edge + 2 - x, 2 - y, + canvas_width - left_edge - 3, + item_height - 3); + cairo_fill (cr); + cairo_restore (cr); + } + + if (!show_dates) { + /* Clear the main area background. */ + cairo_save (cr); + gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS]); + cairo_rectangle (cr, left_edge - x, - y, + canvas_width - left_edge, + canvas_height); + cairo_fill (cr); + cairo_restore (cr); + + /* Draw the selection background. */ + if (GTK_WIDGET_HAS_FOCUS (day_view) + && day_view->selection_start_day != -1) { + gint start_col, end_col, rect_x, rect_y, rect_w, rect_h; + + start_col = day_view->selection_start_day; + end_col = day_view->selection_end_day; + + if (end_col > start_col + || day_view->selection_start_row == -1 + || day_view->selection_end_row == -1) { + rect_x = day_view->day_offsets[start_col]; + rect_y = 0; + rect_w = day_view->day_offsets[end_col + 1] - rect_x; + rect_h = canvas_height - 1 - rect_y; + + cairo_save (cr); + gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_SELECTED]); + cairo_rectangle (cr, rect_x - x, rect_y - y, + rect_w, rect_h); + cairo_fill (cr); + cairo_restore (cr); + } } - } else { - gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND]); } - cairo_move_to (cr, points[0].x, points[0].y); - cairo_line_to (cr, points[1].x, points[1].y); - cairo_line_to (cr, points[2].x, points[2].y); - cairo_line_to (cr, points[0].x, points[0].y); - cairo_fill (cr); - cairo_restore (cr); + if (show_dates) { + /* Draw the date. Set a clipping rectangle so we don't draw over the + next day. */ + for (day = 0; day < day_view->days_shown; day++) { + e_day_view_top_item_get_day_label (day_view, day, buffer, sizeof (buffer)); + clip_rect.x = day_view->day_offsets[day] - x; + clip_rect.y = 2 - y; + if (day_view->days_shown == 1) + clip_rect.width = day_view->top_canvas->allocation.width - day_view->day_offsets[day]; + else + clip_rect.width = day_view->day_widths[day]; + clip_rect.height = item_height - 2; - cairo_save (cr); - gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BORDER]); - cairo_move_to (cr, x, y); - cairo_line_to (cr, x + w, c1); - cairo_move_to (cr, x, y + h - 1); - cairo_line_to (cr, x + w, c2); - cairo_stroke (cr); - cairo_restore (cr); + gdk_gc_set_clip_rectangle (fg_gc, &clip_rect); + + layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer); + pango_layout_get_pixel_size (layout, &date_width, NULL); + date_x = day_view->day_offsets[day] + (clip_rect.width - date_width) / 2; + + gdk_draw_layout (drawable, fg_gc, + date_x - x, + 3 - y, + layout); + g_object_unref (layout); + + gdk_gc_set_clip_rectangle (fg_gc, NULL); + + /* Draw the lines down the left and right of the date cols. */ + if (day != 0) { + cairo_save (cr); + gdk_cairo_set_source_color (cr, &light); + cairo_move_to (cr, day_view->day_offsets[day] - x, + 4 - y); + cairo_line_to (cr, day_view->day_offsets[day] - x, + item_height - 4 - y); + cairo_stroke (cr); + gdk_cairo_set_source_color (cr, &dark); + cairo_move_to (cr, day_view->day_offsets[day] - 1 - x, + 4 - y); + cairo_line_to (cr, day_view->day_offsets[day] - 1 - x, + item_height - 4 - y); + cairo_stroke (cr); + cairo_restore (cr); + } + + /* Draw the lines between each column. */ + if (day != 0) { + cairo_save (cr); + gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_GRID]); + cairo_move_to (cr, day_view->day_offsets[day] - x, + item_height - y); + cairo_line_to (cr, day_view->day_offsets[day] - x, + canvas_height - y); + cairo_stroke (cr); + cairo_restore (cr); + } + } + } + + if (!show_dates) { + /* Draw the long events. */ + for (event_num = 0; event_num < day_view->long_events->len; event_num++) { + day_view_top_item_draw_long_event ( + top_item, event_num, drawable, + x, y, width, height); + } + } cairo_destroy (cr); } -/* This is supposed to return the nearest item the the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ static double -e_day_view_top_item_point (GnomeCanvasItem *item, double x, double y, - gint cx, gint cy, - GnomeCanvasItem **actual_item) +day_view_top_item_point (GnomeCanvasItem *item, + gdouble x, + gdouble y, + gint cx, + gint cy, + GnomeCanvasItem **actual_item) { + /* This is supposed to return the nearest item the the point + * and the distance. Since we are the only item we just return + * ourself and 0 for the distance. This is needed so that we + * get button/motion events. */ *actual_item = item; + return 0.0; } -static gint -e_day_view_top_item_event (GnomeCanvasItem *item, GdkEvent *event) +static void +day_view_top_item_class_init (EDayViewTopItemClass *class) { - switch (event->type) { - case GDK_BUTTON_PRESS: + GObjectClass *object_class; + GnomeCanvasItemClass *item_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EDayViewTopItemPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = day_view_top_item_set_property; + object_class->get_property = day_view_top_item_get_property; + object_class->dispose = day_view_top_item_dispose; + + item_class = GNOME_CANVAS_ITEM_CLASS (class); + item_class->update = day_view_top_item_update; + item_class->draw = day_view_top_item_draw; + item_class->point = day_view_top_item_point; + + g_object_class_install_property ( + object_class, + PROP_DAY_VIEW, + g_param_spec_object ( + "day_view", + "Day View", + NULL, + E_TYPE_DAY_VIEW, + G_PARAM_READWRITE)); - case GDK_BUTTON_RELEASE: + g_object_class_install_property ( + object_class, + PROP_SHOW_DATES, + g_param_spec_boolean ( + "show_dates", + "Show Dates", + NULL, + TRUE, + G_PARAM_READWRITE)); +} - case GDK_MOTION_NOTIFY: +static void +day_view_top_item_init (EDayViewTopItem *top_item) +{ + top_item->priv = E_DAY_VIEW_TOP_ITEM_GET_PRIVATE (top_item); +} - default: - break; +GType +e_day_view_top_item_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + const GTypeInfo type_info = { + sizeof (EDayViewTopItemClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) day_view_top_item_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EDayViewTopItem), + 0, /* n_preallocs */ + (GInstanceInitFunc) day_view_top_item_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GNOME_TYPE_CANVAS_ITEM, "EDayViewTopItem", + &type_info, 0); } - return FALSE; + return type; } void @@ -854,3 +881,45 @@ e_day_view_top_item_get_day_label (EDayView *day_view, gint day, e_utf8_strftime (buffer, buffer_len, format, &day_start); } + +EDayView * +e_day_view_top_item_get_day_view (EDayViewTopItem *top_item) +{ + g_return_val_if_fail (E_IS_DAY_VIEW_TOP_ITEM (top_item), NULL); + + return top_item->priv->day_view; +} + +void +e_day_view_top_item_set_day_view (EDayViewTopItem *top_item, + EDayView *day_view) +{ + g_return_if_fail (E_IS_DAY_VIEW_TOP_ITEM (top_item)); + g_return_if_fail (E_IS_DAY_VIEW (day_view)); + + if (top_item->priv->day_view != NULL) + g_object_unref (top_item->priv->day_view); + + top_item->priv->day_view = g_object_ref (day_view); + + g_object_notify (G_OBJECT (top_item), "day-view"); +} + +gboolean +e_day_view_top_item_get_show_dates (EDayViewTopItem *top_item) +{ + g_return_val_if_fail (E_IS_DAY_VIEW_TOP_ITEM (top_item), FALSE); + + return top_item->priv->show_dates; +} + +void +e_day_view_top_item_set_show_dates (EDayViewTopItem *top_item, + gboolean show_dates) +{ + g_return_if_fail (E_IS_DAY_VIEW_TOP_ITEM (top_item)); + + top_item->priv->show_dates = show_dates; + + g_object_notify (G_OBJECT (top_item), "show-dates"); +} diff --git a/calendar/gui/e-day-view-top-item.h b/calendar/gui/e-day-view-top-item.h index e163e3eb81..64d56b135f 100644 --- a/calendar/gui/e-day-view-top-item.h +++ b/calendar/gui/e-day-view-top-item.h @@ -21,43 +21,64 @@ * */ -#ifndef _E_DAY_VIEW_TOP_ITEM_H_ -#define _E_DAY_VIEW_TOP_ITEM_H_ - -#include "e-day-view.h" - -G_BEGIN_DECLS - /* * EDayViewTopItem - displays the top part of the Day/Work Week calendar view. */ -#define E_DAY_VIEW_TOP_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - e_day_view_top_item_get_type (), EDayViewTopItem)) -#define E_DAY_VIEW_TOP_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k),\ - e_day_view_top_item_get_type ())) -#define E_IS_DAY_VIEW_TOP_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), \ - e_day_view_top_item_get_type ())) +#ifndef E_DAY_VIEW_TOP_ITEM_H +#define E_DAY_VIEW_TOP_ITEM_H -typedef struct { - GnomeCanvasItem canvas_item; +#include "e-day-view.h" - /* The parent EDayView widget. */ - EDayView *day_view; +/* Standard GObject macros */ +#define E_TYPE_DAY_VIEW_TOP_ITEM \ + (e_day_view_top_item_get_type ()) +#define E_DAY_VIEW_TOP_ITEM(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_DAY_VIEW_TOP_ITEM, EDayViewTopItem)) +#define E_DAY_VIEW_TOP_ITEM_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_DAY_VIEW_TOP_ITEM, EDayViewTopItemClass)) +#define E_IS_DAY_VIEW_TOP_ITEM(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_DAY_VIEW_TOP_ITEM)) +#define E_IS_DAY_VIEW_TOP_ITEM_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_DAY_VIEW_TOP_ITEM)) +#define E_DAY_VIEW_TOP_ITEM_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_DAY_VIEW_TOP_ITEM, EDayViewTopItemClass)) - /* Show dates or events. */ - gboolean show_dates; -} EDayViewTopItem; +G_BEGIN_DECLS -typedef struct { - GnomeCanvasItemClass parent_class; +typedef struct _EDayViewTopItem EDayViewTopItem; +typedef struct _EDayViewTopItemClass EDayViewTopItemClass; +typedef struct _EDayViewTopItemPrivate EDayViewTopItemPrivate; -} EDayViewTopItemClass; +struct _EDayViewTopItem { + GnomeCanvasItem parent; + EDayViewTopItemPrivate *priv; +}; + +struct _EDayViewTopItemClass { + GnomeCanvasItemClass parent_class; +}; -GType e_day_view_top_item_get_type (void); -void e_day_view_top_item_get_day_label (EDayView *day_view, gint day, - gchar *buffer, gint buffer_len); +GType e_day_view_top_item_get_type (void); +void e_day_view_top_item_get_day_label + (EDayView *day_view, + gint day, + gchar *buffer, + gint buffer_len); +EDayView * e_day_view_top_item_get_day_view(EDayViewTopItem *top_item); +void e_day_view_top_item_set_day_view(EDayViewTopItem *top_item, + EDayView *day_view); +gboolean e_day_view_top_item_get_show_dates + (EDayViewTopItem *top_item); +void e_day_view_top_item_set_show_dates + (EDayViewTopItem *top_item, + gboolean show_dates); G_END_DECLS -#endif /* _E_DAY_VIEW_TOP_ITEM_H_ */ +#endif /* E_DAY_VIEW_TOP_ITEM_H */ diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c index 8184cfbdb6..af6fdc66e7 100644 --- a/calendar/gui/e-day-view.c +++ b/calendar/gui/e-day-view.c @@ -831,7 +831,7 @@ time_range_changed_cb (ECalModel *model, time_t start_time, time_t end_time, gpo /* update the time canvas to show proper date in it */ eti = E_DAY_VIEW_TIME_ITEM (day_view->time_canvas_item); - if (eti && eti->second_zone) + if (eti && e_day_view_time_item_get_second_zone (eti)) gtk_widget_queue_draw (day_view->time_canvas); } diff --git a/calendar/gui/e-week-view-event-item.c b/calendar/gui/e-week-view-event-item.c index dc31e20696..0c9afbe651 100644 --- a/calendar/gui/e-week-view-event-item.c +++ b/calendar/gui/e-week-view-event-item.c @@ -40,178 +40,586 @@ #include <text/e-text.h> -static void e_week_view_event_item_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void e_week_view_event_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - gint flags); -static void e_week_view_event_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height); -static void e_week_view_draw_time (EWeekView *week_view, - GdkDrawable *drawable, - gint time_x, - gint time_y, - gint hour, - gint minute); -static void e_week_view_event_item_draw_icons (EWeekViewEventItem *wveitem, - GdkDrawable *drawable, - gint icon_x, - gint icon_y, - gint x2, - gboolean right_align, - GdkRegion *draw_region); -static void e_week_view_event_item_draw_triangle (EWeekViewEventItem *wveitem, - GdkDrawable *drawable, - GdkColor bg_color, - gint x, - gint y, - gint w, - gint h, - GdkRegion *draw_region); -static double e_week_view_event_item_point (GnomeCanvasItem *item, - double x, - double y, - gint cx, - gint cy, - GnomeCanvasItem **actual_item); -static gint e_week_view_event_item_event (GnomeCanvasItem *item, - GdkEvent *event); -static gboolean e_week_view_event_item_button_press (EWeekViewEventItem *wveitem, - GdkEvent *event); -static gboolean e_week_view_event_item_button_release (EWeekViewEventItem *wveitem, - GdkEvent *event); -static gboolean e_week_view_event_item_double_click (EWeekViewEventItem *wveitem, - GdkEvent *bevent); -static ECalendarViewPosition e_week_view_event_item_get_position (EWeekViewEventItem *wveitem, - gdouble x, - gdouble y); - -/* The arguments we take */ +#define E_WEEK_VIEW_EVENT_ITEM_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_WEEK_VIEW_EVENT_ITEM, EWeekViewEventItemPrivate)) + +struct _EWeekViewEventItemPrivate { + /* The event index in the EWeekView events array. */ + gint event_num; + + /* The span index within the event. */ + gint span_num; +}; + enum { PROP_0, PROP_EVENT_NUM, PROP_SPAN_NUM }; -G_DEFINE_TYPE (EWeekViewEventItem, e_week_view_event_item, GNOME_TYPE_CANVAS_ITEM) +static gpointer parent_class; + +static gboolean +can_draw_in_region (GdkRegion *draw_region, + gint x, + gint y, + gint width, + gint height) +{ + GdkRectangle rect; + + g_return_val_if_fail (draw_region != NULL, FALSE); + + rect.x = x; + rect.y = y; + rect.width = width; + rect.height = height; + + return gdk_region_rect_in (draw_region, &rect) != + GDK_OVERLAP_RECTANGLE_OUT; +} + +static ECalendarViewPosition +week_view_event_item_get_position (EWeekViewEventItem *event_item, + gdouble x, + gdouble y) +{ + EWeekView *week_view; + GnomeCanvasItem *item; + + item = GNOME_CANVAS_ITEM (event_item); + + week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent); + g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), E_CALENDAR_VIEW_POS_NONE); + + if (x < item->x1 + E_WEEK_VIEW_EVENT_L_PAD + || x >= item->x2 - E_WEEK_VIEW_EVENT_R_PAD) + return E_CALENDAR_VIEW_POS_NONE; + + /* Support left/right edge for long events only. */ + if (!e_week_view_is_one_day_event (week_view, event_item->priv->event_num)) { + if (x < item->x1 + E_WEEK_VIEW_EVENT_L_PAD + + E_WEEK_VIEW_EVENT_BORDER_WIDTH + + E_WEEK_VIEW_EVENT_EDGE_X_PAD) + return E_CALENDAR_VIEW_POS_LEFT_EDGE; + + if (x >= item->x2 + 1 - E_WEEK_VIEW_EVENT_R_PAD + - E_WEEK_VIEW_EVENT_BORDER_WIDTH + - E_WEEK_VIEW_EVENT_EDGE_X_PAD) + return E_CALENDAR_VIEW_POS_RIGHT_EDGE; + } + + return E_CALENDAR_VIEW_POS_EVENT; +} + +static gboolean +week_view_event_item_double_click (EWeekViewEventItem *event_item, + GdkEvent *bevent) +{ + EWeekView *week_view; + EWeekViewEvent *event; + GnomeCanvasItem *item; + + item = GNOME_CANVAS_ITEM (event_item); + + week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent); + g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE); + + event = &g_array_index ( + week_view->events, EWeekViewEvent, + event_item->priv->event_num); + + if (week_view->editing_event_num >= 0) { + EWeekViewEvent *editing; + + editing = &g_array_index ( + week_view->events, EWeekViewEvent, + week_view->editing_event_num); + + /* do not call edit of the component, if double clicked on the component, which is not on the server */ + if (editing && event && editing->comp_data == event->comp_data && (!event->comp_data || !is_icalcomp_on_the_server (event->comp_data->icalcomp, event->comp_data->client))) + return TRUE; + } + + e_week_view_stop_editing_event (week_view); + + e_calendar_view_edit_appointment ( + E_CALENDAR_VIEW (week_view), + event->comp_data->client, + event->comp_data->icalcomp, FALSE); + + return TRUE; +} + +static gboolean +week_view_event_item_button_press (EWeekViewEventItem *event_item, + GdkEvent *bevent) +{ + EWeekView *week_view; + ECalendarViewPosition pos; + EWeekViewEvent *event; + EWeekViewEventSpan *span; + GnomeCanvasItem *item; + + item = GNOME_CANVAS_ITEM (event_item); + + week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent); + g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE); + + event = &g_array_index (week_view->events, EWeekViewEvent, + event_item->priv->event_num); + span = &g_array_index (week_view->spans, EWeekViewEventSpan, + event->spans_index + event_item->priv->span_num); + + pos = week_view_event_item_get_position (event_item, bevent->button.x, + bevent->button.y); + if (pos == E_CALENDAR_VIEW_POS_NONE) + return FALSE; + + if (bevent->button.button == 1) { + week_view->pressed_event_num = event_item->priv->event_num; + week_view->pressed_span_num = event_item->priv->span_num; + + /* Ignore clicks on the event while editing. */ + if (E_TEXT (span->text_item)->editing) + return FALSE; + + /* Remember the item clicked and the mouse position, + so we can start a drag if the mouse moves. */ + week_view->drag_event_x = bevent->button.x; + week_view->drag_event_y = bevent->button.y; + + /* FIXME: Remember the day offset from the start of the event. + */ + + return TRUE; + } else if (bevent->button.button == 3) { + if (!GTK_WIDGET_HAS_FOCUS (week_view)) { + gtk_widget_grab_focus (GTK_WIDGET (week_view)); + if (week_view->event_destroyed) { + week_view->event_destroyed = FALSE; + return FALSE; + } + + } + + e_week_view_set_selected_time_range_visible ( + week_view, event->start, event->end); + + e_week_view_show_popup_menu ( + week_view, (GdkEventButton*) bevent, + event_item->priv->event_num); + g_signal_stop_emission_by_name ( + item->canvas, "button_press_event"); + + return TRUE; + } + + return FALSE; +} + +static gboolean +week_view_event_item_button_release (EWeekViewEventItem *event_item, + GdkEvent *event) +{ + EWeekView *week_view; + GnomeCanvasItem *item; + + item = GNOME_CANVAS_ITEM (event_item); + + week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent); + g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE); + + if (week_view->pressed_event_num != -1 + && week_view->pressed_event_num == event_item->priv->event_num + && week_view->pressed_span_num == event_item->priv->span_num) { + e_week_view_start_editing_event (week_view, + event_item->priv->event_num, + event_item->priv->span_num, + NULL); + week_view->pressed_event_num = -1; + return TRUE; + } + + week_view->pressed_event_num = -1; + + return FALSE; +} static void -e_week_view_event_item_class_init (EWeekViewEventItemClass *class) +week_view_draw_time (EWeekView *week_view, + GdkDrawable *drawable, + gint time_x, + gint time_y, + gint hour, + gint minute) { - GObjectClass *object_class; - GnomeCanvasItemClass *item_class; + ECalModel *model; + GtkStyle *style; + GdkGC *gc; + gint hour_to_display, suffix_width; + gint time_y_normal_font, time_y_small_font; + const gchar *suffix; + gchar buffer[128]; + PangoLayout *layout; + PangoFontDescription *small_font_desc; - object_class = G_OBJECT_CLASS (class); - object_class->set_property = e_week_view_event_item_set_property; + model = e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)); - item_class = GNOME_CANVAS_ITEM_CLASS (class); - item_class->update = e_week_view_event_item_update; - item_class->draw = e_week_view_event_item_draw; - item_class->point = e_week_view_event_item_point; - item_class->event = e_week_view_event_item_event; + style = gtk_widget_get_style (GTK_WIDGET (week_view)); + small_font_desc = week_view->small_font_desc; + gc = week_view->main_gc; - g_object_class_install_property ( - object_class, - PROP_EVENT_NUM, - g_param_spec_int ( - "event_num", - NULL, - NULL, - G_MININT, - G_MAXINT, - -1, - G_PARAM_WRITABLE)); + gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_TEXT]); - g_object_class_install_property ( - object_class, - PROP_SPAN_NUM, - g_param_spec_int ( - "span_num", - NULL, - NULL, - G_MININT, - G_MAXINT, - -1, - G_PARAM_WRITABLE)); + layout = gtk_widget_create_pango_layout (GTK_WIDGET (week_view), NULL); + + time_y_normal_font = time_y_small_font = time_y; + if (small_font_desc) + time_y_small_font = time_y; + + e_week_view_convert_time_to_display (week_view, hour, &hour_to_display, + &suffix, &suffix_width); + + if (week_view->use_small_font && week_view->small_font_desc) { + g_snprintf (buffer, sizeof (buffer), "%2i:%02i", + hour_to_display, minute); + + /* Draw the hour. */ + if (hour_to_display < 10) { + pango_layout_set_text (layout, buffer + 1, 1); + gdk_draw_layout (drawable, gc, + time_x + week_view->digit_width, + time_y_normal_font, + layout); + } else { + pango_layout_set_text (layout, buffer, 2); + gdk_draw_layout (drawable, gc, + time_x, + time_y_normal_font, + layout); + } + + time_x += week_view->digit_width * 2; + + /* Draw the start minute, in the small font. */ + pango_layout_set_font_description (layout, week_view->small_font_desc); + pango_layout_set_text (layout, buffer + 3, 2); + gdk_draw_layout (drawable, gc, + time_x, + time_y_small_font, + layout); + + pango_layout_set_font_description (layout, style->font_desc); + + time_x += week_view->small_digit_width * 2; + + /* Draw the 'am'/'pm' suffix, if 12-hour format. */ + if (!e_cal_model_get_use_24_hour_format (model)) { + pango_layout_set_text (layout, suffix, -1); + + gdk_draw_layout (drawable, gc, + time_x, + time_y_normal_font, + layout); + } + } else { + /* Draw the start time in one go. */ + g_snprintf (buffer, sizeof (buffer), "%2i:%02i%s", + hour_to_display, minute, suffix); + if (hour_to_display < 10) { + pango_layout_set_text (layout, buffer + 1, -1); + gdk_draw_layout (drawable, gc, + time_x + week_view->digit_width, + time_y_normal_font, + layout); + } else { + pango_layout_set_text (layout, buffer, -1); + gdk_draw_layout (drawable, gc, + time_x, + time_y_normal_font, + layout); + } + + } + g_object_unref (layout); } static void -e_week_view_event_item_init (EWeekViewEventItem *wveitem) +week_view_event_item_draw_icons (EWeekViewEventItem *event_item, + GdkDrawable *drawable, + gint icon_x, + gint icon_y, + gint x2, + gboolean right_align, + GdkRegion *draw_region) { - wveitem->event_num = -1; - wveitem->span_num = -1; + EWeekView *week_view; + EWeekViewEvent *event; + ECalComponent *comp; + GdkGC *gc; + gint num_icons = 0, icon_x_inc; + gboolean draw_reminder_icon = FALSE, draw_recurrence_icon = FALSE; + gboolean draw_timezone_icon = FALSE, draw_attach_icon = FALSE; + gboolean draw_meeting_icon = FALSE; + GSList *categories_pixbufs = NULL, *pixbufs; + cairo_t *cr; + + week_view = E_WEEK_VIEW (GTK_WIDGET (GNOME_CANVAS_ITEM (event_item)->canvas)->parent); + + event = &g_array_index (week_view->events, EWeekViewEvent, + event_item->priv->event_num); + comp = e_cal_component_new (); + e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp)); + + gc = week_view->main_gc; + cr = gdk_cairo_create (drawable); + + if (e_cal_component_has_alarms (comp)) { + draw_reminder_icon = TRUE; + num_icons++; + } + + if (e_cal_component_has_recurrences (comp) || e_cal_component_is_instance (comp)) { + draw_recurrence_icon = TRUE; + num_icons++; + } + + if (e_cal_component_has_attachments (comp)) { + draw_attach_icon = TRUE; + num_icons++; + } + + if (e_cal_component_has_attendees (comp)) { + draw_meeting_icon = TRUE; + num_icons++; + } + + if (event->different_timezone) { + draw_timezone_icon = TRUE; + num_icons++; + } + + num_icons += cal_comp_util_get_n_icons (comp, &categories_pixbufs); + + icon_x_inc = E_WEEK_VIEW_ICON_WIDTH + E_WEEK_VIEW_ICON_X_PAD; + + if (right_align) + icon_x -= icon_x_inc * num_icons; + + #define draw_pixbuf(pf) \ + if (can_draw_in_region (draw_region, icon_x, icon_y, \ + E_WEEK_VIEW_ICON_WIDTH, E_WEEK_VIEW_ICON_HEIGHT)) { \ + cairo_save (cr); \ + gdk_cairo_set_source_pixbuf (cr, pf, icon_x, icon_y); \ + cairo_paint (cr); \ + cairo_restore (cr); \ + } \ + \ + icon_x += icon_x_inc; + + if (draw_reminder_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { + draw_pixbuf (week_view->reminder_icon); + } + + if (draw_attach_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { + draw_pixbuf (week_view->attach_icon); + } + + if (draw_recurrence_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { + draw_pixbuf (week_view->recurrence_icon); + } + + if (draw_timezone_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { + draw_pixbuf (week_view->timezone_icon); + } + + if (draw_meeting_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { + draw_pixbuf (week_view->meeting_icon); + } + + /* draw categories icons */ + for (pixbufs = categories_pixbufs; + pixbufs; + pixbufs = pixbufs->next) { + GdkPixbuf *pixbuf = pixbufs->data; + + draw_pixbuf (pixbuf); + } + + #undef draw_pixbuf + + g_slist_foreach (categories_pixbufs, (GFunc)g_object_unref, NULL); + g_slist_free (categories_pixbufs); + + cairo_destroy (cr); + g_object_unref(comp); + gdk_gc_set_clip_mask (gc, NULL); } +/* This draws a little triangle to indicate that an event extends past + the days visible on screen. */ static void -e_week_view_event_item_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) +week_view_event_item_draw_triangle (EWeekViewEventItem *event_item, + GdkDrawable *drawable, + GdkColor bg_color, + gint x, + gint y, + gint w, + gint h, + GdkRegion *draw_region) { - GnomeCanvasItem *item; - EWeekViewEventItem *wveitem; + EWeekView *week_view; + EWeekViewEvent *event; + GdkGC *gc; + GdkPoint points[3]; + gint c1, c2; + cairo_t *cr; + + if (!can_draw_in_region (draw_region, x, y, w, h)) + return; + + week_view = E_WEEK_VIEW (GTK_WIDGET (GNOME_CANVAS_ITEM (event_item)->canvas)->parent); + + event = &g_array_index (week_view->events, EWeekViewEvent, + event_item->priv->event_num); + + gc = week_view->main_gc; + cr = gdk_cairo_create (drawable); + + points[0].x = x; + points[0].y = y; + points[1].x = x + w; + points[1].y = y + (h / 2); + points[2].x = x; + points[2].y = y + h - 1; - item = GNOME_CANVAS_ITEM (object); - wveitem = E_WEEK_VIEW_EVENT_ITEM (object); + if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)), + event->comp_data), + &bg_color)) { + GdkColormap *colormap; + + colormap = gtk_widget_get_colormap (GTK_WIDGET (week_view)); + if (gdk_colormap_alloc_color (colormap, &bg_color, TRUE, TRUE)) { + gdk_cairo_set_source_color (cr, &bg_color); + } + else { + gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND]); + } + } else { + gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND]); + } + + cairo_save (cr); + cairo_set_line_width (cr, 0.7); + cairo_move_to (cr, points[0].x, points[0].y); + cairo_line_to (cr, points[1].x, points[1].y); + cairo_line_to (cr, points[2].x, points[2].y); + cairo_line_to (cr, points[0].x, points[0].y); + cairo_fill (cr); + cairo_restore (cr); + + cairo_save (cr); + gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BORDER]); + + /* If the height is odd we can use the same central point for both + lines. If it is even we use different end-points. */ + c1 = c2 = y + (h / 2); + if (h % 2 == 0) + c1--; + + cairo_set_line_width (cr, 0.7); + cairo_move_to (cr, x, y); + cairo_line_to (cr, x + w, c1); + cairo_move_to (cr, x, y + h - 1); + cairo_line_to (cr, x + w, c2); + cairo_restore (cr); + + cairo_destroy (cr); +} + +static void +week_view_event_item_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ switch (property_id) { - case PROP_EVENT_NUM: - wveitem->event_num = g_value_get_int (value); - gnome_canvas_item_request_update (item); - return; - case PROP_SPAN_NUM: - wveitem->span_num = g_value_get_int (value); - gnome_canvas_item_request_update (item); - return; + case PROP_EVENT_NUM: + e_week_view_event_item_set_event_num ( + E_WEEK_VIEW_EVENT_ITEM (object), + g_value_get_int (value)); + return; + + case PROP_SPAN_NUM: + e_week_view_event_item_set_span_num ( + E_WEEK_VIEW_EVENT_ITEM (object), + g_value_get_int (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +week_view_event_item_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_EVENT_NUM: + g_value_set_int ( + value, + e_week_view_event_item_get_event_num ( + E_WEEK_VIEW_EVENT_ITEM (object))); + return; + + case PROP_SPAN_NUM: + g_value_set_int ( + value, + e_week_view_event_item_get_span_num ( + E_WEEK_VIEW_EVENT_ITEM (object))); + return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } static void -e_week_view_event_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - gint flags) +week_view_event_item_update (GnomeCanvasItem *item, + gdouble *affine, + ArtSVP *clip_path, + gint flags) { - EWeekViewEventItem *wveitem; + GnomeCanvasItemClass *canvas_item_class; + EWeekViewEventItem *event_item; EWeekView *week_view; + gint event_num, span_num; gint span_x, span_y, span_w; -#if 0 - g_print ("In e_week_view_event_item_update\n"); -#endif - - wveitem = E_WEEK_VIEW_EVENT_ITEM (item); + event_item = E_WEEK_VIEW_EVENT_ITEM (item); week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent); g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - if (GNOME_CANVAS_ITEM_CLASS (e_week_view_event_item_parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (e_week_view_event_item_parent_class)->update) (item, affine, clip_path, flags); + /* Chain up to parent's update() method. */ + canvas_item_class = GNOME_CANVAS_ITEM_CLASS (parent_class); + canvas_item_class->update (item, affine, clip_path, flags); item->x1 = 0; item->y1 = 0; item->x2 = 0; item->y2 = 0; - if (wveitem->event_num != -1 && wveitem->span_num != -1) { - if (e_week_view_get_span_position (week_view, - wveitem->event_num, - wveitem->span_num, - &span_x, &span_y, - &span_w)) { -#if 0 - g_print (" Event:%i Span:%i %i,%i W:%i\n", - wveitem->event_num, wveitem->span_num, - span_x, span_y, span_w); -#endif + event_num = e_week_view_event_item_get_event_num (event_item); + span_num = e_week_view_event_item_get_span_num (event_item); + + if (event_num != -1 && span_num != -1) { + if (e_week_view_get_span_position ( + week_view, event_num, span_num, + &span_x, &span_y, &span_w)) { item->x1 = span_x; item->y1 = span_y; item->x2 = span_x + span_w - 1; @@ -220,33 +628,15 @@ e_week_view_event_item_update (GnomeCanvasItem *item, } } -static gboolean -can_draw_in_region (GdkRegion *draw_region, gint x, gint y, gint width, gint height) -{ - GdkRectangle rect; - - g_return_val_if_fail (draw_region != NULL, FALSE); - - rect.x = x; - rect.y = y; - rect.width = width; - rect.height = height; - - return gdk_region_rect_in (draw_region, &rect) != GDK_OVERLAP_RECTANGLE_OUT; -} - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ static void -e_week_view_event_item_draw (GnomeCanvasItem *canvas_item, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height) +week_view_event_item_draw (GnomeCanvasItem *canvas_item, + GdkDrawable *drawable, + gint x, + gint y, + gint width, + gint height) { - EWeekViewEventItem *wveitem; + EWeekViewEventItem *event_item; EWeekView *week_view; EWeekViewEvent *event; EWeekViewEventSpan *span; @@ -269,27 +659,22 @@ e_week_view_event_item_draw (GnomeCanvasItem *canvas_item, GdkRegion *draw_region; GdkRectangle rect; -#if 0 - g_print ("In e_week_view_event_item_draw %i,%i %ix%i\n", - x, y, width, height); -#endif - - wveitem = E_WEEK_VIEW_EVENT_ITEM (canvas_item); + event_item = E_WEEK_VIEW_EVENT_ITEM (canvas_item); week_view = E_WEEK_VIEW (GTK_WIDGET (canvas_item->canvas)->parent); g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - if (wveitem->event_num == -1 || wveitem->span_num == -1) + if (event_item->priv->event_num == -1 || event_item->priv->span_num == -1) return; - g_return_if_fail (wveitem->event_num < week_view->events->len); + g_return_if_fail (event_item->priv->event_num < week_view->events->len); event = &g_array_index (week_view->events, EWeekViewEvent, - wveitem->event_num); + event_item->priv->event_num); - g_return_if_fail (event->spans_index + wveitem->span_num < week_view->spans->len); + g_return_if_fail (event->spans_index + event_item->priv->span_num < week_view->spans->len); span = &g_array_index (week_view->spans, EWeekViewEventSpan, - event->spans_index + wveitem->span_num); + event->spans_index + event_item->priv->span_num); gc = week_view->main_gc; @@ -331,7 +716,7 @@ e_week_view_event_item_draw (GnomeCanvasItem *canvas_item, time_width = e_week_view_get_time_string_width (week_view); - one_day_event = e_week_view_is_one_day_event (week_view, wveitem->event_num); + one_day_event = e_week_view_is_one_day_event (week_view, event_item->priv->event_num); bg_color = week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND]; if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)), event->comp_data), &bg_color)) { @@ -425,17 +810,17 @@ e_week_view_event_item_draw (GnomeCanvasItem *canvas_item, } if (draw_start) { - e_week_view_draw_time (week_view, drawable, - time_x, time_y, - start_hour, start_minute); + week_view_draw_time ( + week_view, drawable, time_x, + time_y, start_hour, start_minute); time_x += time_width; } if (draw_end) { time_x += E_WEEK_VIEW_EVENT_TIME_SPACING; - e_week_view_draw_time (week_view, drawable, - time_x, time_y, - end_hour, end_minute); + week_view_draw_time ( + week_view, drawable, time_x, + time_y, end_hour, end_minute); time_x += time_width; } @@ -444,9 +829,9 @@ e_week_view_event_item_draw (GnomeCanvasItem *canvas_item, icon_x += E_WEEK_VIEW_EVENT_TIME_X_PAD; /* Draw the icons. */ - e_week_view_event_item_draw_icons (wveitem, drawable, - icon_x, icon_y, - x2, FALSE, draw_region); + week_view_event_item_draw_icons ( + event_item, drawable, icon_x, + icon_y, x2, FALSE, draw_region); } else { rect_x = x1 + E_WEEK_VIEW_EVENT_L_PAD; @@ -518,7 +903,10 @@ e_week_view_event_item_draw (GnomeCanvasItem *canvas_item, } if (draw_start_triangle) { - e_week_view_event_item_draw_triangle (wveitem, drawable, bg_color, x1 + E_WEEK_VIEW_EVENT_L_PAD + 2, y1, -3, y2 - y1 + 1, draw_region); + week_view_event_item_draw_triangle ( + event_item, drawable, bg_color, + x1 + E_WEEK_VIEW_EVENT_L_PAD + 2, + y1, -3, y2 - y1 + 1, draw_region); } else if (can_draw_in_region (draw_region, rect_x, y1, 1, y2 - y1)) { cairo_save (cr); gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BORDER]); @@ -530,7 +918,10 @@ e_week_view_event_item_draw (GnomeCanvasItem *canvas_item, } if (draw_end_triangle) { - e_week_view_event_item_draw_triangle (wveitem, drawable, bg_color, x2 - E_WEEK_VIEW_EVENT_R_PAD - 2, y1, 3, y2 - y1 + 1, draw_region); + week_view_event_item_draw_triangle ( + event_item, drawable, bg_color, + x2 - E_WEEK_VIEW_EVENT_R_PAD - 2, + y1, 3, y2 - y1 + 1, draw_region); } else if (can_draw_in_region (draw_region, rect_x2, y2, 1, 1)) { cairo_save (cr); gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BORDER]); @@ -570,9 +961,9 @@ e_week_view_event_item_draw (GnomeCanvasItem *canvas_item, gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_TEXT]); - e_week_view_draw_time (week_view, drawable, - time_x, time_y, - start_hour, start_minute); + week_view_draw_time ( + week_view, drawable, time_x, + time_y, start_hour, start_minute); gdk_gc_set_clip_rectangle (gc, NULL); @@ -598,9 +989,9 @@ e_week_view_event_item_draw (GnomeCanvasItem *canvas_item, /* Draw the end time, if the position is greater than the minimum calculated above. */ if (time_x >= min_end_time_x) { - e_week_view_draw_time (week_view, drawable, - time_x, time_y, - end_hour, end_minute); + week_view_draw_time ( + week_view, drawable, time_x, + time_y, end_hour, end_minute); max_icon_x -= time_width + E_WEEK_VIEW_EVENT_TIME_X_PAD; } @@ -608,12 +999,12 @@ e_week_view_event_item_draw (GnomeCanvasItem *canvas_item, /* Draw the icons. */ if (span->text_item - && (week_view->editing_event_num != wveitem->event_num - || week_view->editing_span_num != wveitem->span_num)) { + && (week_view->editing_event_num != event_item->priv->event_num + || week_view->editing_span_num != event_item->priv->span_num)) { icon_x = span->text_item->x1 - E_WEEK_VIEW_ICON_R_PAD - x; - e_week_view_event_item_draw_icons (wveitem, drawable, - icon_x, icon_y, - max_icon_x, TRUE, draw_region); + week_view_event_item_draw_icons ( + event_item, drawable, icon_x, + icon_y, max_icon_x, TRUE, draw_region); } } cairo_destroy (cr); @@ -621,325 +1012,38 @@ e_week_view_event_item_draw (GnomeCanvasItem *canvas_item, gdk_region_destroy (draw_region); } -static void -e_week_view_draw_time (EWeekView *week_view, - GdkDrawable *drawable, - gint time_x, - gint time_y, - gint hour, - gint minute) -{ - ECalModel *model; - GtkStyle *style; - GdkGC *gc; - gint hour_to_display, suffix_width; - gint time_y_normal_font, time_y_small_font; - const gchar *suffix; - gchar buffer[128]; - PangoLayout *layout; - PangoFontDescription *small_font_desc; - - model = e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)); - - style = gtk_widget_get_style (GTK_WIDGET (week_view)); - small_font_desc = week_view->small_font_desc; - gc = week_view->main_gc; - - gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_TEXT]); - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (week_view), NULL); - - time_y_normal_font = time_y_small_font = time_y; - if (small_font_desc) - time_y_small_font = time_y; - - e_week_view_convert_time_to_display (week_view, hour, &hour_to_display, - &suffix, &suffix_width); - - if (week_view->use_small_font && week_view->small_font_desc) { - g_snprintf (buffer, sizeof (buffer), "%2i:%02i", - hour_to_display, minute); - - /* Draw the hour. */ - if (hour_to_display < 10) { - pango_layout_set_text (layout, buffer + 1, 1); - gdk_draw_layout (drawable, gc, - time_x + week_view->digit_width, - time_y_normal_font, - layout); - } else { - pango_layout_set_text (layout, buffer, 2); - gdk_draw_layout (drawable, gc, - time_x, - time_y_normal_font, - layout); - } - - time_x += week_view->digit_width * 2; - - /* Draw the start minute, in the small font. */ - pango_layout_set_font_description (layout, week_view->small_font_desc); - pango_layout_set_text (layout, buffer + 3, 2); - gdk_draw_layout (drawable, gc, - time_x, - time_y_small_font, - layout); - - pango_layout_set_font_description (layout, style->font_desc); - - time_x += week_view->small_digit_width * 2; - - /* Draw the 'am'/'pm' suffix, if 12-hour format. */ - if (!e_cal_model_get_use_24_hour_format (model)) { - pango_layout_set_text (layout, suffix, -1); - - gdk_draw_layout (drawable, gc, - time_x, - time_y_normal_font, - layout); - } - } else { - /* Draw the start time in one go. */ - g_snprintf (buffer, sizeof (buffer), "%2i:%02i%s", - hour_to_display, minute, suffix); - if (hour_to_display < 10) { - pango_layout_set_text (layout, buffer + 1, -1); - gdk_draw_layout (drawable, gc, - time_x + week_view->digit_width, - time_y_normal_font, - layout); - } else { - pango_layout_set_text (layout, buffer, -1); - gdk_draw_layout (drawable, gc, - time_x, - time_y_normal_font, - layout); - } - - } - g_object_unref (layout); -} - -static void -e_week_view_event_item_draw_icons (EWeekViewEventItem *wveitem, - GdkDrawable *drawable, - gint icon_x, - gint icon_y, - gint x2, - gboolean right_align, - GdkRegion *draw_region) -{ - EWeekView *week_view; - EWeekViewEvent *event; - ECalComponent *comp; - GdkGC *gc; - gint num_icons = 0, icon_x_inc; - gboolean draw_reminder_icon = FALSE, draw_recurrence_icon = FALSE; - gboolean draw_timezone_icon = FALSE, draw_attach_icon = FALSE; - gboolean draw_meeting_icon = FALSE; - GSList *categories_pixbufs = NULL, *pixbufs; - cairo_t *cr; - - week_view = E_WEEK_VIEW (GTK_WIDGET (GNOME_CANVAS_ITEM (wveitem)->canvas)->parent); - - event = &g_array_index (week_view->events, EWeekViewEvent, - wveitem->event_num); - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp)); - - gc = week_view->main_gc; - cr = gdk_cairo_create (drawable); - - if (e_cal_component_has_alarms (comp)) { - draw_reminder_icon = TRUE; - num_icons++; - } - - if (e_cal_component_has_recurrences (comp) || e_cal_component_is_instance (comp)) { - draw_recurrence_icon = TRUE; - num_icons++; - } - - if (e_cal_component_has_attachments (comp)) { - draw_attach_icon = TRUE; - num_icons++; - } - - if (e_cal_component_has_attendees (comp)) { - draw_meeting_icon = TRUE; - num_icons++; - } - - if (event->different_timezone) { - draw_timezone_icon = TRUE; - num_icons++; - } - - num_icons += cal_comp_util_get_n_icons (comp, &categories_pixbufs); - - icon_x_inc = E_WEEK_VIEW_ICON_WIDTH + E_WEEK_VIEW_ICON_X_PAD; - - if (right_align) - icon_x -= icon_x_inc * num_icons; - - #define draw_pixbuf(pf) \ - if (can_draw_in_region (draw_region, icon_x, icon_y, \ - E_WEEK_VIEW_ICON_WIDTH, E_WEEK_VIEW_ICON_HEIGHT)) { \ - cairo_save (cr); \ - gdk_cairo_set_source_pixbuf (cr, pf, icon_x, icon_y); \ - cairo_paint (cr); \ - cairo_restore (cr); \ - } \ - \ - icon_x += icon_x_inc; - - if (draw_reminder_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { - draw_pixbuf (week_view->reminder_icon); - } - - if (draw_attach_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { - draw_pixbuf (week_view->attach_icon); - } - - if (draw_recurrence_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { - draw_pixbuf (week_view->recurrence_icon); - } - - if (draw_timezone_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { - draw_pixbuf (week_view->timezone_icon); - } - - if (draw_meeting_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { - draw_pixbuf (week_view->meeting_icon); - } - - /* draw categories icons */ - for (pixbufs = categories_pixbufs; - pixbufs; - pixbufs = pixbufs->next) { - GdkPixbuf *pixbuf = pixbufs->data; - - draw_pixbuf (pixbuf); - } - - #undef draw_pixbuf - - g_slist_foreach (categories_pixbufs, (GFunc)g_object_unref, NULL); - g_slist_free (categories_pixbufs); - - cairo_destroy (cr); - g_object_unref(comp); - gdk_gc_set_clip_mask (gc, NULL); -} - -/* This draws a little triangle to indicate that an event extends past - the days visible on screen. */ -static void -e_week_view_event_item_draw_triangle (EWeekViewEventItem *wveitem, - GdkDrawable *drawable, - GdkColor bg_color, - gint x, - gint y, - gint w, - gint h, - GdkRegion *draw_region) -{ - EWeekView *week_view; - EWeekViewEvent *event; - GdkGC *gc; - GdkPoint points[3]; - gint c1, c2; - cairo_t *cr; - - if (!can_draw_in_region (draw_region, x, y, w, h)) - return; - - week_view = E_WEEK_VIEW (GTK_WIDGET (GNOME_CANVAS_ITEM (wveitem)->canvas)->parent); - - event = &g_array_index (week_view->events, EWeekViewEvent, - wveitem->event_num); - - gc = week_view->main_gc; - cr = gdk_cairo_create (drawable); - - points[0].x = x; - points[0].y = y; - points[1].x = x + w; - points[1].y = y + (h / 2); - points[2].x = x; - points[2].y = y + h - 1; - - if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)), - event->comp_data), - &bg_color)) { - GdkColormap *colormap; - - colormap = gtk_widget_get_colormap (GTK_WIDGET (week_view)); - if (gdk_colormap_alloc_color (colormap, &bg_color, TRUE, TRUE)) { - gdk_cairo_set_source_color (cr, &bg_color); - } - else { - gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND]); - - } - } else { - gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND]); - } - - cairo_save (cr); - cairo_set_line_width (cr, 0.7); - cairo_move_to (cr, points[0].x, points[0].y); - cairo_line_to (cr, points[1].x, points[1].y); - cairo_line_to (cr, points[2].x, points[2].y); - cairo_line_to (cr, points[0].x, points[0].y); - cairo_fill (cr); - cairo_restore (cr); - - cairo_save (cr); - gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BORDER]); - - /* If the height is odd we can use the same central point for both - lines. If it is even we use different end-points. */ - c1 = c2 = y + (h / 2); - if (h % 2 == 0) - c1--; - - cairo_set_line_width (cr, 0.7); - cairo_move_to (cr, x, y); - cairo_line_to (cr, x + w, c1); - cairo_move_to (cr, x, y + h - 1); - cairo_line_to (cr, x + w, c2); - cairo_restore (cr); - - cairo_destroy (cr); -} - -/* This is supposed to return the nearest item the the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ static double -e_week_view_event_item_point (GnomeCanvasItem *item, double x, double y, - gint cx, gint cy, - GnomeCanvasItem **actual_item) +week_view_event_item_point (GnomeCanvasItem *item, + gdouble x, + gdouble y, + gint cx, + gint cy, + GnomeCanvasItem **actual_item) { + /* This is supposed to return the nearest item the the point + * and the distance. Since we are the only item we just return + * ourself and 0 for the distance. This is needed so that we + * get button/motion events. */ *actual_item = item; + return 0.0; } static gint -e_week_view_event_item_event (GnomeCanvasItem *item, GdkEvent *event) +week_view_event_item_event (GnomeCanvasItem *item, + GdkEvent *event) { - EWeekViewEventItem *wveitem; + EWeekViewEventItem *event_item; - wveitem = E_WEEK_VIEW_EVENT_ITEM (item); + event_item = E_WEEK_VIEW_EVENT_ITEM (item); switch (event->type) { case GDK_2BUTTON_PRESS: - return e_week_view_event_item_double_click (wveitem, event); + return week_view_event_item_double_click (event_item, event); case GDK_BUTTON_PRESS: - return e_week_view_event_item_button_press (wveitem, event); + return week_view_event_item_button_press (event_item, event); case GDK_BUTTON_RELEASE: - return e_week_view_event_item_button_release (wveitem, event); + return week_view_event_item_button_release (event_item, event); case GDK_MOTION_NOTIFY: break; default: @@ -949,171 +1053,120 @@ e_week_view_event_item_event (GnomeCanvasItem *item, GdkEvent *event) return FALSE; } -static gboolean -e_week_view_event_item_button_press (EWeekViewEventItem *wveitem, - GdkEvent *bevent) +static void +week_view_event_item_class_init (EWeekViewEventItemClass *class) { - EWeekView *week_view; - ECalendarViewPosition pos; - EWeekViewEvent *event; - EWeekViewEventSpan *span; - GnomeCanvasItem *item; - - item = GNOME_CANVAS_ITEM (wveitem); - - week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent); - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE); - - event = &g_array_index (week_view->events, EWeekViewEvent, - wveitem->event_num); - span = &g_array_index (week_view->spans, EWeekViewEventSpan, - event->spans_index + wveitem->span_num); - -#if 0 - g_print ("In e_week_view_event_item_button_press\n"); -#endif - - pos = e_week_view_event_item_get_position (wveitem, bevent->button.x, - bevent->button.y); - if (pos == E_CALENDAR_VIEW_POS_NONE) - return FALSE; - - if (bevent->button.button == 1) { - week_view->pressed_event_num = wveitem->event_num; - week_view->pressed_span_num = wveitem->span_num; - - /* Ignore clicks on the event while editing. */ - if (E_TEXT (span->text_item)->editing) - return FALSE; - - /* Remember the item clicked and the mouse position, - so we can start a drag if the mouse moves. */ - week_view->drag_event_x = bevent->button.x; - week_view->drag_event_y = bevent->button.y; - - /* FIXME: Remember the day offset from the start of the event. - */ - - return TRUE; - } else if (bevent->button.button == 3) { - if (!GTK_WIDGET_HAS_FOCUS (week_view)) { - gtk_widget_grab_focus (GTK_WIDGET (week_view)); - if (week_view->event_destroyed) { - week_view->event_destroyed = FALSE; - return FALSE; - } + GObjectClass *object_class; + GnomeCanvasItemClass *item_class; - } + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EWeekViewEventItemPrivate)); - e_week_view_set_selected_time_range_visible (week_view, event->start, event->end); + object_class = G_OBJECT_CLASS (class); + object_class->set_property = week_view_event_item_set_property; + object_class->get_property = week_view_event_item_get_property; - e_week_view_show_popup_menu (week_view, - (GdkEventButton*) bevent, - wveitem->event_num); - g_signal_stop_emission_by_name (item->canvas, "button_press_event"); + item_class = GNOME_CANVAS_ITEM_CLASS (class); + item_class->update = week_view_event_item_update; + item_class->draw = week_view_event_item_draw; + item_class->point = week_view_event_item_point; + item_class->event = week_view_event_item_event; - return TRUE; - } + g_object_class_install_property ( + object_class, + PROP_EVENT_NUM, + g_param_spec_int ( + "event-num", + "Event Num", + NULL, + G_MININT, + G_MAXINT, + -1, + G_PARAM_READWRITE)); - return FALSE; + g_object_class_install_property ( + object_class, + PROP_SPAN_NUM, + g_param_spec_int ( + "span-num", + "Span Num", + NULL, + G_MININT, + G_MAXINT, + -1, + G_PARAM_READWRITE)); } -static gboolean -e_week_view_event_item_button_release (EWeekViewEventItem *wveitem, - GdkEvent *event) +static void +week_view_event_item_init (EWeekViewEventItem *event_item) { - EWeekView *week_view; - GnomeCanvasItem *item; - - item = GNOME_CANVAS_ITEM (wveitem); - - week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent); - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE); - -#if 0 - g_print ("In e_week_view_event_item_button_release\n"); -#endif - - if (week_view->pressed_event_num != -1 - && week_view->pressed_event_num == wveitem->event_num - && week_view->pressed_span_num == wveitem->span_num) { - e_week_view_start_editing_event (week_view, - wveitem->event_num, - wveitem->span_num, - NULL); - week_view->pressed_event_num = -1; - return TRUE; - } - - week_view->pressed_event_num = -1; - - return FALSE; + event_item->priv->event_num = -1; + event_item->priv->span_num = -1; } -static gboolean -e_week_view_event_item_double_click (EWeekViewEventItem *wveitem, - GdkEvent *bevent) +GType +e_week_view_event_item_get_type (void) { - EWeekView *week_view; - EWeekViewEvent *event; - GnomeCanvasItem *item; - - item = GNOME_CANVAS_ITEM (wveitem); - - week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent); - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE); - - event = &g_array_index (week_view->events, EWeekViewEvent, - wveitem->event_num); - - if (week_view->editing_event_num >= 0) { - EWeekViewEvent *editing = &g_array_index (week_view->events, EWeekViewEvent, week_view->editing_event_num); - - /* do not call edit of the component, if double clicked on the component, which is not on the server */ - if (editing && event && editing->comp_data == event->comp_data && (!event->comp_data || !is_icalcomp_on_the_server (event->comp_data->icalcomp, event->comp_data->client))) - return TRUE; + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + const GTypeInfo type_info = { + sizeof (EWeekViewEventItemClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) week_view_event_item_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EWeekViewEventItem), + 0, /* n_preallocs */ + (GInstanceInitFunc) week_view_event_item_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GNOME_TYPE_CANVAS_ITEM, "EWeekViewEventItem", + &type_info, 0); } - e_week_view_stop_editing_event (week_view); + return type; +} - e_calendar_view_edit_appointment (E_CALENDAR_VIEW (week_view), event->comp_data->client, event->comp_data->icalcomp, FALSE); +gint +e_week_view_event_item_get_event_num (EWeekViewEventItem *event_item) +{ + g_return_val_if_fail (E_IS_WEEK_VIEW_EVENT_ITEM (event_item), -1); - return TRUE; + return event_item->priv->event_num; } -static ECalendarViewPosition -e_week_view_event_item_get_position (EWeekViewEventItem *wveitem, - gdouble x, - gdouble y) +void +e_week_view_event_item_set_event_num (EWeekViewEventItem *event_item, + gint event_num) { - EWeekView *week_view; - GnomeCanvasItem *item; + g_return_if_fail (E_IS_WEEK_VIEW_EVENT_ITEM (event_item)); - item = GNOME_CANVAS_ITEM (wveitem); + event_item->priv->event_num = event_num; + gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (event_item)); - week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent); - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), E_CALENDAR_VIEW_POS_NONE); + g_object_notify (G_OBJECT (event_item), "event-num"); +} -#if 0 - g_print ("In e_week_view_event_item_get_position item: %g,%g %g,%g point: %g,%g\n", item->x1, item->y1, item->x2, item->y2, x, y); -#endif +gint +e_week_view_event_item_get_span_num (EWeekViewEventItem *event_item) +{ + g_return_val_if_fail (E_IS_WEEK_VIEW_EVENT_ITEM (event_item), -1); - if (x < item->x1 + E_WEEK_VIEW_EVENT_L_PAD - || x >= item->x2 - E_WEEK_VIEW_EVENT_R_PAD) - return E_CALENDAR_VIEW_POS_NONE; + return event_item->priv->span_num; +} - /* Support left/right edge for long events only. */ - if (!e_week_view_is_one_day_event (week_view, wveitem->event_num)) { - if (x < item->x1 + E_WEEK_VIEW_EVENT_L_PAD - + E_WEEK_VIEW_EVENT_BORDER_WIDTH - + E_WEEK_VIEW_EVENT_EDGE_X_PAD) - return E_CALENDAR_VIEW_POS_LEFT_EDGE; +void +e_week_view_event_item_set_span_num (EWeekViewEventItem *event_item, + gint span_num) +{ + g_return_if_fail (E_IS_WEEK_VIEW_EVENT_ITEM (event_item)); - if (x >= item->x2 + 1 - E_WEEK_VIEW_EVENT_R_PAD - - E_WEEK_VIEW_EVENT_BORDER_WIDTH - - E_WEEK_VIEW_EVENT_EDGE_X_PAD) - return E_CALENDAR_VIEW_POS_RIGHT_EDGE; - } + event_item->priv->span_num = span_num; + gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (event_item)); - return E_CALENDAR_VIEW_POS_EVENT; + g_object_notify (G_OBJECT (event_item), "span-num"); } diff --git a/calendar/gui/e-week-view-event-item.h b/calendar/gui/e-week-view-event-item.h index 6c077747f1..ff32eec83d 100644 --- a/calendar/gui/e-week-view-event-item.h +++ b/calendar/gui/e-week-view-event-item.h @@ -21,43 +21,63 @@ * */ -#ifndef _E_WEEK_VIEW_EVENT_ITEM_H_ -#define _E_WEEK_VIEW_EVENT_ITEM_H_ - -#include "e-week-view.h" - -G_BEGIN_DECLS - /* * EWeekViewEventItem - displays the background, times and icons for an event * in the week/month views. A separate EText canvas item is used to display & * edit the text. */ -#define E_WEEK_VIEW_EVENT_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - e_week_view_event_item_get_type (), EWeekViewEventItem)) -#define E_WEEK_VIEW_EVENT_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k),\ - e_week_view_event_item_get_type ())) -#define E_IS_WEEK_VIEW_EVENT_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), \ - e_week_view_event_item_get_type ())) +#ifndef E_WEEK_VIEW_EVENT_ITEM_H +#define E_WEEK_VIEW_EVENT_ITEM_H -typedef struct { - GnomeCanvasItem canvas_item; +#include "e-week-view.h" - /* The event index in the EWeekView events array. */ - gint event_num; +/* Standard GObject macros */ +#define E_TYPE_WEEK_VIEW_EVENT_ITEM \ + (e_week_view_event_item_get_type ()) +#define E_WEEK_VIEW_EVENT_ITEM(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_WEEK_VIEW_EVENT_ITEM, EWeekViewEventItem)) +#define E_WEEK_VIEW_EVENT_ITEM_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_WEEK_VIEW_EVENT_ITEM, EWeekViewEventItemClass)) +#define E_IS_WEEK_VIEW_EVENT_ITEM(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_WEEK_VIEW_EVENT_ITEM)) +#define E_IS_WEEK_VIEW_EVENT_ITEM_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_WEEK_VIEW_EVENT_ITEM)) +#define E_WEEK_VIEW_EVENT_ITEM_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_WEEK_VIEW_EVENT_ITEM, EWeekViewEventItemClass)) - /* The span index within the event. */ - gint span_num; -} EWeekViewEventItem; +G_BEGIN_DECLS -typedef struct { - GnomeCanvasItemClass parent_class; +typedef struct _EWeekViewEventItem EWeekViewEventItem; +typedef struct _EWeekViewEventItemClass EWeekViewEventItemClass; +typedef struct _EWeekViewEventItemPrivate EWeekViewEventItemPrivate; -} EWeekViewEventItemClass; +struct _EWeekViewEventItem { + GnomeCanvasItem parent; + EWeekViewEventItemPrivate *priv; +}; + +struct _EWeekViewEventItemClass { + GnomeCanvasItemClass parent_class; +}; -GType e_week_view_event_item_get_type (void); +GType e_week_view_event_item_get_type (void); +gint e_week_view_event_item_get_event_num + (EWeekViewEventItem *event_item); +void e_week_view_event_item_set_event_num + (EWeekViewEventItem *event_item, + gint event_num); +gint e_week_view_event_item_get_span_num + (EWeekViewEventItem *event_item); +void e_week_view_event_item_set_span_num + (EWeekViewEventItem *event_item, + gint span_num); G_END_DECLS -#endif /* _E_WEEK_VIEW_EVENT_ITEM_H_ */ +#endif /* E_WEEK_VIEW_EVENT_ITEM_H */ diff --git a/calendar/gui/e-week-view-main-item.c b/calendar/gui/e-week-view-main-item.c index 21db0a8e27..27a8fdb28a 100644 --- a/calendar/gui/e-week-view-main-item.c +++ b/calendar/gui/e-week-view-main-item.c @@ -28,163 +28,25 @@ #include <string.h> #include <glib.h> #include <glib/gi18n.h> + #include "e-week-view-main-item.h" #include "ea-calendar.h" #include "calendar-config.h" -static void e_week_view_main_item_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void e_week_view_main_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - gint flags); -static void e_week_view_main_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height); -static void e_week_view_main_item_draw_day (EWeekViewMainItem *wvmitem, - gint day, - GDate *date, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height); -static double e_week_view_main_item_point (GnomeCanvasItem *item, - double x, - double y, - gint cx, - gint cy, - GnomeCanvasItem **actual_item); - -/* The arguments we take */ +#define E_WEEK_VIEW_MAIN_ITEM_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_WEEK_VIEW_MAIN_ITEM, EWeekViewMainItemPrivate)) + +struct _EWeekViewMainItemPrivate { + EWeekView *week_view; +}; + enum { PROP_0, PROP_WEEK_VIEW }; -G_DEFINE_TYPE (EWeekViewMainItem, e_week_view_main_item, GNOME_TYPE_CANVAS_ITEM) - -static void -e_week_view_main_item_class_init (EWeekViewMainItemClass *class) -{ - GObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = G_OBJECT_CLASS (class); - object_class->set_property = e_week_view_main_item_set_property; - - item_class = GNOME_CANVAS_ITEM_CLASS (class); - item_class->update = e_week_view_main_item_update; - item_class->draw = e_week_view_main_item_draw; - item_class->point = e_week_view_main_item_point; - - g_object_class_install_property ( - object_class, - PROP_WEEK_VIEW, - g_param_spec_pointer ( - "week_view", - NULL, - NULL, - G_PARAM_WRITABLE)); - - /* init the accessibility support for e_week_view_main_item */ - e_week_view_main_item_a11y_init (); -} - -static void -e_week_view_main_item_init (EWeekViewMainItem *wvmitem) -{ - wvmitem->week_view = NULL; -} - -static void -e_week_view_main_item_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - EWeekViewMainItem *wvmitem; - - wvmitem = E_WEEK_VIEW_MAIN_ITEM (object); - - switch (property_id) { - case PROP_WEEK_VIEW: - wvmitem->week_view = g_value_get_pointer (value); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -e_week_view_main_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - gint flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (e_week_view_main_item_parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (e_week_view_main_item_parent_class)->update) (item, affine, clip_path, flags); - - /* The item covers the entire canvas area. */ - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; -} - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ -static void -e_week_view_main_item_draw (GnomeCanvasItem *canvas_item, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height) -{ - EWeekViewMainItem *wvmitem; - EWeekView *week_view; - GDate date; - gint num_days, day, day_x, day_y, day_w, day_h; - -#if 0 - g_print ("In e_week_view_main_item_draw %i,%i %ix%i\n", - x, y, width, height); -#endif - - wvmitem = E_WEEK_VIEW_MAIN_ITEM (canvas_item); - week_view = wvmitem->week_view; - g_return_if_fail (week_view != NULL); - - /* Step through each of the days. */ - date = week_view->first_day_shown; - - /* If no date has been set, we just use Dec 1999/January 2000. */ - if (!g_date_valid (&date)) - g_date_set_dmy (&date, 27, 12, 1999); - - num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7; - for (day = 0; day < num_days; day++) { - e_week_view_get_day_position (week_view, day, - &day_x, &day_y, - &day_w, &day_h); - /* Skip any days which are outside the area. */ - if (day_x < x + width && day_x + day_w >= x - && day_y < y + height && day_y + day_h >= y) { - e_week_view_main_item_draw_day (wvmitem, day, &date, - drawable, - day_x - x, day_y - y, - day_w, day_h); - } - g_date_add_days (&date, 1); - } -} +static gpointer parent_class; static gint gdate_to_cal_weekdays (GDateWeekday wd) @@ -204,14 +66,14 @@ gdate_to_cal_weekdays (GDateWeekday wd) } static void -e_week_view_main_item_draw_day (EWeekViewMainItem *wvmitem, - gint day, - GDate *date, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height) +week_view_main_item_draw_day (EWeekViewMainItem *main_item, + gint day, + GDate *date, + GdkDrawable *drawable, + gint x, + gint y, + gint width, + gint height) { EWeekView *week_view; GtkStyle *style; @@ -229,10 +91,7 @@ e_week_view_main_item_draw_day (EWeekViewMainItem *wvmitem, cairo_t *cr; CalWeekdays working_days; -#if 0 - g_print ("Drawing Day:%i at %i,%i\n", day, x, y); -#endif - week_view = wvmitem->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); style = gtk_widget_get_style (GTK_WIDGET (week_view)); gc = week_view->main_gc; cr = gdk_cairo_create (drawable); @@ -437,15 +296,217 @@ e_week_view_main_item_draw_day (EWeekViewMainItem *wvmitem, cairo_destroy (cr); } -/* This is supposed to return the nearest item the the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ -static double -e_week_view_main_item_point (GnomeCanvasItem *item, double x, double y, - gint cx, gint cy, - GnomeCanvasItem **actual_item) +static void +week_view_main_item_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_WEEK_VIEW: + e_week_view_main_item_set_week_view ( + E_WEEK_VIEW_MAIN_ITEM (object), + g_value_get_object (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +week_view_main_item_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_WEEK_VIEW: + g_value_set_object ( + value, e_week_view_main_item_get_week_view ( + E_WEEK_VIEW_MAIN_ITEM (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +week_view_main_item_dispose (GObject *object) +{ + EWeekViewMainItemPrivate *priv; + + priv = E_WEEK_VIEW_MAIN_ITEM_GET_PRIVATE (object); + + if (priv->week_view != NULL) { + g_object_unref (priv->week_view); + priv->week_view = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +week_view_main_item_update (GnomeCanvasItem *item, + gdouble *affine, + ArtSVP *clip_path, + gint flags) +{ + GnomeCanvasItemClass *canvas_item_class; + + /* Chain up to parent's update() method. */ + canvas_item_class = GNOME_CANVAS_ITEM_CLASS (parent_class); + canvas_item_class->update (item, affine, clip_path, flags); + + /* The item covers the entire canvas area. */ + item->x1 = 0; + item->y1 = 0; + item->x2 = INT_MAX; + item->y2 = INT_MAX; +} + +static void +week_view_main_item_draw (GnomeCanvasItem *canvas_item, + GdkDrawable *drawable, + gint x, + gint y, + gint width, + gint height) { + EWeekViewMainItem *main_item; + EWeekView *week_view; + GDate date; + gint num_days, day, day_x, day_y, day_w, day_h; + + main_item = E_WEEK_VIEW_MAIN_ITEM (canvas_item); + week_view = e_week_view_main_item_get_week_view (main_item); + g_return_if_fail (week_view != NULL); + + /* Step through each of the days. */ + date = week_view->first_day_shown; + + /* If no date has been set, we just use Dec 1999/January 2000. */ + if (!g_date_valid (&date)) + g_date_set_dmy (&date, 27, 12, 1999); + + num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7; + for (day = 0; day < num_days; day++) { + e_week_view_get_day_position (week_view, day, + &day_x, &day_y, + &day_w, &day_h); + /* Skip any days which are outside the area. */ + if (day_x < x + width && day_x + day_w >= x + && day_y < y + height && day_y + day_h >= y) { + week_view_main_item_draw_day ( + main_item, day, &date, drawable, + day_x - x, day_y - y, day_w, day_h); + } + g_date_add_days (&date, 1); + } +} + +static gdouble +week_view_main_item_point (GnomeCanvasItem *item, + gdouble x, + gdouble y, + gint cx, + gint cy, + GnomeCanvasItem **actual_item) +{ + /* This is supposed to return the nearest item the the point + * and the distance. Since we are the only item we just return + * ourself and 0 for the distance. This is needed so that we + * get button/motion events. */ *actual_item = item; + return 0.0; } +static void +week_view_main_item_class_init (EWeekViewMainItemClass *class) +{ + GObjectClass *object_class; + GnomeCanvasItemClass *item_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EWeekViewMainItemPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = week_view_main_item_set_property; + object_class->get_property = week_view_main_item_get_property; + object_class->dispose = week_view_main_item_dispose; + + item_class = GNOME_CANVAS_ITEM_CLASS (class); + item_class->update = week_view_main_item_update; + item_class->draw = week_view_main_item_draw; + item_class->point = week_view_main_item_point; + + g_object_class_install_property ( + object_class, + PROP_WEEK_VIEW, + g_param_spec_object ( + "week-view", + "Week View", + NULL, + E_TYPE_WEEK_VIEW, + G_PARAM_READWRITE)); + + /* init the accessibility support for e_week_view_main_item */ + e_week_view_main_item_a11y_init (); +} + +static void +week_view_main_item_init (EWeekViewMainItem *main_item) +{ + main_item->priv = E_WEEK_VIEW_MAIN_ITEM_GET_PRIVATE (main_item); +} + +GType +e_week_view_main_item_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + const GTypeInfo type_info = { + sizeof (EWeekViewMainItemClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) week_view_main_item_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EWeekViewMainItem), + 0, /* n_preallocs */ + (GInstanceInitFunc) week_view_main_item_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GNOME_TYPE_CANVAS_ITEM, "EWeekViewMainItem", + &type_info, 0); + } + + return type; +} + +EWeekView * +e_week_view_main_item_get_week_view (EWeekViewMainItem *main_item) +{ + g_return_val_if_fail (E_IS_WEEK_VIEW_MAIN_ITEM (main_item), NULL); + + return main_item->priv->week_view; +} + +void +e_week_view_main_item_set_week_view (EWeekViewMainItem *main_item, + EWeekView *week_view) +{ + g_return_if_fail (E_IS_WEEK_VIEW_MAIN_ITEM (main_item)); + g_return_if_fail (E_IS_WEEK_VIEW (week_view)); + + if (main_item->priv->week_view != NULL) + g_object_unref (main_item->priv->week_view); + + main_item->priv->week_view = g_object_ref (week_view); + + g_object_notify (G_OBJECT (main_item), "week-view"); +} diff --git a/calendar/gui/e-week-view-main-item.h b/calendar/gui/e-week-view-main-item.h index 3be9bbe5f3..7dc0187d4b 100644 --- a/calendar/gui/e-week-view-main-item.h +++ b/calendar/gui/e-week-view-main-item.h @@ -1,4 +1,5 @@ /* + * e-week-view-main-item.h * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -21,39 +22,57 @@ * */ -#ifndef _E_WEEK_VIEW_MAIN_ITEM_H_ -#define _E_WEEK_VIEW_MAIN_ITEM_H_ - -#include "e-week-view.h" - -G_BEGIN_DECLS - /* * EWeekViewMainItem - displays the background grid and dates for the Week and * Month calendar views. */ -#define E_WEEK_VIEW_MAIN_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - e_week_view_main_item_get_type (), EWeekViewMainItem)) -#define E_WEEK_VIEW_MAIN_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k),\ - e_week_view_main_item_get_type ())) -#define E_IS_WEEK_VIEW_MAIN_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), \ - e_week_view_main_item_get_type ())) +#ifndef E_WEEK_VIEW_MAIN_ITEM_H +#define E_WEEK_VIEW_MAIN_ITEM_H -typedef struct { - GnomeCanvasItem canvas_item; +#include "e-week-view.h" - /* The parent EWeekView widget. */ - EWeekView *week_view; -} EWeekViewMainItem; +/* Standard GObject macros */ +#define E_TYPE_WEEK_VIEW_MAIN_ITEM \ + (e_week_view_main_item_get_type ()) +#define E_WEEK_VIEW_MAIN_ITEM(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_WEEK_VIEW_MAIN_ITEM, EWeekViewMainItem)) +#define E_WEEK_VIEW_MAIN_ITEM_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_WEEK_VIEW_MAIN_ITEM, EWeekViewMainItemClass)) +#define E_IS_WEEK_VIEW_MAIN_ITEM(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_WEEK_VIEW_MAIN_ITEM)) +#define E_IS_WEEK_VIEW_MAIN_ITEM_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_WEEK_VIEW_MAIN_ITEM)) +#define E_WEEK_VIEW_MAIN_ITEM_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_WEEK_VIEW_MAIN_ITEM, EWeekViewMainItemClass)) -typedef struct { - GnomeCanvasItemClass parent_class; +G_BEGIN_DECLS + +typedef struct _EWeekViewMainItem EWeekViewMainItem; +typedef struct _EWeekViewMainItemClass EWeekViewMainItemClass; +typedef struct _EWeekViewMainItemPrivate EWeekViewMainItemPrivate; -} EWeekViewMainItemClass; +struct _EWeekViewMainItem { + GnomeCanvasItem parent; + EWeekViewMainItemPrivate *priv; +}; + +struct _EWeekViewMainItemClass { + GnomeCanvasItemClass parent_class; +}; -GType e_week_view_main_item_get_type (void); +GType e_week_view_main_item_get_type (void); +EWeekView * e_week_view_main_item_get_week_view + (EWeekViewMainItem *main_item); +void e_week_view_main_item_set_week_view + (EWeekViewMainItem *main_item, + EWeekView *week_view); G_END_DECLS -#endif /* _E_WEEK_VIEW_MAIN_ITEM_H_ */ +#endif /* E_WEEK_VIEW_MAIN_ITEM_H */ diff --git a/calendar/gui/e-week-view-titles-item.c b/calendar/gui/e-week-view-titles-item.c index 69108f43cb..f2d90e7150 100644 --- a/calendar/gui/e-week-view-titles-item.c +++ b/calendar/gui/e-week-view-titles-item.c @@ -29,92 +29,83 @@ #include <e-util/e-util.h> #include "e-week-view-titles-item.h" -static void e_week_view_titles_item_set_property(GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void e_week_view_titles_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - gint flags); -static void e_week_view_titles_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height); -static double e_week_view_titles_item_point (GnomeCanvasItem *item, - double x, - double y, - gint cx, - gint cy, - GnomeCanvasItem **actual_item); - -/* The arguments we take */ +#define E_WEEK_VIEW_TITLES_ITEM_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_WEEK_VIEW_TITLES_ITEM, EWeekViewTitlesItemPrivate)) + +struct _EWeekViewTitlesItemPrivate { + EWeekView *week_view; +}; + enum { PROP_0, PROP_WEEK_VIEW }; -G_DEFINE_TYPE (EWeekViewTitlesItem, e_week_view_titles_item, GNOME_TYPE_CANVAS_ITEM) +static gpointer parent_class; static void -e_week_view_titles_item_class_init (EWeekViewTitlesItemClass *class) +week_view_titles_item_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) { - GObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = G_OBJECT_CLASS (class); - object_class->set_property = e_week_view_titles_item_set_property; - - item_class = GNOME_CANVAS_ITEM_CLASS (class); - item_class->update = e_week_view_titles_item_update; - item_class->draw = e_week_view_titles_item_draw; - item_class->point = e_week_view_titles_item_point; + switch (property_id) { + case PROP_WEEK_VIEW: + e_week_view_titles_item_set_week_view ( + E_WEEK_VIEW_TITLES_ITEM (object), + g_value_get_object (value)); + return; + } - g_object_class_install_property ( - object_class, - PROP_WEEK_VIEW, - g_param_spec_pointer ( - "week_view", - NULL, - NULL, - G_PARAM_WRITABLE)); + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } static void -e_week_view_titles_item_init (EWeekViewTitlesItem *wvtitem) +week_view_titles_item_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) { - wvtitem->week_view = NULL; + switch (property_id) { + case PROP_WEEK_VIEW: + g_value_set_object ( + value, + e_week_view_titles_item_get_week_view ( + E_WEEK_VIEW_TITLES_ITEM (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } static void -e_week_view_titles_item_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) +week_view_titles_item_dispose (GObject *object) { - EWeekViewTitlesItem *wvtitem; + EWeekViewTitlesItemPrivate *priv; - wvtitem = E_WEEK_VIEW_TITLES_ITEM (object); + priv = E_WEEK_VIEW_TITLES_ITEM_GET_PRIVATE (object); - switch (property_id) { - case PROP_WEEK_VIEW: - wvtitem->week_view = g_value_get_pointer (value); - return; + if (priv->week_view != NULL) { + g_object_unref (priv->week_view); + priv->week_view = NULL; } - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); } static void -e_week_view_titles_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - gint flags) +week_view_titles_item_update (GnomeCanvasItem *item, + gdouble *affine, + ArtSVP *clip_path, + gint flags) { - if (GNOME_CANVAS_ITEM_CLASS (e_week_view_titles_item_parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (e_week_view_titles_item_parent_class)->update) (item, affine, clip_path, flags); + GnomeCanvasItemClass *canvas_item_class; + + /* Chain up to parent's update() method. */ + canvas_item_class = GNOME_CANVAS_ITEM_CLASS (parent_class); + canvas_item_class->update (item, affine, clip_path, flags); /* The item covers the entire canvas area. */ item->x1 = 0; @@ -123,19 +114,15 @@ e_week_view_titles_item_update (GnomeCanvasItem *item, item->y2 = INT_MAX; } -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ - static void -e_week_view_titles_item_draw (GnomeCanvasItem *canvas_item, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height) +week_view_titles_item_draw (GnomeCanvasItem *canvas_item, + GdkDrawable *drawable, + gint x, + gint y, + gint width, + gint height) { - EWeekViewTitlesItem *wvtitem; + EWeekViewTitlesItem *titles_item; EWeekView *week_view; GtkStyle *style; GdkGC *fg_gc, *light_gc, *dark_gc; @@ -146,13 +133,8 @@ e_week_view_titles_item_draw (GnomeCanvasItem *canvas_item, gint weekday; PangoLayout *layout; -#if 0 - g_print ("In e_week_view_titles_item_draw %i,%i %ix%i\n", - x, y, width, height); -#endif - - wvtitem = E_WEEK_VIEW_TITLES_ITEM (canvas_item); - week_view = wvtitem->week_view; + titles_item = E_WEEK_VIEW_TITLES_ITEM (canvas_item); + week_view = e_week_view_titles_item_get_week_view (titles_item); g_return_if_fail (week_view != NULL); style = gtk_widget_get_style (GTK_WIDGET (week_view)); @@ -259,15 +241,105 @@ e_week_view_titles_item_draw (GnomeCanvasItem *canvas_item, g_object_unref (layout); } -/* This is supposed to return the nearest item the the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ static double -e_week_view_titles_item_point (GnomeCanvasItem *item, double x, double y, - gint cx, gint cy, - GnomeCanvasItem **actual_item) +week_view_titles_item_point (GnomeCanvasItem *item, + gdouble x, + gdouble y, + gint cx, + gint cy, + GnomeCanvasItem **actual_item) { + /* This is supposed to return the nearest item the the point + * and the distance. Since we are the only item we just return + * ourself and 0 for the distance. This is needed so that we + * get button/motion events. */ *actual_item = item; + return 0.0; } +static void +week_view_titles_item_class_init (EWeekViewTitlesItemClass *class) +{ + GObjectClass *object_class; + GnomeCanvasItemClass *item_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EWeekViewTitlesItemPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = week_view_titles_item_set_property; + object_class->get_property = week_view_titles_item_get_property; + object_class->dispose = week_view_titles_item_dispose; + + item_class = GNOME_CANVAS_ITEM_CLASS (class); + item_class->update = week_view_titles_item_update; + item_class->draw = week_view_titles_item_draw; + item_class->point = week_view_titles_item_point; + + g_object_class_install_property ( + object_class, + PROP_WEEK_VIEW, + g_param_spec_object ( + "week-view", + "Week View", + NULL, + E_TYPE_WEEK_VIEW, + G_PARAM_READWRITE)); +} + +static void +week_view_titles_item_init (EWeekViewTitlesItem *titles_item) +{ + titles_item->priv = E_WEEK_VIEW_TITLES_ITEM_GET_PRIVATE (titles_item); +} + +GType +e_week_view_titles_item_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + const GTypeInfo type_info = { + sizeof (EWeekViewTitlesItemClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) week_view_titles_item_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EWeekViewTitlesItem), + 0, /* n_preallocs */ + (GInstanceInitFunc) week_view_titles_item_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GNOME_TYPE_CANVAS_ITEM, "EWeekViewTitlesItem", + &type_info, 0); + } + + return type; +} + +EWeekView * +e_week_view_titles_item_get_week_view (EWeekViewTitlesItem *titles_item) +{ + g_return_val_if_fail (E_IS_WEEK_VIEW_TITLES_ITEM (titles_item), NULL); + + return titles_item->priv->week_view; +} + +void +e_week_view_titles_item_set_week_view (EWeekViewTitlesItem *titles_item, + EWeekView *week_view) +{ + g_return_if_fail (E_IS_WEEK_VIEW_TITLES_ITEM (titles_item)); + g_return_if_fail (E_IS_WEEK_VIEW (week_view)); + + if (titles_item->priv->week_view != NULL) + g_object_unref (titles_item->priv->week_view); + + titles_item->priv->week_view = g_object_ref (week_view); + + g_object_notify (G_OBJECT (titles_item), "week-view"); +} diff --git a/calendar/gui/e-week-view-titles-item.h b/calendar/gui/e-week-view-titles-item.h index 3b27034202..d4cc111117 100644 --- a/calendar/gui/e-week-view-titles-item.h +++ b/calendar/gui/e-week-view-titles-item.h @@ -21,39 +21,57 @@ * */ -#ifndef _E_WEEK_VIEW_TITLES_ITEM_H_ -#define _E_WEEK_VIEW_TITLES_ITEM_H_ - -#include "e-week-view.h" - -G_BEGIN_DECLS - /* * EWeekViewTitlesItem - displays the 'Monday', 'Tuesday' etc. at the top of * the Month calendar view. */ -#define E_WEEK_VIEW_TITLES_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - e_week_view_titles_item_get_type (), EWeekViewTitlesItem)) -#define E_WEEK_VIEW_TITLES_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k),\ - e_week_view_titles_item_get_type ())) -#define E_IS_WEEK_VIEW_TITLES_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), \ - e_week_view_titles_item_get_type ())) +#ifndef E_WEEK_VIEW_TITLES_ITEM_H +#define E_WEEK_VIEW_TITLES_ITEM_H -typedef struct { - GnomeCanvasItem canvas_item; +#include "e-week-view.h" - /* The parent EWeekView widget. */ - EWeekView *week_view; -} EWeekViewTitlesItem; +/* Standard GObject macros */ +#define E_TYPE_WEEK_VIEW_TITLES_ITEM \ + (e_week_view_titles_item_get_type ()) +#define E_WEEK_VIEW_TITLES_ITEM(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_WEEK_VIEW_TITLES_ITEM, EWeekViewTitlesItem)) +#define E_WEEK_VIEW_TITLES_ITEM_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_WEEK_VIEW_TITLES_ITEM, EWeekViewTitlesItemClass)) +#define E_IS_WEEK_VIEW_TITLES_ITEM(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_WEEK_VIEW_TITLES_ITEM)) +#define E_IS_WEEK_VIEW_TITLES_ITEM_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_WEEK_VIEW_TITLES_ITEM)) +#define E_WEEK_VIEW_TITLES_ITEM_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_WEEK_VIEW_TITLES_ITEM, EWeekViewTitlesItemClass)) -typedef struct { - GnomeCanvasItemClass parent_class; +G_BEGIN_DECLS + +typedef struct _EWeekViewTitlesItem EWeekViewTitlesItem; +typedef struct _EWeekViewTitlesItemClass EWeekViewTitlesItemClass; +typedef struct _EWeekViewTitlesItemPrivate EWeekViewTitlesItemPrivate; -} EWeekViewTitlesItemClass; +struct _EWeekViewTitlesItem { + GnomeCanvasItem parent; + EWeekViewTitlesItemPrivate *priv; +}; + +struct _EWeekViewTitlesItemClass { + GnomeCanvasItemClass parent_class; +}; -GType e_week_view_titles_item_get_type (void); +GType e_week_view_titles_item_get_type(void); +EWeekView * e_week_view_titles_item_get_week_view + (EWeekViewTitlesItem *titles_item); +void e_week_view_titles_item_set_week_view + (EWeekViewTitlesItem *titles_item, + EWeekView *week_view); G_END_DECLS -#endif /* _E_WEEK_VIEW_TITLES_ITEM_H_ */ +#endif /* E_WEEK_VIEW_TITLES_ITEM_H */ diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c index fc9237e6ea..a3a482b401 100644 --- a/calendar/gui/e-week-view.c +++ b/calendar/gui/e-week-view.c @@ -2197,9 +2197,14 @@ e_week_view_remove_event_cb (EWeekView *week_view, if (span && span->background_item && E_IS_WEEK_VIEW_EVENT_ITEM (span->background_item)) { EWeekViewEventItem *wveitem = E_WEEK_VIEW_EVENT_ITEM (span->background_item); + gint wveitem_event_num; - if (wveitem->event_num > event_num) - wveitem->event_num--; + wveitem_event_num = + e_week_view_event_item_get_event_num (wveitem); + + if (wveitem_event_num > event_num) + e_week_view_event_item_set_event_num ( + wveitem, wveitem_event_num - 1); } } } diff --git a/calendar/gui/ea-day-view-main-item.c b/calendar/gui/ea-day-view-main-item.c index 89b6f1a57b..9d277287f6 100644 --- a/calendar/gui/ea-day-view-main-item.c +++ b/calendar/gui/ea-day-view-main-item.c @@ -232,6 +232,7 @@ ea_day_view_main_item_new (GObject *obj) AtkObject *accessible; GnomeCalendar *gcal; EDayViewMainItem *main_item; + EDayView *day_view; g_return_val_if_fail (E_IS_DAY_VIEW_MAIN_ITEM (obj), NULL); @@ -246,13 +247,17 @@ ea_day_view_main_item_new (GObject *obj) printf ("ACC_DEBUG: n_ea_day_view_main_item_created = %d\n", n_ea_day_view_main_item_created); #endif + main_item = E_DAY_VIEW_MAIN_ITEM (obj); - g_signal_connect (main_item->day_view, "selected_time_changed", - G_CALLBACK (ea_day_view_main_item_time_change_cb), - accessible); + day_view = e_day_view_main_item_get_day_view (main_item); + + g_signal_connect ( + day_view, "selected_time_changed", + G_CALLBACK (ea_day_view_main_item_time_change_cb), + accessible); /* listen for date changes of calendar */ - gcal = e_calendar_view_get_calendar (E_CALENDAR_VIEW (main_item->day_view)); + gcal = e_calendar_view_get_calendar (E_CALENDAR_VIEW (day_view)); if (gcal) g_signal_connect (gcal, "dates_shown_changed", G_CALLBACK (ea_day_view_main_item_dates_change_cb), @@ -316,7 +321,7 @@ ea_day_view_main_item_get_n_children (AtkObject *accessible) return -1; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); return day_view->rows * day_view->days_shown; } @@ -341,7 +346,7 @@ ea_day_view_main_item_ref_child (AtkObject *accessible, gint index) return NULL; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); n_children = ea_day_view_main_item_get_n_children (accessible); if (index < 0 || index >= n_children) @@ -371,6 +376,7 @@ ea_day_view_main_item_get_parent (AtkObject *accessible) AtkGObjectAccessible *atk_gobj; GObject *g_obj; EDayViewMainItem *main_item; + EDayView *day_view; g_return_val_if_fail (EA_IS_DAY_VIEW_MAIN_ITEM (accessible), NULL); @@ -380,7 +386,9 @@ ea_day_view_main_item_get_parent (AtkObject *accessible) return NULL; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - return gtk_widget_get_accessible (GTK_WIDGET (main_item->day_view)); + day_view = e_day_view_main_item_get_day_view (main_item); + + return gtk_widget_get_accessible (GTK_WIDGET (day_view)); } static gint @@ -474,7 +482,7 @@ ea_day_view_main_item_get_child_index_at (EaDayViewMainItem *ea_main_item, return -1; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); if (row >= 0 && row < day_view->rows && column >= 0 && column < day_view->days_shown) @@ -500,7 +508,7 @@ ea_day_view_main_item_get_row_at_index (EaDayViewMainItem *ea_main_item, return -1; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); n_children = ea_day_view_main_item_get_n_children (ATK_OBJECT (ea_main_item)); if (index >= 0 && index < n_children) @@ -526,7 +534,7 @@ ea_day_view_main_item_get_column_at_index (EaDayViewMainItem *ea_main_item, return -1; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); n_children = ea_day_view_main_item_get_n_children (ATK_OBJECT (ea_main_item)); if (index >= 0 && index < n_children) @@ -553,7 +561,7 @@ ea_day_view_main_item_get_row_label (EaDayViewMainItem *ea_main_item, return 0; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); hour = day_view->first_hour_shown; minute = day_view->first_minute_shown; @@ -584,7 +592,7 @@ ea_day_view_main_item_get_cell_data (EaDayViewMainItem *ea_main_item) return NULL; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); cell_data = g_object_get_data (G_OBJECT(ea_main_item), "ea-day-view-cell-table"); @@ -642,7 +650,7 @@ component_interface_get_extents (AtkComponent *component, /* defunct object*/ return; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); ea_canvas = gtk_widget_get_accessible (day_view->main_canvas); atk_component_get_extents (ATK_COMPONENT (ea_canvas), x, y, @@ -712,7 +720,7 @@ table_interface_get_n_rows (AtkTable *table) return -1; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); return day_view->rows; } @@ -732,7 +740,7 @@ table_interface_get_n_columns (AtkTable *table) return -1; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); return day_view->days_shown; } @@ -821,7 +829,7 @@ table_interface_is_row_selected (AtkTable *table, return FALSE; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); if (day_view->selection_start_day == -1) /* no selection */ @@ -860,7 +868,7 @@ table_interface_is_column_selected (AtkTable *table, return FALSE; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); if (column >= day_view->selection_start_day && column <= day_view->selection_end_day) @@ -885,7 +893,7 @@ table_interface_get_selected_rows (AtkTable *table, return -1; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); if (day_view->selection_start_day == -1) return 0; @@ -926,7 +934,7 @@ table_interface_get_selected_columns (AtkTable *table, return -1; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); if (day_view->selection_start_day == -1) return 0; @@ -959,7 +967,7 @@ table_interface_add_row_selection (AtkTable *table, return FALSE; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); /* FIXME: we need multi-selection */ @@ -999,7 +1007,7 @@ table_interface_add_column_selection (AtkTable *table, return FALSE; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); /* FIXME: we need multi-selection */ @@ -1062,7 +1070,7 @@ table_interface_get_column_description (AtkTable *table, return NULL; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); if (in_col < 0 || in_col >= day_view->days_shown) return NULL; @@ -1149,7 +1157,7 @@ selection_interface_add_selection (AtkSelection *selection, gint i) return FALSE; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); row = ea_day_view_main_item_get_row_at_index (ea_main_item, i); column = ea_day_view_main_item_get_column_at_index (ea_main_item, i); @@ -1186,7 +1194,7 @@ selection_interface_clear_selection (AtkSelection *selection) return FALSE; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); day_view->selection_start_row = -1; day_view->selection_start_day = -1; @@ -1204,6 +1212,7 @@ selection_interface_ref_selection (AtkSelection *selection, gint i) { gint count; GObject *g_obj; + EDayViewMainItem *main_item; EDayView *day_view; EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (selection); gint start_index; @@ -1213,7 +1222,10 @@ selection_interface_ref_selection (AtkSelection *selection, gint i) return NULL; g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (ea_main_item)); - day_view = E_DAY_VIEW_MAIN_ITEM (g_obj)->day_view; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = e_day_view_main_item_get_day_view (main_item); + start_index = ea_day_view_main_item_get_child_index_at (ea_main_item, day_view->selection_start_row, day_view->selection_start_day); @@ -1237,7 +1249,7 @@ selection_interface_get_selection_count (AtkSelection *selection) return 0; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); if (day_view->selection_start_day == -1 || day_view->selection_start_row == -1) @@ -1268,7 +1280,7 @@ selection_interface_is_child_selected (AtkSelection *selection, gint i) return FALSE; main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); - day_view = main_item->day_view; + day_view = e_day_view_main_item_get_day_view (main_item); row = ea_day_view_main_item_get_row_at_index (ea_main_item, i); column = ea_day_view_main_item_get_column_at_index (ea_main_item, i); diff --git a/calendar/gui/ea-week-view-main-item.c b/calendar/gui/ea-week-view-main-item.c index 3d0bd9e8e8..22ce67ca82 100644 --- a/calendar/gui/ea-week-view-main-item.c +++ b/calendar/gui/ea-week-view-main-item.c @@ -232,6 +232,7 @@ ea_week_view_main_item_new (GObject *obj) AtkObject *accessible; GnomeCalendar *gcal; EWeekViewMainItem *main_item; + EWeekView *week_view; g_return_val_if_fail (E_IS_WEEK_VIEW_MAIN_ITEM (obj), NULL); @@ -246,13 +247,17 @@ ea_week_view_main_item_new (GObject *obj) printf ("ACC_DEBUG: n_ea_week_view_main_item_created = %d\n", n_ea_week_view_main_item_created); #endif + main_item = E_WEEK_VIEW_MAIN_ITEM (obj); - g_signal_connect (main_item->week_view, "selected_time_changed", - G_CALLBACK (ea_week_view_main_item_time_change_cb), - accessible); + week_view = e_week_view_main_item_get_week_view (main_item); + + g_signal_connect ( + week_view, "selected_time_changed", + G_CALLBACK (ea_week_view_main_item_time_change_cb), + accessible); /* listen for date changes of calendar */ - gcal = e_calendar_view_get_calendar (E_CALENDAR_VIEW (main_item->week_view)); + gcal = e_calendar_view_get_calendar (E_CALENDAR_VIEW (week_view)); if (gcal) g_signal_connect (gcal, "dates_shown_changed", G_CALLBACK (ea_week_view_main_item_dates_change_cb), @@ -313,7 +318,7 @@ ea_week_view_main_item_get_n_children (AtkObject *accessible) return -1; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); if (week_view->multi_week_view) return 7 * week_view->weeks_shown; @@ -341,7 +346,7 @@ ea_week_view_main_item_ref_child (AtkObject *accessible, gint index) return NULL; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); n_children = ea_week_view_main_item_get_n_children (accessible); if (index < 0 || index >= n_children) @@ -371,6 +376,7 @@ ea_week_view_main_item_get_parent (AtkObject *accessible) AtkGObjectAccessible *atk_gobj; GObject *g_obj; EWeekViewMainItem *main_item; + EWeekView *week_view; g_return_val_if_fail (EA_IS_WEEK_VIEW_MAIN_ITEM (accessible), NULL); @@ -380,7 +386,9 @@ ea_week_view_main_item_get_parent (AtkObject *accessible) return NULL; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - return gtk_widget_get_accessible (GTK_WIDGET (main_item->week_view)); + week_view = e_week_view_main_item_get_week_view (main_item); + + return gtk_widget_get_accessible (GTK_WIDGET (week_view)); } static gint @@ -472,7 +480,7 @@ ea_week_view_main_item_get_child_index_at (EaWeekViewMainItem *ea_main_item, return -1; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); if (row >= 0 && row < week_view->weeks_shown && column >= 0 && column < 7) @@ -559,7 +567,7 @@ ea_week_view_main_item_get_cell_data (EaWeekViewMainItem *ea_main_item) return NULL; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); cell_data = g_object_get_data (G_OBJECT(ea_main_item), "ea-week-view-cell-table"); @@ -616,7 +624,7 @@ component_interface_get_extents (AtkComponent *component, /* defunct object*/ return; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); ea_canvas = gtk_widget_get_accessible (week_view->main_canvas); atk_component_get_extents (ATK_COMPONENT (ea_canvas), x, y, @@ -686,7 +694,7 @@ table_interface_get_n_rows (AtkTable *table) return -1; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); return week_view->weeks_shown; } @@ -790,7 +798,7 @@ table_interface_is_row_selected (AtkTable *table, return FALSE; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); if (week_view->selection_start_day == -1) /* no selection */ @@ -828,7 +836,7 @@ table_interface_is_column_selected (AtkTable *table, return FALSE; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); if ((column <0)||(column >6)) return FALSE; @@ -859,7 +867,7 @@ table_interface_get_selected_rows (AtkTable *table, return -1; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); if (week_view->selection_start_day == -1) return 0; @@ -894,7 +902,7 @@ table_interface_get_selected_columns (AtkTable *table, return -1; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); if (week_view->selection_start_day == -1) return 0; @@ -931,7 +939,7 @@ table_interface_add_row_selection (AtkTable *table, return FALSE; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); /* FIXME: we need multi-selection */ @@ -965,7 +973,7 @@ table_interface_add_column_selection (AtkTable *table, return FALSE; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); /* FIXME: we need multi-selection */ @@ -1082,7 +1090,7 @@ table_interface_get_row_description (AtkTable *table, return NULL; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); if (row < 0 || row >= week_view->weeks_shown) return NULL; @@ -1137,7 +1145,7 @@ selection_interface_add_selection (AtkSelection *selection, gint i) return FALSE; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); if (i < 0 || i > week_view->weeks_shown * 7 -1) return FALSE; @@ -1165,7 +1173,7 @@ selection_interface_clear_selection (AtkSelection *selection) return FALSE; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); week_view->selection_start_day = -1; week_view->selection_end_day = -1; @@ -1180,6 +1188,7 @@ selection_interface_ref_selection (AtkSelection *selection, gint i) { gint count; GObject *g_obj; + EWeekViewMainItem *main_item; EWeekView *week_view; EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (selection); gint start_index; @@ -1189,7 +1198,10 @@ selection_interface_ref_selection (AtkSelection *selection, gint i) return NULL; g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (ea_main_item)); - week_view = E_WEEK_VIEW_MAIN_ITEM (g_obj)->week_view; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = e_week_view_main_item_get_week_view (main_item); + start_index = ea_week_view_main_item_get_child_index_at (ea_main_item, week_view->selection_start_day / 7, week_view->selection_start_day % 7); @@ -1212,7 +1224,7 @@ selection_interface_get_selection_count (AtkSelection *selection) return 0; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); if (week_view->selection_start_day == -1 || week_view->selection_end_day == -1) @@ -1236,7 +1248,7 @@ selection_interface_is_child_selected (AtkSelection *selection, gint i) return FALSE; main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); - week_view = main_item->week_view; + week_view = e_week_view_main_item_get_week_view (main_item); if ((week_view->selection_start_day <= i)&&(week_view->selection_end_day >= i)) return TRUE; |