CellRendererIcon: add prelight state and render background - SL #3989

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 <manuq@laptop.org>
Acked-by: Simon Schampijer <simon@laptop.org>
master
Manuel Quiñones 12 years ago
parent 63a34191b1
commit f5b96e1fbd

@ -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()

Loading…
Cancel
Save