1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/uxtheme.h
3 // Purpose: wxUxThemeEngine class: support for XP themes
4 // Author: John Platts, Vadim Zeitlin
8 // Copyright: (c) 2003 John Platts, Vadim Zeitlin
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_UXTHEME_H_
13 #define _WX_UXTHEME_H_
17 #include "wx/msw/private.h" // we use GetHwndOf()
18 #include "wx/msw/uxthemep.h"
20 // Amazingly, GetThemeFont() and GetThemeSysFont() functions use LOGFONTA under
21 // XP but LOGFONTW (even in non-Unicode build) under later versions of Windows.
22 // If we declare them as taking LOGFONT below, the code would be able to
23 // silently pass LOGFONTA to them in ANSI build and would crash at run-time
24 // under Windows Vista/7 because of a buffer overrun (LOGFONTA being smaller
25 // than LOGFONTW expected by these functions). If we we declare them as taking
26 // LOGFONTW, the code wouldn't work correctly under XP. So we use a special
27 // wxUxThemeFont class to encapsulate this and intentionally change the LOGFONT
28 // output parameters of the theme functions to take it instead.
33 // Trivial default ctor.
36 // Just some unique type.
40 // In Unicode build we always use LOGFONT anyhow so this class is
41 // completely trivial.
42 Ptr
*GetPtr() { return reinterpret_cast<Ptr
*>(&m_lfW
); }
43 const LOGFONTW
& GetLOGFONT() { return m_lfW
; }
44 #else // !wxUSE_UNICODE
45 // Return either LOGFONTA or LOGFONTW pointer as required by the current
49 return UseLOGFONTW() ? reinterpret_cast<Ptr
*>(&m_lfW
)
50 : reinterpret_cast<Ptr
*>(&m_lfA
);
53 // This method returns LOGFONT (i.e. LOGFONTA in ANSI build and LOGFONTW in
54 // Unicode one) which can be used with other, normal, Windows or wx
55 // functions. Internally it may need to transform LOGFONTW to LOGFONTA.
56 const LOGFONTA
& GetLOGFONT()
60 // Most of the fields are the same in LOGFONTA and LOGFONTW so just
61 // copy everything by default.
62 memcpy(&m_lfA
, &m_lfW
, sizeof(m_lfA
));
64 // But the face name must be converted from Unicode.
65 WideCharToMultiByte(CP_ACP
, 0, m_lfW
.lfFaceName
, -1,
66 m_lfA
.lfFaceName
, sizeof(m_lfA
.lfFaceName
),
74 static bool UseLOGFONTW()
76 return wxGetWinVersion() >= wxWinVersion_Vista
;
80 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
85 wxDECLARE_NO_COPY_CLASS(wxUxThemeFont
);
88 typedef HTHEME (__stdcall
*PFNWXUOPENTHEMEDATA
)(HWND
, const wchar_t *);
89 typedef HRESULT (__stdcall
*PFNWXUCLOSETHEMEDATA
)(HTHEME
);
90 typedef HRESULT (__stdcall
*PFNWXUDRAWTHEMEBACKGROUND
)(HTHEME
, HDC
, int, int, const RECT
*, const RECT
*);
91 typedef HRESULT (__stdcall
*PFNWXUDRAWTHEMETEXT
)(HTHEME
, HDC
, int, int, const wchar_t *, int, DWORD
, DWORD
, const RECT
*);
92 typedef HRESULT (__stdcall
*PFNWXUGETTHEMEBACKGROUNDCONTENTRECT
)(HTHEME
, HDC
, int, int, const RECT
*, RECT
*);
93 typedef HRESULT (__stdcall
*PFNWXUGETTHEMEBACKGROUNDEXTENT
)(HTHEME
, HDC
, int, int, const RECT
*, RECT
*);
94 typedef HRESULT (__stdcall
*PFNWXUGETTHEMEPARTSIZE
)(HTHEME
, HDC
, int, int, const RECT
*, /* enum */ THEMESIZE
, SIZE
*);
95 typedef HRESULT (__stdcall
*PFNWXUGETTHEMETEXTEXTENT
)(HTHEME
, HDC
, int, int, const wchar_t *, int, DWORD
, const RECT
*, RECT
*);
96 typedef HRESULT (__stdcall
*PFNWXUGETTHEMETEXTMETRICS
)(HTHEME
, HDC
, int, int, TEXTMETRIC
*);
97 typedef HRESULT (__stdcall
*PFNWXUGETTHEMEBACKGROUNDREGION
)(HTHEME
, HDC
, int, int, const RECT
*, HRGN
*);
98 typedef HRESULT (__stdcall
*PFNWXUHITTESTTHEMEBACKGROUND
)(HTHEME
, HDC
, int, int, DWORD
, const RECT
*, HRGN
, POINT
, unsigned short *);
99 typedef HRESULT (__stdcall
*PFNWXUDRAWTHEMEEDGE
)(HTHEME
, HDC
, int, int, const RECT
*, unsigned int, unsigned int, RECT
*);
100 typedef HRESULT (__stdcall
*PFNWXUDRAWTHEMEICON
)(HTHEME
, HDC
, int, int, const RECT
*, HIMAGELIST
, int);
101 typedef BOOL (__stdcall
*PFNWXUISTHEMEPARTDEFINED
)(HTHEME
, int, int);
102 typedef BOOL (__stdcall
*PFNWXUISTHEMEBACKGROUNDPARTIALLYTRANSPARENT
)(HTHEME
, int, int);
103 typedef HRESULT (__stdcall
*PFNWXUGETTHEMECOLOR
)(HTHEME
, int, int, int, COLORREF
*);
104 typedef HRESULT (__stdcall
*PFNWXUGETTHEMEMETRIC
)(HTHEME
, HDC
, int, int, int, int *);
105 typedef HRESULT (__stdcall
*PFNWXUGETTHEMESTRING
)(HTHEME
, int, int, int, wchar_t *, int);
106 typedef HRESULT (__stdcall
*PFNWXUGETTHEMEBOOL
)(HTHEME
, int, int, int, BOOL
*);
107 typedef HRESULT (__stdcall
*PFNWXUGETTHEMEINT
)(HTHEME
, int, int, int, int *);
108 typedef HRESULT (__stdcall
*PFNWXUGETTHEMEENUMVALUE
)(HTHEME
, int, int, int, int *);
109 typedef HRESULT (__stdcall
*PFNWXUGETTHEMEPOSITION
)(HTHEME
, int, int, int, POINT
*);
110 typedef HRESULT (__stdcall
*PFNWXUGETTHEMEFONT
)(HTHEME
, HDC
, int, int, int, wxUxThemeFont::Ptr
*);
111 typedef HRESULT (__stdcall
*PFNWXUGETTHEMERECT
)(HTHEME
, int, int, int, RECT
*);
112 typedef HRESULT (__stdcall
*PFNWXUGETTHEMEMARGINS
)(HTHEME
, HDC
, int, int, int, RECT
*, MARGINS
*);
113 typedef HRESULT (__stdcall
*PFNWXUGETTHEMEINTLIST
)(HTHEME
, int, int, int, INTLIST
*);
114 typedef HRESULT (__stdcall
*PFNWXUGETTHEMEPROPERTYORIGIN
)(HTHEME
, int, int, int, /* enum */ PROPERTYORIGIN
*);
115 typedef HRESULT (__stdcall
*PFNWXUSETWINDOWTHEME
)(HWND
, const wchar_t*, const wchar_t *);
116 typedef HRESULT (__stdcall
*PFNWXUGETTHEMEFILENAME
)(HTHEME
, int, int, int, wchar_t *, int);
117 typedef COLORREF(__stdcall
*PFNWXUGETTHEMESYSCOLOR
)(HTHEME
, int);
118 typedef HBRUSH (__stdcall
*PFNWXUGETTHEMESYSCOLORBRUSH
)(HTHEME
, int);
119 typedef BOOL (__stdcall
*PFNWXUGETTHEMESYSBOOL
)(HTHEME
, int);
120 typedef int (__stdcall
*PFNWXUGETTHEMESYSSIZE
)(HTHEME
, int);
121 typedef HRESULT (__stdcall
*PFNWXUGETTHEMESYSFONT
)(HTHEME
, int, wxUxThemeFont::Ptr
*);
122 typedef HRESULT (__stdcall
*PFNWXUGETTHEMESYSSTRING
)(HTHEME
, int, wchar_t *, int);
123 typedef HRESULT (__stdcall
*PFNWXUGETTHEMESYSINT
)(HTHEME
, int, int *);
124 typedef BOOL (__stdcall
*PFNWXUISTHEMEACTIVE
)();
125 typedef BOOL (__stdcall
*PFNWXUISAPPTHEMED
)();
126 typedef HTHEME (__stdcall
*PFNWXUGETWINDOWTHEME
)(HWND
);
127 typedef HRESULT (__stdcall
*PFNWXUENABLETHEMEDIALOGTEXTURE
)(HWND
, DWORD
);
128 typedef BOOL (__stdcall
*PFNWXUISTHEMEDIALOGTEXTUREENABLED
)(HWND
);
129 typedef DWORD (__stdcall
*PFNWXUGETTHEMEAPPPROPERTIES
)();
130 typedef void (__stdcall
*PFNWXUSETTHEMEAPPPROPERTIES
)(DWORD
);
131 typedef HRESULT (__stdcall
*PFNWXUGETCURRENTTHEMENAME
)(wchar_t *, int, wchar_t *, int, wchar_t *, int);
132 typedef HRESULT (__stdcall
*PFNWXUGETTHEMEDOCUMENTATIONPROPERTY
)(const wchar_t *, const wchar_t *, wchar_t *, int);
133 typedef HRESULT (__stdcall
*PFNWXUDRAWTHEMEPARENTBACKGROUND
)(HWND
, HDC
, RECT
*);
134 typedef HRESULT (__stdcall
*PFNWXUENABLETHEMING
)(BOOL
);
136 // ----------------------------------------------------------------------------
137 // wxUxThemeEngine: provides all theme functions from uxtheme.dll
138 // ----------------------------------------------------------------------------
140 // we always define this class, even if wxUSE_UXTHEME == 0, but we just make it
141 // empty in this case -- this allows to use it elsewhere without any #ifdefs
143 #include "wx/dynlib.h"
145 #define wxUX_THEME_DECLARE(type, func) type func;
147 #define wxUX_THEME_DECLARE(type, func) type func(...) { return 0; }
150 class WXDLLIMPEXP_CORE wxUxThemeEngine
153 // get the theme engine or NULL if themes are not available
154 static wxUxThemeEngine
*Get();
156 // get the theme enging or NULL if themes are not available or not used for
158 static wxUxThemeEngine
*GetIfActive();
160 // all uxtheme.dll functions
161 wxUX_THEME_DECLARE(PFNWXUOPENTHEMEDATA
, OpenThemeData
)
162 wxUX_THEME_DECLARE(PFNWXUCLOSETHEMEDATA
, CloseThemeData
)
163 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEBACKGROUND
, DrawThemeBackground
)
164 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMETEXT
, DrawThemeText
)
165 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBACKGROUNDCONTENTRECT
, GetThemeBackgroundContentRect
)
166 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBACKGROUNDEXTENT
, GetThemeBackgroundExtent
)
167 wxUX_THEME_DECLARE(PFNWXUGETTHEMEPARTSIZE
, GetThemePartSize
)
168 wxUX_THEME_DECLARE(PFNWXUGETTHEMETEXTEXTENT
, GetThemeTextExtent
)
169 wxUX_THEME_DECLARE(PFNWXUGETTHEMETEXTMETRICS
, GetThemeTextMetrics
)
170 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBACKGROUNDREGION
, GetThemeBackgroundRegion
)
171 wxUX_THEME_DECLARE(PFNWXUHITTESTTHEMEBACKGROUND
, HitTestThemeBackground
)
172 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEEDGE
, DrawThemeEdge
)
173 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEICON
, DrawThemeIcon
)
174 wxUX_THEME_DECLARE(PFNWXUISTHEMEPARTDEFINED
, IsThemePartDefined
)
175 wxUX_THEME_DECLARE(PFNWXUISTHEMEBACKGROUNDPARTIALLYTRANSPARENT
, IsThemeBackgroundPartiallyTransparent
)
176 wxUX_THEME_DECLARE(PFNWXUGETTHEMECOLOR
, GetThemeColor
)
177 wxUX_THEME_DECLARE(PFNWXUGETTHEMEMETRIC
, GetThemeMetric
)
178 wxUX_THEME_DECLARE(PFNWXUGETTHEMESTRING
, GetThemeString
)
179 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBOOL
, GetThemeBool
)
180 wxUX_THEME_DECLARE(PFNWXUGETTHEMEINT
, GetThemeInt
)
181 wxUX_THEME_DECLARE(PFNWXUGETTHEMEENUMVALUE
, GetThemeEnumValue
)
182 wxUX_THEME_DECLARE(PFNWXUGETTHEMEPOSITION
, GetThemePosition
)
183 wxUX_THEME_DECLARE(PFNWXUGETTHEMEFONT
, GetThemeFont
)
184 wxUX_THEME_DECLARE(PFNWXUGETTHEMERECT
, GetThemeRect
)
185 wxUX_THEME_DECLARE(PFNWXUGETTHEMEMARGINS
, GetThemeMargins
)
186 wxUX_THEME_DECLARE(PFNWXUGETTHEMEINTLIST
, GetThemeIntList
)
187 wxUX_THEME_DECLARE(PFNWXUGETTHEMEPROPERTYORIGIN
, GetThemePropertyOrigin
)
188 wxUX_THEME_DECLARE(PFNWXUSETWINDOWTHEME
, SetWindowTheme
)
189 wxUX_THEME_DECLARE(PFNWXUGETTHEMEFILENAME
, GetThemeFilename
)
190 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSCOLOR
, GetThemeSysColor
)
191 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSCOLORBRUSH
, GetThemeSysColorBrush
)
192 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSBOOL
, GetThemeSysBool
)
193 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSSIZE
, GetThemeSysSize
)
194 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSFONT
, GetThemeSysFont
)
195 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSSTRING
, GetThemeSysString
)
196 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSINT
, GetThemeSysInt
)
197 wxUX_THEME_DECLARE(PFNWXUISTHEMEACTIVE
, IsThemeActive
)
198 wxUX_THEME_DECLARE(PFNWXUISAPPTHEMED
, IsAppThemed
)
199 wxUX_THEME_DECLARE(PFNWXUGETWINDOWTHEME
, GetWindowTheme
)
200 wxUX_THEME_DECLARE(PFNWXUENABLETHEMEDIALOGTEXTURE
, EnableThemeDialogTexture
)
201 wxUX_THEME_DECLARE(PFNWXUISTHEMEDIALOGTEXTUREENABLED
, IsThemeDialogTextureEnabled
)
202 wxUX_THEME_DECLARE(PFNWXUGETTHEMEAPPPROPERTIES
, GetThemeAppProperties
)
203 wxUX_THEME_DECLARE(PFNWXUSETTHEMEAPPPROPERTIES
, SetThemeAppProperties
)
204 wxUX_THEME_DECLARE(PFNWXUGETCURRENTTHEMENAME
, GetCurrentThemeName
)
205 wxUX_THEME_DECLARE(PFNWXUGETTHEMEDOCUMENTATIONPROPERTY
, GetThemeDocumentationProperty
)
206 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEPARENTBACKGROUND
, DrawThemeParentBackground
)
207 wxUX_THEME_DECLARE(PFNWXUENABLETHEMING
, EnableTheming
)
210 // construcor is private as only Get() can create us and is also trivial as
211 // everything really happens in Initialize()
212 wxUxThemeEngine() { }
214 // destructor is private as only Get() and wxUxThemeModule delete us, it is
215 // not virtual as we're not supposed to be derived from
216 ~wxUxThemeEngine() { }
219 // initialize the theme engine: load the DLL, resolve the functions
221 // return true if we can be used, false if themes are not available
226 wxDynamicLibrary m_dllUxTheme
;
229 // the one and only theme engine, initially NULL
230 static wxUxThemeEngine
*ms_themeEngine
;
232 // this is a bool which initially has the value -1 meaning "unknown"
233 static int ms_isThemeEngineAvailable
;
235 // it must be able to delete us
236 friend class wxUxThemeModule
;
237 #endif // wxUSE_UXTHEME
239 wxDECLARE_NO_COPY_CLASS(wxUxThemeEngine
);
244 /* static */ inline wxUxThemeEngine
*wxUxThemeEngine::GetIfActive()
246 wxUxThemeEngine
*engine
= Get();
247 return engine
&& engine
->IsAppThemed() && engine
->IsThemeActive()
252 #else // !wxUSE_UXTHEME
254 /* static */ inline wxUxThemeEngine
*wxUxThemeEngine::Get()
259 /* static */ inline wxUxThemeEngine
*wxUxThemeEngine::GetIfActive()
264 #endif // wxUSE_UXTHEME/!wxUSE_UXTHEME
266 // ----------------------------------------------------------------------------
267 // wxUxThemeHandle: encapsulates ::Open/CloseThemeData()
268 // ----------------------------------------------------------------------------
270 class wxUxThemeHandle
273 wxUxThemeHandle(const wxWindow
*win
, const wchar_t *classes
)
275 wxUxThemeEngine
*engine
= wxUxThemeEngine::Get();
277 m_hTheme
= engine
? (HTHEME
)engine
->OpenThemeData(GetHwndOf(win
), classes
)
281 operator HTHEME() const { return m_hTheme
; }
287 wxUxThemeEngine::Get()->CloseThemeData(m_hTheme
);
294 wxDECLARE_NO_COPY_CLASS(wxUxThemeHandle
);
297 #endif // _WX_UXTHEME_H_