gtk+ r21744 - in trunk: . docs/reference docs/reference/gtk gtk



Author: matthiasc
Date: Sat Nov  1 04:15:14 2008
New Revision: 21744
URL: http://svn.gnome.org/viewvc/gtk+?rev=21744&view=rev

Log:
2008-11-01  Matthias Clasen  <mclasen redhat com>

        Bug 412134 â Add API to query style properties from the style

        * gtk/gtk.symbols:
        * gtk/gtkstyle.[hc]: Add getters for style properties to
        avoid the need for ugly workarounds with dummy widget instances.
        Patch by Mariano SuÃrez-Alvarez


Modified:
   trunk/ChangeLog
   trunk/docs/reference/ChangeLog
   trunk/docs/reference/gtk/gtk-sections.txt
   trunk/gtk/gtk.symbols
   trunk/gtk/gtkstyle.c
   trunk/gtk/gtkstyle.h

Modified: trunk/docs/reference/gtk/gtk-sections.txt
==============================================================================
--- trunk/docs/reference/gtk/gtk-sections.txt	(original)
+++ trunk/docs/reference/gtk/gtk-sections.txt	Sat Nov  1 04:15:14 2008
@@ -5699,6 +5699,9 @@
 gtk_style_render_icon
 gtk_style_get_font
 gtk_style_set_font
+gtk_style_get_property
+gtk_style_get_valist
+gtk_style_get
 gtk_draw_hline
 gtk_draw_vline
 gtk_draw_shadow

Modified: trunk/gtk/gtk.symbols
==============================================================================
--- trunk/gtk/gtk.symbols	(original)
+++ trunk/gtk/gtk.symbols	Sat Nov  1 04:15:14 2008
@@ -1227,6 +1227,9 @@
 gtk_style_render_icon
 gtk_style_set_background
 gtk_draw_insertion_cursor
+gtk_style_get_property
+gtk_style_get_valist
+gtk_style_get
 #endif
 #endif
 

Modified: trunk/gtk/gtkstyle.c
==============================================================================
--- trunk/gtk/gtkstyle.c	(original)
+++ trunk/gtk/gtkstyle.c	Sat Nov  1 04:15:14 2008
@@ -28,6 +28,7 @@
 #include <math.h>
 #include <stdlib.h>
 #include <string.h>
+#include <gobject/gvaluecollector.h>
 #include "gtkgc.h"
 #include "gtkmarshalers.h"
 #undef GTK_DISABLE_DEPRECATED
@@ -1696,6 +1697,147 @@
     return val1->widget_type < val2->widget_type ? -1 : 1;
 }
 
