]>
Commit | Line | Data |
---|---|---|
72cdf4c9 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: common/appcmn.cpp | |
3 | // Purpose: 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" | |
bf188f1a | 33 | #include "wx/intl.h" |
e87271f3 | 34 | #include "wx/list.h" |
a69be60b VZ |
35 | #if wxUSE_LOG |
36 | #include "wx/log.h" | |
37 | #endif // wxUSE_LOG | |
a5f1fd3e VZ |
38 | #if wxUSE_GUI |
39 | #include "wx/msgdlg.h" | |
40 | #endif // wxUSE_GUI | |
72cdf4c9 VZ |
41 | #endif |
42 | ||
bf188f1a | 43 | #include "wx/cmdline.h" |
72cdf4c9 | 44 | #include "wx/thread.h" |
7beba2fc | 45 | #include "wx/confbase.h" |
697c5f51 | 46 | #include "wx/tokenzr.h" |
bebc39e3 | 47 | #include "wx/utils.h" |
74698d3a | 48 | #include "wx/msgout.h" |
8d38cdb7 VZ |
49 | |
50 | #if wxUSE_GUI | |
51 | #include "wx/artprov.h" | |
52 | #endif // wxUSE_GUI | |
e1ee679c | 53 | |
a5f1fd3e VZ |
54 | #if !defined(__WXMSW__) || defined(__WXMICROWIN__) |
55 | #include <signal.h> // for SIGTRAP used by wxTrap() | |
56 | #endif //Win/Unix | |
57 | ||
58 | #if defined(__WXMSW__) | |
59 | #include "wx/msw/private.h" // includes windows.h for MessageBox() | |
60 | #endif | |
61 | ||
5128e3be SC |
62 | #if defined(__WXMAC__) |
63 | #include "wx/mac/private.h" // includes mac headers | |
64 | #endif | |
65 | ||
090a6d7a VZ |
66 | // private functions prototypes |
67 | #ifdef __WXDEBUG__ | |
68 | static void LINKAGEMODE SetTraceMasks(); | |
69 | #endif // __WXDEBUG__ | |
70 | ||
d54598dd VZ |
71 | // =========================================================================== |
72 | // implementation | |
73 | // =========================================================================== | |
74 | ||
bf188f1a VZ |
75 | // ---------------------------------------------------------------------------- |
76 | // initialization and termination | |
77 | // ---------------------------------------------------------------------------- | |
78 | ||
090a6d7a | 79 | wxAppBase::wxAppBase() |
697c5f51 | 80 | { |
1e6feb95 VZ |
81 | wxTheApp = (wxApp *)this; |
82 | ||
73deed44 | 83 | #if WXWIN_COMPATIBILITY_2_2 |
1e6feb95 | 84 | m_wantDebugOutput = FALSE; |
73deed44 | 85 | #endif // WXWIN_COMPATIBILITY_2_2 |
1e6feb95 VZ |
86 | |
87 | #if wxUSE_GUI | |
88 | m_topWindow = (wxWindow *)NULL; | |
89 | m_useBestVisual = FALSE; | |
1e6feb95 | 90 | m_isActive = TRUE; |
1cbee0b4 VZ |
91 | |
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 | |
98 | // SetExitOnFrameDelete(FALSE) from OnInit(). | |
99 | // | |
100 | // So we use the special "Later" value which is such that | |
101 | // GetExitOnFrameDelete() returns FALSE for it but which we know we can | |
102 | // safely (i.e. without losing the effect of the users SetExitOnFrameDelete | |
103 | // call) overwrite in OnRun() | |
104 | m_exitOnFrameDelete = Later; | |
1e6feb95 | 105 | #endif // wxUSE_GUI |
697c5f51 VS |
106 | |
107 | #ifdef __WXDEBUG__ | |
108 | SetTraceMasks(); | |
109 | #endif | |
1e6feb95 VZ |
110 | } |
111 | ||
799ea011 GD |
112 | wxAppBase::~wxAppBase() |
113 | { | |
114 | // this destructor is required for Darwin | |
115 | } | |
116 | ||
1e6feb95 | 117 | #if wxUSE_GUI |
9e5b30eb | 118 | |
1e6feb95 VZ |
119 | bool wxAppBase::OnInitGui() |
120 | { | |
121 | #ifdef __WXUNIVERSAL__ | |
bf188f1a | 122 | if ( !wxTheme::Get() && !wxTheme::CreateDefault() ) |
1e6feb95 | 123 | return FALSE; |
536b70ac VS |
124 | wxArtProvider *art = wxTheme::Get()->GetArtProvider(); |
125 | if ( art ) | |
126 | wxArtProvider::PushProvider(art); | |
1e6feb95 VZ |
127 | #endif // __WXUNIVERSAL__ |
128 | ||
129 | return TRUE; | |
130 | } | |
1e6feb95 | 131 | |
1cbee0b4 VZ |
132 | int wxAppBase::OnRun() |
133 | { | |
134 | // see the comment in ctor: if the initial value hasn't been changed, use | |
135 | // the default Yes from now on | |
136 | if ( m_exitOnFrameDelete == Later ) | |
137 | { | |
138 | m_exitOnFrameDelete = Yes; | |
139 | } | |
140 | //else: it has been changed, assume the user knows what he is doing | |
141 | ||
142 | return MainLoop(); | |
143 | } | |
144 | ||
9e5b30eb VZ |
145 | #endif // wxUSE_GUI |
146 | ||
1e6feb95 VZ |
147 | int wxAppBase::OnExit() |
148 | { | |
149 | #if wxUSE_CONFIG | |
150 | // delete the config object if any (don't use Get() here, but Set() | |
151 | // because Get() could create a new config object) | |
152 | delete wxConfigBase::Set((wxConfigBase *) NULL); | |
153 | #endif // wxUSE_CONFIG | |
154 | ||
155 | #ifdef __WXUNIVERSAL__ | |
156 | delete wxTheme::Set(NULL); | |
157 | #endif // __WXUNIVERSAL__ | |
158 | ||
a69be60b VZ |
159 | // use Set(NULL) and not Get() to avoid creating a message output object on |
160 | // demand when we just want to delete it | |
161 | delete wxMessageOutput::Set(NULL); | |
162 | ||
1e6feb95 VZ |
163 | return 0; |
164 | } | |
165 | ||
a69be60b VZ |
166 | // ---------------------------------------------------------------------------- |
167 | // customization hooks | |
168 | // ---------------------------------------------------------------------------- | |
169 | ||
170 | #if wxUSE_LOG | |
171 | ||
172 | wxLog *wxAppBase::CreateLogTarget() | |
173 | { | |
174 | #if wxUSE_GUI && wxUSE_LOGGUI && !defined(__WXMICROWIN__) | |
175 | return new wxLogGui; | |
176 | #else // !GUI | |
177 | return new wxLogStderr; | |
178 | #endif // wxUSE_GUI | |
179 | } | |
180 | ||
181 | #endif // wxUSE_LOG | |
182 | ||
183 | wxMessageOutput *wxAppBase::CreateMessageOutput() | |
184 | { | |
185 | // The standard way of printing help on command line arguments (app --help) | |
186 | // is (according to common practice): | |
187 | // - console apps: to stderr (on any platform) | |
188 | // - GUI apps: stderr on Unix platforms (!) | |
189 | // message box under Windows and others | |
190 | #if wxUSE_GUI && !defined(__UNIX__) | |
191 | // wxMessageOutputMessageBox doesn't work under Motif | |
192 | #ifdef __WXMOTIF__ | |
193 | return new wxMessageOutputLog; | |
194 | #else | |
195 | return new wxMessageOutputMessageBox; | |
196 | #endif | |
197 | #else // !wxUSE_GUI || __UNIX__ | |
198 | return new wxMessageOutputStderr; | |
199 | #endif | |
200 | } | |
201 | ||
72cdf4c9 VZ |
202 | // --------------------------------------------------------------------------- |
203 | // wxAppBase | |
204 | // ---------------------------------------------------------------------------- | |
205 | ||
206 | void wxAppBase::ProcessPendingEvents() | |
207 | { | |
208 | // ensure that we're the only thread to modify the pending events list | |
16c1f79c | 209 | wxENTER_CRIT_SECT( *wxPendingEventsLocker ); |
72cdf4c9 VZ |
210 | |
211 | if ( !wxPendingEvents ) | |
16c1f79c RR |
212 | { |
213 | wxLEAVE_CRIT_SECT( *wxPendingEventsLocker ); | |
72cdf4c9 | 214 | return; |
16c1f79c | 215 | } |
72cdf4c9 VZ |
216 | |
217 | // iterate until the list becomes empty | |
218 | wxNode *node = wxPendingEvents->First(); | |
219 | while (node) | |
220 | { | |
221 | wxEvtHandler *handler = (wxEvtHandler *)node->Data(); | |
16c1f79c | 222 | delete node; |
72cdf4c9 | 223 | |
16c1f79c | 224 | // In ProcessPendingEvents(), new handlers might be add |
1d910ac1 | 225 | // and we can safely leave the critical section here. |
16c1f79c | 226 | wxLEAVE_CRIT_SECT( *wxPendingEventsLocker ); |
72cdf4c9 | 227 | handler->ProcessPendingEvents(); |
16c1f79c | 228 | wxENTER_CRIT_SECT( *wxPendingEventsLocker ); |
72cdf4c9 | 229 | |
72cdf4c9 VZ |
230 | node = wxPendingEvents->First(); |
231 | } | |
1d910ac1 | 232 | |
16c1f79c | 233 | wxLEAVE_CRIT_SECT( *wxPendingEventsLocker ); |
72cdf4c9 VZ |
234 | } |
235 | ||
1e6feb95 VZ |
236 | // ---------------------------------------------------------------------------- |
237 | // misc | |
238 | // ---------------------------------------------------------------------------- | |
239 | ||
240 | #if wxUSE_GUI | |
241 | ||
6e169cf3 | 242 | void wxAppBase::SetActive(bool active, wxWindow * WXUNUSED(lastFocus)) |
7beba2fc | 243 | { |
66dfed9b VZ |
244 | if ( active == m_isActive ) |
245 | return; | |
246 | ||
1e6feb95 | 247 | m_isActive = active; |
66dfed9b VZ |
248 | |
249 | wxActivateEvent event(wxEVT_ACTIVATE_APP, active); | |
250 | event.SetEventObject(this); | |
251 | ||
252 | (void)ProcessEvent(event); | |
7beba2fc | 253 | } |
1e6feb95 VZ |
254 | |
255 | #endif // wxUSE_GUI | |
bf188f1a | 256 | |
9154d8cf VZ |
257 | int wxAppBase::FilterEvent(wxEvent& WXUNUSED(event)) |
258 | { | |
259 | // process the events normally by default | |
260 | return -1; | |
261 | } | |
262 | ||
bf188f1a VZ |
263 | // ---------------------------------------------------------------------------- |
264 | // cmd line parsing | |
265 | // ---------------------------------------------------------------------------- | |
266 | ||
267 | bool wxAppBase::OnInit() | |
268 | { | |
269 | #if wxUSE_CMDLINE_PARSER | |
270 | wxCmdLineParser parser(argc, argv); | |
271 | ||
272 | OnInitCmdLine(parser); | |
273 | ||
274 | bool cont; | |
be03c0ec | 275 | switch ( parser.Parse(FALSE /* don't show usage */) ) |
bf188f1a VZ |
276 | { |
277 | case -1: | |
278 | cont = OnCmdLineHelp(parser); | |
279 | break; | |
280 | ||
281 | case 0: | |
282 | cont = OnCmdLineParsed(parser); | |
283 | break; | |
284 | ||
285 | default: | |
286 | cont = OnCmdLineError(parser); | |
287 | break; | |
288 | } | |
289 | ||
290 | if ( !cont ) | |
291 | return FALSE; | |
292 | #endif // wxUSE_CMDLINE_PARSER | |
293 | ||
294 | return TRUE; | |
295 | } | |
296 | ||
297 | #if wxUSE_CMDLINE_PARSER | |
298 | ||
299 | #define OPTION_VERBOSE _T("verbose") | |
300 | #define OPTION_THEME _T("theme") | |
c358c660 | 301 | #define OPTION_MODE _T("mode") |
bf188f1a VZ |
302 | |
303 | void wxAppBase::OnInitCmdLine(wxCmdLineParser& parser) | |
304 | { | |
305 | // the standard command line options | |
306 | static const wxCmdLineEntryDesc cmdLineDesc[] = | |
307 | { | |
308 | { | |
309 | wxCMD_LINE_SWITCH, | |
310 | _T("h"), | |
311 | _T("help"), | |
312 | gettext_noop("show this help message"), | |
313 | wxCMD_LINE_VAL_NONE, | |
314 | wxCMD_LINE_OPTION_HELP | |
315 | }, | |
316 | ||
317 | #if wxUSE_LOG | |
318 | { | |
319 | wxCMD_LINE_SWITCH, | |
320 | _T(""), | |
321 | OPTION_VERBOSE, | |
ba161d7e GD |
322 | gettext_noop("generate verbose log messages"), |
323 | wxCMD_LINE_VAL_NONE, | |
324 | 0x0 | |
bf188f1a | 325 | }, |
0f02d3d0 | 326 | #endif // wxUSE_LOG |
bf188f1a VZ |
327 | |
328 | #ifdef __WXUNIVERSAL__ | |
329 | { | |
330 | wxCMD_LINE_OPTION, | |
331 | _T(""), | |
332 | OPTION_THEME, | |
333 | gettext_noop("specify the theme to use"), | |
ba161d7e GD |
334 | wxCMD_LINE_VAL_STRING, |
335 | 0x0 | |
bf188f1a VZ |
336 | }, |
337 | #endif // __WXUNIVERSAL__ | |
338 | ||
c358c660 VS |
339 | #if defined(__WXMGL__) |
340 | // VS: this is not specific to wxMGL, all fullscreen (framebuffer) ports | |
341 | // should provide this option. That's why it is in common/appcmn.cpp | |
342 | // and not mgl/app.cpp | |
343 | { | |
344 | wxCMD_LINE_OPTION, | |
345 | _T(""), | |
346 | OPTION_MODE, | |
347 | gettext_noop("specify display mode to use (e.g. 640x480-16)"), | |
ba161d7e GD |
348 | wxCMD_LINE_VAL_STRING, |
349 | 0x0 | |
c358c660 VS |
350 | }, |
351 | #endif // __WXMGL__ | |
352 | ||
bf188f1a | 353 | // terminator |
ba161d7e GD |
354 | { |
355 | wxCMD_LINE_NONE, | |
356 | _T(""), | |
357 | _T(""), | |
358 | _T(""), | |
359 | wxCMD_LINE_VAL_NONE, | |
360 | 0x0 | |
361 | } | |
bf188f1a VZ |
362 | }; |
363 | ||
364 | parser.SetDesc(cmdLineDesc); | |
365 | } | |
366 | ||
367 | bool wxAppBase::OnCmdLineParsed(wxCmdLineParser& parser) | |
368 | { | |
369 | #if wxUSE_LOG | |
370 | if ( parser.Found(OPTION_VERBOSE) ) | |
371 | { | |
372 | wxLog::SetVerbose(TRUE); | |
373 | } | |
374 | #endif // wxUSE_LOG | |
375 | ||
376 | #ifdef __WXUNIVERSAL__ | |
377 | wxString themeName; | |
378 | if ( parser.Found(OPTION_THEME, &themeName) ) | |
379 | { | |
380 | wxTheme *theme = wxTheme::Create(themeName); | |
381 | if ( !theme ) | |
382 | { | |
383 | wxLogError(_("Unsupported theme '%s'."), themeName.c_str()); | |
384 | ||
385 | return FALSE; | |
386 | } | |
387 | ||
388 | wxTheme::Set(theme); | |
389 | } | |
390 | #endif // __WXUNIVERSAL__ | |
391 | ||
c358c660 VS |
392 | #if defined(__WXMGL__) |
393 | wxString modeDesc; | |
394 | if ( parser.Found(OPTION_MODE, &modeDesc) ) | |
395 | { | |
396 | unsigned w, h, bpp; | |
397 | if ( wxSscanf(modeDesc.c_str(), _T("%ux%u-%u"), &w, &h, &bpp) != 3 ) | |
398 | { | |
49e885f8 | 399 | wxLogError(_("Invalid display mode specification '%s'."), modeDesc.c_str()); |
c358c660 VS |
400 | |
401 | return FALSE; | |
402 | } | |
403 | ||
07082b28 | 404 | if ( !SetDisplayMode(wxDisplayModeInfo(w, h, bpp)) ) |
49e885f8 | 405 | return FALSE; |
c358c660 | 406 | } |
be03c0ec | 407 | #endif // __WXMGL__ |
c358c660 | 408 | |
bf188f1a VZ |
409 | return TRUE; |
410 | } | |
411 | ||
412 | bool wxAppBase::OnCmdLineHelp(wxCmdLineParser& parser) | |
413 | { | |
414 | parser.Usage(); | |
415 | ||
416 | return FALSE; | |
417 | } | |
418 | ||
419 | bool wxAppBase::OnCmdLineError(wxCmdLineParser& parser) | |
420 | { | |
421 | parser.Usage(); | |
422 | ||
423 | return FALSE; | |
424 | } | |
425 | ||
426 | #endif // wxUSE_CMDLINE_PARSER | |
427 | ||
a5f1fd3e VZ |
428 | // ---------------------------------------------------------------------------- |
429 | // debugging support | |
430 | // ---------------------------------------------------------------------------- | |
431 | ||
090a6d7a VZ |
432 | /* static */ |
433 | bool wxAppBase::CheckBuildOptions(const wxBuildOptions& opts) | |
434 | { | |
435 | #define wxCMP(what) (what == opts.m_ ## what) | |
436 | ||
437 | bool | |
438 | #ifdef __WXDEBUG__ | |
439 | isDebug = TRUE; | |
440 | #else | |
441 | isDebug = FALSE; | |
442 | #endif | |
443 | ||
444 | int verMaj = wxMAJOR_VERSION, | |
445 | verMin = wxMINOR_VERSION; | |
446 | ||
e6e6fcc9 VZ |
447 | if ( !(wxCMP(isDebug) && wxCMP(verMaj) && wxCMP(verMin)) ) |
448 | { | |
449 | wxLogFatalError(_T("Mismatch between the program and library build ") | |
450 | _T("versions detected.")); | |
090a6d7a | 451 | |
e6e6fcc9 VZ |
452 | // normally wxLogFatalError doesn't return |
453 | return FALSE; | |
454 | } | |
090a6d7a | 455 | #undef wxCMP |
e6e6fcc9 VZ |
456 | |
457 | return TRUE; | |
090a6d7a VZ |
458 | } |
459 | ||
a5f1fd3e VZ |
460 | #ifdef __WXDEBUG__ |
461 | ||
090a6d7a VZ |
462 | static void LINKAGEMODE SetTraceMasks() |
463 | { | |
464 | wxString mask; | |
465 | if ( wxGetEnv(wxT("WXTRACE"), &mask) ) | |
466 | { | |
467 | wxStringTokenizer tkn(mask, wxT(",")); | |
468 | while ( tkn.HasMoreTokens() ) | |
469 | wxLog::AddTraceMask(tkn.GetNextToken()); | |
470 | } | |
471 | } | |
472 | ||
a5f1fd3e VZ |
473 | // wxASSERT() helper |
474 | bool wxAssertIsEqual(int x, int y) | |
475 | { | |
476 | return x == y; | |
477 | } | |
478 | ||
479 | // break into the debugger | |
480 | void wxTrap() | |
481 | { | |
482 | #if defined(__WXMSW__) && !defined(__WXMICROWIN__) | |
483 | DebugBreak(); | |
c31ad41d | 484 | #elif defined(__WXMAC__) && !defined(__DARWIN__) |
a5f1fd3e VZ |
485 | #if __powerc |
486 | Debugger(); | |
487 | #else | |
488 | SysBreak(); | |
489 | #endif | |
490 | #elif defined(__UNIX__) | |
491 | raise(SIGTRAP); | |
492 | #else | |
493 | // TODO | |
494 | #endif // Win/Unix | |
495 | } | |
496 | ||
497 | // show the assert modal dialog | |
498 | static | |
aad65f13 VZ |
499 | void ShowAssertDialog(const wxChar *szFile, |
500 | int nLine, | |
501 | const wxChar *szCond, | |
502 | const wxChar *szMsg) | |
a5f1fd3e VZ |
503 | { |
504 | // this variable can be set to true to suppress "assert failure" messages | |
505 | static bool s_bNoAsserts = FALSE; | |
a5f1fd3e VZ |
506 | |
507 | wxChar szBuf[4096]; | |
508 | ||
aad65f13 VZ |
509 | // make life easier for people using VC++ IDE by using this format: like |
510 | // this, clicking on the message will take us immediately to the place of | |
511 | // the failed assert | |
a5f1fd3e | 512 | wxSnprintf(szBuf, WXSIZEOF(szBuf), |
aad65f13 VZ |
513 | wxT("%s(%d): assert \"%s\" failed"), |
514 | szFile, nLine, szCond); | |
a5f1fd3e VZ |
515 | |
516 | if ( szMsg != NULL ) | |
517 | { | |
518 | wxStrcat(szBuf, wxT(": ")); | |
519 | wxStrcat(szBuf, szMsg); | |
520 | } | |
521 | else // no message given | |
522 | { | |
523 | wxStrcat(szBuf, wxT(".")); | |
524 | } | |
525 | ||
526 | if ( !s_bNoAsserts ) | |
527 | { | |
528 | // send it to the normal log destination | |
529 | wxLogDebug(szBuf); | |
530 | ||
531 | #if (wxUSE_GUI && wxUSE_MSGDLG) || defined(__WXMSW__) | |
532 | // this message is intentionally not translated - it is for | |
533 | // developpers only | |
534 | wxStrcat(szBuf, wxT("\nDo you want to stop the program?\nYou can also choose [Cancel] to suppress further warnings.")); | |
535 | ||
536 | // use the native message box if available: this is more robust than | |
537 | // using our own | |
538 | #if defined(__WXMSW__) && !defined(__WXMICROWIN__) | |
539 | switch ( ::MessageBox(NULL, szBuf, _T("Debug"), | |
540 | MB_YESNOCANCEL | MB_ICONSTOP ) ) | |
541 | { | |
542 | case IDYES: | |
543 | wxTrap(); | |
544 | break; | |
545 | ||
546 | case IDCANCEL: | |
547 | s_bNoAsserts = TRUE; | |
548 | break; | |
549 | ||
550 | //case IDNO: nothing to do | |
551 | } | |
552 | #else // !MSW | |
553 | switch ( wxMessageBox(szBuf, wxT("Debug"), | |
554 | wxYES_NO | wxCANCEL | wxICON_STOP ) ) | |
555 | { | |
556 | case wxYES: | |
557 | wxTrap(); | |
558 | break; | |
559 | ||
560 | case wxCANCEL: | |
561 | s_bNoAsserts = TRUE; | |
562 | break; | |
563 | ||
564 | //case wxNO: nothing to do | |
565 | } | |
566 | #endif // GUI or MSW | |
567 | ||
568 | #else // !GUI | |
569 | wxTrap(); | |
570 | #endif // GUI/!GUI | |
571 | } | |
a5f1fd3e VZ |
572 | } |
573 | ||
574 | // this function is called when an assert fails | |
aad65f13 VZ |
575 | void wxOnAssert(const wxChar *szFile, |
576 | int nLine, | |
577 | const wxChar *szCond, | |
578 | const wxChar *szMsg) | |
a5f1fd3e | 579 | { |
76456676 VZ |
580 | // FIXME MT-unsafe |
581 | static bool s_bInAssert = FALSE; | |
582 | ||
583 | if ( s_bInAssert ) | |
584 | { | |
585 | // He-e-e-e-elp!! we're trapped in endless loop | |
586 | wxTrap(); | |
587 | ||
588 | s_bInAssert = FALSE; | |
589 | ||
590 | return; | |
591 | } | |
592 | ||
593 | s_bInAssert = TRUE; | |
594 | ||
a5f1fd3e VZ |
595 | if ( !wxTheApp ) |
596 | { | |
597 | // by default, show the assert dialog box - we can't customize this | |
598 | // behaviour | |
aad65f13 | 599 | ShowAssertDialog(szFile, nLine, szCond, szMsg); |
a5f1fd3e VZ |
600 | } |
601 | else | |
602 | { | |
603 | // let the app process it as it wants | |
aad65f13 | 604 | wxTheApp->OnAssert(szFile, nLine, szCond, szMsg); |
a5f1fd3e | 605 | } |
76456676 VZ |
606 | |
607 | s_bInAssert = FALSE; | |
a5f1fd3e VZ |
608 | } |
609 | ||
aad65f13 VZ |
610 | void wxAppBase::OnAssert(const wxChar *file, |
611 | int line, | |
612 | const wxChar *cond, | |
613 | const wxChar *msg) | |
a5f1fd3e | 614 | { |
aad65f13 | 615 | ShowAssertDialog(file, line, cond, msg); |
a5f1fd3e VZ |
616 | } |
617 | ||
618 | #endif //WXDEBUG | |
619 |