Use wxApp::GetTraitsIfExists() wrappers when applicable

This is simpler and more clear than testing wxTheApp explicitly.

No real changes.
This commit is contained in:
Vadim Zeitlin
2021-03-07 15:43:55 +01:00
parent 69e48f036b
commit 9073221584
11 changed files with 11 additions and 13 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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();

View File

@@ -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();

View File

@@ -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'));

View File

@@ -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) )

View File

@@ -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") );

View File

@@ -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());

View File

@@ -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();

View File

@@ -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 )
{

View File

@@ -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;