]> git.saurik.com Git - wxWidgets.git/blob - src/univ/theme.cpp
Committing in .
[wxWidgets.git] / src / univ / theme.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: 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
42 wxThemeInfo *wxTheme::ms_allThemes = (wxThemeInfo *)NULL;
43 wxTheme *wxTheme::ms_theme = (wxTheme *)NULL;
44
45 // ----------------------------------------------------------------------------
46 // "dynamic" theme creation
47 // ----------------------------------------------------------------------------
48
49 wxThemeInfo::wxThemeInfo(Constructor c,
50 const wxChar *n,
51 const wxChar *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 (wxTheme *)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(_T("WXTHEME"));
92 if ( p )
93 {
94 nameDefTheme = p;
95 }
96 else // use native theme by default
97 {
98 #if defined(__WXGTK__)
99 nameDefTheme = _T("gtk");
100 #elif defined(__WXX11__)
101 nameDefTheme = _T("win32");
102 #else
103 nameDefTheme = _T("win32");
104 #endif
105 }
106
107 wxTheme *theme = Create(nameDefTheme);
108
109 // fallback to the first one in the list
110 if ( !theme && ms_allThemes )
111 {
112 theme = ms_allThemes->ctor();
113 }
114
115 // abort if still nothing
116 if ( !theme )
117 {
118 wxLogError(_("Failed to initialize GUI: no built-in themes found."));
119
120 return false;
121 }
122
123 // Set the theme as current.
124 wxTheme::Set(theme);
125
126 return true;
127 }
128
129 /* static */ wxTheme *wxTheme::Set(wxTheme *theme)
130 {
131 wxTheme *themeOld = ms_theme;
132 ms_theme = theme;
133
134 if ( ms_theme )
135 {
136 // automatically start using the art provider of the new theme if it
137 // has one
138 wxArtProvider *art = ms_theme->GetArtProvider();
139 if ( art )
140 wxArtProvider::PushProvider(art);
141 }
142
143 return themeOld;
144 }
145
146 // ----------------------------------------------------------------------------
147 // assorted trivial dtors
148 // ----------------------------------------------------------------------------
149
150 wxTheme::~wxTheme()
151 {
152 }
153