]> git.saurik.com Git - wxWidgets.git/blob - src/msw/uxtheme.cpp
return begining of the selection for GetInsertionPoint to match what
[wxWidgets.git] / src / msw / uxtheme.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/uxtheme.cpp
3 // Purpose: implements wxUxThemeEngine class: support for XP themes
4 // Author:
5 // Modified by:
6 // Created: 2003
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 wxWidgets Dev-Team
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma implementation "uxtheme.h"
18 #endif
19
20 // ----------------------------------------------------------------------------
21 // headers
22 // ----------------------------------------------------------------------------
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #if wxUSE_UXTHEME
32
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
40 #include "wx/module.h"
41
42 #include "wx/msw/uxtheme.h"
43
44 // ============================================================================
45 // wxUxThemeModule
46 // ============================================================================
47
48 // this module is responsable for deleting the theme engine
49 class wxUxThemeModule : public wxModule
50 {
51 public:
52 virtual bool OnInit() { return true; }
53 virtual void OnExit()
54 {
55 if ( wxUxThemeEngine::ms_themeEngine )
56 {
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
66 delete themeEngine;
67 }
68 }
69
70
71 DECLARE_DYNAMIC_CLASS(wxUxThemeModule)
72 };
73
74 IMPLEMENT_DYNAMIC_CLASS(wxUxThemeModule, wxModule)
75
76 // ============================================================================
77 // wxUxThemeEngine implementation
78 // ============================================================================
79
80 wxUxThemeEngine *wxUxThemeEngine::ms_themeEngine = NULL;
81 int wxUxThemeEngine::ms_isThemeEngineAvailable = -1; // unknown
82
83 wxUxThemeEngine* wxUxThemeEngine::Get()
84 {
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 )
88 {
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 }
104 }
105
106 return ms_themeEngine;
107 }
108
109 bool wxUxThemeEngine::Initialize()
110 {
111 if ( wxApp::GetComCtl32Version() < 600 )
112 {
113 // not using theme-aware comctl32.dll anyhow, don't even try to use
114 // themes
115 return false;
116 }
117
118 // we're prepared to handle the errors
119 wxLogNull noLog;
120
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;
180 }
181
182 #endif // wxUSE_UXTHEME
183