Commit de3155a4 authored by Michael Natterer's avatar Michael Natterer Committed by Michael Natterer

Added symbolic themable colors. Patch is a merged version of proposals

2005-11-23  Michael Natterer  <mitch@imendio.com>

	Added symbolic themable colors. Patch is a merged version of
	proposals from Matthias and maemo-gtk. Fixes bug #114355.

	* configure.in: require glib >= 2.9.1 for refcountable hashtables.

	* gtk/gtksettings.c: added property "color-scheme" which is a
	string defining colors like "foreground:black\nbackground:grey".
	Automatically provide a name->GdkColor hash table mapping for the
	color scheme.

	* gtk/gtkrc.[ch]: added list of color hashes that works like the
	list of icon factories. Append the color scheme hash from
	GtkSettings if it exists. Extended gtkrc syntax to allow defining
	and referencing of logical colors. Also allow to modulate colors
	in gtkrc by using arbitrary expressions of mix(), shade(),
	lighter() and darker(). Added internal function
	_gtk_rc_style_get_color_hashes().

	* gtk/gtkstyle.[ch]: keep a private list of color hashes around.
	Get the list from _gtk_rc_style_get_color_hashes(). Export
	internal function _gtk_style_shade() (used by above color
	expressions). Added public API gtk_style_lookup_color() which
	looks up a logical color by name.

	* gtk/gtk.symbols: add gtk_style_lookup_color

	* tests/testgtkrc: use symbolic colors for making
	the scrollbars red.
