win32: Update color handling to recent GtkWin32Theme changes
This commit is contained in:
@ -62,7 +62,7 @@ struct _GtkCssValue
|
|||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
gchar *theme_class;
|
GtkWin32Theme *theme;
|
||||||
gint id;
|
gint id;
|
||||||
} win32;
|
} win32;
|
||||||
} sym_col;
|
} sym_col;
|
||||||
@ -90,7 +90,7 @@ gtk_css_value_color_free (GtkCssValue *color)
|
|||||||
_gtk_css_value_unref (color->sym_col.mix.color2);
|
_gtk_css_value_unref (color->sym_col.mix.color2);
|
||||||
break;
|
break;
|
||||||
case COLOR_TYPE_WIN32:
|
case COLOR_TYPE_WIN32:
|
||||||
g_free (color->sym_col.win32.theme_class);
|
gtk_win32_theme_unref (color->sym_col.win32.theme);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -243,10 +243,9 @@ _gtk_css_color_value_resolve (GtkCssValue *color,
|
|||||||
{
|
{
|
||||||
GdkRGBA res;
|
GdkRGBA res;
|
||||||
|
|
||||||
if (!_gtk_win32_theme_color_resolve (color->sym_col.win32.theme_class,
|
gtk_win32_theme_get_color (color->sym_col.win32.theme,
|
||||||
color->sym_col.win32.id,
|
color->sym_col.win32.id,
|
||||||
&res))
|
&res);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
value = _gtk_css_rgba_value_new_from_rgba (&res);
|
value = _gtk_css_rgba_value_new_from_rgba (&res);
|
||||||
}
|
}
|
||||||
@ -350,7 +349,7 @@ gtk_css_value_color_equal (const GtkCssValue *value1,
|
|||||||
_gtk_css_value_equal (value1->sym_col.mix.color2,
|
_gtk_css_value_equal (value1->sym_col.mix.color2,
|
||||||
value2->sym_col.mix.color2);
|
value2->sym_col.mix.color2);
|
||||||
case COLOR_TYPE_WIN32:
|
case COLOR_TYPE_WIN32:
|
||||||
return g_str_equal (value1->sym_col.win32.theme_class, value2->sym_col.win32.theme_class) &&
|
return gtk_win32_theme_equal (value1->sym_col.win32.theme, value2->sym_col.win32.theme) &&
|
||||||
value1->sym_col.win32.id == value2->sym_col.win32.id;
|
value1->sym_col.win32.id == value2->sym_col.win32.id;
|
||||||
case COLOR_TYPE_CURRENT_COLOR:
|
case COLOR_TYPE_CURRENT_COLOR:
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -422,8 +421,9 @@ gtk_css_value_color_print (const GtkCssValue *value,
|
|||||||
break;
|
break;
|
||||||
case COLOR_TYPE_WIN32:
|
case COLOR_TYPE_WIN32:
|
||||||
{
|
{
|
||||||
g_string_append_printf (string, GTK_WIN32_THEME_SYMBOLIC_COLOR_NAME"(%s, %d)",
|
g_string_append (string, GTK_WIN32_THEME_SYMBOLIC_COLOR_NAME"(");
|
||||||
value->sym_col.win32.theme_class, value->sym_col.win32.id);
|
gtk_win32_theme_print (value->sym_col.win32.theme, string);
|
||||||
|
g_string_append_printf (string, "%d)", value->sym_col.win32.id);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case COLOR_TYPE_CURRENT_COLOR:
|
case COLOR_TYPE_CURRENT_COLOR:
|
||||||
@ -532,22 +532,38 @@ _gtk_css_color_value_new_mix (GtkCssValue *color1,
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkCssValue *
|
static GtkCssValue *
|
||||||
_gtk_css_color_value_new_win32 (const gchar *theme_class,
|
gtk_css_color_value_new_win32_for_theme (GtkWin32Theme *theme,
|
||||||
gint id)
|
gint id)
|
||||||
{
|
{
|
||||||
GtkCssValue *value;
|
GtkCssValue *value;
|
||||||
|
|
||||||
gtk_internal_return_val_if_fail (theme_class != NULL, NULL);
|
gtk_internal_return_val_if_fail (theme != NULL, NULL);
|
||||||
|
|
||||||
value = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_COLOR);
|
value = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_COLOR);
|
||||||
value->type = COLOR_TYPE_WIN32;
|
value->type = COLOR_TYPE_WIN32;
|
||||||
value->sym_col.win32.theme_class = g_strdup (theme_class);
|
value->sym_col.win32.theme = gtk_win32_theme_ref (theme);
|
||||||
value->sym_col.win32.id = id;
|
value->sym_col.win32.id = id;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GtkCssValue *
|
||||||
|
_gtk_css_color_value_new_win32 (const gchar *theme_class,
|
||||||
|
gint id)
|
||||||
|
{
|
||||||
|
GtkWin32Theme *theme;
|
||||||
|
GtkCssValue *value;
|
||||||
|
|
||||||
|
gtk_internal_return_val_if_fail (theme_class != NULL, NULL);
|
||||||
|
|
||||||
|
theme = gtk_win32_theme_lookup (theme_class);
|
||||||
|
value = gtk_css_color_value_new_win32_for_theme (theme, id);
|
||||||
|
gtk_win32_theme_unref (theme);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
GtkCssValue *
|
GtkCssValue *
|
||||||
_gtk_css_color_value_new_current_color (void)
|
_gtk_css_color_value_new_current_color (void)
|
||||||
{
|
{
|
||||||
@ -571,20 +587,16 @@ static GtkCssValue *
|
|||||||
gtk_css_color_parse_win32 (GtkCssParser *parser)
|
gtk_css_color_parse_win32 (GtkCssParser *parser)
|
||||||
{
|
{
|
||||||
GtkCssValue *color;
|
GtkCssValue *color;
|
||||||
char *class;
|
GtkWin32Theme *theme;
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
class = _gtk_css_parser_try_name (parser, TRUE);
|
theme = gtk_win32_theme_parse (parser);
|
||||||
if (class == NULL)
|
if (theme == NULL)
|
||||||
{
|
|
||||||
_gtk_css_parser_error (parser,
|
|
||||||
"Expected name as first argument to '-gtk-win32-color'");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (! _gtk_css_parser_try (parser, ",", TRUE))
|
if (! _gtk_css_parser_try (parser, ",", TRUE))
|
||||||
{
|
{
|
||||||
g_free (class);
|
gtk_win32_theme_unref (theme);
|
||||||
_gtk_css_parser_error (parser,
|
_gtk_css_parser_error (parser,
|
||||||
"Expected ','");
|
"Expected ','");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -592,13 +604,13 @@ gtk_css_color_parse_win32 (GtkCssParser *parser)
|
|||||||
|
|
||||||
if (!_gtk_css_parser_try_int (parser, &id))
|
if (!_gtk_css_parser_try_int (parser, &id))
|
||||||
{
|
{
|
||||||
g_free (class);
|
gtk_win32_theme_unref (theme);
|
||||||
_gtk_css_parser_error (parser, "Expected a valid integer value");
|
_gtk_css_parser_error (parser, "Expected a valid integer value");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
color = _gtk_css_color_value_new_win32 (class, id);
|
color = gtk_css_color_value_new_win32_for_theme (theme, id);
|
||||||
g_free (class);
|
gtk_win32_theme_unref (theme);
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ typedef HRESULT (FAR PASCAL *GetThemePartSizeFunc) (HTHEME hTheme,
|
|||||||
SIZE *psz);
|
SIZE *psz);
|
||||||
|
|
||||||
static GetThemeSysFontFunc get_theme_sys_font = NULL;
|
static GetThemeSysFontFunc get_theme_sys_font = NULL;
|
||||||
static GetThemeSysColorFunc get_theme_sys_color = NULL;
|
static GetThemeSysColorFunc GetThemeSysColor = NULL;
|
||||||
static GetThemeSysSizeFunc get_theme_sys_metric = NULL;
|
static GetThemeSysSizeFunc get_theme_sys_metric = NULL;
|
||||||
static OpenThemeDataFunc OpenThemeData = NULL;
|
static OpenThemeDataFunc OpenThemeData = NULL;
|
||||||
static CloseThemeDataFunc CloseThemeData = NULL;
|
static CloseThemeDataFunc CloseThemeData = NULL;
|
||||||
@ -205,7 +205,7 @@ gtk_win32_theme_init (void)
|
|||||||
draw_theme_background = (DrawThemeBackgroundFunc) GetProcAddress (uxtheme_dll, "DrawThemeBackground");
|
draw_theme_background = (DrawThemeBackgroundFunc) GetProcAddress (uxtheme_dll, "DrawThemeBackground");
|
||||||
enable_theme_dialog_texture = (EnableThemeDialogTextureFunc) GetProcAddress (uxtheme_dll, "EnableThemeDialogTexture");
|
enable_theme_dialog_texture = (EnableThemeDialogTextureFunc) GetProcAddress (uxtheme_dll, "EnableThemeDialogTexture");
|
||||||
get_theme_sys_font = (GetThemeSysFontFunc) GetProcAddress (uxtheme_dll, "GetThemeSysFont");
|
get_theme_sys_font = (GetThemeSysFontFunc) GetProcAddress (uxtheme_dll, "GetThemeSysFont");
|
||||||
get_theme_sys_color = (GetThemeSysColorFunc) GetProcAddress (uxtheme_dll, "GetThemeSysColor");
|
GetThemeSysColor = (GetThemeSysColorFunc) GetProcAddress (uxtheme_dll, "GetThemeSysColor");
|
||||||
get_theme_sys_metric = (GetThemeSysSizeFunc) GetProcAddress (uxtheme_dll, "GetThemeSysSize");
|
get_theme_sys_metric = (GetThemeSysSizeFunc) GetProcAddress (uxtheme_dll, "GetThemeSysSize");
|
||||||
is_theme_partially_transparent = (IsThemeBackgroundPartiallyTransparentFunc) GetProcAddress (uxtheme_dll, "IsThemeBackgroundPartiallyTransparent");
|
is_theme_partially_transparent = (IsThemeBackgroundPartiallyTransparentFunc) GetProcAddress (uxtheme_dll, "IsThemeBackgroundPartiallyTransparent");
|
||||||
draw_theme_parent_background = (DrawThemeParentBackgroundFunc) GetProcAddress (uxtheme_dll, "DrawThemeParentBackground");
|
draw_theme_parent_background = (DrawThemeParentBackgroundFunc) GetProcAddress (uxtheme_dll, "DrawThemeParentBackground");
|
||||||
@ -251,22 +251,27 @@ canonicalize_class_name (const char *classname)
|
|||||||
return g_ascii_strdown (classname, -1);
|
return g_ascii_strdown (classname, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GtkWin32Theme *
|
GtkWin32Theme *
|
||||||
gtk_win32_theme_lookup (const char *classname)
|
gtk_win32_theme_lookup (const char *classname)
|
||||||
{
|
{
|
||||||
GtkWin32Theme *theme;
|
GtkWin32Theme *theme;
|
||||||
|
char *canonical_classname;
|
||||||
|
|
||||||
if (G_UNLIKELY (themes_by_class == NULL))
|
if (G_UNLIKELY (themes_by_class == NULL))
|
||||||
themes_by_class = g_hash_table_new (g_str_hash, g_str_equal);
|
themes_by_class = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
|
|
||||||
theme = g_hash_table_lookup (themes_by_class, classname);
|
canonical_classname = canonicalize_class_name (classname);
|
||||||
|
theme = g_hash_table_lookup (themes_by_class, canonical_classname);
|
||||||
|
|
||||||
if (theme != NULL)
|
if (theme != NULL)
|
||||||
|
{
|
||||||
|
g_free (canonical_classname);
|
||||||
return gtk_win32_theme_ref (theme);
|
return gtk_win32_theme_ref (theme);
|
||||||
|
}
|
||||||
|
|
||||||
theme = g_slice_new0 (GtkWin32Theme);
|
theme = g_slice_new0 (GtkWin32Theme);
|
||||||
theme->ref_count = 1;
|
theme->ref_count = 1;
|
||||||
theme->class_name = g_strdup (classname);
|
theme->class_name = canonical_classname;
|
||||||
|
|
||||||
g_hash_table_insert (themes_by_class, theme->class_name, theme);
|
g_hash_table_insert (themes_by_class, theme->class_name, theme);
|
||||||
|
|
||||||
@ -277,7 +282,7 @@ GtkWin32Theme *
|
|||||||
gtk_win32_theme_parse (GtkCssParser *parser)
|
gtk_win32_theme_parse (GtkCssParser *parser)
|
||||||
{
|
{
|
||||||
GtkWin32Theme *theme;
|
GtkWin32Theme *theme;
|
||||||
char *canonical_class_name, *class_name;
|
char *class_name;
|
||||||
|
|
||||||
class_name = _gtk_css_parser_try_name (parser, TRUE);
|
class_name = _gtk_css_parser_try_name (parser, TRUE);
|
||||||
if (class_name == NULL)
|
if (class_name == NULL)
|
||||||
@ -285,10 +290,8 @@ gtk_win32_theme_parse (GtkCssParser *parser)
|
|||||||
_gtk_css_parser_error (parser, "Expected valid win32 theme name");
|
_gtk_css_parser_error (parser, "Expected valid win32 theme name");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
canonical_class_name = canonicalize_class_name (class_name);
|
|
||||||
|
|
||||||
theme = gtk_win32_theme_lookup (canonical_class_name);
|
theme = gtk_win32_theme_lookup (class_name);
|
||||||
g_free (canonical_class_name);
|
|
||||||
g_free (class_name);
|
g_free (class_name);
|
||||||
|
|
||||||
return theme;
|
return theme;
|
||||||
@ -405,30 +408,25 @@ gtk_win32_theme_get_size (GtkWin32Theme *theme,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
_gtk_win32_theme_color_resolve (const char *theme_class,
|
gtk_win32_theme_get_color (GtkWin32Theme *theme,
|
||||||
gint id,
|
gint id,
|
||||||
GdkRGBA *color)
|
GdkRGBA *color)
|
||||||
{
|
{
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
GtkWin32Theme *theme;
|
|
||||||
HTHEME htheme;
|
HTHEME htheme;
|
||||||
DWORD dcolor;
|
DWORD dcolor;
|
||||||
|
|
||||||
theme = gtk_win32_theme_lookup (theme_class);
|
if (use_xp_theme && GetThemeSysColor != NULL)
|
||||||
if (use_xp_theme && get_theme_sys_color != NULL)
|
|
||||||
{
|
{
|
||||||
htheme = gtk_win32_theme_get_htheme (theme);
|
htheme = gtk_win32_theme_get_htheme (theme);
|
||||||
|
|
||||||
/* if htheme is NULL, it will just return the GetSystemColor()
|
/* if htheme is NULL, it will just return the GetSysColor() value */
|
||||||
value */
|
dcolor = GetThemeSysColor (htheme, id);
|
||||||
dcolor = get_theme_sys_color (htheme, id);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
dcolor = GetSysColor (id);
|
dcolor = GetSysColor (id);
|
||||||
|
|
||||||
gtk_win32_theme_unref (theme);
|
|
||||||
|
|
||||||
color->alpha = 1.0;
|
color->alpha = 1.0;
|
||||||
color->red = GetRValue (dcolor) / 255.0;
|
color->red = GetRValue (dcolor) / 255.0;
|
||||||
color->green = GetGValue (dcolor) / 255.0;
|
color->green = GetGValue (dcolor) / 255.0;
|
||||||
@ -436,7 +434,6 @@ _gtk_win32_theme_color_resolve (const char *theme_class,
|
|||||||
#else
|
#else
|
||||||
gdk_rgba_parse (color, "pink");
|
gdk_rgba_parse (color, "pink");
|
||||||
#endif
|
#endif
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -28,6 +28,7 @@ typedef struct _GtkWin32Theme GtkWin32Theme;
|
|||||||
|
|
||||||
#define GTK_WIN32_THEME_SYMBOLIC_COLOR_NAME "-gtk-win32-color"
|
#define GTK_WIN32_THEME_SYMBOLIC_COLOR_NAME "-gtk-win32-color"
|
||||||
|
|
||||||
|
GtkWin32Theme * gtk_win32_theme_lookup (const char *class_name);
|
||||||
GtkWin32Theme * gtk_win32_theme_parse (GtkCssParser *parser);
|
GtkWin32Theme * gtk_win32_theme_parse (GtkCssParser *parser);
|
||||||
|
|
||||||
GtkWin32Theme * gtk_win32_theme_ref (GtkWin32Theme *theme);
|
GtkWin32Theme * gtk_win32_theme_ref (GtkWin32Theme *theme);
|
||||||
@ -49,8 +50,7 @@ cairo_surface_t * gtk_win32_theme_create_surface (GtkWin32Theme *theme,
|
|||||||
int *y_offs_out);
|
int *y_offs_out);
|
||||||
int gtk_win32_theme_get_size (GtkWin32Theme *theme,
|
int gtk_win32_theme_get_size (GtkWin32Theme *theme,
|
||||||
int id);
|
int id);
|
||||||
|
void gtk_win32_theme_get_color (GtkWin32Theme *theme,
|
||||||
gboolean _gtk_win32_theme_color_resolve (const char *theme_class,
|
|
||||||
gint id,
|
gint id,
|
||||||
GdkRGBA *color);
|
GdkRGBA *color);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user