]> git.saurik.com Git - wxWidgets.git/blob - src/common/msgout.cpp
don't return void values
[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 wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #if defined(__BORLANDC__)
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/string.h"
29 #include "wx/ffile.h"
30 #include "wx/app.h"
31 #include "wx/intl.h"
32 #if wxUSE_GUI
33 #include "wx/msgdlg.h"
34 #endif // wxUSE_GUI
35 #endif
36
37 #include "wx/msgout.h"
38 #include "wx/apptrait.h"
39 #include "wx/log.h"
40
41 #include <stdarg.h>
42 #include <stdio.h>
43
44 #if defined(__WINDOWS__)
45 #include "wx/msw/private.h"
46 #endif
47 #ifdef __WXMAC__
48 #include "wx/mac/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->GetTraits()->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 // wxMessageOutputBest
82 // ----------------------------------------------------------------------------
83
84 #ifdef __WINDOWS__
85
86 // check if we're running in a console under Windows
87 static inline bool IsInConsole()
88 {
89 #ifdef __WXWINCE__
90 return false;
91 #else // !__WXWINCE__
92 HANDLE hStdErr = ::GetStdHandle(STD_ERROR_HANDLE);
93 return hStdErr && hStdErr != INVALID_HANDLE_VALUE;
94 #endif // __WXWINCE__/!__WXWINCE__
95 }
96
97 #endif // __WINDOWS__
98
99 void wxMessageOutputBest::Printf(const wxChar* format, ...)
100 {
101 va_list args;
102 va_start(args, format);
103 wxString out;
104
105 out.PrintfV(format, args);
106 va_end(args);
107
108 #ifdef __WINDOWS__
109 if ( !IsInConsole() )
110 {
111 ::MessageBox(NULL, out, _T("wxWidgets"), MB_ICONINFORMATION | MB_OK);
112 }
113 else
114 #endif // __WINDOWS__/!__WINDOWS__
115 {
116 fprintf(stderr, "%s", (const char*) out.mb_str());
117 }
118 }
119
120 // ----------------------------------------------------------------------------
121 // wxMessageOutputStderr
122 // ----------------------------------------------------------------------------
123
124 void wxMessageOutputStderr::Printf(const wxChar* format, ...)
125 {
126 va_list args;
127 va_start(args, format);
128 wxString out;
129
130 out.PrintfV(format, args);
131 va_end(args);
132
133 fprintf(stderr, "%s", (const char*) out.mb_str());
134 }
135
136 // ----------------------------------------------------------------------------
137 // wxMessageOutputDebug
138 // ----------------------------------------------------------------------------
139
140 void wxMessageOutputDebug::Printf(const wxChar* format, ...)
141 {
142 wxString out;
143
144 va_list args;
145 va_start(args, format);
146
147 out.PrintfV(format, args);
148 va_end(args);
149
150 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
151 out.Replace(wxT("\t"), wxT(" "));
152 out.Replace(wxT("\n"), wxT("\r\n"));
153 ::OutputDebugString(out);
154 #elif defined(__WXMAC__) && !defined(__DARWIN__)
155 if ( wxIsDebuggerRunning() )
156 {
157 Str255 pstr;
158 wxString output = out + wxT(";g") ;
159 wxMacStringToPascal(output.c_str(), pstr);
160
161 #ifdef __powerc
162 DebugStr(pstr);
163 #else
164 SysBreakStr(pstr);
165 #endif
166 }
167 #else
168 wxFputs( out , stderr ) ;
169 if ( out.Right(1) != wxT("\n") )
170 wxFputs( wxT("\n") , stderr ) ;
171 fflush( stderr ) ;
172 #endif // platform
173 }
174
175 // ----------------------------------------------------------------------------
176 // wxMessageOutputLog
177 // ----------------------------------------------------------------------------
178
179 void wxMessageOutputLog::Printf(const wxChar* format, ...)
180 {
181 wxString out;
182
183 va_list args;
184 va_start(args, format);
185
186 out.PrintfV(format, args);
187 va_end(args);
188
189 out.Replace(wxT("\t"), wxT(" "));
190
191 ::wxLogMessage(wxT("%s"), out.c_str());
192 }
193
194 #endif // wxUSE_BASE
195
196 // ----------------------------------------------------------------------------
197 // wxMessageOutputMessageBox
198 // ----------------------------------------------------------------------------
199
200 #if wxUSE_GUI
201
202 void wxMessageOutputMessageBox::Printf(const wxChar* format, ...)
203 {
204 va_list args;
205 va_start(args, format);
206 wxString out;
207
208 out.PrintfV(format, args);
209 va_end(args);
210
211 // the native MSW msg box understands the TABs, others don't
212 #ifndef __WXMSW__
213 out.Replace(wxT("\t"), wxT(" "));
214 #endif
215
216 wxString title;
217 if ( wxTheApp )
218 title.Printf(_("%s message"), wxTheApp->GetAppName().c_str());
219
220 ::wxMessageBox(out, title);
221 }
222
223 #endif // wxUSE_GUI
224