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