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 wxString
&), DoPrintf
)
42 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
43 WX_DEFINE_VARARG_FUNC_VOID(Printf
, 1, (const char*), DoPrintf
)
44 WX_DEFINE_VARARG_FUNC_VOID(Printf
, 1, (const wchar_t*), DoPrintf
)
45 WX_DEFINE_VARARG_FUNC_VOID(Printf
, 1, (const wxCStrData
&), DoPrintf
)
49 // NB: this is pure virtual so that it can be implemented in dllexported
50 // wxMessagOutput class
51 virtual void DoPrintf(const wxString
& format
, ...) = 0;
53 // called by DoPrintf() to output formatted string
54 virtual void Output(const wxString
& str
) = 0;
58 // "non dll-interface class 'wxStringPrintfMixin' used as base interface
59 // for dll-interface class 'wxString'" -- this is OK in our case
60 #pragma warning (disable:4275)
63 class WXDLLIMPEXP_BASE wxMessageOutput
: public wxMessageOutputBase
66 virtual ~wxMessageOutput() { }
68 // gets the current wxMessageOutput object (may be NULL during
69 // initialization or shutdown)
70 static wxMessageOutput
* Get();
72 // sets the global wxMessageOutput instance; returns the previous one
73 static wxMessageOutput
* Set(wxMessageOutput
* msgout
);
76 virtual void DoPrintf(const wxString
& format
, ...);
77 virtual void Output(const wxString
& str
) = 0;
80 static wxMessageOutput
* ms_msgOut
;
84 #pragma warning (default:4275)
87 // ----------------------------------------------------------------------------
88 // implementation showing the message to the user in "best" possible way: uses
89 // native message box if available (currently only under Windows) and stderr
90 // otherwise; unlike wxMessageOutputMessageBox this class is always safe to use
91 // ----------------------------------------------------------------------------
93 class WXDLLIMPEXP_BASE wxMessageOutputBest
: public wxMessageOutput
96 wxMessageOutputBest() { }
99 virtual void Output(const wxString
& str
);
102 // ----------------------------------------------------------------------------
103 // implementation which sends output to stderr
104 // ----------------------------------------------------------------------------
106 class WXDLLIMPEXP_BASE wxMessageOutputStderr
: public wxMessageOutput
109 wxMessageOutputStderr() { }
112 virtual void Output(const wxString
& str
);
115 // ----------------------------------------------------------------------------
116 // implementation which shows output in a message box
117 // ----------------------------------------------------------------------------
121 class WXDLLIMPEXP_CORE wxMessageOutputMessageBox
: public wxMessageOutput
124 wxMessageOutputMessageBox() { }
127 virtual void Output(const wxString
& str
);
132 // ----------------------------------------------------------------------------
133 // implementation using the native way of outputting debug messages
134 // ----------------------------------------------------------------------------
136 class WXDLLIMPEXP_BASE wxMessageOutputDebug
: public wxMessageOutput
139 wxMessageOutputDebug() { }
142 virtual void Output(const wxString
& str
);
145 // ----------------------------------------------------------------------------
146 // implementation using wxLog (mainly for backwards compatibility)
147 // ----------------------------------------------------------------------------
149 class WXDLLIMPEXP_BASE wxMessageOutputLog
: public wxMessageOutput
152 wxMessageOutputLog() { }
155 virtual void Output(const wxString
& str
);