[gtk+/gtk-style-context: 18/206] GtkStyleContext: Add getters and setter for state.



commit ea4b5413b70f53a7c86b694d3c611ece7fd538e6
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Mar 10 01:02:46 2010 +0100

    GtkStyleContext: Add getters and setter for state.

 gtk/gtkstylecontext.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkstylecontext.h |    7 ++++++
 2 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index a37226a..85727e3 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -40,6 +40,7 @@ struct GtkStyleContextPrivate
 {
   GList *providers;
   GtkStyleSet *store;
+  GtkStateFlags state_flags;
 };
 
 #define GTK_STYLE_CONTEXT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_STYLE_CONTEXT, GtkStyleContextPrivate))
@@ -270,5 +271,59 @@ gtk_style_context_get (GtkStyleContext *context,
   va_end (args);
 }
 
+void
+gtk_style_context_set_state (GtkStyleContext *context,
+                             GtkStateFlags    flags)
+{
+  GtkStyleContextPrivate *priv;
+
+  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+
+  priv = GTK_STYLE_CONTEXT_GET_PRIVATE (context);
+  priv->state_flags = flags;
+}
+
+GtkStateFlags
+gtk_style_context_get_state (GtkStyleContext *context)
+{
+  GtkStyleContextPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), 0);
+
+  priv = GTK_STYLE_CONTEXT_GET_PRIVATE (context);
+  return priv->state_flags;
+}
+
+gboolean
+gtk_style_context_is_state_set (GtkStyleContext *context,
+                                GtkStateType     state)
+{
+  GtkStyleContextPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
+
+  priv = GTK_STYLE_CONTEXT_GET_PRIVATE (context);
+
+  switch (state)
+    {
+    case GTK_STATE_NORMAL:
+      return priv->state_flags == 0;
+    case GTK_STATE_ACTIVE:
+      return priv->state_flags & GTK_STATE_FLAG_ACTIVE;
+    case GTK_STATE_PRELIGHT:
+      return priv->state_flags & GTK_STATE_FLAG_PRELIGHT;
+    case GTK_STATE_SELECTED:
+      return priv->state_flags & GTK_STATE_FLAG_SELECTED;
+    case GTK_STATE_INSENSITIVE:
+      return priv->state_flags & GTK_STATE_FLAG_INSENSITIVE;
+    case GTK_STATE_INCONSISTENT:
+      return priv->state_flags & GTK_STATE_FLAG_INCONSISTENT;
+    case GTK_STATE_FOCUSED:
+      return priv->state_flags & GTK_STATE_FLAG_FOCUSED;
+    default:
+      return FALSE;
+    }
+}
+
 #define __GTK_STYLE_CONTEXT_C__
 #include "gtkaliasdef.c"
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index 37d4f15..edc6732 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -65,6 +65,13 @@ void gtk_style_context_get          (GtkStyleContext *context,
                                      GtkStateType     state,
                                      ...) G_GNUC_NULL_TERMINATED;
 
+void          gtk_style_context_set_state    (GtkStyleContext *context,
+                                              GtkStateFlags    flags);
+GtkStateFlags gtk_style_context_get_state    (GtkStyleContext *context);
+
+gboolean      gtk_style_context_is_state_set (GtkStyleContext *context,
+                                              GtkStateType     state);
+
 G_END_DECLS
 
 #endif /* __GTK_STYLE_CONTEXT_H__ */



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