1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/uxtheme.cpp
3 // Purpose: implements wxUxThemeEngine class: support for XP themes
8 // Copyright: (c) 2003 wxWindows Dev-Team
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
17 #pragma implementation "uxtheme.h"
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
35 #include "wx/toplevel.h"
36 #include "wx/string.h"
40 #include "wx/module.h"
42 #include "wx/msw/uxtheme.h"
44 // ============================================================================
46 // ============================================================================
48 // this module is responsable for deleting the theme engine
49 class wxUxThemeModule
: public wxModule
52 virtual bool OnInit() { return true; }
55 if ( wxUxThemeEngine::ms_themeEngine
)
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;
71 DECLARE_DYNAMIC_CLASS(wxUxThemeModule
)
74 IMPLEMENT_DYNAMIC_CLASS(wxUxThemeModule
, wxModule
)
76 // ============================================================================
77 // wxUxThemeEngine implementation
78 // ============================================================================
80 wxUxThemeEngine
*wxUxThemeEngine::ms_themeEngine
= NULL
;
81 int wxUxThemeEngine::ms_isThemeEngineAvailable
= -1; // unknown
83 wxUxThemeEngine
* wxUxThemeEngine::Get()
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 )
89 // we're called or the first time, check if the themes are available
90 ms_themeEngine
= new wxUxThemeEngine
;
91 if ( !ms_themeEngine
->Initialize() )
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
;
98 ms_isThemeEngineAvailable
= false;
100 else // initialized ok
102 ms_isThemeEngineAvailable
= true;
106 return ms_themeEngine
;
109 bool wxUxThemeEngine::Initialize()
111 if ( wxTheApp
->GetComCtl32Version() < 600 )
113 // not using theme-aware comctl32.dll anyhow, don't even try to use
118 // we're prepared to handle the errors
121 if ( !m_dllUxTheme
.Load(_T("uxtheme.dll")) )
124 #define RESOLVE_UXTHEME_FUNCTION(type, funcname) \
125 funcname = (type)m_dllUxTheme.GetSymbol(_T(#funcname)); \
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
);
177 #undef RESOLVE_UXTHEME_FUNCTION
182 #endif // wxUSE_UXTHEME