2010-03-04 19:59:18 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2010 Carlos Garnacho <carlosg@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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-03-04 19:59:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2011-05-19 12:00:14 +00:00
|
|
|
#include "gtkstylepropertiesprivate.h"
|
2010-11-26 01:39:53 +00:00
|
|
|
|
2010-03-05 00:45:47 +00:00
|
|
|
#include <stdlib.h>
|
2010-03-05 02:02:59 +00:00
|
|
|
#include <gobject/gvaluecollector.h>
|
2010-11-12 20:43:13 +00:00
|
|
|
#include <cairo-gobject.h>
|
2010-03-05 00:45:47 +00:00
|
|
|
|
2010-03-04 21:51:56 +00:00
|
|
|
#include "gtkstyleprovider.h"
|
2011-12-31 12:50:03 +00:00
|
|
|
#include "gtkcssshorthandpropertyprivate.h"
|
2012-04-07 05:40:36 +00:00
|
|
|
#include "gtkcsstypedvalueprivate.h"
|
2011-05-26 01:50:53 +00:00
|
|
|
#include "gtkcsstypesprivate.h"
|
2011-05-21 02:17:28 +00:00
|
|
|
|
2011-12-29 01:28:32 +00:00
|
|
|
#include "gtkprivatetypebuiltins.h"
|
2011-05-21 02:17:28 +00:00
|
|
|
#include "gtkstylepropertyprivate.h"
|
2011-12-28 21:59:55 +00:00
|
|
|
#include "gtkstyleproviderprivate.h"
|
2010-03-04 19:59:18 +00:00
|
|
|
#include "gtkintl.h"
|
2011-11-15 19:52:45 +00:00
|
|
|
|
2014-08-29 20:33:37 +00:00
|
|
|
#include "deprecated/gtkthemingengine.h"
|
2012-11-25 03:16:43 +00:00
|
|
|
#include "deprecated/gtkgradient.h"
|
|
|
|
#include "deprecated/gtksymboliccolorprivate.h"
|
|
|
|
|
2014-10-24 19:22:43 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
|
|
|
|
2010-11-21 23:00:30 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtkstyleproperties
|
|
|
|
* @Short_description: Store for style property information
|
|
|
|
* @Title: GtkStyleProperties
|
|
|
|
*
|
|
|
|
* GtkStyleProperties provides the storage for style information
|
|
|
|
* that is used by #GtkStyleContext and other #GtkStyleProvider
|
|
|
|
* implementations.
|
|
|
|
*
|
|
|
|
* Before style properties can be stored in GtkStyleProperties, they
|
|
|
|
* must be registered with gtk_style_properties_register_property().
|
|
|
|
*
|
|
|
|
* Unless you are writing a #GtkStyleProvider implementation, you
|
|
|
|
* are unlikely to use this API directly, as gtk_style_context_get()
|
|
|
|
* and its variants are the preferred way to access styling information
|
|
|
|
* from widget implementations and theming engine implementations
|
|
|
|
* should use the APIs provided by #GtkThemingEngine instead.
|
2014-10-24 19:22:43 +00:00
|
|
|
*
|
|
|
|
* #GtkStyleProperties has been deprecated in GTK 3.16. The CSS
|
|
|
|
* machinery does not use it anymore and all users of this object
|
|
|
|
* have been deprecated.
|
2010-11-21 23:00:30 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-04 19:59:18 +00:00
|
|
|
typedef struct PropertyData PropertyData;
|
2010-08-16 17:09:34 +00:00
|
|
|
typedef struct ValueData ValueData;
|
2010-03-05 00:45:47 +00:00
|
|
|
|
2010-08-16 17:09:34 +00:00
|
|
|
struct ValueData
|
|
|
|
{
|
|
|
|
GtkStateFlags state;
|
2012-03-06 13:16:32 +00:00
|
|
|
GtkCssValue *value;
|
2010-08-16 17:09:34 +00:00
|
|
|
};
|
|
|
|
|
2010-03-04 19:59:18 +00:00
|
|
|
struct PropertyData
|
|
|
|
{
|
2010-08-16 17:09:34 +00:00
|
|
|
GArray *values;
|
2010-03-04 19:59:18 +00:00
|
|
|
};
|
|
|
|
|
2011-12-21 07:00:45 +00:00
|
|
|
struct _GtkStylePropertiesPrivate
|
2010-03-04 19:59:18 +00:00
|
|
|
{
|
2010-06-25 17:37:54 +00:00
|
|
|
GHashTable *color_map;
|
2010-03-04 19:59:18 +00:00
|
|
|
GHashTable *properties;
|
|
|
|
};
|
|
|
|
|
2011-12-28 21:59:55 +00:00
|
|
|
static void gtk_style_properties_provider_init (GtkStyleProviderIface *iface);
|
|
|
|
static void gtk_style_properties_provider_private_init (GtkStyleProviderPrivateInterface *iface);
|
|
|
|
static void gtk_style_properties_finalize (GObject *object);
|
2010-03-04 19:59:18 +00:00
|
|
|
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkStyleProperties, gtk_style_properties, G_TYPE_OBJECT,
|
|
|
|
G_ADD_PRIVATE (GtkStyleProperties)
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
|
|
|
|
gtk_style_properties_provider_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER_PRIVATE,
|
|
|
|
gtk_style_properties_provider_private_init));
|
2010-03-04 19:59:18 +00:00
|
|
|
|
|
|
|
static void
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_class_init (GtkStylePropertiesClass *klass)
|
2010-03-04 19:59:18 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
object_class->finalize = gtk_style_properties_finalize;
|
2010-03-04 19:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PropertyData *
|
|
|
|
property_data_new (void)
|
|
|
|
{
|
|
|
|
PropertyData *data;
|
|
|
|
|
|
|
|
data = g_slice_new0 (PropertyData);
|
2010-08-16 17:09:34 +00:00
|
|
|
data->values = g_array_new (FALSE, FALSE, sizeof (ValueData));
|
2010-03-04 19:59:18 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-01-17 03:06:57 +00:00
|
|
|
property_data_remove_values (PropertyData *data)
|
2010-03-04 19:59:18 +00:00
|
|
|
{
|
2010-08-16 17:09:34 +00:00
|
|
|
guint i;
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-08-16 17:09:34 +00:00
|
|
|
for (i = 0; i < data->values->len; i++)
|
2010-03-04 21:51:56 +00:00
|
|
|
{
|
2010-08-16 17:09:34 +00:00
|
|
|
ValueData *value_data;
|
|
|
|
|
|
|
|
value_data = &g_array_index (data->values, ValueData, i);
|
|
|
|
|
2012-03-06 13:16:32 +00:00
|
|
|
_gtk_css_value_unref (value_data->value);
|
|
|
|
value_data->value = NULL;
|
2010-03-04 21:51:56 +00:00
|
|
|
}
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2011-01-17 03:06:57 +00:00
|
|
|
if (data->values->len > 0)
|
|
|
|
g_array_remove_range (data->values, 0, data->values->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
property_data_free (PropertyData *data)
|
|
|
|
{
|
|
|
|
property_data_remove_values (data);
|
2010-08-19 23:16:40 +00:00
|
|
|
g_array_free (data->values, TRUE);
|
2010-03-04 19:59:18 +00:00
|
|
|
g_slice_free (PropertyData, data);
|
|
|
|
}
|
|
|
|
|
2010-08-16 17:09:34 +00:00
|
|
|
static gboolean
|
|
|
|
property_data_find_position (PropertyData *data,
|
|
|
|
GtkStateFlags state,
|
|
|
|
guint *pos)
|
|
|
|
{
|
|
|
|
gint min, max, mid;
|
|
|
|
gboolean found = FALSE;
|
|
|
|
guint position;
|
|
|
|
|
|
|
|
if (pos)
|
|
|
|
*pos = 0;
|
|
|
|
|
|
|
|
if (data->values->len == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Find position for the given state, or the position where
|
|
|
|
* it would be if not found, the array is ordered by the
|
|
|
|
* state flags.
|
|
|
|
*/
|
|
|
|
min = 0;
|
|
|
|
max = data->values->len - 1;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ValueData *value_data;
|
|
|
|
|
|
|
|
mid = (min + max) / 2;
|
|
|
|
value_data = &g_array_index (data->values, ValueData, mid);
|
|
|
|
|
|
|
|
if (value_data->state == state)
|
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
position = mid;
|
|
|
|
}
|
|
|
|
else if (value_data->state < state)
|
|
|
|
position = min = mid + 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
max = mid - 1;
|
|
|
|
position = mid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (!found && min <= max);
|
|
|
|
|
|
|
|
if (pos)
|
|
|
|
*pos = position;
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:16:32 +00:00
|
|
|
static ValueData *
|
2010-08-16 17:09:34 +00:00
|
|
|
property_data_get_value (PropertyData *data,
|
|
|
|
GtkStateFlags state)
|
|
|
|
{
|
|
|
|
guint pos;
|
|
|
|
|
|
|
|
if (!property_data_find_position (data, state, &pos))
|
|
|
|
{
|
|
|
|
ValueData new = { 0 };
|
|
|
|
|
|
|
|
new.state = state;
|
|
|
|
g_array_insert_val (data->values, pos, new);
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:16:32 +00:00
|
|
|
return &g_array_index (data->values, ValueData, pos);
|
2010-08-16 17:09:34 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 13:16:32 +00:00
|
|
|
static GtkCssValue *
|
2010-08-16 17:09:34 +00:00
|
|
|
property_data_match_state (PropertyData *data,
|
|
|
|
GtkStateFlags state)
|
|
|
|
{
|
|
|
|
guint pos;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (property_data_find_position (data, state, &pos))
|
|
|
|
{
|
|
|
|
ValueData *val_data;
|
|
|
|
|
|
|
|
/* Exact match */
|
|
|
|
val_data = &g_array_index (data->values, ValueData, pos);
|
2012-03-06 13:16:32 +00:00
|
|
|
return val_data->value;
|
2010-08-16 17:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pos >= data->values->len)
|
|
|
|
pos = data->values->len - 1;
|
|
|
|
|
|
|
|
/* No exact match, go downwards the list to find
|
|
|
|
* the closest match to the given state flags, as
|
|
|
|
* a side effect, there is an implicit precedence
|
|
|
|
* of higher flags over the smaller ones.
|
|
|
|
*/
|
|
|
|
for (i = pos; i >= 0; i--)
|
|
|
|
{
|
|
|
|
ValueData *val_data;
|
|
|
|
|
|
|
|
val_data = &g_array_index (data->values, ValueData, i);
|
|
|
|
|
|
|
|
/* Check whether any of the requested
|
|
|
|
* flags are set, and no other flags are.
|
|
|
|
*
|
|
|
|
* Also, no flags acts as a wildcard, such
|
|
|
|
* value should be always in the first position
|
|
|
|
* in the array (if present) anyways.
|
|
|
|
*/
|
|
|
|
if (val_data->state == 0 ||
|
|
|
|
((val_data->state & state) != 0 &&
|
|
|
|
(val_data->state & ~state) == 0))
|
2012-03-06 13:16:32 +00:00
|
|
|
return val_data->value;
|
2010-08-16 17:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-03-04 19:59:18 +00:00
|
|
|
static void
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_init (GtkStyleProperties *props)
|
2010-03-04 19:59:18 +00:00
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
props->priv = gtk_style_properties_get_instance_private (props);
|
|
|
|
props->priv->properties = g_hash_table_new_full (NULL, NULL, NULL,
|
|
|
|
(GDestroyNotify) property_data_free);
|
2010-03-04 19:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_finalize (GObject *object)
|
2010-03-04 19:59:18 +00:00
|
|
|
{
|
2010-10-29 04:47:32 +00:00
|
|
|
GtkStylePropertiesPrivate *priv;
|
|
|
|
GtkStyleProperties *props;
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
props = GTK_STYLE_PROPERTIES (object);
|
|
|
|
priv = props->priv;
|
2010-03-04 19:59:18 +00:00
|
|
|
g_hash_table_destroy (priv->properties);
|
|
|
|
|
2010-06-25 17:37:54 +00:00
|
|
|
if (priv->color_map)
|
|
|
|
g_hash_table_destroy (priv->color_map);
|
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
G_OBJECT_CLASS (gtk_style_properties_parent_class)->finalize (object);
|
2010-03-04 19:59:18 +00:00
|
|
|
}
|
|
|
|
|
2010-03-04 21:51:56 +00:00
|
|
|
static void
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_provider_init (GtkStyleProviderIface *iface)
|
2010-03-04 21:51:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-11-25 01:28:59 +00:00
|
|
|
static GtkCssValue *
|
2011-12-28 21:59:55 +00:00
|
|
|
gtk_style_properties_provider_get_color (GtkStyleProviderPrivate *provider,
|
|
|
|
const char *name)
|
|
|
|
{
|
2012-11-25 02:34:08 +00:00
|
|
|
GtkSymbolicColor *symbolic;
|
|
|
|
|
|
|
|
symbolic = gtk_style_properties_lookup_color (GTK_STYLE_PROPERTIES (provider), name);
|
|
|
|
if (symbolic == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return _gtk_symbolic_color_get_css_value (symbolic);
|
2011-12-28 21:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_style_properties_provider_lookup (GtkStyleProviderPrivate *provider,
|
2012-03-17 01:36:11 +00:00
|
|
|
const GtkCssMatcher *matcher,
|
2014-12-09 18:31:17 +00:00
|
|
|
GtkCssLookup *lookup,
|
|
|
|
GtkCssChange *change)
|
2011-12-28 21:59:55 +00:00
|
|
|
{
|
|
|
|
GtkStyleProperties *props;
|
|
|
|
GtkStylePropertiesPrivate *priv;
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
|
|
|
|
|
|
|
props = GTK_STYLE_PROPERTIES (provider);
|
|
|
|
priv = props->priv;
|
|
|
|
|
|
|
|
/* Merge symbolic style properties */
|
|
|
|
g_hash_table_iter_init (&iter, priv->properties);
|
|
|
|
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
2011-12-31 18:45:17 +00:00
|
|
|
GtkCssStyleProperty *prop = key;
|
2011-12-28 21:59:55 +00:00
|
|
|
PropertyData *data = value;
|
2015-05-31 01:21:00 +00:00
|
|
|
GtkCssValue *val;
|
2011-12-28 21:59:55 +00:00
|
|
|
guint id;
|
|
|
|
|
2011-12-31 18:45:17 +00:00
|
|
|
id = _gtk_css_style_property_get_id (prop);
|
2011-12-28 21:59:55 +00:00
|
|
|
|
|
|
|
if (!_gtk_css_lookup_is_missing (lookup, id))
|
|
|
|
continue;
|
|
|
|
|
2015-05-31 01:21:00 +00:00
|
|
|
val = property_data_match_state (data, _gtk_css_matcher_get_state (matcher));
|
|
|
|
if (val == NULL)
|
2011-12-28 21:59:55 +00:00
|
|
|
continue;
|
|
|
|
|
2015-05-31 01:21:00 +00:00
|
|
|
_gtk_css_lookup_set (lookup, id, NULL, val);
|
2011-12-28 21:59:55 +00:00
|
|
|
}
|
|
|
|
|
2014-12-09 18:31:17 +00:00
|
|
|
if (change)
|
|
|
|
*change = GTK_CSS_CHANGE_STATE;
|
2012-03-17 20:09:51 +00:00
|
|
|
}
|
|
|
|
|
2011-12-28 21:59:55 +00:00
|
|
|
static void
|
|
|
|
gtk_style_properties_provider_private_init (GtkStyleProviderPrivateInterface *iface)
|
|
|
|
{
|
|
|
|
iface->get_color = gtk_style_properties_provider_get_color;
|
|
|
|
iface->lookup = gtk_style_properties_provider_lookup;
|
|
|
|
}
|
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
/* GtkStyleProperties methods */
|
2010-03-04 21:51:56 +00:00
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
2010-10-29 04:47:32 +00:00
|
|
|
* gtk_style_properties_new:
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
2010-10-29 04:47:32 +00:00
|
|
|
* Returns a newly created #GtkStyleProperties
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
2010-10-29 04:47:32 +00:00
|
|
|
* Returns: a new #GtkStyleProperties
|
2014-10-24 19:22:43 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.16: #GtkStyleProperties are deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-10-29 04:47:32 +00:00
|
|
|
GtkStyleProperties *
|
|
|
|
gtk_style_properties_new (void)
|
2010-03-04 19:59:18 +00:00
|
|
|
{
|
2010-10-29 04:47:32 +00:00
|
|
|
return g_object_new (GTK_TYPE_STYLE_PROPERTIES, NULL);
|
2010-03-04 19:59:18 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
2010-10-29 04:47:32 +00:00
|
|
|
* gtk_style_properties_map_color:
|
|
|
|
* @props: a #GtkStyleProperties
|
2010-10-19 08:59:46 +00:00
|
|
|
* @name: color name
|
|
|
|
* @color: #GtkSymbolicColor to map @name to
|
|
|
|
*
|
|
|
|
* Maps @color so it can be referenced by @name. See
|
2010-10-29 04:47:32 +00:00
|
|
|
* gtk_style_properties_lookup_color()
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
2012-11-25 02:34:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: #GtkSymbolicColor is deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-06-25 17:37:54 +00:00
|
|
|
void
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_map_color (GtkStyleProperties *props,
|
|
|
|
const gchar *name,
|
|
|
|
GtkSymbolicColor *color)
|
2010-06-25 17:37:54 +00:00
|
|
|
{
|
2010-10-29 04:47:32 +00:00
|
|
|
GtkStylePropertiesPrivate *priv;
|
2010-06-25 17:37:54 +00:00
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
|
2010-06-25 17:37:54 +00:00
|
|
|
g_return_if_fail (name != NULL);
|
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
priv = props->priv;
|
2010-06-25 17:37:54 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (!priv->color_map))
|
|
|
|
priv->color_map = g_hash_table_new_full (g_str_hash,
|
|
|
|
g_str_equal,
|
|
|
|
(GDestroyNotify) g_free,
|
|
|
|
(GDestroyNotify) gtk_symbolic_color_unref);
|
|
|
|
|
|
|
|
g_hash_table_replace (priv->color_map,
|
|
|
|
g_strdup (name),
|
|
|
|
gtk_symbolic_color_ref (color));
|
2012-04-08 15:35:24 +00:00
|
|
|
|
|
|
|
_gtk_style_provider_private_changed (GTK_STYLE_PROVIDER_PRIVATE (props));
|
2010-06-25 17:37:54 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
2010-10-29 04:47:32 +00:00
|
|
|
* gtk_style_properties_lookup_color:
|
|
|
|
* @props: a #GtkStyleProperties
|
2010-10-19 08:59:46 +00:00
|
|
|
* @name: color name to lookup
|
|
|
|
*
|
|
|
|
* Returns the symbolic color that is mapped
|
|
|
|
* to @name.
|
|
|
|
*
|
2011-01-18 09:01:17 +00:00
|
|
|
* Returns: (transfer none): The mapped color
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
2012-11-25 02:34:08 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: #GtkSymbolicColor is deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-06-25 17:37:54 +00:00
|
|
|
GtkSymbolicColor *
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_lookup_color (GtkStyleProperties *props,
|
|
|
|
const gchar *name)
|
2010-06-25 17:37:54 +00:00
|
|
|
{
|
2010-10-29 04:47:32 +00:00
|
|
|
GtkStylePropertiesPrivate *priv;
|
2010-06-25 17:37:54 +00:00
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), NULL);
|
2010-06-25 17:37:54 +00:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
priv = props->priv;
|
2010-06-25 17:37:54 +00:00
|
|
|
|
|
|
|
if (!priv->color_map)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return g_hash_table_lookup (priv->color_map, name);
|
|
|
|
}
|
|
|
|
|
2010-08-16 17:09:34 +00:00
|
|
|
void
|
2011-12-31 18:45:17 +00:00
|
|
|
_gtk_style_properties_set_property_by_property (GtkStyleProperties *props,
|
|
|
|
GtkCssStyleProperty *style_prop,
|
|
|
|
GtkStateFlags state,
|
2012-03-06 13:16:32 +00:00
|
|
|
GtkCssValue *value)
|
2010-03-04 19:59:18 +00:00
|
|
|
{
|
2010-10-29 04:47:32 +00:00
|
|
|
GtkStylePropertiesPrivate *priv;
|
2010-03-04 19:59:18 +00:00
|
|
|
PropertyData *prop;
|
2012-03-06 13:16:32 +00:00
|
|
|
ValueData *val;
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
priv = props->priv;
|
2011-05-28 02:36:48 +00:00
|
|
|
prop = g_hash_table_lookup (priv->properties, style_prop);
|
2010-03-04 19:59:18 +00:00
|
|
|
|
|
|
|
if (!prop)
|
|
|
|
{
|
|
|
|
prop = property_data_new ();
|
2011-05-28 02:36:48 +00:00
|
|
|
g_hash_table_insert (priv->properties, (gpointer) style_prop, prop);
|
2010-03-04 19:59:18 +00:00
|
|
|
}
|
|
|
|
|
2010-08-16 17:09:34 +00:00
|
|
|
val = property_data_get_value (prop, state);
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2012-03-06 13:16:32 +00:00
|
|
|
_gtk_css_value_unref (val->value);
|
|
|
|
val->value = _gtk_css_value_ref (value);
|
2012-04-08 15:35:24 +00:00
|
|
|
|
|
|
|
_gtk_style_provider_private_changed (GTK_STYLE_PROVIDER_PRIVATE (props));
|
2010-03-04 19:59:18 +00:00
|
|
|
}
|
|
|
|
|
2011-05-16 21:37:29 +00:00
|
|
|
/**
|
|
|
|
* gtk_style_properties_set_property:
|
|
|
|
* @props: a #GtkStyleProperties
|
|
|
|
* @property: styling property to set
|
|
|
|
* @state: state to set the value for
|
|
|
|
* @value: new value for the property
|
|
|
|
*
|
|
|
|
* Sets a styling property in @props.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2014-10-24 19:22:43 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.16: #GtkStyleProperties are deprecated.
|
2011-05-16 21:37:29 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_style_properties_set_property (GtkStyleProperties *props,
|
|
|
|
const gchar *property,
|
|
|
|
GtkStateFlags state,
|
|
|
|
const GValue *value)
|
|
|
|
{
|
2011-12-31 15:08:23 +00:00
|
|
|
GtkStyleProperty *node;
|
2011-05-16 21:37:29 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
|
|
|
|
g_return_if_fail (property != NULL);
|
|
|
|
g_return_if_fail (value != NULL);
|
|
|
|
|
2011-05-19 12:00:14 +00:00
|
|
|
node = _gtk_style_property_lookup (property);
|
2011-05-16 21:37:29 +00:00
|
|
|
|
|
|
|
if (!node)
|
|
|
|
{
|
|
|
|
g_warning ("Style property \"%s\" is not registered", property);
|
|
|
|
return;
|
|
|
|
}
|
2011-12-31 18:03:53 +00:00
|
|
|
if (_gtk_style_property_get_value_type (node) == G_TYPE_NONE)
|
|
|
|
{
|
|
|
|
g_warning ("Style property \"%s\" is not settable", property);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_gtk_style_property_assign (node, props, state, value);
|
2011-05-16 21:37:29 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
2010-10-29 04:47:32 +00:00
|
|
|
* gtk_style_properties_set_valist:
|
|
|
|
* @props: a #GtkStyleProperties
|
2010-10-19 08:59:46 +00:00
|
|
|
* @state: state to set the values for
|
|
|
|
* @args: va_list of property name/value pairs, followed by %NULL
|
|
|
|
*
|
2010-10-29 04:47:32 +00:00
|
|
|
* Sets several style properties on @props.
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
2014-10-24 19:22:43 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.16: #GtkStyleProperties are deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-05-04 17:55:19 +00:00
|
|
|
void
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_set_valist (GtkStyleProperties *props,
|
|
|
|
GtkStateFlags state,
|
|
|
|
va_list args)
|
2010-03-05 02:02:59 +00:00
|
|
|
{
|
|
|
|
const gchar *property_name;
|
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
|
2010-03-05 02:02:59 +00:00
|
|
|
|
|
|
|
property_name = va_arg (args, const gchar *);
|
|
|
|
|
|
|
|
while (property_name)
|
|
|
|
{
|
2011-12-31 15:08:23 +00:00
|
|
|
GtkStyleProperty *node;
|
2010-03-05 02:02:59 +00:00
|
|
|
gchar *error = NULL;
|
2011-12-31 16:58:30 +00:00
|
|
|
GType val_type;
|
2011-09-30 15:31:04 +00:00
|
|
|
GValue val = G_VALUE_INIT;
|
2010-03-05 02:02:59 +00:00
|
|
|
|
2011-05-19 12:00:14 +00:00
|
|
|
node = _gtk_style_property_lookup (property_name);
|
2010-03-05 02:02:59 +00:00
|
|
|
|
|
|
|
if (!node)
|
|
|
|
{
|
|
|
|
g_warning ("Style property \"%s\" is not registered", property_name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-31 16:58:30 +00:00
|
|
|
val_type = _gtk_style_property_get_value_type (node);
|
|
|
|
if (val_type == G_TYPE_NONE)
|
|
|
|
{
|
|
|
|
g_warning ("Style property \"%s\" is not settable", property_name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_VALUE_COLLECT_INIT (&val, _gtk_style_property_get_value_type (node),
|
2011-02-05 17:54:02 +00:00
|
|
|
args, 0, &error);
|
2010-03-05 02:02:59 +00:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_warning ("Could not set style property \"%s\": %s", property_name, error);
|
2011-05-21 19:19:57 +00:00
|
|
|
g_value_unset (&val);
|
2010-08-16 17:09:34 +00:00
|
|
|
g_free (error);
|
2010-03-05 02:02:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-31 18:03:53 +00:00
|
|
|
_gtk_style_property_assign (node, props, state, &val);
|
2011-05-21 19:19:57 +00:00
|
|
|
g_value_unset (&val);
|
|
|
|
|
2010-03-05 02:02:59 +00:00
|
|
|
property_name = va_arg (args, const gchar *);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
2010-10-29 04:47:32 +00:00
|
|
|
* gtk_style_properties_set:
|
|
|
|
* @props: a #GtkStyleProperties
|
2010-10-19 08:59:46 +00:00
|
|
|
* @state: state to set the values for
|
|
|
|
* @...: property name/value pairs, followed by %NULL
|
|
|
|
*
|
2010-10-29 04:47:32 +00:00
|
|
|
* Sets several style properties on @props.
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
2014-10-24 19:22:43 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.16: #GtkStyleProperties are deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-03-05 02:02:59 +00:00
|
|
|
void
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_set (GtkStyleProperties *props,
|
|
|
|
GtkStateFlags state,
|
|
|
|
...)
|
2010-03-05 02:02:59 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
|
2010-03-05 02:02:59 +00:00
|
|
|
|
|
|
|
va_start (args, state);
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_set_valist (props, state, args);
|
2010-03-05 02:02:59 +00:00
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
2012-01-11 01:43:16 +00:00
|
|
|
typedef struct {
|
|
|
|
GtkStyleProperties *props;
|
|
|
|
GtkStateFlags state;
|
|
|
|
} StyleQueryData;
|
|
|
|
|
2012-03-06 13:16:32 +00:00
|
|
|
static GtkCssValue *
|
2012-01-11 01:43:16 +00:00
|
|
|
style_query_func (guint id,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
StyleQueryData *query = data;
|
2014-10-24 19:03:36 +00:00
|
|
|
PropertyData *prop;
|
|
|
|
|
|
|
|
prop = g_hash_table_lookup (query->props->priv->properties,
|
|
|
|
_gtk_css_style_property_lookup_by_id (id));
|
|
|
|
if (prop == NULL)
|
|
|
|
return NULL;
|
2012-01-11 01:43:16 +00:00
|
|
|
|
2014-10-24 19:03:36 +00:00
|
|
|
return property_data_match_state (prop, query->state);
|
2012-01-11 01:43:16 +00:00
|
|
|
}
|
|
|
|
|
2012-01-02 18:22:30 +00:00
|
|
|
/**
|
|
|
|
* gtk_style_properties_get_property:
|
|
|
|
* @props: a #GtkStyleProperties
|
|
|
|
* @property: style property name
|
|
|
|
* @state: state to retrieve the property value for
|
|
|
|
* @value: (out) (transfer full): return location for the style property value.
|
|
|
|
*
|
|
|
|
* Gets a style property from @props for the given state. When done with @value,
|
|
|
|
* g_value_unset() needs to be called to free any allocated memory.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the property exists in @props, %FALSE otherwise
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2014-10-24 19:22:43 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.16: #GtkStyleProperties are deprecated.
|
2012-01-02 18:22:30 +00:00
|
|
|
**/
|
2010-03-04 19:59:18 +00:00
|
|
|
gboolean
|
2012-01-02 18:22:30 +00:00
|
|
|
gtk_style_properties_get_property (GtkStyleProperties *props,
|
|
|
|
const gchar *property,
|
|
|
|
GtkStateFlags state,
|
|
|
|
GValue *value)
|
2010-03-04 19:59:18 +00:00
|
|
|
{
|
2012-01-11 01:43:16 +00:00
|
|
|
StyleQueryData query = { props, state };
|
2011-12-31 15:08:23 +00:00
|
|
|
GtkStyleProperty *node;
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
|
2010-03-04 19:59:18 +00:00
|
|
|
g_return_val_if_fail (property != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (value != NULL, FALSE);
|
|
|
|
|
2011-11-15 16:10:22 +00:00
|
|
|
node = _gtk_style_property_lookup (property);
|
2010-03-05 01:06:53 +00:00
|
|
|
if (!node)
|
2011-11-15 16:10:22 +00:00
|
|
|
{
|
|
|
|
g_warning ("Style property \"%s\" is not registered", property);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-12-31 16:58:30 +00:00
|
|
|
if (_gtk_style_property_get_value_type (node) == G_TYPE_NONE)
|
|
|
|
{
|
|
|
|
g_warning ("Style property \"%s\" is not gettable", property);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-11-15 16:10:22 +00:00
|
|
|
|
2012-03-26 05:08:24 +00:00
|
|
|
_gtk_style_property_query (node,
|
|
|
|
value,
|
|
|
|
style_query_func,
|
|
|
|
&query);
|
2012-03-06 13:16:32 +00:00
|
|
|
|
2010-03-04 19:59:18 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
2012-01-02 18:22:30 +00:00
|
|
|
* gtk_style_properties_get_valist:
|
2010-10-29 04:47:32 +00:00
|
|
|
* @props: a #GtkStyleProperties
|
2012-01-02 18:22:30 +00:00
|
|
|
* @state: state to retrieve the property values for
|
|
|
|
* @args: va_list of property name/return location pairs, followed by %NULL
|
2011-11-15 15:56:59 +00:00
|
|
|
*
|
2012-01-02 18:22:30 +00:00
|
|
|
* Retrieves several style property values from @props for a given state.
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
2014-10-24 19:22:43 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.16: #GtkStyleProperties are deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-03-05 02:02:59 +00:00
|
|
|
void
|
2012-01-02 18:22:30 +00:00
|
|
|
gtk_style_properties_get_valist (GtkStyleProperties *props,
|
|
|
|
GtkStateFlags state,
|
|
|
|
va_list args)
|
2010-03-05 02:02:59 +00:00
|
|
|
{
|
|
|
|
const gchar *property_name;
|
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
|
2010-03-05 02:02:59 +00:00
|
|
|
|
|
|
|
property_name = va_arg (args, const gchar *);
|
|
|
|
|
|
|
|
while (property_name)
|
|
|
|
{
|
|
|
|
gchar *error = NULL;
|
2011-11-15 16:10:22 +00:00
|
|
|
GValue value = G_VALUE_INIT;
|
2011-05-21 21:47:19 +00:00
|
|
|
|
2012-01-02 18:22:30 +00:00
|
|
|
if (!gtk_style_properties_get_property (props,
|
|
|
|
property_name,
|
|
|
|
state,
|
|
|
|
&value))
|
2011-11-15 16:10:22 +00:00
|
|
|
break;
|
2010-03-05 02:02:59 +00:00
|
|
|
|
2011-11-15 16:10:22 +00:00
|
|
|
G_VALUE_LCOPY (&value, args, 0, &error);
|
|
|
|
g_value_unset (&value);
|
2010-09-01 23:58:48 +00:00
|
|
|
|
2010-03-05 02:02:59 +00:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_warning ("Could not get style property \"%s\": %s", property_name, error);
|
2010-06-13 15:10:05 +00:00
|
|
|
g_free (error);
|
2010-03-05 02:02:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
property_name = va_arg (args, const gchar *);
|
|
|
|
}
|
|
|
|
}
|
2011-11-15 15:56:59 +00:00
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
2010-10-29 04:47:32 +00:00
|
|
|
* gtk_style_properties_get:
|
|
|
|
* @props: a #GtkStyleProperties
|
2010-10-19 08:59:46 +00:00
|
|
|
* @state: state to retrieve the property values for
|
|
|
|
* @...: property name /return value pairs, followed by %NULL
|
|
|
|
*
|
2010-10-29 04:47:32 +00:00
|
|
|
* Retrieves several style property values from @props for a
|
2010-10-19 08:59:46 +00:00
|
|
|
* given state.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2014-10-24 19:22:43 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.16: #GtkStyleProperties are deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-03-05 02:02:59 +00:00
|
|
|
void
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_get (GtkStyleProperties *props,
|
|
|
|
GtkStateFlags state,
|
|
|
|
...)
|
2010-03-05 02:02:59 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
|
2010-03-05 02:02:59 +00:00
|
|
|
|
|
|
|
va_start (args, state);
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_get_valist (props, state, args);
|
2010-03-05 02:02:59 +00:00
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
2010-10-29 04:47:32 +00:00
|
|
|
* gtk_style_properties_unset_property:
|
|
|
|
* @props: a #GtkStyleProperties
|
2010-10-19 08:59:46 +00:00
|
|
|
* @property: property to unset
|
|
|
|
* @state: state to unset
|
|
|
|
*
|
2010-10-29 04:47:32 +00:00
|
|
|
* Unsets a style property in @props.
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
2014-10-24 19:22:43 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.16: #GtkStyleProperties are deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-03-04 19:59:18 +00:00
|
|
|
void
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_unset_property (GtkStyleProperties *props,
|
|
|
|
const gchar *property,
|
|
|
|
GtkStateFlags state)
|
2010-03-04 19:59:18 +00:00
|
|
|
{
|
2010-10-29 04:47:32 +00:00
|
|
|
GtkStylePropertiesPrivate *priv;
|
2011-12-31 15:08:23 +00:00
|
|
|
GtkStyleProperty *node;
|
2010-03-04 19:59:18 +00:00
|
|
|
PropertyData *prop;
|
2010-08-16 17:09:34 +00:00
|
|
|
guint pos;
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
|
2010-03-04 19:59:18 +00:00
|
|
|
g_return_if_fail (property != NULL);
|
|
|
|
|
2011-05-19 12:00:14 +00:00
|
|
|
node = _gtk_style_property_lookup (property);
|
2010-03-05 01:06:53 +00:00
|
|
|
|
|
|
|
if (!node)
|
|
|
|
{
|
|
|
|
g_warning ("Style property \"%s\" is not registered", property);
|
|
|
|
return;
|
|
|
|
}
|
2011-12-31 21:17:25 +00:00
|
|
|
if (_gtk_style_property_get_value_type (node) == G_TYPE_NONE)
|
|
|
|
{
|
|
|
|
g_warning ("Style property \"%s\" is not settable", property);
|
|
|
|
return;
|
|
|
|
}
|
2010-03-05 01:06:53 +00:00
|
|
|
|
2011-12-31 21:17:25 +00:00
|
|
|
if (GTK_IS_CSS_SHORTHAND_PROPERTY (node))
|
2011-07-19 09:11:12 +00:00
|
|
|
{
|
2011-12-31 21:17:25 +00:00
|
|
|
GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (node);
|
|
|
|
|
|
|
|
for (pos = 0; pos < _gtk_css_shorthand_property_get_n_subproperties (shorthand); pos++)
|
|
|
|
{
|
|
|
|
GtkCssStyleProperty *sub = _gtk_css_shorthand_property_get_subproperty (shorthand, pos);
|
|
|
|
gtk_style_properties_unset_property (props,
|
|
|
|
_gtk_style_property_get_name (GTK_STYLE_PROPERTY (sub)),
|
|
|
|
state);
|
|
|
|
}
|
2011-07-19 09:11:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
priv = props->priv;
|
2011-05-28 02:36:48 +00:00
|
|
|
prop = g_hash_table_lookup (priv->properties, node);
|
2010-03-04 19:59:18 +00:00
|
|
|
|
|
|
|
if (!prop)
|
|
|
|
return;
|
|
|
|
|
2010-08-16 17:09:34 +00:00
|
|
|
if (property_data_find_position (prop, state, &pos))
|
|
|
|
{
|
|
|
|
ValueData *data;
|
|
|
|
|
|
|
|
data = &g_array_index (prop->values, ValueData, pos);
|
|
|
|
|
2012-03-06 13:16:32 +00:00
|
|
|
_gtk_css_value_unref (data->value);
|
|
|
|
data->value = NULL;
|
2010-08-16 17:09:34 +00:00
|
|
|
|
|
|
|
g_array_remove_index (prop->values, pos);
|
2012-04-08 15:35:24 +00:00
|
|
|
|
|
|
|
_gtk_style_provider_private_changed (GTK_STYLE_PROVIDER_PRIVATE (props));
|
2010-08-16 17:09:34 +00:00
|
|
|
}
|
2010-03-04 19:59:18 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
2010-10-29 04:47:32 +00:00
|
|
|
* gtk_style_properties_clear:
|
|
|
|
* @props: a #GtkStyleProperties
|
2010-10-19 08:59:46 +00:00
|
|
|
*
|
2010-10-29 04:47:32 +00:00
|
|
|
* Clears all style information from @props.
|
2014-10-24 19:22:43 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.16: #GtkStyleProperties are deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-03-04 19:59:18 +00:00
|
|
|
void
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_clear (GtkStyleProperties *props)
|
2010-03-04 19:59:18 +00:00
|
|
|
{
|
2010-10-29 04:47:32 +00:00
|
|
|
GtkStylePropertiesPrivate *priv;
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
priv = props->priv;
|
2010-03-04 19:59:18 +00:00
|
|
|
g_hash_table_remove_all (priv->properties);
|
2012-04-08 15:35:24 +00:00
|
|
|
|
|
|
|
_gtk_style_provider_private_changed (GTK_STYLE_PROVIDER_PRIVATE (props));
|
2010-03-04 19:59:18 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 08:59:46 +00:00
|
|
|
/**
|
2010-10-29 04:47:32 +00:00
|
|
|
* gtk_style_properties_merge:
|
|
|
|
* @props: a #GtkStyleProperties
|
|
|
|
* @props_to_merge: a second #GtkStyleProperties
|
2010-10-19 08:59:46 +00:00
|
|
|
* @replace: whether to replace values or not
|
|
|
|
*
|
2010-10-29 04:47:32 +00:00
|
|
|
* Merges into @props all the style information contained
|
|
|
|
* in @props_to_merge. If @replace is %TRUE, the values
|
2010-10-19 08:59:46 +00:00
|
|
|
* will be overwritten, if it is %FALSE, the older values
|
|
|
|
* will prevail.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
2014-10-24 19:22:43 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.16: #GtkStyleProperties are deprecated.
|
2010-10-19 08:59:46 +00:00
|
|
|
**/
|
2010-03-04 19:59:18 +00:00
|
|
|
void
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_merge (GtkStyleProperties *props,
|
|
|
|
const GtkStyleProperties *props_to_merge,
|
|
|
|
gboolean replace)
|
2010-03-04 19:59:18 +00:00
|
|
|
{
|
2010-10-29 04:47:32 +00:00
|
|
|
GtkStylePropertiesPrivate *priv, *priv_to_merge;
|
2010-03-04 19:59:18 +00:00
|
|
|
GHashTableIter iter;
|
2015-05-31 01:21:00 +00:00
|
|
|
gpointer key, val;
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
|
|
|
|
g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props_to_merge));
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
priv = props->priv;
|
|
|
|
priv_to_merge = props_to_merge->priv;
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-06-25 17:37:54 +00:00
|
|
|
/* Merge symbolic color map */
|
|
|
|
if (priv_to_merge->color_map)
|
|
|
|
{
|
|
|
|
g_hash_table_iter_init (&iter, priv_to_merge->color_map);
|
|
|
|
|
2015-05-31 01:21:00 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, &key, &val))
|
2010-06-25 17:37:54 +00:00
|
|
|
{
|
|
|
|
const gchar *name;
|
|
|
|
GtkSymbolicColor *color;
|
|
|
|
|
|
|
|
name = key;
|
2015-05-31 01:21:00 +00:00
|
|
|
color = val;
|
2010-06-25 17:37:54 +00:00
|
|
|
|
|
|
|
if (!replace &&
|
|
|
|
g_hash_table_lookup (priv->color_map, name))
|
|
|
|
continue;
|
|
|
|
|
2010-10-29 04:47:32 +00:00
|
|
|
gtk_style_properties_map_color (props, name, color);
|
2010-06-25 17:37:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Merge symbolic style properties */
|
2010-03-04 19:59:18 +00:00
|
|
|
g_hash_table_iter_init (&iter, priv_to_merge->properties);
|
|
|
|
|
2015-05-31 01:21:00 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, &key, &val))
|
2010-03-04 19:59:18 +00:00
|
|
|
{
|
2015-05-31 01:21:00 +00:00
|
|
|
PropertyData *prop_to_merge = val;
|
2010-08-16 17:09:34 +00:00
|
|
|
PropertyData *prop;
|
|
|
|
guint i;
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-08-16 17:09:34 +00:00
|
|
|
prop = g_hash_table_lookup (priv->properties, key);
|
|
|
|
|
|
|
|
if (!prop)
|
2010-03-04 19:59:18 +00:00
|
|
|
{
|
2010-08-16 17:09:34 +00:00
|
|
|
prop = property_data_new ();
|
|
|
|
g_hash_table_insert (priv->properties, key, prop);
|
|
|
|
}
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-08-16 17:09:34 +00:00
|
|
|
for (i = 0; i < prop_to_merge->values->len; i++)
|
|
|
|
{
|
|
|
|
ValueData *data;
|
2012-03-06 13:16:32 +00:00
|
|
|
ValueData *value;
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-08-16 17:09:34 +00:00
|
|
|
data = &g_array_index (prop_to_merge->values, ValueData, i);
|
2011-01-17 03:06:57 +00:00
|
|
|
|
|
|
|
if (replace && data->state == GTK_STATE_FLAG_NORMAL &&
|
2012-04-07 05:40:36 +00:00
|
|
|
_gtk_is_css_typed_value_of_type (data->value, PANGO_TYPE_FONT_DESCRIPTION))
|
2011-01-17 03:06:57 +00:00
|
|
|
{
|
|
|
|
/* Let normal state override all states
|
|
|
|
* previously set in the original set
|
|
|
|
*/
|
|
|
|
property_data_remove_values (prop);
|
|
|
|
}
|
|
|
|
|
2010-08-16 17:09:34 +00:00
|
|
|
value = property_data_get_value (prop, data->state);
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2012-04-07 05:40:36 +00:00
|
|
|
if (_gtk_is_css_typed_value_of_type (data->value, PANGO_TYPE_FONT_DESCRIPTION) &&
|
2012-03-06 13:16:32 +00:00
|
|
|
value->value != NULL)
|
2010-11-03 10:36:18 +00:00
|
|
|
{
|
|
|
|
PangoFontDescription *font_desc;
|
|
|
|
PangoFontDescription *font_desc_to_merge;
|
|
|
|
|
|
|
|
/* Handle merging of font descriptions */
|
2012-04-07 05:40:36 +00:00
|
|
|
font_desc = g_value_get_boxed (_gtk_css_typed_value_get (value->value));
|
|
|
|
font_desc_to_merge = g_value_get_boxed (_gtk_css_typed_value_get (data->value));
|
2010-11-03 10:36:18 +00:00
|
|
|
|
2011-03-22 18:35:23 +00:00
|
|
|
pango_font_description_merge (font_desc, font_desc_to_merge, replace);
|
2010-11-03 10:36:18 +00:00
|
|
|
}
|
2012-04-07 05:40:36 +00:00
|
|
|
else if (_gtk_is_css_typed_value_of_type (data->value, G_TYPE_PTR_ARRAY) &&
|
2012-03-06 13:16:32 +00:00
|
|
|
value->value != NULL)
|
2011-01-28 08:59:02 +00:00
|
|
|
{
|
|
|
|
GPtrArray *array, *array_to_merge;
|
|
|
|
|
|
|
|
/* Append the array, mainly thought
|
|
|
|
* for the gtk-key-bindings property
|
|
|
|
*/
|
2012-04-07 05:40:36 +00:00
|
|
|
array = g_value_get_boxed (_gtk_css_typed_value_get (value->value));
|
|
|
|
array_to_merge = g_value_get_boxed (_gtk_css_typed_value_get (data->value));
|
2011-01-28 08:59:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < array_to_merge->len; i++)
|
|
|
|
g_ptr_array_add (array, g_ptr_array_index (array_to_merge, i));
|
|
|
|
}
|
2012-03-06 13:16:32 +00:00
|
|
|
else if (replace || value->value == NULL)
|
2010-03-04 19:59:18 +00:00
|
|
|
{
|
2012-03-06 13:16:32 +00:00
|
|
|
_gtk_css_value_unref (value->value);
|
|
|
|
value->value = _gtk_css_value_ref (data->value);
|
2010-03-04 19:59:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-08 15:35:24 +00:00
|
|
|
|
|
|
|
_gtk_style_provider_private_changed (GTK_STYLE_PROVIDER_PRIVATE (props));
|
2010-03-04 19:59:18 +00:00
|
|
|
}
|
2014-10-24 19:22:43 +00:00
|
|
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|