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