1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/uxtheme.cpp
3 // Purpose: implements wxUxThemeEngine class: support for XP themes
4 // Author: John Platts, Vadim Zeitlin
5 // Modified by:
6 // Created: 2003
7 // Copyright: (c) 2003 John Platts, Vadim Zeitlin
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_UXTHEME
27
28 #ifndef WX_PRECOMP
29 #include "wx/app.h"
30 #include "wx/toplevel.h"
31 #include "wx/string.h"
32 #include "wx/log.h"
33 #include "wx/module.h"
34 #endif //WX_PRECOMP
35
36 #include "wx/msw/uxtheme.h"
37
38 // ============================================================================
39 // wxUxThemeModule
40 // ============================================================================
41
42 // this module is responsable for deleting the theme engine
43 class wxUxThemeModule : public wxModule
44 {
45 public:
OnInit()46 virtual bool OnInit() { return true; }
OnExit()47 virtual void OnExit()
48 {
49 if ( wxUxThemeEngine::ms_themeEngine )
50 {
51 // this is probably not necessary right now but try to be careful
52 // and avoid the problems which we might have if someone ever
53 // decides to show a message box using the theme engine from
54 // wxUxThemeEngine dtor (e.g. from wxDynamicLibrary dtor...) or
55 // something like this
56 wxUxThemeEngine *themeEngine = wxUxThemeEngine::ms_themeEngine;
57 wxUxThemeEngine::ms_themeEngine = NULL;
58 wxUxThemeEngine::ms_isThemeEngineAvailable = -1;
59
60 delete themeEngine;
61 }
62 }
63
64
65 DECLARE_DYNAMIC_CLASS(wxUxThemeModule)
66 };
67
68 IMPLEMENT_DYNAMIC_CLASS(wxUxThemeModule, wxModule)
69
70 // ============================================================================
71 // wxUxThemeEngine implementation
72 // ============================================================================
73
74 wxUxThemeEngine *wxUxThemeEngine::ms_themeEngine = NULL;
75 int wxUxThemeEngine::ms_isThemeEngineAvailable = -1; // unknown
76
Get()77 wxUxThemeEngine* wxUxThemeEngine::Get()
78 {
79 // we assume that themes are only used in the main thread hence no need for
80 // critical section here
81 if ( ms_isThemeEngineAvailable == -1 )
82 {
83 // we're called or the first time, check if the themes are available
84 ms_themeEngine = new wxUxThemeEngine;
85 if ( !ms_themeEngine->Initialize() )
86 {
87 // can't use themes, probably because the system doesn't support
88 // them, don't do it again
89 delete ms_themeEngine;
90 ms_themeEngine = NULL;
91
92 ms_isThemeEngineAvailable = false;
93 }
94 else // initialized ok
95 {
96 ms_isThemeEngineAvailable = true;
97 }
98 }
99
100 return ms_themeEngine;
101 }
102
Initialize()103 bool wxUxThemeEngine::Initialize()
104 {
105 if ( wxApp::GetComCtl32Version() < 600 )
106 {
107 // not using theme-aware comctl32.dll anyhow, don't even try to use
108 // themes
109 return false;
110 }
111
112 // we're prepared to handle the errors
113 wxLogNull noLog;
114
115 if ( !m_dllUxTheme.Load(wxT("uxtheme.dll")) )
116 return false;
117
118 #define RESOLVE_UXTHEME_FUNCTION(type, funcname) \
119 funcname = (type)m_dllUxTheme.GetSymbol(wxT(#funcname)); \
120 if ( !funcname ) \
121 return false
122
123 RESOLVE_UXTHEME_FUNCTION(PFNWXUOPENTHEMEDATA, OpenThemeData);
124 RESOLVE_UXTHEME_FUNCTION(PFNWXUCLOSETHEMEDATA, CloseThemeData);
125 RESOLVE_UXTHEME_FUNCTION(PFNWXUDRAWTHEMEBACKGROUND, DrawThemeBackground);
126 RESOLVE_UXTHEME_FUNCTION(PFNWXUDRAWTHEMETEXT, DrawThemeText);
127 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEBACKGROUNDCONTENTRECT, GetThemeBackgroundContentRect);
128 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEBACKGROUNDEXTENT, GetThemeBackgroundExtent);
129 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEPARTSIZE, GetThemePartSize);
130 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMETEXTEXTENT, GetThemeTextExtent);
131 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMETEXTMETRICS, GetThemeTextMetrics);
132 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEBACKGROUNDREGION, GetThemeBackgroundRegion);
133 RESOLVE_UXTHEME_FUNCTION(PFNWXUHITTESTTHEMEBACKGROUND, HitTestThemeBackground);
134 RESOLVE_UXTHEME_FUNCTION(PFNWXUDRAWTHEMEEDGE, DrawThemeEdge);
135 RESOLVE_UXTHEME_FUNCTION(PFNWXUDRAWTHEMEICON, DrawThemeIcon);
136 RESOLVE_UXTHEME_FUNCTION(PFNWXUISTHEMEPARTDEFINED, IsThemePartDefined);
137 RESOLVE_UXTHEME_FUNCTION(PFNWXUISTHEMEBACKGROUNDPARTIALLYTRANSPARENT, IsThemeBackgroundPartiallyTransparent);
138 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMECOLOR, GetThemeColor);
139 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEMETRIC, GetThemeMetric);
140 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMESTRING, GetThemeString);
141 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEBOOL, GetThemeBool);
142 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEINT, GetThemeInt);
143 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEENUMVALUE, GetThemeEnumValue);
144 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEPOSITION, GetThemePosition);
145 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEFONT, GetThemeFont);
146 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMERECT, GetThemeRect);
147 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEMARGINS, GetThemeMargins);
148 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEINTLIST, GetThemeIntList);
149 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEPROPERTYORIGIN, GetThemePropertyOrigin);
150 RESOLVE_UXTHEME_FUNCTION(PFNWXUSETWINDOWTHEME, SetWindowTheme);
151 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEFILENAME, GetThemeFilename);
152 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMESYSCOLOR, GetThemeSysColor);
153 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMESYSCOLORBRUSH, GetThemeSysColorBrush);
154 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMESYSBOOL, GetThemeSysBool);
155 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMESYSSIZE, GetThemeSysSize);
156 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMESYSFONT, GetThemeSysFont);
157 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMESYSSTRING, GetThemeSysString);
158 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMESYSINT, GetThemeSysInt);
159 RESOLVE_UXTHEME_FUNCTION(PFNWXUISTHEMEACTIVE, IsThemeActive);
160 RESOLVE_UXTHEME_FUNCTION(PFNWXUISAPPTHEMED, IsAppThemed);
161 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETWINDOWTHEME, GetWindowTheme);
162 RESOLVE_UXTHEME_FUNCTION(PFNWXUENABLETHEMEDIALOGTEXTURE, EnableThemeDialogTexture);
163 RESOLVE_UXTHEME_FUNCTION(PFNWXUISTHEMEDIALOGTEXTUREENABLED, IsThemeDialogTextureEnabled);
164 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEAPPPROPERTIES, GetThemeAppProperties);
165 RESOLVE_UXTHEME_FUNCTION(PFNWXUSETTHEMEAPPPROPERTIES, SetThemeAppProperties);
166 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETCURRENTTHEMENAME, GetCurrentThemeName);
167 RESOLVE_UXTHEME_FUNCTION(PFNWXUGETTHEMEDOCUMENTATIONPROPERTY, GetThemeDocumentationProperty);
168 RESOLVE_UXTHEME_FUNCTION(PFNWXUDRAWTHEMEPARENTBACKGROUND, DrawThemeParentBackground);
169 RESOLVE_UXTHEME_FUNCTION(PFNWXUENABLETHEMING, EnableTheming);
170
171 #undef RESOLVE_UXTHEME_FUNCTION
172
173 return true;
174 }
175
176 #endif // wxUSE_UXTHEME
177