diff options
Diffstat (limited to 'widgets/table/e-cell-toggle.c')
-rw-r--r-- | widgets/table/e-cell-toggle.c | 135 |
1 files changed, 28 insertions, 107 deletions
diff --git a/widgets/table/e-cell-toggle.c b/widgets/table/e-cell-toggle.c index ce98cbeb89..9abdda64b5 100644 --- a/widgets/table/e-cell-toggle.c +++ b/widgets/table/e-cell-toggle.c @@ -41,7 +41,6 @@ typedef struct { ECellView cell_view; GdkGC *gc; GnomeCanvas *canvas; - GdkPixmap **pixmap_cache; } ECellToggleView; #define CACHE_SEQ_COUNT 6 @@ -55,8 +54,6 @@ etog_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) ECellToggleView *toggle_view = g_new0 (ECellToggleView, 1); ETableItem *eti = E_TABLE_ITEM (e_table_item_view); GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas; - ECellToggle *etog = E_CELL_TOGGLE (ecell); - int i; toggle_view->cell_view.ecell = ecell; toggle_view->cell_view.e_table_model = table_model; @@ -64,9 +61,6 @@ etog_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) toggle_view->cell_view.kill_view_cb = NULL; toggle_view->cell_view.kill_view_cb_data = NULL; toggle_view->canvas = canvas; - toggle_view->pixmap_cache = g_new (GdkPixmap *, etog->n_states * CACHE_SEQ_COUNT); - for (i = 0; i < etog->n_states * CACHE_SEQ_COUNT; i++) - toggle_view->pixmap_cache[i] = NULL; return (ECellView *) toggle_view; } @@ -74,9 +68,7 @@ etog_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) static void etog_kill_view (ECellView *ecell_view) { - ECellToggle *etog = E_CELL_TOGGLE (ecell_view->ecell); ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - int i; if (toggle_view->cell_view.kill_view_cb) (toggle_view->cell_view.kill_view_cb)(ecell_view, toggle_view->cell_view.kill_view_cb_data); @@ -84,10 +76,6 @@ etog_kill_view (ECellView *ecell_view) if (toggle_view->cell_view.kill_view_cb_data) g_list_free(toggle_view->cell_view.kill_view_cb_data); - for (i = 0; i < etog->n_states * CACHE_SEQ_COUNT; i++) - if (toggle_view->pixmap_cache[i]) - g_object_unref (toggle_view->pixmap_cache[i]); - g_free (toggle_view->pixmap_cache); g_free (ecell_view); } @@ -111,65 +99,10 @@ etog_unrealize (ECellView *ecv) toggle_view->gc = NULL; } -#define PIXMAP_CACHE(toggle_view, cache_seq, image_seq) ((toggle_view)->pixmap_cache[(cache_seq) * E_CELL_TOGGLE (((ECellView *) (toggle_view))->ecell)->n_states + (image_seq)]) - #define RGB_COLOR(color) (((color).red & 0xff00) << 8 | \ ((color).green & 0xff00) | \ ((color).blue & 0xff00) >> 8) -static void -check_cache (ECellToggleView *toggle_view, int image_seq, int cache_seq) -{ - ECellView *ecell_view = (ECellView *) toggle_view; - ECellToggle *etog = E_CELL_TOGGLE (ecell_view->ecell); - - if (PIXMAP_CACHE (toggle_view, cache_seq, image_seq) == NULL) { - GdkPixbuf *image = etog->images[image_seq]; - GdkPixbuf *flat; - GdkColor color; - int width = gdk_pixbuf_get_width (image); - int height = gdk_pixbuf_get_height (image); - - PIXMAP_CACHE (toggle_view, cache_seq, image_seq) = - gdk_pixmap_new (toggle_view->canvas->layout.bin_window, width, height, - gtk_widget_get_visual (GTK_WIDGET (toggle_view->canvas))->depth); - - - switch (cache_seq % 3) { - case 0: - color = GTK_WIDGET (toggle_view->canvas)->style->bg [GTK_STATE_SELECTED]; - break; - case 1: - color = GTK_WIDGET (toggle_view->canvas)->style->bg [GTK_STATE_ACTIVE]; - break; - case 2: - color = GTK_WIDGET (toggle_view->canvas)->style->base [GTK_STATE_NORMAL]; - break; - } - - if (cache_seq >= 3) { - e_hsv_tweak (&color, 0.0f, 0.0f, -0.07f); - } - - flat = gdk_pixbuf_composite_color_simple (image, - width, height, - GDK_INTERP_BILINEAR, - 255, - 1, - RGB_COLOR (color), RGB_COLOR (color)); - - gdk_draw_pixbuf (PIXMAP_CACHE (toggle_view, cache_seq, image_seq), - toggle_view->gc, - flat, - 0, 0, - 0, 0, - width, height, - GDK_RGB_DITHER_NORMAL, - 0, 0); - g_object_unref (flat); - } -} - /* * ECell::draw method */ @@ -180,10 +113,10 @@ etog_draw (ECellView *ecell_view, GdkDrawable *drawable, { ECellToggle *toggle = E_CELL_TOGGLE (ecell_view->ecell); ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - GdkPixmap *pixmap; GdkPixbuf *image; int x, y, width, height; int cache_seq; + cairo_t *cr; const int value = GPOINTER_TO_INT ( e_table_model_value_at (ecell_view->e_table_model, model_col, row)); @@ -205,11 +138,9 @@ etog_draw (ECellView *ecell_view, GdkDrawable *drawable, if (E_TABLE_ITEM (ecell_view->e_table_item_view)->alternating_row_colors && (row % 2) == 0) cache_seq += 3; - check_cache (toggle_view, value, cache_seq); - pixmap = PIXMAP_CACHE (toggle_view, cache_seq, value); image = toggle->images[value]; - + if ((x2 - x1) < gdk_pixbuf_get_width (image)){ x = x1; width = x2 - x1; @@ -217,7 +148,7 @@ etog_draw (ECellView *ecell_view, GdkDrawable *drawable, x = x1 + ((x2 - x1) - gdk_pixbuf_get_width (image)) / 2; width = gdk_pixbuf_get_width (image); } - + if ((y2 - y1) < gdk_pixbuf_get_height (image)){ y = y1; height = y2 - y1; @@ -226,12 +157,14 @@ etog_draw (ECellView *ecell_view, GdkDrawable *drawable, height = gdk_pixbuf_get_height (image); } - gdk_draw_drawable (drawable, toggle_view->gc, - pixmap, - 0, 0, - x, y, - width, height); -} + cr = gdk_cairo_create (drawable); + cairo_save (cr); + gdk_cairo_set_source_pixbuf (cr, image, x, y); + cairo_paint_with_alpha (cr, 1); + cairo_restore (cr); + cairo_destroy (cr); + +} static void etog_set_value (ECellToggleView *toggle_view, int model_col, int view_col, int row, int value) @@ -310,20 +243,22 @@ etog_print (ECellView *ecell_view, GtkPrintContext *context, return; } - cr = gtk_print_context_get_cairo_context (context); - cairo_save(cr); image = toggle->images[value]; - cairo_translate (cr, 0 , 0); - image = gdk_pixbuf_add_alpha (image, TRUE, 255, 255, 255); - image_width = (double)gdk_pixbuf_get_width (image); - image_height = (double)gdk_pixbuf_get_height (image); - cairo_rectangle (cr, image_width / 7, image_height / 3, - image_width - image_width / 4, - image_width - image_height / 7); - cairo_clip (cr); - gdk_cairo_set_source_pixbuf (cr, image, 0, image_height / 4); - cairo_paint (cr); - cairo_restore(cr); + if (image) { + cr = gtk_print_context_get_cairo_context (context); + cairo_save(cr); + cairo_translate (cr, 0 , 0); + image = gdk_pixbuf_add_alpha (image, TRUE, 255, 255, 255); + image_width = (double)gdk_pixbuf_get_width (image); + image_height = (double)gdk_pixbuf_get_height (image); + cairo_rectangle (cr, image_width / 7, image_height / 3, + image_width - image_width / 4, + image_width - image_height / 7); + cairo_clip (cr); + gdk_cairo_set_source_pixbuf (cr, image, 0, image_height / 4); + cairo_paint (cr); + cairo_restore(cr); + } } static gdouble @@ -358,21 +293,6 @@ etog_max_width (ECellView *ecell_view, int model_col, int view_col) } static void -etog_style_set (ECellView *ecell_view, GtkStyle *previous_style) -{ - ECellToggle *toggle = E_CELL_TOGGLE (ecell_view->ecell); - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - int i; - - for (i = 0; i < toggle->n_states * CACHE_SEQ_COUNT; i++) { - if (toggle_view->pixmap_cache[i]) { - g_object_unref (toggle_view->pixmap_cache[i]); - toggle_view->pixmap_cache[i] = NULL; - } - } -} - -static void etog_finalize (GObject *object) { ECellToggle *etog = E_CELL_TOGGLE (object); @@ -406,7 +326,6 @@ e_cell_toggle_class_init (ECellToggleClass *klass) ecc->print = etog_print; ecc->print_height = etog_print_height; ecc->max_width = etog_max_width; - ecc->style_set = etog_style_set; gal_a11y_e_cell_registry_add_cell_type (NULL, E_CELL_TOGGLE_TYPE, @@ -443,10 +362,12 @@ e_cell_toggle_construct (ECellToggle *etog, int border, int n_states, GdkPixbuf for (i = 0; i < n_states; i++){ etog->images [i] = images [i]; + if (images[i]) { g_object_ref (images [i]); if (gdk_pixbuf_get_height (images [i]) > max_height) max_height = gdk_pixbuf_get_height (images [i]); + } } etog->height = max_height; |