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