From: Vadim Zeitlin Date: Thu, 9 May 2002 15:59:42 +0000 (+0000) Subject: added (and documented) wxSafeShowMessage, use it in wxLogFatalError instead of wxMess... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/c11d62a6e22ead4c327b7ad45ad466b451b1aff6 added (and documented) wxSafeShowMessage, use it in wxLogFatalError instead of wxMessageBox git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15466 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/latex/wx/function.tex b/docs/latex/wx/function.tex index 2568e53be0..8bcd603ee0 100644 --- a/docs/latex/wx/function.tex +++ b/docs/latex/wx/function.tex @@ -180,6 +180,7 @@ the corresponding topic. \helpref{wxResourceRegisterBitmapData}{registerbitmapdata}\\ \helpref{wxResourceRegisterIconData}{wxresourceregistericondata}\\ \helpref{wxRmdir}{wxrmdir}\\ +\helpref{wxSafeShowMessage}{wxsafeshowmessage}\\ \helpref{wxSafeYield}{wxsafeyield}\\ \helpref{wxSetClipboardData}{wxsetclipboarddata}\\ \helpref{wxSetCursor}{wxsetcursor}\\ @@ -3168,6 +3169,32 @@ trace masks. \item wxTraceOleCalls: trace OLE method calls (Win32 only) \end{itemize} +\membersection{::wxSafeShowMessage}\label{wxsafeshowmessage} + +\func{void}{wxSafeShowMessage}{\param{const wxString\& }{title}, \param{const wxString\& }{text}} + +This function shows a message to the user in a safe way and should be safe to +call even before the application has been initialized or if it is currently in +some other strange state (for example, about to crash). Under Windows this +function shows a message box using a native dialog instead of +\helpref{wxMessageBox}{wxmessagebox} (which might be unsafe to call), elsewhere +it simply prints the message to the standard output using the title as prefix. + +\wxheading{Parameters} + +\docparam{title}{The title of the message box shown to the user or the prefix +of the message string} + +\docparam{text}{The text to show to the user} + +\wxheading{See also} + +\helpref{wxLogFatalError}{wxlogfatalerror} + +\wxheading{Include files} + + + \membersection{::wxSysErrorCode}\label{wxsyserrorcode} \func{unsigned long}{wxSysErrorCode}{\void} diff --git a/include/wx/log.h b/include/wx/log.h index f505a16237..00485e46de 100644 --- a/include/wx/log.h +++ b/include/wx/log.h @@ -476,11 +476,13 @@ private: // return the last system error code WXDLLEXPORT unsigned long wxSysErrorCode(); + // return the error message for given (or last if 0) error code WXDLLEXPORT const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0); +// ---------------------------------------------------------------------------- // define wxLog -// ------------------- +// ---------------------------------------------------------------------------- #define DECLARE_LOG_FUNCTION(level) \ extern void WXDLLEXPORT wxVLog##level(const wxChar *szFormat, \ @@ -559,6 +561,10 @@ DECLARE_LOG_FUNCTION2(SysError, long lErrCode); inline void wxLogTrace(const wxChar *, const wxChar *, ...) { } #endif // debug/!debug +// wxLogFatalError helper: show the (fatal) error to the user in a safe way, +// i.e. without using wxMessageBox() for example because it could crash +extern void wxSafeShowMessage(const wxString& title, const wxString& text); + // ---------------------------------------------------------------------------- // debug only logging functions: use them with API name and error code // ---------------------------------------------------------------------------- @@ -588,4 +594,3 @@ DECLARE_LOG_FUNCTION2(SysError, long lErrCode); #endif // _WX_LOG_H_ -// vi:sts=4:sw=4:et diff --git a/src/common/log.cpp b/src/common/log.cpp index 93842ef100..b577f27aef 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -159,17 +159,22 @@ IMPLEMENT_LOG_FUNCTION(Message) IMPLEMENT_LOG_FUNCTION(Info) IMPLEMENT_LOG_FUNCTION(Status) +void wxSafeShowMessage(const wxString& title, const wxString& text) +{ +#ifdef __WINDOWS__ + ::MessageBox(NULL, text, title, MB_OK | MB_ICONSTOP); +#else + wxFprintf(stderr, _T("%s: %s\n"), title.c_str(), text.c_str()); +#endif +} + // fatal errors can't be suppressed nor handled by the custom log target and // always terminate the program void wxVLogFatalError(const wxChar *szFormat, va_list argptr) { wxVsnprintf(s_szBuf, s_szBufSize, szFormat, argptr); -#if wxUSE_GUI - wxMessageBox(s_szBuf, _("Fatal Error"), wxID_OK | wxICON_STOP); -#else - wxFprintf(stderr, _("Fatal error: %s\n"), s_szBuf); -#endif + wxSafeShowMessage(_T("Fatal Error"), s_szBuf); abort(); }