]> git.saurik.com Git - wxWidgets.git/blob - src/msw/uxtheme.cpp
wxCocoa: Added preliminary Blit support
[wxWidgets.git] / src / msw / uxtheme.cpp
1 /*
2 * wxuxthem.h : wxWindows support for Microsoft Windows XP Theme library
3 * (uxtheme.dll)
4 * Modified to work with almost all Win32 compilers
5 * Compiler must support Unicode, the __cdecl calling convention, and the
6 * __stdcall calling convention
7 */
8
9 #ifdef __GNUG__
10 #pragma implementation "uxtheme.h"
11 #endif
12
13 // For compilers that support precompilation, includes "wx.h".
14 #include "wx/wxprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifndef WX_PRECOMP
21 #include "wx/app.h"
22 #include "wx/toplevel.h"
23 #include "wx/string.h"
24 #include "wx/log.h"
25 #endif //WX_PRECOMP
26
27 #include "wx/module.h"
28
29 #if wxUSE_UXTHEME
30
31 #include "wx/msw/wrapwin.h"
32
33 #include "wx/msw/uxtheme.h"
34 #include "wx/msw/private.h"
35 #include "wx/app.h" // for GetComCtl32Version
36
37 wxUxThemeEngine* g_pThemeEngine = ((wxUxThemeEngine*)NULL) ;
38
39 BOOL wxCanUseInitThemeEngine()
40 {
41 WXUOSVERSIONINFOEX wxuosex ;
42 memset((void*)&wxuosex, 0, sizeof(WXUOSVERSIONINFOEX)) ;
43 wxuosex.dwOSVersionInfoSize = sizeof(WXUOSVERSIONINFOEX) ;
44 if(!GetVersionEx((LPOSVERSIONINFO)&wxuosex))
45 {
46 wxuosex.dwOSVersionInfoSize = sizeof(OSVERSIONINFO) ;
47 if(!GetVersionEx((LPOSVERSIONINFO)&wxuosex))
48 {
49 return FALSE ;
50 }
51 }
52 if ((wxuosex.dwMajorVersion == 5) && (wxuosex.dwMinorVersion > 0))
53 {
54 return (wxTheApp->GetComCtl32Version() >= 600) ;
55 }
56 else
57 {
58 return FALSE ;
59 }
60 }
61
62 wxUxThemeEngine* wxUxThemeEngine::wxInitUxThemeEngine()
63 {
64 wxUxThemeEngine* pThemeEngine = new wxUxThemeEngine ;
65 return pThemeEngine ;
66 }
67
68 wxUxThemeEngine* wxUxThemeEngine::Get()
69 {
70 return g_pThemeEngine;
71 }
72
73 #ifdef WXU_USE_WXMODULE
74 class wxUxThemeModule : public wxModule
75 {
76 DECLARE_DYNAMIC_CLASS(wxUxThemeModule)
77 public:
78 virtual void OnExit()
79 {
80 if((wxCanUseInitThemeEngine()) && (g_pThemeEngine))
81 {
82 delete g_pThemeEngine ;
83 g_pThemeEngine = ((wxUxThemeEngine*)NULL) ;
84 }
85 }
86
87 virtual bool OnInit()
88 {
89 if(!wxCanUseInitThemeEngine())
90 {
91 g_pThemeEngine = ((wxUxThemeEngine*)NULL) ;
92 return TRUE ;
93 }
94 g_pThemeEngine = wxUxThemeEngine::wxInitUxThemeEngine() ;
95 if(!g_pThemeEngine)
96 {
97 return FALSE ;
98 }
99 else if(!g_pThemeEngine->IsInitialized())
100 {
101 OnExit() ;
102 return FALSE ;
103 }
104
105 return TRUE ;
106 }
107 };
108
109 IMPLEMENT_DYNAMIC_CLASS(wxUxThemeModule, wxModule)
110 #else
111 static void __cdecl wxUxThemeEngineOnExit()
112 {
113 if(g_pThemeEngine)
114 {
115 delete g_pThemeEngine ;
116 g_pThemeEngine = ((wxUxThemeEngine*)NULL) ;
117 }
118 }
119
120 BOOL wxUxInitThemeEngine()
121 {
122 if(!wxCanUseInitThemeEngine())
123 {
124 return TRUE ;
125 }
126 g_pThemeEngine = wxUxThemeEngine::wxInitUxThemeEngine() ;
127 if(!g_pThemeEngine)
128 {
129 return FALSE ;
130 }
131 else if(!g_pThemeEngine->IsInitialized())
132 {
133 wxUxThemeEngineOnExit() ;
134 return FALSE ;
135 }
136
137 if(atexit(wxUxThemeEngineOnExit) != 0)
138 {
139 wxUxThemeEngineOnExit() ;
140 return FALSE ;
141 }
142
143 return TRUE ;
144 }
145 #endif
146
147 #define WXU_GET_FN_PTR(hmod, type, pfunc, funcname) if(hmod != ((HINSTANCE)NULL)) { \
148 pfunc = (type)::GetProcAddress(hmod, funcname) ; \
149 if(pfunc == ((type)NULL)) \
150 { \
151 ::FreeLibrary(hmod) ; \
152 hmod = ((HINSTANCE)NULL) ; \
153 } \
154 }
155
156 wxUxThemeEngine::wxUxThemeEngine()
157 {
158 m_hInstUXThemeDLL = ::LoadLibraryA("uxtheme.dll") ;
159 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUOPENTHEMEDATA, m_pfnOpenThemeData, "OpenThemeData")
160 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUCLOSETHEMEDATA, m_pfnCloseThemeData, "CloseThemeData")
161 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUDRAWTHEMEBACKGROUND, m_pfnDrawThemeBackground, "DrawThemeBackground")
162 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUDRAWTHEMETEXT, m_pfnDrawThemeText, "DrawThemeText")
163 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEBACKGROUNDCONTENTRECT, m_pfnGetThemeBackgroundContentRect, "GetThemeBackgroundContentRect")
164 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEBACKGROUNDEXTENT, m_pfnGetThemeBackgroundExtent, "GetThemeBackgroundExtent")
165 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEPARTSIZE, m_pfnGetThemePartSize, "GetThemePartSize")
166 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMETEXTEXTENT, m_pfnGetThemeTextExtent, "GetThemeTextExtent")
167 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMETEXTMETRICS, m_pfnGetThemeTextMetrics, "GetThemeTextMetrics")
168 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEBACKGROUNDREGION, m_pfnGetThemeBackgroundRegion, "GetThemeBackgroundRegion")
169 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUHITTESTTHEMEBACKGROUND, m_pfnHitTestThemeBackground, "HitTestThemeBackground")
170 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUDRAWTHEMEEDGE, m_pfnDrawThemeEdge, "DrawThemeEdge")
171 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUDRAWTHEMEICON, m_pfnDrawThemeIcon, "DrawThemeIcon")
172 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUISTHEMEPARTDEFINED, m_pfnIsThemePartDefined, "IsThemePartDefined")
173 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUISTHEMEBACKGROUNDPARTIALLYTRANSPARENT, m_pfnIsThemeBackgroundPartiallyTransparent, "IsThemeBackgroundPartiallyTransparent")
174 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMECOLOR, m_pfnGetThemeColor, "GetThemeColor")
175 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEMETRIC, m_pfnGetThemeMetric, "GetThemeMetric")
176 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMESTRING, m_pfnGetThemeString, "GetThemeString")
177 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEBOOL, m_pfnGetThemeBool, "GetThemeBool")
178 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEINT, m_pfnGetThemeInt, "GetThemeInt")
179 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEENUMVALUE, m_pfnGetThemeEnumValue, "GetThemeEnumValue")
180 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEPOSITION, m_pfnGetThemePosition, "GetThemePosition")
181 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEFONT, m_pfnGetThemeFont, "GetThemeFont")
182 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMERECT, m_pfnGetThemeRect, "GetThemeRect")
183 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEMARGINS, m_pfnGetThemeMargins, "GetThemeMargins")
184 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEINTLIST, m_pfnGetThemeIntList, "GetThemeIntList")
185 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEPROPERTYORIGIN, m_pfnGetThemePropertyOrigin, "GetThemePropertyOrigin")
186 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUSETWINDOWTHEME, m_pfnSetWindowTheme, "SetWindowTheme")
187 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEFILENAME, m_pfnGetThemeFilename, "GetThemeFilename")
188 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMESYSCOLOR, m_pfnGetThemeSysColor, "GetThemeSysColor")
189 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMESYSCOLORBRUSH, m_pfnGetThemeSysColorBrush, "GetThemeSysColorBrush")
190 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMESYSBOOL, m_pfnGetThemeSysBool, "GetThemeSysBool")
191 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMESYSSIZE, m_pfnGetThemeSysSize, "GetThemeSysSize")
192 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMESYSFONT, m_pfnGetThemeSysFont, "GetThemeSysFont")
193 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMESYSSTRING, m_pfnGetThemeSysString, "GetThemeSysString")
194 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMESYSINT, m_pfnGetThemeSysInt, "GetThemeSysInt")
195 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUISTHEMEACTIVE, m_pfnIsThemeActive, "IsThemeActive")
196 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUISAPPTHEMED, m_pfnIsAppThemed, "IsAppThemed")
197 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETWINDOWTHEME, m_pfnGetWindowTheme, "GetWindowTheme")
198 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUENABLETHEMEDIALOGTEXTURE, m_pfnEnableThemeDialogTexture, "EnableThemeDialogTexture")
199 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUISTHEMEDIALOGTEXTUREENABLED, m_pfnIsThemeDialogTextureEnabled, "IsThemeDialogTextureEnabled")
200 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEAPPPROPERTIES, m_pfnGetThemeAppProperties, "GetThemeAppProperties")
201 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUSETTHEMEAPPPROPERTIES, m_pfnSetThemeAppProperties, "SetThemeAppProperties")
202 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETCURRENTTHEMENAME, m_pfnGetCurrentThemeName, "GetCurrentThemeName")
203 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUGETTHEMEDOCUMENTATIONPROPERTY, m_pfnGetThemeDocumentationProperty, "GetThemeDocumentationProperty")
204 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUDRAWTHEMEPARENTBACKGROUND, m_pfnDrawThemeParentBackground, "DrawThemeParentBackground")
205 WXU_GET_FN_PTR (m_hInstUXThemeDLL, PFNWXUENABLETHEMING, m_pfnEnableTheming, "EnableTheming")
206 m_bIsInitialized = (m_hInstUXThemeDLL != ((HINSTANCE)NULL)) ;
207 if(!m_bIsInitialized)
208 {
209 ResetFunctionPointers() ;
210 }
211 }
212
213 void wxUxThemeEngine::ResetFunctionPointers()
214 {
215 m_pfnOpenThemeData = ((PFNWXUOPENTHEMEDATA)NULL) ;
216 m_pfnCloseThemeData = ((PFNWXUCLOSETHEMEDATA)NULL) ;
217 m_pfnDrawThemeBackground = ((PFNWXUDRAWTHEMEBACKGROUND)NULL) ;
218 m_pfnDrawThemeText = ((PFNWXUDRAWTHEMETEXT)NULL) ;
219 m_pfnGetThemeBackgroundContentRect = ((PFNWXUGETTHEMEBACKGROUNDCONTENTRECT)NULL) ;
220 m_pfnGetThemeBackgroundExtent = ((PFNWXUGETTHEMEBACKGROUNDEXTENT)NULL) ;
221 m_pfnGetThemePartSize = ((PFNWXUGETTHEMEPARTSIZE)NULL) ;
222 m_pfnGetThemeTextExtent = ((PFNWXUGETTHEMETEXTEXTENT)NULL) ;
223 m_pfnGetThemeTextMetrics = ((PFNWXUGETTHEMETEXTMETRICS)NULL) ;
224 m_pfnGetThemeBackgroundRegion = ((PFNWXUGETTHEMEBACKGROUNDREGION)NULL) ;
225 m_pfnHitTestThemeBackground = ((PFNWXUHITTESTTHEMEBACKGROUND)NULL) ;
226 m_pfnDrawThemeEdge = ((PFNWXUDRAWTHEMEEDGE)NULL) ;
227 m_pfnDrawThemeIcon = ((PFNWXUDRAWTHEMEICON)NULL) ;
228 m_pfnIsThemePartDefined = ((PFNWXUISTHEMEPARTDEFINED)NULL) ;
229 m_pfnIsThemeBackgroundPartiallyTransparent = ((PFNWXUISTHEMEBACKGROUNDPARTIALLYTRANSPARENT)NULL) ;
230 m_pfnGetThemeColor = ((PFNWXUGETTHEMECOLOR)NULL) ;
231 m_pfnGetThemeMetric = ((PFNWXUGETTHEMEMETRIC)NULL) ;
232 m_pfnGetThemeString = ((PFNWXUGETTHEMESTRING)NULL) ;
233 m_pfnGetThemeBool = ((PFNWXUGETTHEMEBOOL)NULL) ;
234 m_pfnGetThemeInt = ((PFNWXUGETTHEMEINT)NULL) ;
235 m_pfnGetThemeEnumValue = ((PFNWXUGETTHEMEENUMVALUE)NULL) ;
236 m_pfnGetThemePosition = ((PFNWXUGETTHEMEPOSITION)NULL) ;
237 m_pfnGetThemeFont = ((PFNWXUGETTHEMEFONT)NULL) ;
238 m_pfnGetThemeRect = ((PFNWXUGETTHEMERECT)NULL) ;
239 m_pfnGetThemeMargins = ((PFNWXUGETTHEMEMARGINS)NULL) ;
240 m_pfnGetThemeIntList = ((PFNWXUGETTHEMEINTLIST)NULL) ;
241 m_pfnGetThemePropertyOrigin = ((PFNWXUGETTHEMEPROPERTYORIGIN)NULL) ;
242 m_pfnSetWindowTheme = ((PFNWXUSETWINDOWTHEME)NULL) ;
243 m_pfnGetThemeFilename = ((PFNWXUGETTHEMEFILENAME)NULL) ;
244 m_pfnGetThemeSysColor = ((PFNWXUGETTHEMESYSCOLOR)NULL) ;
245 m_pfnGetThemeSysColorBrush = ((PFNWXUGETTHEMESYSCOLORBRUSH)NULL) ;
246 m_pfnGetThemeSysBool = ((PFNWXUGETTHEMESYSBOOL)NULL) ;
247 m_pfnGetThemeSysSize = ((PFNWXUGETTHEMESYSSIZE)NULL) ;
248 m_pfnGetThemeSysFont = ((PFNWXUGETTHEMESYSFONT)NULL) ;
249 m_pfnGetThemeSysString = ((PFNWXUGETTHEMESYSSTRING)NULL) ;
250 m_pfnGetThemeSysInt = ((PFNWXUGETTHEMESYSINT)NULL) ;
251 m_pfnIsThemeActive = ((PFNWXUISTHEMEACTIVE)NULL) ;
252 m_pfnIsAppThemed = ((PFNWXUISAPPTHEMED)NULL) ;
253 m_pfnGetWindowTheme = ((PFNWXUGETWINDOWTHEME)NULL) ;
254 m_pfnEnableThemeDialogTexture = ((PFNWXUENABLETHEMEDIALOGTEXTURE)NULL) ;
255 m_pfnIsThemeDialogTextureEnabled = ((PFNWXUISTHEMEDIALOGTEXTUREENABLED)NULL) ;
256 m_pfnGetThemeAppProperties = ((PFNWXUGETTHEMEAPPPROPERTIES)NULL) ;
257 m_pfnSetThemeAppProperties = ((PFNWXUSETTHEMEAPPPROPERTIES)NULL) ;
258 m_pfnGetCurrentThemeName = ((PFNWXUGETCURRENTTHEMENAME)NULL) ;
259 m_pfnGetThemeDocumentationProperty = ((PFNWXUGETTHEMEDOCUMENTATIONPROPERTY)NULL) ;
260 m_pfnDrawThemeParentBackground = ((PFNWXUDRAWTHEMEPARENTBACKGROUND)NULL) ;
261 m_pfnEnableTheming = ((PFNWXUENABLETHEMING)NULL) ;
262 }
263
264 wxUxThemeEngine::~wxUxThemeEngine()
265 {
266 if(m_hInstUXThemeDLL != ((HINSTANCE)NULL))
267 {
268 ::FreeLibrary(m_hInstUXThemeDLL) ;
269 }
270 ResetFunctionPointers() ;
271 }
272
273 #endif
274 // wxUSE_UXTHEME
275