]> git.saurik.com Git - wxWidgets.git/blob - src/common/msgout.cpp
Committing in .
[wxWidgets.git] / src / common / msgout.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/msgout.cpp
3 // Purpose: wxMessageOutput implementation
4 // Author: Mattia Barbon
5 // Modified by:
6 // Created: 17.07.02
7 // RCS-ID: $Id$
8 // Copyright: (c) the wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "msgout.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #if defined(__BORLANDC__)
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/string.h"
33 #include "wx/ffile.h"
34 #include "wx/app.h"
35 #include "wx/intl.h"
36 #if wxUSE_GUI
37 #include "wx/msgdlg.h"
38 #endif // wxUSE_GUI
39 #endif
40
41 #include "wx/msgout.h"
42 #include "wx/log.h"
43
44 #include <stdarg.h>
45 #include <stdio.h>
46
47 #ifdef __WXMSW__
48 #include "wx/msw/private.h"
49 #endif
50
51 // ===========================================================================
52 // implementation
53 // ===========================================================================
54
55 #if wxUSE_BASE
56
57 // ----------------------------------------------------------------------------
58 // wxMessageOutput
59 // ----------------------------------------------------------------------------
60
61 wxMessageOutput* wxMessageOutput::ms_msgOut = 0;
62
63 wxMessageOutput* wxMessageOutput::Get()
64 {
65 if ( !ms_msgOut && wxTheApp )
66 {
67 ms_msgOut = wxTheApp->CreateMessageOutput();
68 }
69
70 return ms_msgOut;
71 }
72
73 wxMessageOutput* wxMessageOutput::Set(wxMessageOutput* msgout)
74 {
75 wxMessageOutput* old = ms_msgOut;
76 ms_msgOut = msgout;
77 return old;
78 }
79
80 // ----------------------------------------------------------------------------
81 // wxMessageOutputStderr
82 // ----------------------------------------------------------------------------
83
84 void wxMessageOutputStderr::Printf(const wxChar* format, ...)
85 {
86 va_list args;
87 va_start(args, format);
88 wxString out;
89
90 out.PrintfV(format, args);
91 va_end(args);
92
93 fprintf(stderr, "%s", (const char*) out.mb_str());
94 }
95
96 // ----------------------------------------------------------------------------
97 // wxMessageOutputDebug
98 // ----------------------------------------------------------------------------
99
100 void wxMessageOutputDebug::Printf(const wxChar* format, ...)
101 {
102 wxString out;
103
104 va_list args;
105 va_start(args, format);
106
107 out.PrintfV(format, args);
108 va_end(args);
109
110 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
111 out.Replace(wxT("\t"), wxT(" "));
112 out += _T("\r\n");
113 ::OutputDebugString(out);
114 #elif defined(__WXMAC__) && !defined(__DARWIN__)
115 if ( wxIsDebuggerRunning() )
116 {
117 Str255 pstr;
118 wxString output = str + wxT(";g") ;
119 wxMacStringToPascal(output.c_str(), pstr);
120
121 #ifdef __powerc
122 DebugStr(pstr);
123 #else
124 SysBreakStr(pstr);
125 #endif
126 }
127 #else // !MSW, !Mac
128 // FIXME: why is wxFputs() not defined under Linux?
129 fputs(out.mb_str(), stderr);
130 fflush(stderr);
131 #endif // platform
132 }
133
134 // ----------------------------------------------------------------------------
135 // wxMessageOutputLog
136 // ----------------------------------------------------------------------------
137
138 void wxMessageOutputLog::Printf(const wxChar* format, ...)
139 {
140 wxString out;
141
142 va_list args;
143 va_start(args, format);
144
145 out.PrintfV(format, args);
146 va_end(args);
147
148 out.Replace(wxT("\t"), wxT(" "));
149
150 ::wxLogMessage(wxT("%s"), out.c_str());
151 }
152
153 #endif // wxUSE_BASE
154
155 // ----------------------------------------------------------------------------
156 // wxMessageOutputMessageBox
157 // ----------------------------------------------------------------------------
158
159 #if wxUSE_GUI
160
161 void wxMessageOutputMessageBox::Printf(const wxChar* format, ...)
162 {
163 va_list args;
164 va_start(args, format);
165 wxString out;
166
167 out.PrintfV(format, args);
168 va_end(args);
169
170 // the native MSW msg box understands the TABs, others don't
171 #ifndef __WXMSW__
172 out.Replace(wxT("\t"), wxT(" "));
173 #endif
174
175 wxString title;
176 if ( wxTheApp )
177 title.Printf(_("%s message"), wxTheApp->GetAppName().c_str());
178
179 ::wxMessageBox(out, title);
180 }
181
182 #endif // wxUSE_GUI
183