[gtk+] docs: Reinstate pixbufs section in GDK docs



commit ded14b256202d8792629b88874d934638762cee3
Author: Benjamin Otte <otte redhat com>
Date:   Thu Dec 9 11:13:41 2010 +0100

    docs: Reinstate pixbufs section in GDK docs
    
    It was accidentally removed in 0775b0a85818e14d12087f33977e14efec6a058a

 docs/reference/gdk/gdk-docs.sgml |    1 +
 gtk/gtkgradient.c                |   23 ++---
 gtk/gtkgradient.h                |    6 +-
 gtk/gtkicontheme.c               |  179 ++++++++++++++------------------------
 gtk/gtkinfobar.c                 |   64 ++------------
 gtk/gtkstyle.c                   |   26 ++----
 gtk/gtkstyle.h                   |    2 +-
 gtk/gtkstylecontext.c            |   92 +++++++++++++------
 gtk/gtkstylecontext.h            |    8 +-
 gtk/gtkstyleproperties.c         |   32 ++-----
 gtk/gtksymboliccolor.c           |   57 +++++-------
 gtk/gtksymboliccolor.h           |    2 +-
 gtk/gtkthemingengine.c           |   10 +--
 gtk/gtkthemingengine.h           |    6 +-
 14 files changed, 202 insertions(+), 306 deletions(-)
---
diff --git a/docs/reference/gdk/gdk-docs.sgml b/docs/reference/gdk/gdk-docs.sgml
index c77b8be..ed18e2f 100644
--- a/docs/reference/gdk/gdk-docs.sgml
+++ b/docs/reference/gdk/gdk-docs.sgml
@@ -22,6 +22,7 @@
     <xi:include href="xml/gdkdisplaymanager.xml" />
     <xi:include href="xml/gdkscreen.xml" />
     <xi:include href="xml/regions.xml" />
+    <xi:include href="xml/pixbufs.xml" />
     <xi:include href="xml/colors.xml" />
     <xi:include href="xml/rgba_colors.xml" />
     <xi:include href="xml/visuals.xml" />
diff --git a/gtk/gtkgradient.c b/gtk/gtkgradient.c
index a19b8fe..1ebc62d 100644
--- a/gtk/gtkgradient.c
+++ b/gtk/gtkgradient.c
@@ -226,7 +226,6 @@ gtk_gradient_unref (GtkGradient *gradient)
  * gtk_gradient_resolve:
  * @gradient: a #GtkGradient
  * @props: #GtkStyleProperties to use when resolving named colors
- * @resolved_gradient: (out): return location for the resolved pattern
  *
  * If @gradient is resolvable, @resolved_gradient will be filled in
  * with the resolved gradient as a cairo_pattern_t, and %TRUE will
@@ -234,21 +233,20 @@ gtk_gradient_unref (GtkGradient *gradient)
  * due to it being defined on top of a named color that doesn't
  * exist in @props.
  *
- * Returns: %TRUE if the gradient has been resolved
+ * Returns: the resolved pattern. Use cairo_pattern_destroy()
+ *   after use.
  *
  * Since: 3.0
  **/
-gboolean
+cairo_pattern_t *
 gtk_gradient_resolve (GtkGradient         *gradient,
-                      GtkStyleProperties  *props,
-                      cairo_pattern_t    **resolved_gradient)
+                      GtkStyleProperties  *props)
 {
   cairo_pattern_t *pattern;
   guint i;
 
-  g_return_val_if_fail (gradient != NULL, FALSE);
-  g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
-  g_return_val_if_fail (resolved_gradient != NULL, FALSE);
+  g_return_val_if_fail (gradient != NULL, NULL);
+  g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), NULL);
 
   if (gradient->radius0 == 0 && gradient->radius1 == 0)
     pattern = cairo_pattern_create_linear (gradient->x0, gradient->y0,
@@ -266,17 +264,12 @@ gtk_gradient_resolve (GtkGradient         *gradient,
 
       stop = &g_array_index (gradient->stops, ColorStop, i);
 
-      if (!gtk_symbolic_color_resolve (stop->color, props, &color))
-        {
-          cairo_pattern_destroy (pattern);
-          return FALSE;
-        }
+      gtk_symbolic_color_resolve (stop->color, props, &color);
 
       cairo_pattern_add_color_stop_rgba (pattern, stop->offset,
                                          color.red, color.green,
                                          color.blue, color.alpha);
     }
 
-  *resolved_gradient = pattern;
-  return TRUE;
+  return pattern;
 }
