mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 06:00:22 +00:00
css: Add a -gtk-icon-theme CSS property
The property is useless to set (it only allows 'initial', 'inherit' and 'unset' as values), but it is used to track changes to the icon theme. And as such, it can ensure that widgets can track when they need to reload icons. https://bugzilla.gnome.org/show_bug.cgi?id=743341
This commit is contained in:
parent
9cbf04c1d2
commit
11d70f1ac3
@ -377,6 +377,7 @@ gtk_private_h_sources = \
|
||||
gtkcsseasevalueprivate.h \
|
||||
gtkcssenginevalueprivate.h \
|
||||
gtkcssenumvalueprivate.h \
|
||||
gtkcssiconthemevalueprivate.h \
|
||||
gtkcssimagebuiltinprivate.h \
|
||||
gtkcssimagecrossfadeprivate.h \
|
||||
gtkcssimagegradientprivate.h \
|
||||
@ -605,6 +606,7 @@ gtk_base_c_sources = \
|
||||
gtkcsseasevalue.c \
|
||||
gtkcssenumvalue.c \
|
||||
gtkcssenginevalue.c \
|
||||
gtkcssiconthemevalue.c \
|
||||
gtkcssimage.c \
|
||||
gtkcssimagebuiltin.c \
|
||||
gtkcssimagecrossfade.c \
|
||||
|
135
gtk/gtkcssiconthemevalue.c
Normal file
135
gtk/gtkcssiconthemevalue.c
Normal file
@ -0,0 +1,135 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2011 Red Hat, Inc.
|
||||
*
|
||||
* 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 "gtkcssiconthemevalueprivate.h"
|
||||
|
||||
#include "gtkicontheme.h"
|
||||
#include "gtksettingsprivate.h"
|
||||
#include "gtkstyleproviderprivate.h"
|
||||
|
||||
/*
|
||||
* The idea behind this value (and the '-gtk-icon-theme' CSS property) is
|
||||
* to track changes to the icon theme.
|
||||
*
|
||||
* We create a new instance of this value whenever the icon theme changes
|
||||
* (via emitting the changed signal). So as long as the icon theme does
|
||||
* not change, we will compute the same value. We can then compare values
|
||||
* by pointer to see if the icon theme changed.
|
||||
*/
|
||||
|
||||
struct _GtkCssValue {
|
||||
GTK_CSS_VALUE_BASE
|
||||
GtkIconTheme *icontheme;
|
||||
guint changed_id;
|
||||
};
|
||||
|
||||
static void
|
||||
gtk_css_value_icon_theme_disconnect_handler (GtkCssValue *value)
|
||||
{
|
||||
if (value->changed_id == 0)
|
||||
return;
|
||||
|
||||
g_object_set_data (G_OBJECT (value->icontheme), "-gtk-css-value", NULL);
|
||||
|
||||
g_signal_handler_disconnect (value->icontheme, value->changed_id);
|
||||
value->changed_id = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_css_value_icon_theme_changed_cb (GtkIconTheme *icontheme,
|
||||
GtkCssValue *value)
|
||||
{
|
||||
gtk_css_value_icon_theme_disconnect_handler (value);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_css_value_icon_theme_free (GtkCssValue *value)
|
||||
{
|
||||
gtk_css_value_icon_theme_disconnect_handler (value);
|
||||
|
||||
if (value->icontheme)
|
||||
g_object_unref (value->icontheme);
|
||||
|
||||
g_slice_free (GtkCssValue, value);
|
||||
}
|
||||
|
||||
static GtkCssValue *
|
||||
gtk_css_value_icon_theme_compute (GtkCssValue *icon_theme,
|
||||
guint property_id,
|
||||
GtkStyleProviderPrivate *provider,
|
||||
int scale,
|
||||
GtkCssStyle *style,
|
||||
GtkCssStyle *parent_style,
|
||||
GtkCssDependencies *dependencies)
|
||||
{
|
||||
GtkCssValue *result;
|
||||
GtkIconTheme *icontheme;
|
||||
|
||||
icontheme = gtk_icon_theme_get_for_screen (_gtk_settings_get_screen (_gtk_style_provider_private_get_settings (provider)));
|
||||
|
||||
result = g_object_get_data (G_OBJECT (icontheme), "-gtk-css-value");
|
||||
if (result)
|
||||
return _gtk_css_value_ref (result);
|
||||
|
||||
result = _gtk_css_icon_theme_value_new ();
|
||||
result->icontheme = g_object_ref (icontheme);
|
||||
|
||||
g_object_set_data (G_OBJECT (icontheme), "-gtk-css-value", result);
|
||||
result->changed_id = g_signal_connect (icontheme, "changed", G_CALLBACK (gtk_css_value_icon_theme_changed_cb), result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_value_icon_theme_equal (const GtkCssValue *value1,
|
||||
const GtkCssValue *value2)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static GtkCssValue *
|
||||
gtk_css_value_icon_theme_transition (GtkCssValue *start,
|
||||
GtkCssValue *end,
|
||||
guint property_id,
|
||||
double progress)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_css_value_icon_theme_print (const GtkCssValue *icon_theme,
|
||||
GString *string)
|
||||
{
|
||||
g_string_append (string, "initial");
|
||||
}
|
||||
|
||||
static const GtkCssValueClass GTK_CSS_VALUE_ICON_THEME = {
|
||||
gtk_css_value_icon_theme_free,
|
||||
gtk_css_value_icon_theme_compute,
|
||||
gtk_css_value_icon_theme_equal,
|
||||
gtk_css_value_icon_theme_transition,
|
||||
gtk_css_value_icon_theme_print
|
||||
};
|
||||
|
||||
GtkCssValue *
|
||||
_gtk_css_icon_theme_value_new (void)
|
||||
{
|
||||
return _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_ICON_THEME);
|
||||
}
|
||||
|
32
gtk/gtkcssiconthemevalueprivate.h
Normal file
32
gtk/gtkcssiconthemevalueprivate.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright © 2012 Red Hat Inc.
|
||||
*
|
||||
* 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.1 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/>.
|
||||
*
|
||||
* Authors: Alexander Larsson <alexl@gnome.org>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_CSS_ICON_THEME_VALUE_PRIVATE_H__
|
||||
#define __GTK_CSS_ICON_THEME_VALUE_PRIVATE_H__
|
||||
|
||||
#include "gtkcssparserprivate.h"
|
||||
#include "gtkcssvalueprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
GtkCssValue * _gtk_css_icon_theme_value_new (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_CSS_ICON_THEME_VALUE_PRIVATE_H__ */
|
@ -45,6 +45,7 @@
|
||||
#include "gtkcsscornervalueprivate.h"
|
||||
#include "gtkcsseasevalueprivate.h"
|
||||
#include "gtkcssenginevalueprivate.h"
|
||||
#include "gtkcssiconthemevalueprivate.h"
|
||||
#include "gtkcssimageprivate.h"
|
||||
#include "gtkcssimagebuiltinprivate.h"
|
||||
#include "gtkcssimagegradientprivate.h"
|
||||
@ -945,6 +946,15 @@ background_position_parse (GtkCssStyleProperty *property,
|
||||
return _gtk_css_array_value_parse (parser, _gtk_css_position_value_parse);
|
||||
}
|
||||
|
||||
static GtkCssValue *
|
||||
icon_theme_value_parse (GtkCssStyleProperty *property,
|
||||
GtkCssParser *parser)
|
||||
{
|
||||
_gtk_css_parser_error (parser, "Only 'inherit', 'initial' or 'unset' are allowed");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*** REGISTRATION ***/
|
||||
|
||||
void
|
||||
@ -975,6 +985,15 @@ _gtk_css_style_property_init_properties (void)
|
||||
|
||||
/* properties that aren't referenced when computing values
|
||||
* start here */
|
||||
gtk_css_style_property_register ("-gtk-icon-theme",
|
||||
GTK_CSS_PROPERTY_ICON_THEME,
|
||||
G_TYPE_NONE,
|
||||
GTK_STYLE_PROPERTY_INHERIT,
|
||||
GTK_CSS_AFFECTS_ICON,
|
||||
icon_theme_value_parse,
|
||||
NULL,
|
||||
NULL,
|
||||
_gtk_css_icon_theme_value_new());
|
||||
gtk_css_style_property_register ("background-color",
|
||||
GTK_CSS_PROPERTY_BACKGROUND_COLOR,
|
||||
GDK_TYPE_RGBA,
|
||||
|
@ -111,6 +111,7 @@ typedef enum /*< skip >*/ {
|
||||
enum { /*< skip >*/
|
||||
GTK_CSS_PROPERTY_COLOR,
|
||||
GTK_CSS_PROPERTY_FONT_SIZE,
|
||||
GTK_CSS_PROPERTY_ICON_THEME,
|
||||
GTK_CSS_PROPERTY_BACKGROUND_COLOR,
|
||||
GTK_CSS_PROPERTY_FONT_FAMILY,
|
||||
GTK_CSS_PROPERTY_FONT_STYLE,
|
||||
|
Loading…
Reference in New Issue
Block a user