]> git.saurik.com Git - wxWidgets.git/blame - src/common/appcmn.cpp
fixed linker errors
[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"
bf188f1a 33 #include "wx/intl.h"
e87271f3 34 #include "wx/list.h"
46446cc2 35 #include "wx/log.h"
e2478fde 36 #include "wx/msgdlg.h"
72cdf4c9
VZ
37#endif
38
e2478fde
VZ
39#include "wx/apptrait.h"
40#if wxUSE_FONTMAP
41 #include "wx/fontmap.h"
42#endif // wxUSE_FONTMAP
43#include "wx/msgout.h"
72cdf4c9 44#include "wx/thread.h"
bebc39e3 45#include "wx/utils.h"
a5f1fd3e 46
e2478fde
VZ
47// ============================================================================
48// wxAppBase implementation
49// ============================================================================
d54598dd 50
bf188f1a
VZ
51// ----------------------------------------------------------------------------
52// initialization and termination
53// ----------------------------------------------------------------------------
54
090a6d7a 55wxAppBase::wxAppBase()
697c5f51 56{
1e6feb95
VZ
57 m_topWindow = (wxWindow *)NULL;
58 m_useBestVisual = FALSE;
1e6feb95 59 m_isActive = TRUE;
1cbee0b4
VZ
60
61 // We don't want to exit the app if the user code shows a dialog from its
62 // OnInit() -- but this is what would happen if we set m_exitOnFrameDelete
63 // to Yes initially as this dialog would be the last top level window.
64 // OTOH, if we set it to No initially we'll have to overwrite it with Yes
65 // when we enter our OnRun() because we do want the default behaviour from
66 // then on. But this would be a problem if the user code calls
67 // SetExitOnFrameDelete(FALSE) from OnInit().
68 //
69 // So we use the special "Later" value which is such that
70 // GetExitOnFrameDelete() returns FALSE for it but which we know we can
71 // safely (i.e. without losing the effect of the users SetExitOnFrameDelete
72 // call) overwrite in OnRun()
73 m_exitOnFrameDelete = Later;
1e6feb95
VZ
74}
75
799ea011
GD
76wxAppBase::~wxAppBase()
77{
78 // this destructor is required for Darwin
79}
80
1e6feb95
VZ
81bool wxAppBase::OnInitGui()
82{
83#ifdef __WXUNIVERSAL__
bf188f1a 84 if ( !wxTheme::Get() && !wxTheme::CreateDefault() )
1e6feb95
VZ
85 return FALSE;
86#endif // __WXUNIVERSAL__
87
88 return TRUE;
89}
1e6feb95 90
1cbee0b4
VZ
91int wxAppBase::OnRun()
92{
93 // see the comment in ctor: if the initial value hasn't been changed, use
94 // the default Yes from now on
95 if ( m_exitOnFrameDelete == Later )
96 {
97 m_exitOnFrameDelete = Yes;
98 }
99 //else: it has been changed, assume the user knows what he is doing
100
101 return MainLoop();
102}
103
e2478fde 104void wxAppBase::Exit()
1e6feb95 105{
e2478fde 106 ExitMainLoop();
1e6feb95
VZ
107}
108
e2478fde 109wxAppTraits *wxAppBase::CreateTraits()
a69be60b 110{
e2478fde 111 return wxAppTraits::CreateGUI();
72cdf4c9
VZ
112}
113
1e6feb95
VZ
114// ----------------------------------------------------------------------------
115// misc
116// ----------------------------------------------------------------------------
117
6e169cf3 118void wxAppBase::SetActive(bool active, wxWindow * WXUNUSED(lastFocus))
7beba2fc 119{
66dfed9b
VZ
120 if ( active == m_isActive )
121 return;
122
1e6feb95 123 m_isActive = active;
66dfed9b
VZ
124
125 wxActivateEvent event(wxEVT_ACTIVATE_APP, active);
126 event.SetEventObject(this);
127
128 (void)ProcessEvent(event);
7beba2fc 129}
1e6feb95 130
bf188f1a 131// ----------------------------------------------------------------------------
e2478fde 132// wxGUIAppTraitsBase
bf188f1a
VZ
133// ----------------------------------------------------------------------------
134
bf188f1a 135#if wxUSE_LOG
bf188f1a 136
e2478fde
VZ
137wxLog *wxGUIAppTraitsBase::CreateLogTarget()
138{
139 return new wxLogGui;
bf188f1a
VZ
140}
141
bf188f1a
VZ
142#endif // wxUSE_LOG
143
e2478fde 144wxMessageOutput *wxGUIAppTraitsBase::CreateMessageOutput()
bf188f1a 145{
e2478fde
VZ
146 // The standard way of printing help on command line arguments (app --help)
147 // is (according to common practice):
148 // - console apps: to stderr (on any platform)
149 // - GUI apps: stderr on Unix platforms (!)
150 // message box under Windows and others
151#ifdef __UNIX__
152 return new wxMessageOutputStderr;
153#else // !__UNIX__
154 // wxMessageOutputMessageBox doesn't work under Motif
155 #ifdef __WXMOTIF__
156 return new wxMessageOutputLog;
157 #else
158 return new wxMessageOutputMessageBox;
159 #endif
160#endif // __UNIX__/!__UNIX__
bf188f1a
VZ
161}
162
e2478fde 163#if wxUSE_FONTMAP
bf188f1a 164
e2478fde
VZ
165wxFontMapper *wxGUIAppTraitsBase::CreateFontMapper()
166{
167 return new wxFontMapper;
bf188f1a
VZ
168}
169
e2478fde 170#endif // wxUSE_FONTMAP
bf188f1a 171
090a6d7a 172#ifdef __WXDEBUG__
e6e6fcc9 173
e2478fde
VZ
174bool wxGUIAppTraitsBase::ShowAssertDialog(const wxString& msg)
175{
176 // under MSW we prefer to use the base class version using ::MessageBox()
177 // even if wxMessageBox() is available because it has less chances to
178 // double fault our app than our wxMessageBox()
179#if defined(__WXMSW__) || !wxUSE_MSGDLG
180 return wxAppTraitsBase::ShowAssertDialog(msg);
181#else // wxUSE_MSGDLG
182 // this message is intentionally not translated -- it is for
183 // developpers only
184 wxString msgDlg(msg);
185 msgDlg += wxT("\nDo you want to stop the program?\n")
186 wxT("You can also choose [Cancel] to suppress ")
187 wxT("further warnings.");
188
189 switch ( wxMessageBox(msgDlg, wxT("wxWindows Debug Alert"),
190 wxYES_NO | wxCANCEL | wxICON_STOP ) )
191 {
192 case wxYES:
193 wxTrap();
194 break;
090a6d7a 195
e2478fde
VZ
196 case wxCANCEL:
197 // no more asserts
198 return true;
a5f1fd3e 199
e2478fde 200 //case wxNO: nothing to do
090a6d7a 201 }
090a6d7a 202
e2478fde
VZ
203 return false;
204#endif // !wxUSE_MSGDLG/wxUSE_MSGDLG
a5f1fd3e
VZ
205}
206
e2478fde
VZ
207#endif // __WXDEBUG__
208
209bool wxGUIAppTraitsBase::HasStderr()
a5f1fd3e 210{
e2478fde
VZ
211 // we consider that under Unix stderr always goes somewhere, even if the
212 // user doesn't always see it under GUI desktops
213#ifdef __UNIX__
214 return true;
a5f1fd3e 215#else
e2478fde 216 return false;
a5f1fd3e 217#endif
a5f1fd3e
VZ
218}
219
e2478fde 220void wxGUIAppTraitsBase::ScheduleForDestroy(wxObject *object)
a5f1fd3e 221{
e2478fde
VZ
222 if ( !wxPendingDelete.Member(object) )
223 wxPendingDelete.Append(object);
a5f1fd3e
VZ
224}
225
e2478fde 226void wxGUIAppTraitsBase::RemoveFromPendingDelete(wxObject *object)
a5f1fd3e 227{
e2478fde 228 wxPendingDelete.DeleteObject(object);
a5f1fd3e
VZ
229}
230
e2478fde
VZ
231// ----------------------------------------------------------------------------
232// wxAppTraits
233// ----------------------------------------------------------------------------
234
235wxAppTraits *wxAppTraitsBase::CreateGUI()
a5f1fd3e 236{
e2478fde 237 return new wxGUIAppTraits;
a5f1fd3e
VZ
238}
239