parent dfa4870b
2005-11-23 Michael Natterer <mitch@imendio.com>
Added symbolic themable colors. Patch is a merged version of
proposals from Matthias and maemo-gtk. Fixes bug #114355.
* configure.in: require glib >= 2.9.1 for refcountable hashtables.
* gtk/gtksettings.c: added property "color-scheme" which is a
string defining colors like "foreground:black\nbackground:grey".
Automatically provide a name->GdkColor hash table mapping for the
color scheme.
* gtk/gtkrc.[ch]: added list of color hashes that works like the
list of icon factories. Append the color scheme hash from
GtkSettings if it exists. Extended gtkrc syntax to allow defining
and referencing of logical colors. Also allow to modulate colors
in gtkrc by using arbitrary expressions of mix(), shade(),
lighter() and darker(). Added internal function
_gtk_rc_style_get_color_hashes().
* gtk/gtkstyle.[ch]: keep a private list of color hashes around.
Get the list from _gtk_rc_style_get_color_hashes(). Export
internal function _gtk_style_shade() (used by above color
expressions). Added public API gtk_style_lookup_color() which
looks up a logical color by name.
* gtk/gtk.symbols: add gtk_style_lookup_color
* tests/testgtkrc: use symbolic colors for making
the scrollbars red.
2005-11-22 Michael Natterer <mitch@imendio.com>
Made button-press timeouts which work like key repeat timeouts
......
2005-11-23 Michael Natterer <mitch@imendio.com>
Added symbolic themable colors. Patch is a merged version of
proposals from Matthias and maemo-gtk. Fixes bug #114355.
* configure.in: require glib >= 2.9.1 for refcountable hashtables.
* gtk/gtksettings.c: added property "color-scheme" which is a
string defining colors like "foreground:black\nbackground:grey".
Automatically provide a name->GdkColor hash table mapping for the
color scheme.
* gtk/gtkrc.[ch]: added list of color hashes that works like the
list of icon factories. Append the color scheme hash from
GtkSettings if it exists. Extended gtkrc syntax to allow defining
and referencing of logical colors. Also allow to modulate colors
in gtkrc by using arbitrary expressions of mix(), shade(),
lighter() and darker(). Added internal function
_gtk_rc_style_get_color_hashes().
* gtk/gtkstyle.[ch]: keep a private list of color hashes around.
Get the list from _gtk_rc_style_get_color_hashes(). Export
internal function _gtk_style_shade() (used by above color
expressions). Added public API gtk_style_lookup_color() which
looks up a logical color by name.
* gtk/gtk.symbols: add gtk_style_lookup_color
* tests/testgtkrc: use symbolic colors for making
the scrollbars red.
2005-11-22 Michael Natterer <mitch@imendio.com>
Made button-press timeouts which work like key repeat timeouts
......
......@@ -31,7 +31,7 @@ m4_define([gtk_api_version], [2.0])
m4_define([gtk_binary_version], [2.4.0])
# required versions of other packages
m4_define([glib_required_version], [2.9.0])
m4_define([glib_required_version], [2.9.1])
m4_define([pango_required_version], [1.9.0])
m4_define([atk_required_version], [1.0.1])
m4_define([cairo_required_version], [0.9.2])
......
......@@ -1068,6 +1068,7 @@ gtk_style_copy
gtk_style_detach
gtk_style_get_type G_GNUC_CONST
gtk_style_lookup_icon_set
gtk_style_lookup_color
gtk_style_new
gtk_style_render_icon
gtk_style_set_background
......
This diff is collapsed.
......@@ -209,6 +209,7 @@ typedef enum {
GTK_RC_TOKEN_STOCK,
GTK_RC_TOKEN_LTR,
GTK_RC_TOKEN_RTL,
GTK_RC_TOKEN_COLOR,
GTK_RC_TOKEN_LAST
} GtkRcTokenType;
......@@ -237,6 +238,8 @@ const GtkRcProperty* _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style,
GQuark type_name,
GQuark property_name);
GSList * _gtk_rc_style_get_color_hashes (GtkRcStyle *rc_style);
const gchar* _gtk_rc_context_get_default_font_name (GtkSettings *settings);
G_END_DECLS
......
......@@ -84,7 +84,8 @@ enum {
PROP_SHOW_INPUT_METHOD_MENU,
PROP_SHOW_UNICODE_MENU,
PROP_TIMEOUT_INITIAL,
PROP_TIMEOUT_REPEAT
PROP_TIMEOUT_REPEAT,
PROP_COLOR_SCHEME
};
......@@ -107,6 +108,7 @@ static guint settings_install_property_parser (GtkSettingsClass *class,
GtkRcPropertyParser parser);
static void settings_update_double_click (GtkSettings *settings);
static void settings_update_modules (GtkSettings *settings);
static void settings_update_color_scheme (GtkSettings *settings);
#ifdef GDK_WINDOWING_X11
static void settings_update_cursor_theme (GtkSettings *settings);
......@@ -416,7 +418,7 @@ gtk_settings_class_init (GtkSettingsClass *class)
P_("Start timeout"),
P_("Starting value for timeouts, when button is pressed"),
0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
G_PARAM_READWRITE),
GTK_PARAM_READWRITE),
NULL);
g_assert (result == PROP_TIMEOUT_INITIAL);
......@@ -426,10 +428,20 @@ gtk_settings_class_init (GtkSettingsClass *class)
P_("Repeat timeout"),
P_("Repeat value for timeouts, when button is pressed"),
0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
G_PARAM_READWRITE),
GTK_PARAM_READWRITE),
NULL);
g_assert (result == PROP_TIMEOUT_REPEAT);
result = settings_install_property_parser (class,
g_param_spec_string ("gtk-color-scheme",
P_("Color scheme"),
P_("A palette of named colors for use in themes"),
"foreground:black\nbackground:gray",
GTK_PARAM_READWRITE),
NULL);
g_assert (result == PROP_COLOR_SCHEME);
}
static void
......@@ -602,6 +614,9 @@ gtk_settings_notify (GObject *object,
case PROP_MODULES:
settings_update_modules (settings);
break;
case PROP_COLOR_SCHEME:
settings_update_color_scheme (settings);
break;
case PROP_DOUBLE_CLICK_TIME:
case PROP_DOUBLE_CLICK_DISTANCE:
settings_update_double_click (settings);
......@@ -1511,5 +1526,81 @@ settings_update_resolution (GtkSettings *settings)
}
#endif
static GHashTable *
gtk_color_table_from_string (const gchar *str)
{
gchar *copy, *s, *p, *name;
GdkColor color;
GHashTable *colors;
colors = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) gdk_color_free);
copy = g_strdup (str);
s = copy;
while (s && *s)
{
name = s;
p = strchr (s, ':');
if (p)
{
*p = '\0';
p++;
}
else
{
g_hash_table_destroy (colors);
colors = NULL;
break;
}
while (*p == ' ')
p++;
s = strchr (p, '\n');
if (s)
{
*s = '\0';
s++;
}
if (!gdk_color_parse (p, &color))
{
g_hash_table_destroy (colors);
colors = NULL;
break;
}
g_hash_table_insert (colors,
g_strdup (name),
gdk_color_copy (&color));
}
g_free (copy);
return colors;
}
static void
settings_update_color_scheme (GtkSettings *settings)
{
gchar *colors;
GHashTable *color_hash;
g_object_get (settings,
"gtk-color-scheme", &colors,
NULL);
color_hash = gtk_color_table_from_string (colors);
g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
color_hash, (GDestroyNotify) g_hash_table_unref);
g_free (colors);
}
#define __GTK_SETTINGS_C__
#include "gtkaliasdef.c"
......@@ -50,6 +50,14 @@ typedef struct {
GValue value;
} PropertyValue;
#define GTK_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_STYLE, GtkStylePrivate))
typedef struct _GtkStylePrivate GtkStylePrivate;
struct _GtkStylePrivate {
GSList *color_hashes;
};
/* --- prototypes --- */
static void gtk_style_init (GtkStyle *style);
static void gtk_style_class_init (GtkStyleClass *klass);
......@@ -305,9 +313,6 @@ static void gtk_default_draw_resize_grip (GtkStyle *style,
gint width,
gint height);
static void gtk_style_shade (GdkColor *a,
GdkColor *b,
gdouble k);
static void rgb_to_hls (gdouble *r,
gdouble *g,
gdouble *b);
......@@ -534,7 +539,8 @@ gtk_style_class_init (GtkStyleClass *klass)
klass->draw_layout = gtk_default_draw_layout;
klass->draw_resize_grip = gtk_default_draw_resize_grip;
g_type_class_add_private (object_class, sizeof (GtkStylePrivate));
/**
* GtkStyle::realize:
* @style: the object which received the signal
......@@ -596,6 +602,7 @@ static void
gtk_style_finalize (GObject *object)
{
GtkStyle *style = GTK_STYLE (object);
GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
g_return_if_fail (style->attach_count == 0);
......@@ -625,18 +632,11 @@ gtk_style_finalize (GObject *object)
}
}
if (style->icon_factories)
{
GSList *tmp_list = style->icon_factories;
g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
g_slist_free (style->icon_factories);
while (tmp_list)
{
g_object_unref (tmp_list->data);
tmp_list = tmp_list->next;
}
g_slist_free (style->icon_factories);
}
g_slist_foreach (priv->color_hashes, (GFunc) g_hash_table_unref, NULL);
g_slist_free (priv->color_hashes);
pango_font_description_free (style->font_desc);
......@@ -895,6 +895,53 @@ gtk_style_lookup_icon_set (GtkStyle *style,
return gtk_icon_factory_lookup_default (stock_id);
}
/**
* gtk_style_lookup_color:
* @style: a #GtkStyle
* @color_name: the name of the logical color to look up
* @color: the #GdkColor to fill in
*
* Looks up @color_name in the style's logical color mappings,
* filling in @color and returning %TRUE if found, otherwise
* returning %FALSE. Do not cache the found mapping, because
* it depends on the #GtkStyle and might change when a theme
* switch occurs.
*
* Return value: %TRUE if the mapping was found.
*
* Since: 2.10
**/
gboolean
gtk_style_lookup_color (GtkStyle *style,
const char *color_name,
GdkColor *color)
{
GtkStylePrivate *priv;
GSList *iter;
g_return_val_if_fail (GTK_IS_STYLE (style), FALSE);
g_return_val_if_fail (color_name != NULL, FALSE);
g_return_val_if_fail (color != NULL, FALSE);
priv = GTK_STYLE_GET_PRIVATE (style);
for (iter = priv->color_hashes; iter != NULL; iter = iter->next)
{
GHashTable *hash = iter->data;
GdkColor *mapping = g_hash_table_lookup (hash, color_name);
if (mapping)
{
color->red = mapping->red;
color->green = mapping->green;
color->blue = mapping->blue;
return TRUE;
}
}
return FALSE;
}
/**
* gtk_draw_hline:
* @style: a #GtkStyle
......@@ -1613,6 +1660,7 @@ static void
gtk_style_real_init_from_rc (GtkStyle *style,
GtkRcStyle *rc_style)
{
GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
gint i;
/* cache _should_ be still empty */
......@@ -1638,19 +1686,11 @@ gtk_style_real_init_from_rc (GtkStyle *style,
if (rc_style->ythickness >= 0)
style->ythickness = rc_style->ythickness;
if (rc_style->icon_factories)
{
GSList *iter;
style->icon_factories = g_slist_copy (rc_style->icon_factories);
g_slist_foreach (style->icon_factories, (GFunc) g_object_ref, NULL);
style->icon_factories = g_slist_copy (rc_style->icon_factories);
iter = style->icon_factories;
while (iter != NULL)
{
g_object_ref (iter->data);
iter = g_slist_next (iter);
}
}
priv->color_hashes = g_slist_copy (_gtk_rc_style_get_color_hashes (rc_style));
g_slist_foreach (priv->color_hashes, (GFunc) g_hash_table_ref, NULL);
}
static gint
......@@ -1773,9 +1813,9 @@ gtk_style_real_realize (GtkStyle *style)
for (i = 0; i < 5; i++)
{
gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
_gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
_gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
......@@ -3396,7 +3436,7 @@ get_darkened_gc (GdkWindow *window,
while (darken_count)
{
gtk_style_shade (&src, &shaded, 0.93);
_gtk_style_shade (&src, &shaded, 0.93);
src = shaded;
--darken_count;
}
......@@ -4705,9 +4745,9 @@ gtk_default_draw_handle (GtkStyle *style,
if (state_type == GTK_STATE_SELECTED && widget && !GTK_WIDGET_HAS_FOCUS (widget))
{
GdkColor unfocused_light;
gtk_style_shade (&style->base[GTK_STATE_ACTIVE], &unfocused_light,
LIGHTNESS_MULT);
_gtk_style_shade (&style->base[GTK_STATE_ACTIVE], &unfocused_light,
LIGHTNESS_MULT);
light_gc = free_me = gdk_gc_new (window);
gdk_gc_set_rgb_fg_color (light_gc, &unfocused_light);
......@@ -5417,10 +5457,10 @@ gtk_default_draw_resize_grip (GtkStyle *style,
}
}
static void
gtk_style_shade (GdkColor *a,
GdkColor *b,
gdouble k)
void
_gtk_style_shade (GdkColor *a,
GdkColor *b,
gdouble k)
{
gdouble red;
gdouble green;
......
......@@ -452,8 +452,12 @@ void gtk_style_apply_default_background (GtkStyle *style,
gint width,
gint height);
GtkIconSet* gtk_style_lookup_icon_set (GtkStyle *style,
const gchar *stock_id);
GtkIconSet* gtk_style_lookup_icon_set (GtkStyle *style,
const gchar *stock_id);
gboolean gtk_style_lookup_color (GtkStyle *style,
const gchar *color_name,
GdkColor *color);
GdkPixbuf* gtk_style_render_icon (GtkStyle *style,
const GtkIconSource *source,
GtkTextDirection direction,
......@@ -461,6 +465,7 @@ GdkPixbuf* gtk_style_render_icon (GtkStyle *style,
GtkIconSize size,
GtkWidget *widget,
const gchar *detail);
#ifndef GTK_DISABLE_DEPRECATED
void gtk_draw_hline (GtkStyle *style,
GdkWindow *window,
......@@ -852,7 +857,7 @@ void gtk_paint_resize_grip (GtkStyle *style,
GType gtk_border_get_type (void) G_GNUC_CONST;
GtkBorder *gtk_border_copy (const GtkBorder *border_);
void gtk_border_free ( GtkBorder *border_);
void gtk_border_free (GtkBorder *border_);
/* --- private API --- */
const GValue* _gtk_style_peek_property_value (GtkStyle *style,
......@@ -860,8 +865,12 @@ const GValue* _gtk_style_peek_property_value (GtkStyle *style,
GParamSpec *pspec,
GtkRcPropertyParser parser);
void _gtk_style_init_for_settings (GtkStyle *style,
GtkSettings *settings);
void _gtk_style_init_for_settings (GtkStyle *style,
GtkSettings *settings);
void _gtk_style_shade (GdkColor *a,
GdkColor *b,
gdouble k);
/* deprecated */
#ifndef GTK_DISABLE_DEPRECATED
......
......@@ -109,9 +109,17 @@ style "curve"
fg[NORMAL] = { 58000, 0, 0 } # red
}
style "red-bar"
style "red-bar-parent"
{
bg[PRELIGHT] = { 0.95, .55, 0.55 }
color["my-red"] = "red"
color["my-other-red"] = { 0.95, .55, 0.55 }
}
style "red-bar" = "red-bar-parent"
{
color["my-light-red"] = lighter (lighter (@my-red))
bg[PRELIGHT] = @my-light-red
}
# override testgtk2, introduce the green color in the button list
......
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