]>
git.saurik.com Git - wxWidgets.git/blob - src/univ/theme.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: univ/theme.cpp
3 // Purpose: implementation of wxTheme
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
32 #include "wx/artprov.h"
34 #include "wx/univ/renderer.h"
35 #include "wx/univ/inphand.h"
36 #include "wx/univ/theme.h"
38 // ============================================================================
40 // ============================================================================
42 wxThemeInfo
*wxTheme::ms_allThemes
= (wxThemeInfo
*)NULL
;
43 wxTheme
*wxTheme::ms_theme
= (wxTheme
*)NULL
;
45 // ----------------------------------------------------------------------------
46 // "dynamic" theme creation
47 // ----------------------------------------------------------------------------
49 wxThemeInfo::wxThemeInfo(Constructor c
,
52 : name(n
), desc(d
), ctor(c
)
54 // insert us (in the head of) the linked list
55 next
= wxTheme::ms_allThemes
;
56 wxTheme::ms_allThemes
= this;
59 /* static */ wxTheme
*wxTheme::Create(const wxString
& name
)
61 // find the theme in the list by name
62 wxThemeInfo
*info
= ms_allThemes
;
65 if ( name
.CmpNoCase(info
->name
) == 0 )
73 return (wxTheme
*)NULL
;
76 // ----------------------------------------------------------------------------
77 // the default theme (called by wxApp::OnInitGui)
78 // ----------------------------------------------------------------------------
80 /* static */ bool wxTheme::CreateDefault()
84 // we already have a theme
88 wxString nameDefTheme
;
90 // use the environment variable first
91 const wxChar
*p
= wxGetenv(_T("WXTHEME"));
96 #ifdef wxUNIV_DEFAULT_THEME
97 else // use native theme by default
99 nameDefTheme
= wxSTRINGIZE_T(wxUNIV_DEFAULT_THEME
);
101 #endif // wxUNIV_DEFAULT_THEME
103 wxTheme
*theme
= Create(nameDefTheme
);
105 // fallback to the first one in the list
106 if ( !theme
&& ms_allThemes
)
108 theme
= ms_allThemes
->ctor();
111 // abort if still nothing
114 wxLogError(_("Failed to initialize GUI: no built-in themes found."));
119 // Set the theme as current.
125 /* static */ wxTheme
*wxTheme::Set(wxTheme
*theme
)
127 wxTheme
*themeOld
= ms_theme
;
132 // automatically start using the art provider of the new theme if it
134 wxArtProvider
*art
= ms_theme
->GetArtProvider();
136 wxArtProvider::Push(art
);
142 // ----------------------------------------------------------------------------
143 // assorted trivial dtors
144 // ----------------------------------------------------------------------------
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 wxDelegateTheme::wxDelegateTheme(const wxString
& theme
)
161 wxDelegateTheme::~wxDelegateTheme()
166 bool wxDelegateTheme::GetOrCreateTheme()
169 m_theme
= wxTheme::Create(m_themeName
);
170 return m_theme
!= NULL
;
173 wxRenderer
*wxDelegateTheme::GetRenderer()
175 if ( !GetOrCreateTheme() )
178 return m_theme
->GetRenderer();
181 wxArtProvider
*wxDelegateTheme::GetArtProvider()
183 if ( !GetOrCreateTheme() )
186 return m_theme
->GetArtProvider();
189 wxInputHandler
*wxDelegateTheme::GetInputHandler(const wxString
& control
,
190 wxInputConsumer
*consumer
)
192 if ( !GetOrCreateTheme() )
195 return m_theme
->GetInputHandler(control
, consumer
);
198 wxColourScheme
*wxDelegateTheme::GetColourScheme()
200 if ( !GetOrCreateTheme() )
203 return m_theme
->GetColourScheme();