diff options
author | Benjamin Otte <otte@redhat.com> | 2010-10-09 08:49:52 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2010-10-30 01:49:58 +0800 |
commit | 9a3e7eddaa09dae434efb38cf68a45085460240c (patch) | |
tree | 90b7236bef68d707b6087a53ac494f258881f876 | |
parent | de1adb892b2ab74695c03ef1899651d644c7ec91 (diff) | |
download | gsoc2013-evolution-9a3e7eddaa09dae434efb38cf68a45085460240c.tar gsoc2013-evolution-9a3e7eddaa09dae434efb38cf68a45085460240c.tar.gz gsoc2013-evolution-9a3e7eddaa09dae434efb38cf68a45085460240c.tar.bz2 gsoc2013-evolution-9a3e7eddaa09dae434efb38cf68a45085460240c.tar.lz gsoc2013-evolution-9a3e7eddaa09dae434efb38cf68a45085460240c.tar.xz gsoc2013-evolution-9a3e7eddaa09dae434efb38cf68a45085460240c.tar.zst gsoc2013-evolution-9a3e7eddaa09dae434efb38cf68a45085460240c.zip |
calendar: Port meeting time selector to Cairo
-rw-r--r-- | calendar/gui/e-meeting-time-sel-item.c | 41 | ||||
-rw-r--r-- | calendar/gui/e-meeting-time-sel.c | 78 | ||||
-rw-r--r-- | calendar/gui/e-meeting-time-sel.h | 7 |
3 files changed, 74 insertions, 52 deletions
diff --git a/calendar/gui/e-meeting-time-sel-item.c b/calendar/gui/e-meeting-time-sel-item.c index 102254dd7e..9433a9beaa 100644 --- a/calendar/gui/e-meeting-time-sel-item.c +++ b/calendar/gui/e-meeting-time-sel-item.c @@ -134,7 +134,6 @@ e_meeting_time_selector_item_init (EMeetingTimeSelectorItem *mts_item) mts_item->mts = NULL; mts_item->main_gc = NULL; - mts_item->stipple_gc = NULL; /* Create the cursors. */ mts_item->normal_cursor = gdk_cursor_new (GDK_LEFT_PTR); @@ -206,7 +205,6 @@ e_meeting_time_selector_item_realize (GnomeCanvasItem *item) window = gtk_widget_get_window (GTK_WIDGET (canvas)); mts_item->main_gc = gdk_gc_new (window); - mts_item->stipple_gc = gdk_gc_new (window); } static void @@ -218,8 +216,6 @@ e_meeting_time_selector_item_unrealize (GnomeCanvasItem *item) g_object_unref (mts_item->main_gc); mts_item->main_gc = NULL; - g_object_unref (mts_item->stipple_gc); - mts_item->stipple_gc = NULL; if (GNOME_CANVAS_ITEM_CLASS (e_meeting_time_selector_item_parent_class)->unrealize) (*GNOME_CANVAS_ITEM_CLASS (e_meeting_time_selector_item_parent_class)->unrealize)(item); @@ -243,6 +239,25 @@ e_meeting_time_selector_item_update (GnomeCanvasItem *item, double *affine, ArtS */ static void +draw_strikeout_box (EMeetingTimeSelectorItem *mts_item, cairo_t *cr, + int x, int y, int width, int height) +{ + GnomeCanvas *canvas = GNOME_CANVAS_ITEM (mts_item)->canvas; + EMeetingTimeSelector *mts = mts_item->mts; + + cairo_save (cr); + + cairo_rectangle (cr, x, y, width, height); + cairo_clip (cr); + + cairo_translate (cr, -canvas->draw_xofs, -canvas->draw_yofs); + cairo_set_source (cr, mts->no_info_pattern); + cairo_paint (cr); + + cairo_restore (cr); +} + +static void e_meeting_time_selector_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable, gint x, gint y, gint width, gint height) { EMeetingTimeSelector *mts; @@ -252,14 +267,13 @@ e_meeting_time_selector_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable, gint row, row_y, start_x, end_x; GDate date, last_date, current_date; gboolean is_display_top, show_meeting_time; - GdkGC *gc, *stipple_gc; + GdkGC *gc; cairo_t *cr; mts_item = E_MEETING_TIME_SELECTOR_ITEM (item); mts = mts_item->mts; g_return_if_fail (mts != NULL); gc = mts_item->main_gc; - stipple_gc = mts_item->stipple_gc; cr = gdk_cairo_create (drawable); is_display_top = (GTK_WIDGET (item->canvas) == mts->display_top) @@ -311,11 +325,6 @@ e_meeting_time_selector_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable, if (!is_display_top) { gdk_cairo_set_source_color (cr, &mts->grid_color); gdk_gc_set_foreground (gc, &mts->grid_color); - gdk_gc_set_foreground (stipple_gc, &mts->grid_color); - gdk_gc_set_background (stipple_gc, &mts->stipple_bg_color); - gdk_gc_set_stipple (stipple_gc, mts->stipple); - gnome_canvas_set_stipple_origin (item->canvas, stipple_gc); - gdk_gc_set_fill (stipple_gc, GDK_OPAQUE_STIPPLED); row = y / mts->row_height; row_y = row * mts->row_height - y; while (row < e_meeting_store_count_actual_attendees (mts->model) && row_y < height) { @@ -324,16 +333,16 @@ e_meeting_time_selector_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable, if (e_meeting_attendee_get_has_calendar_info (ia)) { if (e_meeting_time_selector_item_calculate_busy_range (mts, row, x, width, &start_x, &end_x)) { if (start_x >= width || end_x <= 0) { - gdk_draw_rectangle (drawable, stipple_gc, TRUE, 0, row_y, width, mts->row_height); + draw_strikeout_box (mts_item, cr, 0, row_y, width, mts->row_height); } else { if (start_x >= 0) { - gdk_draw_rectangle (drawable, stipple_gc, TRUE, 0, row_y, start_x, mts->row_height); + draw_strikeout_box (mts_item, cr, 0, row_y, start_x, mts->row_height); cairo_move_to (cr, start_x, row_y); cairo_line_to (cr, start_x, row_y + mts->row_height); cairo_stroke (cr); } if (end_x <= width) { - gdk_draw_rectangle (drawable, stipple_gc, TRUE, end_x, row_y, width - end_x, mts->row_height); + draw_strikeout_box (mts_item, cr, end_x, row_y, width - end_x, mts->row_height); cairo_move_to (cr, end_x, row_y); cairo_line_to (cr, end_x, row_y + mts->row_height); cairo_stroke (cr); @@ -341,9 +350,7 @@ e_meeting_time_selector_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable, } } } else { - gdk_draw_rectangle (drawable, stipple_gc, TRUE, - 0, row_y, - width, mts->row_height); + draw_strikeout_box (mts_item, cr, 0, row_y, width, mts->row_height); } row++; row_y += mts->row_height; diff --git a/calendar/gui/e-meeting-time-sel.c b/calendar/gui/e-meeting-time-sel.c index ae82b8cdf8..cc7f4dbf6d 100644 --- a/calendar/gui/e-meeting-time-sel.c +++ b/calendar/gui/e-meeting-time-sel.c @@ -277,11 +277,6 @@ meeting_time_selector_dispose (GObject *object) e_meeting_time_selector_remove_timeout (mts); - if (mts->stipple) { - g_object_unref (mts->stipple); - mts->stipple = NULL; - } - if (mts->model) { g_signal_handlers_disconnect_matched ( mts->model, G_SIGNAL_MATCH_DATA, @@ -406,9 +401,6 @@ e_meeting_time_selector_construct (EMeetingTimeSelector * mts, EMeetingStore *em guint accel_key; time_t meeting_start_time; struct tm *meeting_start_tm; - guchar stipple_bits[] = { - 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, - }; AtkObject *a11y_label, *a11y_date_edit; /* The default meeting time is the nearest half-hour interval in the @@ -838,7 +830,6 @@ e_meeting_time_selector_construct (EMeetingTimeSelector * mts, EMeetingStore *em e_meeting_time_selector_alloc_named_color (mts, "black", &mts->grid_color); e_meeting_time_selector_alloc_named_color (mts, "white", &mts->grid_shadow_color); e_meeting_time_selector_alloc_named_color (mts, "gray50", &mts->grid_unused_color); - e_meeting_time_selector_alloc_named_color (mts, "white", &mts->stipple_bg_color); e_meeting_time_selector_alloc_named_color (mts, "white", &mts->attendee_list_bg_color); e_meeting_time_selector_alloc_named_color (mts, "snow4", &mts->meeting_time_bg_color); @@ -847,10 +838,6 @@ e_meeting_time_selector_construct (EMeetingTimeSelector * mts, EMeetingStore *em e_meeting_time_selector_alloc_named_color (mts, "blue", &mts->busy_colors[E_MEETING_FREE_BUSY_BUSY]); e_meeting_time_selector_alloc_named_color (mts, "orange4", &mts->busy_colors[E_MEETING_FREE_BUSY_OUT_OF_OFFICE]); - /* Create the stipple, for attendees with no data. */ - mts->stipple = gdk_bitmap_create_from_data (NULL, (gchar *)stipple_bits, - 8, 8); - /* Connect handlers to the adjustments scroll the other items. */ layout = GTK_LAYOUT (mts->display_main); adjustment = gtk_layout_get_hadjustment (layout); @@ -912,35 +899,32 @@ e_meeting_time_selector_expose_key_color (GtkWidget *darea, GtkAllocation allocation; GdkWindow *window; GtkStyle *style; - GdkGC *gc; + cairo_t *cr; style = gtk_widget_get_style (darea); window = gtk_widget_get_window (darea); gtk_widget_get_allocation (darea, &allocation); mts = g_object_get_data (G_OBJECT (darea), "data"); - gc = mts->color_key_gc; gtk_paint_shadow ( style, window, GTK_STATE_NORMAL, GTK_SHADOW_IN, NULL, NULL, NULL, 0, 0, allocation.width, allocation.height); + cr = gdk_cairo_create (event->window); + if (color) { - gdk_gc_set_foreground (gc, color); - gdk_draw_rectangle ( - window, gc, TRUE, 1, 1, - allocation.width - 2, allocation.height - 2); + gdk_cairo_set_source_color (cr, color); } else { - gdk_gc_set_foreground (gc, &mts->grid_color); - gdk_gc_set_background (gc, &mts->stipple_bg_color); - gdk_gc_set_stipple (gc, mts->stipple); - gdk_gc_set_fill (gc, GDK_OPAQUE_STIPPLED); - gdk_draw_rectangle ( - window, gc, TRUE, 1, 1, - allocation.width - 2, allocation.height - 2); - gdk_gc_set_fill (gc, GDK_SOLID); + cairo_set_source (cr, mts->no_info_pattern); } + cairo_rectangle (cr, + 1, 1, + allocation.width - 2, allocation.height - 2); + cairo_fill (cr); + + cairo_destroy (cr); return TRUE; } @@ -1059,6 +1043,40 @@ e_meeting_time_selector_set_week_start_day (EMeetingTimeSelector *mts, g_object_notify (G_OBJECT (mts), "week-start-day"); } +static cairo_pattern_t * +e_meeting_time_selector_create_no_info_pattern (EMeetingTimeSelector *mts) +{ + cairo_surface_t *surface; + cairo_pattern_t *pattern; + GdkColor color; + cairo_t *cr; + + surface = gdk_window_create_similar_surface (gtk_widget_get_window (GTK_WIDGET (mts)), + CAIRO_CONTENT_COLOR, 8, 8); + cr = cairo_create (surface); + + gdk_color_parse ("white", &color); + gdk_cairo_set_source_color (cr, &color); + cairo_paint (cr); + + gdk_cairo_set_source_color (cr, &mts->grid_color); + cairo_set_line_width (cr, 1.0); + cairo_move_to (cr, -1, 5); + cairo_line_to (cr, 9, -5); + cairo_move_to (cr, -1, 13); + cairo_line_to (cr, 9, 3); + cairo_stroke (cr); + + cairo_destroy (cr); + + pattern = cairo_pattern_create_for_surface (surface); + cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); + + cairo_surface_destroy (surface); + + return pattern; +} + static void e_meeting_time_selector_realize (GtkWidget *widget) { @@ -1071,7 +1089,7 @@ e_meeting_time_selector_realize (GtkWidget *widget) mts = E_MEETING_TIME_SELECTOR (widget); window = gtk_widget_get_window (widget); - mts->color_key_gc = gdk_gc_new (window); + mts->no_info_pattern = e_meeting_time_selector_create_no_info_pattern (mts); } static void @@ -1081,8 +1099,8 @@ e_meeting_time_selector_unrealize (GtkWidget *widget) mts = E_MEETING_TIME_SELECTOR (widget); - g_object_unref (mts->color_key_gc); - mts->color_key_gc = NULL; + cairo_pattern_destroy (mts->no_info_pattern); + mts->no_info_pattern = NULL; if (GTK_WIDGET_CLASS (e_meeting_time_selector_parent_class)->unrealize) (*GTK_WIDGET_CLASS (e_meeting_time_selector_parent_class)->unrealize)(widget); diff --git a/calendar/gui/e-meeting-time-sel.h b/calendar/gui/e-meeting-time-sel.h index efd7671f3d..5fd5086dc0 100644 --- a/calendar/gui/e-meeting-time-sel.h +++ b/calendar/gui/e-meeting-time-sel.h @@ -181,11 +181,8 @@ struct _EMeetingTimeSelector { GdkColor grid_unused_color; GdkColor busy_colors[E_MEETING_FREE_BUSY_LAST]; - /* The stipple used for attendees with no data. */ - GdkPixmap *stipple; - - /* GC for drawing the color key. */ - GdkGC *color_key_gc; + /* The pattern used for attendees with no data. */ + cairo_pattern_t *no_info_pattern; /* Width of the hours strings (e.g. "1:00") in the current font. */ gint hour_widths[24]; |