]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcellrenderertoggle.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkcellrenderertoggle.c
index 177cafd32ab63e9fee364ea157f2b8d14d2f99d3..f94ff2a71a04b09382fb2c7b698bd7712cff0034 100644 (file)
@@ -12,9 +12,7 @@
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
 #include "gtkmarshalers.h"
 #include "gtkprivate.h"
 #include "gtktreeprivate.h"
+#include "a11y/gtkbooleancellaccessible.h"
+
+
+/**
+ * SECTION:gtkcellrenderertoggle
+ * @Short_description: Renders a toggle button in a cell
+ * @Title: GtkCellRendererToggle
+ *
+ * #GtkCellRendererToggle renders a toggle button in a cell. The
+ * button is drawn as a radio or a checkbutton, depending on the
+ * #GtkCellRendererToggle:radio property.
+ * When activated, it emits the #GtkCellRendererToggle::toggled signal.
+ */
 
 
 static void gtk_cell_renderer_toggle_get_property  (GObject                    *object,
@@ -70,7 +81,7 @@ enum {
   PROP_INDICATOR_SIZE
 };
 
-#define TOGGLE_WIDTH 13
+#define TOGGLE_WIDTH 16
 
 static guint toggle_cell_signals[LAST_SIGNAL] = { 0 };
 
@@ -184,6 +195,8 @@ gtk_cell_renderer_toggle_class_init (GtkCellRendererToggleClass *class)
                  G_TYPE_STRING);
 
   g_type_class_add_private (object_class, sizeof (GtkCellRendererTogglePrivate));
+
+  gtk_cell_renderer_class_set_accessible_type (cell_class, GTK_TYPE_BOOLEAN_CELL_ACCESSIBLE);
 }
 
 static void
@@ -331,12 +344,13 @@ gtk_cell_renderer_toggle_render (GtkCellRenderer      *cell,
 {
   GtkCellRendererToggle *celltoggle = GTK_CELL_RENDERER_TOGGLE (cell);
   GtkCellRendererTogglePrivate *priv = celltoggle->priv;
+  GtkStyleContext *context;
   gint width, height;
   gint x_offset, y_offset;
   gint xpad, ypad;
-  GtkShadowType shadow;
-  GtkStateType state = 0;
+  GtkStateFlags state;
 
+  context = gtk_widget_get_style_context (widget);
   gtk_cell_renderer_toggle_get_size (cell, widget, cell_area,
                                     &x_offset, &y_offset,
                                     &width, &height);
@@ -347,57 +361,44 @@ gtk_cell_renderer_toggle_render (GtkCellRenderer      *cell,
   if (width <= 0 || height <= 0)
     return;
 
-  if (priv->inconsistent)
-    shadow = GTK_SHADOW_ETCHED_IN;
-  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 ||
-      !gtk_cell_renderer_get_sensitive (cell))
-    {
-      state = GTK_STATE_INSENSITIVE;
-    }
-  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;
-    }
+  if (!priv->activatable)
+    state |= GTK_STATE_FLAG_INSENSITIVE;
+
+  state &= ~(GTK_STATE_FLAG_INCONSISTENT | GTK_STATE_FLAG_ACTIVE);
+
+  if (priv->inconsistent)
+    state |= GTK_STATE_FLAG_INCONSISTENT;
+  else if (priv->active)
+    state |= GTK_STATE_FLAG_ACTIVE;
 
   cairo_save (cr);
 
   gdk_cairo_rectangle (cr, cell_area);
   cairo_clip (cr);
 
+  gtk_style_context_save (context);
+  gtk_style_context_set_state (context, state);
+
   if (priv->radio)
     {
-      gtk_paint_option (gtk_widget_get_style (widget),
-                              cr,
-                              state, shadow,
-                              widget, "cellradio",
-                              cell_area->x + x_offset + xpad,
-                              cell_area->y + y_offset + ypad,
-                              width, height);
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_RADIO);
+      gtk_render_option (context, cr,
+                         cell_area->x + x_offset + xpad,
+                         cell_area->y + y_offset + ypad,
+                         width, height);
     }
   else
     {
-      gtk_paint_check (gtk_widget_get_style (widget),
-                             cr,
-                             state, shadow,
-                             widget, "cellcheck",
-                             cell_area->x + x_offset + xpad,
-                             cell_area->y + y_offset + ypad,
-                             width, height);
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_CHECK);
+      gtk_render_check (context, cr,
+                        cell_area->x + x_offset + xpad,
+                        cell_area->y + y_offset + ypad,
+                        width, height);
     }
 
+  gtk_style_context_restore (context);
   cairo_restore (cr);
 }