]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/univ/theme.cpp
Factor the brush selection out of OnPaint so it can be overridden in
[wxWidgets.git] / src / univ / theme.cpp
... / ...
CommitLineData
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
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 {
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#ifdef wxUNIV_DEFAULT_THEME
97 else // use native theme by default
98 {
99 nameDefTheme = wxSTRINGIZE_T(wxUNIV_DEFAULT_THEME);
100 }
101#endif // wxUNIV_DEFAULT_THEME
102
103 wxTheme *theme = Create(nameDefTheme);
104
105 // fallback to the first one in the list
106 if ( !theme && ms_allThemes )
107 {
108 theme = ms_allThemes->ctor();
109 }
110
111 // abort if still nothing
112 if ( !theme )
113 {
114 wxLogError(_("Failed to initialize GUI: no built-in themes found."));
115
116 return false;
117 }
118
119 // Set the theme as current.
120 wxTheme::Set(theme);
121
122 return true;
123}
124
125/* static */ wxTheme *wxTheme::Set(wxTheme *theme)
126{
127 wxTheme *themeOld = ms_theme;
128 ms_theme = theme;
129
130 if ( ms_theme )
131 {
132 // automatically start using the art provider of the new theme if it
133 // has one
134 wxArtProvider *art = ms_theme->GetArtProvider();
135 if ( art )
136 wxArtProvider::Push(art);
137 }
138
139 return themeOld;
140}
141
142// ----------------------------------------------------------------------------
143// assorted trivial dtors
144// ----------------------------------------------------------------------------
145
146wxTheme::~wxTheme()
147{
148}
149