Add a helper wxApp::GetValidTraits() method.

This method always returns some valid traits, even if we don't have wxTheApp
(which is possible in the console applications) or if its GetTraits() was
overridden to return NULL (which shouldn't be, but still guard against this).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74349 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2013-07-03 00:31:49 +00:00
parent c36ddebf93
commit 76015a6bb7
3 changed files with 19 additions and 8 deletions

View File

@@ -124,15 +124,9 @@ wxEventLoopBase::AddSourceForFD(int fd,
wxEventLoopSourceHandler *handler,
int flags)
{
// Ensure that we have some valid traits.
wxConsoleAppTraits traitsConsole;
wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
if ( !traits )
traits = &traitsConsole;
// And delegate to the event loop sources manager defined by it.
// Delegate to the event loop sources manager defined by it.
wxEventLoopSourcesManagerBase* const
manager = traits->GetEventLoopSourcesManager();
manager = wxApp::GetValidTraits().GetEventLoopSourcesManager();
wxCHECK_MSG( manager, NULL, wxS("Must have wxEventLoopSourcesManager") );
return manager->AddSourceForFD(fd, handler, flags);