[gtk+/cellarea-style-transitions: 6/9] cellrenderertoggle: Implement methods to handle animations



commit f26646be37a99f73847b74ffdfb8e1534fdc2323
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed May 11 13:41:14 2011 +0200

    cellrenderertoggle: Implement methods to handle animations
    
    By implementing get_current_state() and apply_style(), GtkCellArea
    has all the necessary information to handle state transitions in
    toggle cell renderers.

 gtk/gtkcellrenderertoggle.c |   38 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 37 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkcellrenderertoggle.c b/gtk/gtkcellrenderertoggle.c
index 2c8debd..b66c606 100644
--- a/gtk/gtkcellrenderertoggle.c
+++ b/gtk/gtkcellrenderertoggle.c
@@ -67,6 +67,10 @@ static gboolean gtk_cell_renderer_toggle_activate  (GtkCellRenderer            *
 						    const GdkRectangle         *cell_area,
 						    GtkCellRendererState        flags);
 
+static GtkStateFlags gtk_cell_renderer_toggle_get_current_state (GtkCellRenderer *cell);
+static void          gtk_cell_renderer_toggle_apply_style       (GtkCellRenderer *cell,
+                                                                 GtkStyleContext *context);
+
 
 enum {
   TOGGLED,
@@ -133,7 +137,9 @@ gtk_cell_renderer_toggle_class_init (GtkCellRendererToggleClass *class)
   cell_class->get_size = gtk_cell_renderer_toggle_get_size;
   cell_class->render = gtk_cell_renderer_toggle_render;
   cell_class->activate = gtk_cell_renderer_toggle_activate;
-  
+  cell_class->get_current_state = gtk_cell_renderer_toggle_get_current_state;
+  cell_class->apply_style = gtk_cell_renderer_toggle_apply_style;
+
   g_object_class_install_property (object_class,
 				   PROP_ACTIVE,
 				   g_param_spec_boolean ("active",
@@ -423,6 +429,36 @@ gtk_cell_renderer_toggle_activate (GtkCellRenderer      *cell,
   return FALSE;
 }
 
+static GtkStateFlags
+gtk_cell_renderer_toggle_get_current_state (GtkCellRenderer *cell)
+{
+  GtkCellRendererTogglePrivate *priv;
+  GtkStateFlags state = 0;
+
+  priv = GTK_CELL_RENDERER_TOGGLE (cell)->priv;
+
+  if (priv->inconsistent)
+    state |= GTK_STATE_FLAG_INCONSISTENT;
+  else if (priv->active)
+    state |= GTK_STATE_FLAG_ACTIVE;
+
+  return state;
+}
+
+static void
+gtk_cell_renderer_toggle_apply_style (GtkCellRenderer *cell,
+                                      GtkStyleContext *context)
+{
+  GtkCellRendererTogglePrivate *priv;
+
+  priv = GTK_CELL_RENDERER_TOGGLE (cell)->priv;
+
+  if (priv->radio)
+    gtk_style_context_add_class (context, GTK_STYLE_CLASS_RADIO);
+  else
+    gtk_style_context_add_class (context, GTK_STYLE_CLASS_CHECK);
+}
+
 /**
  * gtk_cell_renderer_toggle_set_radio:
  * @toggle: a #GtkCellRendererToggle



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]