2012-03-16 04:14:41 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2012 Benjamin Otte <otte@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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkstylecascadeprivate.h"
|
|
|
|
|
|
|
|
#include "gtkstyleprovider.h"
|
|
|
|
#include "gtkstyleproviderprivate.h"
|
2015-09-11 20:30:07 +00:00
|
|
|
#include "gtkprivate.h"
|
2012-03-16 04:14:41 +00:00
|
|
|
|
|
|
|
typedef struct _GtkStyleCascadeIter GtkStyleCascadeIter;
|
|
|
|
typedef struct _GtkStyleProviderData GtkStyleProviderData;
|
|
|
|
|
|
|
|
struct _GtkStyleCascadeIter {
|
2016-06-16 03:02:11 +00:00
|
|
|
int n_cascades;
|
|
|
|
int *cascade_index; /* each one points at last index that was returned, */
|
|
|
|
/* not next one that should be returned */
|
2023-01-17 12:39:51 +00:00
|
|
|
int index_[20];
|
2012-03-16 04:14:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkStyleProviderData
|
|
|
|
{
|
|
|
|
GtkStyleProvider *provider;
|
|
|
|
guint priority;
|
2012-04-08 15:35:24 +00:00
|
|
|
guint changed_signal_id;
|
2012-03-16 04:14:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static GtkStyleProvider *
|
|
|
|
gtk_style_cascade_iter_next (GtkStyleCascade *cascade,
|
|
|
|
GtkStyleCascadeIter *iter)
|
|
|
|
{
|
2016-06-16 03:02:11 +00:00
|
|
|
GtkStyleCascade *cas;
|
|
|
|
int ix, highest_priority_index = 0;
|
|
|
|
GtkStyleProviderData *highest_priority_data = NULL;
|
2012-03-16 04:14:41 +00:00
|
|
|
|
2016-06-16 03:02:11 +00:00
|
|
|
for (cas = cascade, ix = 0; ix < iter->n_cascades; cas = cas->parent, ix++)
|
|
|
|
{
|
2016-06-27 03:58:42 +00:00
|
|
|
GtkStyleProviderData *data;
|
2016-06-30 10:00:47 +00:00
|
|
|
|
2016-06-16 03:02:11 +00:00
|
|
|
if (iter->cascade_index[ix] <= 0)
|
|
|
|
continue;
|
2012-03-16 04:14:41 +00:00
|
|
|
|
2016-06-27 03:58:42 +00:00
|
|
|
data = &g_array_index (cas->providers,
|
2016-06-30 10:00:47 +00:00
|
|
|
GtkStyleProviderData,
|
|
|
|
iter->cascade_index[ix] - 1);
|
2016-06-16 03:02:11 +00:00
|
|
|
if (highest_priority_data == NULL || data->priority > highest_priority_data->priority)
|
2012-03-16 04:14:41 +00:00
|
|
|
{
|
2016-06-16 03:02:11 +00:00
|
|
|
highest_priority_index = ix;
|
|
|
|
highest_priority_data = data;
|
2012-03-16 04:14:41 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-16 03:02:11 +00:00
|
|
|
|
|
|
|
if (highest_priority_data != NULL)
|
2012-03-16 04:14:41 +00:00
|
|
|
{
|
2016-06-16 03:02:11 +00:00
|
|
|
iter->cascade_index[highest_priority_index]--;
|
|
|
|
return highest_priority_data->provider;
|
2012-03-16 04:14:41 +00:00
|
|
|
}
|
2016-06-16 03:02:11 +00:00
|
|
|
return NULL;
|
2012-03-16 04:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkStyleProvider *
|
|
|
|
gtk_style_cascade_iter_init (GtkStyleCascade *cascade,
|
|
|
|
GtkStyleCascadeIter *iter)
|
|
|
|
{
|
2016-06-16 03:02:11 +00:00
|
|
|
GtkStyleCascade *cas = cascade;
|
|
|
|
int ix;
|
|
|
|
|
|
|
|
iter->n_cascades = 1;
|
|
|
|
while ((cas = cas->parent) != NULL)
|
|
|
|
iter->n_cascades++;
|
|
|
|
|
2023-01-17 12:39:51 +00:00
|
|
|
if (iter->n_cascades < 20)
|
|
|
|
iter->cascade_index = iter->index_;
|
|
|
|
else
|
|
|
|
iter->cascade_index = g_new (int, iter->n_cascades);
|
|
|
|
|
2016-06-16 03:02:11 +00:00
|
|
|
for (cas = cascade, ix = 0; ix < iter->n_cascades; cas = cas->parent, ix++)
|
|
|
|
iter->cascade_index[ix] = cas->providers->len;
|
2012-03-16 04:14:41 +00:00
|
|
|
|
|
|
|
return gtk_style_cascade_iter_next (cascade, iter);
|
|
|
|
}
|
|
|
|
|
2016-06-16 03:02:11 +00:00
|
|
|
static void
|
|
|
|
gtk_style_cascade_iter_clear (GtkStyleCascadeIter *iter)
|
|
|
|
{
|
2023-01-17 12:39:51 +00:00
|
|
|
if (iter->cascade_index != iter->index_)
|
|
|
|
g_free (iter->cascade_index);
|
2016-06-16 03:02:11 +00:00
|
|
|
}
|
|
|
|
|
2012-12-01 00:24:12 +00:00
|
|
|
static GtkSettings *
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_style_cascade_get_settings (GtkStyleProvider *provider)
|
2012-12-01 00:24:12 +00:00
|
|
|
{
|
|
|
|
GtkStyleCascade *cascade = GTK_STYLE_CASCADE (provider);
|
|
|
|
GtkStyleCascadeIter iter;
|
|
|
|
GtkSettings *settings;
|
|
|
|
GtkStyleProvider *item;
|
|
|
|
|
|
|
|
for (item = gtk_style_cascade_iter_init (cascade, &iter);
|
|
|
|
item;
|
|
|
|
item = gtk_style_cascade_iter_next (cascade, &iter))
|
|
|
|
{
|
2020-01-19 06:09:11 +00:00
|
|
|
settings = gtk_style_provider_get_settings (item);
|
2012-12-01 00:24:12 +00:00
|
|
|
if (settings)
|
2016-06-16 03:02:11 +00:00
|
|
|
{
|
|
|
|
gtk_style_cascade_iter_clear (&iter);
|
|
|
|
return settings;
|
|
|
|
}
|
2012-12-01 00:24:12 +00:00
|
|
|
}
|
|
|
|
|
2016-06-16 03:02:11 +00:00
|
|
|
gtk_style_cascade_iter_clear (&iter);
|
2012-12-01 00:24:12 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-25 01:28:59 +00:00
|
|
|
static GtkCssValue *
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_style_cascade_get_color (GtkStyleProvider *provider,
|
2012-03-16 04:14:41 +00:00
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
GtkStyleCascade *cascade = GTK_STYLE_CASCADE (provider);
|
|
|
|
GtkStyleCascadeIter iter;
|
2012-11-25 01:28:59 +00:00
|
|
|
GtkCssValue *color;
|
2012-03-16 04:14:41 +00:00
|
|
|
GtkStyleProvider *item;
|
|
|
|
|
|
|
|
for (item = gtk_style_cascade_iter_init (cascade, &iter);
|
|
|
|
item;
|
|
|
|
item = gtk_style_cascade_iter_next (cascade, &iter))
|
|
|
|
{
|
2020-01-19 06:09:11 +00:00
|
|
|
color = gtk_style_provider_get_color (item, name);
|
|
|
|
if (color)
|
2012-03-16 04:14:41 +00:00
|
|
|
{
|
2020-01-19 06:09:11 +00:00
|
|
|
gtk_style_cascade_iter_clear (&iter);
|
|
|
|
return color;
|
2012-03-16 04:14:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-16 03:02:11 +00:00
|
|
|
gtk_style_cascade_iter_clear (&iter);
|
2012-03-16 04:14:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-01-31 10:56:15 +00:00
|
|
|
static int
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_style_cascade_get_scale (GtkStyleProvider *provider)
|
2015-01-31 10:56:15 +00:00
|
|
|
{
|
|
|
|
GtkStyleCascade *cascade = GTK_STYLE_CASCADE (provider);
|
|
|
|
|
|
|
|
return cascade->scale;
|
|
|
|
}
|
|
|
|
|
2012-09-18 17:36:35 +00:00
|
|
|
static GtkCssKeyframes *
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_style_cascade_get_keyframes (GtkStyleProvider *provider,
|
|
|
|
const char *name)
|
2012-04-19 01:58:28 +00:00
|
|
|
{
|
|
|
|
GtkStyleCascade *cascade = GTK_STYLE_CASCADE (provider);
|
|
|
|
GtkStyleCascadeIter iter;
|
|
|
|
GtkCssKeyframes *keyframes;
|
|
|
|
GtkStyleProvider *item;
|
|
|
|
|
|
|
|
for (item = gtk_style_cascade_iter_init (cascade, &iter);
|
|
|
|
item;
|
|
|
|
item = gtk_style_cascade_iter_next (cascade, &iter))
|
|
|
|
{
|
2020-01-19 06:09:11 +00:00
|
|
|
keyframes = gtk_style_provider_get_keyframes (item, name);
|
2012-04-19 01:58:28 +00:00
|
|
|
if (keyframes)
|
2016-06-16 03:02:11 +00:00
|
|
|
{
|
|
|
|
gtk_style_cascade_iter_clear (&iter);
|
|
|
|
return keyframes;
|
|
|
|
}
|
2012-04-19 01:58:28 +00:00
|
|
|
}
|
|
|
|
|
2016-06-16 03:02:11 +00:00
|
|
|
gtk_style_cascade_iter_clear (&iter);
|
2012-04-19 01:58:28 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-16 04:14:41 +00:00
|
|
|
static void
|
2020-01-26 03:37:17 +00:00
|
|
|
gtk_style_cascade_lookup (GtkStyleProvider *provider,
|
|
|
|
const GtkCountingBloomFilter *filter,
|
|
|
|
GtkCssNode *node,
|
|
|
|
GtkCssLookup *lookup,
|
|
|
|
GtkCssChange *change)
|
2012-03-16 04:14:41 +00:00
|
|
|
{
|
|
|
|
GtkStyleCascade *cascade = GTK_STYLE_CASCADE (provider);
|
|
|
|
GtkStyleCascadeIter iter;
|
|
|
|
GtkStyleProvider *item;
|
2014-12-09 18:31:17 +00:00
|
|
|
GtkCssChange iter_change;
|
2012-03-16 04:14:41 +00:00
|
|
|
|
|
|
|
for (item = gtk_style_cascade_iter_init (cascade, &iter);
|
|
|
|
item;
|
|
|
|
item = gtk_style_cascade_iter_next (cascade, &iter))
|
|
|
|
{
|
2020-01-26 03:37:17 +00:00
|
|
|
gtk_style_provider_lookup (item, filter, node, lookup,
|
2020-01-19 06:09:11 +00:00
|
|
|
change ? &iter_change : NULL);
|
|
|
|
if (change)
|
|
|
|
*change |= iter_change;
|
2012-03-16 04:14:41 +00:00
|
|
|
}
|
2016-06-16 03:02:11 +00:00
|
|
|
gtk_style_cascade_iter_clear (&iter);
|
2012-03-16 04:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_style_cascade_provider_iface_init (GtkStyleProviderInterface *iface)
|
2012-03-16 04:14:41 +00:00
|
|
|
{
|
|
|
|
iface->get_color = gtk_style_cascade_get_color;
|
2012-12-01 00:24:12 +00:00
|
|
|
iface->get_settings = gtk_style_cascade_get_settings;
|
2015-01-31 10:56:15 +00:00
|
|
|
iface->get_scale = gtk_style_cascade_get_scale;
|
2012-04-19 01:58:28 +00:00
|
|
|
iface->get_keyframes = gtk_style_cascade_get_keyframes;
|
2012-03-16 04:14:41 +00:00
|
|
|
iface->lookup = gtk_style_cascade_lookup;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_EXTENDED (GtkStyleCascade, _gtk_style_cascade, G_TYPE_OBJECT, 0,
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_style_cascade_provider_iface_init));
|
2012-03-16 04:14:41 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_style_cascade_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkStyleCascade *cascade = GTK_STYLE_CASCADE (object);
|
|
|
|
|
|
|
|
_gtk_style_cascade_set_parent (cascade, NULL);
|
|
|
|
g_array_unref (cascade->providers);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (_gtk_style_cascade_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_style_cascade_class_init (GtkStyleCascadeClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->dispose = gtk_style_cascade_dispose;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
style_provider_data_clear (gpointer data_)
|
|
|
|
{
|
|
|
|
GtkStyleProviderData *data = data_;
|
|
|
|
|
2012-04-08 15:35:24 +00:00
|
|
|
g_signal_handler_disconnect (data->provider, data->changed_signal_id);
|
2012-03-16 04:14:41 +00:00
|
|
|
g_object_unref (data->provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_style_cascade_init (GtkStyleCascade *cascade)
|
|
|
|
{
|
2015-01-31 10:01:25 +00:00
|
|
|
cascade->scale = 1;
|
|
|
|
|
2012-03-16 04:14:41 +00:00
|
|
|
cascade->providers = g_array_new (FALSE, FALSE, sizeof (GtkStyleProviderData));
|
|
|
|
g_array_set_clear_func (cascade->providers, style_provider_data_clear);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkStyleCascade *
|
|
|
|
_gtk_style_cascade_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_STYLE_CASCADE, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_style_cascade_set_parent (GtkStyleCascade *cascade,
|
|
|
|
GtkStyleCascade *parent)
|
|
|
|
{
|
2015-09-11 20:30:07 +00:00
|
|
|
gtk_internal_return_if_fail (GTK_IS_STYLE_CASCADE (cascade));
|
|
|
|
gtk_internal_return_if_fail (parent == NULL || GTK_IS_STYLE_CASCADE (parent));
|
2012-03-16 04:14:41 +00:00
|
|
|
|
|
|
|
if (cascade->parent == parent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (parent)
|
2012-04-08 15:35:24 +00:00
|
|
|
{
|
|
|
|
g_object_ref (parent);
|
|
|
|
g_signal_connect_swapped (parent,
|
2019-11-12 19:51:33 +00:00
|
|
|
"gtk-private-changed",
|
2017-10-31 03:31:46 +00:00
|
|
|
G_CALLBACK (gtk_style_provider_changed),
|
2012-04-08 15:35:24 +00:00
|
|
|
cascade);
|
|
|
|
}
|
2012-03-16 04:14:41 +00:00
|
|
|
|
|
|
|
if (cascade->parent)
|
2012-04-08 15:35:24 +00:00
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (cascade->parent,
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_style_provider_changed,
|
2012-04-08 15:35:24 +00:00
|
|
|
cascade);
|
|
|
|
g_object_unref (cascade->parent);
|
|
|
|
}
|
2012-03-16 04:14:41 +00:00
|
|
|
|
|
|
|
cascade->parent = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_style_cascade_add_provider (GtkStyleCascade *cascade,
|
|
|
|
GtkStyleProvider *provider,
|
|
|
|
guint priority)
|
|
|
|
{
|
|
|
|
GtkStyleProviderData data;
|
|
|
|
guint i;
|
|
|
|
|
2015-09-11 20:30:07 +00:00
|
|
|
gtk_internal_return_if_fail (GTK_IS_STYLE_CASCADE (cascade));
|
|
|
|
gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
|
|
|
|
gtk_internal_return_if_fail (GTK_STYLE_PROVIDER (cascade) != provider);
|
2012-03-16 04:14:41 +00:00
|
|
|
|
|
|
|
data.provider = g_object_ref (provider);
|
|
|
|
data.priority = priority;
|
2012-04-08 15:35:24 +00:00
|
|
|
data.changed_signal_id = g_signal_connect_swapped (provider,
|
2019-11-12 19:51:33 +00:00
|
|
|
"gtk-private-changed",
|
2017-10-31 03:31:46 +00:00
|
|
|
G_CALLBACK (gtk_style_provider_changed),
|
2012-04-08 15:35:24 +00:00
|
|
|
cascade);
|
2012-03-16 04:14:41 +00:00
|
|
|
|
|
|
|
/* ensure it gets removed first */
|
|
|
|
_gtk_style_cascade_remove_provider (cascade, provider);
|
|
|
|
|
|
|
|
for (i = 0; i < cascade->providers->len; i++)
|
|
|
|
{
|
|
|
|
if (g_array_index (cascade->providers, GtkStyleProviderData, i).priority > priority)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_array_insert_val (cascade->providers, i, data);
|
2012-04-08 15:35:24 +00:00
|
|
|
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_style_provider_changed (GTK_STYLE_PROVIDER (cascade));
|
2012-03-16 04:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_style_cascade_remove_provider (GtkStyleCascade *cascade,
|
|
|
|
GtkStyleProvider *provider)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
2015-09-11 20:30:07 +00:00
|
|
|
gtk_internal_return_if_fail (GTK_IS_STYLE_CASCADE (cascade));
|
|
|
|
gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
|
2012-03-16 04:14:41 +00:00
|
|
|
|
|
|
|
for (i = 0; i < cascade->providers->len; i++)
|
|
|
|
{
|
|
|
|
GtkStyleProviderData *data = &g_array_index (cascade->providers, GtkStyleProviderData, i);
|
|
|
|
|
|
|
|
if (data->provider == provider)
|
|
|
|
{
|
|
|
|
g_array_remove_index (cascade->providers, i);
|
2012-04-08 15:35:24 +00:00
|
|
|
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_style_provider_changed (GTK_STYLE_PROVIDER (cascade));
|
2012-03-16 04:14:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-31 10:01:25 +00:00
|
|
|
void
|
|
|
|
_gtk_style_cascade_set_scale (GtkStyleCascade *cascade,
|
|
|
|
int scale)
|
|
|
|
{
|
2015-09-11 20:30:07 +00:00
|
|
|
gtk_internal_return_if_fail (GTK_IS_STYLE_CASCADE (cascade));
|
2015-01-31 10:01:25 +00:00
|
|
|
|
|
|
|
if (cascade->scale == scale)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cascade->scale = scale;
|
|
|
|
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_style_provider_changed (GTK_STYLE_PROVIDER (cascade));
|
2015-01-31 10:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_gtk_style_cascade_get_scale (GtkStyleCascade *cascade)
|
|
|
|
{
|
2015-09-11 20:30:07 +00:00
|
|
|
gtk_internal_return_val_if_fail (GTK_IS_STYLE_CASCADE (cascade), 1);
|
2015-01-31 10:01:25 +00:00
|
|
|
|
|
|
|
return cascade->scale;
|
|
|
|
}
|