X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9e5b30eb3e7545940135671fd21311d7c5596c66..878711c01c1b9ad5b97d35f379a048b8ce1bfb49:/src/common/appcmn.cpp diff --git a/src/common/appcmn.cpp b/src/common/appcmn.cpp index fec6879ea6..25bda2572b 100644 --- a/src/common/appcmn.cpp +++ b/src/common/appcmn.cpp @@ -32,6 +32,9 @@ #include "wx/app.h" #include "wx/intl.h" #include "wx/list.h" + #if wxUSE_LOG + #include "wx/log.h" + #endif // wxUSE_LOG #if wxUSE_GUI #include "wx/msgdlg.h" #endif // wxUSE_GUI @@ -118,9 +121,6 @@ bool wxAppBase::OnInitGui() #ifdef __WXUNIVERSAL__ if ( !wxTheme::Get() && !wxTheme::CreateDefault() ) return FALSE; - wxArtProvider *art = wxTheme::Get()->GetArtProvider(); - if ( art ) - wxArtProvider::PushProvider(art); #endif // __WXUNIVERSAL__ return TRUE; @@ -153,9 +153,49 @@ int wxAppBase::OnExit() delete wxTheme::Set(NULL); #endif // __WXUNIVERSAL__ + // use Set(NULL) and not Get() to avoid creating a message output object on + // demand when we just want to delete it + delete wxMessageOutput::Set(NULL); + return 0; } +// ---------------------------------------------------------------------------- +// customization hooks +// ---------------------------------------------------------------------------- + +#if wxUSE_LOG + +wxLog *wxAppBase::CreateLogTarget() +{ +#if wxUSE_GUI && wxUSE_LOGGUI && !defined(__WXMICROWIN__) + return new wxLogGui; +#else // !GUI + return new wxLogStderr; +#endif // wxUSE_GUI +} + +#endif // wxUSE_LOG + +wxMessageOutput *wxAppBase::CreateMessageOutput() +{ + // The standard way of printing help on command line arguments (app --help) + // is (according to common practice): + // - console apps: to stderr (on any platform) + // - GUI apps: stderr on Unix platforms (!) + // message box under Windows and others +#if wxUSE_GUI && !defined(__UNIX__) + // wxMessageOutputMessageBox doesn't work under Motif + #ifdef __WXMOTIF__ + return new wxMessageOutputLog; + #else + return new wxMessageOutputMessageBox; + #endif +#else // !wxUSE_GUI || __UNIX__ + return new wxMessageOutputStderr; +#endif +} + // --------------------------------------------------------------------------- // wxAppBase // ---------------------------------------------------------------------------- @@ -172,10 +212,10 @@ void wxAppBase::ProcessPendingEvents() } // iterate until the list becomes empty - wxNode *node = wxPendingEvents->First(); + wxNode *node = wxPendingEvents->GetFirst(); while (node) { - wxEvtHandler *handler = (wxEvtHandler *)node->Data(); + wxEvtHandler *handler = (wxEvtHandler *)node->GetData(); delete node; // In ProcessPendingEvents(), new handlers might be add @@ -184,7 +224,7 @@ void wxAppBase::ProcessPendingEvents() handler->ProcessPendingEvents(); wxENTER_CRIT_SECT( *wxPendingEventsLocker ); - node = wxPendingEvents->First(); + node = wxPendingEvents->GetFirst(); } wxLEAVE_CRIT_SECT( *wxPendingEventsLocker ); @@ -217,34 +257,12 @@ int wxAppBase::FilterEvent(wxEvent& WXUNUSED(event)) return -1; } -void wxAppBase::DoInit() -{ - if (wxMessageOutput::Get()) - return; - - // NB: The standard way of printing help on command line arguments (app --help) - // is (according to common practice): - // - console apps: to stderr (on any platform) - // - GUI apps: stderr on Unix platforms (!) - // message box under Windows and others -#if wxUSE_GUI && !defined(__UNIX__) - #ifdef __WXMOTIF__ - wxMessageOutput::Set(new wxMessageOutputLog); - #else - wxMessageOutput::Set(new wxMessageOutputMessageBox); - #endif -#else - wxMessageOutput::Set(new wxMessageOutputStderr); -#endif -} - // ---------------------------------------------------------------------------- // cmd line parsing // ---------------------------------------------------------------------------- bool wxAppBase::OnInit() { - DoInit(); #if wxUSE_CMDLINE_PARSER wxCmdLineParser parser(argc, argv); @@ -360,10 +378,11 @@ bool wxAppBase::OnCmdLineParsed(wxCmdLineParser& parser) if ( !theme ) { wxLogError(_("Unsupported theme '%s'."), themeName.c_str()); - return FALSE; } + // Delete the defaultly created theme and set the new theme. + delete wxTheme::Get(); wxTheme::Set(theme); } #endif // __WXUNIVERSAL__ @@ -376,7 +395,6 @@ bool wxAppBase::OnCmdLineParsed(wxCmdLineParser& parser) if ( wxSscanf(modeDesc.c_str(), _T("%ux%u-%u"), &w, &h, &bpp) != 3 ) { wxLogError(_("Invalid display mode specification '%s'."), modeDesc.c_str()); - return FALSE; } @@ -425,8 +443,23 @@ bool wxAppBase::CheckBuildOptions(const wxBuildOptions& opts) if ( !(wxCMP(isDebug) && wxCMP(verMaj) && wxCMP(verMin)) ) { - wxLogFatalError(_T("Mismatch between the program and library build ") - _T("versions detected.")); + wxString msg; + wxString libDebug, progDebug; + + if (isDebug) + libDebug = wxT("debug"); + else + libDebug = wxT("no debug"); + + if (opts.m_isDebug) + progDebug = wxT("debug"); + else + progDebug = wxT("no debug"); + + msg.Printf(_T("Mismatch between the program and library build versions detected.\nThe library used %d.%d (%s), and your program used %d.%d (%s)."), + verMaj, verMin, libDebug.c_str(), opts.m_verMaj, opts.m_verMin, progDebug.c_str()); + + wxLogFatalError(msg); // normally wxLogFatalError doesn't return return FALSE; @@ -440,6 +473,7 @@ bool wxAppBase::CheckBuildOptions(const wxBuildOptions& opts) static void LINKAGEMODE SetTraceMasks() { +#if wxUSE_LOG wxString mask; if ( wxGetEnv(wxT("WXTRACE"), &mask) ) { @@ -447,6 +481,7 @@ static void LINKAGEMODE SetTraceMasks() while ( tkn.HasMoreTokens() ) wxLog::AddTraceMask(tkn.GetNextToken()); } +#endif // wxUSE_LOG } // wxASSERT() helper @@ -473,6 +508,17 @@ void wxTrap() #endif // Win/Unix } + +void wxAssert(int cond, + const wxChar *szFile, + int nLine, + const wxChar *szCond, + const wxChar *szMsg) +{ + if ( !cond ) + wxOnAssert(szFile, nLine, szCond, szMsg); +} + // show the assert modal dialog static void ShowAssertDialog(const wxChar *szFile, @@ -502,6 +548,24 @@ void ShowAssertDialog(const wxChar *szFile, wxStrcat(szBuf, wxT(".")); } +#if wxUSE_THREADS + // if we are not in the main thread, + // output the assert directly and trap since dialogs cannot be displayed + if (!wxThread::IsMain()) { + wxStrcat(szBuf, wxT(" [in child thread]")); +#if defined(__WXMSW__) && !defined(__WXMICROWIN__) + wxStrcat(szBuf, wxT("\r\n")); + OutputDebugString(szBuf); +#else + // send to stderr + wxFprintf(stderr, wxT("%s\n"), szBuf); + fflush(stderr); +#endif + // He-e-e-e-elp!! we're asserting in a child thread + wxTrap(); + } +#endif // wxUSE_THREADS + if ( !s_bNoAsserts ) { // send it to the normal log destination