File: msgout.h

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (185 lines) | stat: -rw-r--r-- 6,029 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/////////////////////////////////////////////////////////////////////////////
// Name:        wx/msgout.h
// Purpose:     interface of wxMessageOutput and derived classes
// Author:      Vadim Zeitlin
// Copyright:   (c) 2009 Vadim Zeitlin
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

/**
    Simple class allowing to write strings to various output channels.

    wxMessageOutput is a low-level class and doesn't provide any of the
    conveniences of wxLog. It simply allows writing a message to some output
    channel: usually file or standard error but possibly also a message box.
    While use of wxLog and related functions is preferable in many cases
    sometimes this simple interface may be more convenient.

    This class itself is an abstract base class for various concrete derived
    classes:
        - wxMessageOutputStderr
        - wxMessageOutputBest
        - wxMessageOutputMessageBox
        - wxMessageOutputLog

    It also provides access to the global message output object which is
    created by wxAppTraits::CreateMessageOutput() which creates an object of
    class wxMessageOutputStderr in console applications and wxMessageOutputBest
    in the GUI ones but may be overridden in user-defined traits class.

    Example of using this class:
    @code
        wxMessageOutputDebug().Printf("name=%s, preparing to greet...", name);
        wxMessageOutput::Get()->Printf("Hello, %s!", name);
    @endcode

    @library{wxbase}
    @category{logging}
 */
class wxMessageOutput
{
public:
    /**
        Return the global message output object.

        This object is never @NULL while the program is running but may be
        @NULL during initialization (before wxApp object is instantiated) or
        shutdown.(after wxApp destruction).

        @see wxAppTraits::CreateMessageOutput()
     */
    static wxMessageOutput* Get();

    /**
        Sets the global message output object.

        Using this function may be a simpler alternative to changing the
        message output object used for your program than overriding
        wxAppTraits::CreateMessageOutput().

        Remember to delete the returned pointer or restore it later with
        another call to Set().
     */
    static wxMessageOutput* Set(wxMessageOutput* msgout);

    /**
        Output a message.

        This function uses the same conventions as standard @c printf().
     */
    void Printf(const wxString& format, ...);

    /**
        Method called by Printf() to really output the text.

        This method is overridden in various derived classes and is also the
        one you should override if you implement a custom message output
        object.

        It may also be called directly instead of Printf(). This is especially
        useful when outputting a user-defined string because it can be simply
        called with this string instead of using
        @code
            msgout.Printf("%s", str);
        @endcode
        (notice that passing user-defined string to Printf() directly is, of
        course, a security risk).
     */
    virtual void Output(const wxString& str) = 0;
};

/**
    Output messages to stderr or another STDIO file stream.

    Implements wxMessageOutput by using stderr or specified file.

    @library{wxbase}
    @category{logging}
 */
class wxMessageOutputStderr : public wxMessageOutput
{
public:
    /**
        Create a new message output object associated with standard error
        stream by default.

        @param fp
            Non-null STDIO file stream. Notice that this object does @e not
            take ownership of this pointer, i.e. the caller is responsible for
            both ensuring that its life-time is great er than life-time of this
            object and for deleting it if necessary.
     */
    wxMessageOutputStderr(FILE *fp = stderr);
};

/**
    Flags used with wxMessageOutputBest.

    See wxMessageOutputBest::wxMessageOutputBest().
 */
enum wxMessageOutputFlags
{
    wxMSGOUT_PREFER_STDERR = 0, ///< use stderr if available (this is the default)
    wxMSGOUT_PREFER_MSGBOX = 1  ///< always use message box if available
};

/**
    Output messages in the best possible way.

    Some systems (e.g. MSW) are capable of showing message boxes even from
    console programs. If this is the case, this class will use message box if
    standard error stream is not available (e.g. running console program not
    from console under Windows) or possibly even always, depending on the value
    of flags constructor argument.

    @library{wxbase}
    @category{logging}
 */
class wxMessageOutputBest : public wxMessageOutputStderr
{
public:
    /**
        Create a new message output object.

        @param flags
            May be either @c wxMSGOUT_PREFER_STDERR (default) meaning that
            standard error will be used if it's available (e.g. program is
            being run from console under Windows) or @c wxMSGOUT_PREFER_MSGBOX
            meaning that a message box will always be used if the current
            system supports showing message boxes from console programs
            (currently only Windows does).
     */
    wxMessageOutputBest(wxMessageOutputFlags flags = wxMSGOUT_PREFER_STDERR);
};

/**
    Output messages to the system debug output channel.

    Under MSW this class outputs messages to the so called debug output. Under
    the other systems it simply uses the standard error stream.

    @library{wxbase}
    @category{logging}
 */
class wxMessageOutputDebug : public wxMessageOutputStderr
{
public:
    /// Default constructor.
    wxMessageOutputDebug();
};

/**
    Output messages by showing them in a message box.

    This class is only available to GUI applications, unlike all the other
    wxMessageOutput-derived classes.

    @library{wxcore}
    @category{logging}
 */
class wxMessageOutputMessageBox : public wxMessageOutput
{
public:
    /// Default constructor.
    wxMessageOutputMessageBox();
};