]>
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && !defined(__EMX__)
21 // Some older compilers (such as EMX) cannot handle
22 // #pragma interface/implementation correctly, iff
23 // #pragma implementation is used in _two_ translation
24 // units (as created by e.g. event.cpp compiled for
25 // libwx_base and event.cpp compiled for libwx_gui_core).
26 // So we must not use those pragmas for those compilers in
28 #pragma implementation "msgout.h"
31 // For compilers that support precompilation, includes "wx.h".
32 #include "wx/wxprec.h"
34 #if defined(__BORLANDC__)
39 #include "wx/string.h"
44 #include "wx/msgdlg.h"
48 #include "wx/msgout.h"
49 #include "wx/apptrait.h"
55 #if defined(__WINDOWS__)
56 #include "wx/msw/private.h"
59 #include "wx/mac/private.h"
62 // ===========================================================================
64 // ===========================================================================
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 wxMessageOutput
* wxMessageOutput::ms_msgOut
= 0;
74 wxMessageOutput
* wxMessageOutput::Get()
76 if ( !ms_msgOut
&& wxTheApp
)
78 ms_msgOut
= wxTheApp
->GetTraits()->CreateMessageOutput();
84 wxMessageOutput
* wxMessageOutput::Set(wxMessageOutput
* msgout
)
86 wxMessageOutput
* old
= ms_msgOut
;
91 // ----------------------------------------------------------------------------
92 // wxMessageOutputBest
93 // ----------------------------------------------------------------------------
97 // check if we're running in a console under Windows
98 static inline bool IsInConsole()
102 #else // !__WXWINCE__
103 HANDLE hStdErr
= ::GetStdHandle(STD_ERROR_HANDLE
);
104 return hStdErr
&& hStdErr
!= INVALID_HANDLE_VALUE
;
105 #endif // __WXWINCE__/!__WXWINCE__
108 #endif // __WINDOWS__
110 void wxMessageOutputBest::Printf(const wxChar
* format
, ...)
113 va_start(args
, format
);
116 out
.PrintfV(format
, args
);
120 if ( !IsInConsole() )
122 ::MessageBox(NULL
, out
, _T("wxWidgets"), MB_ICONINFORMATION
| MB_OK
);
125 #endif // __WINDOWS__/!__WINDOWS__
127 fprintf(stderr
, "%s", (const char*) out
.mb_str());
131 // ----------------------------------------------------------------------------
132 // wxMessageOutputStderr
133 // ----------------------------------------------------------------------------
135 void wxMessageOutputStderr::Printf(const wxChar
* format
, ...)
138 va_start(args
, format
);
141 out
.PrintfV(format
, args
);
144 fprintf(stderr
, "%s", (const char*) out
.mb_str());
147 // ----------------------------------------------------------------------------
148 // wxMessageOutputDebug
149 // ----------------------------------------------------------------------------
151 void wxMessageOutputDebug::Printf(const wxChar
* format
, ...)
156 va_start(args
, format
);
158 out
.PrintfV(format
, args
);
161 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
162 out
.Replace(wxT("\t"), wxT(" "));
163 out
.Replace(wxT("\n"), wxT("\r\n"));
164 ::OutputDebugString(out
);
165 #elif defined(__WXMAC__) && !defined(__DARWIN__)
166 if ( wxIsDebuggerRunning() )
169 wxString output
= out
+ wxT(";g") ;
170 wxMacStringToPascal(output
.c_str(), pstr
);
179 wxFputs( out
, stderr
) ;
180 if ( out
.Right(1) != wxT("\n") )
181 wxFputs( wxT("\n") , stderr
) ;
186 // ----------------------------------------------------------------------------
187 // wxMessageOutputLog
188 // ----------------------------------------------------------------------------
190 void wxMessageOutputLog::Printf(const wxChar
* format
, ...)
195 va_start(args
, format
);
197 out
.PrintfV(format
, args
);
200 out
.Replace(wxT("\t"), wxT(" "));
202 ::wxLogMessage(wxT("%s"), out
.c_str());
207 // ----------------------------------------------------------------------------
208 // wxMessageOutputMessageBox
209 // ----------------------------------------------------------------------------
213 void wxMessageOutputMessageBox::Printf(const wxChar
* format
, ...)
216 va_start(args
, format
);
219 out
.PrintfV(format
, args
);
222 // the native MSW msg box understands the TABs, others don't
224 out
.Replace(wxT("\t"), wxT(" "));
229 title
.Printf(_("%s message"), wxTheApp
->GetAppName().c_str());
231 ::wxMessageBox(out
, title
);