From f5b96e1fbd1d3e8fc2b781b159820ac56be68062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= Date: Wed, 17 Oct 2012 09:31:42 -0300 Subject: [PATCH] CellRendererIcon: add prelight state and render background - SL #3989 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is to provide feedback on mouse over. The styling needs to be done in the artwork component. Because cell renderers don't inherit GtkWidget anymore, the styling can't be done using the __gtype_name__ . Instead, it has to be done adding a css class [1] to the style context, and rendering the background in the reimplementation of the do_render method. For reference, see how GtkCellRendererToggle implements render [2] and how Baobab app does it [3]. [1] http://developer.gnome.org/gtk3/3.2/GtkStyleContext.html#gtk-style-context-add-class [2] http://git.gnome.org/browse/gtk+/tree/gtk/gtkcellrenderertoggle.c#n338 [3] http://git.gnome.org/browse/baobab/tree/src/baobab-cellrenderers.vala#n125 Signed-off-by: Manuel QuiƱones Acked-by: Simon Schampijer --- src/sugar3/graphics/icon.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py index 2d66cf91..60c18043 100644 --- a/src/sugar3/graphics/icon.py +++ b/src/sugar3/graphics/icon.py @@ -760,7 +760,7 @@ class CellRendererIcon(Gtk.CellRenderer): self._prelit_stroke_color = None self._palette_invoker = CellRendererInvoker() - GObject.GObject.__init__(self) + Gtk.CellRenderer.__init__(self) self._palette_invoker.attach_cell_renderer(tree_view, self) @@ -882,6 +882,23 @@ class CellRendererIcon(Gtk.CellRenderer): return False def do_render(self, cr, widget, background_area, cell_area, flags): + context = widget.get_style_context() + context.save() + context.add_class("sugar-icon-cell") + + # The context will have prelight state if the mouse pointer is + # in the entire row, but we want that state if the pointer is + # in this cell only: + if flags & Gtk.CellRendererState.PRELIT: + if not self._is_prelit(widget): + context.set_state(Gtk.StateFlags.NORMAL) + + Gtk.render_background(context, cr, background_area.x, background_area.y, + background_area.width, background_area.height) + + Gtk.render_frame(context, cr, background_area.x, background_area.y, + background_area.width, background_area.height) + if self._xo_color is not None: stroke_color = self._xo_color.get_stroke_color() fill_color = self._xo_color.get_fill_color()