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