diff --git a/gtk/gtkgradient.h b/gtk/gtkgradient.h
index f097c40..21cf6be 100644
--- a/gtk/gtkgradient.h
+++ b/gtk/gtkgradient.h
@@ -52,9 +52,9 @@ void          gtk_gradient_add_color_stop (GtkGradient         *gradient,
 GtkGradient * gtk_gradient_ref            (GtkGradient         *gradient);
 void          gtk_gradient_unref          (GtkGradient         *gradient);
 
-gboolean      gtk_gradient_resolve        (GtkGradient         *gradient,
-                                           GtkStyleProperties  *props,
-                                           cairo_pattern_t    **resolved_gradient);
+cairo_pattern_t *
+              gtk_gradient_resolve        (GtkGradient         *gradient,
+                                           GtkStyleProperties  *props);
 
 G_END_DECLS
 
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 2f41849..c90ec99 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -3060,16 +3060,7 @@ gtk_icon_info_load_icon (GtkIconInfo *icon_info,
 }
 
 static gchar *
-gdk_color_to_css (GdkColor *color)
-{
-  return g_strdup_printf ("rgb(%d,%d,%d)",
-                          color->red >> 8,
-                          color->green >> 8,
-                          color->blue >> 8);
-}
-
-static gchar *
-gdk_rgba_to_css (GdkRGBA *color)
+gdk_rgba_to_css (const GdkRGBA *color)
 {
   return g_strdup_printf ("rgba(%d,%d,%d,%f)",
                           (gint)(color->red * 255),
@@ -3078,41 +3069,40 @@ gdk_rgba_to_css (GdkRGBA *color)
                           color->alpha);
 }
 
+static char *
+_gtk_icon_info_color_to_css (const GdkRGBA *rgba,
+                             const char    *color_name)
+{
+  GdkRGBA color;
+
+  if (rgba)
+    return gdk_rgba_to_css (rgba);
+
+  gtk_style_context_lookup_default_color (color_name, &color);
+  return gdk_rgba_to_css (&color);
+}
+
 static GdkPixbuf *
-_gtk_icon_info_load_symbolic_internal (GtkIconInfo  *icon_info,
-                                       const gchar  *css_fg,
-                                       const gchar  *css_success,
-                                       const gchar  *css_warning,
-                                       const gchar  *css_error,
-                                       GError      **error)
+_gtk_icon_info_load_symbolic_internal (GtkIconInfo    *icon_info,
+                                       const GdkRGBA  *fg,
+                                       const GdkRGBA  *success_rgba,
+                                       const GdkRGBA  *warning_rgba,
+                                       const GdkRGBA  *error_rgba,
+                                       GError        **error)
 {
   GInputStream *stream;
   GdkPixbuf *pixbuf;
   gchar *data;
-  gchar *success, *warning, *err;
+  char *css_fg, *css_success, *css_warning, *css_error;
 
   /* css_fg can't possibly have failed, otherwise
    * that would mean we have a broken style */
-  g_return_val_if_fail (css_fg != NULL, NULL);
-
-  success = warning = err = NULL;
-
-  if (!css_success)
-    {
-      GdkColor success_default_color = { 0, 0x4e00, 0x9a00, 0x0600 };
-      success = gdk_color_to_css (&success_default_color);
-    }
-  if (!css_warning)
-    {
-      GdkColor warning_default_color = { 0, 0xf500, 0x7900, 0x3e00 };
-      warning = gdk_color_to_css (&warning_default_color);
-    }
-  if (!css_error)
-    {
-      GdkColor error_default_color = { 0, 0xcc00, 0x0000, 0x0000 };
-      err = gdk_color_to_css (&error_default_color);
-    }
+  g_return_val_if_fail (fg != NULL, NULL);
 
+  css_fg = _gtk_icon_info_color_to_css (fg, "color");
+  css_warning = _gtk_icon_info_color_to_css (warning_rgba, "warning_color");
+  css_error = _gtk_icon_info_color_to_css (error_rgba, "error_color");
+  css_success = _gtk_icon_info_color_to_css (success_rgba, "success_color");
 
   data = g_strconcat ("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
                       "<svg version=\"1.1\"\n"
@@ -3122,24 +3112,26 @@ _gtk_icon_info_load_symbolic_internal (GtkIconInfo  *icon_info,
                       "     height=\"16\">\n"
                       "  <style type=\"text/css\">\n"
                       "    rect,path {\n"
-                      "      fill: ", css_fg," !important;\n"
+                      "      fill: ", css_fg, " !important;\n"
                       "    }\n"
                       "    .warning {\n"
-                      "      fill: ", css_warning ? css_warning : warning," !important;\n"
+                      "      fill: ", css_warning, " !important;\n"
                       "    }\n"
                       "    .error {\n"
-                      "      fill: ", css_error ? css_error : err," !important;\n"
+                      "      fill: ", css_error, " !important;\n"
                       "    }\n"
                       "    .success {\n"
-                      "      fill: ", css_success ? css_success : success," !important;\n"
+                      "      fill: ", css_success, " !important;\n"
                       "    }\n"
                       "  </style>\n"
                       "  <xi:include href=\"", icon_info->filename, "\"/>\n"
                       "</svg>",
                       NULL);
-  g_free (warning);
-  g_free (err);
-  g_free (success);
+
+  g_free (css_fg);
+  g_free (css_warning);
+  g_free (css_error);
+  g_free (css_success);
 
   stream = g_memory_input_stream_new_from_data (data, -1, g_free);
   pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream,
@@ -3199,10 +3191,6 @@ gtk_icon_info_load_symbolic (GtkIconInfo  *icon_info,
                              GError      **error)
 {
   GdkPixbuf *pixbuf;
-  gchar *css_fg;
-  gchar *css_success;
-  gchar *css_warning;
-  gchar *css_error;
 
   g_return_val_if_fail (fg != NULL, NULL);
 
@@ -3217,27 +3205,10 @@ gtk_icon_info_load_symbolic (GtkIconInfo  *icon_info,
   if (was_symbolic)
     *was_symbolic = TRUE;
 
-  css_fg = gdk_rgba_to_string (fg);
-
-  css_success = css_warning = css_error = NULL;
-
-  if (warning_color)
-    css_warning = gdk_rgba_to_string (warning_color);
-
-  if (error_color)
-    css_error = gdk_rgba_to_string (error_color);
-
-  if (success_color)
-    css_success = gdk_rgba_to_string (success_color);
-
   pixbuf = _gtk_icon_info_load_symbolic_internal (icon_info,
-                                                  css_fg, css_success,
-                                                  css_warning, css_error,
+                                                  fg, success_color,
+                                                  warning_color, error_color,
                                                   error);
-  g_free (css_fg);
-  g_free (css_warning);
-  g_free (css_success);
-  g_free (css_error);
 
   return pixbuf;
 }
@@ -3271,9 +3242,7 @@ gtk_icon_info_load_symbolic_for_context (GtkIconInfo      *icon_info,
 {
   GdkPixbuf *pixbuf;
   GdkRGBA *color = NULL;
-  GdkRGBA rgba;
-  gchar *css_fg = NULL, *css_success;
-  gchar *css_warning, *css_error;
+  GdkRGBA success_color, warning_color, error_color;
   GtkStateFlags state;
 
   if (!icon_info->filename ||
@@ -3289,36 +3258,30 @@ gtk_icon_info_load_symbolic_for_context (GtkIconInfo      *icon_info,
 
   state = gtk_style_context_get_state (context);
   gtk_style_context_get (context, state, "color", &color, NULL);
-  if (color)
-    {
-      css_fg = gdk_rgba_to_css (color);
-      gdk_rgba_free (color);
-    }
-
-  css_success = css_warning = css_error = NULL;
-
-  if (gtk_style_context_lookup_color (context, "success_color", &rgba))
-    css_success = gdk_rgba_to_css (&rgba);
-
-  if (gtk_style_context_lookup_color (context, "warning_color", &rgba))
-    css_warning = gdk_rgba_to_css (&rgba);
-
-  if (gtk_style_context_lookup_color (context, "error_color", &rgba))
-    css_error = gdk_rgba_to_css (&rgba);
+  gtk_style_context_lookup_color (context, "success_color", &success_color);
+  gtk_style_context_lookup_color (context, "warning_color", &warning_color);
+  gtk_style_context_lookup_color (context, "error_color", &error_color);
 
   pixbuf = _gtk_icon_info_load_symbolic_internal (icon_info,
-                                                  css_fg, css_success,
-                                                  css_warning, css_error,
+                                                  color, &success_color,
+                                                  &warning_color, &error_color,
                                                   error);
 
-  g_free (css_fg);
-  g_free (css_success);
-  g_free (css_warning);
-  g_free (css_error);
+  gdk_rgba_free (color);
 
   return pixbuf;
 }
 
+static void
+_color_to_rgba (const GdkColor *color,
+                GdkRGBA        *rgba)
+{
+  rgba->red = color->red / 65535.0;
+  rgba->green = color->green / 65535.0;
+  rgba->blue = color->blue / 65535.0;
+  rgba->alpha = 1.0;
+}
+
 /**
  * gtk_icon_info_load_symbolic_for_style:
  * @icon_info: a #GtkIconInfo
@@ -3351,12 +3314,8 @@ gtk_icon_info_load_symbolic_for_style (GtkIconInfo   *icon_info,
                                        GError       **error)
 {
   GdkPixbuf *pixbuf;
-  GdkColor success_color;
-  GdkColor warning_color;
-  GdkColor error_color;
-  GdkColor *fg;
-  gchar *css_fg, *css_success;
-  gchar *css_warning, *css_error;
+  GdkColor success_color, warning_color, error_color;
+  GdkRGBA fg_rgba, success_rgba, warning_rgba, error_rgba;
 
   if (!icon_info->filename ||
       !g_str_has_suffix (icon_info->filename, "-symbolic.svg"))
@@ -3369,30 +3328,22 @@ gtk_icon_info_load_symbolic_for_style (GtkIconInfo   *icon_info,
   if (was_symbolic)
     *was_symbolic = TRUE;
 
-  fg = &style->fg[state];
-  css_fg = gdk_color_to_css (fg);
+  _color_to_rgba (&style->fg[state], &fg_rgba);
 
-  css_success = css_warning = css_error = NULL;
+  gtk_style_lookup_color (style, "success_color", &success_color);
+  _color_to_rgba (&success_color, &success_rgba);
 
-  if (gtk_style_lookup_color (style, "success_color", &success_color))
-    css_success = gdk_color_to_css (&success_color);
+  gtk_style_lookup_color (style, "warning_color", &warning_color);
+  _color_to_rgba (&warning_color, &warning_rgba);
 
-  if (gtk_style_lookup_color (style, "warning_color", &warning_color))
-    css_warning = gdk_color_to_css (&warning_color);
-
-  if (gtk_style_lookup_color (style, "error_color", &error_color))
-    css_error = gdk_color_to_css (&error_color);
+  gtk_style_lookup_color (style, "error_color", &error_color);
+  _color_to_rgba (&error_color, &error_rgba);
 
   pixbuf = _gtk_icon_info_load_symbolic_internal (icon_info,
-                                                  css_fg, css_success,
-                                                  css_warning, css_error,
+                                                  &fg_rgba, &success_rgba,
+                                                  &warning_rgba, &error_rgba,
                                                   error);
 
-  g_free (css_fg);
-  g_free (css_success);
-  g_free (css_warning);
-  g_free (css_error);
-
   return pixbuf;
 }
 
diff --git a/gtk/gtkinfobar.c b/gtk/gtkinfobar.c
index a787960..ef832fc 100644
--- a/gtk/gtkinfobar.c
+++ b/gtk/gtkinfobar.c
@@ -495,18 +495,7 @@ gtk_info_bar_update_colors (GtkInfoBar *info_bar)
 {
   GtkWidget *widget = GTK_WIDGET (info_bar);
   GtkInfoBarPrivate *priv = info_bar->priv;
-  GdkRGBA info_default_border_color     = { 0.71, 0.67, 0.61, 1.0 };
-  GdkRGBA info_default_fill_color       = { 0.99, 0.99, 0.74, 1.0 };
-  GdkRGBA warning_default_border_color  = { 0.68, 0.47, 0.16, 1.0 };
-  GdkRGBA warning_default_fill_color    = { 0.98, 0.68, 0.24, 1.0 };
-  GdkRGBA question_default_border_color = { 0.38, 0.48, 0.84, 1.0 };
-  GdkRGBA question_default_fill_color   = { 0.54, 0.68, 0.83, 1.0 };
-  GdkRGBA error_default_border_color    = { 0.65, 0.15, 0.15, 1.0 };
-  GdkRGBA error_default_fill_color      = { 0.93, 0.21, 0.21, 1.0 };
-  GdkRGBA other_default_border_color    = { 0.71, 0.67, 0.61, 1.0 };
-  GdkRGBA other_default_fill_color      = { 0.99, 0.99, 0.74, 1.0 };
-  GdkRGBA *fg, *bg;
-  GdkRGBA sym_fg, sym_bg;
+  GdkRGBA fg, bg;
   GdkRGBA *color, *bg_color;
   GtkStyleContext *context;
 
@@ -527,56 +516,17 @@ gtk_info_bar_update_colors (GtkInfoBar *info_bar)
 
   context = gtk_widget_get_style_context (widget);
 
-  if (gtk_style_context_lookup_color (context, fg_color_name[priv->message_type], &sym_fg) &&
-      gtk_style_context_lookup_color (context, bg_color_name[priv->message_type], &sym_bg))
-    {
-      fg = &sym_fg;
-      bg = &sym_bg;
-    }
-  else
-    {
-      switch (priv->message_type)
-        {
-        case GTK_MESSAGE_INFO:
-          fg = &info_default_border_color;
-          bg = &info_default_fill_color;
-          break;
-
-        case GTK_MESSAGE_WARNING:
-          fg = &warning_default_border_color;
-          bg = &warning_default_fill_color;
-          break;
-
-        case GTK_MESSAGE_QUESTION:
-          fg = &question_default_border_color;
-          bg = &question_default_fill_color;
-          break;
-
-        case GTK_MESSAGE_ERROR:
-          fg = &error_default_border_color;
-          bg = &error_default_fill_color;
-          break;
-
-        case GTK_MESSAGE_OTHER:
-          fg = &other_default_border_color;
-          bg = &other_default_fill_color;
-          break;
-
-        default:
-          g_assert_not_reached();
-          fg = NULL;
-          bg = NULL;
-        }
-    }
+  gtk_style_context_lookup_color (context, fg_color_name[priv->message_type], &fg);
+  gtk_style_context_lookup_color (context, bg_color_name[priv->message_type], &bg);
 
   gtk_style_context_get (context, 0,
                          "color", &color,
                          "background-color", &bg_color,
                          NULL);
-  if (!gdk_rgba_equal (bg_color, bg))
-    gtk_widget_override_background_color (widget, 0, bg);
-  if (!gdk_rgba_equal (color, fg))
-    gtk_widget_override_color (widget, 0, fg);
+  if (!gdk_rgba_equal (bg_color, &bg))
+    gtk_widget_override_background_color (widget, 0, &bg);
+  if (!gdk_rgba_equal (color, &fg))
+    gtk_widget_override_color (widget, 0, &fg);
 
   gdk_rgba_free (color);
   gdk_rgba_free (bg_color);
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index fab8607..9474ae0 100644
--- a/gtk/gtkstyle.c
+++ b/gtk/gtkstyle.c
@@ -1071,35 +1071,25 @@ gtk_style_lookup_icon_set (GtkStyle   *style,
  *
  * Deprecated:3.0: Use gtk_style_context_lookup_color() instead
  **/
-gboolean
+void
 gtk_style_lookup_color (GtkStyle   *style,
                         const char *color_name,
                         GdkColor   *color)
 {
   GtkStylePrivate *priv;
-  gboolean result;
   GdkRGBA rgba;
 
-  g_return_val_if_fail (GTK_IS_STYLE (style), FALSE);
-  g_return_val_if_fail (color_name != NULL, FALSE);
-  g_return_val_if_fail (color != NULL, FALSE);
+  g_return_if_fail (GTK_IS_STYLE (style));
+  g_return_if_fail (color_name != NULL);
 
   priv = GTK_STYLE_GET_PRIVATE (style);
 
-  if (!priv->context)
-    return FALSE;
-
-  result = gtk_style_context_lookup_color (priv->context, color_name, &rgba);
-
-  if (color)
-    {
-      color->red = (guint16) (rgba.red * 65535);
-      color->green = (guint16) (rgba.green * 65535);
-      color->blue = (guint16) (rgba.blue * 65535);
-      color->pixel = 0;
-    }
+  gtk_style_context_lookup_color (priv->context, color_name, &rgba);
 
-  return result;
+  color->red = (guint16) (rgba.red * 65535);
+  color->green = (guint16) (rgba.green * 65535);
+  color->blue = (guint16) (rgba.blue * 65535);
+  color->pixel = 0;
 }
 
 /**
diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h
index 3d44b1f..eb6f2b0 100644
--- a/gtk/gtkstyle.h
+++ b/gtk/gtkstyle.h
@@ -402,7 +402,7 @@ void	  gtk_style_apply_default_background (GtkStyle	   *style,
 
 GtkIconSet* gtk_style_lookup_icon_set        (GtkStyle     *style,
                                               const gchar  *stock_id);
-gboolean    gtk_style_lookup_color           (GtkStyle     *style,
+void        gtk_style_lookup_color           (GtkStyle     *style,
                                               const gchar  *color_name,
                                               GdkColor     *color);
 
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 2aee8b2..223017a 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -2317,29 +2317,25 @@ _gtk_style_context_peek_style_property (GtkStyleContext *context,
 
                   color = g_value_get_boxed (&pcache->value);
 
-                  if (gtk_symbolic_color_resolve (color, data->store, &rgba))
+                  gtk_symbolic_color_resolve (color, data->store, &rgba);
+                  g_value_unset (&pcache->value);
+
+                  if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
                     {
-                      g_value_unset (&pcache->value);
-
-                      if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
-                        {
-                          g_value_init (&pcache->value, GDK_TYPE_RGBA);
-                          g_value_set_boxed (&pcache->value, &rgba);
-                        }
-                      else
-                        {
-                          GdkColor rgb;
-
-                          rgb.red = rgba.red * 65535. + 0.5;
-                          rgb.green = rgba.green * 65535. + 0.5;
-                          rgb.blue = rgba.blue * 65535. + 0.5;
-
-                          g_value_init (&pcache->value, GDK_TYPE_COLOR);
-                          g_value_set_boxed (&pcache->value, &rgb);
-                        }
+                      g_value_init (&pcache->value, GDK_TYPE_RGBA);
+                      g_value_set_boxed (&pcache->value, &rgba);
                     }
                   else
-                    g_param_value_set_default (pspec, &pcache->value);
+                    {
+                      GdkColor rgb;
+
+                      rgb.red = rgba.red * 65535. + 0.5;
+                      rgb.green = rgba.green * 65535. + 0.5;
+                      rgb.blue = rgba.blue * 65535. + 0.5;
+
+                      g_value_init (&pcache->value, GDK_TYPE_COLOR);
+                      g_value_set_boxed (&pcache->value, &rgb);
+                    }
                 }
 
               return &pcache->value;
@@ -2708,6 +2704,44 @@ gtk_style_context_get_junction_sides (GtkStyleContext *context)
   return info->junction_sides;
 }
 
+gboolean
+gtk_style_context_lookup_default_color (const gchar *color_name,
+                                        GdkRGBA *color)
+{
+  static const GdkRGBA fallback_color = { 1.0, 0.0, 1.0, 1.0 };
+  static const struct {
+    const char *name;
+    const GdkRGBA rgba;
+  } colors[] = {
+    { "success_color",     { 0.3,   0.6,   0.02,  1.0 } },
+    { "warning_color",     { 0.96,  0.474, 0.24,  1.0 } },
+    { "error_color",       { 0.8,   0.0,   0.0,   1.0 } },
+    { "info_fg_color",     { 0.71,  0.67,  0.61,  1.0 } },
+    { "info_bg_color",     { 0.99,  0.99,  0.74,  1.0 } },
+    { "warning_fg_color",  { 0.68,  0.47,  0.16,  1.0 } },
+    { "warning_bg_color",  { 0.98,  0.68,  0.24,  1.0 } },
+    { "question_fg_color", { 0.38,  0.48,  0.84,  1.0 } },
+    { "question_bg_color", { 0.54,  0.68,  0.83,  1.0 } },
+    { "error_fg_color",    { 0.65,  0.15,  0.15,  1.0 } },
+    { "error_bg_color",    { 0.93,  0.21,  0.21,  1.0 } },
+    { "other_fg_color",    { 0.71,  0.67,  0.61,  1.0 } },
+    { "other_bg_color",    { 0.99,  0.99,  0.74,  1.0 } }
+  };
+  guint i;
+
+  for (i = 0; i < G_N_ELEMENTS (colors); i++)
+    {
+      if (g_str_equal (color_name, colors[i].name))
+        {
+          *color = colors[i].rgba;
+          return TRUE;
+        }
+    }
+
+  *color = fallback_color;
+  return FALSE;
+}
+
 /**
  * gtk_style_context_lookup_color:
  * @context: a #GtkStyleContext
@@ -2718,7 +2752,7 @@ gtk_style_context_get_junction_sides (GtkStyleContext *context)
  *
  * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
  **/
-gboolean
+void
 gtk_style_context_lookup_color (GtkStyleContext *context,
                                 const gchar     *color_name,
                                 GdkRGBA         *color)
@@ -2727,20 +2761,20 @@ gtk_style_context_lookup_color (GtkStyleContext *context,
   GtkSymbolicColor *sym_color;
   StyleData *data;
 
-  g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
-  g_return_val_if_fail (color_name != NULL, FALSE);
-  g_return_val_if_fail (color != NULL, FALSE);
+  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+  g_return_if_fail (color_name != NULL);
+  g_return_if_fail (color != NULL);
 
   priv = context->priv;
-  g_return_val_if_fail (priv->widget_path != NULL, FALSE);
+  g_return_if_fail (priv->widget_path != NULL);
 
   data = style_data_lookup (context);
   sym_color = gtk_style_properties_lookup_color (data->store, color_name);
 
-  if (!sym_color)
-    return FALSE;
-
-  return gtk_symbolic_color_resolve (sym_color, data->store, color);
+  if (sym_color)
+    gtk_symbolic_color_resolve (sym_color, data->store, color);
+  else
+    gtk_style_context_lookup_default_color (color_name, color);
 }
 
 /**
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index a67e523..cff1a58 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -415,9 +415,11 @@ void             gtk_style_context_set_junction_sides (GtkStyleContext  *context
 						       GtkJunctionSides  sides);
 GtkJunctionSides gtk_style_context_get_junction_sides (GtkStyleContext  *context);
 
-gboolean gtk_style_context_lookup_color (GtkStyleContext *context,
-                                         const gchar     *color_name,
-                                         GdkRGBA         *color);
+void gtk_style_context_lookup_color (GtkStyleContext *context,
+                                     const gchar     *color_name,
+                                     GdkRGBA         *color);
+gboolean gtk_style_context_lookup_default_color (const gchar *color_name,
+                                                 GdkRGBA     *color);
 
 void  gtk_style_context_notify_state_change (GtkStyleContext *context,
                                              GdkWindow       *window,
diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c
index c659274..915e1a4 100644
--- a/gtk/gtkstyleproperties.c
+++ b/gtk/gtkstyleproperties.c
@@ -566,7 +566,7 @@ gtk_style_properties_map_color (GtkStyleProperties *props,
  * Returns the symbolic color that is mapped
  * to @name.
  *
- * Returns: The mapped color
+ * Returns: The mapped color or %NULL if no color is mapped to @name
  *
  * Since: 3.0
  **/
@@ -760,33 +760,29 @@ gtk_style_properties_set (GtkStyleProperties *props,
   va_end (args);
 }
 
-static gboolean
+static void
 resolve_color (GtkStyleProperties *props,
 	       GValue             *value)
 {
   GdkRGBA color;
 
   /* Resolve symbolic color to GdkRGBA */
-  if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
-    return FALSE;
+  gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color);
 
   /* Store it back, this is where GdkRGBA caching happens */
   g_value_unset (value);
   g_value_init (value, GDK_TYPE_RGBA);
   g_value_set_boxed (value, &color);
-
-  return TRUE;
 }
 
-static gboolean
+static void
 resolve_color_rgb (GtkStyleProperties *props,
                    GValue             *value)
 {
   GdkColor color = { 0 };
   GdkRGBA rgba;
 
-  if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba))
-    return FALSE;
+  gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba);
 
   color.red = rgba.red * 65535. + 0.5;
   color.green = rgba.green * 65535. + 0.5;
@@ -795,8 +791,6 @@ resolve_color_rgb (GtkStyleProperties *props,
   g_value_unset (value);
   g_value_init (value, GDK_TYPE_COLOR);
   g_value_set_boxed (value, &color);
-
-  return TRUE;
 }
 
 static gboolean
@@ -805,8 +799,7 @@ resolve_gradient (GtkStyleProperties *props,
 {
   cairo_pattern_t *gradient;
 
-  if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
-    return FALSE;
+  gradient = gtk_gradient_resolve (g_value_get_boxed (value), props);
 
   /* Store it back, this is where cairo_pattern_t caching happens */
   g_value_unset (value);
@@ -824,15 +817,9 @@ style_properties_resolve_type (GtkStyleProperties *props,
   if (val && G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
     {
       if (node->pspec->value_type == GDK_TYPE_RGBA)
-        {
-          if (!resolve_color (props, val))
-            return FALSE;
-        }
+        resolve_color (props, val);
       else if (node->pspec->value_type == GDK_TYPE_COLOR)
-        {
-          if (!resolve_color_rgb (props, val))
-            return FALSE;
-        }
+        resolve_color_rgb (props, val);
       else
         return FALSE;
     }
@@ -840,8 +827,7 @@ style_properties_resolve_type (GtkStyleProperties *props,
     {
       g_return_val_if_fail (node->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN, FALSE);
 
-      if (!resolve_gradient (props, val))
-        return FALSE;
+      resolve_gradient (props, val);
     }
 
   return TRUE;
diff --git a/gtk/gtksymboliccolor.c b/gtk/gtksymboliccolor.c
index 2345cfa..cd53025 100644
--- a/gtk/gtksymboliccolor.c
+++ b/gtk/gtksymboliccolor.c
@@ -19,6 +19,7 @@
 
 #include "config.h"
 #include "gtksymboliccolor.h"
+#include "gtkstylecontext.h"
 #include "gtkstyleproperties.h"
 #include "gtkintl.h"
 
@@ -468,91 +469,81 @@ _shade_color (GdkRGBA *color,
  * @props: #GtkStyleProperties to use when resolving named colors
  * @resolved_color: (out): return location for the resolved color
  *
- * If @color is resolvable, @resolved_color will be filled in
- * with the resolved color, and %TRUE will be returned. Generally,
- * if @color can't be resolved, it is due to it being defined on
- * top of a named color that doesn't exist in @props.
+ * Resolves @color using @props. @resolved_color will be filled in
+ * with the resolved color.
  *
- * Returns: %TRUE if the color has been resolved
+ * If @props does not contain information for resolving @color or
+ * any of the colors it depends on, then solid pink (#FF00FF) will
+ * be assumed for the missing colors. This is to make it visually
+ * obvious when a color is missing.
  *
  * Since: 3.0
  **/
-gboolean
+void
 gtk_symbolic_color_resolve (GtkSymbolicColor   *color,
                             GtkStyleProperties *props,
                             GdkRGBA            *resolved_color)
 {
-  g_return_val_if_fail (color != NULL, FALSE);
-  g_return_val_if_fail (resolved_color != NULL, FALSE);
+  g_return_if_fail (color != NULL);
+  g_return_if_fail (resolved_color != NULL);
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
 
   switch (color->type)
     {
     case COLOR_TYPE_LITERAL:
       *resolved_color = color->color;
-      return TRUE;
+      break;
+
     case COLOR_TYPE_NAME:
       {
         GtkSymbolicColor *named_color;
 
-        g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
-
         named_color = gtk_style_properties_lookup_color (props, color->name);
 
         if (!named_color)
-          return FALSE;
+          gtk_style_context_lookup_default_color (color->name, resolved_color);
 
-        return gtk_symbolic_color_resolve (named_color, props, resolved_color);
+        gtk_symbolic_color_resolve (named_color, props, resolved_color);
       }
-
       break;
+
     case COLOR_TYPE_SHADE:
       {
         GdkRGBA shade;
 
-        if (!gtk_symbolic_color_resolve (color->shade.color, props, &shade))
-          return FALSE;
+        gtk_symbolic_color_resolve (color->shade.color, props, &shade);
 
         _shade_color (&shade, color->shade.factor);
         *resolved_color = shade;
-
-        return TRUE;
       }
-
       break;
+
     case COLOR_TYPE_ALPHA:
       {
         GdkRGBA alpha;
 
-        if (!gtk_symbolic_color_resolve (color->alpha.color, props, &alpha))
-          return FALSE;
+        gtk_symbolic_color_resolve (color->alpha.color, props, &alpha);
 
         *resolved_color = alpha;
         resolved_color->alpha = CLAMP (alpha.alpha * color->alpha.factor, 0, 1);
-
-        return TRUE;
       }
+      break;
+
     case COLOR_TYPE_MIX:
       {
         GdkRGBA color1, color2;
 
-        if (!gtk_symbolic_color_resolve (color->mix.color1, props, &color1))
-          return FALSE;
-
-        if (!gtk_symbolic_color_resolve (color->mix.color2, props, &color2))
-          return FALSE;
+        gtk_symbolic_color_resolve (color->mix.color1, props, &color1);
+        gtk_symbolic_color_resolve (color->mix.color2, props, &color2);
 
         resolved_color->red = CLAMP (color1.red + ((color2.red - color1.red) * color->mix.factor), 0, 1);
         resolved_color->green = CLAMP (color1.green + ((color2.green - color1.green) * color->mix.factor), 0, 1);
         resolved_color->blue = CLAMP (color1.blue + ((color2.blue - color1.blue) * color->mix.factor), 0, 1);
         resolved_color->alpha = CLAMP (color1.alpha + ((color2.alpha - color1.alpha) * color->mix.factor), 0, 1);
-
-        return TRUE;
       }
-
       break;
+
     default:
       g_assert_not_reached ();
     }
-
-  return FALSE;
 }
diff --git a/gtk/gtksymboliccolor.h b/gtk/gtksymboliccolor.h
index 4f4b813..2deff1b 100644
--- a/gtk/gtksymboliccolor.h
+++ b/gtk/gtksymboliccolor.h
@@ -46,7 +46,7 @@ GtkSymbolicColor * gtk_symbolic_color_new_mix     (GtkSymbolicColor   *color1,
 GtkSymbolicColor * gtk_symbolic_color_ref         (GtkSymbolicColor   *color);
 void               gtk_symbolic_color_unref       (GtkSymbolicColor   *color);
 
-gboolean           gtk_symbolic_color_resolve     (GtkSymbolicColor   *color,
+void               gtk_symbolic_color_resolve     (GtkSymbolicColor   *color,
                                                    GtkStyleProperties *props,
                                                    GdkRGBA            *resolved_color);
 
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index 1c77dbc..75301f5 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -549,21 +549,19 @@ gtk_theming_engine_get_style (GtkThemingEngine *engine,
  * @color: (out): Return location for the looked up color
  *
  * Looks up and resolves a color name in the current style's color map.
- *
- * Returns: %TRUE if @color_name was found and resolved, %FALSE otherwise
  **/
-gboolean
+void
 gtk_theming_engine_lookup_color (GtkThemingEngine *engine,
                                  const gchar      *color_name,
                                  GdkRGBA          *color)
 {
   GtkThemingEnginePrivate *priv;
 
-  g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), FALSE);
-  g_return_val_if_fail (color_name != NULL, FALSE);
+  g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+  g_return_if_fail (color_name != NULL);
 
   priv = engine->priv;
-  return gtk_style_context_lookup_color (priv->context, color_name, color);
+  gtk_style_context_lookup_color (priv->context, color_name, color);
 }
 
 /**
diff --git a/gtk/gtkthemingengine.h b/gtk/gtkthemingengine.h
index 64b3921..dc07d47 100644
--- a/gtk/gtkthemingengine.h
+++ b/gtk/gtkthemingengine.h
@@ -198,9 +198,9 @@ void gtk_theming_engine_get_style_valist   (GtkThemingEngine *engine,
 void gtk_theming_engine_get_style          (GtkThemingEngine *engine,
                                             ...);
 
-gboolean gtk_theming_engine_lookup_color (GtkThemingEngine *engine,
-                                          const gchar      *color_name,
-                                          GdkRGBA          *color);
+void gtk_theming_engine_lookup_color (GtkThemingEngine *engine,
+                                      const gchar      *color_name,
+                                      GdkRGBA          *color);
 
 G_CONST_RETURN GtkWidgetPath * gtk_theming_engine_get_path (GtkThemingEngine *engine);
 



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