Added part of patch
[wxWidgets.git] / src / common / appbase.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/appbase.cpp
3 // Purpose: implements wxAppConsole class
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 19.06.2003 (extracted from common/appcmn.cpp)
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #ifdef __WXMSW__
29 #include "wx/msw/wrapwin.h" // includes windows.h for MessageBox()
30 #endif
31 #include "wx/list.h"
32 #include "wx/app.h"
33 #include "wx/intl.h"
34 #include "wx/log.h"
35 #include "wx/utils.h"
36 #endif //WX_PRECOMP
37
38 #include "wx/apptrait.h"
39 #include "wx/cmdline.h"
40 #include "wx/confbase.h"
41 #include "wx/filename.h"
42 #include "wx/msgout.h"
43 #include "wx/tokenzr.h"
44
45 #if !defined(__WXMSW__) || defined(__WXMICROWIN__)
46 #include <signal.h> // for SIGTRAP used by wxTrap()
47 #endif //Win/Unix
48
49 #if wxUSE_FONTMAP
50 #include "wx/fontmap.h"
51 #endif // wxUSE_FONTMAP
52
53 #if defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
54 // For MacTypes.h for Debugger function
55 #include <CoreFoundation/CFBase.h>
56 #endif
57
58 #if defined(__WXMAC__)
59 #ifdef __DARWIN__
60 #include <CoreServices/CoreServices.h>
61 #else
62 #include "wx/mac/private.h" // includes mac headers
63 #endif
64 #endif // __WXMAC__
65
66 #ifdef __WXDEBUG__
67 #if wxUSE_STACKWALKER
68 #include "wx/stackwalk.h"
69 #ifdef __WXMSW__
70 #include "wx/msw/debughlp.h"
71 #endif
72 #endif // wxUSE_STACKWALKER
73 #endif // __WXDEBUG__
74
75 // wxABI_VERSION can be defined when compiling applications but it should be
76 // left undefined when compiling the library itself, it is then set to its
77 // default value in version.h
78 #if wxABI_VERSION != wxMAJOR_VERSION * 10000 + wxMINOR_VERSION * 100 + 99
79 #error "wxABI_VERSION should not be defined when compiling the library"
80 #endif
81
82 // ----------------------------------------------------------------------------
83 // private functions prototypes
84 // ----------------------------------------------------------------------------
85
86 #ifdef __WXDEBUG__
87 // really just show the assert dialog
88 static bool DoShowAssertDialog(const wxString& msg);
89
90 // prepare for showing the assert dialog, use the given traits or
91 // DoShowAssertDialog() as last fallback to really show it
92 static
93 void ShowAssertDialog(const wxChar *szFile,
94 int nLine,
95 const wxChar *szFunc,
96 const wxChar *szCond,
97 const wxChar *szMsg,
98 wxAppTraits *traits = NULL);
99
100 // turn on the trace masks specified in the env variable WXTRACE
101 static void LINKAGEMODE SetTraceMasks();
102 #endif // __WXDEBUG__
103
104 // ----------------------------------------------------------------------------
105 // global vars
106 // ----------------------------------------------------------------------------
107
108 wxAppConsole *wxAppConsole::ms_appInstance = NULL;
109
110 wxAppInitializerFunction wxAppConsole::ms_appInitFn = NULL;
111
112 // ============================================================================
113 // wxAppConsole implementation
114 // ============================================================================
115
116 // ----------------------------------------------------------------------------
117 // ctor/dtor
118 // ----------------------------------------------------------------------------
119
120 wxAppConsole::wxAppConsole()
121 {
122 m_traits = NULL;
123
124 ms_appInstance = this;
125
126 #ifdef __WXDEBUG__
127 SetTraceMasks();
128 #if wxUSE_UNICODE
129 // In unicode mode the SetTraceMasks call can cause an apptraits to be
130 // created, but since we are still in the constructor the wrong kind will
131 // be created for GUI apps. Destroy it so it can be created again later.
132 delete m_traits;
133 m_traits = NULL;
134 #endif
135 #endif
136 }
137
138 wxAppConsole::~wxAppConsole()
139 {
140 delete m_traits;
141 }
142
143 // ----------------------------------------------------------------------------
144 // initilization/cleanup
145 // ----------------------------------------------------------------------------
146
147 bool wxAppConsole::Initialize(int& argcOrig, wxChar **argvOrig)
148 {
149 // remember the command line arguments
150 argc = argcOrig;
151 argv = argvOrig;
152
153 #ifndef __WXPALMOS__
154 if ( m_appName.empty() && argv )
155 {
156 // the application name is, by default, the name of its executable file
157 wxFileName::SplitPath(argv[0], NULL, &m_appName, NULL);
158 }
159 #endif
160
161 return true;
162 }
163
164 void wxAppConsole::CleanUp()
165 {
166 }
167
168 // ----------------------------------------------------------------------------
169 // OnXXX() callbacks
170 // ----------------------------------------------------------------------------
171
172 bool wxAppConsole::OnInit()
173 {
174 #if wxUSE_CMDLINE_PARSER
175 wxCmdLineParser parser(argc, argv);
176
177 OnInitCmdLine(parser);
178
179 bool cont;
180 switch ( parser.Parse(false /* don't show usage */) )
181 {
182 case -1:
183 cont = OnCmdLineHelp(parser);
184 break;
185
186 case 0:
187 cont = OnCmdLineParsed(parser);
188 break;
189
190 default:
191 cont = OnCmdLineError(parser);
192 break;
193 }
194
195 if ( !cont )
196 return false;
197 #endif // wxUSE_CMDLINE_PARSER
198
199 return true;
200 }
201
202 int wxAppConsole::OnExit()
203 {
204 #if wxUSE_CONFIG
205 // delete the config object if any (don't use Get() here, but Set()
206 // because Get() could create a new config object)
207 delete wxConfigBase::Set((wxConfigBase *) NULL);
208 #endif // wxUSE_CONFIG
209
210 return 0;
211 }
212
213 void wxAppConsole::Exit()
214 {
215 exit(-1);
216 }
217
218 wxLayoutDirection wxAppConsole::GetLayoutDirection() const
219 {
220 #if wxUSE_INTL
221 const wxLocale *const locale = wxGetLocale();
222 if ( locale )
223 {
224 const wxLanguageInfo *const
225 info = wxLocale::GetLanguageInfo(locale->GetLanguage());
226
227 if ( info )
228 return info->LayoutDirection;
229 }
230 #endif // wxUSE_INTL
231
232 // we don't know
233 return wxLayout_Default;
234 }
235
236 // ----------------------------------------------------------------------------
237 // traits stuff
238 // ----------------------------------------------------------------------------
239
240 wxAppTraits *wxAppConsole::CreateTraits()
241 {
242 return new wxConsoleAppTraits;
243 }
244
245 wxAppTraits *wxAppConsole::GetTraits()
246 {
247 // FIXME-MT: protect this with a CS?
248 if ( !m_traits )
249 {
250 m_traits = CreateTraits();
251
252 wxASSERT_MSG( m_traits, _T("wxApp::CreateTraits() failed?") );
253 }
254
255 return m_traits;
256 }
257
258 // we must implement CreateXXX() in wxApp itself for backwards compatibility
259 #if WXWIN_COMPATIBILITY_2_4
260
261 #if wxUSE_LOG
262
263 wxLog *wxAppConsole::CreateLogTarget()
264 {
265 wxAppTraits *traits = GetTraits();
266 return traits ? traits->CreateLogTarget() : NULL;
267 }
268
269 #endif // wxUSE_LOG
270
271 wxMessageOutput *wxAppConsole::CreateMessageOutput()
272 {
273 wxAppTraits *traits = GetTraits();
274 return traits ? traits->CreateMessageOutput() : NULL;
275 }
276
277 #endif // WXWIN_COMPATIBILITY_2_4
278
279 // ----------------------------------------------------------------------------
280 // event processing
281 // ----------------------------------------------------------------------------
282
283 void wxAppConsole::ProcessPendingEvents()
284 {
285 #if wxUSE_THREADS
286 if ( !wxPendingEventsLocker )
287 return;
288 #endif
289
290 // ensure that we're the only thread to modify the pending events list
291 wxENTER_CRIT_SECT( *wxPendingEventsLocker );
292
293 if ( !wxPendingEvents )
294 {
295 wxLEAVE_CRIT_SECT( *wxPendingEventsLocker );
296 return;
297 }
298
299 // iterate until the list becomes empty
300 wxList::compatibility_iterator node = wxPendingEvents->GetFirst();
301
302 while (node &&
303 ((wxEvtHandler *)node->GetData())->IsEventHandlingInProgress() &&
304 ((wxEvtHandler *)node->GetData())->IsReentranceAllowed() == false)
305 {
306 // skip over event
307 node = node->GetNext();
308 }
309
310 while (node)
311 {
312 wxEvtHandler *handler = (wxEvtHandler *)node->GetData();
313 wxPendingEvents->Erase(node);
314
315 // In ProcessPendingEvents(), new handlers might be add
316 // and we can safely leave the critical section here.
317 wxLEAVE_CRIT_SECT( *wxPendingEventsLocker );
318
319 handler->ProcessPendingEvents();
320
321 wxENTER_CRIT_SECT( *wxPendingEventsLocker );
322
323 node = wxPendingEvents->GetFirst();
324
325 while (node &&
326 ((wxEvtHandler *)node->GetData())->IsEventHandlingInProgress() &&
327 ((wxEvtHandler *)node->GetData())->IsReentranceAllowed() == false)
328 {
329 // skip over event
330 node = node->GetNext();
331 }
332 }
333
334 wxLEAVE_CRIT_SECT( *wxPendingEventsLocker );
335 }
336
337 int wxAppConsole::FilterEvent(wxEvent& WXUNUSED(event))
338 {
339 // process the events normally by default
340 return -1;
341 }
342
343 // ----------------------------------------------------------------------------
344 // exception handling
345 // ----------------------------------------------------------------------------
346
347 #if wxUSE_EXCEPTIONS
348
349 void
350 wxAppConsole::HandleEvent(wxEvtHandler *handler,
351 wxEventFunction func,
352 wxEvent& event) const
353 {
354 // by default, simply call the handler
355 (handler->*func)(event);
356 }
357
358 #endif // wxUSE_EXCEPTIONS
359
360 // ----------------------------------------------------------------------------
361 // cmd line parsing
362 // ----------------------------------------------------------------------------
363
364 #if wxUSE_CMDLINE_PARSER
365
366 #define OPTION_VERBOSE _T("verbose")
367
368 void wxAppConsole::OnInitCmdLine(wxCmdLineParser& parser)
369 {
370 // the standard command line options
371 static const wxCmdLineEntryDesc cmdLineDesc[] =
372 {
373 {
374 wxCMD_LINE_SWITCH,
375 _T("h"),
376 _T("help"),
377 gettext_noop("show this help message"),
378 wxCMD_LINE_VAL_NONE,
379 wxCMD_LINE_OPTION_HELP
380 },
381
382 #if wxUSE_LOG
383 {
384 wxCMD_LINE_SWITCH,
385 wxEmptyString,
386 OPTION_VERBOSE,
387 gettext_noop("generate verbose log messages"),
388 wxCMD_LINE_VAL_NONE,
389 0x0
390 },
391 #endif // wxUSE_LOG
392
393 // terminator
394 {
395 wxCMD_LINE_NONE,
396 wxEmptyString,
397 wxEmptyString,
398 wxEmptyString,
399 wxCMD_LINE_VAL_NONE,
400 0x0
401 }
402 };
403
404 parser.SetDesc(cmdLineDesc);
405 }
406
407 bool wxAppConsole::OnCmdLineParsed(wxCmdLineParser& parser)
408 {
409 #if wxUSE_LOG
410 if ( parser.Found(OPTION_VERBOSE) )
411 {
412 wxLog::SetVerbose(true);
413 }
414 #else
415 wxUnusedVar(parser);
416 #endif // wxUSE_LOG
417
418 return true;
419 }
420
421 bool wxAppConsole::OnCmdLineHelp(wxCmdLineParser& parser)
422 {
423 parser.Usage();
424
425 return false;
426 }
427
428 bool wxAppConsole::OnCmdLineError(wxCmdLineParser& parser)
429 {
430 parser.Usage();
431
432 return false;
433 }
434
435 #endif // wxUSE_CMDLINE_PARSER
436
437 // ----------------------------------------------------------------------------
438 // debugging support
439 // ----------------------------------------------------------------------------
440
441 /* static */
442 bool wxAppConsole::CheckBuildOptions(const char *optionsSignature,
443 const char *componentName)
444 {
445 #if 0 // can't use wxLogTrace, not up and running yet
446 printf("checking build options object '%s' (ptr %p) in '%s'\n",
447 optionsSignature, optionsSignature, componentName);
448 #endif
449
450 if ( strcmp(optionsSignature, WX_BUILD_OPTIONS_SIGNATURE) != 0 )
451 {
452 wxString lib = wxString::FromAscii(WX_BUILD_OPTIONS_SIGNATURE);
453 wxString prog = wxString::FromAscii(optionsSignature);
454 wxString progName = wxString::FromAscii(componentName);
455 wxString msg;
456
457 msg.Printf(_T("Mismatch between the program and library build versions detected.\nThe library used %s,\nand %s used %s."),
458 lib.c_str(), progName.c_str(), prog.c_str());
459
460 wxLogFatalError(msg.c_str());
461
462 // normally wxLogFatalError doesn't return
463 return false;
464 }
465 #undef wxCMP
466
467 return true;
468 }
469
470 #ifdef __WXDEBUG__
471
472 void wxAppConsole::OnAssertFailure(const wxChar *file,
473 int line,
474 const wxChar *func,
475 const wxChar *cond,
476 const wxChar *msg)
477 {
478 ShowAssertDialog(file, line, func, cond, msg, GetTraits());
479 }
480
481 void wxAppConsole::OnAssert(const wxChar *file,
482 int line,
483 const wxChar *cond,
484 const wxChar *msg)
485 {
486 OnAssertFailure(file, line, NULL, cond, msg);
487 }
488
489 #endif // __WXDEBUG__
490
491 #if WXWIN_COMPATIBILITY_2_4
492
493 bool wxAppConsole::CheckBuildOptions(const wxBuildOptions& buildOptions)
494 {
495 return CheckBuildOptions(buildOptions.m_signature, "your program");
496 }
497
498 #endif
499
500 // ============================================================================
501 // other classes implementations
502 // ============================================================================
503
504 // ----------------------------------------------------------------------------
505 // wxConsoleAppTraitsBase
506 // ----------------------------------------------------------------------------
507
508 #if wxUSE_LOG
509
510 wxLog *wxConsoleAppTraitsBase::CreateLogTarget()
511 {
512 return new wxLogStderr;
513 }
514
515 #endif // wxUSE_LOG
516
517 wxMessageOutput *wxConsoleAppTraitsBase::CreateMessageOutput()
518 {
519 return new wxMessageOutputStderr;
520 }
521
522 #if wxUSE_FONTMAP
523
524 wxFontMapper *wxConsoleAppTraitsBase::CreateFontMapper()
525 {
526 return (wxFontMapper *)new wxFontMapperBase;
527 }
528
529 #endif // wxUSE_FONTMAP
530
531 wxRendererNative *wxConsoleAppTraitsBase::CreateRenderer()
532 {
533 // console applications don't use renderers
534 return NULL;
535 }
536
537 #ifdef __WXDEBUG__
538 bool wxConsoleAppTraitsBase::ShowAssertDialog(const wxString& msg)
539 {
540 return wxAppTraitsBase::ShowAssertDialog(msg);
541 }
542 #endif
543
544 bool wxConsoleAppTraitsBase::HasStderr()
545 {
546 // console applications always have stderr, even under Mac/Windows
547 return true;
548 }
549
550 void wxConsoleAppTraitsBase::ScheduleForDestroy(wxObject *object)
551 {
552 delete object;
553 }
554
555 void wxConsoleAppTraitsBase::RemoveFromPendingDelete(wxObject * WXUNUSED(object))
556 {
557 // nothing to do
558 }
559
560 #if wxUSE_SOCKETS
561 GSocketGUIFunctionsTable* wxConsoleAppTraitsBase::GetSocketGUIFunctionsTable()
562 {
563 return NULL;
564 }
565 #endif
566
567 // ----------------------------------------------------------------------------
568 // wxAppTraits
569 // ----------------------------------------------------------------------------
570
571 #ifdef __WXDEBUG__
572
573 bool wxAppTraitsBase::ShowAssertDialog(const wxString& msg)
574 {
575 return DoShowAssertDialog(msg);
576 }
577
578 #endif // __WXDEBUG__
579
580 // ============================================================================
581 // global functions implementation
582 // ============================================================================
583
584 void wxExit()
585 {
586 if ( wxTheApp )
587 {
588 wxTheApp->Exit();
589 }
590 else
591 {
592 // what else can we do?
593 exit(-1);
594 }
595 }
596
597 void wxWakeUpIdle()
598 {
599 if ( wxTheApp )
600 {
601 wxTheApp->WakeUpIdle();
602 }
603 //else: do nothing, what can we do?
604 }
605
606 #ifdef __WXDEBUG__
607
608 // wxASSERT() helper
609 bool wxAssertIsEqual(int x, int y)
610 {
611 return x == y;
612 }
613
614 // break into the debugger
615 void wxTrap()
616 {
617 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
618 DebugBreak();
619 #elif defined(__WXMAC__) && !defined(__DARWIN__)
620 #if __powerc
621 Debugger();
622 #else
623 SysBreak();
624 #endif
625 #elif defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
626 Debugger();
627 #elif defined(__UNIX__)
628 raise(SIGTRAP);
629 #else
630 // TODO
631 #endif // Win/Unix
632 }
633
634 // this function is called when an assert fails
635 void wxOnAssert(const wxChar *szFile,
636 int nLine,
637 const char *szFunc,
638 const wxChar *szCond,
639 const wxChar *szMsg)
640 {
641 // FIXME MT-unsafe
642 static bool s_bInAssert = false;
643
644 if ( s_bInAssert )
645 {
646 // He-e-e-e-elp!! we're trapped in endless loop
647 wxTrap();
648
649 s_bInAssert = false;
650
651 return;
652 }
653
654 s_bInAssert = true;
655
656 // __FUNCTION__ is always in ASCII, convert it to wide char if needed
657 const wxString strFunc = wxString::FromAscii(szFunc);
658
659 if ( !wxTheApp )
660 {
661 // by default, show the assert dialog box -- we can't customize this
662 // behaviour
663 ShowAssertDialog(szFile, nLine, strFunc, szCond, szMsg);
664 }
665 else
666 {
667 // let the app process it as it wants
668 wxTheApp->OnAssertFailure(szFile, nLine, strFunc, szCond, szMsg);
669 }
670
671 s_bInAssert = false;
672 }
673
674 #endif // __WXDEBUG__
675
676 // ============================================================================
677 // private functions implementation
678 // ============================================================================
679
680 #ifdef __WXDEBUG__
681
682 static void LINKAGEMODE SetTraceMasks()
683 {
684 #if wxUSE_LOG
685 wxString mask;
686 if ( wxGetEnv(wxT("WXTRACE"), &mask) )
687 {
688 wxStringTokenizer tkn(mask, wxT(",;:"));
689 while ( tkn.HasMoreTokens() )
690 wxLog::AddTraceMask(tkn.GetNextToken());
691 }
692 #endif // wxUSE_LOG
693 }
694
695 bool DoShowAssertDialog(const wxString& msg)
696 {
697 // under MSW we can show the dialog even in the console mode
698 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
699 wxString msgDlg(msg);
700
701 // this message is intentionally not translated -- it is for
702 // developpers only
703 msgDlg += wxT("\nDo you want to stop the program?\n")
704 wxT("You can also choose [Cancel] to suppress ")
705 wxT("further warnings.");
706
707 switch ( ::MessageBox(NULL, msgDlg, _T("wxWidgets Debug Alert"),
708 MB_YESNOCANCEL | MB_ICONSTOP ) )
709 {
710 case IDYES:
711 wxTrap();
712 break;
713
714 case IDCANCEL:
715 // stop the asserts
716 return true;
717
718 //case IDNO: nothing to do
719 }
720 #else // !__WXMSW__
721 wxFprintf(stderr, wxT("%s\n"), msg.c_str());
722 fflush(stderr);
723
724 // TODO: ask the user to enter "Y" or "N" on the console?
725 wxTrap();
726 #endif // __WXMSW__/!__WXMSW__
727
728 // continue with the asserts
729 return false;
730 }
731
732 #if wxUSE_STACKWALKER
733 static wxString GetAssertStackTrace()
734 {
735 wxString stackTrace;
736
737 class StackDump : public wxStackWalker
738 {
739 public:
740 StackDump() { }
741
742 const wxString& GetStackTrace() const { return m_stackTrace; }
743
744 protected:
745 virtual void OnStackFrame(const wxStackFrame& frame)
746 {
747 m_stackTrace << wxString::Format
748 (
749 _T("[%02d] "),
750 wx_truncate_cast(int, frame.GetLevel())
751 );
752
753 wxString name = frame.GetName();
754 if ( !name.empty() )
755 {
756 m_stackTrace << wxString::Format(_T("%-40s"), name.c_str());
757 }
758 else
759 {
760 m_stackTrace << wxString::Format(_T("%p"), frame.GetAddress());
761 }
762
763 if ( frame.HasSourceLocation() )
764 {
765 m_stackTrace << _T('\t')
766 << frame.GetFileName()
767 << _T(':')
768 << frame.GetLine();
769 }
770
771 m_stackTrace << _T('\n');
772 }
773
774 private:
775 wxString m_stackTrace;
776 };
777
778 StackDump dump;
779 dump.Walk(2); // don't show OnAssert() call itself
780 stackTrace = dump.GetStackTrace();
781
782 // don't show more than maxLines or we could get a dialog too tall to be
783 // shown on screen: 20 should be ok everywhere as even with 15 pixel high
784 // characters it is still only 300 pixels...
785 static const int maxLines = 20;
786 const int count = stackTrace.Freq(wxT('\n'));
787 for ( int i = 0; i < count - maxLines; i++ )
788 stackTrace = stackTrace.BeforeLast(wxT('\n'));
789
790 return stackTrace;
791 }
792 #endif // wxUSE_STACKWALKER
793
794 // show the assert modal dialog
795 static
796 void ShowAssertDialog(const wxChar *szFile,
797 int nLine,
798 const wxChar *szFunc,
799 const wxChar *szCond,
800 const wxChar *szMsg,
801 wxAppTraits *traits)
802 {
803 // this variable can be set to true to suppress "assert failure" messages
804 static bool s_bNoAsserts = false;
805
806 wxString msg;
807 msg.reserve(2048);
808
809 // make life easier for people using VC++ IDE by using this format: like
810 // this, clicking on the message will take us immediately to the place of
811 // the failed assert
812 msg.Printf(wxT("%s(%d): assert \"%s\" failed"), szFile, nLine, szCond);
813
814 // add the function name, if any
815 if ( szFunc && *szFunc )
816 msg << _T(" in ") << szFunc << _T("()");
817
818 // and the message itself
819 if ( szMsg )
820 {
821 msg << _T(": ") << szMsg;
822 }
823 else // no message given
824 {
825 msg << _T('.');
826 }
827
828 #if wxUSE_STACKWALKER
829 const wxString stackTrace = GetAssertStackTrace();
830 if ( !stackTrace.empty() )
831 {
832 msg << _T("\n\nCall stack:\n") << stackTrace;
833 }
834 #endif // wxUSE_STACKWALKER
835
836 #if wxUSE_THREADS
837 // if we are not in the main thread, output the assert directly and trap
838 // since dialogs cannot be displayed
839 if ( !wxThread::IsMain() )
840 {
841 msg += wxT(" [in child thread]");
842
843 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
844 msg << wxT("\r\n");
845 OutputDebugString(msg );
846 #else
847 // send to stderr
848 wxFprintf(stderr, wxT("%s\n"), msg.c_str());
849 fflush(stderr);
850 #endif
851 // He-e-e-e-elp!! we're asserting in a child thread
852 wxTrap();
853 }
854 else
855 #endif // wxUSE_THREADS
856
857 if ( !s_bNoAsserts )
858 {
859 // send it to the normal log destination
860 wxLogDebug(_T("%s"), msg.c_str());
861
862 if ( traits )
863 {
864 // delegate showing assert dialog (if possible) to that class
865 s_bNoAsserts = traits->ShowAssertDialog(msg);
866 }
867 else // no traits object
868 {
869 // fall back to the function of last resort
870 s_bNoAsserts = DoShowAssertDialog(msg);
871 }
872 }
873 }
874
875 #endif // __WXDEBUG__