]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/univ/theme.cpp
Rename wxWebHistoryItem to wxWebViewHistoryItem.
[wxWidgets.git] / src / univ / theme.cpp
... / ...
CommitLineData
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// RCS-ID: $Id$
8// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
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
32#include "wx/artprov.h"
33
34#include "wx/univ/renderer.h"
35#include "wx/univ/inphand.h"
36#include "wx/univ/theme.h"
37
38// ============================================================================
39// implementation
40// ============================================================================
41
42wxThemeInfo *wxTheme::ms_allThemes = NULL;
43wxTheme *wxTheme::ms_theme = NULL;
44
45// ----------------------------------------------------------------------------
46// "dynamic" theme creation
47// ----------------------------------------------------------------------------
48
49wxThemeInfo::wxThemeInfo(Constructor c,
50 const wxString& n,
51 const wxString& d)
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 {
65 if ( name.CmpNoCase(info->name) == 0 )
66 {
67 return info->ctor();
68 }
69
70 info = info->next;
71 }
72
73 return NULL;
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
85 return true;
86 }
87
88 wxString nameDefTheme;
89
90 // use the environment variable first
91 const wxChar *p = wxGetenv(wxT("WXTHEME"));
92 if ( p )
93 {
94 nameDefTheme = p;
95 }
96#ifdef wxUNIV_DEFAULT_THEME
97 else // use native theme by default
98 {
99 nameDefTheme = wxSTRINGIZE_T(wxUNIV_DEFAULT_THEME);
100 }
101#endif // wxUNIV_DEFAULT_THEME
102
103 wxTheme *theme = Create(nameDefTheme);
104
105 // fallback to the first one in the list
106 if ( !theme && ms_allThemes )
107 {
108 theme = ms_allThemes->ctor();
109 }
110
111 // abort if still nothing
112 if ( !theme )
113 {
114 wxLogError(_("Failed to initialize GUI: no built-in themes found."));
115
116 return false;
117 }
118
119 // Set the theme as current.
120 wxTheme::Set(theme);
121
122 return true;
123}
124
125/* static */ wxTheme *wxTheme::Set(wxTheme *theme)
126{
127 wxTheme *themeOld = ms_theme;
128 ms_theme = theme;
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 )
136 wxArtProvider::Push(art);
137 }
138
139 return themeOld;
140}
141
142// ----------------------------------------------------------------------------
143// assorted trivial dtors
144// ----------------------------------------------------------------------------
145
146wxTheme::~wxTheme()
147{
148}
149
150
151// ----------------------------------------------------------------------------
152// wxDelegateTheme
153// ----------------------------------------------------------------------------
154
155wxDelegateTheme::wxDelegateTheme(const wxString& theme)
156{
157 m_themeName = theme;
158 m_theme = NULL;
159}
160
161wxDelegateTheme::~wxDelegateTheme()
162{
163 delete m_theme;
164}
165
166bool wxDelegateTheme::GetOrCreateTheme()
167{
168 if ( !m_theme )
169 m_theme = wxTheme::Create(m_themeName);
170 return m_theme != NULL;
171}
172
173wxRenderer *wxDelegateTheme::GetRenderer()
174{
175 if ( !GetOrCreateTheme() )
176 return NULL;
177
178 return m_theme->GetRenderer();
179}
180
181wxArtProvider *wxDelegateTheme::GetArtProvider()
182{
183 if ( !GetOrCreateTheme() )
184 return NULL;
185
186 return m_theme->GetArtProvider();
187}
188
189wxInputHandler *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
198wxColourScheme *wxDelegateTheme::GetColourScheme()
199{
200 if ( !GetOrCreateTheme() )
201 return NULL;
202
203 return m_theme->GetColourScheme();
204}