Merge branch 'safe-show-message'

Show message box from wxSafeShowMessage() in the other ports too, if
possible.

Currently this is done using wxMessageBox() if it can be sure that it's
safe to call and only MSW uses native function which is always safe to
call. Ideal would be to also use a native function under Mac, where it
should also be the case, but this doesn't seem to work for whichever
reason.

See https://github.com/wxWidgets/wxWidgets/pull/2270
This commit is contained in:
Vadim Zeitlin
2021-03-23 18:59:51 +01:00
34 changed files with 194 additions and 47 deletions

View File

@@ -622,6 +622,10 @@ public:
// there are none, will return NULL)
virtual wxWindow *GetTopWindow() const;
// convenient helper which is safe to use even if there is no wxApp at
// all, it will just return NULL in this case
static wxWindow *GetMainTopWindow();
// control the exit behaviour: by default, the program will exit the
// main loop (and so, usually, terminate) when the last top-level
// program window is deleted. Beware that if you disable this behaviour

View File

@@ -88,6 +88,16 @@ public:
// return true to suppress subsequent asserts, false to continue as before
virtual bool ShowAssertDialog(const wxString& msg) = 0;
// show the message safely to the user, i.e. show it in a message box if
// possible (even in a console application!) or return false if we can't do
// it (e.g. GUI is not initialized at all)
//
// note that this function can be called even when wxApp doesn't exist, as
// it's supposed to be always safe to call -- hence the name
//
// return true if the message box was shown, false if nothing was done
virtual bool SafeMessageBox(const wxString& text, const wxString& title) = 0;
// return true if fprintf(stderr) goes somewhere, false otherwise
virtual bool HasStderr() = 0;
@@ -208,6 +218,8 @@ public:
virtual bool ShowAssertDialog(const wxString& msg) wxOVERRIDE;
virtual bool HasStderr() wxOVERRIDE;
virtual bool SafeMessageBox(const wxString& text,
const wxString& title) wxOVERRIDE;
// the GetToolkitVersion for console application is always the same
wxPortId GetToolkitVersion(int *verMaj = NULL,
@@ -248,6 +260,13 @@ public:
virtual bool ShowAssertDialog(const wxString& msg) wxOVERRIDE;
virtual bool HasStderr() wxOVERRIDE;
// Win32 has its own implementation using native message box directly in
// the base class, don't override it.
#ifndef __WIN32__
virtual bool SafeMessageBox(const wxString& text,
const wxString& title) wxOVERRIDE;
#endif // !__WIN32__
virtual bool IsUsingUniversalWidgets() const wxOVERRIDE
{
#ifdef __WXUNIVERSAL__

View File

@@ -1459,7 +1459,7 @@ inline void wxLogNop() { }
// wxLogFatalError helper: show the (fatal) error to the user in a safe way,
// i.e. without using wxMessageBox() for example because it could crash
void WXDLLIMPEXP_BASE
bool WXDLLIMPEXP_BASE
wxSafeShowMessage(const wxString& title, const wxString& text);
// ----------------------------------------------------------------------------

View File

@@ -58,6 +58,13 @@ 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;
// implement this base class function for both console and GUI applications
virtual bool SafeMessageBox(const wxString& text,
const wxString& title) wxOVERRIDE;
protected:
#if wxUSE_THREADS
// implementation of WaitForThread() for the console applications which is

View File

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