]> git.saurik.com Git - wxWidgets.git/blame - src/univ/theme.cpp
Removed wxLogNull's used to supress errors coming from
[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
1e6feb95
VZ
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
815b393a
VZ
32#include "wx/artprov.h"
33
1e6feb95
VZ
34#include "wx/univ/renderer.h"
35#include "wx/univ/inphand.h"
36#include "wx/univ/theme.h"
37
38// ============================================================================
39// implementation
40// ============================================================================
41
42wxThemeInfo *wxTheme::ms_allThemes = (wxThemeInfo *)NULL;
43wxTheme *wxTheme::ms_theme = (wxTheme *)NULL;
44
45// ----------------------------------------------------------------------------
46// "dynamic" theme creation
47// ----------------------------------------------------------------------------
48
49wxThemeInfo::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 {
b8d5d8b8 65 if ( name.CmpNoCase(info->name) == 0 )
1e6feb95
VZ
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
a290fa5a 85 return true;
1e6feb95
VZ
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 {
43d611cb 98 #if defined(__WXGTK__)
1e6feb95 99 nameDefTheme = _T("gtk");
67d947ba 100 #elif defined(__WXX11__)
e4ba9eb2 101 nameDefTheme = _T("win32");
43d611cb 102 #else
19193a2c 103 nameDefTheme = _T("win32");
1e6feb95
VZ
104 #endif
105 }
106
815b393a 107 wxTheme *theme = Create(nameDefTheme);
1e6feb95
VZ
108
109 // fallback to the first one in the list
815b393a 110 if ( !theme && ms_allThemes )
1e6feb95 111 {
815b393a 112 theme = ms_allThemes->ctor();
1e6feb95
VZ
113 }
114
115 // abort if still nothing
815b393a 116 if ( !theme )
1e6feb95
VZ
117 {
118 wxLogError(_("Failed to initialize GUI: no built-in themes found."));
119
a290fa5a 120 return false;
1e6feb95
VZ
121 }
122
815b393a
VZ
123 // Set the theme as current.
124 wxTheme::Set(theme);
125
a290fa5a 126 return true;
1e6feb95
VZ
127}
128
129/* static */ wxTheme *wxTheme::Set(wxTheme *theme)
130{
131 wxTheme *themeOld = ms_theme;
132 ms_theme = theme;
815b393a
VZ
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
1e6feb95
VZ
143 return themeOld;
144}
145
146// ----------------------------------------------------------------------------
147// assorted trivial dtors
148// ----------------------------------------------------------------------------
149
150wxTheme::~wxTheme()
151{
152}
153