]>
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 // ===========================================================================
49 // ===========================================================================
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 wxMessageOutput
* wxMessageOutput::ms_msgOut
= 0;
59 wxMessageOutput
* wxMessageOutput::Get()
61 if ( !ms_msgOut
&& wxTheApp
)
63 ms_msgOut
= wxTheApp
->GetTraits()->CreateMessageOutput();
69 wxMessageOutput
* wxMessageOutput::Set(wxMessageOutput
* msgout
)
71 wxMessageOutput
* old
= ms_msgOut
;
76 #if !wxUSE_UTF8_LOCALE_ONLY
77 void wxMessageOutput::DoPrintfWchar(const wxChar
*format
, ...)
80 va_start(args
, format
);
83 out
.PrintfV(format
, args
);
88 #endif // !wxUSE_UTF8_LOCALE_ONLY
90 #if wxUSE_UNICODE_UTF8
91 void wxMessageOutput::DoPrintfUtf8(const char *format
, ...)
94 va_start(args
, format
);
97 out
.PrintfV(format
, args
);
102 #endif // wxUSE_UNICODE_UTF8
104 // ----------------------------------------------------------------------------
105 // wxMessageOutputBest
106 // ----------------------------------------------------------------------------
110 // check if we're running in a console under Windows
111 static inline bool IsInConsole()
115 #else // !__WXWINCE__
116 HANDLE hStdErr
= ::GetStdHandle(STD_ERROR_HANDLE
);
117 return hStdErr
&& hStdErr
!= INVALID_HANDLE_VALUE
;
118 #endif // __WXWINCE__/!__WXWINCE__
121 #endif // __WINDOWS__
123 void wxMessageOutputBest::Output(const wxString
& str
)
126 if ( !IsInConsole() )
128 ::MessageBox(NULL
, str
.wx_str(), _T("wxWidgets"),
129 MB_ICONINFORMATION
| MB_OK
);
132 #endif // __WINDOWS__/!__WINDOWS__
134 const wxWX2MBbuf buf
= str
.mb_str();
137 fprintf(stderr
, "%s", (const char*) buf
);
138 else // print at least something
139 fprintf(stderr
, "%s", (const char*) str
.ToAscii());
143 // ----------------------------------------------------------------------------
144 // wxMessageOutputStderr
145 // ----------------------------------------------------------------------------
147 void wxMessageOutputStderr::Output(const wxString
& str
)
149 const wxWX2MBbuf buf
= str
.mb_str();
152 fprintf(stderr
, "%s", (const char*) buf
);
153 else // print at least something
154 fprintf(stderr
, "%s", (const char*) str
.ToAscii());
157 // ----------------------------------------------------------------------------
158 // wxMessageOutputDebug
159 // ----------------------------------------------------------------------------
161 void wxMessageOutputDebug::Output(const wxString
& str
)
165 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
166 out
.Replace(wxT("\t"), wxT(" "));
167 out
.Replace(wxT("\n"), wxT("\r\n"));
168 ::OutputDebugString(out
.wx_str());
170 wxFputs( out
, stderr
) ;
171 if ( out
.Right(1) != wxT("\n") )
172 wxFputs( wxT("\n") , stderr
) ;
177 // ----------------------------------------------------------------------------
178 // wxMessageOutputLog
179 // ----------------------------------------------------------------------------
181 void wxMessageOutputLog::Output(const wxString
& str
)
185 out
.Replace(wxT("\t"), wxT(" "));
187 ::wxLogMessage(wxT("%s"), out
.c_str());
192 // ----------------------------------------------------------------------------
193 // wxMessageOutputMessageBox
194 // ----------------------------------------------------------------------------
196 #if wxUSE_GUI && wxUSE_MSGDLG
198 void wxMessageOutputMessageBox::Output(const wxString
& str
)
202 // the native MSW msg box understands the TABs, others don't
204 out
.Replace(wxT("\t"), wxT(" "));
209 title
.Printf(_("%s message"), wxTheApp
->GetAppDisplayName().c_str());
211 ::wxMessageBox(out
, title
);