]>
git.saurik.com Git - wxWidgets.git/blob - src/univ/theme.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/theme.cpp
3 // Purpose: implementation of wxTheme
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ===========================================================================
13 // ===========================================================================
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
31 #include "wx/artprov.h"
33 #include "wx/univ/renderer.h"
34 #include "wx/univ/inphand.h"
35 #include "wx/univ/theme.h"
37 // ============================================================================
39 // ============================================================================
41 wxThemeInfo
*wxTheme::ms_allThemes
= NULL
;
42 wxTheme
*wxTheme::ms_theme
= NULL
;
44 // ----------------------------------------------------------------------------
45 // "dynamic" theme creation
46 // ----------------------------------------------------------------------------
48 wxThemeInfo::wxThemeInfo(Constructor c
,
51 : name(n
), desc(d
), ctor(c
)
53 // insert us (in the head of) the linked list
54 next
= wxTheme::ms_allThemes
;
55 wxTheme::ms_allThemes
= this;
58 /* static */ wxTheme
*wxTheme::Create(const wxString
& name
)
60 // find the theme in the list by name
61 wxThemeInfo
*info
= ms_allThemes
;
64 if ( name
.CmpNoCase(info
->name
) == 0 )
75 // ----------------------------------------------------------------------------
76 // the default theme (called by wxApp::OnInitGui)
77 // ----------------------------------------------------------------------------
79 /* static */ bool wxTheme::CreateDefault()
83 // we already have a theme
87 wxString nameDefTheme
;
89 // use the environment variable first
90 const wxChar
*p
= wxGetenv(wxT("WXTHEME"));
95 #ifdef wxUNIV_DEFAULT_THEME
96 else // use native theme by default
98 nameDefTheme
= wxSTRINGIZE_T(wxUNIV_DEFAULT_THEME
);
100 #endif // wxUNIV_DEFAULT_THEME
102 wxTheme
*theme
= Create(nameDefTheme
);
104 // fallback to the first one in the list
105 if ( !theme
&& ms_allThemes
)
107 theme
= ms_allThemes
->ctor();
110 // abort if still nothing
113 wxLogError(_("Failed to initialize GUI: no built-in themes found."));
118 // Set the theme as current.
124 /* static */ wxTheme
*wxTheme::Set(wxTheme
*theme
)
126 wxTheme
*themeOld
= ms_theme
;
131 // automatically start using the art provider of the new theme if it
133 wxArtProvider
*art
= ms_theme
->GetArtProvider();
135 wxArtProvider::Push(art
);
141 // ----------------------------------------------------------------------------
142 // assorted trivial dtors
143 // ----------------------------------------------------------------------------
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
154 wxDelegateTheme::wxDelegateTheme(const wxString
& theme
)
160 wxDelegateTheme::~wxDelegateTheme()
165 bool wxDelegateTheme::GetOrCreateTheme()
168 m_theme
= wxTheme::Create(m_themeName
);
169 return m_theme
!= NULL
;
172 wxRenderer
*wxDelegateTheme::GetRenderer()
174 if ( !GetOrCreateTheme() )
177 return m_theme
->GetRenderer();
180 wxArtProvider
*wxDelegateTheme::GetArtProvider()
182 if ( !GetOrCreateTheme() )
185 return m_theme
->GetArtProvider();
188 wxInputHandler
*wxDelegateTheme::GetInputHandler(const wxString
& control
,
189 wxInputConsumer
*consumer
)
191 if ( !GetOrCreateTheme() )
194 return m_theme
->GetInputHandler(control
, consumer
);
197 wxColourScheme
*wxDelegateTheme::GetColourScheme()
199 if ( !GetOrCreateTheme() )
202 return m_theme
->GetColourScheme();