+/**
+ * gtk_style_get_property:
+ * @style: a #GtkStyle
+ * @widget_type: the #GType of a descendant of #GtkWidget
+ * @property_name: the name of the style property to get
+ * @value: a #GValue where the value of the property being
+ *     queried will be stored
+ *
+ * Queries the value of a style property corresponding to a
+ * widget class is in the given style.
+ *
+ * Since: 2.16
+ */
+void 
+gtk_style_get_property (GtkStyle     *style,
+                        GType        widget_type,
+                        const gchar *property_name,
+                        GValue      *value)
+{
+  GtkWidgetClass *klass;
+  GParamSpec *pspec;
+  GtkRcPropertyParser parser;
+  const GValue *peek_value;
+
+  klass = g_type_class_peek (widget_type);
+  pspec = gtk_widget_class_find_style_property (klass, property_name);
+
+  if (!pspec)
+    {
+      g_warning ("%s: widget class `%s' has no property named `%s'",
+                 G_STRLOC,
+                 g_type_name (widget_type),
+                 property_name);
+      return;
+    }
+
+  parser = g_param_spec_get_qdata (pspec,
+                                   g_quark_from_static_string ("gtk-rc-property-parser"));
+
+  peek_value = _gtk_style_peek_property_value (style, widget_type, pspec, parser);
+
+  if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
+    g_value_copy (peek_value, value);
+  else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
+    g_value_transform (peek_value, value);
+  else
+    g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
+               pspec->name,
+               g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
+               G_VALUE_TYPE_NAME (value));
+}
+
+/**
+ * gtk_style_get_valist:
+ * @style: a #GtkStyle
+ * @widget_type: the #GType of a descendant of #GtkWidget
+ * @first_property_name: the name of the first style property to get
+ * @var_list: a <type>va_list</type> of pairs of property names and
+ *     locations to return the property values, starting with the
+ *     location for @first_property_name.
+ *
+ * Non-vararg variant of gtk_style_get().
+ * Used primarily by language bindings.
+ *
+ * Since: 2.16
+ */
+void 
+gtk_style_get_valist (GtkStyle    *style,
+                      GType        widget_type,
+                      const gchar *first_property_name,
+                      va_list      var_args)
+{
+  const char *property_name;
+  GtkWidgetClass *klass;
+
+  g_return_if_fail (GTK_IS_STYLE (style));
+
+  klass = g_type_class_ref (widget_type);
+
+  property_name = first_property_name;
+  while (property_name)
+    {
+      GParamSpec *pspec;
+      GtkRcPropertyParser parser;
+      const GValue *peek_value;
+      gchar *error;
+
+      pspec = gtk_widget_class_find_style_property (klass, property_name);
+
+      if (!pspec)
+        {
+          g_warning ("%s: widget class `%s' has no property named `%s'",
+                     G_STRLOC,
+                     g_type_name (widget_type),
+                     property_name);
+          break;
+        }
+
+      parser = g_param_spec_get_qdata (pspec,
+                                       g_quark_from_static_string ("gtk-rc-property-parser"));
+
+      peek_value = _gtk_style_peek_property_value (style, widget_type, pspec, parser);
+      G_VALUE_LCOPY (peek_value, var_args, 0, &error);
+      if (error)
+        {
+          g_warning ("%s: %s", G_STRLOC, error);
+          g_free (error);
+          break;
+        }
+
+      property_name = va_arg (var_args, gchar*);
+    }
+
+  g_type_class_unref (klass);
+}
+
+/**
+ * gtk_style_get:
+ * @style: a #GtkStyle
+ * @widget_type: the #GType of a descendant of #GtkWidget
+ * @first_property_name: the name of the first style property to get
+ * @Varargs: pairs of property names and locations to
+ *   return the property values, starting with the location for
+ *   @first_property_name, terminated by %NULL.
+ *
+ * Gets the values of a multiple style properties for @widget_type
+ * from @style.
+ */
+void
+gtk_style_get (GtkStyle    *style,
+               GType        widget_type,
+               const gchar *first_property_name,
+               ...)
+{
+  va_list var_args;
+
+  va_start (var_args, first_property_name);
+  gtk_style_get_valist (style, widget_type, first_property_name, var_args);
+  va_end (var_args);
+}
+
 const GValue*
 _gtk_style_peek_property_value (GtkStyle           *style,
 				GType               widget_type,

Modified: trunk/gtk/gtkstyle.h
==============================================================================
--- trunk/gtk/gtkstyle.h	(original)
+++ trunk/gtk/gtkstyle.h	Sat Nov  1 04:15:14 2008
@@ -863,6 +863,19 @@
 GtkBorder *gtk_border_copy     (const GtkBorder *border_);
 void       gtk_border_free     (GtkBorder       *border_);
 
+void gtk_style_get_property (GtkStyle    *style,
+                             GType        widget_type,
+                             const gchar *property_name,
+                             GValue      *value);
+void gtk_style_get_valist   (GtkStyle    *style,
+                             GType        widget_type,
+                             const gchar *first_property_name,
+                             va_list      var_args);
+void gtk_style_get          (GtkStyle    *style,
+                             GType        widget_type,
+                             const gchar *first_property_name,
+                             ...) G_GNUC_NULL_TERMINATED;
+
 /* --- private API --- */
 const GValue* _gtk_style_peek_property_value (GtkStyle           *style,
 					      GType               widget_type,



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