]> Pileus Git - ~andy/gtk/commitdiff
gtkstyle: add a gtkstyle-fallback style class for RC colors
authorCosimo Cecchi <cosimoc@gnome.org>
Thu, 28 Jun 2012 22:09:33 +0000 (18:09 -0400)
committerCosimo Cecchi <cosimoc@gnome.org>
Mon, 2 Jul 2012 14:44:40 +0000 (10:44 -0400)
As an addition to 10423726709539724be0ea19bed76ba4331af774, themes might
want to avoid using the hardcoded GTK defaults for legacy GtkStyle
values. Add a gtkstyle-fallback style class that can be used by themes
to tweak the legacy GtkStyle defaults.

https://bugzilla.gnome.org/show_bug.cgi?id=679092

gtk/deprecated/gtkstyle.c

index 16e3ce4542cfead8853aa2d307781da31469f1b6..d6ea17e80a48ec5fbdbbe35513449e67e7055d87 100644 (file)
@@ -617,34 +617,16 @@ gtk_style_get_property (GObject      *object,
     }
 }
 
-static void
-set_color (GtkStyle        *style,
-           GtkStyleContext *context,
-           GtkStateType     state,
-           GtkRcFlags       prop)
+static gboolean
+set_color_from_context (GtkStyle *style,
+                        GtkStateType state,
+                        GtkStyleContext *context,
+                        GtkStateFlags flags,
+                        GtkRcFlags prop)
 {
-  GtkStateFlags flags;
   GdkRGBA *color = NULL;
   GdkColor *dest = { 0 }; /* Shut up gcc */
 
-  switch (state)
-    {
-    case GTK_STATE_ACTIVE:
-      flags = GTK_STATE_FLAG_ACTIVE;
-      break;
-    case GTK_STATE_PRELIGHT:
-      flags = GTK_STATE_FLAG_PRELIGHT;
-      break;
-    case GTK_STATE_SELECTED:
-      flags = GTK_STATE_FLAG_SELECTED;
-      break;
-    case GTK_STATE_INSENSITIVE:
-      flags = GTK_STATE_FLAG_INSENSITIVE;
-      break;
-    default:
-      flags = 0;
-    }
-
   switch (prop)
     {
     case GTK_RC_BG:
@@ -673,13 +655,57 @@ set_color (GtkStyle        *style,
       break;
     }
 
-  if (color && color->alpha > 0.01)
+  if (!color || !(color->alpha > 0.01))
+    return FALSE;
+
+  dest->pixel = 0;
+  dest->red = CLAMP ((guint) (color->red * 65535), 0, 65535);
+  dest->green = CLAMP ((guint) (color->green * 65535), 0, 65535);
+  dest->blue = CLAMP ((guint) (color->blue * 65535), 0, 65535);
+  gdk_rgba_free (color);
+
+  return TRUE;
+}
+
+static void
+set_color (GtkStyle        *style,
+           GtkStyleContext *context,
+           GtkStateType     state,
+           GtkRcFlags       prop)
+{
+  GtkStateFlags flags;
+
+  switch (state)
+    {
+    case GTK_STATE_ACTIVE:
+      flags = GTK_STATE_FLAG_ACTIVE;
+      break;
+    case GTK_STATE_PRELIGHT:
+      flags = GTK_STATE_FLAG_PRELIGHT;
+      break;
+    case GTK_STATE_SELECTED:
+      flags = GTK_STATE_FLAG_SELECTED;
+      break;
+    case GTK_STATE_INSENSITIVE:
+      flags = GTK_STATE_FLAG_INSENSITIVE;
+      break;
+    default:
+      flags = 0;
+    }
+
+  /* Try to fill in the values from the associated GtkStyleContext.
+   * Since fully-transparent black is a very common default (e.g. for 
+   * background-color properties), and we must store the result in a GdkColor
+   * to retain API compatibility, in case the fetched color is fully transparent
+   * we give themes a fallback style class they can style, before using the
+   * hardcoded default values.
+   */
+  if (!set_color_from_context (style, state, context, flags, prop))
     {
-      dest->pixel = 0;
-      dest->red = CLAMP ((guint) (color->red * 65535), 0, 65535);
-      dest->green = CLAMP ((guint) (color->green * 65535), 0, 65535);
-      dest->blue = CLAMP ((guint) (color->blue * 65535), 0, 65535);
-      gdk_rgba_free (color);
+      gtk_style_context_save (context);
+      gtk_style_context_add_class (context, "gtkstyle-fallback");
+      set_color_from_context (style, state, context, flags, prop);
+      gtk_style_context_restore (context);
     }
 }