]> git.saurik.com Git - wxWidgets.git/blame - src/univ/theme.cpp
todos, cleanups, detabified
[wxWidgets.git] / src / univ / theme.cpp
CommitLineData
1e6feb95
VZ
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$
442b35b5 8// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
65571936 9// Licence: wxWindows licence
1e6feb95
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
1e6feb95
VZ
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
815b393a
VZ
36#include "wx/artprov.h"
37
1e6feb95
VZ
38#include "wx/univ/renderer.h"
39#include "wx/univ/inphand.h"
40#include "wx/univ/theme.h"
41
42// ============================================================================
43// implementation
44// ============================================================================
45
46wxThemeInfo *wxTheme::ms_allThemes = (wxThemeInfo *)NULL;
47wxTheme *wxTheme::ms_theme = (wxTheme *)NULL;
48
49// ----------------------------------------------------------------------------
50// "dynamic" theme creation
51// ----------------------------------------------------------------------------
52
53wxThemeInfo::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 {
b8d5d8b8 69 if ( name.CmpNoCase(info->name) == 0 )
1e6feb95
VZ
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
a290fa5a 89 return true;
1e6feb95
VZ
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 {
43d611cb 102 #if defined(__WXGTK__)
1e6feb95 103 nameDefTheme = _T("gtk");
67d947ba 104 #elif defined(__WXX11__)
e4ba9eb2 105 nameDefTheme = _T("win32");
43d611cb 106 #else
19193a2c 107 nameDefTheme = _T("win32");
1e6feb95
VZ
108 #endif
109 }
110
815b393a 111 wxTheme *theme = Create(nameDefTheme);
1e6feb95
VZ
112
113 // fallback to the first one in the list
815b393a 114 if ( !theme && ms_allThemes )
1e6feb95 115 {
815b393a 116 theme = ms_allThemes->ctor();
1e6feb95
VZ
117 }
118
119 // abort if still nothing
815b393a 120 if ( !theme )
1e6feb95
VZ
121 {
122 wxLogError(_("Failed to initialize GUI: no built-in themes found."));
123
a290fa5a 124 return false;
1e6feb95
VZ
125 }
126
815b393a
VZ
127 // Set the theme as current.
128 wxTheme::Set(theme);
129
a290fa5a 130 return true;
1e6feb95
VZ
131}
132
133/* static */ wxTheme *wxTheme::Set(wxTheme *theme)
134{
135 wxTheme *themeOld = ms_theme;
136 ms_theme = theme;
815b393a
VZ
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
1e6feb95
VZ
147 return themeOld;
148}
149
150// ----------------------------------------------------------------------------
151// assorted trivial dtors
152// ----------------------------------------------------------------------------
153
154wxTheme::~wxTheme()
155{
156}
157