]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msgout.h
Increase version to 2.9.5.
[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
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).
33class wxMessageOutputBase
74698d3a
MB
34{
35public:
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
59a14f69
VS
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)));
2523e9b7 52#endif
c9f78968 53
8a946489
VZ
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
c9f78968 58protected:
b5536269
VS
59 // NB: this is pure virtual so that it can be implemented in dllexported
60 // wxMessagOutput class
d1f6e2cf
VS
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
c9f78968
VS
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
fb330c2e 72 #pragma warning (push)
c9f78968
VS
73 #pragma warning (disable:4275)
74#endif
75
76class WXDLLIMPEXP_BASE wxMessageOutput : public wxMessageOutputBase
77{
78public:
79 virtual ~wxMessageOutput() { }
98020767 80
e12a951e
VZ
81 // gets the current wxMessageOutput object (may be NULL during
82 // initialization or shutdown)
74698d3a 83 static wxMessageOutput* Get();
98020767 84
74698d3a
MB
85 // sets the global wxMessageOutput instance; returns the previous one
86 static wxMessageOutput* Set(wxMessageOutput* msgout);
98020767 87
b5536269 88protected:
d1f6e2cf
VS
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
b5536269 95
74698d3a
MB
96private:
97 static wxMessageOutput* ms_msgOut;
98};
99
c9f78968 100#ifdef __VISUALC__
fb330c2e 101 #pragma warning (pop)
c9f78968
VS
102#endif
103
e12a951e 104// ----------------------------------------------------------------------------
e8c9268b 105// implementation which sends output to stderr or specified file
e12a951e
VZ
106// ----------------------------------------------------------------------------
107
784ee7d5 108class WXDLLIMPEXP_BASE wxMessageOutputStderr : public wxMessageOutput
e12a951e
VZ
109{
110public:
e8c9268b 111 wxMessageOutputStderr(FILE *fp = stderr) : m_fp(fp) { }
e12a951e 112
5b077ec7 113 virtual void Output(const wxString& str);
784ee7d5 114
8a946489 115protected:
784ee7d5
VZ
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);
e8c9268b
VZ
119
120 FILE *m_fp;
e12a951e
VZ
121};
122
98020767 123// ----------------------------------------------------------------------------
784ee7d5
VZ
124// implementation showing the message to the user in "best" possible way:
125// uses stderr or message box if available according to the flag given to ctor.
98020767
VZ
126// ----------------------------------------------------------------------------
127
784ee7d5
VZ
128enum wxMessageOutputFlags
129{
130 wxMSGOUT_PREFER_STDERR = 0, // use stderr if available (this is the default)
131 wxMSGOUT_PREFER_MSGBOX = 1 // always use message box if available
132};
133
134class WXDLLIMPEXP_BASE wxMessageOutputBest : public wxMessageOutputStderr
74698d3a
MB
135{
136public:
784ee7d5
VZ
137 wxMessageOutputBest(wxMessageOutputFlags flags = wxMSGOUT_PREFER_STDERR)
138 : m_flags(flags) { }
74698d3a 139
5b077ec7 140 virtual void Output(const wxString& str);
784ee7d5
VZ
141
142private:
143 wxMessageOutputFlags m_flags;
74698d3a
MB
144};
145
98020767
VZ
146// ----------------------------------------------------------------------------
147// implementation which shows output in a message box
148// ----------------------------------------------------------------------------
149
fae86641 150#if wxUSE_GUI && wxUSE_MSGDLG
74698d3a 151
bddd7a8d 152class WXDLLIMPEXP_CORE wxMessageOutputMessageBox : public wxMessageOutput
74698d3a
MB
153{
154public:
98020767 155 wxMessageOutputMessageBox() { }
74698d3a 156
5b077ec7 157 virtual void Output(const wxString& str);
74698d3a
MB
158};
159
fae86641 160#endif // wxUSE_GUI && wxUSE_MSGDLG
74698d3a 161
e2478fde
VZ
162// ----------------------------------------------------------------------------
163// implementation using the native way of outputting debug messages
164// ----------------------------------------------------------------------------
165
784ee7d5 166class WXDLLIMPEXP_BASE wxMessageOutputDebug : public wxMessageOutputStderr
e2478fde
VZ
167{
168public:
169 wxMessageOutputDebug() { }
170
5b077ec7 171 virtual void Output(const wxString& str);
e2478fde
VZ
172};
173
98020767
VZ
174// ----------------------------------------------------------------------------
175// implementation using wxLog (mainly for backwards compatibility)
176// ----------------------------------------------------------------------------
177
bddd7a8d 178class WXDLLIMPEXP_BASE wxMessageOutputLog : public wxMessageOutput
74698d3a
MB
179{
180public:
98020767 181 wxMessageOutputLog() { }
74698d3a 182
5b077ec7 183 virtual void Output(const wxString& str);
74698d3a
MB
184};
185
784ee7d5 186#endif // _WX_MSGOUT_H_