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_DEFINE_VARARG_FUNC_VOID(Printf
, 1, (const char*),
45 DoPrintfWchar
, DoPrintfUtf8
)
46 WX_DEFINE_VARARG_FUNC_VOID(Printf
, 1, (const wchar_t*),
47 DoPrintfWchar
, DoPrintfUtf8
)
48 WX_DEFINE_VARARG_FUNC_VOID(Printf
, 1, (const wxCStrData
&),
49 DoPrintfWchar
, DoPrintfUtf8
)
53 // NB: this is pure virtual so that it can be implemented in dllexported
54 // wxMessagOutput class
55 #if !wxUSE_UTF8_LOCALE_ONLY
56 virtual void DoPrintfWchar(const wxChar
*format
, ...) = 0;
58 #if wxUSE_UNICODE_UTF8
59 virtual void DoPrintfUtf8(const char *format
, ...) = 0;
62 // called by DoPrintf() to output formatted string
63 virtual void Output(const wxString
& str
) = 0;
67 // "non dll-interface class 'wxStringPrintfMixin' used as base interface
68 // for dll-interface class 'wxString'" -- this is OK in our case
69 #pragma warning (disable:4275)
72 class WXDLLIMPEXP_BASE wxMessageOutput
: public wxMessageOutputBase
75 virtual ~wxMessageOutput() { }
77 // gets the current wxMessageOutput object (may be NULL during
78 // initialization or shutdown)
79 static wxMessageOutput
* Get();
81 // sets the global wxMessageOutput instance; returns the previous one
82 static wxMessageOutput
* Set(wxMessageOutput
* msgout
);
85 #if !wxUSE_UTF8_LOCALE_ONLY
86 virtual void DoPrintfWchar(const wxChar
*format
, ...);
88 #if wxUSE_UNICODE_UTF8
89 virtual void DoPrintfUtf8(const char *format
, ...);
91 virtual void Output(const wxString
& str
) = 0;
94 static wxMessageOutput
* ms_msgOut
;
98 #pragma warning (default:4275)
101 // ----------------------------------------------------------------------------
102 // implementation showing the message to the user in "best" possible way: uses
103 // native message box if available (currently only under Windows) and stderr
104 // otherwise; unlike wxMessageOutputMessageBox this class is always safe to use
105 // ----------------------------------------------------------------------------
107 class WXDLLIMPEXP_BASE wxMessageOutputBest
: public wxMessageOutput
110 wxMessageOutputBest() { }
113 virtual void Output(const wxString
& str
);
116 // ----------------------------------------------------------------------------
117 // implementation which sends output to stderr
118 // ----------------------------------------------------------------------------
120 class WXDLLIMPEXP_BASE wxMessageOutputStderr
: public wxMessageOutput
123 wxMessageOutputStderr() { }
126 virtual void Output(const wxString
& str
);
129 // ----------------------------------------------------------------------------
130 // implementation which shows output in a message box
131 // ----------------------------------------------------------------------------
135 class WXDLLIMPEXP_CORE wxMessageOutputMessageBox
: public wxMessageOutput
138 wxMessageOutputMessageBox() { }
141 virtual void Output(const wxString
& str
);
146 // ----------------------------------------------------------------------------
147 // implementation using the native way of outputting debug messages
148 // ----------------------------------------------------------------------------
150 class WXDLLIMPEXP_BASE wxMessageOutputDebug
: public wxMessageOutput
153 wxMessageOutputDebug() { }
156 virtual void Output(const wxString
& str
);
159 // ----------------------------------------------------------------------------
160 // implementation using wxLog (mainly for backwards compatibility)
161 // ----------------------------------------------------------------------------
163 class WXDLLIMPEXP_BASE wxMessageOutputLog
: public wxMessageOutput
166 wxMessageOutputLog() { }
169 virtual void Output(const wxString
& str
);