]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/uxtheme.h
clear m_aTypes array in Clear() as well (patch 1165866)
[wxWidgets.git] / include / wx / msw / uxtheme.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/msw/uxtheme.h
3 // Purpose: wxUxThemeEngine class: support for XP themes
4 // Author:
5 // Modified by:
6 // Created: 2003
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 wxWidgets Dev-Team
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_UXTHEME_H_
13 #define _WX_UXTHEME_H_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "uxtheme.h"
17 #endif
18
19 #include "wx/defs.h"
20
21 #include "wx/msw/wrapwin.h"
22
23 #if wxUSE_UNICODE
24 typedef struct _WXUOSVERSIONINFOEXW {
25 WXDWORD dwOSVersionInfoSize;
26 WXDWORD dwMajorVersion;
27 WXDWORD dwMinorVersion;
28 WXDWORD dwBuildNumber;
29 WXDWORD dwPlatformId;
30 wchar_t szCSDVersion[ 128 ]; // Maintenance string for PSS usage
31 unsigned short wServicePackMajor;
32 unsigned short wServicePackMinor;
33 unsigned short wSuiteMask;
34 unsigned char wProductType;
35 unsigned char wReserved;
36 } WXUOSVERSIONINFOEXW, *PWXUOSVERSIONINFOEXW, *LPWXUOSVERSIONINFOEXW;
37 #define WXUOSVERSIONINFOEX WXUOSVERSIONINFOEXW
38 #define PWXUOSVERSIONINFOEX PWXUOSVERSIONINFOEXW
39 #define LPWXUOSVERSIONINFOEX LPWXUOSVERSIONINFOEXW
40 #else
41 typedef struct _WXUOSVERSIONINFOEXA {
42 WXDWORD dwOSVersionInfoSize;
43 WXDWORD dwMajorVersion;
44 WXDWORD dwMinorVersion;
45 WXDWORD dwBuildNumber;
46 WXDWORD dwPlatformId;
47 char szCSDVersion [128]; // Maintenance string for PSS usage
48 unsigned short wServicePackMajor;
49 unsigned short wServicePackMinor;
50 unsigned short wSuiteMask;
51 unsigned char wProductType;
52 unsigned char wReserved;
53 } WXUOSVERSIONINFOEXA, *PWXUOSVERSIONINFOEXA, *LPWXUOSVERSIONINFOEXA;
54 #define WXUOSVERSIONINFOEX WXUOSVERSIONINFOEXA
55 #define PWXUOSVERSIONINFOEX PWXUOSVERSIONINFOEXA
56 #define LPWXUOSVERSIONINFOEX LPWXUOSVERSIONINFOEXA
57 #endif
58
59 typedef void* WXHTHEME;
60 typedef long WXUHRESULT;
61 typedef WXHTHEME (__stdcall *PFNWXUOPENTHEMEDATA)(WXHWND, const wchar_t *);
62 typedef WXUHRESULT (__stdcall *PFNWXUCLOSETHEMEDATA)(WXHTHEME);
63 typedef WXUHRESULT (__stdcall *PFNWXUDRAWTHEMEBACKGROUND)(WXHTHEME, WXHDC,
64 int, int, const RECT *, const RECT *);
65 #define WXU_DTT_GRAYED 0x1
66 typedef WXUHRESULT (__stdcall *PFNWXUDRAWTHEMETEXT)(WXHTHEME, WXHDC, int,
67 int, const wchar_t *, int, DWORD,
68 DWORD, const RECT *);
69 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDCONTENTRECT)(WXHTHEME, WXHDC,
70 int, int, const RECT *, RECT *);
71 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDEXTENT)(WXHTHEME, WXHDC, int, int,
72 const RECT *, RECT *);
73
74 enum WXUTHEMESIZE
75 {
76 WXU_TS_MIN, // minimum size
77 WXU_TS_TRUE, // size without stretching
78 WXU_TS_DRAW // size that theme mgr will use to draw part
79 };
80
81 typedef struct tagWXUSIZE
82 {
83 long cx;
84 long cy;
85 } WXUSIZE;
86
87 typedef struct tagWXUTEXTMETRIC
88 {
89 long tmHeight;
90 long tmAscent;
91 long tmDescent;
92 long tmInternalLeading;
93 long tmExternalLeading;
94 long tmAveCharWidth;
95 long tmMaxCharWidth;
96 long tmWeight;
97 long tmOverhang;
98 long tmDigitizedAspectX;
99 long tmDigitizedAspectY;
100 wchar_t tmFirstChar;
101 wchar_t tmLastChar;
102 wchar_t tmDefaultChar;
103 wchar_t tmBreakChar;
104 unsigned char tmItalic;
105 unsigned char tmUnderlined;
106 unsigned char tmStruckOut;
107 unsigned char tmPitchAndFamily;
108 unsigned char tmCharSet;
109 } WXUTEXTMETRIC;
110
111 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEPARTSIZE)(WXHTHEME, WXHDC, int, int, const RECT *,
112 enum WXUTHEMESIZE, WXUSIZE *);
113 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMETEXTEXTENT)(WXHTHEME, WXHDC, int, int, const wchar_t *,
114 int, WXDWORD, const RECT *, RECT *);
115 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMETEXTMETRICS)(WXHTHEME, WXHDC,
116 int, int, WXUTEXTMETRIC*);
117 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDREGION)(WXHTHEME, WXHDC,
118 int, int, const RECT *, WXHRGN *);
119
120 #define WXU_HTTB_BACKGROUNDSEG 0x0000
121 #define WXU_HTTB_FIXEDBORDER 0x0002
122 #define WXU_HTTB_CAPTION 0x0004
123 #define WXU_HTTB_RESIZINGBORDER_LEFT 0x0010
124 #define WXU_HTTB_RESIZINGBORDER_TOP 0x0020
125 #define WXU_HTTB_RESIZINGBORDER_RIGHT 0x0040
126 #define WXU_HTTB_RESIZINGBORDER_BOTTOM 0x0080
127 #define WXU_HTTB_RESIZINGBORDER 0x00F0
128 #define WXU_HTTB_SIZINGTEMPLATE 0x0100
129 #define WXU_HTTB_SYSTEMSIZINGMARGINS 0x0200
130
131 typedef struct tagWXUPOINT
132 {
133 long x;
134 long y;
135 } WXUPOINT;
136
137 typedef WXUHRESULT (__stdcall *PFNWXUHITTESTTHEMEBACKGROUND)(WXHTHEME, WXHDC, int,
138 int, WXDWORD, const RECT *, WXHRGN,
139 WXUPOINT, unsigned short *);
140 typedef WXUHRESULT (__stdcall *PFNWXUDRAWTHEMEEDGE)(WXHTHEME, WXHDC, int, int,
141 const RECT *, unsigned int, unsigned int, RECT *);
142 typedef WXUHRESULT (__stdcall *PFNWXUDRAWTHEMEICON)(WXHTHEME, WXHDC, int, int,
143 const RECT *, WXHIMAGELIST, int);
144 typedef BOOL (__stdcall *PFNWXUISTHEMEPARTDEFINED)(WXHTHEME, int, int);
145 typedef BOOL (__stdcall *PFNWXUISTHEMEBACKGROUNDPARTIALLYTRANSPARENT)(WXHTHEME, int, int);
146 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMECOLOR)(WXHTHEME, int, int, int, WXCOLORREF*);
147 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEMETRIC)(WXHTHEME, WXHDC, int,
148 int, int, int *);
149 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMESTRING)(WXHTHEME, int,
150 int, int, wchar_t *, int);
151 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEBOOL)(WXHTHEME, int, int, int, BOOL *);
152 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEINT)(WXHTHEME, int, int, int, int *);
153 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEENUMVALUE)(WXHTHEME, int, int, int, int *);
154 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEPOSITION)(WXHTHEME, int, int, int, WXUPOINT *);
155 typedef struct tagWXULOGFONT
156 {
157 long lfHeight;
158 long lfWidth;
159 long lfEscapement;
160 long lfOrientation;
161 long lfWeight;
162 unsigned char lfItalic;
163 unsigned char lfUnderline;
164 unsigned char lfStrikeOut;
165 unsigned char lfCharSet;
166 unsigned char lfOutPrecision;
167 unsigned char lfClipPrecision;
168 unsigned char lfQuality;
169 unsigned char lfPitchAndFamily;
170 wchar_t lfFaceName[32];
171 } WXULOGFONT;
172 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEFONT)(WXHTHEME, WXHDC, int, int, int, WXULOGFONT *);
173 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMERECT)(WXHTHEME, int, int, int, RECT *);
174 typedef struct _WXUMARGINS
175 {
176 int cxLeftWidth; // width of left border that retains its size
177 int cxRightWidth; // width of right border that retains its size
178 int cyTopHeight; // height of top border that retains its size
179 int cyBottomHeight; // height of bottom border that retains its size
180 } WXUMARGINS, *PWXUMARGINS;
181 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEMARGINS)(WXHTHEME, WXHDC, int,
182 int, int, RECT *, WXUMARGINS *);
183
184 #define WXU_MAX_INTLIST_COUNT 10
185 typedef struct _WXUINTLIST
186 {
187 int iValueCount; // number of values in iValues
188 int iValues[WXU_MAX_INTLIST_COUNT];
189 } WXUINTLIST, *PWXUINTLIST;
190 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEINTLIST)(WXHTHEME, int,
191 int, int, WXUINTLIST*);
192
193 enum WXUPROPERTYORIGIN
194 {
195 WXU_PO_STATE, // property was found in the state section
196 WXU_PO_PART, // property was found in the part section
197 WXU_PO_CLASS, // property was found in the class section
198 WXU_PO_GLOBAL, // property was found in [globals] section
199 WXU_PO_NOTFOUND // property was not found
200 };
201
202 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEPROPERTYORIGIN)(WXHTHEME, int,
203 int, int, enum WXUPROPERTYORIGIN *);
204 typedef WXUHRESULT (__stdcall *PFNWXUSETWINDOWTHEME)(WXHWND, const wchar_t*, const wchar_t *);
205 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEFILENAME)(WXHTHEME, int, int, int, wchar_t *, int);
206 typedef WXCOLORREF (__stdcall *PFNWXUGETTHEMESYSCOLOR)(WXHTHEME, int);
207 typedef WXHBRUSH (__stdcall *PFNWXUGETTHEMESYSCOLORBRUSH)(WXHTHEME, int);
208 typedef BOOL (__stdcall *PFNWXUGETTHEMESYSBOOL)(WXHTHEME, int);
209 typedef int (__stdcall *PFNWXUGETTHEMESYSSIZE)(WXHTHEME, int);
210 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMESYSFONT)(WXHTHEME, int, WXULOGFONT *);
211 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMESYSSTRING)(WXHTHEME, int, wchar_t *, int);
212 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMESYSINT)(WXHTHEME, int, int *);
213 typedef BOOL (__stdcall *PFNWXUISTHEMEACTIVE)();
214 typedef BOOL (__stdcall *PFNWXUISAPPTHEMED)();
215 typedef WXHTHEME (__stdcall *PFNWXUGETWINDOWTHEME)(WXHWND);
216
217 #define WXU_ETDT_DISABLE 0x00000001
218 #define WXU_ETDT_ENABLE 0x00000002
219 #define WXU_ETDT_USETABTEXTURE 0x00000004
220 #define WXU_ETDT_ENABLETAB 0x00000006
221
222 typedef WXUHRESULT (__stdcall *PFNWXUENABLETHEMEDIALOGTEXTURE)(WXHWND, WXDWORD);
223 typedef BOOL (__stdcall *PFNWXUISTHEMEDIALOGTEXTUREENABLED)(WXHWND);
224
225 #define WXU_STAP_ALLOW_NONCLIENT 1
226 #define WXU_STAP_ALLOW_CONTROLS 2
227 #define WXU_STAP_ALLOW_WEBCONTENT 4
228
229 typedef WXDWORD (__stdcall *PFNWXUGETTHEMEAPPPROPERTIES)();
230 typedef void (__stdcall *PFNWXUSETTHEMEAPPPROPERTIES)(WXDWORD);
231 typedef WXUHRESULT (__stdcall *PFNWXUGETCURRENTTHEMENAME)(wchar_t *, int,
232 wchar_t *, int, wchar_t *, int);
233
234 #define WXU_SZ_THDOCPROP_DISPLAYNAME L"DisplayName"
235 #define WXU_SZ_THDOCPROP_CANONICALNAME L"ThemeName"
236 #define WXU_SZ_THDOCPROP_TOOLTIP L"ToolTip"
237 #define WXU_SZ_THDOCPROP_AUTHOR L"author"
238
239 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEDOCUMENTATIONPROPERTY)(const wchar_t *,
240 const wchar_t *, wchar_t *, int);
241 typedef WXUHRESULT (__stdcall *PFNWXUDRAWTHEMEPARENTBACKGROUND)(WXHWND, WXHDC, RECT *);
242 typedef WXUHRESULT (__stdcall *PFNWXUENABLETHEMING)(BOOL);
243
244 // ----------------------------------------------------------------------------
245 // wxUxThemeEngine: provides all theme functions from uxtheme.dll
246 // ----------------------------------------------------------------------------
247
248 // we always define this class, even if wxUSE_UXTHEME == 0, but we just make it
249 // empty in this case -- this allows to use it elsewhere without any #ifdefs
250 #if wxUSE_UXTHEME
251 #include "wx/dynload.h"
252
253 #define wxUX_THEME_DECLARE(type, func) type func;
254 #else
255 #define wxUX_THEME_DECLARE(type, func) type func(...) { return 0; }
256 #endif
257
258 class WXDLLEXPORT wxUxThemeEngine
259 {
260 public:
261 // get the theme engine or NULL if themes are not available
262 static wxUxThemeEngine *Get();
263
264 // get the theme enging or NULL if themes are not available or not used for
265 // this application
266 static wxUxThemeEngine *GetIfActive();
267
268 // all uxtheme.dll functions
269 wxUX_THEME_DECLARE(PFNWXUOPENTHEMEDATA, OpenThemeData)
270 wxUX_THEME_DECLARE(PFNWXUCLOSETHEMEDATA, CloseThemeData)
271 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEBACKGROUND, DrawThemeBackground)
272 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMETEXT, DrawThemeText)
273 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBACKGROUNDCONTENTRECT, GetThemeBackgroundContentRect)
274 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBACKGROUNDEXTENT, GetThemeBackgroundExtent)
275 wxUX_THEME_DECLARE(PFNWXUGETTHEMEPARTSIZE, GetThemePartSize)
276 wxUX_THEME_DECLARE(PFNWXUGETTHEMETEXTEXTENT, GetThemeTextExtent)
277 wxUX_THEME_DECLARE(PFNWXUGETTHEMETEXTMETRICS, GetThemeTextMetrics)
278 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBACKGROUNDREGION, GetThemeBackgroundRegion)
279 wxUX_THEME_DECLARE(PFNWXUHITTESTTHEMEBACKGROUND, HitTestThemeBackground)
280 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEEDGE, DrawThemeEdge)
281 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEICON, DrawThemeIcon)
282 wxUX_THEME_DECLARE(PFNWXUISTHEMEPARTDEFINED, IsThemePartDefined)
283 wxUX_THEME_DECLARE(PFNWXUISTHEMEBACKGROUNDPARTIALLYTRANSPARENT, IsThemeBackgroundPartiallyTransparent)
284 wxUX_THEME_DECLARE(PFNWXUGETTHEMECOLOR, GetThemeColor)
285 wxUX_THEME_DECLARE(PFNWXUGETTHEMEMETRIC, GetThemeMetric)
286 wxUX_THEME_DECLARE(PFNWXUGETTHEMESTRING, GetThemeString)
287 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBOOL, GetThemeBool)
288 wxUX_THEME_DECLARE(PFNWXUGETTHEMEINT, GetThemeInt)
289 wxUX_THEME_DECLARE(PFNWXUGETTHEMEENUMVALUE, GetThemeEnumValue)
290 wxUX_THEME_DECLARE(PFNWXUGETTHEMEPOSITION, GetThemePosition)
291 wxUX_THEME_DECLARE(PFNWXUGETTHEMEFONT, GetThemeFont)
292 wxUX_THEME_DECLARE(PFNWXUGETTHEMERECT, GetThemeRect)
293 wxUX_THEME_DECLARE(PFNWXUGETTHEMEMARGINS, GetThemeMargins)
294 wxUX_THEME_DECLARE(PFNWXUGETTHEMEINTLIST, GetThemeIntList)
295 wxUX_THEME_DECLARE(PFNWXUGETTHEMEPROPERTYORIGIN, GetThemePropertyOrigin)
296 wxUX_THEME_DECLARE(PFNWXUSETWINDOWTHEME, SetWindowTheme)
297 wxUX_THEME_DECLARE(PFNWXUGETTHEMEFILENAME, GetThemeFilename)
298 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSCOLOR, GetThemeSysColor)
299 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSCOLORBRUSH, GetThemeSysColorBrush)
300 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSBOOL, GetThemeSysBool)
301 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSSIZE, GetThemeSysSize)
302 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSFONT, GetThemeSysFont)
303 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSSTRING, GetThemeSysString)
304 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSINT, GetThemeSysInt)
305 wxUX_THEME_DECLARE(PFNWXUISTHEMEACTIVE, IsThemeActive)
306 wxUX_THEME_DECLARE(PFNWXUISAPPTHEMED, IsAppThemed)
307 wxUX_THEME_DECLARE(PFNWXUGETWINDOWTHEME, GetWindowTheme)
308 wxUX_THEME_DECLARE(PFNWXUENABLETHEMEDIALOGTEXTURE, EnableThemeDialogTexture)
309 wxUX_THEME_DECLARE(PFNWXUISTHEMEDIALOGTEXTUREENABLED, IsThemeDialogTextureEnabled)
310 wxUX_THEME_DECLARE(PFNWXUGETTHEMEAPPPROPERTIES, GetThemeAppProperties)
311 wxUX_THEME_DECLARE(PFNWXUSETTHEMEAPPPROPERTIES, SetThemeAppProperties)
312 wxUX_THEME_DECLARE(PFNWXUGETCURRENTTHEMENAME, GetCurrentThemeName)
313 wxUX_THEME_DECLARE(PFNWXUGETTHEMEDOCUMENTATIONPROPERTY, GetThemeDocumentationProperty)
314 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEPARENTBACKGROUND, DrawThemeParentBackground)
315 wxUX_THEME_DECLARE(PFNWXUENABLETHEMING, EnableTheming)
316
317 private:
318 // construcor is private as only Get() can create us and is also trivial as
319 // everything really happens in Initialize()
320 wxUxThemeEngine() { }
321
322 // destructor is private as only Get() and wxUxThemeModule delete us, it is
323 // not virtual as we're not supposed to be derived from
324 ~wxUxThemeEngine() { }
325
326 #if wxUSE_UXTHEME
327 // initialize the theme engine: load the DLL, resolve the functions
328 //
329 // return true if we can be used, false if themes are not available
330 bool Initialize();
331
332
333 // uxtheme.dll
334 wxDynamicLibrary m_dllUxTheme;
335
336
337 // the one and only theme engine, initially NULL
338 static wxUxThemeEngine *ms_themeEngine;
339
340 // this is a bool which initially has the value -1 meaning "unknown"
341 static int ms_isThemeEngineAvailable;
342
343 // it must be able to delete us
344 friend class wxUxThemeModule;
345 #endif // wxUSE_UXTHEME
346
347 DECLARE_NO_COPY_CLASS(wxUxThemeEngine)
348 };
349
350 #if wxUSE_UXTHEME
351
352 /* static */ inline wxUxThemeEngine *wxUxThemeEngine::GetIfActive()
353 {
354 wxUxThemeEngine *engine = Get();
355 return engine && engine->IsAppThemed() && engine->IsThemeActive()
356 ? engine
357 : NULL;
358 }
359
360 #else // !wxUSE_UXTHEME
361
362 /* static */ inline wxUxThemeEngine *wxUxThemeEngine::Get()
363 {
364 return NULL;
365 }
366
367 /* static */ inline wxUxThemeEngine *wxUxThemeEngine::GetIfActive()
368 {
369 return NULL;
370 }
371
372 #endif // wxUSE_UXTHEME/!wxUSE_UXTHEME
373
374 // ----------------------------------------------------------------------------
375 // wxUxThemeHandle: encapsulates ::Open/CloseThemeData()
376 // ----------------------------------------------------------------------------
377
378 class wxUxThemeHandle
379 {
380 public:
381 wxUxThemeHandle(wxWindow *win, const wchar_t *classes)
382 {
383 wxUxThemeEngine *engine = wxUxThemeEngine::Get();
384
385 m_hTheme =
386 engine ? (WXHTHEME)engine->OpenThemeData(win->GetHWND(), classes)
387 : NULL;
388 }
389
390 operator WXHTHEME() const { return m_hTheme; }
391
392 ~wxUxThemeHandle()
393 {
394 if ( m_hTheme )
395 {
396 wxUxThemeEngine::Get()->CloseThemeData(m_hTheme);
397 }
398 }
399
400 private:
401 WXHTHEME m_hTheme;
402
403 DECLARE_NO_COPY_CLASS(wxUxThemeHandle)
404 };
405
406 #endif // _WX_UXTHEME_H_
407