]>
Commit | Line | Data |
---|---|---|
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) |
1e6feb95 VZ |
9 | // Licence: wxWindows license |
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/univ/renderer.h" | |
37 | #include "wx/univ/inphand.h" | |
38 | #include "wx/univ/theme.h" | |
39 | ||
40 | // ============================================================================ | |
41 | // implementation | |
42 | // ============================================================================ | |
43 | ||
44 | wxThemeInfo *wxTheme::ms_allThemes = (wxThemeInfo *)NULL; | |
45 | wxTheme *wxTheme::ms_theme = (wxTheme *)NULL; | |
46 | ||
47 | // ---------------------------------------------------------------------------- | |
48 | // "dynamic" theme creation | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
51 | wxThemeInfo::wxThemeInfo(Constructor c, | |
52 | const wxChar *n, | |
53 | const wxChar *d) | |
54 | : name(n), desc(d), ctor(c) | |
55 | { | |
56 | // insert us (in the head of) the linked list | |
57 | next = wxTheme::ms_allThemes; | |
58 | wxTheme::ms_allThemes = this; | |
59 | } | |
60 | ||
61 | /* static */ wxTheme *wxTheme::Create(const wxString& name) | |
62 | { | |
63 | // find the theme in the list by name | |
64 | wxThemeInfo *info = ms_allThemes; | |
65 | while ( info ) | |
66 | { | |
67 | if ( name == info->name ) | |
68 | { | |
69 | return info->ctor(); | |
70 | } | |
71 | ||
72 | info = info->next; | |
73 | } | |
74 | ||
75 | return (wxTheme *)NULL; | |
76 | } | |
77 | ||
78 | // ---------------------------------------------------------------------------- | |
79 | // the default theme (called by wxApp::OnInitGui) | |
80 | // ---------------------------------------------------------------------------- | |
81 | ||
82 | /* static */ bool wxTheme::CreateDefault() | |
83 | { | |
84 | if ( ms_theme ) | |
85 | { | |
86 | // we already have a theme | |
87 | return TRUE; | |
88 | } | |
89 | ||
90 | wxString nameDefTheme; | |
91 | ||
92 | // use the environment variable first | |
93 | const wxChar *p = wxGetenv(_T("WXTHEME")); | |
94 | if ( p ) | |
95 | { | |
96 | nameDefTheme = p; | |
97 | } | |
98 | else // use native theme by default | |
99 | { | |
100 | #if defined(__WXMSW__) | |
101 | nameDefTheme = _T("win32"); | |
102 | #elif defined(__WXGTK__) | |
103 | nameDefTheme = _T("gtk"); | |
104 | #endif | |
105 | } | |
106 | ||
107 | ms_theme = Create(nameDefTheme); | |
108 | ||
109 | // fallback to the first one in the list | |
110 | if ( !ms_theme && ms_allThemes ) | |
111 | { | |
112 | ms_theme = ms_allThemes->ctor(); | |
113 | } | |
114 | ||
115 | // abort if still nothing | |
116 | if ( !ms_theme ) | |
117 | { | |
118 | wxLogError(_("Failed to initialize GUI: no built-in themes found.")); | |
119 | ||
120 | return FALSE; | |
121 | } | |
122 | ||
123 | return TRUE; | |
124 | } | |
125 | ||
126 | /* static */ wxTheme *wxTheme::Set(wxTheme *theme) | |
127 | { | |
128 | wxTheme *themeOld = ms_theme; | |
129 | ms_theme = theme; | |
130 | return themeOld; | |
131 | } | |
132 | ||
133 | // ---------------------------------------------------------------------------- | |
134 | // assorted trivial dtors | |
135 | // ---------------------------------------------------------------------------- | |
136 | ||
137 | wxTheme::~wxTheme() | |
138 | { | |
139 | } | |
140 |