]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msgout.h
use WPARAM (which is 64 bit under Win64) for timer ids instead of long (which is...
[wxWidgets.git] / include / wx / msgout.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msgout.h
3 // Purpose: wxMessageOutput class. Shows a message to the user
4 // Author: Mattia Barbon
5 // Modified by:
6 // Created: 17.07.02
7 // RCS-ID: $Id$
8 // Copyright: (c) Mattia Barbon
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MSGOUT_H_
13 #define _WX_MSGOUT_H_
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #include "wx/defs.h"
20 #include "wx/chartype.h"
21 #include "wx/strvararg.h"
22
23 // ----------------------------------------------------------------------------
24 // wxMessageOutput is a class abstracting formatted output target, i.e.
25 // something you can printf() to
26 // ----------------------------------------------------------------------------
27
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
34 {
35 public:
36 virtual ~wxMessageOutputBase() { }
37
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)
42 #ifdef __WATCOMC__
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)));
52 #endif
53
54 // called by DoPrintf() to output formatted string but can also be called
55 // directly if no formatting is needed
56 virtual void Output(const wxString& str) = 0;
57
58 protected:
59 // NB: this is pure virtual so that it can be implemented in dllexported
60 // wxMessagOutput class
61 #if !wxUSE_UTF8_LOCALE_ONLY
62 virtual void DoPrintfWchar(const wxChar *format, ...) = 0;
63 #endif
64 #if wxUSE_UNICODE_UTF8
65 virtual void DoPrintfUtf8(const char *format, ...) = 0;
66 #endif
67 };
68
69 #ifdef __VISUALC__
70 // "non dll-interface class 'wxStringPrintfMixin' used as base interface
71 // for dll-interface class 'wxString'" -- this is OK in our case
72 #pragma warning (push)
73 #pragma warning (disable:4275)
74 #endif
75
76 class WXDLLIMPEXP_BASE wxMessageOutput : public wxMessageOutputBase
77 {
78 public:
79 virtual ~wxMessageOutput() { }
80
81 // gets the current wxMessageOutput object (may be NULL during
82 // initialization or shutdown)
83 static wxMessageOutput* Get();
84
85 // sets the global wxMessageOutput instance; returns the previous one
86 static wxMessageOutput* Set(wxMessageOutput* msgout);
87
88 protected:
89 #if !wxUSE_UTF8_LOCALE_ONLY
90 virtual void DoPrintfWchar(const wxChar *format, ...);
91 #endif
92 #if wxUSE_UNICODE_UTF8
93 virtual void DoPrintfUtf8(const char *format, ...);
94 #endif
95
96 private:
97 static wxMessageOutput* ms_msgOut;
98 };
99
100 #ifdef __VISUALC__
101 #pragma warning (pop)
102 #endif
103
104 // ----------------------------------------------------------------------------
105 // implementation which sends output to stderr
106 // ----------------------------------------------------------------------------
107
108 class WXDLLIMPEXP_BASE wxMessageOutputStderr : public wxMessageOutput
109 {
110 public:
111 wxMessageOutputStderr() { }
112
113 virtual void Output(const wxString& str);
114
115 protected:
116 // return the string with "\n" appended if it doesn't already terminate
117 // with it (in which case it's returned unchanged)
118 wxString AppendLineFeedIfNeeded(const wxString& str);
119 };
120
121 // ----------------------------------------------------------------------------
122 // implementation showing the message to the user in "best" possible way:
123 // uses stderr or message box if available according to the flag given to ctor.
124 // ----------------------------------------------------------------------------
125
126 enum wxMessageOutputFlags
127 {
128 wxMSGOUT_PREFER_STDERR = 0, // use stderr if available (this is the default)
129 wxMSGOUT_PREFER_MSGBOX = 1 // always use message box if available
130 };
131
132 class WXDLLIMPEXP_BASE wxMessageOutputBest : public wxMessageOutputStderr
133 {
134 public:
135 wxMessageOutputBest(wxMessageOutputFlags flags = wxMSGOUT_PREFER_STDERR)
136 : m_flags(flags) { }
137
138 virtual void Output(const wxString& str);
139
140 private:
141 wxMessageOutputFlags m_flags;
142 };
143
144 // ----------------------------------------------------------------------------
145 // implementation which shows output in a message box
146 // ----------------------------------------------------------------------------
147
148 #if wxUSE_GUI && wxUSE_MSGDLG
149
150 class WXDLLIMPEXP_CORE wxMessageOutputMessageBox : public wxMessageOutput
151 {
152 public:
153 wxMessageOutputMessageBox() { }
154
155 virtual void Output(const wxString& str);
156 };
157
158 #endif // wxUSE_GUI && wxUSE_MSGDLG
159
160 // ----------------------------------------------------------------------------
161 // implementation using the native way of outputting debug messages
162 // ----------------------------------------------------------------------------
163
164 class WXDLLIMPEXP_BASE wxMessageOutputDebug : public wxMessageOutputStderr
165 {
166 public:
167 wxMessageOutputDebug() { }
168
169 virtual void Output(const wxString& str);
170 };
171
172 // ----------------------------------------------------------------------------
173 // implementation using wxLog (mainly for backwards compatibility)
174 // ----------------------------------------------------------------------------
175
176 class WXDLLIMPEXP_BASE wxMessageOutputLog : public wxMessageOutput
177 {
178 public:
179 wxMessageOutputLog() { }
180
181 virtual void Output(const wxString& str);
182 };
183
184 #endif // _WX_MSGOUT_H_