]> git.saurik.com Git - wxWidgets.git/blob - src/univ/theme.cpp
compilation fix for Mac and reformatted the code
[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 #ifdef __GNUG__
21 #pragma implementation "theme.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/intl.h"
33 #include "wx/log.h"
34 #endif // WX_PRECOMP
35
36 #include "wx/artprov.h"
37
38 #include "wx/univ/renderer.h"
39 #include "wx/univ/inphand.h"
40 #include "wx/univ/theme.h"
41
42 // ============================================================================
43 // implementation
44 // ============================================================================
45
46 wxThemeInfo *wxTheme::ms_allThemes = (wxThemeInfo *)NULL;
47 wxTheme *wxTheme::ms_theme = (wxTheme *)NULL;
48
49 // ----------------------------------------------------------------------------
50 // "dynamic" theme creation
51 // ----------------------------------------------------------------------------
52
53 wxThemeInfo::wxThemeInfo(Constructor c,
54 const wxChar *n,
55 const wxChar *d)
56 : name(n), desc(d), ctor(c)
57 {
58 // insert us (in the head of) the linked list
59 next = wxTheme::ms_allThemes;
60 wxTheme::ms_allThemes = this;
61 }
62
63 /* static */ wxTheme *wxTheme::Create(const wxString& name)
64 {
65 // find the theme in the list by name
66 wxThemeInfo *info = ms_allThemes;
67 while ( info )
68 {
69 if ( name.CmpNoCase(info->name) == 0 )
70 {
71 return info->ctor();
72 }
73
74 info = info->next;
75 }
76
77 return (wxTheme *)NULL;
78 }
79
80 // ----------------------------------------------------------------------------
81 // the default theme (called by wxApp::OnInitGui)
82 // ----------------------------------------------------------------------------
83
84 /* static */ bool wxTheme::CreateDefault()
85 {
86 if ( ms_theme )
87 {
88 // we already have a theme
89 return TRUE;
90 }
91
92 wxString nameDefTheme;
93
94 // use the environment variable first
95 const wxChar *p = wxGetenv(_T("WXTHEME"));
96 if ( p )
97 {
98 nameDefTheme = p;
99 }
100 else // use native theme by default
101 {
102 #if defined(__WXGTK__)
103 nameDefTheme = _T("gtk");
104 #elif defined(__WXX11__)
105 nameDefTheme = _T("win32");
106 #else
107 nameDefTheme = _T("win32");
108 #endif
109 }
110
111 wxTheme *theme = Create(nameDefTheme);
112
113 // fallback to the first one in the list
114 if ( !theme && ms_allThemes )
115 {
116 theme = ms_allThemes->ctor();
117 }
118
119 // abort if still nothing
120 if ( !theme )
121 {
122 wxLogError(_("Failed to initialize GUI: no built-in themes found."));
123
124 return FALSE;
125 }
126
127 // Set the theme as current.
128 wxTheme::Set(theme);
129
130 return TRUE;
131 }
132
133 /* static */ wxTheme *wxTheme::Set(wxTheme *theme)
134 {
135 wxTheme *themeOld = ms_theme;
136 ms_theme = theme;
137
138 if ( ms_theme )
139 {
140 // automatically start using the art provider of the new theme if it
141 // has one
142 wxArtProvider *art = ms_theme->GetArtProvider();
143 if ( art )
144 wxArtProvider::PushProvider(art);
145 }
146
147 return themeOld;
148 }
149
150 // ----------------------------------------------------------------------------
151 // assorted trivial dtors
152 // ----------------------------------------------------------------------------
153
154 wxTheme::~wxTheme()
155 {
156 }
157