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