]>
git.saurik.com Git - wxWidgets.git/blob - src/common/msgout.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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"
33 #include "wx/msgdlg.h"
37 #include "wx/msgout.h"
38 #include "wx/apptrait.h"
44 #if defined(__WINDOWS__)
45 #include "wx/msw/private.h"
48 #include "wx/mac/private.h"
51 // ===========================================================================
53 // ===========================================================================
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 wxMessageOutput
* wxMessageOutput::ms_msgOut
= 0;
63 wxMessageOutput
* wxMessageOutput::Get()
65 if ( !ms_msgOut
&& wxTheApp
)
67 ms_msgOut
= wxTheApp
->GetTraits()->CreateMessageOutput();
73 wxMessageOutput
* wxMessageOutput::Set(wxMessageOutput
* msgout
)
75 wxMessageOutput
* old
= ms_msgOut
;
80 // ----------------------------------------------------------------------------
81 // wxMessageOutputBest
82 // ----------------------------------------------------------------------------
86 // check if we're running in a console under Windows
87 static inline bool IsInConsole()
92 HANDLE hStdErr
= ::GetStdHandle(STD_ERROR_HANDLE
);
93 return hStdErr
&& hStdErr
!= INVALID_HANDLE_VALUE
;
94 #endif // __WXWINCE__/!__WXWINCE__
99 void wxMessageOutputBest::Printf(const wxChar
* format
, ...)
102 va_start(args
, format
);
105 out
.PrintfV(format
, args
);
109 if ( !IsInConsole() )
111 ::MessageBox(NULL
, out
, _T("wxWidgets"), MB_ICONINFORMATION
| MB_OK
);
114 #endif // __WINDOWS__/!__WINDOWS__
116 fprintf(stderr
, "%s", (const char*) out
.mb_str());
120 // ----------------------------------------------------------------------------
121 // wxMessageOutputStderr
122 // ----------------------------------------------------------------------------
124 void wxMessageOutputStderr::Printf(const wxChar
* format
, ...)
127 va_start(args
, format
);
130 out
.PrintfV(format
, args
);
133 fprintf(stderr
, "%s", (const char*) out
.mb_str());
136 // ----------------------------------------------------------------------------
137 // wxMessageOutputDebug
138 // ----------------------------------------------------------------------------
140 void wxMessageOutputDebug::Printf(const wxChar
* format
, ...)
145 va_start(args
, format
);
147 out
.PrintfV(format
, args
);
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() )
158 wxString output
= out
+ wxT(";g") ;
159 wxMacStringToPascal(output
.c_str(), pstr
);
168 wxFputs( out
, stderr
) ;
169 if ( out
.Right(1) != wxT("\n") )
170 wxFputs( wxT("\n") , stderr
) ;
175 // ----------------------------------------------------------------------------
176 // wxMessageOutputLog
177 // ----------------------------------------------------------------------------
179 void wxMessageOutputLog::Printf(const wxChar
* format
, ...)
184 va_start(args
, format
);
186 out
.PrintfV(format
, args
);
189 out
.Replace(wxT("\t"), wxT(" "));
191 ::wxLogMessage(wxT("%s"), out
.c_str());
196 // ----------------------------------------------------------------------------
197 // wxMessageOutputMessageBox
198 // ----------------------------------------------------------------------------
202 void wxMessageOutputMessageBox::Printf(const wxChar
* format
, ...)
205 va_start(args
, format
);
208 out
.PrintfV(format
, args
);
211 // the native MSW msg box understands the TABs, others don't
213 out
.Replace(wxT("\t"), wxT(" "));
218 title
.Printf(_("%s message"), wxTheApp
->GetAppName().c_str());
220 ::wxMessageBox(out
, title
);