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