From 7be192643685acdc081332fc9177417d67870c53 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 21 Sep 2009 19:25:41 -0400 Subject: Calendar canvas item cleanup. --- calendar/gui/e-week-view-main-item.c | 395 ++++++++++++++++++++--------------- 1 file changed, 228 insertions(+), 167 deletions(-) (limited to 'calendar/gui/e-week-view-main-item.c') 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 #include #include + #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"); +} -- cgit v1.2.3