]> git.saurik.com Git - wxWidgets.git/blame - src/common/appcmn.cpp
fixed VC++ warning in release build
[wxWidgets.git] / src / common / appcmn.cpp
CommitLineData
72cdf4c9
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: common/appcmn.cpp
e2478fde 3// Purpose: wxAppConsole and wxAppBase methods common to all platforms
72cdf4c9
VZ
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"
b2e972ec 33 #include "wx/bitmap.h"
bf188f1a 34 #include "wx/intl.h"
e87271f3 35 #include "wx/list.h"
46446cc2 36 #include "wx/log.h"
e2478fde 37 #include "wx/msgdlg.h"
72cdf4c9
VZ
38#endif
39
e2478fde
VZ
40#include "wx/apptrait.h"
41#if wxUSE_FONTMAP
42 #include "wx/fontmap.h"
43#endif // wxUSE_FONTMAP
44#include "wx/msgout.h"
72cdf4c9 45#include "wx/thread.h"
bebc39e3 46#include "wx/utils.h"
a5f1fd3e 47
e2478fde
VZ
48// ============================================================================
49// wxAppBase implementation
50// ============================================================================
d54598dd 51
bf188f1a 52// ----------------------------------------------------------------------------
94826170 53// initialization
bf188f1a
VZ
54// ----------------------------------------------------------------------------
55
090a6d7a 56wxAppBase::wxAppBase()
697c5f51 57{
1e6feb95
VZ
58 m_topWindow = (wxWindow *)NULL;
59 m_useBestVisual = FALSE;
1e6feb95 60 m_isActive = TRUE;
1cbee0b4
VZ
61
62 // We don't want to exit the app if the user code shows a dialog from its
63 // OnInit() -- but this is what would happen if we set m_exitOnFrameDelete
64 // to Yes initially as this dialog would be the last top level window.
65 // OTOH, if we set it to No initially we'll have to overwrite it with Yes
66 // when we enter our OnRun() because we do want the default behaviour from
67 // then on. But this would be a problem if the user code calls
68 // SetExitOnFrameDelete(FALSE) from OnInit().
69 //
70 // So we use the special "Later" value which is such that
71 // GetExitOnFrameDelete() returns FALSE for it but which we know we can
72 // safely (i.e. without losing the effect of the users SetExitOnFrameDelete
73 // call) overwrite in OnRun()
74 m_exitOnFrameDelete = Later;
1e6feb95
VZ
75}
76
05e2b077 77bool wxAppBase::Initialize(int& argc, wxChar **argv)
94826170
VZ
78{
79 if ( !wxAppConsole::Initialize(argc, argv) )
80 return false;
81
94826170
VZ
82#if wxUSE_THREADS
83 wxPendingEventsLocker = new wxCriticalSection;
84#endif
85
86 wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
87 wxTheColourDatabase->Initialize();
88
89 wxInitializeStockLists();
90 wxInitializeStockObjects();
91
92 wxBitmap::InitStandardHandlers();
93
94 return true;
95}
96
97// ----------------------------------------------------------------------------
98// cleanup
99// ----------------------------------------------------------------------------
100
799ea011
GD
101wxAppBase::~wxAppBase()
102{
103 // this destructor is required for Darwin
104}
105
94826170
VZ
106void wxAppBase::CleanUp()
107{
108 // one last chance for pending objects to be cleaned up
109 DeletePendingObjects();
110
111 wxBitmap::CleanUpHandlers();
112
113 wxDeleteStockObjects();
114
115 wxDeleteStockLists();
116
117 delete wxTheColourDatabase;
118 wxTheColourDatabase = NULL;
119
120#if wxUSE_THREADS
121 delete wxPendingEvents;
122 wxPendingEvents = NULL;
123
124 delete wxPendingEventsLocker;
125 wxPendingEventsLocker = NULL;
126
127#if wxUSE_VALIDATORS
128 // If we don't do the following, we get an apparent memory leak.
129 ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker();
130#endif // wxUSE_VALIDATORS
131#endif // wxUSE_THREADS
132}
133
134// ----------------------------------------------------------------------------
135// OnXXX() hooks
136// ----------------------------------------------------------------------------
137
1e6feb95
VZ
138bool wxAppBase::OnInitGui()
139{
140#ifdef __WXUNIVERSAL__
bf188f1a 141 if ( !wxTheme::Get() && !wxTheme::CreateDefault() )
1e6feb95
VZ
142 return FALSE;
143#endif // __WXUNIVERSAL__
144
145 return TRUE;
146}
1e6feb95 147
1cbee0b4
VZ
148int wxAppBase::OnRun()
149{
150 // see the comment in ctor: if the initial value hasn't been changed, use
151 // the default Yes from now on
152 if ( m_exitOnFrameDelete == Later )
153 {
154 m_exitOnFrameDelete = Yes;
155 }
156 //else: it has been changed, assume the user knows what he is doing
157
158 return MainLoop();
159}
160
e2478fde 161void wxAppBase::Exit()
1e6feb95 162{
e2478fde 163 ExitMainLoop();
1e6feb95
VZ
164}
165
e2478fde 166wxAppTraits *wxAppBase::CreateTraits()
a69be60b 167{
e2478fde 168 return wxAppTraits::CreateGUI();
72cdf4c9
VZ
169}
170
1e6feb95
VZ
171// ----------------------------------------------------------------------------
172// misc
173// ----------------------------------------------------------------------------
174
6e169cf3 175void wxAppBase::SetActive(bool active, wxWindow * WXUNUSED(lastFocus))
7beba2fc 176{
66dfed9b
VZ
177 if ( active == m_isActive )
178 return;
179
1e6feb95 180 m_isActive = active;
66dfed9b
VZ
181
182 wxActivateEvent event(wxEVT_ACTIVATE_APP, active);
183 event.SetEventObject(this);
184
185 (void)ProcessEvent(event);
7beba2fc 186}
1e6feb95 187
94826170
VZ
188void wxAppBase::DeletePendingObjects()
189{
190 wxNode *node = wxPendingDelete.GetFirst();
191 while (node)
192 {
193 wxObject *obj = node->GetData();
194
195 delete obj;
196
197 if (wxPendingDelete.Member(obj))
198 delete node;
199
200 // Deleting one object may have deleted other pending
201 // objects, so start from beginning of list again.
202 node = wxPendingDelete.GetFirst();
203 }
204}
205
bf188f1a 206// ----------------------------------------------------------------------------
e2478fde 207// wxGUIAppTraitsBase
bf188f1a
VZ
208// ----------------------------------------------------------------------------
209
bf188f1a 210#if wxUSE_LOG
bf188f1a 211
e2478fde
VZ
212wxLog *wxGUIAppTraitsBase::CreateLogTarget()
213{
214 return new wxLogGui;
bf188f1a
VZ
215}
216
bf188f1a
VZ
217#endif // wxUSE_LOG
218
e2478fde 219wxMessageOutput *wxGUIAppTraitsBase::CreateMessageOutput()
bf188f1a 220{
e2478fde
VZ
221 // The standard way of printing help on command line arguments (app --help)
222 // is (according to common practice):
223 // - console apps: to stderr (on any platform)
224 // - GUI apps: stderr on Unix platforms (!)
225 // message box under Windows and others
226#ifdef __UNIX__
227 return new wxMessageOutputStderr;
228#else // !__UNIX__
229 // wxMessageOutputMessageBox doesn't work under Motif
230 #ifdef __WXMOTIF__
231 return new wxMessageOutputLog;
232 #else
233 return new wxMessageOutputMessageBox;
234 #endif
235#endif // __UNIX__/!__UNIX__
bf188f1a
VZ
236}
237
e2478fde 238#if wxUSE_FONTMAP
bf188f1a 239
e2478fde
VZ
240wxFontMapper *wxGUIAppTraitsBase::CreateFontMapper()
241{
242 return new wxFontMapper;
bf188f1a
VZ
243}
244
e2478fde 245#endif // wxUSE_FONTMAP
bf188f1a 246
090a6d7a 247#ifdef __WXDEBUG__
e6e6fcc9 248
e2478fde
VZ
249bool wxGUIAppTraitsBase::ShowAssertDialog(const wxString& msg)
250{
251 // under MSW we prefer to use the base class version using ::MessageBox()
252 // even if wxMessageBox() is available because it has less chances to
253 // double fault our app than our wxMessageBox()
254#if defined(__WXMSW__) || !wxUSE_MSGDLG
255 return wxAppTraitsBase::ShowAssertDialog(msg);
256#else // wxUSE_MSGDLG
257 // this message is intentionally not translated -- it is for
258 // developpers only
259 wxString msgDlg(msg);
260 msgDlg += wxT("\nDo you want to stop the program?\n")
261 wxT("You can also choose [Cancel] to suppress ")
262 wxT("further warnings.");
263
264 switch ( wxMessageBox(msgDlg, wxT("wxWindows Debug Alert"),
265 wxYES_NO | wxCANCEL | wxICON_STOP ) )
266 {
267 case wxYES:
268 wxTrap();
269 break;
090a6d7a 270
e2478fde
VZ
271 case wxCANCEL:
272 // no more asserts
273 return true;
a5f1fd3e 274
e2478fde 275 //case wxNO: nothing to do
090a6d7a 276 }
090a6d7a 277
e2478fde
VZ
278 return false;
279#endif // !wxUSE_MSGDLG/wxUSE_MSGDLG
a5f1fd3e
VZ
280}
281
e2478fde
VZ
282#endif // __WXDEBUG__
283
284bool wxGUIAppTraitsBase::HasStderr()
a5f1fd3e 285{
e2478fde
VZ
286 // we consider that under Unix stderr always goes somewhere, even if the
287 // user doesn't always see it under GUI desktops
288#ifdef __UNIX__
289 return true;
a5f1fd3e 290#else
e2478fde 291 return false;
a5f1fd3e 292#endif
a5f1fd3e
VZ
293}
294
e2478fde 295void wxGUIAppTraitsBase::ScheduleForDestroy(wxObject *object)
a5f1fd3e 296{
e2478fde
VZ
297 if ( !wxPendingDelete.Member(object) )
298 wxPendingDelete.Append(object);
a5f1fd3e
VZ
299}
300
e2478fde 301void wxGUIAppTraitsBase::RemoveFromPendingDelete(wxObject *object)
a5f1fd3e 302{
e2478fde 303 wxPendingDelete.DeleteObject(object);
a5f1fd3e
VZ
304}
305
e2478fde
VZ
306// ----------------------------------------------------------------------------
307// wxAppTraits
308// ----------------------------------------------------------------------------
309
310wxAppTraits *wxAppTraitsBase::CreateGUI()
a5f1fd3e 311{
e2478fde 312 return new wxGUIAppTraits;
a5f1fd3e
VZ
313}
314