]> Pileus Git - ~andy/gtk/blobdiff - gtk/deprecated/gtkstyle.c
Fix opacity group hack
[~andy/gtk] / gtk / deprecated / gtkstyle.c
index 16e3ce4542cfead8853aa2d307781da31469f1b6..c7ea8159eaca6148b07c64650afae0388e5aca32 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,63 @@ set_color (GtkStyle        *style,
       break;
     }
 
-  if (color && color->alpha > 0.01)
+  if (!color)
+    return FALSE;
+
+  if (!(color->alpha > 0.01))
     {
-      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 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))
+    {
+      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);
     }
 }
 
@@ -3983,7 +4015,23 @@ gtk_paint_spinner (GtkStyle           *style,
   cairo_restore (cr);
 }
 
-static GtkStyle        *gtk_default_style = NULL;
+static GtkStyle *
+gtk_widget_get_default_style_for_screen (GdkScreen *screen)
+{
+  GtkStyle *default_style;
+
+  default_style = g_object_get_data (G_OBJECT (screen), "gtk-legacy-default-style");
+  if (default_style == NULL)
+    {
+      default_style = gtk_style_new ();
+      g_object_set_data_full (G_OBJECT (screen),
+                              I_("gtk-legacy-default-style"),
+                              default_style,
+                              g_object_unref);
+    }
+
+  return default_style;
+}
 
 /**
  * gtk_widget_get_default_style:
@@ -3997,16 +4045,23 @@ static GtkStyle        *gtk_default_style = NULL;
  *     gtk_css_provider_get_default() to obtain a #GtkStyleProvider
  *     with the default widget style information.
  */
-GtkStyle*
+GtkStyle *
 gtk_widget_get_default_style (void)
 {
-  if (!gtk_default_style)
+  static GtkStyle *default_style = NULL;
+  GtkStyle *style = NULL;
+  GdkScreen *screen = gdk_screen_get_default ();
+
+  if (screen)
+    style = gtk_widget_get_default_style_for_screen (screen);
+  else
     {
-      gtk_default_style = gtk_style_new ();
-      g_object_ref (gtk_default_style);
+      if (default_style == NULL)
+        default_style = gtk_style_new ();
+      style = default_style;
     }
 
-  return gtk_default_style;
+  return style;
 }
 
 /**