forked from AuroraMiddleware/gtk
Bug 412134 – Add API to query style properties from the style
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 svn path=/trunk/; revision=21744
This commit is contained in:
parent
54dbd8c1a4
commit
4f8f288163
@ -1,3 +1,12 @@
|
||||
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
|
||||
|
||||
2008-10-31 Christian Dywan <christian@imendio.com>
|
||||
|
||||
Bug 558667 – gtk_font_selection_dialog_get_apply_button - deprecate?
|
||||
|
@ -1,3 +1,7 @@
|
||||
2008-11-01 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gtk/gtk-sections.txt: Add new GtkStyle functions.
|
||||
|
||||
2008-10-29 Federico Mena Quintero <federico@novell.com>
|
||||
|
||||
* gtk/drawing-model.xml: New chapter for "The GTK+ Drawing Model".
|
||||
|
@ -5699,6 +5699,9 @@ gtk_style_lookup_icon_set
|
||||
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
|
||||
|
@ -1227,6 +1227,9 @@ gtk_style_new
|
||||
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
|
||||
|
||||
|
142
gtk/gtkstyle.c
142
gtk/gtkstyle.c
@ -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 @@ style_property_values_cmp (gconstpointer bsearch_node1,
|
||||
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,
|
||||
|
@ -863,6 +863,19 @@ GtkBorder *gtk_border_new (void) G_GNUC_MALLOC;
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user