From 77593c5996b3514ac807581a987183278e189737 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 14 Mar 2021 13:18:36 +0100 Subject: [PATCH] Add return value to wxSafeShowMessage() This allows the caller to log the message to the console in addition to showing the message box, for example. Previously, this would be impossible to do without getting the duplicates if the message box was not shown, but now it is. --- include/wx/log.h | 2 +- interface/wx/log.h | 7 ++++++- src/common/log.cpp | 6 +++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/wx/log.h b/include/wx/log.h index f3552e9724..b6d3ecc209 100644 --- a/include/wx/log.h +++ b/include/wx/log.h @@ -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); // ---------------------------------------------------------------------------- diff --git a/interface/wx/log.h b/interface/wx/log.h index f875709dba..62f46a2e5c 100644 --- a/interface/wx/log.h +++ b/interface/wx/log.h @@ -1268,12 +1268,17 @@ public: message string. @param text The text to show to the user. + @return + @true If a message box was actually shown or @false if the message was + logged to the console because there is no safe to show it currently + (the return value is only available since wxWidgets 3.1.5, the function + doesn't return anything in the previous versions). @see wxLogFatalError() @header{wx/log.h} */ -void wxSafeShowMessage(const wxString& title, const wxString& text); +bool wxSafeShowMessage(const wxString& title, const wxString& text); /** Returns the error code from the last system call. This function uses diff --git a/src/common/log.cpp b/src/common/log.cpp index c5ab359fd0..ee11051613 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -180,13 +180,17 @@ private: // helper global functions // ---------------------------------------------------------------------------- -void wxSafeShowMessage(const wxString& title, const wxString& text) +bool wxSafeShowMessage(const wxString& title, const wxString& text) { if ( !wxApp::GetValidTraits().SafeMessageBox(text, title) ) { wxFprintf(stderr, wxS("%s: %s\n"), title.c_str(), text.c_str()); fflush(stderr); + return false; } + + // Message box actually shown. + return true; } // ----------------------------------------------------------------------------