]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msgout.h
Comment-only update
[wxWidgets.git] / include / wx / msgout.h
CommitLineData
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
99d80019 7// Copyright: (c) Mattia Barbon
65571936 8// Licence: wxWindows licence
74698d3a
MB
9///////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_MSGOUT_H_
12#define _WX_MSGOUT_H_
13
14// ----------------------------------------------------------------------------
15// headers
16// ----------------------------------------------------------------------------
17
74698d3a 18#include "wx/defs.h"
e3f6cbd9 19#include "wx/chartype.h"
c9f78968 20#include "wx/strvararg.h"
74698d3a 21
98020767
VZ
22// ----------------------------------------------------------------------------
23// wxMessageOutput is a class abstracting formatted output target, i.e.
24// something you can printf() to
25// ----------------------------------------------------------------------------
26
c9f78968
VS
27// NB: VC6 has a bug that causes linker errors if you have template methods
28// in a class using __declspec(dllimport). The solution is to split such
29// class into two classes, one that contains the template methods and does
30// *not* use WXDLLIMPEXP_BASE and another class that contains the rest
31// (with DLL linkage).
32class wxMessageOutputBase
74698d3a
MB
33{
34public:
c9f78968 35 virtual ~wxMessageOutputBase() { }
74698d3a
MB
36
37 // show a message to the user
2523e9b7 38 // void Printf(const wxString& format, ...) = 0;
1528e0b8 39 WX_DEFINE_VARARG_FUNC_VOID(Printf, 1, (const wxFormatString&),
d1f6e2cf 40 DoPrintfWchar, DoPrintfUtf8)
2523e9b7
VS
41#ifdef __WATCOMC__
42 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
59a14f69
VS
43 WX_VARARG_WATCOM_WORKAROUND(void, Printf, 1, (const wxString&),
44 (wxFormatString(f1)));
45 WX_VARARG_WATCOM_WORKAROUND(void, Printf, 1, (const wxCStrData&),
46 (wxFormatString(f1)));
47 WX_VARARG_WATCOM_WORKAROUND(void, Printf, 1, (const char*),
48 (wxFormatString(f1)));
49 WX_VARARG_WATCOM_WORKAROUND(void, Printf, 1, (const wchar_t*),
50 (wxFormatString(f1)));
2523e9b7 51#endif
c9f78968 52
8a946489
VZ
53 // called by DoPrintf() to output formatted string but can also be called
54 // directly if no formatting is needed
55 virtual void Output(const wxString& str) = 0;
56
c9f78968 57protected:
b5536269
VS
58 // NB: this is pure virtual so that it can be implemented in dllexported
59 // wxMessagOutput class
d1f6e2cf
VS
60#if !wxUSE_UTF8_LOCALE_ONLY
61 virtual void DoPrintfWchar(const wxChar *format, ...) = 0;
62#endif
63#if wxUSE_UNICODE_UTF8
64 virtual void DoPrintfUtf8(const char *format, ...) = 0;
65#endif
c9f78968
VS
66};
67
68#ifdef __VISUALC__
69 // "non dll-interface class 'wxStringPrintfMixin' used as base interface
70 // for dll-interface class 'wxString'" -- this is OK in our case
fb330c2e 71 #pragma warning (push)
c9f78968
VS
72 #pragma warning (disable:4275)
73#endif
74
75class WXDLLIMPEXP_BASE wxMessageOutput : public wxMessageOutputBase
76{
77public:
78 virtual ~wxMessageOutput() { }
98020767 79
e12a951e
VZ
80 // gets the current wxMessageOutput object (may be NULL during
81 // initialization or shutdown)
74698d3a 82 static wxMessageOutput* Get();
98020767 83
74698d3a
MB
84 // sets the global wxMessageOutput instance; returns the previous one
85 static wxMessageOutput* Set(wxMessageOutput* msgout);
98020767 86
b5536269 87protected:
d1f6e2cf
VS
88#if !wxUSE_UTF8_LOCALE_ONLY
89 virtual void DoPrintfWchar(const wxChar *format, ...);
90#endif
91#if wxUSE_UNICODE_UTF8
92 virtual void DoPrintfUtf8(const char *format, ...);
93#endif
b5536269 94
74698d3a
MB
95private:
96 static wxMessageOutput* ms_msgOut;
97};
98
c9f78968 99#ifdef __VISUALC__
fb330c2e 100 #pragma warning (pop)
c9f78968
VS
101#endif
102
e12a951e 103// ----------------------------------------------------------------------------
e8c9268b 104// implementation which sends output to stderr or specified file
e12a951e
VZ
105// ----------------------------------------------------------------------------
106
784ee7d5 107class WXDLLIMPEXP_BASE wxMessageOutputStderr : public wxMessageOutput
e12a951e
VZ
108{
109public:
e8c9268b 110 wxMessageOutputStderr(FILE *fp = stderr) : m_fp(fp) { }
e12a951e 111
5b077ec7 112 virtual void Output(const wxString& str);
784ee7d5 113
8a946489 114protected:
784ee7d5
VZ
115 // return the string with "\n" appended if it doesn't already terminate
116 // with it (in which case it's returned unchanged)
117 wxString AppendLineFeedIfNeeded(const wxString& str);
e8c9268b
VZ
118
119 FILE *m_fp;
e12a951e
VZ
120};
121
98020767 122// ----------------------------------------------------------------------------
784ee7d5
VZ
123// implementation showing the message to the user in "best" possible way:
124// uses stderr or message box if available according to the flag given to ctor.
98020767
VZ
125// ----------------------------------------------------------------------------
126
784ee7d5
VZ
127enum wxMessageOutputFlags
128{
129 wxMSGOUT_PREFER_STDERR = 0, // use stderr if available (this is the default)
130 wxMSGOUT_PREFER_MSGBOX = 1 // always use message box if available
131};
132
133class WXDLLIMPEXP_BASE wxMessageOutputBest : public wxMessageOutputStderr
74698d3a
MB
134{
135public:
784ee7d5
VZ
136 wxMessageOutputBest(wxMessageOutputFlags flags = wxMSGOUT_PREFER_STDERR)
137 : m_flags(flags) { }
74698d3a 138
5b077ec7 139 virtual void Output(const wxString& str);
784ee7d5
VZ
140
141private:
142 wxMessageOutputFlags m_flags;
74698d3a
MB
143};
144
98020767
VZ
145// ----------------------------------------------------------------------------
146// implementation which shows output in a message box
147// ----------------------------------------------------------------------------
148
fae86641 149#if wxUSE_GUI && wxUSE_MSGDLG
74698d3a 150
bddd7a8d 151class WXDLLIMPEXP_CORE wxMessageOutputMessageBox : public wxMessageOutput
74698d3a
MB
152{
153public:
98020767 154 wxMessageOutputMessageBox() { }
74698d3a 155
5b077ec7 156 virtual void Output(const wxString& str);
74698d3a
MB
157};
158
fae86641 159#endif // wxUSE_GUI && wxUSE_MSGDLG
74698d3a 160
e2478fde
VZ
161// ----------------------------------------------------------------------------
162// implementation using the native way of outputting debug messages
163// ----------------------------------------------------------------------------
164
784ee7d5 165class WXDLLIMPEXP_BASE wxMessageOutputDebug : public wxMessageOutputStderr
e2478fde
VZ
166{
167public:
168 wxMessageOutputDebug() { }
169
5b077ec7 170 virtual void Output(const wxString& str);
e2478fde
VZ
171};
172
98020767
VZ
173// ----------------------------------------------------------------------------
174// implementation using wxLog (mainly for backwards compatibility)
175// ----------------------------------------------------------------------------
176
bddd7a8d 177class WXDLLIMPEXP_BASE wxMessageOutputLog : public wxMessageOutput
74698d3a
MB
178{
179public:
98020767 180 wxMessageOutputLog() { }
74698d3a 181
5b077ec7 182 virtual void Output(const wxString& str);
74698d3a
MB
183};
184
784ee7d5 185#endif // _WX_MSGOUT_H_