Make GtkCellRendererToggle use GtkStyleContext

This commit is contained in:
Carlos Garnacho 2011-01-12 21:27:25 +01:00
parent 7c2f35d7c1
commit 9b091ae330

View File

@ -331,12 +331,13 @@ gtk_cell_renderer_toggle_render (GtkCellRenderer *cell,
{ {
GtkCellRendererToggle *celltoggle = GTK_CELL_RENDERER_TOGGLE (cell); GtkCellRendererToggle *celltoggle = GTK_CELL_RENDERER_TOGGLE (cell);
GtkCellRendererTogglePrivate *priv = celltoggle->priv; GtkCellRendererTogglePrivate *priv = celltoggle->priv;
GtkStyleContext *context;
gint width, height; gint width, height;
gint x_offset, y_offset; gint x_offset, y_offset;
gint xpad, ypad; gint xpad, ypad;
GtkShadowType shadow; GtkStateFlags state;
GtkStateType state = 0;
context = gtk_widget_get_style_context (widget);
gtk_cell_renderer_toggle_get_size (cell, widget, cell_area, gtk_cell_renderer_toggle_get_size (cell, widget, cell_area,
&x_offset, &y_offset, &x_offset, &y_offset,
&width, &height); &width, &height);
@ -347,57 +348,42 @@ gtk_cell_renderer_toggle_render (GtkCellRenderer *cell,
if (width <= 0 || height <= 0) if (width <= 0 || height <= 0)
return; return;
if (priv->inconsistent) if (!priv->activatable)
shadow = GTK_SHADOW_ETCHED_IN; state = GTK_STATE_FLAG_INSENSITIVE;
else else
shadow = priv->active ? GTK_SHADOW_IN : GTK_SHADOW_OUT; state = gtk_cell_renderer_get_state (cell, widget, flags);
if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE || if (priv->inconsistent)
!gtk_cell_renderer_get_sensitive (cell)) state |= GTK_STATE_FLAG_INCONSISTENT;
{ else if (priv->active)
state = GTK_STATE_INSENSITIVE; state |= GTK_STATE_FLAG_ACTIVE;
}
else if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
{
if (gtk_widget_has_focus (widget))
state = GTK_STATE_SELECTED;
else
state = GTK_STATE_ACTIVE;
}
else
{
if (priv->activatable)
state = GTK_STATE_NORMAL;
else
state = GTK_STATE_INSENSITIVE;
}
cairo_save (cr); cairo_save (cr);
gdk_cairo_rectangle (cr, cell_area); gdk_cairo_rectangle (cr, cell_area);
cairo_clip (cr); cairo_clip (cr);
gtk_style_context_save (context);
gtk_style_context_set_state (context, state);
if (priv->radio) if (priv->radio)
{ {
gtk_paint_option (gtk_widget_get_style (widget), gtk_style_context_add_class (context, GTK_STYLE_CLASS_RADIO);
cr, gtk_render_option (context, cr,
state, shadow, cell_area->x + x_offset + xpad,
widget, "cellradio", cell_area->y + y_offset + ypad,
cell_area->x + x_offset + xpad, width, height);
cell_area->y + y_offset + ypad,
width, height);
} }
else else
{ {
gtk_paint_check (gtk_widget_get_style (widget), gtk_style_context_add_class (context, GTK_STYLE_CLASS_CHECK);
cr, gtk_render_check (context, cr,
state, shadow, cell_area->x + x_offset + xpad,
widget, "cellcheck", cell_area->y + y_offset + ypad,
cell_area->x + x_offset + xpad, width, height);
cell_area->y + y_offset + ypad,
width, height);
} }
gtk_style_context_restore (context);
cairo_restore (cr); cairo_restore (cr);
} }