]> git.saurik.com Git - wxWidgets.git/blob - src/common/msgout.cpp
small fixed-wixth tab sizing bug fixed
[wxWidgets.git] / src / common / msgout.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 #include "wx/log.h"
33 #if wxUSE_GUI
34 #include "wx/msgdlg.h"
35 #endif // wxUSE_GUI
36 #endif
37
38 #include "wx/msgout.h"
39 #include "wx/apptrait.h"
40 #include <stdarg.h>
41 #include <stdio.h>
42
43 #if defined(__WINDOWS__)
44 #include "wx/msw/private.h"
45 #endif
46 #ifdef __WXMAC__
47 #include "wx/mac/private.h"
48 #endif
49
50 // ===========================================================================
51 // implementation
52 // ===========================================================================
53
54 #if wxUSE_BASE
55
56 // ----------------------------------------------------------------------------
57 // wxMessageOutput
58 // ----------------------------------------------------------------------------
59
60 wxMessageOutput* wxMessageOutput::ms_msgOut = 0;
61
62 wxMessageOutput* wxMessageOutput::Get()
63 {
64 if ( !ms_msgOut && wxTheApp )
65 {
66 ms_msgOut = wxTheApp->GetTraits()->CreateMessageOutput();
67 }
68
69 return ms_msgOut;
70 }
71
72 wxMessageOutput* wxMessageOutput::Set(wxMessageOutput* msgout)
73 {
74 wxMessageOutput* old = ms_msgOut;
75 ms_msgOut = msgout;
76 return old;
77 }
78
79 // ----------------------------------------------------------------------------
80 // wxMessageOutputBest
81 // ----------------------------------------------------------------------------
82
83 #ifdef __WINDOWS__
84
85 // check if we're running in a console under Windows
86 static inline bool IsInConsole()
87 {
88 #ifdef __WXWINCE__
89 return false;
90 #else // !__WXWINCE__
91 HANDLE hStdErr = ::GetStdHandle(STD_ERROR_HANDLE);
92 return hStdErr && hStdErr != INVALID_HANDLE_VALUE;
93 #endif // __WXWINCE__/!__WXWINCE__
94 }
95
96 #endif // __WINDOWS__
97
98 void wxMessageOutputBest::Printf(const wxChar* format, ...)
99 {
100 va_list args;
101 va_start(args, format);
102 wxString out;
103
104 out.PrintfV(format, args);
105 va_end(args);
106
107 #ifdef __WINDOWS__
108 if ( !IsInConsole() )
109 {
110 ::MessageBox(NULL, out, _T("wxWidgets"), MB_ICONINFORMATION | MB_OK);
111 }
112 else
113 #endif // __WINDOWS__/!__WINDOWS__
114 {
115 fprintf(stderr, "%s", (const char*) out.mb_str());
116 }
117 }
118
119 // ----------------------------------------------------------------------------
120 // wxMessageOutputStderr
121 // ----------------------------------------------------------------------------
122
123 void wxMessageOutputStderr::Printf(const wxChar* format, ...)
124 {
125 va_list args;
126 va_start(args, format);
127 wxString out;
128
129 out.PrintfV(format, args);
130 va_end(args);
131
132 fprintf(stderr, "%s", (const char*) out.mb_str());
133 }
134
135 // ----------------------------------------------------------------------------
136 // wxMessageOutputDebug
137 // ----------------------------------------------------------------------------
138
139 void wxMessageOutputDebug::Printf(const wxChar* format, ...)
140 {
141 wxString out;
142
143 va_list args;
144 va_start(args, format);
145
146 out.PrintfV(format, args);
147 va_end(args);
148
149 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
150 out.Replace(wxT("\t"), wxT(" "));
151 out.Replace(wxT("\n"), wxT("\r\n"));
152 ::OutputDebugString(out);
153 #elif defined(__WXMAC__) && !defined(__DARWIN__)
154 if ( wxIsDebuggerRunning() )
155 {
156 Str255 pstr;
157 wxString output = out + wxT(";g") ;
158 wxMacStringToPascal(output.c_str(), pstr);
159
160 #ifdef __powerc
161 DebugStr(pstr);
162 #else
163 SysBreakStr(pstr);
164 #endif
165 }
166 #else
167 wxFputs( out , stderr ) ;
168 if ( out.Right(1) != wxT("\n") )
169 wxFputs( wxT("\n") , stderr ) ;
170 fflush( stderr ) ;
171 #endif // platform
172 }
173
174 // ----------------------------------------------------------------------------
175 // wxMessageOutputLog
176 // ----------------------------------------------------------------------------
177
178 void wxMessageOutputLog::Printf(const wxChar* format, ...)
179 {
180 wxString out;
181
182 va_list args;
183 va_start(args, format);
184
185 out.PrintfV(format, args);
186 va_end(args);
187
188 out.Replace(wxT("\t"), wxT(" "));
189
190 ::wxLogMessage(wxT("%s"), out.c_str());
191 }
192
193 #endif // wxUSE_BASE
194
195 // ----------------------------------------------------------------------------
196 // wxMessageOutputMessageBox
197 // ----------------------------------------------------------------------------
198
199 #if wxUSE_GUI
200
201 void wxMessageOutputMessageBox::Printf(const wxChar* format, ...)
202 {
203 va_list args;
204 va_start(args, format);
205 wxString out;
206
207 out.PrintfV(format, args);
208 va_end(args);
209
210 // the native MSW msg box understands the TABs, others don't
211 #ifndef __WXMSW__
212 out.Replace(wxT("\t"), wxT(" "));
213 #endif
214
215 wxString title;
216 if ( wxTheApp )
217 title.Printf(_("%s message"), wxTheApp->GetAppName().c_str());
218
219 ::wxMessageBox(out, title);
220 }
221
222 #endif // wxUSE_GUI