1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/msgout.cpp
3 // Purpose: wxMessageOutput implementation
4 // Author: Mattia Barbon
8 // Copyright: (c) the wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
23 #if defined(__BORLANDC__)
28 #include "wx/string.h"
34 #include "wx/msgdlg.h"
38 #include "wx/msgout.h"
39 #include "wx/apptrait.h"
43 #if defined(__WINDOWS__)
44 #include "wx/msw/private.h"
47 #include "wx/mac/private.h"
50 // ===========================================================================
52 // ===========================================================================
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 wxMessageOutput
* wxMessageOutput::ms_msgOut
= 0;
62 wxMessageOutput
* wxMessageOutput::Get()
64 if ( !ms_msgOut
&& wxTheApp
)
66 ms_msgOut
= wxTheApp
->GetTraits()->CreateMessageOutput();
72 wxMessageOutput
* wxMessageOutput::Set(wxMessageOutput
* msgout
)
74 wxMessageOutput
* old
= ms_msgOut
;
79 // ----------------------------------------------------------------------------
80 // wxMessageOutputBest
81 // ----------------------------------------------------------------------------
85 // check if we're running in a console under Windows
86 static inline bool IsInConsole()
91 HANDLE hStdErr
= ::GetStdHandle(STD_ERROR_HANDLE
);
92 return hStdErr
&& hStdErr
!= INVALID_HANDLE_VALUE
;
93 #endif // __WXWINCE__/!__WXWINCE__
98 void wxMessageOutputBest::Printf(const wxChar
* format
, ...)
101 va_start(args
, format
);
104 out
.PrintfV(format
, args
);
108 if ( !IsInConsole() )
110 ::MessageBox(NULL
, out
, _T("wxWidgets"), MB_ICONINFORMATION
| MB_OK
);
113 #endif // __WINDOWS__/!__WINDOWS__
115 fprintf(stderr
, "%s", (const char*) out
.mb_str());
119 // ----------------------------------------------------------------------------
120 // wxMessageOutputStderr
121 // ----------------------------------------------------------------------------
123 void wxMessageOutputStderr::Printf(const wxChar
* format
, ...)
126 va_start(args
, format
);
129 out
.PrintfV(format
, args
);
132 fprintf(stderr
, "%s", (const char*) out
.mb_str());
135 // ----------------------------------------------------------------------------
136 // wxMessageOutputDebug
137 // ----------------------------------------------------------------------------
139 void wxMessageOutputDebug::Printf(const wxChar
* format
, ...)
144 va_start(args
, format
);
146 out
.PrintfV(format
, args
);
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() )
157 wxString output
= out
+ wxT(";g") ;
158 wxMacStringToPascal(output
.c_str(), pstr
);
167 wxFputs( out
, stderr
) ;
168 if ( out
.Right(1) != wxT("\n") )
169 wxFputs( wxT("\n") , stderr
) ;
174 // ----------------------------------------------------------------------------
175 // wxMessageOutputLog
176 // ----------------------------------------------------------------------------
178 void wxMessageOutputLog::Printf(const wxChar
* format
, ...)
183 va_start(args
, format
);
185 out
.PrintfV(format
, args
);
188 out
.Replace(wxT("\t"), wxT(" "));
190 ::wxLogMessage(wxT("%s"), out
.c_str());
195 // ----------------------------------------------------------------------------
196 // wxMessageOutputMessageBox
197 // ----------------------------------------------------------------------------
201 void wxMessageOutputMessageBox::Printf(const wxChar
* format
, ...)
204 va_start(args
, format
);
207 out
.PrintfV(format
, args
);
210 // the native MSW msg box understands the TABs, others don't
212 out
.Replace(wxT("\t"), wxT(" "));
217 title
.Printf(_("%s message"), wxTheApp
->GetAppName().c_str());
219 ::wxMessageBox(out
, title
);