]>
git.saurik.com Git - wxWidgets.git/blob - src/common/msgout.cpp
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 #if !wxUSE_UTF8_LOCALE_ONLY
80 void wxMessageOutput::DoPrintfWchar(const wxChar
*format
, ...)
83 va_start(args
, format
);
86 out
.PrintfV(format
, args
);
91 #endif // !wxUSE_UTF8_LOCALE_ONLY
93 #if wxUSE_UNICODE_UTF8
94 void wxMessageOutput::DoPrintfUtf8(const char *format
, ...)
97 va_start(args
, format
);
100 out
.PrintfV(format
, args
);
105 #endif // wxUSE_UNICODE_UTF8
107 // ----------------------------------------------------------------------------
108 // wxMessageOutputBest
109 // ----------------------------------------------------------------------------
113 // check if we're running in a console under Windows
114 static inline bool IsInConsole()
118 #else // !__WXWINCE__
119 HANDLE hStdErr
= ::GetStdHandle(STD_ERROR_HANDLE
);
120 return hStdErr
&& hStdErr
!= INVALID_HANDLE_VALUE
;
121 #endif // __WXWINCE__/!__WXWINCE__
124 #endif // __WINDOWS__
126 void wxMessageOutputBest::Output(const wxString
& str
)
129 if ( !IsInConsole() )
131 ::MessageBox(NULL
, str
.wx_str(), _T("wxWidgets"),
132 MB_ICONINFORMATION
| MB_OK
);
135 #endif // __WINDOWS__/!__WINDOWS__
137 const wxWX2MBbuf buf
= str
.mb_str();
140 fprintf(stderr
, "%s", (const char*) buf
);
141 else // print at least something
142 fprintf(stderr
, "%s", (const char*) str
.ToAscii());
146 // ----------------------------------------------------------------------------
147 // wxMessageOutputStderr
148 // ----------------------------------------------------------------------------
150 void wxMessageOutputStderr::Output(const wxString
& str
)
152 const wxWX2MBbuf buf
= str
.mb_str();
155 fprintf(stderr
, "%s", (const char*) buf
);
156 else // print at least something
157 fprintf(stderr
, "%s", (const char*) str
.ToAscii());
160 // ----------------------------------------------------------------------------
161 // wxMessageOutputDebug
162 // ----------------------------------------------------------------------------
164 void wxMessageOutputDebug::Output(const wxString
& str
)
168 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
169 out
.Replace(wxT("\t"), wxT(" "));
170 out
.Replace(wxT("\n"), wxT("\r\n"));
171 ::OutputDebugString(out
.wx_str());
173 wxFputs( out
, stderr
) ;
174 if ( out
.Right(1) != wxT("\n") )
175 wxFputs( wxT("\n") , stderr
) ;
180 // ----------------------------------------------------------------------------
181 // wxMessageOutputLog
182 // ----------------------------------------------------------------------------
184 void wxMessageOutputLog::Output(const wxString
& str
)
188 out
.Replace(wxT("\t"), wxT(" "));
190 ::wxLogMessage(wxT("%s"), out
.c_str());
195 // ----------------------------------------------------------------------------
196 // wxMessageOutputMessageBox
197 // ----------------------------------------------------------------------------
199 #if wxUSE_GUI && wxUSE_MSGDLG
201 void wxMessageOutputMessageBox::Output(const wxString
& str
)
205 // the native MSW msg box understands the TABs, others don't
207 out
.Replace(wxT("\t"), wxT(" "));
212 title
.Printf(_("%s message"), wxTheApp
->GetAppDisplayName().c_str());
214 ::wxMessageBox(out
, title
);