]>
Commit | Line | Data |
---|---|---|
1e6feb95 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: univ/theme.cpp | |
3 | // Purpose: implementation of wxTheme | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 06.08.00 | |
7 | // RCS-ID: $Id$ | |
442b35b5 | 8 | // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com) |
65571936 | 9 | // Licence: wxWindows licence |
1e6feb95 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // =========================================================================== | |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
1e6feb95 VZ |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #ifndef WX_PRECOMP | |
28 | #include "wx/intl.h" | |
29 | #include "wx/log.h" | |
30 | #endif // WX_PRECOMP | |
31 | ||
815b393a VZ |
32 | #include "wx/artprov.h" |
33 | ||
1e6feb95 VZ |
34 | #include "wx/univ/renderer.h" |
35 | #include "wx/univ/inphand.h" | |
36 | #include "wx/univ/theme.h" | |
37 | ||
38 | // ============================================================================ | |
39 | // implementation | |
40 | // ============================================================================ | |
41 | ||
d3b9f782 VZ |
42 | wxThemeInfo *wxTheme::ms_allThemes = NULL; |
43 | wxTheme *wxTheme::ms_theme = NULL; | |
1e6feb95 VZ |
44 | |
45 | // ---------------------------------------------------------------------------- | |
46 | // "dynamic" theme creation | |
47 | // ---------------------------------------------------------------------------- | |
48 | ||
49 | wxThemeInfo::wxThemeInfo(Constructor c, | |
c2e45372 VZ |
50 | const wxString& n, |
51 | const wxString& d) | |
1e6feb95 VZ |
52 | : name(n), desc(d), ctor(c) |
53 | { | |
54 | // insert us (in the head of) the linked list | |
55 | next = wxTheme::ms_allThemes; | |
56 | wxTheme::ms_allThemes = this; | |
57 | } | |
58 | ||
59 | /* static */ wxTheme *wxTheme::Create(const wxString& name) | |
60 | { | |
61 | // find the theme in the list by name | |
62 | wxThemeInfo *info = ms_allThemes; | |
63 | while ( info ) | |
64 | { | |
b8d5d8b8 | 65 | if ( name.CmpNoCase(info->name) == 0 ) |
1e6feb95 VZ |
66 | { |
67 | return info->ctor(); | |
68 | } | |
69 | ||
70 | info = info->next; | |
71 | } | |
72 | ||
d3b9f782 | 73 | return NULL; |
1e6feb95 VZ |
74 | } |
75 | ||
76 | // ---------------------------------------------------------------------------- | |
77 | // the default theme (called by wxApp::OnInitGui) | |
78 | // ---------------------------------------------------------------------------- | |
79 | ||
80 | /* static */ bool wxTheme::CreateDefault() | |
81 | { | |
82 | if ( ms_theme ) | |
83 | { | |
84 | // we already have a theme | |
a290fa5a | 85 | return true; |
1e6feb95 VZ |
86 | } |
87 | ||
88 | wxString nameDefTheme; | |
89 | ||
90 | // use the environment variable first | |
9a83f860 | 91 | const wxChar *p = wxGetenv(wxT("WXTHEME")); |
1e6feb95 VZ |
92 | if ( p ) |
93 | { | |
94 | nameDefTheme = p; | |
95 | } | |
affebd0a | 96 | #ifdef wxUNIV_DEFAULT_THEME |
1e6feb95 VZ |
97 | else // use native theme by default |
98 | { | |
affebd0a | 99 | nameDefTheme = wxSTRINGIZE_T(wxUNIV_DEFAULT_THEME); |
1e6feb95 | 100 | } |
affebd0a | 101 | #endif // wxUNIV_DEFAULT_THEME |
1e6feb95 | 102 | |
815b393a | 103 | wxTheme *theme = Create(nameDefTheme); |
1e6feb95 VZ |
104 | |
105 | // fallback to the first one in the list | |
815b393a | 106 | if ( !theme && ms_allThemes ) |
1e6feb95 | 107 | { |
815b393a | 108 | theme = ms_allThemes->ctor(); |
1e6feb95 VZ |
109 | } |
110 | ||
111 | // abort if still nothing | |
815b393a | 112 | if ( !theme ) |
1e6feb95 VZ |
113 | { |
114 | wxLogError(_("Failed to initialize GUI: no built-in themes found.")); | |
115 | ||
a290fa5a | 116 | return false; |
1e6feb95 VZ |
117 | } |
118 | ||
815b393a VZ |
119 | // Set the theme as current. |
120 | wxTheme::Set(theme); | |
121 | ||
a290fa5a | 122 | return true; |
1e6feb95 VZ |
123 | } |
124 | ||
125 | /* static */ wxTheme *wxTheme::Set(wxTheme *theme) | |
126 | { | |
127 | wxTheme *themeOld = ms_theme; | |
128 | ms_theme = theme; | |
815b393a VZ |
129 | |
130 | if ( ms_theme ) | |
131 | { | |
132 | // automatically start using the art provider of the new theme if it | |
133 | // has one | |
134 | wxArtProvider *art = ms_theme->GetArtProvider(); | |
135 | if ( art ) | |
571d2e0f | 136 | wxArtProvider::Push(art); |
815b393a VZ |
137 | } |
138 | ||
1e6feb95 VZ |
139 | return themeOld; |
140 | } | |
141 | ||
142 | // ---------------------------------------------------------------------------- | |
143 | // assorted trivial dtors | |
144 | // ---------------------------------------------------------------------------- | |
145 | ||
146 | wxTheme::~wxTheme() | |
147 | { | |
148 | } | |
149 | ||
eef1a0cc VS |
150 | |
151 | // ---------------------------------------------------------------------------- | |
152 | // wxDelegateTheme | |
153 | // ---------------------------------------------------------------------------- | |
154 | ||
c2e45372 | 155 | wxDelegateTheme::wxDelegateTheme(const wxString& theme) |
eef1a0cc VS |
156 | { |
157 | m_themeName = theme; | |
158 | m_theme = NULL; | |
159 | } | |
160 | ||
161 | wxDelegateTheme::~wxDelegateTheme() | |
162 | { | |
163 | delete m_theme; | |
164 | } | |
165 | ||
166 | bool wxDelegateTheme::GetOrCreateTheme() | |
167 | { | |
168 | if ( !m_theme ) | |
169 | m_theme = wxTheme::Create(m_themeName); | |
170 | return m_theme != NULL; | |
171 | } | |
172 | ||
173 | wxRenderer *wxDelegateTheme::GetRenderer() | |
174 | { | |
175 | if ( !GetOrCreateTheme() ) | |
176 | return NULL; | |
177 | ||
178 | return m_theme->GetRenderer(); | |
179 | } | |
180 | ||
181 | wxArtProvider *wxDelegateTheme::GetArtProvider() | |
182 | { | |
183 | if ( !GetOrCreateTheme() ) | |
184 | return NULL; | |
185 | ||
186 | return m_theme->GetArtProvider(); | |
187 | } | |
188 | ||
189 | wxInputHandler *wxDelegateTheme::GetInputHandler(const wxString& control, | |
190 | wxInputConsumer *consumer) | |
191 | { | |
192 | if ( !GetOrCreateTheme() ) | |
193 | return NULL; | |
194 | ||
195 | return m_theme->GetInputHandler(control, consumer); | |
196 | } | |
197 | ||
198 | wxColourScheme *wxDelegateTheme::GetColourScheme() | |
199 | { | |
200 | if ( !GetOrCreateTheme() ) | |
201 | return NULL; | |
202 | ||
203 | return m_theme->GetColourScheme(); | |
204 | } |