[gtk+/gtk-style-context: 527/533] GtkStyleProvider: Add GtkStateFlags parameter to get_style_property().



commit 3f561c6448db4b0a924687f97c68eec8b4b9d5a3
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Nov 30 02:14:00 2010 +0100

    GtkStyleProvider: Add GtkStateFlags parameter to get_style_property().
    
    Widget style properties can now have different values depending on the
    current state.

 gtk/gtkcssprovider.c   |    5 ++++-
 gtk/gtkstylecontext.c  |   34 +++++++++++++++++++++++-----------
 gtk/gtkstylecontext.h  |    1 +
 gtk/gtkstyleprovider.c |    4 +++-
 gtk/gtkstyleprovider.h |    2 ++
 gtk/gtkwidget.c        |    9 +++++++--
 6 files changed, 40 insertions(+), 15 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 2e5b2a9..bd96332 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1340,6 +1340,7 @@ gtk_css_provider_get_style (GtkStyleProvider *provider,
 static gboolean
 gtk_css_provider_get_style_property (GtkStyleProvider *provider,
                                      GtkWidgetPath    *path,
+                                     GtkStateFlags     state,
                                      GParamSpec       *pspec,
                                      GValue           *value)
 {
@@ -1362,7 +1363,9 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
       info = &g_array_index (priority_info, StylePriorityInfo, i);
       val = g_hash_table_lookup (info->style, prop_name);
 
-      if (val)
+      if (val &&
+          (info->state & state) != 0 &&
+          (info->state & ~(state)) == 0)
         {
           const gchar *val_str;
 
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 35d7eee..c458c24 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -427,6 +427,7 @@ struct PropertyValue
 {
   GType       widget_type;
   GParamSpec *pspec;
+  GtkStateFlags state;
   GValue      value;
 };
 
@@ -2221,15 +2222,22 @@ style_property_values_cmp (gconstpointer bsearch_node1,
   const PropertyValue *val1 = bsearch_node1;
   const PropertyValue *val2 = bsearch_node2;
 
-  if (val1->widget_type == val2->widget_type)
-    return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
-  else
+  if (val1->widget_type != val2->widget_type)
     return val1->widget_type < val2->widget_type ? -1 : 1;
+
+  if (val1->pspec != val2->pspec)
+    return val1->pspec < val2->pspec ? -1 : 1;
+
+  if (val1->state != val2->state)
+    return val1->state < val2->state ? -1 : 1;
+
+  return 0;
 }
 
 const GValue *
 _gtk_style_context_peek_style_property (GtkStyleContext *context,
                                         GType            widget_type,
+                                        GtkStateFlags    state,
                                         GParamSpec      *pspec)
 {
   GtkStyleContextPrivate *priv;
@@ -2242,6 +2250,7 @@ _gtk_style_context_peek_style_property (GtkStyleContext *context,
   data = style_data_lookup (context);
 
   key.widget_type = widget_type;
+  key.state = state;
   key.pspec = pspec;
 
   /* need value cache array */
@@ -2293,8 +2302,8 @@ _gtk_style_context_peek_style_property (GtkStyleContext *context,
             global = global->prev;
 
           if (gtk_style_provider_get_style_property (provider_data->provider,
-                                                     priv->widget_path, pspec,
-                                                     &pcache->value))
+                                                     priv->widget_path, state,
+                                                     pspec, &pcache->value))
             {
               /* Resolve symbolic colors to GdkColor/GdkRGBA */
               if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
@@ -2358,6 +2367,7 @@ gtk_style_context_get_style_property (GtkStyleContext *context,
 {
   GtkStyleContextPrivate *priv;
   GtkWidgetClass *widget_class;
+  GtkStateFlags state;
   GParamSpec *pspec;
   const GValue *peek_value;
   GType widget_type;
@@ -2386,9 +2396,9 @@ gtk_style_context_get_style_property (GtkStyleContext *context,
       return;
     }
 
-  peek_value = _gtk_style_context_peek_style_property (context,
-                                                       widget_type,
-                                                       pspec);
+  state = gtk_style_context_get_state (context);
+  peek_value = _gtk_style_context_peek_style_property (context, widget_type,
+                                                       state, pspec);
 
   if (G_VALUE_TYPE (value) == G_VALUE_TYPE (peek_value))
     g_value_copy (peek_value, value);
@@ -2417,6 +2427,7 @@ gtk_style_context_get_style_valist (GtkStyleContext *context,
 {
   GtkStyleContextPrivate *priv;
   const gchar *prop_name;
+  GtkStateFlags state;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
 
@@ -2426,6 +2437,8 @@ gtk_style_context_get_style_valist (GtkStyleContext *context,
   if (!priv->widget_path)
     return;
 
+  state = gtk_style_context_get_state (context);
+
   while (prop_name)
     {
       GtkWidgetClass *widget_class;
@@ -2449,9 +2462,8 @@ gtk_style_context_get_style_valist (GtkStyleContext *context,
           continue;
         }
 
-      peek_value = _gtk_style_context_peek_style_property (context,
-                                                           widget_type,
-                                                           pspec);
+      peek_value = _gtk_style_context_peek_style_property (context, widget_type,
+                                                           state, pspec);
 
       G_VALUE_LCOPY (peek_value, args, 0, &error);
 
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index 2868c85..b2dd734 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -424,6 +424,7 @@ void gtk_style_context_pop_animatable_region  (GtkStyleContext *context);
 /* Semi-private API */
 const GValue * _gtk_style_context_peek_style_property (GtkStyleContext *context,
                                                        GType            widget_type,
+                                                       GtkStateFlags    state,
                                                        GParamSpec      *pspec);
 void           _gtk_style_context_invalidate_animation_areas (GtkStyleContext *context);
 void           _gtk_style_context_coalesce_animation_areas   (GtkStyleContext *context,
diff --git a/gtk/gtkstyleprovider.c b/gtk/gtkstyleprovider.c
index 76257ba..8ed0d97 100644
--- a/gtk/gtkstyleprovider.c
+++ b/gtk/gtkstyleprovider.c
@@ -86,6 +86,7 @@ gtk_style_provider_get_style (GtkStyleProvider *provider,
  * gtk_style_provider_get_style_property:
  * @provider: a #GtkStyleProvider
  * @path: #GtkWidgetPath to query
+ * @state: state to query the style property for
  * @pspec: The #GParamSpec to query
  * @value: (out): return location for the property value
  *
@@ -97,6 +98,7 @@ gtk_style_provider_get_style (GtkStyleProvider *provider,
 gboolean
 gtk_style_provider_get_style_property (GtkStyleProvider *provider,
                                        GtkWidgetPath    *path,
+                                       GtkStateFlags     state,
                                        GParamSpec       *pspec,
                                        GValue           *value)
 {
@@ -113,7 +115,7 @@ gtk_style_provider_get_style_property (GtkStyleProvider *provider,
   if (!iface->get_style_property)
     return FALSE;
 
-  return iface->get_style_property (provider, path, pspec, value);
+  return iface->get_style_property (provider, path, state, pspec, value);
 }
 
 /**
diff --git a/gtk/gtkstyleprovider.h b/gtk/gtkstyleprovider.h
index a920256..31e7b42 100644
--- a/gtk/gtkstyleprovider.h
+++ b/gtk/gtkstyleprovider.h
@@ -97,6 +97,7 @@ struct _GtkStyleProviderIface
 
   gboolean (* get_style_property) (GtkStyleProvider *provider,
                                    GtkWidgetPath    *path,
+                                   GtkStateFlags     state,
                                    GParamSpec       *pspec,
                                    GValue           *value);
 
@@ -111,6 +112,7 @@ GtkStyleProperties *gtk_style_provider_get_style (GtkStyleProvider *provider,
 
 gboolean gtk_style_provider_get_style_property (GtkStyleProvider *provider,
                                                 GtkWidgetPath    *path,
+                                                GtkStateFlags     state,
                                                 GParamSpec       *pspec,
                                                 GValue           *value);
 
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 58f6995..5f4d559 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -11402,11 +11402,14 @@ gtk_widget_style_get_property (GtkWidget   *widget,
     {
       GtkStyleContext *context;
       const GValue *peek_value;
+      GtkStateFlags state;
 
       context = gtk_widget_get_style_context (widget);
+      state = gtk_widget_get_state_flags (widget);
+
       peek_value = _gtk_style_context_peek_style_property (context,
                                                            G_OBJECT_TYPE (widget),
-                                                           pspec);
+                                                           state, pspec);
 
       /* auto-conversion of the caller's value type
        */
@@ -11440,12 +11443,14 @@ gtk_widget_style_get_valist (GtkWidget   *widget,
 			     va_list      var_args)
 {
   GtkStyleContext *context;
+  GtkStateFlags state;
   const gchar *name;
 
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
   g_object_ref (widget);
   context = gtk_widget_get_style_context (widget);
+  state = gtk_widget_get_state_flags (widget);
 
   name = first_property_name;
   while (name)
@@ -11470,7 +11475,7 @@ gtk_widget_style_get_valist (GtkWidget   *widget,
 
       peek_value = _gtk_style_context_peek_style_property (context,
                                                            G_OBJECT_TYPE (widget),
-                                                           pspec);
+                                                           state, pspec);
 
       G_VALUE_LCOPY (peek_value, var_args, 0, &error);
       if (error)



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