Disable main window when showing msgbox in wxSafeShowMessage()
Pass correct parent HWND to ::MessageBox() in order to disable the window while the message box is shown, as this function is supposed to be similar to modal wxMessageBox() and it was unexpected that the application could be reentered via the event handlers from inside it. This required adding wxAppTraits::GetMainHWND() in order to only use the HWND in GUI applications from the function defined in non-GUI code.
This commit is contained in:
@@ -58,6 +58,9 @@ public:
|
||||
// write text to the console, return true if ok or false on error
|
||||
virtual bool WriteToStderr(const wxString& text) = 0;
|
||||
|
||||
// return the main application window or 0 if none
|
||||
virtual WXHWND GetMainHWND() const = 0;
|
||||
|
||||
protected:
|
||||
#if wxUSE_THREADS
|
||||
// implementation of WaitForThread() for the console applications which is
|
||||
|
@@ -30,6 +30,7 @@ public:
|
||||
#endif // wxUSE_THREADS
|
||||
virtual bool CanUseStderr() wxOVERRIDE { return true; }
|
||||
virtual bool WriteToStderr(const wxString& text) wxOVERRIDE;
|
||||
virtual WXHWND GetMainHWND() const wxOVERRIDE { return NULL; }
|
||||
};
|
||||
|
||||
#if wxUSE_GUI
|
||||
@@ -55,6 +56,7 @@ public:
|
||||
|
||||
virtual bool CanUseStderr() wxOVERRIDE;
|
||||
virtual bool WriteToStderr(const wxString& text) wxOVERRIDE;
|
||||
virtual WXHWND GetMainHWND() const wxOVERRIDE;
|
||||
};
|
||||
|
||||
#elif defined(__WXGTK__)
|
||||
@@ -85,6 +87,7 @@ public:
|
||||
|
||||
virtual bool CanUseStderr() { return false; }
|
||||
virtual bool WriteToStderr(const wxString& WXUNUSED(text)) { return false; }
|
||||
virtual WXHWND GetMainHWND() const wxOVERRIDE { return NULL; }
|
||||
};
|
||||
|
||||
#elif defined(__WXQT__)
|
||||
@@ -110,6 +113,7 @@ public:
|
||||
|
||||
virtual bool CanUseStderr() { return false; }
|
||||
virtual bool WriteToStderr(const wxString&) { return false; }
|
||||
virtual WXHWND GetMainHWND() const wxOVERRIDE { return NULL; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -183,7 +183,9 @@ private:
|
||||
void wxSafeShowMessage(const wxString& title, const wxString& text)
|
||||
{
|
||||
#ifdef __WINDOWS__
|
||||
::MessageBox(NULL, text.t_str(), title.t_str(), MB_OK | MB_ICONSTOP);
|
||||
const wxAppTraits* const traits = wxApp::GetTraitsIfExists();
|
||||
::MessageBox(traits ? traits->GetMainHWND() : NULL,
|
||||
text.t_str(), title.t_str(), MB_OK | MB_ICONSTOP);
|
||||
#else
|
||||
wxFprintf(stderr, wxS("%s: %s\n"), title.c_str(), text.c_str());
|
||||
fflush(stderr);
|
||||
|
@@ -603,6 +603,12 @@ bool wxGUIAppTraits::WriteToStderr(const wxString& WXUNUSED(text))
|
||||
|
||||
#endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS
|
||||
|
||||
WXHWND wxGUIAppTraits::GetMainHWND() const
|
||||
{
|
||||
const wxWindow* const w = wxApp::GetMainTopWindow();
|
||||
return w ? w->GetHWND() : NULL;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// wxApp implementation
|
||||
// ===========================================================================
|
||||
|
Reference in New Issue
Block a user