[gtk+/gtk-style-context: 539/540] Add helper API for getting colors/borders in GtkStyleContext/GtkThemingEngine
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-style-context: 539/540] Add helper API for getting colors/borders in GtkStyleContext/GtkThemingEngine
- Date: Fri, 3 Dec 2010 03:21:25 +0000 (UTC)
commit 810c25710547121fd931e32958aaa46a1f778857
Author: Carlos Garnacho <carlosg gnome org>
Date: Thu Dec 2 23:41:24 2010 +0100
Add helper API for getting colors/borders in GtkStyleContext/GtkThemingEngine
docs/reference/gtk/gtk3-sections.txt | 12 ++
gtk/gtkstylecontext.c | 192 ++++++++++++++++++++++++++++++++++
gtk/gtkstylecontext.h | 21 ++++
gtk/gtkstyleproperties.c | 37 +++++++
gtk/gtkstyleproperties.h | 5 +
gtk/gtkthemingengine.c | 139 ++++++++++++++++++++++++
gtk/gtkthemingengine.h | 22 ++++
7 files changed, 428 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 632b0bc..bbf8178 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -5402,6 +5402,12 @@ gtk_style_context_get_style
gtk_style_context_get_style_property
gtk_style_context_get_style_valist
gtk_style_context_get_valist
+gtk_style_context_get_color
+gtk_style_context_get_background_color
+gtk_style_context_get_border_color
+gtk_style_context_get_border
+gtk_style_context_get_padding
+gtk_style_context_get_margin
gtk_style_context_invalidate
gtk_style_context_state_is_running
gtk_style_context_lookup_color
@@ -5506,6 +5512,12 @@ gtk_theming_engine_get_style
gtk_theming_engine_get_style_property
gtk_theming_engine_get_style_valist
gtk_theming_engine_get_valist
+gtk_theming_engine_get_color
+gtk_theming_engine_get_background_color
+gtk_theming_engine_get_border_color
+gtk_theming_engine_get_border
+gtk_theming_engine_get_padding
+gtk_theming_engine_get_margin
gtk_theming_engine_has_class
gtk_theming_engine_has_region
gtk_theming_engine_lookup_color
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 6525540..d4f5db3 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -3151,6 +3151,198 @@ gtk_style_context_set_background (GtkStyleContext *context,
}
}
+/**
+ * gtk_style_context_get_color:
+ * @context: a #GtkStyleContext
+ * @state: state to retrieve the color for
+ * @color: (out): return value for the foreground color
+ *
+ * Gets the foreground color for a given state.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_context_get_color (GtkStyleContext *context,
+ GtkStateFlags state,
+ GdkRGBA *color)
+{
+ GtkStyleContextPrivate *priv;
+ StyleData *data;
+ const GValue *value;
+ GdkRGBA *c;
+
+ g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+
+ priv = context->priv;
+ g_return_if_fail (priv->widget_path != NULL);
+
+ data = style_data_lookup (context);
+ value = _gtk_style_properties_peek_property (data->store,
+ "color", state);
+ c = g_value_get_boxed (value);
+ *color = *c;
+}
+
+/**
+ * gtk_style_context_get_background_color:
+ * @context: a #GtkStyleContext
+ * @state: state to retrieve the color for
+ * @color: (out): return value for the background color
+ *
+ * Gets the background color for a given state.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_context_get_background_color (GtkStyleContext *context,
+ GtkStateFlags state,
+ GdkRGBA *color)
+{
+ GtkStyleContextPrivate *priv;
+ StyleData *data;
+ const GValue *value;
+ GdkRGBA *c;
+
+ g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+
+ priv = context->priv;
+ g_return_if_fail (priv->widget_path != NULL);
+
+ data = style_data_lookup (context);
+ value = _gtk_style_properties_peek_property (data->store,
+ "background-color", state);
+ c = g_value_get_boxed (value);
+ *color = *c;
+}
+
+/**
+ * gtk_style_context_get_border_color:
+ * @context: a #GtkStyleContext
+ * @state: state to retrieve the color for
+ * @color: (out): return value for the border color
+ *
+ * Gets the border color for a given state.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_context_get_border_color (GtkStyleContext *context,
+ GtkStateFlags state,
+ GdkRGBA *color)
+{
+ GtkStyleContextPrivate *priv;
+ StyleData *data;
+ const GValue *value;
+ GdkRGBA *c;
+
+ g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+
+ priv = context->priv;
+ g_return_if_fail (priv->widget_path != NULL);
+
+ data = style_data_lookup (context);
+ value = _gtk_style_properties_peek_property (data->store,
+ "border-color", state);
+ c = g_value_get_boxed (value);
+ *color = *c;
+}
+
+/**
+ * gtk_style_context_get_border:
+ * @context: a #GtkStyleContext
+ * @state: state to retrieve the border for
+ * @color: (out): return value for the border settings
+ *
+ * Gets the border for a given state as a #GtkBorder.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_context_get_border (GtkStyleContext *context,
+ GtkStateFlags state,
+ GtkBorder *border)
+{
+ GtkStyleContextPrivate *priv;
+ StyleData *data;
+ const GValue *value;
+ GtkBorder *b;
+
+ g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+
+ priv = context->priv;
+ g_return_if_fail (priv->widget_path != NULL);
+
+ data = style_data_lookup (context);
+ value = _gtk_style_properties_peek_property (data->store,
+ "border-width", state);
+ b = g_value_get_boxed (value);
+ *border = *b;
+}
+
+/**
+ * gtk_style_context_get_padding:
+ * @context: a #GtkStyleContext
+ * @state: state to retrieve the padding for
+ * @color: (out): return value for the padding settings
+ *
+ * Gets the padding for a given state as a #GtkBorder.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_context_get_padding (GtkStyleContext *context,
+ GtkStateFlags state,
+ GtkBorder *padding)
+{
+ GtkStyleContextPrivate *priv;
+ StyleData *data;
+ const GValue *value;
+ GtkBorder *b;
+
+ g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+
+ priv = context->priv;
+ g_return_if_fail (priv->widget_path != NULL);
+
+ data = style_data_lookup (context);
+ value = _gtk_style_properties_peek_property (data->store,
+ "padding", state);
+ b = g_value_get_boxed (value);
+ *padding = *b;
+}
+
+/**
+ * gtk_style_context_get_margin:
+ * @context: a #GtkStyleContext
+ * @state: state to retrieve the border for
+ * @color: (out): return value for the margin settings
+ *
+ * Gets the margin for a given state as a #GtkBorder.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_context_get_margin (GtkStyleContext *context,
+ GtkStateFlags state,
+ GtkBorder *margin)
+{
+ GtkStyleContextPrivate *priv;
+ StyleData *data;
+ const GValue *value;
+ GtkBorder *b;
+
+ g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+
+ priv = context->priv;
+ g_return_if_fail (priv->widget_path != NULL);
+
+ data = style_data_lookup (context);
+ value = _gtk_style_properties_peek_property (data->store,
+ "margin", state);
+ b = g_value_get_boxed (value);
+ *margin = *b;
+}
+
/* Paint methods */
/**
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index b2dd734..be20bf9 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -23,6 +23,7 @@
#include <glib-object.h>
#include <gtk/gtkstyleprovider.h>
#include <gtk/gtkwidgetpath.h>
+#include <gtk/gtkborder.h>
G_BEGIN_DECLS
@@ -420,6 +421,26 @@ void gtk_style_context_push_animatable_region (GtkStyleContext *context,
gpointer region_id);
void gtk_style_context_pop_animatable_region (GtkStyleContext *context);
+/* Some helper functions to retrieve most common properties */
+void gtk_style_context_get_color (GtkStyleContext *context,
+ GtkStateFlags state,
+ GdkRGBA *color);
+void gtk_style_context_get_background_color (GtkStyleContext *context,
+ GtkStateFlags state,
+ GdkRGBA *color);
+void gtk_style_context_get_border_color (GtkStyleContext *context,
+ GtkStateFlags state,
+ GdkRGBA *color);
+
+void gtk_style_context_get_border (GtkStyleContext *context,
+ GtkStateFlags state,
+ GtkBorder *border);
+void gtk_style_context_get_padding (GtkStyleContext *context,
+ GtkStateFlags state,
+ GtkBorder *padding);
+void gtk_style_context_get_margin (GtkStyleContext *context,
+ GtkStateFlags state,
+ GtkBorder *margin);
/* Semi-private API */
const GValue * _gtk_style_context_peek_style_property (GtkStyleContext *context,
diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c
index 9930829..c659274 100644
--- a/gtk/gtkstyleproperties.c
+++ b/gtk/gtkstyleproperties.c
@@ -857,6 +857,43 @@ lookup_default_value (PropertyNode *node,
g_param_value_set_default (node->pspec, value);
}
+const GValue *
+_gtk_style_properties_peek_property (GtkStyleProperties *props,
+ const gchar *prop_name,
+ GtkStateFlags state)
+{
+ GtkStylePropertiesPrivate *priv;
+ PropertyNode *node;
+ PropertyData *prop;
+ GValue *val;
+
+ g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), NULL);
+ g_return_val_if_fail (prop_name != NULL, NULL);
+
+ node = property_node_lookup (g_quark_try_string (prop_name));
+
+ if (!node)
+ {
+ g_warning ("Style property \"%s\" is not registered", prop_name);
+ return NULL;
+ }
+
+ priv = props->priv;
+ prop = g_hash_table_lookup (priv->properties,
+ GINT_TO_POINTER (node->property_quark));
+
+ if (!prop)
+ return NULL;
+
+ val = property_data_match_state (prop, state);
+
+ if (val &&
+ !style_properties_resolve_type (props, node, val))
+ return NULL;
+
+ return val;
+}
+
/**
* gtk_style_properties_get_property:
* @props: a #GtkStyleProperties
diff --git a/gtk/gtkstyleproperties.h b/gtk/gtkstyleproperties.h
index 8a243b7..4ff783a 100644
--- a/gtk/gtkstyleproperties.h
+++ b/gtk/gtkstyleproperties.h
@@ -56,6 +56,11 @@ typedef gboolean (* GtkStylePropertyParser) (const gchar *string,
GType gtk_style_properties_get_type (void) G_GNUC_CONST;
+/* Semi-private API */
+const GValue * _gtk_style_properties_peek_property (GtkStyleProperties *props,
+ const gchar *prop_name,
+ GtkStateFlags state);
+
/* Functions to register style properties */
void gtk_style_properties_register_property (GtkStylePropertyParser parse_func,
GParamSpec *pspec);
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index e5d9e57..7469aef 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -737,6 +737,145 @@ gtk_theming_engine_get_junction_sides (GtkThemingEngine *engine)
return gtk_style_context_get_junction_sides (priv->context);
}
+/**
+ * gtk_theming_engine_get_color:
+ * @engine: a #GtkThemingEngine
+ * @state: state to retrieve the color for
+ * @color: (out): return value for the foreground color
+ *
+ * Gets the foreground color for a given state.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_color (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GdkRGBA *color)
+{
+ GtkThemingEnginePrivate *priv;
+
+ g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+ priv = engine->priv;
+ gtk_style_context_get_color (priv->context, state, color);
+}
+
+/**
+ * gtk_theming_engine_get_background_color:
+ * @engine: a #GtkThemingEngine
+ * @state: state to retrieve the color for
+ * @color: (out): return value for the background color
+ *
+ * Gets the background color for a given state.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_background_color (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GdkRGBA *color)
+{
+ GtkThemingEnginePrivate *priv;
+
+ g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+ priv = engine->priv;
+ gtk_style_context_get_background_color (priv->context, state, color);
+}
+
+/**
+ * gtk_theming_engine_get_border_color:
+ * @engine: a #GtkThemingEngine
+ * @state: state to retrieve the color for
+ * @color: (out): return value for the border color
+ *
+ * Gets the border color for a given state.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_border_color (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GdkRGBA *color)
+{
+ GtkThemingEnginePrivate *priv;
+
+ g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+ priv = engine->priv;
+ gtk_style_context_get_border_color (priv->context, state, color);
+}
+
+/**
+ * gtk_theming_engine_get_border:
+ * @engine: a #GtkthemingEngine
+ * @state: state to retrieve the border for
+ * @color: (out): return value for the border settings
+ *
+ * Gets the border for a given state as a #GtkBorder.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_border (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GtkBorder *border)
+{
+ GtkThemingEnginePrivate *priv;
+
+ g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+ priv = engine->priv;
+ gtk_style_context_get_border (priv->context, state, border);
+}
+
+/**
+ * gtk_theming_engine_get_padding:
+ * @engine: a #GtkthemingEngine
+ * @state: state to retrieve the padding for
+ * @color: (out): return value for the padding settings
+ *
+ * Gets the padding for a given state as a #GtkBorder.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_padding (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GtkBorder *padding)
+{
+ GtkThemingEnginePrivate *priv;
+
+ g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+ priv = engine->priv;
+ gtk_style_context_get_padding (priv->context, state, padding);
+}
+
+/**
+ * gtk_theming_engine_get_margin:
+ * @engien: a #GtkThemingEngine
+ * @state: state to retrieve the border for
+ * @color: (out): return value for the margin settings
+ *
+ * Gets the margin for a given state as a #GtkBorder.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_theming_engine_get_margin (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GtkBorder *margin)
+{
+ GtkThemingEnginePrivate *priv;
+
+ g_return_if_fail (GTK_IS_THEMING_ENGINE (engine));
+
+ priv = engine->priv;
+ gtk_style_context_get_margin (priv->context, state, margin);
+}
+
+
/* GtkThemingModule */
static gboolean
diff --git a/gtk/gtkthemingengine.h b/gtk/gtkthemingengine.h
index 8dc862e..71cd635 100644
--- a/gtk/gtkthemingengine.h
+++ b/gtk/gtkthemingengine.h
@@ -215,6 +215,28 @@ GtkTextDirection gtk_theming_engine_get_direction (GtkThemingEngine *engine);
GtkJunctionSides gtk_theming_engine_get_junction_sides (GtkThemingEngine *engine);
+/* Helper functions */
+void gtk_theming_engine_get_color (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GdkRGBA *color);
+void gtk_theming_engine_get_background_color (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GdkRGBA *color);
+void gtk_theming_engine_get_border_color (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GdkRGBA *color);
+
+void gtk_theming_engine_get_border (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GtkBorder *border);
+void gtk_theming_engine_get_padding (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GtkBorder *padding);
+void gtk_theming_engine_get_margin (GtkThemingEngine *engine,
+ GtkStateFlags state,
+ GtkBorder *margin);
+
+
GtkThemingEngine * gtk_theming_engine_load (const gchar *name);
GdkScreen * gtk_theming_engine_get_screen (GtkThemingEngine *engine);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]