forked from AuroraMiddleware/gtk
Add helper API for getting colors/borders in GtkStyleContext/GtkThemingEngine
This commit is contained in:
parent
3e8d138ed6
commit
bacb7906f2
@ -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
|
||||
|
@ -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 */
|
||||
|
||||
/**
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user