]> git.saurik.com Git - wxWidgets.git/blob - src/common/appcmn.cpp
compilation fix
[wxWidgets.git] / src / common / appcmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/appcmn.cpp
3 // Purpose: wxAppConsole and 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"
33 #include "wx/intl.h"
34 #include "wx/list.h"
35 #include "wx/log.h"
36 #include "wx/msgdlg.h"
37 #endif
38
39 #include "wx/apptrait.h"
40 #if wxUSE_FONTMAP
41 #include "wx/fontmap.h"
42 #endif // wxUSE_FONTMAP
43 #include "wx/msgout.h"
44 #include "wx/thread.h"
45 #include "wx/utils.h"
46
47 // ============================================================================
48 // wxAppBase implementation
49 // ============================================================================
50
51 // ----------------------------------------------------------------------------
52 // initialization and termination
53 // ----------------------------------------------------------------------------
54
55 wxAppBase::wxAppBase()
56 {
57 m_topWindow = (wxWindow *)NULL;
58 m_useBestVisual = FALSE;
59 m_isActive = TRUE;
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;
74 }
75
76 wxAppBase::~wxAppBase()
77 {
78 // this destructor is required for Darwin
79 }
80
81 bool wxAppBase::OnInitGui()
82 {
83 #ifdef __WXUNIVERSAL__
84 if ( !wxTheme::Get() && !wxTheme::CreateDefault() )
85 return FALSE;
86 #endif // __WXUNIVERSAL__
87
88 return TRUE;
89 }
90
91 int 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
104 void wxAppBase::Exit()
105 {
106 ExitMainLoop();
107 }
108
109 wxAppTraits *wxAppBase::CreateTraits()
110 {
111 return wxAppTraits::CreateGUI();
112 }
113
114 // ----------------------------------------------------------------------------
115 // misc
116 // ----------------------------------------------------------------------------
117
118 void wxAppBase::SetActive(bool active, wxWindow * WXUNUSED(lastFocus))
119 {
120 if ( active == m_isActive )
121 return;
122
123 m_isActive = active;
124
125 wxActivateEvent event(wxEVT_ACTIVATE_APP, active);
126 event.SetEventObject(this);
127
128 (void)ProcessEvent(event);
129 }
130
131 // ----------------------------------------------------------------------------
132 // wxGUIAppTraitsBase
133 // ----------------------------------------------------------------------------
134
135 #if wxUSE_LOG
136
137 wxLog *wxGUIAppTraitsBase::CreateLogTarget()
138 {
139 return new wxLogGui;
140 }
141
142 #endif // wxUSE_LOG
143
144 wxMessageOutput *wxGUIAppTraitsBase::CreateMessageOutput()
145 {
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__
161 }
162
163 #if wxUSE_FONTMAP
164
165 wxFontMapper *wxGUIAppTraitsBase::CreateFontMapper()
166 {
167 return new wxFontMapper;
168 }
169
170 #endif // wxUSE_FONTMAP
171
172 #ifdef __WXDEBUG__
173
174 bool 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;
195
196 case wxCANCEL:
197 // no more asserts
198 return true;
199
200 //case wxNO: nothing to do
201 }
202
203 return false;
204 #endif // !wxUSE_MSGDLG/wxUSE_MSGDLG
205 }
206
207 #endif // __WXDEBUG__
208
209 bool wxGUIAppTraitsBase::HasStderr()
210 {
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;
215 #else
216 return false;
217 #endif
218 }
219
220 void wxGUIAppTraitsBase::ScheduleForDestroy(wxObject *object)
221 {
222 if ( !wxPendingDelete.Member(object) )
223 wxPendingDelete.Append(object);
224 }
225
226 void wxGUIAppTraitsBase::RemoveFromPendingDelete(wxObject *object)
227 {
228 wxPendingDelete.DeleteObject(object);
229 }
230
231 // ----------------------------------------------------------------------------
232 // wxAppTraits
233 // ----------------------------------------------------------------------------
234
235 wxAppTraits *wxAppTraitsBase::CreateGUI()
236 {
237 return new wxGUIAppTraits;
238 }
239