From 9073221584f3fed50a1786db3313e4eabc1823d7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 7 Mar 2021 15:43:55 +0100 Subject: [PATCH] Use wxApp::GetTraitsIfExists() wrappers when applicable This is simpler and more clear than testing wxTheApp explicitly. No real changes. --- src/common/appbase.cpp | 2 +- src/common/cmdline.cpp | 3 +-- src/common/config.cpp | 2 +- src/common/fmapbase.cpp | 2 +- src/common/log.cpp | 2 +- src/common/msgout.cpp | 2 +- src/common/platinfo.cpp | 2 +- src/common/rendcmn.cpp | 3 +-- src/common/stdpbase.cpp | 2 +- src/common/timercmn.cpp | 2 +- src/msw/utilsexc.cpp | 2 +- 11 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/common/appbase.cpp b/src/common/appbase.cpp index 7d1467f2c2..af819469b2 100644 --- a/src/common/appbase.cpp +++ b/src/common/appbase.cpp @@ -358,7 +358,7 @@ wxAppTraits *wxAppConsoleBase::GetTraitsIfExists() wxAppTraits& wxAppConsoleBase::GetValidTraits() { static wxConsoleAppTraits s_traitsConsole; - wxAppTraits* const traits = (wxTheApp ? wxTheApp->GetTraits() : NULL); + wxAppTraits* const traits = GetTraitsIfExists(); return *(traits ? traits : &s_traitsConsole); } diff --git a/src/common/cmdline.cpp b/src/common/cmdline.cpp index eb2b806830..531f7a772f 100644 --- a/src/common/cmdline.cpp +++ b/src/common/cmdline.cpp @@ -1430,9 +1430,8 @@ wxString wxCmdLineParser::GetUsageString() const count = namesOptions.size(); // get option names & descriptions for standard options, if any: - wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL; wxString stdDesc; - if ( traits ) + if ( wxAppTraits *traits = wxApp::GetTraitsIfExists() ) stdDesc = traits->GetStandardCmdLineOptions(namesOptions, descOptions); // now construct the detailed help message diff --git a/src/common/config.cpp b/src/common/config.cpp index 6cbded738d..f2ea75e3be 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -98,7 +98,7 @@ wxConfigBase *wxConfigBase::Set(wxConfigBase *pConfig) wxConfigBase *wxConfigBase::Create() { if ( ms_bAutoCreate && ms_pConfig == NULL ) { - wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL; + wxAppTraits * const traits = wxApp::GetTraitsIfExists(); wxCHECK_MSG( traits, NULL, wxT("create wxApp before calling this") ); ms_pConfig = traits->CreateConfig(); diff --git a/src/common/fmapbase.cpp b/src/common/fmapbase.cpp index 32b1d3bf49..21704ea4d4 100644 --- a/src/common/fmapbase.cpp +++ b/src/common/fmapbase.cpp @@ -413,7 +413,7 @@ wxFontMapperBase *wxFontMapperBase::Get() { if ( !sm_instance ) { - wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL; + wxAppTraits *traits = wxApp::GetTraitsIfExists(); if ( traits ) { sm_instance = traits->CreateFontMapper(); diff --git a/src/common/log.cpp b/src/common/log.cpp index 85e8b4fd61..3bf1c33d40 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -892,7 +892,7 @@ void wxLogStderr::DoLogText(const wxString& msg) // simply lost if ( m_fp == stderr ) { - wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL; + wxAppTraits *traits = wxApp::GetTraitsIfExists(); if ( traits && !traits->HasStderr() ) { wxMessageOutputDebug().Output(msg + wxS('\n')); diff --git a/src/common/msgout.cpp b/src/common/msgout.cpp index bae7b781b3..0511224168 100644 --- a/src/common/msgout.cpp +++ b/src/common/msgout.cpp @@ -105,7 +105,7 @@ void wxMessageOutputBest::Output(const wxString& str) { #ifdef __WINDOWS__ // decide whether to use console output or not - wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL; + wxAppTraits * const traits = wxApp::GetTraitsIfExists(); const bool hasStderr = traits ? traits->CanUseStderr() : false; if ( !(m_flags & wxMSGOUT_PREFER_MSGBOX) ) diff --git a/src/common/platinfo.cpp b/src/common/platinfo.cpp index f06e0706e7..b19f6f9e09 100644 --- a/src/common/platinfo.cpp +++ b/src/common/platinfo.cpp @@ -174,7 +174,7 @@ void wxPlatformInfo::InitForCurrentPlatform() m_initializedForCurrentPlatform = true; // autodetect all informations - const wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL; + const wxAppTraits * const traits = wxApp::GetTraitsIfExists(); if ( !traits ) { wxFAIL_MSG( wxT("failed to initialize wxPlatformInfo") ); diff --git a/src/common/rendcmn.cpp b/src/common/rendcmn.cpp index 0f02a2740a..d17940b427 100644 --- a/src/common/rendcmn.cpp +++ b/src/common/rendcmn.cpp @@ -65,8 +65,7 @@ private: void DoInit() { - wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL; - if ( traits ) + if ( wxAppTraits *traits = wxApp::GetTraitsIfExists() ) { // ask the traits object to create a renderer for us reset(traits->CreateRenderer()); diff --git a/src/common/stdpbase.cpp b/src/common/stdpbase.cpp index 59897b33af..5f5c12a0c8 100644 --- a/src/common/stdpbase.cpp +++ b/src/common/stdpbase.cpp @@ -55,7 +55,7 @@ static wxStandardPathsDefault gs_stdPaths; /* static */ wxStandardPaths& wxStandardPathsBase::Get() { - wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL; + wxAppTraits * const traits = wxApp::GetTraitsIfExists(); wxCHECK_MSG( traits, gs_stdPaths, wxT("create wxApp before calling this") ); return traits->GetStandardPaths(); diff --git a/src/common/timercmn.cpp b/src/common/timercmn.cpp index 0f8f1f41f4..943ef10ec7 100644 --- a/src/common/timercmn.cpp +++ b/src/common/timercmn.cpp @@ -54,7 +54,7 @@ wxTimer::~wxTimer() void wxTimer::Init() { - wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL; + wxAppTraits * const traits = wxApp::GetTraitsIfExists(); m_impl = traits ? traits->CreateTimerImpl(this) : NULL; if ( !m_impl ) { diff --git a/src/msw/utilsexc.cpp b/src/msw/utilsexc.cpp index 0ebdd59d24..e23b22fc26 100644 --- a/src/msw/utilsexc.cpp +++ b/src/msw/utilsexc.cpp @@ -1018,7 +1018,7 @@ long wxExecute(const wxString& cmd, int flags, wxProcess *handler, return pi.dwProcessId; } - wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL; + wxAppTraits *traits = wxApp::GetTraitsIfExists(); wxCHECK_MSG( traits, -1, wxT("no wxAppTraits in wxExecute()?") ); void *cookie = NULL;