]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/uxtheme.h
define wxUSE_MFC as 0 if it's not defined (fixes gcc -Wundef warning)
[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 #include "wx/msw/uxthemep.h"
23
24 typedef HTHEME (__stdcall *PFNWXUOPENTHEMEDATA)(HWND, const wchar_t *);
25 typedef HRESULT (__stdcall *PFNWXUCLOSETHEMEDATA)(HTHEME);
26 typedef HRESULT (__stdcall *PFNWXUDRAWTHEMEBACKGROUND)(HTHEME, HDC, int, int, const RECT *, const RECT *);
27 typedef HRESULT (__stdcall *PFNWXUDRAWTHEMETEXT)(HTHEME, HDC, int, int, const wchar_t *, int, DWORD, DWORD, const RECT *);
28 typedef HRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDCONTENTRECT)(HTHEME, HDC, int, int, const RECT *, RECT *);
29 typedef HRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDEXTENT)(HTHEME, HDC, int, int, const RECT *, RECT *);
30 typedef HRESULT (__stdcall *PFNWXUGETTHEMEPARTSIZE)(HTHEME, HDC, int, int, const RECT *, /* enum */ THEMESIZE, SIZE *);
31 typedef HRESULT (__stdcall *PFNWXUGETTHEMETEXTEXTENT)(HTHEME, HDC, int, int, const wchar_t *, int, DWORD, const RECT *, RECT *);
32 typedef HRESULT (__stdcall *PFNWXUGETTHEMETEXTMETRICS)(HTHEME, HDC, int, int, TEXTMETRIC*);
33 typedef HRESULT (__stdcall *PFNWXUGETTHEMEBACKGROUNDREGION)(HTHEME, HDC, int, int, const RECT *, HRGN *);
34 typedef HRESULT (__stdcall *PFNWXUHITTESTTHEMEBACKGROUND)(HTHEME, HDC, int, int, DWORD, const RECT *, HRGN, POINT, unsigned short *);
35 typedef HRESULT (__stdcall *PFNWXUDRAWTHEMEEDGE)(HTHEME, HDC, int, int, const RECT *, unsigned int, unsigned int, RECT *);
36 typedef HRESULT (__stdcall *PFNWXUDRAWTHEMEICON)(HTHEME, HDC, int, int, const RECT *, HIMAGELIST, int);
37 typedef BOOL (__stdcall *PFNWXUISTHEMEPARTDEFINED)(HTHEME, int, int);
38 typedef BOOL (__stdcall *PFNWXUISTHEMEBACKGROUNDPARTIALLYTRANSPARENT)(HTHEME, int, int);
39 typedef HRESULT (__stdcall *PFNWXUGETTHEMECOLOR)(HTHEME, int, int, int, COLORREF*);
40 typedef HRESULT (__stdcall *PFNWXUGETTHEMEMETRIC)(HTHEME, HDC, int, int, int, int *);
41 typedef HRESULT (__stdcall *PFNWXUGETTHEMESTRING)(HTHEME, int, int, int, wchar_t *, int);
42 typedef HRESULT (__stdcall *PFNWXUGETTHEMEBOOL)(HTHEME, int, int, int, BOOL *);
43 typedef HRESULT (__stdcall *PFNWXUGETTHEMEINT)(HTHEME, int, int, int, int *);
44 typedef HRESULT (__stdcall *PFNWXUGETTHEMEENUMVALUE)(HTHEME, int, int, int, int *);
45 typedef HRESULT (__stdcall *PFNWXUGETTHEMEPOSITION)(HTHEME, int, int, int, POINT *);
46 typedef HRESULT (__stdcall *PFNWXUGETTHEMEFONT)(HTHEME, HDC, int, int, int, LOGFONT *);
47 typedef HRESULT (__stdcall *PFNWXUGETTHEMERECT)(HTHEME, int, int, int, RECT *);
48 typedef HRESULT (__stdcall *PFNWXUGETTHEMEMARGINS)(HTHEME, HDC, int, int, int, RECT *, MARGINS *);
49 typedef HRESULT (__stdcall *PFNWXUGETTHEMEINTLIST)(HTHEME, int, int, int, INTLIST*);
50 typedef HRESULT (__stdcall *PFNWXUGETTHEMEPROPERTYORIGIN)(HTHEME, int, int, int, /* enum */ PROPERTYORIGIN *);
51 typedef HRESULT (__stdcall *PFNWXUSETWINDOWTHEME)(HWND, const wchar_t*, const wchar_t *);
52 typedef HRESULT (__stdcall *PFNWXUGETTHEMEFILENAME)(HTHEME, int, int, int, wchar_t *, int);
53 typedef COLORREF(__stdcall *PFNWXUGETTHEMESYSCOLOR)(HTHEME, int);
54 typedef HBRUSH (__stdcall *PFNWXUGETTHEMESYSCOLORBRUSH)(HTHEME, int);
55 typedef BOOL (__stdcall *PFNWXUGETTHEMESYSBOOL)(HTHEME, int);
56 typedef int (__stdcall *PFNWXUGETTHEMESYSSIZE)(HTHEME, int);
57 typedef HRESULT (__stdcall *PFNWXUGETTHEMESYSFONT)(HTHEME, int, LOGFONT *);
58 typedef HRESULT (__stdcall *PFNWXUGETTHEMESYSSTRING)(HTHEME, int, wchar_t *, int);
59 typedef HRESULT (__stdcall *PFNWXUGETTHEMESYSINT)(HTHEME, int, int *);
60 typedef BOOL (__stdcall *PFNWXUISTHEMEACTIVE)();
61 typedef BOOL (__stdcall *PFNWXUISAPPTHEMED)();
62 typedef HTHEME (__stdcall *PFNWXUGETWINDOWTHEME)(HWND);
63 typedef HRESULT (__stdcall *PFNWXUENABLETHEMEDIALOGTEXTURE)(HWND, DWORD);
64 typedef BOOL (__stdcall *PFNWXUISTHEMEDIALOGTEXTUREENABLED)(HWND);
65 typedef DWORD (__stdcall *PFNWXUGETTHEMEAPPPROPERTIES)();
66 typedef void (__stdcall *PFNWXUSETTHEMEAPPPROPERTIES)(DWORD);
67 typedef HRESULT (__stdcall *PFNWXUGETCURRENTTHEMENAME)(wchar_t *, int, wchar_t *, int, wchar_t *, int);
68 typedef HRESULT (__stdcall *PFNWXUGETTHEMEDOCUMENTATIONPROPERTY)(const wchar_t *, const wchar_t *, wchar_t *, int);
69 typedef HRESULT (__stdcall *PFNWXUDRAWTHEMEPARENTBACKGROUND)(HWND, HDC, RECT *);
70 typedef HRESULT (__stdcall *PFNWXUENABLETHEMING)(BOOL);
71
72 // ----------------------------------------------------------------------------
73 // wxUxThemeEngine: provides all theme functions from uxtheme.dll
74 // ----------------------------------------------------------------------------
75
76 // we always define this class, even if wxUSE_UXTHEME == 0, but we just make it
77 // empty in this case -- this allows to use it elsewhere without any #ifdefs
78 #if wxUSE_UXTHEME
79 #include "wx/dynload.h"
80
81 #define wxUX_THEME_DECLARE(type, func) type func;
82 #else
83 #define wxUX_THEME_DECLARE(type, func) type func(...) { return 0; }
84 #endif
85
86 class WXDLLEXPORT wxUxThemeEngine
87 {
88 public:
89 // get the theme engine or NULL if themes are not available
90 static wxUxThemeEngine *Get();
91
92 // get the theme enging or NULL if themes are not available or not used for
93 // this application
94 static wxUxThemeEngine *GetIfActive();
95
96 // all uxtheme.dll functions
97 wxUX_THEME_DECLARE(PFNWXUOPENTHEMEDATA, OpenThemeData)
98 wxUX_THEME_DECLARE(PFNWXUCLOSETHEMEDATA, CloseThemeData)
99 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEBACKGROUND, DrawThemeBackground)
100 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMETEXT, DrawThemeText)
101 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBACKGROUNDCONTENTRECT, GetThemeBackgroundContentRect)
102 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBACKGROUNDEXTENT, GetThemeBackgroundExtent)
103 wxUX_THEME_DECLARE(PFNWXUGETTHEMEPARTSIZE, GetThemePartSize)
104 wxUX_THEME_DECLARE(PFNWXUGETTHEMETEXTEXTENT, GetThemeTextExtent)
105 wxUX_THEME_DECLARE(PFNWXUGETTHEMETEXTMETRICS, GetThemeTextMetrics)
106 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBACKGROUNDREGION, GetThemeBackgroundRegion)
107 wxUX_THEME_DECLARE(PFNWXUHITTESTTHEMEBACKGROUND, HitTestThemeBackground)
108 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEEDGE, DrawThemeEdge)
109 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEICON, DrawThemeIcon)
110 wxUX_THEME_DECLARE(PFNWXUISTHEMEPARTDEFINED, IsThemePartDefined)
111 wxUX_THEME_DECLARE(PFNWXUISTHEMEBACKGROUNDPARTIALLYTRANSPARENT, IsThemeBackgroundPartiallyTransparent)
112 wxUX_THEME_DECLARE(PFNWXUGETTHEMECOLOR, GetThemeColor)
113 wxUX_THEME_DECLARE(PFNWXUGETTHEMEMETRIC, GetThemeMetric)
114 wxUX_THEME_DECLARE(PFNWXUGETTHEMESTRING, GetThemeString)
115 wxUX_THEME_DECLARE(PFNWXUGETTHEMEBOOL, GetThemeBool)
116 wxUX_THEME_DECLARE(PFNWXUGETTHEMEINT, GetThemeInt)
117 wxUX_THEME_DECLARE(PFNWXUGETTHEMEENUMVALUE, GetThemeEnumValue)
118 wxUX_THEME_DECLARE(PFNWXUGETTHEMEPOSITION, GetThemePosition)
119 wxUX_THEME_DECLARE(PFNWXUGETTHEMEFONT, GetThemeFont)
120 wxUX_THEME_DECLARE(PFNWXUGETTHEMERECT, GetThemeRect)
121 wxUX_THEME_DECLARE(PFNWXUGETTHEMEMARGINS, GetThemeMargins)
122 wxUX_THEME_DECLARE(PFNWXUGETTHEMEINTLIST, GetThemeIntList)
123 wxUX_THEME_DECLARE(PFNWXUGETTHEMEPROPERTYORIGIN, GetThemePropertyOrigin)
124 wxUX_THEME_DECLARE(PFNWXUSETWINDOWTHEME, SetWindowTheme)
125 wxUX_THEME_DECLARE(PFNWXUGETTHEMEFILENAME, GetThemeFilename)
126 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSCOLOR, GetThemeSysColor)
127 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSCOLORBRUSH, GetThemeSysColorBrush)
128 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSBOOL, GetThemeSysBool)
129 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSSIZE, GetThemeSysSize)
130 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSFONT, GetThemeSysFont)
131 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSSTRING, GetThemeSysString)
132 wxUX_THEME_DECLARE(PFNWXUGETTHEMESYSINT, GetThemeSysInt)
133 wxUX_THEME_DECLARE(PFNWXUISTHEMEACTIVE, IsThemeActive)
134 wxUX_THEME_DECLARE(PFNWXUISAPPTHEMED, IsAppThemed)
135 wxUX_THEME_DECLARE(PFNWXUGETWINDOWTHEME, GetWindowTheme)
136 wxUX_THEME_DECLARE(PFNWXUENABLETHEMEDIALOGTEXTURE, EnableThemeDialogTexture)
137 wxUX_THEME_DECLARE(PFNWXUISTHEMEDIALOGTEXTUREENABLED, IsThemeDialogTextureEnabled)
138 wxUX_THEME_DECLARE(PFNWXUGETTHEMEAPPPROPERTIES, GetThemeAppProperties)
139 wxUX_THEME_DECLARE(PFNWXUSETTHEMEAPPPROPERTIES, SetThemeAppProperties)
140 wxUX_THEME_DECLARE(PFNWXUGETCURRENTTHEMENAME, GetCurrentThemeName)
141 wxUX_THEME_DECLARE(PFNWXUGETTHEMEDOCUMENTATIONPROPERTY, GetThemeDocumentationProperty)
142 wxUX_THEME_DECLARE(PFNWXUDRAWTHEMEPARENTBACKGROUND, DrawThemeParentBackground)
143 wxUX_THEME_DECLARE(PFNWXUENABLETHEMING, EnableTheming)
144
145 private:
146 // construcor is private as only Get() can create us and is also trivial as
147 // everything really happens in Initialize()
148 wxUxThemeEngine() { }
149
150 // destructor is private as only Get() and wxUxThemeModule delete us, it is
151 // not virtual as we're not supposed to be derived from
152 ~wxUxThemeEngine() { }
153
154 #if wxUSE_UXTHEME
155 // initialize the theme engine: load the DLL, resolve the functions
156 //
157 // return true if we can be used, false if themes are not available
158 bool Initialize();
159
160
161 // uxtheme.dll
162 wxDynamicLibrary m_dllUxTheme;
163
164
165 // the one and only theme engine, initially NULL
166 static wxUxThemeEngine *ms_themeEngine;
167
168 // this is a bool which initially has the value -1 meaning "unknown"
169 static int ms_isThemeEngineAvailable;
170
171 // it must be able to delete us
172 friend class wxUxThemeModule;
173 #endif // wxUSE_UXTHEME
174
175 DECLARE_NO_COPY_CLASS(wxUxThemeEngine)
176 };
177
178 #if wxUSE_UXTHEME
179
180 /* static */ inline wxUxThemeEngine *wxUxThemeEngine::GetIfActive()
181 {
182 wxUxThemeEngine *engine = Get();
183 return engine && engine->IsAppThemed() && engine->IsThemeActive()
184 ? engine
185 : NULL;
186 }
187
188 #else // !wxUSE_UXTHEME
189
190 /* static */ inline wxUxThemeEngine *wxUxThemeEngine::Get()
191 {
192 return NULL;
193 }
194
195 /* static */ inline wxUxThemeEngine *wxUxThemeEngine::GetIfActive()
196 {
197 return NULL;
198 }
199
200 #endif // wxUSE_UXTHEME/!wxUSE_UXTHEME
201
202 // ----------------------------------------------------------------------------
203 // wxUxThemeHandle: encapsulates ::Open/CloseThemeData()
204 // ----------------------------------------------------------------------------
205
206 class wxUxThemeHandle
207 {
208 public:
209 wxUxThemeHandle(wxWindow *win, const wchar_t *classes)
210 {
211 wxUxThemeEngine *engine = wxUxThemeEngine::Get();
212
213 m_hTheme =
214 engine ? (HTHEME)engine->OpenThemeData((HWND) win->GetHWND(), classes)
215 : NULL;
216 }
217
218 operator HTHEME() const { return m_hTheme; }
219
220 ~wxUxThemeHandle()
221 {
222 if ( m_hTheme )
223 {
224 wxUxThemeEngine::Get()->CloseThemeData(m_hTheme);
225 }
226 }
227
228 private:
229 HTHEME m_hTheme;
230
231 DECLARE_NO_COPY_CLASS(wxUxThemeHandle)
232 };
233
234 #endif // _WX_UXTHEME_H_
235