Lightweight theme switching

This commit is contained in:
Raymond Penners 2003-10-07 19:58:28 +00:00
parent bb3f3dbc15
commit ab490bdcde
5 changed files with 86 additions and 33 deletions

View File

@ -1,3 +1,13 @@
2003-10-07 Raymond Penners <raymond@dotsphinx.com>
* src/wimp_style.c: Tabs not located on top of the notebook are
now (again) no longer rendered using XP theming.
* src/xp_theme.c: Added a more lightweight method to cope with
theme changes. Added a crude theme switch detection scheme in the
case that GTK+ does not implement gdk_window_add_filter properly
(GTK+ 2.2.0?).
2003-10-07 Dom Lachowicz <cinamod@hotmail.com>
* Added new mingw based build system, tidied up other missing bits
@ -5,9 +15,12 @@
2003-10-07 Raymond Penners <raymond@dotsphinx.com>
* src/wimp_style.c: Tabs not located on top of the notebook are
now (again) no longer rendered using XP theming.
now (again) no longer rendered using XP theming.
* src/xp_theme.c: We now properly use IsThemeActive().
* src/xp_theme.c: We now properly use IsThemeActive(). Added a
more lightweight method to cope with theme changes. Added a crude
theme switch detection scheme in the case that GTK+ does not
implement gdk_window_add_filter properly (GTK+ 2.2.0?).
* src/xp_theme_defs.h: Renamed from xp_theme_dfns.h

View File

@ -1113,6 +1113,7 @@ draw_box (GtkStyle *style,
else
{
gboolean is_default = !strcmp (detail, "buttondefault");
g_warning("BUTT");
if (xp_theme_draw(window, is_default ? XP_THEME_ELEMENT_DEFAULT_BUTTON
: XP_THEME_ELEMENT_BUTTON, style, x, y,
width, height, state_type, area))

View File

@ -49,7 +49,7 @@ global_filter_func (void *xevent,
/* catch theme changes */
case WM_THEMECHANGED:
case WM_SYSCOLORCHANGE:
xp_theme_exit();
xp_theme_reset ();
wimp_style_init ();
/* force all gtkwidgets to redraw */

View File

@ -118,8 +118,25 @@ static DrawThemeBackgroundFunc draw_theme_background_func = NULL;
static EnableThemeDialogTextureFunc enable_theme_dialog_texture_func = NULL;
static IsThemeActiveFunc is_theme_active_func = NULL;
static gboolean was_theming_active = FALSE;
static void
xp_theme_close_open_handles (void)
{
int i;
for (i=0; i < XP_THEME_CLASS__SIZEOF; i++)
{
if (open_themes[i])
{
close_theme_data_func (open_themes[i]);
open_themes[i] = NULL;
}
}
}
void
xp_theme_init(void)
xp_theme_init (void)
{
if (uxtheme_dll)
return;
@ -133,25 +150,30 @@ xp_theme_init(void)
draw_theme_background_func = (DrawThemeBackgroundFunc) GetProcAddress(uxtheme_dll, "DrawThemeBackground");
enable_theme_dialog_texture_func = (EnableThemeDialogTextureFunc) GetProcAddress(uxtheme_dll, "EnableThemeDialogTexture");
get_theme_sys_font_func = (GetThemeSysFontFunc) GetProcAddress(uxtheme_dll, "GetThemeSysFont");
if (is_theme_active_func)
{
was_theming_active = (*is_theme_active_func) ();
}
}
void
xp_theme_reset (void)
{
xp_theme_close_open_handles ();
was_theming_active = (*is_theme_active_func) ();
}
void
xp_theme_exit(void)
xp_theme_exit (void)
{
int i;
if (! uxtheme_dll)
return;
for (i=0; i < XP_THEME_CLASS__SIZEOF; i++)
{
if (open_themes[i])
{
close_theme_data_func(open_themes[i]);
open_themes[i] = NULL;
}
}
xp_theme_close_open_handles ();
FreeLibrary(uxtheme_dll);
FreeLibrary (uxtheme_dll);
uxtheme_dll = NULL;
is_theme_active_func = NULL;
@ -163,7 +185,7 @@ xp_theme_exit(void)
}
static HTHEME
xp_theme_get_handle_by_class(XpThemeClass klazz)
xp_theme_get_handle_by_class (XpThemeClass klazz)
{
if (!open_themes[klazz] && open_theme_data_func)
{
@ -173,7 +195,7 @@ xp_theme_get_handle_by_class(XpThemeClass klazz)
}
static HTHEME
xp_theme_get_handle_by_element(XpThemeElement element)
xp_theme_get_handle_by_element (XpThemeElement element)
{
HTHEME ret = NULL;
XpThemeClass klazz = XP_THEME_CLASS__SIZEOF;
@ -266,7 +288,7 @@ xp_theme_get_handle_by_element(XpThemeElement element)
}
static int
xp_theme_map_gtk_state(XpThemeElement element, GtkStateType state)
xp_theme_map_gtk_state (XpThemeElement element, GtkStateType state)
{
int ret;
@ -580,9 +602,9 @@ xp_theme_map_gtk_state(XpThemeElement element, GtkStateType state)
}
gboolean
xp_theme_draw(GdkWindow *win, XpThemeElement element, GtkStyle *style,
int x, int y, int width, int height, GtkStateType state_type,
GdkRectangle *area)
xp_theme_draw (GdkWindow *win, XpThemeElement element, GtkStyle *style,
int x, int y, int width, int height,
GtkStateType state_type, GdkRectangle *area)
{
HTHEME theme;
RECT rect, clip, *pClip;
@ -643,17 +665,32 @@ xp_theme_draw(GdkWindow *win, XpThemeElement element, GtkStyle *style,
}
gboolean
xp_theme_is_drawable(XpThemeElement element)
xp_theme_is_drawable (XpThemeElement element)
{
if (is_theme_active_func && (*is_theme_active_func)())
gboolean ret = FALSE;
if (is_theme_active_func)
{
return (xp_theme_get_handle_by_element(element) != NULL);
gboolean active = (*is_theme_active_func) ();
// A bit of a hack, but it at least detects theme
// switches between XP and classic looks on systems
// using older GTK+ version (2.2.0-?) that do not
// support theme switch detection (gdk_window_add_filter).
if (active != was_theming_active)
{
xp_theme_reset ();
}
if (active)
{
ret = (xp_theme_get_handle_by_element (element) != NULL);
}
}
return FALSE;
return ret;
}
gboolean
xp_theme_get_system_font(int fontId, LOGFONT *lf)
xp_theme_get_system_font (int fontId, LOGFONT *lf)
{
if (get_theme_sys_font_func != NULL)
{

View File

@ -85,12 +85,14 @@ typedef enum
XP_THEME_ELEMENT__SIZEOF
} XpThemeElement;
void xp_theme_init(void);
void xp_theme_exit(void);
gboolean xp_theme_draw(GdkWindow *win, XpThemeElement element, GtkStyle *style,
int x, int y, int width, int height, GtkStateType state_type,
GdkRectangle *area);
gboolean xp_theme_is_drawable(XpThemeElement element);
gboolean xp_theme_get_system_font(int fontId, LOGFONT *lf);
void xp_theme_init (void);
void xp_theme_reset (void);
void xp_theme_exit (void);
gboolean xp_theme_draw (GdkWindow *win, XpThemeElement element,
GtkStyle *style, int x, int y, int width,
int height, GtkStateType state_type,
GdkRectangle *area);
gboolean xp_theme_is_drawable (XpThemeElement element);
gboolean xp_theme_get_system_font (int fontId, LOGFONT *lf);
#endif /* XP_THEME_H */