Commit 621a95f5 authored by Carlos Garnacho's avatar Carlos Garnacho

GtkSettings: implement GtkStyleProvider

parent 58a51bca
......@@ -179,6 +179,8 @@ enum {
};
/* --- prototypes --- */
static void gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
static void gtk_settings_finalize (GObject *object);
static void gtk_settings_get_property (GObject *object,
guint property_id,
......@@ -221,7 +223,9 @@ static GSList *object_list = NULL;
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 --- */
static void
......@@ -1246,6 +1250,76 @@ gtk_settings_class_init (GtkSettingsClass *class)
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
gtk_settings_finalize (GObject *object)
{
......
......@@ -35,8 +35,9 @@ G_BEGIN_DECLS
#define GTK_STYLE_PROVIDER_PRIORITY_FALLBACK 1
#define GTK_STYLE_PROVIDER_PRIORITY_DEFAULT 200
#define GTK_STYLE_PROVIDER_PRIORITY_APPLICATION 400
#define GTK_STYLE_PROVIDER_PRIORITY_USER 600
#define GTK_STYLE_PROVIDER_PRIORITY_SETTINGS 400
#define GTK_STYLE_PROVIDER_PRIORITY_APPLICATION 600
#define GTK_STYLE_PROVIDER_PRIORITY_USER 800
typedef struct GtkStyleProviderIface GtkStyleProviderIface;
typedef struct GtkStyleProvider GtkStyleProvider; /* dummy typedef */
......
......@@ -13308,6 +13308,7 @@ gtk_widget_get_style_context (GtkWidget *widget)
static GtkCssProvider *css_provider = NULL;
GtkCssProvider *default_provider;
GtkWidgetPath *path;
GtkSettings *settings;
context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
"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_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);
gtk_style_context_set_path (context, path);
gtk_widget_path_free (path);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment