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