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
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2010-03-05 00:45:47 +00:00
|
|
|
#include <stdlib.h>
|
2010-03-05 02:02:59 +00:00
|
|
|
#include <gobject/gvaluecollector.h>
|
2010-03-05 00:45:47 +00:00
|
|
|
|
2010-03-04 21:51:56 +00:00
|
|
|
#include "gtkstyleprovider.h"
|
2010-03-04 19:59:18 +00:00
|
|
|
#include "gtkstyleset.h"
|
|
|
|
#include "gtkprivate.h"
|
2010-06-13 15:31:22 +00:00
|
|
|
#include "gtkthemingengine.h"
|
2010-03-04 19:59:18 +00:00
|
|
|
#include "gtkintl.h"
|
|
|
|
|
|
|
|
#include "gtkalias.h"
|
|
|
|
|
|
|
|
typedef struct GtkStyleSetPrivate GtkStyleSetPrivate;
|
|
|
|
typedef struct PropertyData PropertyData;
|
2010-03-05 00:45:47 +00:00
|
|
|
typedef struct PropertyNode PropertyNode;
|
|
|
|
|
|
|
|
struct PropertyNode
|
|
|
|
{
|
|
|
|
GQuark property_quark;
|
|
|
|
GType property_type;
|
|
|
|
};
|
2010-03-04 19:59:18 +00:00
|
|
|
|
|
|
|
struct PropertyData
|
|
|
|
{
|
2010-05-04 17:55:19 +00:00
|
|
|
GValue default_value;
|
2010-03-04 19:59:18 +00:00
|
|
|
GValue values[GTK_STATE_LAST];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GtkStyleSetPrivate
|
|
|
|
{
|
2010-06-25 17:37:54 +00:00
|
|
|
GHashTable *color_map;
|
2010-03-04 19:59:18 +00:00
|
|
|
GHashTable *properties;
|
|
|
|
};
|
|
|
|
|
2010-03-05 00:45:47 +00:00
|
|
|
static GArray *properties = NULL;
|
|
|
|
|
2010-03-04 19:59:18 +00:00
|
|
|
#define GTK_STYLE_SET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_STYLE_SET, GtkStyleSetPrivate))
|
|
|
|
|
2010-03-04 21:51:56 +00:00
|
|
|
static void gtk_style_set_provider_init (GtkStyleProviderIface *iface);
|
|
|
|
static void gtk_style_set_finalize (GObject *object);
|
2010-03-04 19:59:18 +00:00
|
|
|
|
|
|
|
|
2010-03-04 21:51:56 +00:00
|
|
|
G_DEFINE_TYPE_EXTENDED (GtkStyleSet, gtk_style_set, G_TYPE_OBJECT, 0,
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
|
|
|
|
gtk_style_set_provider_init));
|
2010-03-04 19:59:18 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_style_set_class_init (GtkStyleSetClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gtk_style_set_finalize;
|
|
|
|
|
2010-03-05 00:45:47 +00:00
|
|
|
/* Initialize default property set */
|
2010-06-13 15:10:05 +00:00
|
|
|
gtk_style_set_register_property ("foreground-color", GDK_TYPE_COLOR);
|
|
|
|
gtk_style_set_register_property ("background-color", GDK_TYPE_COLOR);
|
|
|
|
gtk_style_set_register_property ("text-color", GDK_TYPE_COLOR);
|
|
|
|
gtk_style_set_register_property ("base-color", GDK_TYPE_COLOR);
|
2010-03-05 00:45:47 +00:00
|
|
|
|
2010-06-13 15:10:05 +00:00
|
|
|
gtk_style_set_register_property ("font", PANGO_TYPE_FONT_DESCRIPTION);
|
2010-03-07 18:07:27 +00:00
|
|
|
|
2010-06-13 15:10:05 +00:00
|
|
|
gtk_style_set_register_property ("padding", GTK_TYPE_BORDER);
|
2010-06-13 15:31:22 +00:00
|
|
|
gtk_style_set_register_property ("engine", GTK_TYPE_THEMING_ENGINE);
|
2010-03-07 18:57:53 +00:00
|
|
|
|
2010-03-04 19:59:18 +00:00
|
|
|
g_type_class_add_private (object_class, sizeof (GtkStyleSetPrivate));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PropertyData *
|
|
|
|
property_data_new (void)
|
|
|
|
{
|
|
|
|
PropertyData *data;
|
|
|
|
|
|
|
|
data = g_slice_new0 (PropertyData);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
property_data_free (PropertyData *data)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i <= GTK_STATE_INSENSITIVE; i++)
|
2010-03-04 21:51:56 +00:00
|
|
|
{
|
|
|
|
if (G_IS_VALUE (&data->values[i]))
|
|
|
|
g_value_unset (&data->values[i]);
|
|
|
|
}
|
2010-03-04 19:59:18 +00:00
|
|
|
|
|
|
|
g_slice_free (PropertyData, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_style_set_init (GtkStyleSet *set)
|
|
|
|
{
|
|
|
|
GtkStyleSetPrivate *priv;
|
|
|
|
|
|
|
|
priv = GTK_STYLE_SET_GET_PRIVATE (set);
|
2010-03-05 01:06:53 +00:00
|
|
|
priv->properties = g_hash_table_new_full (NULL, NULL, NULL,
|
2010-03-04 19:59:18 +00:00
|
|
|
(GDestroyNotify) property_data_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_style_set_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkStyleSetPrivate *priv;
|
|
|
|
|
|
|
|
priv = GTK_STYLE_SET_GET_PRIVATE (object);
|
|
|
|
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-03-04 19:59:18 +00:00
|
|
|
G_OBJECT_CLASS (gtk_style_set_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2010-03-04 21:51:56 +00:00
|
|
|
GtkStyleSet *
|
2010-04-11 18:30:24 +00:00
|
|
|
gtk_style_set_get_style (GtkStyleProvider *provider,
|
|
|
|
GtkWidgetPath *path)
|
2010-03-04 21:51:56 +00:00
|
|
|
{
|
|
|
|
/* Return style set itself */
|
|
|
|
return g_object_ref (provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_style_set_provider_init (GtkStyleProviderIface *iface)
|
|
|
|
{
|
|
|
|
iface->get_style = gtk_style_set_get_style;
|
|
|
|
}
|
|
|
|
|
2010-03-05 00:45:47 +00:00
|
|
|
static int
|
|
|
|
compare_property (gconstpointer p1,
|
|
|
|
gconstpointer p2)
|
|
|
|
{
|
|
|
|
PropertyNode *key = (PropertyNode *) p1;
|
|
|
|
PropertyNode *node = (PropertyNode *) p2;
|
|
|
|
|
|
|
|
return (int) key->property_quark - node->property_quark;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PropertyNode *
|
|
|
|
property_node_lookup (GQuark quark)
|
|
|
|
{
|
|
|
|
PropertyNode key = { 0 };
|
|
|
|
|
|
|
|
if (!quark)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!properties)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
key.property_quark = quark;
|
|
|
|
|
|
|
|
return bsearch (&key, properties->data, properties->len,
|
|
|
|
sizeof (PropertyNode), compare_property);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Property registration functions */
|
|
|
|
void
|
2010-04-11 17:52:58 +00:00
|
|
|
gtk_style_set_register_property (const gchar *property_name,
|
2010-06-13 15:10:05 +00:00
|
|
|
GType type)
|
2010-03-05 00:45:47 +00:00
|
|
|
{
|
|
|
|
PropertyNode *node, new = { 0 };
|
|
|
|
GQuark quark;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_if_fail (property_name != NULL);
|
2010-06-13 15:10:05 +00:00
|
|
|
g_return_if_fail (type != 0);
|
2010-03-05 00:45:47 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (!properties))
|
|
|
|
properties = g_array_new (FALSE, TRUE, sizeof (PropertyNode));
|
|
|
|
|
|
|
|
quark = g_quark_try_string (property_name);
|
|
|
|
|
|
|
|
if ((node = property_node_lookup (quark)) != NULL)
|
|
|
|
{
|
|
|
|
g_warning ("Property \"%s\" was already registered with type %s",
|
|
|
|
property_name, g_type_name (node->property_type));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
quark = g_quark_from_string (property_name);
|
|
|
|
|
|
|
|
new.property_quark = quark;
|
|
|
|
new.property_type = type;
|
|
|
|
|
|
|
|
for (i = 0; i < properties->len; i++)
|
|
|
|
{
|
|
|
|
node = &g_array_index (properties, PropertyNode, i);
|
|
|
|
|
|
|
|
if (node->property_quark > quark)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_insert_val (properties, i, new);
|
|
|
|
}
|
|
|
|
|
2010-04-11 18:26:49 +00:00
|
|
|
gboolean
|
|
|
|
gtk_style_set_lookup_property (const gchar *property_name,
|
2010-06-13 15:10:05 +00:00
|
|
|
GType *type)
|
2010-04-11 18:26:49 +00:00
|
|
|
{
|
|
|
|
PropertyNode *node;
|
|
|
|
GtkStyleSetClass *klass;
|
2010-06-13 15:10:05 +00:00
|
|
|
gboolean found = FALSE;
|
2010-04-11 18:26:49 +00:00
|
|
|
GQuark quark;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (property_name != NULL, FALSE);
|
|
|
|
|
|
|
|
klass = g_type_class_ref (GTK_TYPE_STYLE_SET);
|
|
|
|
quark = g_quark_try_string (property_name);
|
|
|
|
|
|
|
|
if (quark == 0)
|
|
|
|
{
|
|
|
|
g_type_class_unref (klass);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < properties->len; i++)
|
|
|
|
{
|
|
|
|
node = &g_array_index (properties, PropertyNode, i);
|
|
|
|
|
|
|
|
if (node->property_quark == quark)
|
|
|
|
{
|
|
|
|
if (type)
|
|
|
|
*type = node->property_type;
|
|
|
|
|
2010-06-13 15:10:05 +00:00
|
|
|
found = TRUE;
|
|
|
|
break;
|
2010-04-11 18:26:49 +00:00
|
|
|
}
|
|
|
|
else if (node->property_quark > quark)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_type_class_unref (klass);
|
|
|
|
|
2010-06-13 15:10:05 +00:00
|
|
|
return found;
|
2010-03-05 00:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* GtkStyleSet methods */
|
2010-03-04 21:51:56 +00:00
|
|
|
|
2010-03-04 19:59:18 +00:00
|
|
|
GtkStyleSet *
|
|
|
|
gtk_style_set_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_STYLE_SET, NULL);
|
|
|
|
}
|
|
|
|
|
2010-06-25 17:37:54 +00:00
|
|
|
void
|
|
|
|
gtk_style_set_map_color (GtkStyleSet *set,
|
|
|
|
const gchar *name,
|
|
|
|
GtkSymbolicColor *color)
|
|
|
|
{
|
|
|
|
GtkStyleSetPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_STYLE_SET (set));
|
|
|
|
g_return_if_fail (name != NULL);
|
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
|
|
|
|
priv = GTK_STYLE_SET_GET_PRIVATE (set);
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkSymbolicColor *
|
|
|
|
gtk_style_set_lookup_color (GtkStyleSet *set,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GtkStyleSetPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_STYLE_SET (set), NULL);
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
|
|
|
|
priv = GTK_STYLE_SET_GET_PRIVATE (set);
|
|
|
|
|
|
|
|
if (!priv->color_map)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return g_hash_table_lookup (priv->color_map, name);
|
|
|
|
}
|
|
|
|
|
2010-05-04 17:55:19 +00:00
|
|
|
static void
|
|
|
|
set_property_internal (GtkStyleSet *set,
|
|
|
|
const gchar *property,
|
|
|
|
gboolean is_default,
|
|
|
|
GtkStateType state,
|
|
|
|
const GValue *value)
|
2010-03-04 19:59:18 +00:00
|
|
|
{
|
|
|
|
GtkStyleSetPrivate *priv;
|
2010-03-05 01:06:53 +00:00
|
|
|
PropertyNode *node;
|
2010-03-04 19:59:18 +00:00
|
|
|
PropertyData *prop;
|
2010-05-04 17:55:19 +00:00
|
|
|
GValue *val;
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-03-05 01:06:53 +00:00
|
|
|
node = property_node_lookup (g_quark_try_string (property));
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
{
|
|
|
|
g_warning ("Style property \"%s\" is not registered", property);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_if_fail (node->property_type == G_VALUE_TYPE (value));
|
|
|
|
|
2010-03-04 19:59:18 +00:00
|
|
|
priv = GTK_STYLE_SET_GET_PRIVATE (set);
|
2010-03-05 01:06:53 +00:00
|
|
|
prop = g_hash_table_lookup (priv->properties,
|
|
|
|
GINT_TO_POINTER (node->property_quark));
|
2010-03-04 19:59:18 +00:00
|
|
|
|
|
|
|
if (!prop)
|
|
|
|
{
|
|
|
|
prop = property_data_new ();
|
|
|
|
g_hash_table_insert (priv->properties,
|
2010-03-05 01:06:53 +00:00
|
|
|
GINT_TO_POINTER (node->property_quark),
|
2010-03-04 19:59:18 +00:00
|
|
|
prop);
|
|
|
|
}
|
|
|
|
|
2010-05-04 17:55:19 +00:00
|
|
|
if (is_default)
|
|
|
|
val = &prop->default_value;
|
2010-03-05 01:06:53 +00:00
|
|
|
else
|
2010-05-04 17:55:19 +00:00
|
|
|
val = &prop->values[state];
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-05-04 17:55:19 +00:00
|
|
|
if (G_IS_VALUE (val))
|
|
|
|
g_value_reset (val);
|
|
|
|
else
|
|
|
|
g_value_init (val, node->property_type);
|
|
|
|
|
|
|
|
g_value_copy (value, val);
|
2010-03-04 19:59:18 +00:00
|
|
|
}
|
|
|
|
|
2010-05-04 17:55:19 +00:00
|
|
|
void
|
|
|
|
gtk_style_set_set_default (GtkStyleSet *set,
|
|
|
|
const gchar *property,
|
|
|
|
const GValue *value)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_STYLE_SET (set));
|
|
|
|
g_return_if_fail (property != NULL);
|
|
|
|
g_return_if_fail (value != NULL);
|
|
|
|
|
|
|
|
set_property_internal (set, property, TRUE, GTK_STATE_NORMAL, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_style_set_set_property (GtkStyleSet *set,
|
|
|
|
const gchar *property,
|
|
|
|
GtkStateType state,
|
|
|
|
const GValue *value)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_STYLE_SET (set));
|
|
|
|
g_return_if_fail (property != NULL);
|
|
|
|
g_return_if_fail (state < GTK_STATE_LAST);
|
|
|
|
g_return_if_fail (value != NULL);
|
|
|
|
|
|
|
|
set_property_internal (set, property, FALSE, state, value);
|
|
|
|
}
|
2010-03-05 02:02:59 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gtk_style_set_set_valist (GtkStyleSet *set,
|
|
|
|
GtkStateType state,
|
|
|
|
va_list args)
|
|
|
|
{
|
|
|
|
GtkStyleSetPrivate *priv;
|
|
|
|
const gchar *property_name;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_STYLE_SET (set));
|
|
|
|
g_return_if_fail (state < GTK_STATE_LAST);
|
|
|
|
|
|
|
|
priv = GTK_STYLE_SET_GET_PRIVATE (set);
|
|
|
|
property_name = va_arg (args, const gchar *);
|
|
|
|
|
|
|
|
while (property_name)
|
|
|
|
{
|
|
|
|
PropertyNode *node;
|
|
|
|
PropertyData *prop;
|
|
|
|
gchar *error = NULL;
|
|
|
|
|
|
|
|
node = property_node_lookup (g_quark_try_string (property_name));
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
{
|
|
|
|
g_warning ("Style property \"%s\" is not registered", property_name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop = g_hash_table_lookup (priv->properties,
|
|
|
|
GINT_TO_POINTER (node->property_quark));
|
|
|
|
|
|
|
|
if (!prop)
|
|
|
|
{
|
|
|
|
prop = property_data_new ();
|
|
|
|
g_hash_table_insert (priv->properties,
|
|
|
|
GINT_TO_POINTER (node->property_quark),
|
|
|
|
prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_value_init (&prop->values[state], node->property_type);
|
|
|
|
G_VALUE_COLLECT (&prop->values[state], args, 0, &error);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_warning ("Could not set style property \"%s\": %s", property_name, error);
|
|
|
|
g_value_unset (&prop->values[state]);
|
|
|
|
g_free (error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
property_name = va_arg (args, const gchar *);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_style_set_set (GtkStyleSet *set,
|
|
|
|
GtkStateType state,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_STYLE_SET (set));
|
|
|
|
g_return_if_fail (state < GTK_STATE_LAST);
|
|
|
|
|
|
|
|
va_start (args, state);
|
|
|
|
gtk_style_set_set_valist (set, state, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
2010-03-04 19:59:18 +00:00
|
|
|
gboolean
|
|
|
|
gtk_style_set_get_property (GtkStyleSet *set,
|
|
|
|
const gchar *property,
|
|
|
|
GtkStateType state,
|
|
|
|
GValue *value)
|
|
|
|
{
|
|
|
|
GtkStyleSetPrivate *priv;
|
2010-03-05 01:06:53 +00:00
|
|
|
PropertyNode *node;
|
2010-03-04 19:59:18 +00:00
|
|
|
PropertyData *prop;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_STYLE_SET (set), FALSE);
|
|
|
|
g_return_val_if_fail (property != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (state < GTK_STATE_LAST, FALSE);
|
|
|
|
g_return_val_if_fail (value != NULL, FALSE);
|
|
|
|
|
2010-03-05 01:06:53 +00:00
|
|
|
node = property_node_lookup (g_quark_try_string (property));
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
{
|
|
|
|
g_warning ("Style property \"%s\" is not registered", property);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-03-04 19:59:18 +00:00
|
|
|
priv = GTK_STYLE_SET_GET_PRIVATE (set);
|
2010-03-05 01:06:53 +00:00
|
|
|
prop = g_hash_table_lookup (priv->properties,
|
|
|
|
GINT_TO_POINTER (node->property_quark));
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-06-13 15:10:05 +00:00
|
|
|
if (!prop)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-06 18:52:18 +00:00
|
|
|
g_value_init (value, node->property_type);
|
2010-03-04 19:59:18 +00:00
|
|
|
|
2010-06-13 15:10:05 +00:00
|
|
|
if (!G_IS_VALUE (&prop->values[state]))
|
2010-05-04 17:55:19 +00:00
|
|
|
g_value_copy (&prop->default_value, value);
|
2010-03-06 18:52:18 +00:00
|
|
|
else
|
|
|
|
g_value_copy (&prop->values[state], value);
|
2010-03-04 19:59:18 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-05 02:02:59 +00:00
|
|
|
void
|
|
|
|
gtk_style_set_get_valist (GtkStyleSet *set,
|
|
|
|
GtkStateType state,
|
|
|
|
va_list args)
|
|
|
|
{
|
|
|
|
GtkStyleSetPrivate *priv;
|
|
|
|
const gchar *property_name;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_STYLE_SET (set));
|
|
|
|
g_return_if_fail (state < GTK_STATE_LAST);
|
|
|
|
|
|
|
|
priv = GTK_STYLE_SET_GET_PRIVATE (set);
|
|
|
|
property_name = va_arg (args, const gchar *);
|
|
|
|
|
|
|
|
while (property_name)
|
|
|
|
{
|
|
|
|
PropertyNode *node;
|
|
|
|
PropertyData *prop;
|
|
|
|
gchar *error = NULL;
|
|
|
|
|
|
|
|
node = property_node_lookup (g_quark_try_string (property_name));
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
{
|
|
|
|
g_warning ("Style property \"%s\" is not registered", property_name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop = g_hash_table_lookup (priv->properties,
|
|
|
|
GINT_TO_POINTER (node->property_quark));
|
|
|
|
|
2010-06-13 15:10:05 +00:00
|
|
|
if (!prop)
|
|
|
|
{
|
|
|
|
GValue *empty_value = { 0 };
|
|
|
|
|
|
|
|
g_warning ("No value for style property \"%s\"", property_name);
|
|
|
|
|
|
|
|
g_value_init (&empty_value, node->property_type);
|
|
|
|
G_VALUE_LCOPY (&empty_value, args, 0, &error);
|
|
|
|
}
|
2010-05-04 17:55:19 +00:00
|
|
|
else if (!G_IS_VALUE (&prop->values[state]))
|
|
|
|
G_VALUE_LCOPY (&prop->default_value, args, 0, &error);
|
2010-03-06 18:52:18 +00:00
|
|
|
else
|
|
|
|
G_VALUE_LCOPY (&prop->values[state], args, 0, &error);
|
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 *);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_style_set_get (GtkStyleSet *set,
|
|
|
|
GtkStateType state,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_STYLE_SET (set));
|
|
|
|
g_return_if_fail (state < GTK_STATE_LAST);
|
|
|
|
|
|
|
|
va_start (args, state);
|
|
|
|
gtk_style_set_get_valist (set, state, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
2010-03-04 19:59:18 +00:00
|
|
|
void
|
|
|
|
gtk_style_set_unset_property (GtkStyleSet *set,
|
|
|
|
const gchar *property,
|
|
|
|
GtkStateType state)
|
|
|
|
{
|
|
|
|
GtkStyleSetPrivate *priv;
|
2010-03-05 01:06:53 +00:00
|
|
|
PropertyNode *node;
|
2010-03-04 19:59:18 +00:00
|
|
|
PropertyData *prop;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_STYLE_SET (set));
|
|
|
|
g_return_if_fail (property != NULL);
|
|
|
|
g_return_if_fail (state < GTK_STATE_LAST);
|
|
|
|
|
2010-03-05 01:06:53 +00:00
|
|
|
node = property_node_lookup (g_quark_try_string (property));
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
{
|
|
|
|
g_warning ("Style property \"%s\" is not registered", property);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-04 19:59:18 +00:00
|
|
|
priv = GTK_STYLE_SET_GET_PRIVATE (set);
|
2010-03-05 01:06:53 +00:00
|
|
|
prop = g_hash_table_lookup (priv->properties,
|
|
|
|
GINT_TO_POINTER (node->property_quark));
|
2010-03-04 19:59:18 +00:00
|
|
|
|
|
|
|
if (!prop)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_value_unset (&prop->values[state]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_style_set_clear (GtkStyleSet *set)
|
|
|
|
{
|
|
|
|
GtkStyleSetPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_STYLE_SET (set));
|
|
|
|
|
|
|
|
priv = GTK_STYLE_SET_GET_PRIVATE (set);
|
|
|
|
g_hash_table_remove_all (priv->properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_style_set_merge (GtkStyleSet *set,
|
|
|
|
const GtkStyleSet *set_to_merge,
|
|
|
|
gboolean replace)
|
|
|
|
{
|
|
|
|
GtkStyleSetPrivate *priv, *priv_to_merge;
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_STYLE_SET (set));
|
|
|
|
g_return_if_fail (GTK_IS_STYLE_SET (set_to_merge));
|
|
|
|
|
|
|
|
priv = GTK_STYLE_SET_GET_PRIVATE (set);
|
|
|
|
priv_to_merge = GTK_STYLE_SET_GET_PRIVATE (set_to_merge);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
|
|
|
const gchar *name;
|
|
|
|
GtkSymbolicColor *color;
|
|
|
|
|
|
|
|
name = key;
|
|
|
|
color = value;
|
|
|
|
|
|
|
|
if (!replace &&
|
|
|
|
g_hash_table_lookup (priv->color_map, name))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gtk_style_set_map_color (set, name, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Merge symbolic style properties */
|
2010-03-04 19:59:18 +00:00
|
|
|
g_hash_table_iter_init (&iter, priv_to_merge->properties);
|
|
|
|
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
|
|
|
PropertyData *prop_to_merge = value;
|
|
|
|
PropertyData *prop = NULL;
|
|
|
|
GtkStateType i;
|
|
|
|
|
|
|
|
for (i = GTK_STATE_NORMAL; i < GTK_STATE_LAST; i++)
|
|
|
|
{
|
|
|
|
if (G_VALUE_TYPE (&prop_to_merge->values[i]) == G_TYPE_INVALID)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!prop)
|
2010-03-05 01:06:53 +00:00
|
|
|
prop = g_hash_table_lookup (priv->properties, key);
|
2010-03-04 19:59:18 +00:00
|
|
|
|
|
|
|
if (!prop)
|
|
|
|
{
|
|
|
|
prop = property_data_new ();
|
2010-03-05 01:06:53 +00:00
|
|
|
g_hash_table_insert (priv->properties, key, prop);
|
2010-03-04 19:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (replace ||
|
|
|
|
G_VALUE_TYPE (&prop->values[i]) == G_TYPE_INVALID)
|
|
|
|
{
|
|
|
|
if (G_VALUE_TYPE (&prop->values[i]) == G_TYPE_INVALID)
|
|
|
|
g_value_init (&prop->values[i], G_VALUE_TYPE (&prop_to_merge->values[i]));
|
|
|
|
|
|
|
|
g_value_copy (&prop_to_merge->values[i],
|
|
|
|
&prop->values[i]);
|
|
|
|
}
|
|
|
|
}
|
2010-05-04 17:55:19 +00:00
|
|
|
|
|
|
|
if (G_IS_VALUE (&prop_to_merge->default_value) &&
|
|
|
|
(replace || !prop || !G_IS_VALUE (&prop->default_value)))
|
|
|
|
{
|
|
|
|
if (!prop)
|
|
|
|
prop = g_hash_table_lookup (priv->properties, key);
|
|
|
|
|
|
|
|
if (!prop)
|
|
|
|
{
|
|
|
|
prop = property_data_new ();
|
|
|
|
g_hash_table_insert (priv->properties, key, prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!G_IS_VALUE (&prop->default_value))
|
|
|
|
g_value_init (&prop->default_value, G_VALUE_TYPE (&prop_to_merge->default_value));
|
|
|
|
|
|
|
|
g_value_copy (&prop_to_merge->default_value,
|
|
|
|
&prop->default_value);
|
|
|
|
}
|
2010-03-04 19:59:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define __GTK_STYLE_SET_C__
|
|
|
|
#include "gtkaliasdef.c"
|