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