1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/uxtheme.cpp
3 // Purpose: implements wxUxThemeEngine class: support for XP themes
4 // Author: John Platts, Vadim Zeitlin
7 // Copyright: (c) 2003 John Platts, Vadim Zeitlin
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
30 #include "wx/toplevel.h"
31 #include "wx/string.h"
33 #include "wx/module.h"
36 #include "wx/msw/uxtheme.h"
38 // ============================================================================
40 // ============================================================================
42 // this module is responsable for deleting the theme engine
43 class wxUxThemeModule
: public wxModule
46 virtual bool OnInit() { return true; }
49 if ( wxUxThemeEngine::ms_themeEngine
)
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
= false;
65 DECLARE_DYNAMIC_CLASS(wxUxThemeModule
)
68 IMPLEMENT_DYNAMIC_CLASS(wxUxThemeModule
, wxModule
)
70 // ============================================================================
71 // wxUxThemeEngine implementation
72 // ============================================================================
74 wxUxThemeEngine
*wxUxThemeEngine::ms_themeEngine
= NULL
;
75 int wxUxThemeEngine::ms_isThemeEngineAvailable
= -1; // unknown
77 wxUxThemeEngine
* wxUxThemeEngine::Get()
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 )
83 // we're called or the first time, check if the themes are available
84 ms_themeEngine
= new wxUxThemeEngine
;
85 if ( !ms_themeEngine
->Initialize() )
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
;
92 ms_isThemeEngineAvailable
= false;
94 else // initialized ok
96 ms_isThemeEngineAvailable
= true;
100 return ms_themeEngine
;
103 bool wxUxThemeEngine::Initialize()
105 if ( wxApp::GetComCtl32Version() < 600 )
107 // not using theme-aware comctl32.dll anyhow, don't even try to use
112 // we're prepared to handle the errors
115 if ( !m_dllUxTheme
.Load(wxT("uxtheme.dll")) )
118 #define RESOLVE_UXTHEME_FUNCTION(type, funcname) \
119 funcname = (type)m_dllUxTheme.GetSymbol(wxT(#funcname)); \
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
);
171 #undef RESOLVE_UXTHEME_FUNCTION
176 #endif // wxUSE_UXTHEME