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