]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msgout.h
added copy ctor to wxCStrData to fix crashes when passing to vararg functions
[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 wxString&), DoPrintf)
41 #ifdef __WATCOMC__
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)
46 #endif
47
48 protected:
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;
52
53 // called by DoPrintf() to output formatted string
54 virtual void Output(const wxString& str) = 0;
55 };
56
57 #ifdef __VISUALC__
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)
61 #endif
62
63 class WXDLLIMPEXP_BASE wxMessageOutput : public wxMessageOutputBase
64 {
65 public:
66 virtual ~wxMessageOutput() { }
67
68 // gets the current wxMessageOutput object (may be NULL during
69 // initialization or shutdown)
70 static wxMessageOutput* Get();
71
72 // sets the global wxMessageOutput instance; returns the previous one
73 static wxMessageOutput* Set(wxMessageOutput* msgout);
74
75 protected:
76 virtual void DoPrintf(const wxString& format, ...);
77 virtual void Output(const wxString& str) = 0;
78
79 private:
80 static wxMessageOutput* ms_msgOut;
81 };
82
83 #ifdef __VISUALC__
84 #pragma warning (default:4275)
85 #endif
86
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 // ----------------------------------------------------------------------------
92
93 class WXDLLIMPEXP_BASE wxMessageOutputBest : public wxMessageOutput
94 {
95 public:
96 wxMessageOutputBest() { }
97
98 protected:
99 virtual void Output(const wxString& str);
100 };
101
102 // ----------------------------------------------------------------------------
103 // implementation which sends output to stderr
104 // ----------------------------------------------------------------------------
105
106 class WXDLLIMPEXP_BASE wxMessageOutputStderr : public wxMessageOutput
107 {
108 public:
109 wxMessageOutputStderr() { }
110
111 protected:
112 virtual void Output(const wxString& str);
113 };
114
115 // ----------------------------------------------------------------------------
116 // implementation which shows output in a message box
117 // ----------------------------------------------------------------------------
118
119 #if wxUSE_GUI
120
121 class WXDLLIMPEXP_CORE wxMessageOutputMessageBox : public wxMessageOutput
122 {
123 public:
124 wxMessageOutputMessageBox() { }
125
126 protected:
127 virtual void Output(const wxString& str);
128 };
129
130 #endif // wxUSE_GUI
131
132 // ----------------------------------------------------------------------------
133 // implementation using the native way of outputting debug messages
134 // ----------------------------------------------------------------------------
135
136 class WXDLLIMPEXP_BASE wxMessageOutputDebug : public wxMessageOutput
137 {
138 public:
139 wxMessageOutputDebug() { }
140
141 protected:
142 virtual void Output(const wxString& str);
143 };
144
145 // ----------------------------------------------------------------------------
146 // implementation using wxLog (mainly for backwards compatibility)
147 // ----------------------------------------------------------------------------
148
149 class WXDLLIMPEXP_BASE wxMessageOutputLog : public wxMessageOutput
150 {
151 public:
152 wxMessageOutputLog() { }
153
154 protected:
155 virtual void Output(const wxString& str);
156 };
157
158 #endif
159 // _WX_MSGOUT_H_