diff options
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/table/ChangeLog | 9 | ||||
-rw-r--r-- | widgets/table/e-cell-toggle.c | 135 | ||||
-rw-r--r-- | widgets/table/e-table-item.c | 53 |
3 files changed, 87 insertions, 110 deletions
diff --git a/widgets/table/ChangeLog b/widgets/table/ChangeLog index deaa32876a..7ebe8f3ab1 100644 --- a/widgets/table/ChangeLog +++ b/widgets/table/ChangeLog @@ -1,3 +1,12 @@ +2008-01-20 Srinivasa Ragavan <sragavan@novell.com> + + * e-cell-toggle.c: (etog_new_view), (etog_kill_view), (etog_draw), + (etog_print), (e_cell_toggle_class_init), + (e_cell_toggle_construct): Removed the pixmap cache. It wasn't giving + alpha for the cairo rendered message list row. + * e-table-item.c: (eti_draw): Render the rows with Cairo. It looks + same as GtkTreeView and seems nice. + 2007-12-05 David Turner <cillian64@googlemail.com> ** Fix for bug #408170 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; diff --git a/widgets/table/e-table-item.c b/widgets/table/e-table-item.c index 4957e1d86a..f0fed160d1 100644 --- a/widgets/table/e-table-item.c +++ b/widgets/table/e-table-item.c @@ -1830,6 +1830,9 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, ArtPoint eti_base, eti_base_item, lower_right; GtkWidget *canvas = GTK_WIDGET(item->canvas); int height_extra = eti->horizontal_draw_grid ? 1 : 0; + cairo_t *cr; + + cr = gdk_cairo_create (drawable); /* * Find out our real position after grouping @@ -1954,6 +1957,8 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, ECellFlags flags; gboolean free_background; GdkColor *background; + int x1, x2, y1, y2; + cairo_pattern_t *pat; switch (eti->cursor_mode) { case E_CURSOR_SIMPLE: @@ -1968,12 +1973,52 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, break; } + x1 = xd; + y1 = yd+1; + x2 = x1 + ecol->width; + y2 = yd+height; + background = eti_get_cell_background_color (eti, row, col, col_selected, &free_background); - gdk_gc_set_foreground (eti->fill_gc, background); - gdk_draw_rectangle (drawable, eti->fill_gc, TRUE, - xd, yd, ecol->width, height); + cairo_save (cr); + pat = cairo_pattern_create_linear (0, y1, 0, y2); + cairo_pattern_add_color_stop_rgba (pat, 0.0, background->red/65535.0 , + background->green/65535.0, + background->blue/65535.0, selected ? 0.8: 1.0); + + cairo_pattern_add_color_stop_rgba (pat, 0.5, background->red/65535.0 , + background->green/65535.0, + background->blue/65535.0, 0.9); + + cairo_pattern_add_color_stop_rgba (pat, 1, background->red/65535.0 , + background->green/65535.0, + background->blue/65535.0, selected ? 0.8 : 1.0); + cairo_rectangle (cr, x1, y1, ecol->width, height-1); + cairo_set_source (cr, pat); + cairo_fill_preserve (cr); + cairo_pattern_destroy (pat); + cairo_set_line_width (cr, 0); + cairo_stroke (cr); + cairo_restore (cr); + cairo_save (cr); + cairo_set_line_width (cr, 1.0); + cairo_set_source_rgba (cr, background->red/65535.0 , + background->green/65535.0, + background->blue/65535.0, 1); + cairo_move_to (cr, x1, y1); + cairo_line_to (cr, x2, y1); + cairo_stroke (cr); + + cairo_set_line_width (cr, 1.0); + cairo_set_source_rgba (cr, background->red/65535.0 , + background->green/65535.0, + background->blue/65535.0, 1); + cairo_move_to (cr, x1, y2); + cairo_line_to (cr, x2, y2); + cairo_stroke (cr); + cairo_restore (cr); + if (free_background) gdk_color_free (background); @@ -2062,6 +2107,8 @@ eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, gdk_draw_rectangle (drawable, eti->focus_gc, FALSE, f_x1, f_y1, f_x2 - f_x1 - 1, f_y2 - f_y1 - 1); } + cairo_destroy (cr); + } static double |