]>
Commit | Line | Data |
---|---|---|
72cdf4c9 | 1 | ///////////////////////////////////////////////////////////////////////////// |
127eab18 | 2 | // Name: src/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 | |
65571936 | 9 | // Licence: wxWindows licence |
72cdf4c9 VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
72cdf4c9 VZ |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #if defined(__BORLANDC__) | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #ifndef WX_PRECOMP | |
28 | #include "wx/app.h" | |
5ff14574 | 29 | #include "wx/window.h" |
b2e972ec | 30 | #include "wx/bitmap.h" |
46446cc2 | 31 | #include "wx/log.h" |
e2478fde | 32 | #include "wx/msgdlg.h" |
b3dfbbc9 | 33 | #include "wx/confbase.h" |
de6185e2 | 34 | #include "wx/utils.h" |
193d0c93 | 35 | #include "wx/wxcrtvararg.h" |
72cdf4c9 VZ |
36 | #endif |
37 | ||
e2478fde | 38 | #include "wx/apptrait.h" |
b913d3ed | 39 | #include "wx/cmdline.h" |
1bf77ee5 | 40 | #include "wx/evtloop.h" |
e2478fde | 41 | #include "wx/msgout.h" |
72cdf4c9 | 42 | #include "wx/thread.h" |
5ff14574 | 43 | #include "wx/vidmode.h" |
1bf77ee5 | 44 | #include "wx/ptr_scpd.h" |
a5f1fd3e | 45 | |
db9febdf RR |
46 | #ifdef __WXDEBUG__ |
47 | #if wxUSE_STACKWALKER | |
48 | #include "wx/stackwalk.h" | |
49 | #endif // wxUSE_STACKWALKER | |
50 | #endif // __WXDEBUG__ | |
51 | ||
82ef81ed WS |
52 | #if defined(__WXMSW__) |
53 | #include "wx/msw/private.h" // includes windows.h for LOGFONT | |
1c193821 JS |
54 | #endif |
55 | ||
56 | #if wxUSE_FONTMAP | |
57 | #include "wx/fontmap.h" | |
58 | #endif // wxUSE_FONTMAP | |
59 | ||
34fdf762 VS |
60 | // DLL options compatibility check: |
61 | #include "wx/build.h" | |
62 | WX_CHECK_BUILD_OPTIONS("wxCore") | |
63 | ||
e7445ff8 | 64 | WXDLLIMPEXP_DATA_CORE(wxList) wxPendingDelete; |
1bf77ee5 VZ |
65 | |
66 | // ---------------------------------------------------------------------------- | |
67 | // wxEventLoopPtr | |
68 | // ---------------------------------------------------------------------------- | |
69 | ||
70 | // this defines wxEventLoopPtr | |
259c43f6 | 71 | wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoop) |
1bf77ee5 | 72 | |
e2478fde VZ |
73 | // ============================================================================ |
74 | // wxAppBase implementation | |
75 | // ============================================================================ | |
d54598dd | 76 | |
bf188f1a | 77 | // ---------------------------------------------------------------------------- |
94826170 | 78 | // initialization |
bf188f1a VZ |
79 | // ---------------------------------------------------------------------------- |
80 | ||
090a6d7a | 81 | wxAppBase::wxAppBase() |
697c5f51 | 82 | { |
1e6feb95 | 83 | m_topWindow = (wxWindow *)NULL; |
515a31bf | 84 | |
4629016d | 85 | m_useBestVisual = false; |
515a31bf RR |
86 | m_forceTrueColour = false; |
87 | ||
4629016d | 88 | m_isActive = true; |
1cbee0b4 | 89 | |
1bf77ee5 VZ |
90 | m_mainLoop = NULL; |
91 | ||
1cbee0b4 VZ |
92 | // We don't want to exit the app if the user code shows a dialog from its |
93 | // OnInit() -- but this is what would happen if we set m_exitOnFrameDelete | |
94 | // to Yes initially as this dialog would be the last top level window. | |
95 | // OTOH, if we set it to No initially we'll have to overwrite it with Yes | |
96 | // when we enter our OnRun() because we do want the default behaviour from | |
97 | // then on. But this would be a problem if the user code calls | |
4629016d | 98 | // SetExitOnFrameDelete(false) from OnInit(). |
1cbee0b4 VZ |
99 | // |
100 | // So we use the special "Later" value which is such that | |
4629016d | 101 | // GetExitOnFrameDelete() returns false for it but which we know we can |
1cbee0b4 VZ |
102 | // safely (i.e. without losing the effect of the users SetExitOnFrameDelete |
103 | // call) overwrite in OnRun() | |
104 | m_exitOnFrameDelete = Later; | |
1e6feb95 VZ |
105 | } |
106 | ||
a54930e0 | 107 | bool wxAppBase::Initialize(int& argcOrig, wxChar **argvOrig) |
94826170 | 108 | { |
a54930e0 | 109 | if ( !wxAppConsole::Initialize(argcOrig, argvOrig) ) |
94826170 VZ |
110 | return false; |
111 | ||
94826170 VZ |
112 | #if wxUSE_THREADS |
113 | wxPendingEventsLocker = new wxCriticalSection; | |
114 | #endif | |
115 | ||
94826170 | 116 | wxInitializeStockLists(); |
94826170 VZ |
117 | |
118 | wxBitmap::InitStandardHandlers(); | |
119 | ||
120 | return true; | |
121 | } | |
122 | ||
123 | // ---------------------------------------------------------------------------- | |
124 | // cleanup | |
125 | // ---------------------------------------------------------------------------- | |
126 | ||
799ea011 GD |
127 | wxAppBase::~wxAppBase() |
128 | { | |
129 | // this destructor is required for Darwin | |
130 | } | |
131 | ||
94826170 VZ |
132 | void wxAppBase::CleanUp() |
133 | { | |
07460370 | 134 | // clean up all the pending objects |
94826170 VZ |
135 | DeletePendingObjects(); |
136 | ||
07460370 VZ |
137 | // and any remaining TLWs (they remove themselves from wxTopLevelWindows |
138 | // when destroyed, so iterate until none are left) | |
139 | while ( !wxTopLevelWindows.empty() ) | |
140 | { | |
141 | // do not use Destroy() here as it only puts the TLW in pending list | |
142 | // but we want to delete them now | |
143 | delete wxTopLevelWindows.GetFirst()->GetData(); | |
144 | } | |
4055ed82 | 145 | |
07460370 | 146 | // undo everything we did in Initialize() above |
94826170 VZ |
147 | wxBitmap::CleanUpHandlers(); |
148 | ||
f516d986 | 149 | wxStockGDI::DeleteAll(); |
94826170 VZ |
150 | |
151 | wxDeleteStockLists(); | |
152 | ||
153 | delete wxTheColourDatabase; | |
154 | wxTheColourDatabase = NULL; | |
155 | ||
94826170 VZ |
156 | delete wxPendingEvents; |
157 | wxPendingEvents = NULL; | |
158 | ||
c8b1e804 | 159 | #if wxUSE_THREADS |
94826170 VZ |
160 | delete wxPendingEventsLocker; |
161 | wxPendingEventsLocker = NULL; | |
162 | ||
b913d3ed VZ |
163 | #if wxUSE_VALIDATORS |
164 | // If we don't do the following, we get an apparent memory leak. | |
165 | ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker(); | |
166 | #endif // wxUSE_VALIDATORS | |
94826170 VZ |
167 | #endif // wxUSE_THREADS |
168 | } | |
169 | ||
475a93b7 VZ |
170 | // ---------------------------------------------------------------------------- |
171 | // various accessors | |
5ff14574 PC |
172 | // ---------------------------------------------------------------------------- |
173 | ||
174 | wxWindow* wxAppBase::GetTopWindow() const | |
175 | { | |
176 | wxWindow* window = m_topWindow; | |
177 | if (window == NULL && wxTopLevelWindows.GetCount() > 0) | |
178 | window = wxTopLevelWindows.GetFirst()->GetData(); | |
179 | return window; | |
180 | } | |
181 | ||
182 | wxVideoMode wxAppBase::GetDisplayMode() const | |
183 | { | |
184 | return wxVideoMode(); | |
185 | } | |
186 | ||
475a93b7 VZ |
187 | wxLayoutDirection wxAppBase::GetLayoutDirection() const |
188 | { | |
189 | #if wxUSE_INTL | |
190 | const wxLocale *const locale = wxGetLocale(); | |
191 | if ( locale ) | |
192 | { | |
193 | const wxLanguageInfo *const | |
194 | info = wxLocale::GetLanguageInfo(locale->GetLanguage()); | |
195 | ||
196 | if ( info ) | |
197 | return info->LayoutDirection; | |
198 | } | |
199 | #endif // wxUSE_INTL | |
200 | ||
201 | // we don't know | |
202 | return wxLayout_Default; | |
203 | } | |
204 | ||
b913d3ed VZ |
205 | #if wxUSE_CMDLINE_PARSER |
206 | ||
207 | // ---------------------------------------------------------------------------- | |
208 | // GUI-specific command line options handling | |
209 | // ---------------------------------------------------------------------------- | |
210 | ||
211 | #define OPTION_THEME _T("theme") | |
212 | #define OPTION_MODE _T("mode") | |
213 | ||
214 | void wxAppBase::OnInitCmdLine(wxCmdLineParser& parser) | |
215 | { | |
9c13e5ef VZ |
216 | // first add the standard non GUI options |
217 | wxAppConsole::OnInitCmdLine(parser); | |
218 | ||
b913d3ed VZ |
219 | // the standard command line options |
220 | static const wxCmdLineEntryDesc cmdLineGUIDesc[] = | |
221 | { | |
222 | #ifdef __WXUNIVERSAL__ | |
223 | { | |
224 | wxCMD_LINE_OPTION, | |
b494c48b | 225 | wxEmptyString, |
b913d3ed VZ |
226 | OPTION_THEME, |
227 | gettext_noop("specify the theme to use"), | |
228 | wxCMD_LINE_VAL_STRING, | |
229 | 0x0 | |
230 | }, | |
231 | #endif // __WXUNIVERSAL__ | |
232 | ||
233 | #if defined(__WXMGL__) | |
234 | // VS: this is not specific to wxMGL, all fullscreen (framebuffer) ports | |
235 | // should provide this option. That's why it is in common/appcmn.cpp | |
236 | // and not mgl/app.cpp | |
237 | { | |
238 | wxCMD_LINE_OPTION, | |
b494c48b | 239 | wxEmptyString, |
b913d3ed VZ |
240 | OPTION_MODE, |
241 | gettext_noop("specify display mode to use (e.g. 640x480-16)"), | |
242 | wxCMD_LINE_VAL_STRING, | |
243 | 0x0 | |
244 | }, | |
245 | #endif // __WXMGL__ | |
246 | ||
247 | // terminator | |
248 | { | |
249 | wxCMD_LINE_NONE, | |
b494c48b WS |
250 | wxEmptyString, |
251 | wxEmptyString, | |
252 | wxEmptyString, | |
b913d3ed VZ |
253 | wxCMD_LINE_VAL_NONE, |
254 | 0x0 | |
255 | } | |
256 | }; | |
257 | ||
258 | parser.SetDesc(cmdLineGUIDesc); | |
259 | } | |
260 | ||
261 | bool wxAppBase::OnCmdLineParsed(wxCmdLineParser& parser) | |
262 | { | |
263 | #ifdef __WXUNIVERSAL__ | |
264 | wxString themeName; | |
265 | if ( parser.Found(OPTION_THEME, &themeName) ) | |
266 | { | |
267 | wxTheme *theme = wxTheme::Create(themeName); | |
268 | if ( !theme ) | |
269 | { | |
270 | wxLogError(_("Unsupported theme '%s'."), themeName.c_str()); | |
4629016d | 271 | return false; |
b913d3ed VZ |
272 | } |
273 | ||
274 | // Delete the defaultly created theme and set the new theme. | |
275 | delete wxTheme::Get(); | |
276 | wxTheme::Set(theme); | |
277 | } | |
278 | #endif // __WXUNIVERSAL__ | |
279 | ||
280 | #if defined(__WXMGL__) | |
281 | wxString modeDesc; | |
282 | if ( parser.Found(OPTION_MODE, &modeDesc) ) | |
283 | { | |
284 | unsigned w, h, bpp; | |
285 | if ( wxSscanf(modeDesc.c_str(), _T("%ux%u-%u"), &w, &h, &bpp) != 3 ) | |
286 | { | |
287 | wxLogError(_("Invalid display mode specification '%s'."), modeDesc.c_str()); | |
4629016d | 288 | return false; |
b913d3ed VZ |
289 | } |
290 | ||
1c53456f | 291 | if ( !SetDisplayMode(wxVideoMode(w, h, bpp)) ) |
4629016d | 292 | return false; |
b913d3ed VZ |
293 | } |
294 | #endif // __WXMGL__ | |
295 | ||
296 | return wxAppConsole::OnCmdLineParsed(parser); | |
297 | } | |
298 | ||
299 | #endif // wxUSE_CMDLINE_PARSER | |
300 | ||
1bf77ee5 VZ |
301 | // ---------------------------------------------------------------------------- |
302 | // main event loop implementation | |
303 | // ---------------------------------------------------------------------------- | |
304 | ||
305 | int wxAppBase::MainLoop() | |
306 | { | |
efbfda9d | 307 | wxEventLoopTiedPtr mainLoop(&m_mainLoop, new wxEventLoop); |
1bf77ee5 VZ |
308 | |
309 | return m_mainLoop->Run(); | |
310 | } | |
311 | ||
312 | void wxAppBase::ExitMainLoop() | |
313 | { | |
314 | // we should exit from the main event loop, not just any currently active | |
315 | // (e.g. modal dialog) event loop | |
dd435a79 | 316 | if ( m_mainLoop && m_mainLoop->IsRunning() ) |
1bf77ee5 VZ |
317 | { |
318 | m_mainLoop->Exit(0); | |
319 | } | |
320 | } | |
321 | ||
322 | bool wxAppBase::Pending() | |
323 | { | |
324 | // use the currently active message loop here, not m_mainLoop, because if | |
325 | // we're showing a modal dialog (with its own event loop) currently the | |
326 | // main event loop is not running anyhow | |
327 | wxEventLoop * const loop = wxEventLoop::GetActive(); | |
328 | ||
329 | return loop && loop->Pending(); | |
330 | } | |
331 | ||
332 | bool wxAppBase::Dispatch() | |
333 | { | |
334 | // see comment in Pending() | |
335 | wxEventLoop * const loop = wxEventLoop::GetActive(); | |
336 | ||
d1fc6f06 | 337 | return loop && loop->Dispatch(); |
1bf77ee5 VZ |
338 | } |
339 | ||
94826170 VZ |
340 | // ---------------------------------------------------------------------------- |
341 | // OnXXX() hooks | |
342 | // ---------------------------------------------------------------------------- | |
343 | ||
1e6feb95 VZ |
344 | bool wxAppBase::OnInitGui() |
345 | { | |
346 | #ifdef __WXUNIVERSAL__ | |
bf188f1a | 347 | if ( !wxTheme::Get() && !wxTheme::CreateDefault() ) |
4629016d | 348 | return false; |
1e6feb95 VZ |
349 | #endif // __WXUNIVERSAL__ |
350 | ||
4629016d | 351 | return true; |
1e6feb95 | 352 | } |
1e6feb95 | 353 | |
1cbee0b4 VZ |
354 | int wxAppBase::OnRun() |
355 | { | |
356 | // see the comment in ctor: if the initial value hasn't been changed, use | |
357 | // the default Yes from now on | |
358 | if ( m_exitOnFrameDelete == Later ) | |
359 | { | |
360 | m_exitOnFrameDelete = Yes; | |
361 | } | |
362 | //else: it has been changed, assume the user knows what he is doing | |
363 | ||
364 | return MainLoop(); | |
365 | } | |
366 | ||
b913d3ed VZ |
367 | int wxAppBase::OnExit() |
368 | { | |
369 | #ifdef __WXUNIVERSAL__ | |
370 | delete wxTheme::Set(NULL); | |
371 | #endif // __WXUNIVERSAL__ | |
372 | ||
373 | return wxAppConsole::OnExit(); | |
374 | } | |
375 | ||
e2478fde | 376 | void wxAppBase::Exit() |
1e6feb95 | 377 | { |
e2478fde | 378 | ExitMainLoop(); |
1e6feb95 VZ |
379 | } |
380 | ||
e2478fde | 381 | wxAppTraits *wxAppBase::CreateTraits() |
a69be60b | 382 | { |
7843d11b | 383 | return new wxGUIAppTraits; |
72cdf4c9 VZ |
384 | } |
385 | ||
1e6feb95 VZ |
386 | // ---------------------------------------------------------------------------- |
387 | // misc | |
388 | // ---------------------------------------------------------------------------- | |
389 | ||
6e169cf3 | 390 | void wxAppBase::SetActive(bool active, wxWindow * WXUNUSED(lastFocus)) |
7beba2fc | 391 | { |
66dfed9b VZ |
392 | if ( active == m_isActive ) |
393 | return; | |
394 | ||
1e6feb95 | 395 | m_isActive = active; |
66dfed9b VZ |
396 | |
397 | wxActivateEvent event(wxEVT_ACTIVATE_APP, active); | |
398 | event.SetEventObject(this); | |
399 | ||
400 | (void)ProcessEvent(event); | |
7beba2fc | 401 | } |
1e6feb95 | 402 | |
2dc62891 VZ |
403 | // ---------------------------------------------------------------------------- |
404 | // idle handling | |
405 | // ---------------------------------------------------------------------------- | |
406 | ||
94826170 VZ |
407 | void wxAppBase::DeletePendingObjects() |
408 | { | |
222ed1d6 | 409 | wxList::compatibility_iterator node = wxPendingDelete.GetFirst(); |
94826170 VZ |
410 | while (node) |
411 | { | |
412 | wxObject *obj = node->GetData(); | |
413 | ||
73865dad VZ |
414 | // remove it from the list first so that if we get back here somehow |
415 | // during the object deletion (e.g. wxYield called from its dtor) we | |
416 | // wouldn't try to delete it the second time | |
417 | if ( wxPendingDelete.Member(obj) ) | |
222ed1d6 | 418 | wxPendingDelete.Erase(node); |
94826170 | 419 | |
73865dad VZ |
420 | delete obj; |
421 | ||
94826170 VZ |
422 | // Deleting one object may have deleted other pending |
423 | // objects, so start from beginning of list again. | |
424 | node = wxPendingDelete.GetFirst(); | |
425 | } | |
426 | } | |
427 | ||
4629016d | 428 | // Returns true if more time is needed. |
e39af974 JS |
429 | bool wxAppBase::ProcessIdle() |
430 | { | |
5109ae5d | 431 | wxIdleEvent event; |
4629016d | 432 | bool needMore = false; |
222ed1d6 | 433 | wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst(); |
e39af974 JS |
434 | while (node) |
435 | { | |
436 | wxWindow* win = node->GetData(); | |
5109ae5d | 437 | if (SendIdleEvents(win, event)) |
4629016d | 438 | needMore = true; |
e39af974 JS |
439 | node = node->GetNext(); |
440 | } | |
441 | ||
e39af974 | 442 | event.SetEventObject(this); |
5109ae5d JS |
443 | (void) ProcessEvent(event); |
444 | if (event.MoreRequested()) | |
4629016d | 445 | needMore = true; |
e39af974 JS |
446 | |
447 | wxUpdateUIEvent::ResetUpdateTime(); | |
4629016d | 448 | |
5109ae5d | 449 | return needMore; |
e39af974 JS |
450 | } |
451 | ||
e39af974 | 452 | // Send idle event to window and all subwindows |
5109ae5d | 453 | bool wxAppBase::SendIdleEvents(wxWindow* win, wxIdleEvent& event) |
e39af974 | 454 | { |
4629016d | 455 | bool needMore = false; |
42d11c8e | 456 | |
5109ae5d | 457 | win->OnInternalIdle(); |
42d11c8e | 458 | |
e39af974 JS |
459 | if (wxIdleEvent::CanSend(win)) |
460 | { | |
e39af974 JS |
461 | event.SetEventObject(win); |
462 | win->GetEventHandler()->ProcessEvent(event); | |
463 | ||
5109ae5d | 464 | if (event.MoreRequested()) |
4629016d | 465 | needMore = true; |
e39af974 | 466 | } |
222ed1d6 | 467 | wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst(); |
e39af974 JS |
468 | while ( node ) |
469 | { | |
529b7f71 JS |
470 | wxWindow *child = node->GetData(); |
471 | if (SendIdleEvents(child, event)) | |
4629016d | 472 | needMore = true; |
e39af974 JS |
473 | |
474 | node = node->GetNext(); | |
475 | } | |
476 | ||
477 | return needMore; | |
478 | } | |
479 | ||
fc7a2a60 | 480 | void wxAppBase::OnIdle(wxIdleEvent& WXUNUSED(event)) |
955a9197 JS |
481 | { |
482 | // If there are pending events, we must process them: pending events | |
483 | // are either events to the threads other than main or events posted | |
484 | // with wxPostEvent() functions | |
485 | // GRG: I have moved this here so that all pending events are processed | |
486 | // before starting to delete any objects. This behaves better (in | |
487 | // particular, wrt wxPostEvent) and is coherent with wxGTK's current | |
488 | // behaviour. Changed Feb/2000 before 2.1.14 | |
489 | ProcessPendingEvents(); | |
490 | ||
491 | // 'Garbage' collection of windows deleted with Close(). | |
492 | DeletePendingObjects(); | |
493 | ||
494 | #if wxUSE_LOG | |
495 | // flush the logged messages if any | |
496 | wxLog::FlushActive(); | |
497 | #endif // wxUSE_LOG | |
498 | ||
499 | } | |
e39af974 | 500 | |
2dc62891 VZ |
501 | // ---------------------------------------------------------------------------- |
502 | // exceptions support | |
503 | // ---------------------------------------------------------------------------- | |
504 | ||
505 | #if wxUSE_EXCEPTIONS | |
506 | ||
507 | bool wxAppBase::OnExceptionInMainLoop() | |
508 | { | |
509 | throw; | |
510 | ||
511 | // some compilers are too stupid to know that we never return after throw | |
512 | #if defined(__DMC__) || (defined(_MSC_VER) && _MSC_VER < 1200) | |
513 | return false; | |
514 | #endif | |
515 | } | |
516 | ||
517 | #endif // wxUSE_EXCEPTIONS | |
518 | ||
bf188f1a | 519 | // ---------------------------------------------------------------------------- |
e2478fde | 520 | // wxGUIAppTraitsBase |
bf188f1a VZ |
521 | // ---------------------------------------------------------------------------- |
522 | ||
bf188f1a | 523 | #if wxUSE_LOG |
bf188f1a | 524 | |
e2478fde VZ |
525 | wxLog *wxGUIAppTraitsBase::CreateLogTarget() |
526 | { | |
461dae94 | 527 | #if wxUSE_LOGGUI |
e2478fde | 528 | return new wxLogGui; |
461dae94 | 529 | #else |
fa6416df | 530 | // we must have something! |
461dae94 VZ |
531 | return new wxLogStderr; |
532 | #endif | |
bf188f1a VZ |
533 | } |
534 | ||
bf188f1a VZ |
535 | #endif // wxUSE_LOG |
536 | ||
e2478fde | 537 | wxMessageOutput *wxGUIAppTraitsBase::CreateMessageOutput() |
bf188f1a | 538 | { |
e2478fde VZ |
539 | // The standard way of printing help on command line arguments (app --help) |
540 | // is (according to common practice): | |
541 | // - console apps: to stderr (on any platform) | |
542 | // - GUI apps: stderr on Unix platforms (!) | |
543 | // message box under Windows and others | |
544 | #ifdef __UNIX__ | |
545 | return new wxMessageOutputStderr; | |
546 | #else // !__UNIX__ | |
547 | // wxMessageOutputMessageBox doesn't work under Motif | |
548 | #ifdef __WXMOTIF__ | |
549 | return new wxMessageOutputLog; | |
550 | #else | |
551 | return new wxMessageOutputMessageBox; | |
552 | #endif | |
553 | #endif // __UNIX__/!__UNIX__ | |
bf188f1a VZ |
554 | } |
555 | ||
e2478fde | 556 | #if wxUSE_FONTMAP |
bf188f1a | 557 | |
e2478fde VZ |
558 | wxFontMapper *wxGUIAppTraitsBase::CreateFontMapper() |
559 | { | |
560 | return new wxFontMapper; | |
bf188f1a VZ |
561 | } |
562 | ||
e2478fde | 563 | #endif // wxUSE_FONTMAP |
bf188f1a | 564 | |
f0244295 VZ |
565 | wxRendererNative *wxGUIAppTraitsBase::CreateRenderer() |
566 | { | |
567 | // use the default native renderer by default | |
568 | return NULL; | |
569 | } | |
570 | ||
090a6d7a | 571 | #ifdef __WXDEBUG__ |
e6e6fcc9 | 572 | |
e2478fde VZ |
573 | bool wxGUIAppTraitsBase::ShowAssertDialog(const wxString& msg) |
574 | { | |
db9febdf | 575 | #if defined(__WXMSW__) || !wxUSE_MSGDLG |
e2478fde VZ |
576 | // under MSW we prefer to use the base class version using ::MessageBox() |
577 | // even if wxMessageBox() is available because it has less chances to | |
578 | // double fault our app than our wxMessageBox() | |
e2478fde VZ |
579 | return wxAppTraitsBase::ShowAssertDialog(msg); |
580 | #else // wxUSE_MSGDLG | |
db9febdf RR |
581 | wxString msgDlg = msg; |
582 | ||
583 | #if wxUSE_STACKWALKER | |
584 | // on Unix stack frame generation may take some time, depending on the | |
585 | // size of the executable mainly... warn the user that we are working | |
586 | wxFprintf(stderr, wxT("[Debug] Generating a stack trace... please wait")); | |
587 | fflush(stderr); | |
588 | ||
589 | const wxString stackTrace = GetAssertStackTrace(); | |
590 | if ( !stackTrace.empty() ) | |
591 | msgDlg << _T("\n\nCall stack:\n") << stackTrace; | |
592 | #endif // wxUSE_STACKWALKER | |
593 | ||
e2478fde VZ |
594 | // this message is intentionally not translated -- it is for |
595 | // developpers only | |
e2478fde VZ |
596 | msgDlg += wxT("\nDo you want to stop the program?\n") |
597 | wxT("You can also choose [Cancel] to suppress ") | |
598 | wxT("further warnings."); | |
599 | ||
77ffb593 | 600 | switch ( wxMessageBox(msgDlg, wxT("wxWidgets Debug Alert"), |
e2478fde VZ |
601 | wxYES_NO | wxCANCEL | wxICON_STOP ) ) |
602 | { | |
603 | case wxYES: | |
604 | wxTrap(); | |
605 | break; | |
090a6d7a | 606 | |
e2478fde VZ |
607 | case wxCANCEL: |
608 | // no more asserts | |
609 | return true; | |
a5f1fd3e | 610 | |
e2478fde | 611 | //case wxNO: nothing to do |
090a6d7a | 612 | } |
090a6d7a | 613 | |
e2478fde VZ |
614 | return false; |
615 | #endif // !wxUSE_MSGDLG/wxUSE_MSGDLG | |
a5f1fd3e VZ |
616 | } |
617 | ||
e2478fde VZ |
618 | #endif // __WXDEBUG__ |
619 | ||
620 | bool wxGUIAppTraitsBase::HasStderr() | |
a5f1fd3e | 621 | { |
e2478fde VZ |
622 | // we consider that under Unix stderr always goes somewhere, even if the |
623 | // user doesn't always see it under GUI desktops | |
624 | #ifdef __UNIX__ | |
625 | return true; | |
a5f1fd3e | 626 | #else |
e2478fde | 627 | return false; |
a5f1fd3e | 628 | #endif |
a5f1fd3e VZ |
629 | } |
630 | ||
e2478fde | 631 | void wxGUIAppTraitsBase::ScheduleForDestroy(wxObject *object) |
a5f1fd3e | 632 | { |
e2478fde VZ |
633 | if ( !wxPendingDelete.Member(object) ) |
634 | wxPendingDelete.Append(object); | |
a5f1fd3e VZ |
635 | } |
636 | ||
e2478fde | 637 | void wxGUIAppTraitsBase::RemoveFromPendingDelete(wxObject *object) |
a5f1fd3e | 638 | { |
e2478fde | 639 | wxPendingDelete.DeleteObject(object); |
a5f1fd3e VZ |
640 | } |
641 | ||
38bb138f VS |
642 | #if wxUSE_SOCKETS |
643 | ||
ae3036a2 | 644 | #if defined(__WINDOWS__) |
38bb138f | 645 | #include "wx/msw/gsockmsw.h" |
ae3036a2 RN |
646 | #elif defined(__UNIX__) || defined(__DARWIN__) || defined(__OS2__) |
647 | #include "wx/unix/gsockunx.h" | |
69aa21ac | 648 | #elif defined(__WXMAC__) |
127eab18 WS |
649 | #include <MacHeaders.c> |
650 | #define OTUNIXERRORS 1 | |
651 | #include <OpenTransport.h> | |
652 | #include <OpenTransportProviders.h> | |
653 | #include <OpenTptInternet.h> | |
69aa21ac | 654 | |
127eab18 | 655 | #include "wx/mac/gsockmac.h" |
38bb138f VS |
656 | #else |
657 | #error "Must include correct GSocket header here" | |
658 | #endif | |
659 | ||
660 | GSocketGUIFunctionsTable* wxGUIAppTraitsBase::GetSocketGUIFunctionsTable() | |
661 | { | |
27a52ff9 GD |
662 | #if defined(__WXMAC__) && !defined(__DARWIN__) |
663 | // NB: wxMac CFM does not have any GUI-specific functions in gsocket.c and | |
14a39351 VS |
664 | // so it doesn't need this table at all |
665 | return NULL; | |
27a52ff9 | 666 | #else // !__WXMAC__ || __DARWIN__ |
1d2ec8e5 DE |
667 | static GSocketGUIFunctionsTableConcrete table; |
668 | return &table; | |
1d2ec8e5 | 669 | #endif // !__WXMAC__ || __DARWIN__ |
38bb138f VS |
670 | } |
671 | ||
672 | #endif |