]>
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
, _T("wxWidgets"), MB_ICONINFORMATION
| MB_OK
);
134 #endif // __WINDOWS__/!__WINDOWS__
136 const wxWX2MBbuf buf
= str
.mb_str();
139 fprintf(stderr
, "%s", (const char*) buf
);
140 else // print at least something
141 fprintf(stderr
, "%s", (const char*) str
.ToAscii());
145 // ----------------------------------------------------------------------------
146 // wxMessageOutputStderr
147 // ----------------------------------------------------------------------------
149 void wxMessageOutputStderr::Output(const wxString
& str
)
151 const wxWX2MBbuf buf
= str
.mb_str();
154 fprintf(stderr
, "%s", (const char*) buf
);
155 else // print at least something
156 fprintf(stderr
, "%s", (const char*) str
.ToAscii());
159 // ----------------------------------------------------------------------------
160 // wxMessageOutputDebug
161 // ----------------------------------------------------------------------------
163 void wxMessageOutputDebug::Output(const wxString
& str
)
167 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
168 out
.Replace(wxT("\t"), wxT(" "));
169 out
.Replace(wxT("\n"), wxT("\r\n"));
170 ::OutputDebugString(out
);
171 #elif defined(__WXMAC__) && !defined(__DARWIN__)
172 if ( wxIsDebuggerRunning() )
175 wxString output
= out
+ wxT(";g") ;
176 wxMacStringToPascal(output
.c_str(), pstr
);
185 wxFputs( out
, stderr
) ;
186 if ( out
.Right(1) != wxT("\n") )
187 wxFputs( wxT("\n") , stderr
) ;
192 // ----------------------------------------------------------------------------
193 // wxMessageOutputLog
194 // ----------------------------------------------------------------------------
196 void wxMessageOutputLog::Output(const wxString
& str
)
200 out
.Replace(wxT("\t"), wxT(" "));
202 ::wxLogMessage(wxT("%s"), out
.c_str());
207 // ----------------------------------------------------------------------------
208 // wxMessageOutputMessageBox
209 // ----------------------------------------------------------------------------
213 void wxMessageOutputMessageBox::Output(const wxString
& str
)
217 // the native MSW msg box understands the TABs, others don't
219 out
.Replace(wxT("\t"), wxT(" "));
224 title
.Printf(_("%s message"), wxTheApp
->GetAppName().c_str());
226 ::wxMessageBox(out
, title
);