[gtk+/wip/css: 9/125] symboliccolor: Add _gtk_symbolic_color_resolve_full()



commit 28cdc2a619fdff440c107974a741eb0692f274c3
Author: Benjamin Otte <otte redhat com>
Date:   Wed Dec 28 16:15:00 2011 +0100

    symboliccolor: Add _gtk_symbolic_color_resolve_full()

 gtk/Makefile.am               |    1 +
 gtk/gtksymboliccolor.c        |   42 +++++++++++++++++++++++++++++++---------
 gtk/gtksymboliccolorprivate.h |   36 +++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 10 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 26caa25..29ddcf4 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -466,6 +466,7 @@ gtk_private_h_sources =		\
 	gtkstylecontextprivate.h \
 	gtkstylepropertiesprivate.h \
 	gtkstylepropertyprivate.h \
+	gtksymboliccolorprivate.h \
 	gtktextbtree.h		\
 	gtktextbufferserialize.h \
 	gtktextchildprivate.h	\
diff --git a/gtk/gtksymboliccolor.c b/gtk/gtksymboliccolor.c
index 23ba2f3..992b7a9 100644
--- a/gtk/gtksymboliccolor.c
+++ b/gtk/gtksymboliccolor.c
@@ -18,7 +18,7 @@
  */
 
 #include "config.h"
-#include "gtksymboliccolor.h"
+#include "gtksymboliccolorprivate.h"
 #include "gtkstyleproperties.h"
 #include "gtkintl.h"
 #include "gtkwin32themeprivate.h"
@@ -506,6 +506,15 @@ _shade_color (GdkRGBA *color,
   *color = temp;
 }
 
+static GtkSymbolicColor *
+resolve_lookup_color (gpointer data, const char *name)
+{
+  if (data == NULL)
+    return NULL;
+
+  return gtk_style_properties_lookup_color (data, name);
+}
+
 /**
  * gtk_symbolic_color_resolve:
  * @color: a #GtkSymbolicColor
@@ -535,6 +544,22 @@ gtk_symbolic_color_resolve (GtkSymbolicColor   *color,
   g_return_val_if_fail (resolved_color != NULL, FALSE);
   g_return_val_if_fail (props == NULL || GTK_IS_STYLE_PROPERTIES (props), FALSE);
 
+  return _gtk_symbolic_color_resolve_full (color,
+                                           resolve_lookup_color,
+                                           props,
+                                           resolved_color);
+}
+
+gboolean
+_gtk_symbolic_color_resolve_full (GtkSymbolicColor           *color,
+                                  GtkSymbolicColorLookupFunc  func,
+                                  gpointer                    data,
+                                  GdkRGBA                    *resolved_color)
+{
+  g_return_val_if_fail (color != NULL, FALSE);
+  g_return_val_if_fail (resolved_color != NULL, FALSE);
+  g_return_val_if_fail (func != NULL, FALSE);
+
   switch (color->type)
     {
     case COLOR_TYPE_LITERAL:
@@ -544,15 +569,12 @@ gtk_symbolic_color_resolve (GtkSymbolicColor   *color,
       {
         GtkSymbolicColor *named_color;
 
-        if (props == NULL)
-          return FALSE;
-
-        named_color = gtk_style_properties_lookup_color (props, color->name);
+        named_color = func (data, color->name);
 
         if (!named_color)
           return FALSE;
 
-        return gtk_symbolic_color_resolve (named_color, props, resolved_color);
+        return _gtk_symbolic_color_resolve_full (named_color, func, data, resolved_color);
       }
 
       break;
@@ -560,7 +582,7 @@ gtk_symbolic_color_resolve (GtkSymbolicColor   *color,
       {
         GdkRGBA shade;
 
-        if (!gtk_symbolic_color_resolve (color->shade.color, props, &shade))
+        if (!_gtk_symbolic_color_resolve_full (color->shade.color, func, data, &shade))
           return FALSE;
 
         _shade_color (&shade, color->shade.factor);
@@ -574,7 +596,7 @@ gtk_symbolic_color_resolve (GtkSymbolicColor   *color,
       {
         GdkRGBA alpha;
 
-        if (!gtk_symbolic_color_resolve (color->alpha.color, props, &alpha))
+        if (!_gtk_symbolic_color_resolve_full (color->alpha.color, func, data, &alpha))
           return FALSE;
 
         *resolved_color = alpha;
@@ -586,10 +608,10 @@ gtk_symbolic_color_resolve (GtkSymbolicColor   *color,
       {
         GdkRGBA color1, color2;
 
-        if (!gtk_symbolic_color_resolve (color->mix.color1, props, &color1))
+        if (!_gtk_symbolic_color_resolve_full (color->mix.color1, func, data, &color1))
           return FALSE;
 
-        if (!gtk_symbolic_color_resolve (color->mix.color2, props, &color2))
+        if (!_gtk_symbolic_color_resolve_full (color->mix.color2, func, data, &color2))
           return FALSE;
 
         resolved_color->red = CLAMP (color1.red + ((color2.red - color1.red) * color->mix.factor), 0, 1);
diff --git a/gtk/gtksymboliccolorprivate.h b/gtk/gtksymboliccolorprivate.h
new file mode 100644
index 0000000..1216a49
--- /dev/null
+++ b/gtk/gtksymboliccolorprivate.h
@@ -0,0 +1,36 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2011 Benjamin Otte <otte gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GTK_SYMBOLIC_COLOR_PRIVATE_H__
+#define __GTK_SYMBOLIC_COLOR_PRIVATE_H__
+
+#include "gtk/gtksymboliccolor.h"
+
+G_BEGIN_DECLS
+
+typedef GtkSymbolicColor * (* GtkSymbolicColorLookupFunc) (gpointer data, const char *name);
+
+gboolean           _gtk_symbolic_color_resolve_full       (GtkSymbolicColor           *color,
+                                                           GtkSymbolicColorLookupFunc  func,
+                                                           gpointer                    data,
+                                                           GdkRGBA                    *resolved_color);
+
+G_END_DECLS
+
+#endif /* __GTK_SYMBOLIC_COLOR_PRIVATE_H__ */



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