1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxMessageOutput and derived classes
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2009 Vadim Zeitlin
7 // Licence: wxWindows license
8 /////////////////////////////////////////////////////////////////////////////
11 Simple class allowing to write strings to various output channels.
13 wxMessageOutput is a low-level class and doesn't provide any of the
14 conveniences of wxLog. It simply allows to write a message to some output
15 channel: usually file or standard error but possibly also a message box.
16 While use of wxLog and related functions is preferable in many cases
17 sometimes this simple interface may be more convenient.
19 This class itself is an abstract base class for various concrete derived
21 - wxMessageOutputStderr
23 - wxMessageOutputMessageBox
26 It also provides access to the global message output object which is
27 created by wxAppTraits::CreateMessageOutput() which creates an object of
28 class wxMessageOutputStderr in console applications and wxMessageOutputBest
29 in the GUI ones but may be overridden in user-defined traits class.
31 Example of using this class:
33 wxMessageOutputDebug().Printf("name=%s, preparing to greet...", name);
34 wxMessageOutput::Get()->Printf("Hello, %s!", name);
44 Return the global message output object.
46 This object is never @NULL while the program is running but may be
47 @NULL during initialization (before wxApp object is instantiated) or
48 shutdown.(after wxApp destruction).
50 @see wxAppTraits::CreateMessageOutput()
52 static wxMessageOutput
* Get();
55 Sets the global message output object.
57 Using this function may be a simpler alternative to changing the
58 message output object used for your program than overriding
59 wxAppTraits::CreateMessageOutput().
61 Remember to delete the returned pointer or restore it later with
62 another call to Set().
64 static wxMessageOutput
* Set(wxMessageOutput
* msgout
);
69 This function uses the same conventions as standard @c printf().
71 void Printf(const wxString
& format
, ...);
74 Method called by Printf() to really output the text.
76 This method is overridden in various derived classes and is also the
77 one you should override if you implement a custom message output
80 It may also be called directly instead of Printf(). This is especially
81 useful when outputting a user-defined string because it can be simply
82 called with this string instead of using
84 msgout.Printf("%s", str);
86 (notice that passing user-defined string to Printf() directly is, of
87 course, a security risk).
89 virtual void Output(const wxString
& str
) = 0;
93 Output messages to stderr or another STDIO file stream.
95 Implements wxMessageOutput by using stderr or specified file.
100 class wxMessageOutputStderr
: public wxMessageOutput
104 Create a new message output object associated with standard error
108 Non-null STDIO file stream. Notice that this object does @e not
109 take ownership of this pointer, i.e. the caller is responsible for
110 both ensuring that its life-time is great er than life-time of this
111 object and for deleting it if necessary.
113 wxMessageOutputStderr(FILE *fp
= stderr
);
117 Output messages in the best possible way.
119 Some systems (e.g. MSW) are capable of showing message boxes even from
120 console programs. If this is the case, this class will use message box if
121 standard error stream is not available (e.g. running console program not
122 from console under Windows) or possibly even always, depending on the value
123 of flags constructor argument.
128 class wxMessageOutputBest
: public wxMessageOutputStderr
132 Create a new message output object.
135 May be either @c wxMSGOUT_PREFER_STDERR (default) meaning that
136 standard error will be used if it's available (e.g. program is
137 being run from console under Windows) or @c wxMSGOUT_PREFER_MSGBOX
138 meaning that a message box will always be used if the current
139 system supports showing message boxes from console programs
140 (currently only Windows does).
142 wxMessageOutputBest(wxMessageOutputFlags flags
= wxMSGOUT_PREFER_STDERR
);
146 Output messages to the system debug output channel.
148 Under MSW this class outputs messages to the so called debug output. Under
149 the other systems it simply uses the standard error stream.
154 class wxMessageOutputDebug
: public wxMessageOutputStderr
157 /// Default constructor.
158 wxMessageOutputDebug();
162 Output messages by showing them in a message box.
164 This class is only available to GUI applications, unlike all the other
165 wxMessageOutput-derived classes.
170 class wxMessageOutputMessageBox
: public wxMessageOutput
173 /// Default constructor.
174 wxMessageOutputMessageBox();