mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-18 09:00:34 +00:00
GtkSettings: implement GtkStyleProvider
This commit is contained in:
parent
58a51bca97
commit
621a95f515
@ -179,6 +179,8 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* --- prototypes --- */
|
/* --- prototypes --- */
|
||||||
|
static void gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
|
||||||
|
|
||||||
static void gtk_settings_finalize (GObject *object);
|
static void gtk_settings_finalize (GObject *object);
|
||||||
static void gtk_settings_get_property (GObject *object,
|
static void gtk_settings_get_property (GObject *object,
|
||||||
guint property_id,
|
guint property_id,
|
||||||
@ -221,7 +223,9 @@ static GSList *object_list = NULL;
|
|||||||
static guint class_n_properties = 0;
|
static guint class_n_properties = 0;
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GtkSettings, gtk_settings, G_TYPE_OBJECT)
|
G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
|
||||||
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
|
||||||
|
gtk_settings_provider_iface_init));
|
||||||
|
|
||||||
/* --- functions --- */
|
/* --- functions --- */
|
||||||
static void
|
static void
|
||||||
@ -1246,6 +1250,76 @@ gtk_settings_class_init (GtkSettingsClass *class)
|
|||||||
g_assert (result == PROP_IM_STATUS_STYLE);
|
g_assert (result == PROP_IM_STATUS_STYLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GtkStyleSet *
|
||||||
|
gtk_settings_get_style (GtkStyleProvider *provider,
|
||||||
|
GtkWidgetPath *path)
|
||||||
|
{
|
||||||
|
PangoFontDescription *font_desc;
|
||||||
|
gchar *font_name, *color_scheme;
|
||||||
|
GtkSettings *settings;
|
||||||
|
GtkStyleSet *set;
|
||||||
|
gchar **colors;
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
settings = GTK_SETTINGS (provider);
|
||||||
|
set = gtk_style_set_new ();
|
||||||
|
|
||||||
|
g_object_get (settings,
|
||||||
|
"gtk-font-name", &font_name,
|
||||||
|
"gtk-color-scheme", &color_scheme,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
colors = g_strsplit_set (color_scheme, "\n;", -1);
|
||||||
|
|
||||||
|
for (i = 0; colors[i]; i++)
|
||||||
|
{
|
||||||
|
gchar *name, *pos;
|
||||||
|
GdkColor col;
|
||||||
|
|
||||||
|
if (!*colors[i])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
name = colors[i];
|
||||||
|
pos = strchr (colors[i], ':');
|
||||||
|
|
||||||
|
if (!pos)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Set NUL after color name */
|
||||||
|
*pos = '\0';
|
||||||
|
pos++;
|
||||||
|
|
||||||
|
/* Find start of color string */
|
||||||
|
while (*pos == ' ')
|
||||||
|
pos++;
|
||||||
|
|
||||||
|
if (!*pos || !gdk_color_parse (pos, &col))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
gtk_style_set_map_color (set, name,
|
||||||
|
gtk_symbolic_color_new_literal (&col));
|
||||||
|
}
|
||||||
|
|
||||||
|
font_desc = pango_font_description_from_string (font_name);
|
||||||
|
|
||||||
|
gtk_style_set_set (set, 0,
|
||||||
|
"font", font_desc,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
pango_font_description_free (font_desc);
|
||||||
|
g_strfreev (colors);
|
||||||
|
g_free (color_scheme);
|
||||||
|
g_free (font_name);
|
||||||
|
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
|
||||||
|
{
|
||||||
|
iface->get_style = gtk_settings_get_style;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_settings_finalize (GObject *object)
|
gtk_settings_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
|
@ -35,8 +35,9 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
#define GTK_STYLE_PROVIDER_PRIORITY_FALLBACK 1
|
#define GTK_STYLE_PROVIDER_PRIORITY_FALLBACK 1
|
||||||
#define GTK_STYLE_PROVIDER_PRIORITY_DEFAULT 200
|
#define GTK_STYLE_PROVIDER_PRIORITY_DEFAULT 200
|
||||||
#define GTK_STYLE_PROVIDER_PRIORITY_APPLICATION 400
|
#define GTK_STYLE_PROVIDER_PRIORITY_SETTINGS 400
|
||||||
#define GTK_STYLE_PROVIDER_PRIORITY_USER 600
|
#define GTK_STYLE_PROVIDER_PRIORITY_APPLICATION 600
|
||||||
|
#define GTK_STYLE_PROVIDER_PRIORITY_USER 800
|
||||||
|
|
||||||
typedef struct GtkStyleProviderIface GtkStyleProviderIface;
|
typedef struct GtkStyleProviderIface GtkStyleProviderIface;
|
||||||
typedef struct GtkStyleProvider GtkStyleProvider; /* dummy typedef */
|
typedef struct GtkStyleProvider GtkStyleProvider; /* dummy typedef */
|
||||||
|
@ -13308,6 +13308,7 @@ gtk_widget_get_style_context (GtkWidget *widget)
|
|||||||
static GtkCssProvider *css_provider = NULL;
|
static GtkCssProvider *css_provider = NULL;
|
||||||
GtkCssProvider *default_provider;
|
GtkCssProvider *default_provider;
|
||||||
GtkWidgetPath *path;
|
GtkWidgetPath *path;
|
||||||
|
GtkSettings *settings;
|
||||||
|
|
||||||
context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
|
context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
|
||||||
"direction", gtk_widget_get_direction (widget),
|
"direction", gtk_widget_get_direction (widget),
|
||||||
@ -13347,6 +13348,11 @@ gtk_widget_get_style_context (GtkWidget *widget)
|
|||||||
GTK_STYLE_PROVIDER (default_provider),
|
GTK_STYLE_PROVIDER (default_provider),
|
||||||
GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
|
GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
|
||||||
|
|
||||||
|
settings = gtk_widget_get_settings (widget);
|
||||||
|
gtk_style_context_add_provider (context,
|
||||||
|
GTK_STYLE_PROVIDER (settings),
|
||||||
|
GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
|
||||||
|
|
||||||
path = gtk_widget_get_path (widget);
|
path = gtk_widget_get_path (widget);
|
||||||
gtk_style_context_set_path (context, path);
|
gtk_style_context_set_path (context, path);
|
||||||
gtk_widget_path_free (path);
|
gtk_widget_path_free (path);
|
||||||
|
Loading…
Reference in New Issue
Block a user