]>
Commit | Line | Data |
---|---|---|
74698d3a MB |
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$ | |
99d80019 | 8 | // Copyright: (c) Mattia Barbon |
65571936 | 9 | // Licence: wxWindows licence |
74698d3a MB |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_MSGOUT_H_ | |
13 | #define _WX_MSGOUT_H_ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
74698d3a | 19 | #include "wx/defs.h" |
e3f6cbd9 | 20 | #include "wx/chartype.h" |
c9f78968 | 21 | #include "wx/strvararg.h" |
74698d3a | 22 | |
98020767 VZ |
23 | // ---------------------------------------------------------------------------- |
24 | // wxMessageOutput is a class abstracting formatted output target, i.e. | |
25 | // something you can printf() to | |
26 | // ---------------------------------------------------------------------------- | |
27 | ||
c9f78968 VS |
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 | |
74698d3a MB |
34 | { |
35 | public: | |
c9f78968 | 36 | virtual ~wxMessageOutputBase() { } |
74698d3a MB |
37 | |
38 | // show a message to the user | |
2523e9b7 | 39 | // void Printf(const wxString& format, ...) = 0; |
1528e0b8 | 40 | WX_DEFINE_VARARG_FUNC_VOID(Printf, 1, (const wxFormatString&), |
d1f6e2cf | 41 | DoPrintfWchar, DoPrintfUtf8) |
2523e9b7 VS |
42 | #ifdef __WATCOMC__ |
43 | // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351 | |
d1f6e2cf VS |
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) | |
2523e9b7 | 50 | #endif |
c9f78968 VS |
51 | |
52 | protected: | |
b5536269 VS |
53 | // NB: this is pure virtual so that it can be implemented in dllexported |
54 | // wxMessagOutput class | |
d1f6e2cf VS |
55 | #if !wxUSE_UTF8_LOCALE_ONLY |
56 | virtual void DoPrintfWchar(const wxChar *format, ...) = 0; | |
57 | #endif | |
58 | #if wxUSE_UNICODE_UTF8 | |
59 | virtual void DoPrintfUtf8(const char *format, ...) = 0; | |
60 | #endif | |
b5536269 VS |
61 | |
62 | // called by DoPrintf() to output formatted string | |
5b077ec7 | 63 | virtual void Output(const wxString& str) = 0; |
c9f78968 VS |
64 | }; |
65 | ||
66 | #ifdef __VISUALC__ | |
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) | |
70 | #endif | |
71 | ||
72 | class WXDLLIMPEXP_BASE wxMessageOutput : public wxMessageOutputBase | |
73 | { | |
74 | public: | |
75 | virtual ~wxMessageOutput() { } | |
98020767 | 76 | |
e12a951e VZ |
77 | // gets the current wxMessageOutput object (may be NULL during |
78 | // initialization or shutdown) | |
74698d3a | 79 | static wxMessageOutput* Get(); |
98020767 | 80 | |
74698d3a MB |
81 | // sets the global wxMessageOutput instance; returns the previous one |
82 | static wxMessageOutput* Set(wxMessageOutput* msgout); | |
98020767 | 83 | |
b5536269 | 84 | protected: |
d1f6e2cf VS |
85 | #if !wxUSE_UTF8_LOCALE_ONLY |
86 | virtual void DoPrintfWchar(const wxChar *format, ...); | |
87 | #endif | |
88 | #if wxUSE_UNICODE_UTF8 | |
89 | virtual void DoPrintfUtf8(const char *format, ...); | |
90 | #endif | |
b5536269 VS |
91 | virtual void Output(const wxString& str) = 0; |
92 | ||
74698d3a MB |
93 | private: |
94 | static wxMessageOutput* ms_msgOut; | |
95 | }; | |
96 | ||
c9f78968 VS |
97 | #ifdef __VISUALC__ |
98 | #pragma warning (default:4275) | |
99 | #endif | |
100 | ||
e12a951e VZ |
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 | // ---------------------------------------------------------------------------- | |
106 | ||
107 | class WXDLLIMPEXP_BASE wxMessageOutputBest : public wxMessageOutput | |
108 | { | |
109 | public: | |
110 | wxMessageOutputBest() { } | |
111 | ||
c9f78968 | 112 | protected: |
5b077ec7 | 113 | virtual void Output(const wxString& str); |
e12a951e VZ |
114 | }; |
115 | ||
98020767 VZ |
116 | // ---------------------------------------------------------------------------- |
117 | // implementation which sends output to stderr | |
118 | // ---------------------------------------------------------------------------- | |
119 | ||
bddd7a8d | 120 | class WXDLLIMPEXP_BASE wxMessageOutputStderr : public wxMessageOutput |
74698d3a MB |
121 | { |
122 | public: | |
98020767 | 123 | wxMessageOutputStderr() { } |
74698d3a | 124 | |
c9f78968 | 125 | protected: |
5b077ec7 | 126 | virtual void Output(const wxString& str); |
74698d3a MB |
127 | }; |
128 | ||
98020767 VZ |
129 | // ---------------------------------------------------------------------------- |
130 | // implementation which shows output in a message box | |
131 | // ---------------------------------------------------------------------------- | |
132 | ||
74698d3a MB |
133 | #if wxUSE_GUI |
134 | ||
bddd7a8d | 135 | class WXDLLIMPEXP_CORE wxMessageOutputMessageBox : public wxMessageOutput |
74698d3a MB |
136 | { |
137 | public: | |
98020767 | 138 | wxMessageOutputMessageBox() { } |
74698d3a | 139 | |
c9f78968 | 140 | protected: |
5b077ec7 | 141 | virtual void Output(const wxString& str); |
74698d3a MB |
142 | }; |
143 | ||
ef357cda | 144 | #endif // wxUSE_GUI |
74698d3a | 145 | |
e2478fde VZ |
146 | // ---------------------------------------------------------------------------- |
147 | // implementation using the native way of outputting debug messages | |
148 | // ---------------------------------------------------------------------------- | |
149 | ||
bddd7a8d | 150 | class WXDLLIMPEXP_BASE wxMessageOutputDebug : public wxMessageOutput |
e2478fde VZ |
151 | { |
152 | public: | |
153 | wxMessageOutputDebug() { } | |
154 | ||
c9f78968 | 155 | protected: |
5b077ec7 | 156 | virtual void Output(const wxString& str); |
e2478fde VZ |
157 | }; |
158 | ||
98020767 VZ |
159 | // ---------------------------------------------------------------------------- |
160 | // implementation using wxLog (mainly for backwards compatibility) | |
161 | // ---------------------------------------------------------------------------- | |
162 | ||
bddd7a8d | 163 | class WXDLLIMPEXP_BASE wxMessageOutputLog : public wxMessageOutput |
74698d3a MB |
164 | { |
165 | public: | |
98020767 | 166 | wxMessageOutputLog() { } |
74698d3a | 167 | |
c9f78968 | 168 | protected: |
5b077ec7 | 169 | virtual void Output(const wxString& str); |
74698d3a MB |
170 | }; |
171 | ||
74698d3a MB |
172 | #endif |
173 | // _WX_MSGOUT_H_ |