]> git.saurik.com Git - wxWidgets.git/blame - src/common/appcmn.cpp
added wxLogChain and wxLogPassThrough classes
[wxWidgets.git] / src / common / appcmn.cpp
CommitLineData
72cdf4c9
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: common/appcmn.cpp
3// Purpose: wxAppBase methods common to all platforms
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 18.10.99
7// RCS-ID: $Id$
8// Copyright: (c) Vadim Zeitlin
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
20#ifdef __GNUG__
21 #pragma implementation "appbase.h"
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#if defined(__BORLANDC__)
28 #pragma hdrstop
29#endif
30
31#ifndef WX_PRECOMP
32 #include "wx/app.h"
bf188f1a 33 #include "wx/intl.h"
e87271f3 34 #include "wx/list.h"
72cdf4c9
VZ
35#endif
36
bf188f1a 37#include "wx/cmdline.h"
72cdf4c9 38#include "wx/thread.h"
7beba2fc 39#include "wx/confbase.h"
e1ee679c 40
d54598dd
VZ
41// ===========================================================================
42// implementation
43// ===========================================================================
44
bf188f1a
VZ
45// ----------------------------------------------------------------------------
46// initialization and termination
47// ----------------------------------------------------------------------------
48
1e6feb95
VZ
49wxAppBase::wxAppBase()
50{
51 wxTheApp = (wxApp *)this;
52
53 // VZ: what's this? is it obsolete?
54 m_wantDebugOutput = FALSE;
55
56#if wxUSE_GUI
57 m_topWindow = (wxWindow *)NULL;
58 m_useBestVisual = FALSE;
59 m_exitOnFrameDelete = TRUE;
60 m_isActive = TRUE;
61#endif // wxUSE_GUI
62}
63
1e6feb95
VZ
64#if wxUSE_GUI
65bool wxAppBase::OnInitGui()
66{
67#ifdef __WXUNIVERSAL__
bf188f1a 68 if ( !wxTheme::Get() && !wxTheme::CreateDefault() )
1e6feb95
VZ
69 return FALSE;
70#endif // __WXUNIVERSAL__
71
72 return TRUE;
73}
74#endif // wxUSE_GUI
75
76int wxAppBase::OnExit()
77{
78#if wxUSE_CONFIG
79 // delete the config object if any (don't use Get() here, but Set()
80 // because Get() could create a new config object)
81 delete wxConfigBase::Set((wxConfigBase *) NULL);
82#endif // wxUSE_CONFIG
83
84#ifdef __WXUNIVERSAL__
85 delete wxTheme::Set(NULL);
86#endif // __WXUNIVERSAL__
87
88 return 0;
89}
90
72cdf4c9
VZ
91// ---------------------------------------------------------------------------
92// wxAppBase
93// ----------------------------------------------------------------------------
94
95void wxAppBase::ProcessPendingEvents()
96{
97 // ensure that we're the only thread to modify the pending events list
16c1f79c 98 wxENTER_CRIT_SECT( *wxPendingEventsLocker );
72cdf4c9
VZ
99
100 if ( !wxPendingEvents )
16c1f79c
RR
101 {
102 wxLEAVE_CRIT_SECT( *wxPendingEventsLocker );
72cdf4c9 103 return;
16c1f79c 104 }
72cdf4c9
VZ
105
106 // iterate until the list becomes empty
107 wxNode *node = wxPendingEvents->First();
108 while (node)
109 {
110 wxEvtHandler *handler = (wxEvtHandler *)node->Data();
16c1f79c 111 delete node;
72cdf4c9 112
16c1f79c 113 // In ProcessPendingEvents(), new handlers might be add
1d910ac1 114 // and we can safely leave the critical section here.
16c1f79c 115 wxLEAVE_CRIT_SECT( *wxPendingEventsLocker );
72cdf4c9 116 handler->ProcessPendingEvents();
16c1f79c 117 wxENTER_CRIT_SECT( *wxPendingEventsLocker );
72cdf4c9 118
72cdf4c9
VZ
119 node = wxPendingEvents->First();
120 }
1d910ac1 121
16c1f79c 122 wxLEAVE_CRIT_SECT( *wxPendingEventsLocker );
72cdf4c9
VZ
123}
124
1e6feb95
VZ
125// ----------------------------------------------------------------------------
126// misc
127// ----------------------------------------------------------------------------
128
129#if wxUSE_GUI
130
6e169cf3 131void wxAppBase::SetActive(bool active, wxWindow * WXUNUSED(lastFocus))
7beba2fc 132{
1e6feb95 133 m_isActive = active;
7beba2fc 134}
1e6feb95
VZ
135
136#endif // wxUSE_GUI
bf188f1a
VZ
137
138// ----------------------------------------------------------------------------
139// cmd line parsing
140// ----------------------------------------------------------------------------
141
142bool wxAppBase::OnInit()
143{
144#if wxUSE_CMDLINE_PARSER
145 wxCmdLineParser parser(argc, argv);
146
147 OnInitCmdLine(parser);
148
149 bool cont;
150 switch ( parser.Parse() )
151 {
152 case -1:
153 cont = OnCmdLineHelp(parser);
154 break;
155
156 case 0:
157 cont = OnCmdLineParsed(parser);
158 break;
159
160 default:
161 cont = OnCmdLineError(parser);
162 break;
163 }
164
165 if ( !cont )
166 return FALSE;
167#endif // wxUSE_CMDLINE_PARSER
168
169 return TRUE;
170}
171
172#if wxUSE_CMDLINE_PARSER
173
174#define OPTION_VERBOSE _T("verbose")
175#define OPTION_THEME _T("theme")
176
177void wxAppBase::OnInitCmdLine(wxCmdLineParser& parser)
178{
179 // the standard command line options
180 static const wxCmdLineEntryDesc cmdLineDesc[] =
181 {
182 {
183 wxCMD_LINE_SWITCH,
184 _T("h"),
185 _T("help"),
186 gettext_noop("show this help message"),
187 wxCMD_LINE_VAL_NONE,
188 wxCMD_LINE_OPTION_HELP
189 },
190
191#if wxUSE_LOG
192 {
193 wxCMD_LINE_SWITCH,
194 _T(""),
195 OPTION_VERBOSE,
196 gettext_noop("generate verbose log messages")
197 },
198#endif wxUSE_LOG
199
200#ifdef __WXUNIVERSAL__
201 {
202 wxCMD_LINE_OPTION,
203 _T(""),
204 OPTION_THEME,
205 gettext_noop("specify the theme to use"),
206 wxCMD_LINE_VAL_STRING
207 },
208#endif // __WXUNIVERSAL__
209
210 // terminator
211 { wxCMD_LINE_NONE }
212 };
213
214 parser.SetDesc(cmdLineDesc);
215}
216
217bool wxAppBase::OnCmdLineParsed(wxCmdLineParser& parser)
218{
219#if wxUSE_LOG
220 if ( parser.Found(OPTION_VERBOSE) )
221 {
222 wxLog::SetVerbose(TRUE);
223 }
224#endif // wxUSE_LOG
225
226#ifdef __WXUNIVERSAL__
227 wxString themeName;
228 if ( parser.Found(OPTION_THEME, &themeName) )
229 {
230 wxTheme *theme = wxTheme::Create(themeName);
231 if ( !theme )
232 {
233 wxLogError(_("Unsupported theme '%s'."), themeName.c_str());
234
235 return FALSE;
236 }
237
238 wxTheme::Set(theme);
239 }
240#endif // __WXUNIVERSAL__
241
242 return TRUE;
243}
244
245bool wxAppBase::OnCmdLineHelp(wxCmdLineParser& parser)
246{
247 parser.Usage();
248
249 return FALSE;
250}
251
252bool wxAppBase::OnCmdLineError(wxCmdLineParser& parser)
253{
254 parser.Usage();
255
256 return FALSE;
257}
258
259#endif // wxUSE_CMDLINE_PARSER
260