]> Pileus Git - ~andy/gtk/commitdiff
GtkStyleProvider: Add GtkStateFlags parameter to get_style_property().
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 30 Nov 2010 01:14:00 +0000 (02:14 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Sat, 4 Dec 2010 14:39:51 +0000 (15:39 +0100)
Widget style properties can now have different values depending on the
current state.

gtk/gtkcssprovider.c
gtk/gtkstylecontext.c
gtk/gtkstylecontext.h
gtk/gtkstyleprovider.c
gtk/gtkstyleprovider.h
gtk/gtkwidget.c

index 2e5b2a99b749704329112797f8e4f1a5ae3c54c6..bd9633295d6052e4a44134dbb84b88399b048f73 100644 (file)
@@ -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;
 
index 35d7eee06b68dc04dda95a52d7b323ab9bd18219..c458c244b4dca5e354d70500fefdfcf91ed0e369 100644 (file)
@@ -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);
 
index 2868c85a8cfea5a9ce0634ee2155ff07ed4427c1..b2dd734d1055400e26495aba07b8bcac3bb67098 100644 (file)
@@ -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,
index 76257ba5e0be440b4c5160ca6fc790abf4fcc3a6..8ed0d975ca8c611ba74a48b33e6f02e7b79fd632 100644 (file)
@@ -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);
 }
 
 /**
index a920256d915fa3473546a83d3cda3a2b2f1cfa3e..31e7b42293514c86f08b8d244500554886e4b7c7 100644 (file)
@@ -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);
 
index d84e9be5e5d0d2b26b27340fb1dd93d511e72698..7c748c4cebb513cc6f66fcece4317e0654aa95e6 100644 (file)
@@ -11372,11 +11372,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
        */
@@ -11410,12 +11413,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)
@@ -11440,7 +11445,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)