1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMessageOutput class. Shows a message to the user
4 // Author: Mattia Barbon
8 // Copyright: (c) Mattia Barbon
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
20 #include "wx/chartype.h"
21 #include "wx/strvararg.h"
23 // ----------------------------------------------------------------------------
24 // wxMessageOutput is a class abstracting formatted output target, i.e.
25 // something you can printf() to
26 // ----------------------------------------------------------------------------
28 // NB: VC6 has a bug that causes linker errors if you have template methods
29 // in a class using __declspec(dllimport). The solution is to split such
30 // class into two classes, one that contains the template methods and does
31 // *not* use WXDLLIMPEXP_BASE and another class that contains the rest
32 // (with DLL linkage).
33 class wxMessageOutputBase
36 virtual ~wxMessageOutputBase() { }
38 // show a message to the user
39 // void Printf(const wxString& format, ...) = 0;
40 WX_DEFINE_VARARG_FUNC_VOID(Printf
, 1, (const wxFormatString
&),
41 DoPrintfWchar
, DoPrintfUtf8
)
43 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
44 WX_VARARG_WATCOM_WORKAROUND(void, Printf
, 1, (const wxString
&),
45 (wxFormatString(f1
)));
46 WX_VARARG_WATCOM_WORKAROUND(void, Printf
, 1, (const wxCStrData
&),
47 (wxFormatString(f1
)));
48 WX_VARARG_WATCOM_WORKAROUND(void, Printf
, 1, (const char*),
49 (wxFormatString(f1
)));
50 WX_VARARG_WATCOM_WORKAROUND(void, Printf
, 1, (const wchar_t*),
51 (wxFormatString(f1
)));
55 // NB: this is pure virtual so that it can be implemented in dllexported
56 // wxMessagOutput class
57 #if !wxUSE_UTF8_LOCALE_ONLY
58 virtual void DoPrintfWchar(const wxChar
*format
, ...) = 0;
60 #if wxUSE_UNICODE_UTF8
61 virtual void DoPrintfUtf8(const char *format
, ...) = 0;
64 // called by DoPrintf() to output formatted string
65 virtual void Output(const wxString
& str
) = 0;
69 // "non dll-interface class 'wxStringPrintfMixin' used as base interface
70 // for dll-interface class 'wxString'" -- this is OK in our case
71 #pragma warning (disable:4275)
74 class WXDLLIMPEXP_BASE wxMessageOutput
: public wxMessageOutputBase
77 virtual ~wxMessageOutput() { }
79 // gets the current wxMessageOutput object (may be NULL during
80 // initialization or shutdown)
81 static wxMessageOutput
* Get();
83 // sets the global wxMessageOutput instance; returns the previous one
84 static wxMessageOutput
* Set(wxMessageOutput
* msgout
);
87 #if !wxUSE_UTF8_LOCALE_ONLY
88 virtual void DoPrintfWchar(const wxChar
*format
, ...);
90 #if wxUSE_UNICODE_UTF8
91 virtual void DoPrintfUtf8(const char *format
, ...);
93 virtual void Output(const wxString
& str
) = 0;
96 static wxMessageOutput
* ms_msgOut
;
100 #pragma warning (default:4275)
103 // ----------------------------------------------------------------------------
104 // implementation showing the message to the user in "best" possible way: uses
105 // native message box if available (currently only under Windows) and stderr
106 // otherwise; unlike wxMessageOutputMessageBox this class is always safe to use
107 // ----------------------------------------------------------------------------
109 class WXDLLIMPEXP_BASE wxMessageOutputBest
: public wxMessageOutput
112 wxMessageOutputBest() { }
115 virtual void Output(const wxString
& str
);
118 // ----------------------------------------------------------------------------
119 // implementation which sends output to stderr
120 // ----------------------------------------------------------------------------
122 class WXDLLIMPEXP_BASE wxMessageOutputStderr
: public wxMessageOutput
125 wxMessageOutputStderr() { }
128 virtual void Output(const wxString
& str
);
131 // ----------------------------------------------------------------------------
132 // implementation which shows output in a message box
133 // ----------------------------------------------------------------------------
135 #if wxUSE_GUI && wxUSE_MSGDLG
137 class WXDLLIMPEXP_CORE wxMessageOutputMessageBox
: public wxMessageOutput
140 wxMessageOutputMessageBox() { }
143 virtual void Output(const wxString
& str
);
146 #endif // wxUSE_GUI && wxUSE_MSGDLG
148 // ----------------------------------------------------------------------------
149 // implementation using the native way of outputting debug messages
150 // ----------------------------------------------------------------------------
152 class WXDLLIMPEXP_BASE wxMessageOutputDebug
: public wxMessageOutput
155 wxMessageOutputDebug() { }
158 virtual void Output(const wxString
& str
);
161 // ----------------------------------------------------------------------------
162 // implementation using wxLog (mainly for backwards compatibility)
163 // ----------------------------------------------------------------------------
165 class WXDLLIMPEXP_BASE wxMessageOutputLog
: public wxMessageOutput
168 wxMessageOutputLog() { }
171 virtual void Output(const wxString
& str
);