From 15e487c7882ffb1cf2dee8c1821534d0c5c9abaa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
Date: Wed, 17 Oct 2012 09:31:42 -0300
Subject: [PATCH toolkit-gtk3] CellRendererIcon: add prelight state and render
background - SL #3989
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
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 is 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 <manuq@laptop.org>
---
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 5863118..5f982d6 100644
a
|
b
|
class CellRendererIcon(Gtk.CellRenderer): |
757 | 757 | self._prelit_stroke_color = None |
758 | 758 | self._palette_invoker = CellRendererInvoker() |
759 | 759 | |
760 | | GObject.GObject.__init__(self) |
| 760 | Gtk.CellRenderer.__init__(self) |
761 | 761 | |
762 | 762 | self._palette_invoker.attach_cell_renderer(tree_view, self) |
763 | 763 | |
… |
… |
class CellRendererIcon(Gtk.CellRenderer): |
879 | 879 | return False |
880 | 880 | |
881 | 881 | def do_render(self, cr, widget, background_area, cell_area, flags): |
| 882 | context = widget.get_style_context() |
| 883 | context.save() |
| 884 | context.add_class("sugar-icon-cell") |
| 885 | |
| 886 | # The context will have prelight state if the mouse pointer is |
| 887 | # in the entire row, but we want that state if the pointer is |
| 888 | # in this cell only: |
| 889 | if flags & Gtk.CellRendererState.PRELIT: |
| 890 | if not self._is_prelit(widget): |
| 891 | context.set_state(Gtk.StateFlags.NORMAL) |
| 892 | |
| 893 | Gtk.render_background(context, cr, background_area.x, background_area.y, |
| 894 | background_area.width, background_area.height) |
| 895 | |
| 896 | Gtk.render_frame(context, cr, background_area.x, background_area.y, |
| 897 | background_area.width, background_area.height) |
| 898 | |
882 | 899 | if self._xo_color is not None: |
883 | 900 | stroke_color = self._xo_color.get_stroke_color() |
884 | 901 | fill_color = self._xo_color.get_fill_color() |