]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/uxtheme.h
corrected minor typos
[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: John Platts, Vadim Zeitlin
5 // Modified by:
6 // Created: 2003
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 John Platts, Vadim Zeitlin
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 typedef void* WXHTHEME;
24 typedef long WXUHRESULT;
25 typedef WXHTHEME (__stdcall *PFNWXUOPENTHEMEDATA)(WXHWND, const wchar_t *);
26 typedef WXUHRESULT (__stdcall *PFNWXUCLOSETHEMEDATA)(WXHTHEME);
27 typedef WXUHRESULT (__stdcall *PFNWXUDRAWTHEMEBACKGROUND)(WXHTHEME, WXHDC,
28 int, int, const RECT *, const RECT *);
29 #define WXU_DTT_GRAYED 0x1
30 typedef WXUHRESULT (__stdcall *PFNWXUDRAWTHEMETEXT)(WXHTHEME, WXHDC, int,
31 int, const wchar_t *, int, DWORD,
32 DWORD, const RECT *);
33 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDCONTENTRECT)(WXHTHEME, WXHDC,
34 int, int, const RECT *, RECT *);
35 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDEXTENT)(WXHTHEME, WXHDC, int, int,
36 const RECT *, RECT *);
37
38 enum WXUTHEMESIZE
39 {
40 WXU_TS_MIN,
41 WXU_TS_TRUE,
42 WXU_TS_DRAW
43 };
44
45 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEPARTSIZE)(WXHTHEME, WXHDC, int, int, const RECT *,
46 enum WXUTHEMESIZE, SIZE *);
47 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMETEXTEXTENT)(WXHTHEME, WXHDC, int, int, const wchar_t *,
48 int, WXDWORD, const RECT *, RECT *);
49 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMETEXTMETRICS)(WXHTHEME, WXHDC,
50 int, int, TEXTMETRIC*);
51 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDREGION)(WXHTHEME, WXHDC,
52 int, int, const RECT *, WXHRGN *);
53
54 #define WXU_HTTB_BACKGROUNDSEG 0x0000
55 #define WXU_HTTB_FIXEDBORDER 0x0002
56 #define WXU_HTTB_CAPTION 0x0004
57 #define WXU_HTTB_RESIZINGBORDER_LEFT 0x0010
58 #define WXU_HTTB_RESIZINGBORDER_TOP 0x0020
59 #define WXU_HTTB_RESIZINGBORDER_RIGHT 0x0040
60 #define WXU_HTTB_RESIZINGBORDER_BOTTOM 0x0080
61 #define WXU_HTTB_RESIZINGBORDER 0x00F0
62 #define WXU_HTTB_SIZINGTEMPLATE 0x0100
63 #define WXU_HTTB_SYSTEMSIZINGMARGINS 0x0200
64
65 typedef WXUHRESULT (__stdcall *PFNWXUHITTESTTHEMEBACKGROUND)(WXHTHEME, WXHDC, int,
66 int, WXDWORD, const RECT *, WXHRGN,
67 POINT, unsigned short *);
68 typedef WXUHRESULT (__stdcall *PFNWXUDRAWTHEMEEDGE)(WXHTHEME, WXHDC, int, int,
69 const RECT *, unsigned int, unsigned int, RECT *);
70 typedef WXUHRESULT (__stdcall *PFNWXUDRAWTHEMEICON)(WXHTHEME, WXHDC, int, int,
71 const RECT *, WXHIMAGELIST, int);
72 typedef BOOL (__stdcall *PFNWXUISTHEMEPARTDEFINED)(WXHTHEME, int, int);
73 typedef BOOL (__stdcall *PFNWXUISTHEMEBACKGROUNDPARTIALLYTRANSPARENT)(WXHTHEME, int, int);
74 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMECOLOR)(WXHTHEME, int, int, int, WXCOLORREF*);
75 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEMETRIC)(WXHTHEME, WXHDC, int,
76 int, int, int *);
77 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMESTRING)(WXHTHEME, int,
78 int, int, wchar_t *, int);
79 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEBOOL)(WXHTHEME, int, int, int, BOOL *);
80 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEINT)(WXHTHEME, int, int, int, int *);
81 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEENUMVALUE)(WXHTHEME, int, int, int, int *);
82 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEPOSITION)(WXHTHEME, int, int, int, POINT *);
83 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEFONT)(WXHTHEME, WXHDC, int, int, int, LOGFONT *);
84 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMERECT)(WXHTHEME, int, int, int, RECT *);
85 typedef struct _WXUMARGINS
86 {
87 int cxLeftWidth;
88 int cxRightWidth;
89 int cyTopHeight;
90 int cyBottomHeight;
91 } WXUMARGINS, *PWXUMARGINS;
92 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEMARGINS)(WXHTHEME, WXHDC, int,
93 int, int, RECT *, WXUMARGINS *);
94
95 #define WXU_MAX_INTLIST_COUNT 10
96 typedef struct _WXUINTLIST
97 {
98 int iValueCount;
99 int iValues[WXU_MAX_INTLIST_COUNT];
100 } WXUINTLIST, *PWXUINTLIST;
101 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEINTLIST)(WXHTHEME, int,
102 int, int, WXUINTLIST*);
103
104 enum WXUPROPERTYORIGIN
105 {
106 WXU_PO_STATE,
107 WXU_PO_PART,
108 WXU_PO_CLASS,
109 WXU_PO_GLOBAL,
110 WXU_PO_NOTFOUND
111 };
112
113 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEPROPERTYORIGIN)(WXHTHEME, int,
114 int, int, enum WXUPROPERTYORIGIN *);
115 typedef WXUHRESULT (__stdcall *PFNWXUSETWINDOWTHEME)(WXHWND, const wchar_t*, const wchar_t *);
116 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEFILENAME)(WXHTHEME, int, int, int, wchar_t *, int);
117 typedef WXCOLORREF (__stdcall *PFNWXUGETTHEMESYSCOLOR)(WXHTHEME, int);
118 typedef WXHBRUSH (__stdcall *PFNWXUGETTHEMESYSCOLORBRUSH)(WXHTHEME, int);
119 typedef BOOL (__stdcall *PFNWXUGETTHEMESYSBOOL)(WXHTHEME, int);
120 typedef int (__stdcall *PFNWXUGETTHEMESYSSIZE)(WXHTHEME, int);
121 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMESYSFONT)(WXHTHEME, int, LOGFONT *);
122 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMESYSSTRING)(WXHTHEME, int, wchar_t *, int);
123 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMESYSINT)(WXHTHEME, int, int *);
124 typedef BOOL (__stdcall *PFNWXUISTHEMEACTIVE)();
125 typedef BOOL (__stdcall *PFNWXUISAPPTHEMED)();
126 typedef WXHTHEME (__stdcall *PFNWXUGETWINDOWTHEME)(WXHWND);
127
128 #define WXU_ETDT_DISABLE 0x00000001
129 #define WXU_ETDT_ENABLE 0x00000002
130 #define WXU_ETDT_USETABTEXTURE 0x00000004
131 #define WXU_ETDT_ENABLETAB 0x00000006
132
133 typedef WXUHRESULT (__stdcall *PFNWXUENABLETHEMEDIALOGTEXTURE)(WXHWND, WXDWORD);
134 typedef BOOL (__stdcall *PFNWXUISTHEMEDIALOGTEXTUREENABLED)(WXHWND);
135
136 #define WXU_STAP_ALLOW_NONCLIENT 1
137 #define WXU_STAP_ALLOW_CONTROLS 2
138 #define WXU_STAP_ALLOW_WEBCONTENT 4
139
140 typedef WXDWORD (__stdcall *PFNWXUGETTHEMEAPPPROPERTIES)();
141 typedef void (__stdcall *PFNWXUSETTHEMEAPPPROPERTIES)(WXDWORD);
142 typedef WXUHRESULT (__stdcall *PFNWXUGETCURRENTTHEMENAME)(wchar_t *, int,
143 wchar_t *, int, wchar_t *, int);
144
145 #define WXU_SZ_THDOCPROP_DISPLAYNAME L"DisplayName"
146 #define WXU_SZ_THDOCPROP_CANONICALNAME L"ThemeName"
147 #define WXU_SZ_THDOCPROP_TOOLTIP L"ToolTip"
148 #define WXU_SZ_THDOCPROP_AUTHOR L"author"
149
150 typedef WXUHRESULT (__stdcall *PFNWXUGETTHEMEDOCUMENTATIONPROPERTY)(const wchar_t *,
151 const wchar_t *, wchar_t *, int);
152 typedef WXUHRESULT (__stdcall *PFNWXUDRAWTHEMEPARENTBACKGROUND)(WXHWND, WXHDC, RECT *);
153 typedef WXUHRESULT (__stdcall *PFNWXUENABLETHEMING)(BOOL);
154
155 // ----------------------------------------------------------------------------
156 // wxUxThemeEngine: provides all theme functions from uxtheme.dll
157 // ----------------------------------------------------------------------------
158
159 // we always define this class, even if wxUSE_UXTHEME == 0, but we just make it
160 // empty in this case -- this allows to use it elsewhere without any #ifdefs
161 #if wxUSE_UXTHEME
162 #include "wx/dynload.h"
163
164 #define wxUX_THEME_DECLARE(type, func) type func;
165 #else
166 #define wxUX_THEME_DECLARE(type, func) type func(...) { return 0; }
167 #endif
168
169 class WXDLLEXPORT wxUxThemeEngine
170 {
171 public:
172 // get the theme engine or NULL if themes are not available
173 static wxUxThemeEngine *Get();
174
175 // get the theme enging or NULL if themes are not available or not used for
176 // this application
177 static wxUxThemeEngine *GetIfActive();
178
179 // all uxtheme.dll functions
180 wxUX_THEME_DECLARE(PFNWXUOPENTHEMEDATA, OpenThemeData)
181 wxUX_THEME_DECLARE(PFNWXUCLOSETHEMEDATA, CloseThemeData)
182 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEBACKGROUND, DrawThemeBackground)
183 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMETEXT, DrawThemeText)
184 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBACKGROUNDCONTENTRECT, GetThemeBackgroundContentRect)
185 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBACKGROUNDEXTENT, GetThemeBackgroundExtent)
186 wxUX_THEME_DECLARE(PFNWXUGETTHEMEPARTSIZE, GetThemePartSize)
187 wxUX_THEME_DECLARE(PFNWXUGETTHEMETEXTEXTENT, GetThemeTextExtent)
188 wxUX_THEME_DECLARE(PFNWXUGETTHEMETEXTMETRICS, GetThemeTextMetrics)
189 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBACKGROUNDREGION, GetThemeBackgroundRegion)
190 wxUX_THEME_DECLARE(PFNWXUHITTESTTHEMEBACKGROUND, HitTestThemeBackground)
191 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEEDGE, DrawThemeEdge)
192 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEICON, DrawThemeIcon)
193 wxUX_THEME_DECLARE(PFNWXUISTHEMEPARTDEFINED, IsThemePartDefined)
194 wxUX_THEME_DECLARE(PFNWXUISTHEMEBACKGROUNDPARTIALLYTRANSPARENT, IsThemeBackgroundPartiallyTransparent)
195 wxUX_THEME_DECLARE(PFNWXUGETTHEMECOLOR, GetThemeColor)
196 wxUX_THEME_DECLARE(PFNWXUGETTHEMEMETRIC, GetThemeMetric)
197 wxUX_THEME_DECLARE(PFNWXUGETTHEMESTRING, GetThemeString)
198 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBOOL, GetThemeBool)
199 wxUX_THEME_DECLARE(PFNWXUGETTHEMEINT, GetThemeInt)
200 wxUX_THEME_DECLARE(PFNWXUGETTHEMEENUMVALUE, GetThemeEnumValue)
201 wxUX_THEME_DECLARE(PFNWXUGETTHEMEPOSITION, GetThemePosition)
202 wxUX_THEME_DECLARE(PFNWXUGETTHEMEFONT, GetThemeFont)
203 wxUX_THEME_DECLARE(PFNWXUGETTHEMERECT, GetThemeRect)
204 wxUX_THEME_DECLARE(PFNWXUGETTHEMEMARGINS, GetThemeMargins)
205 wxUX_THEME_DECLARE(PFNWXUGETTHEMEINTLIST, GetThemeIntList)
206 wxUX_THEME_DECLARE(PFNWXUGETTHEMEPROPERTYORIGIN, GetThemePropertyOrigin)
207 wxUX_THEME_DECLARE(PFNWXUSETWINDOWTHEME, SetWindowTheme)
208 wxUX_THEME_DECLARE(PFNWXUGETTHEMEFILENAME, GetThemeFilename)
209 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSCOLOR, GetThemeSysColor)
210 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSCOLORBRUSH, GetThemeSysColorBrush)
211 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSBOOL, GetThemeSysBool)
212 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSSIZE, GetThemeSysSize)
213 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSFONT, GetThemeSysFont)
214 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSSTRING, GetThemeSysString)
215 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSINT, GetThemeSysInt)
216 wxUX_THEME_DECLARE(PFNWXUISTHEMEACTIVE, IsThemeActive)
217 wxUX_THEME_DECLARE(PFNWXUISAPPTHEMED, IsAppThemed)
218 wxUX_THEME_DECLARE(PFNWXUGETWINDOWTHEME, GetWindowTheme)
219 wxUX_THEME_DECLARE(PFNWXUENABLETHEMEDIALOGTEXTURE, EnableThemeDialogTexture)
220 wxUX_THEME_DECLARE(PFNWXUISTHEMEDIALOGTEXTUREENABLED, IsThemeDialogTextureEnabled)
221 wxUX_THEME_DECLARE(PFNWXUGETTHEMEAPPPROPERTIES, GetThemeAppProperties)
222 wxUX_THEME_DECLARE(PFNWXUSETTHEMEAPPPROPERTIES, SetThemeAppProperties)
223 wxUX_THEME_DECLARE(PFNWXUGETCURRENTTHEMENAME, GetCurrentThemeName)
224 wxUX_THEME_DECLARE(PFNWXUGETTHEMEDOCUMENTATIONPROPERTY, GetThemeDocumentationProperty)
225 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEPARENTBACKGROUND, DrawThemeParentBackground)
226 wxUX_THEME_DECLARE(PFNWXUENABLETHEMING, EnableTheming)
227
228 private:
229 // construcor is private as only Get() can create us and is also trivial as
230 // everything really happens in Initialize()
231 wxUxThemeEngine() { }
232
233 // destructor is private as only Get() and wxUxThemeModule delete us, it is
234 // not virtual as we're not supposed to be derived from
235 ~wxUxThemeEngine() { }
236
237 #if wxUSE_UXTHEME
238 // initialize the theme engine: load the DLL, resolve the functions
239 //
240 // return true if we can be used, false if themes are not available
241 bool Initialize();
242
243
244 // uxtheme.dll
245 wxDynamicLibrary m_dllUxTheme;
246
247
248 // the one and only theme engine, initially NULL
249 static wxUxThemeEngine *ms_themeEngine;
250
251 // this is a bool which initially has the value -1 meaning "unknown"
252 static int ms_isThemeEngineAvailable;
253
254 // it must be able to delete us
255 friend class wxUxThemeModule;
256 #endif // wxUSE_UXTHEME
257
258 DECLARE_NO_COPY_CLASS(wxUxThemeEngine)
259 };
260
261 #if wxUSE_UXTHEME
262
263 /* static */ inline wxUxThemeEngine *wxUxThemeEngine::GetIfActive()
264 {
265 wxUxThemeEngine *engine = Get();
266 return engine && engine->IsAppThemed() && engine->IsThemeActive()
267 ? engine
268 : NULL;
269 }
270
271 #else // !wxUSE_UXTHEME
272
273 /* static */ inline wxUxThemeEngine *wxUxThemeEngine::Get()
274 {
275 return NULL;
276 }
277
278 /* static */ inline wxUxThemeEngine *wxUxThemeEngine::GetIfActive()
279 {
280 return NULL;
281 }
282
283 #endif // wxUSE_UXTHEME/!wxUSE_UXTHEME
284
285 // ----------------------------------------------------------------------------
286 // wxUxThemeHandle: encapsulates ::Open/CloseThemeData()
287 // ----------------------------------------------------------------------------
288
289 class wxUxThemeHandle
290 {
291 public:
292 wxUxThemeHandle(wxWindow *win, const wchar_t *classes)
293 {
294 wxUxThemeEngine *engine = wxUxThemeEngine::Get();
295
296 m_hTheme =
297 engine ? (WXHTHEME)engine->OpenThemeData(win->GetHWND(), classes)
298 : NULL;
299 }
300
301 operator WXHTHEME() const { return m_hTheme; }
302
303 ~wxUxThemeHandle()
304 {
305 if ( m_hTheme )
306 {
307 wxUxThemeEngine::Get()->CloseThemeData(m_hTheme);
308 }
309 }
310
311 private:
312 WXHTHEME m_hTheme;
313
314 DECLARE_NO_COPY_CLASS(wxUxThemeHandle)
315 };
316
317 #endif // _WX_UXTHEME_H_
318