Use new wxAppTraits::SafeMessageBox() in wxSafeShowMessage()

This allows to show message boxes in ports other than wxMSW too by doing
it only when it is safe, i.e. when the GUI is initialized, while still
keeping the old code directly using the native MessageBox() function for
MSW for maximal robustness.
This commit is contained in:
Vadim Zeitlin
2021-03-07 20:50:30 +01:00
parent fdd4ff8bf9
commit e00d5e131b
7 changed files with 107 additions and 28 deletions

View File

@@ -25,6 +25,7 @@
#include "wx/window.h"
#include "wx/bitmap.h"
#include "wx/log.h"
#include "wx/module.h"
#include "wx/msgdlg.h"
#include "wx/confbase.h"
#include "wx/utils.h"
@@ -584,3 +585,21 @@ bool wxGUIAppTraitsBase::HasStderr()
#endif
}
#ifndef __WIN32__
bool wxGUIAppTraitsBase::SafeMessageBox(const wxString& text,
const wxString& title)
{
// The modules are initialized only after a successful call to
// wxApp::Initialize() in wxEntryStart, so it can be used as a proxy for
// GUI availability (note that the mere existence of wxTheApp is not enough
// for this).
if ( !wxModule::AreInitialized() )
return false;
wxMessageBox(text, title, wxOK | wxICON_ERROR);
return true;
}
#endif // !__WIN32__