Changed wxLog DoLogXXX() callbacks and introduced wxLogRecordInfo.
[wxWidgets.git] / include / wx / generic / logg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/logg.h
3 // Purpose: Assorted wxLogXXX functions, and wxLog (sink for logs)
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 29/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_LOGG_H_
13 #define _WX_LOGG_H_
14
15 #if wxUSE_GUI
16
17 class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
18 class WXDLLIMPEXP_FWD_CORE wxLogFrame;
19 class WXDLLIMPEXP_FWD_CORE wxWindow;
20
21 // ----------------------------------------------------------------------------
22 // the following log targets are only compiled in if the we're compiling the
23 // GUI part (andnot just the base one) of the library, they're implemented in
24 // src/generic/logg.cpp *and not src/common/log.cpp unlike all the rest)
25 // ----------------------------------------------------------------------------
26
27 #if wxUSE_TEXTCTRL
28
29 // log everything to a text window (GUI only of course)
30 class WXDLLIMPEXP_CORE wxLogTextCtrl : public wxLog
31 {
32 public:
33 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
34
35 protected:
36 // implement sink function
37 virtual void DoLogText(const wxString& msg);
38
39 private:
40 // the control we use
41 wxTextCtrl *m_pTextCtrl;
42
43 wxDECLARE_NO_COPY_CLASS(wxLogTextCtrl);
44 };
45
46 #endif // wxUSE_TEXTCTRL
47
48 // ----------------------------------------------------------------------------
49 // GUI log target, the default one for wxWidgets programs
50 // ----------------------------------------------------------------------------
51
52 #if wxUSE_LOGGUI
53
54 class WXDLLIMPEXP_CORE wxLogGui : public wxLog
55 {
56 public:
57 // ctor
58 wxLogGui();
59
60 // show all messages that were logged since the last Flush()
61 virtual void Flush();
62
63 protected:
64 virtual void DoLogRecord(wxLogLevel level,
65 const wxString& msg,
66 const wxLogRecordInfo& info);
67
68 // return the title to be used for the log dialog, depending on m_bErrors
69 // and m_bWarnings values
70 wxString GetTitle() const;
71
72 // return the icon (one of wxICON_XXX constants) to be used for the dialog
73 // depending on m_bErrors/m_bWarnings
74 int GetSeverityIcon() const;
75
76 // empty everything
77 void Clear();
78
79
80 wxArrayString m_aMessages; // the log message texts
81 wxArrayInt m_aSeverity; // one of wxLOG_XXX values
82 wxArrayLong m_aTimes; // the time of each message
83 bool m_bErrors, // do we have any errors?
84 m_bWarnings, // any warnings?
85 m_bHasMessages; // any messages at all?
86
87 private:
88 // this method is called to show a single log message, it uses
89 // wxMessageBox() by default
90 virtual void DoShowSingleLogMessage(const wxString& message,
91 const wxString& title,
92 int style);
93
94 // this method is called to show multiple log messages, it uses wxLogDialog
95 virtual void DoShowMultipleLogMessages(const wxArrayString& messages,
96 const wxArrayInt& severities,
97 const wxArrayLong& times,
98 const wxString& title,
99 int style);
100 };
101
102 #endif // wxUSE_LOGGUI
103
104 // ----------------------------------------------------------------------------
105 // (background) log window: this class forwards all log messages to the log
106 // target which was active when it was instantiated, but also collects them
107 // to the log window. This window has it's own menu which allows the user to
108 // close it, clear the log contents or save it to the file.
109 // ----------------------------------------------------------------------------
110
111 #if wxUSE_LOGWINDOW
112
113 class WXDLLIMPEXP_CORE wxLogWindow : public wxLogPassThrough
114 {
115 public:
116 wxLogWindow(wxWindow *pParent, // the parent frame (can be NULL)
117 const wxString& szTitle, // the title of the frame
118 bool bShow = true, // show window immediately?
119 bool bPassToOld = true); // pass messages to the old target?
120
121 virtual ~wxLogWindow();
122
123 // window operations
124 // show/hide the log window
125 void Show(bool bShow = true);
126 // retrieve the pointer to the frame
127 wxFrame *GetFrame() const;
128
129 // overridables
130 // called immediately after the log frame creation allowing for
131 // any extra initializations
132 virtual void OnFrameCreate(wxFrame *frame);
133 // called if the user closes the window interactively, will not be
134 // called if it is destroyed for another reason (such as when program
135 // exits) - return true from here to allow the frame to close, false
136 // to prevent this from happening
137 virtual bool OnFrameClose(wxFrame *frame);
138 // called right before the log frame is going to be deleted: will
139 // always be called unlike OnFrameClose()
140 virtual void OnFrameDelete(wxFrame *frame);
141
142 protected:
143 virtual void DoLogTextAtLevel(wxLogLevel level, const wxString& msg);
144
145 private:
146 wxLogFrame *m_pLogFrame; // the log frame
147
148 wxDECLARE_NO_COPY_CLASS(wxLogWindow);
149 };
150
151 #endif // wxUSE_LOGWINDOW
152
153 #endif // wxUSE_GUI
154
155 #endif // _WX_LOGG_H_
156