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 wxChar* format, ...) ATTRIBUTE_PRINTF_2 = 0;
40 WX_DEFINE_VARARG_FUNC_VOID(Printf
, DoPrintf
)
43 // NB: this is pure virtual so that it can be implemented in dllexported
44 // wxMessagOutput class
45 virtual void DoPrintf(const wxChar
* format
, ...) ATTRIBUTE_PRINTF_2
= 0;
47 // called by DoPrintf() to output formatted string
48 virtual void Output(const wxString
& str
) = 0;
52 // "non dll-interface class 'wxStringPrintfMixin' used as base interface
53 // for dll-interface class 'wxString'" -- this is OK in our case
54 #pragma warning (disable:4275)
57 class WXDLLIMPEXP_BASE wxMessageOutput
: public wxMessageOutputBase
60 virtual ~wxMessageOutput() { }
62 // gets the current wxMessageOutput object (may be NULL during
63 // initialization or shutdown)
64 static wxMessageOutput
* Get();
66 // sets the global wxMessageOutput instance; returns the previous one
67 static wxMessageOutput
* Set(wxMessageOutput
* msgout
);
70 virtual void DoPrintf(const wxChar
* format
, ...) ATTRIBUTE_PRINTF_2
;
71 virtual void Output(const wxString
& str
) = 0;
74 static wxMessageOutput
* ms_msgOut
;
78 #pragma warning (default:4275)
81 // ----------------------------------------------------------------------------
82 // implementation showing the message to the user in "best" possible way: uses
83 // native message box if available (currently only under Windows) and stderr
84 // otherwise; unlike wxMessageOutputMessageBox this class is always safe to use
85 // ----------------------------------------------------------------------------
87 class WXDLLIMPEXP_BASE wxMessageOutputBest
: public wxMessageOutput
90 wxMessageOutputBest() { }
93 virtual void Output(const wxString
& str
);
96 // ----------------------------------------------------------------------------
97 // implementation which sends output to stderr
98 // ----------------------------------------------------------------------------
100 class WXDLLIMPEXP_BASE wxMessageOutputStderr
: public wxMessageOutput
103 wxMessageOutputStderr() { }
106 virtual void Output(const wxString
& str
);
109 // ----------------------------------------------------------------------------
110 // implementation which shows output in a message box
111 // ----------------------------------------------------------------------------
115 class WXDLLIMPEXP_CORE wxMessageOutputMessageBox
: public wxMessageOutput
118 wxMessageOutputMessageBox() { }
121 virtual void Output(const wxString
& str
);
126 // ----------------------------------------------------------------------------
127 // implementation using the native way of outputting debug messages
128 // ----------------------------------------------------------------------------
130 class WXDLLIMPEXP_BASE wxMessageOutputDebug
: public wxMessageOutput
133 wxMessageOutputDebug() { }
136 virtual void Output(const wxString
& str
);
139 // ----------------------------------------------------------------------------
140 // implementation using wxLog (mainly for backwards compatibility)
141 // ----------------------------------------------------------------------------
143 class WXDLLIMPEXP_BASE wxMessageOutputLog
: public wxMessageOutput
146 wxMessageOutputLog() { }
149 virtual void Output(const wxString
& str
);