]>
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 void wxMessageOutput::DoPrintf(const wxChar
* format
, ...)
82 va_start(args
, format
);
85 out
.PrintfV(format
, args
);
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::Output(const wxString
& str
)
113 if ( !IsInConsole() )
115 ::MessageBox(NULL
, str
, _T("wxWidgets"), MB_ICONINFORMATION
| MB_OK
);
118 #endif // __WINDOWS__/!__WINDOWS__
120 const wxWX2MBbuf buf
= str
.mb_str();
123 fprintf(stderr
, "%s", (const char*) buf
);
124 else // print at least something
125 fprintf(stderr
, "%s", (const char*) str
.ToAscii());
129 // ----------------------------------------------------------------------------
130 // wxMessageOutputStderr
131 // ----------------------------------------------------------------------------
133 void wxMessageOutputStderr::Output(const wxString
& str
)
135 const wxWX2MBbuf buf
= str
.mb_str();
138 fprintf(stderr
, "%s", (const char*) buf
);
139 else // print at least something
140 fprintf(stderr
, "%s", (const char*) str
.ToAscii());
143 // ----------------------------------------------------------------------------
144 // wxMessageOutputDebug
145 // ----------------------------------------------------------------------------
147 void wxMessageOutputDebug::Output(const wxString
& str
)
151 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
152 out
.Replace(wxT("\t"), wxT(" "));
153 out
.Replace(wxT("\n"), wxT("\r\n"));
154 ::OutputDebugString(out
);
155 #elif defined(__WXMAC__) && !defined(__DARWIN__)
156 if ( wxIsDebuggerRunning() )
159 wxString output
= out
+ wxT(";g") ;
160 wxMacStringToPascal(output
.c_str(), pstr
);
169 wxFputs( out
, stderr
) ;
170 if ( out
.Right(1) != wxT("\n") )
171 wxFputs( wxT("\n") , stderr
) ;
176 // ----------------------------------------------------------------------------
177 // wxMessageOutputLog
178 // ----------------------------------------------------------------------------
180 void wxMessageOutputLog::Output(const wxString
& str
)
184 out
.Replace(wxT("\t"), wxT(" "));
186 ::wxLogMessage(wxT("%s"), out
.c_str());
191 // ----------------------------------------------------------------------------
192 // wxMessageOutputMessageBox
193 // ----------------------------------------------------------------------------
197 void wxMessageOutputMessageBox::Output(const wxString
& str
)
201 // the native MSW msg box understands the TABs, others don't
203 out
.Replace(wxT("\t"), wxT(" "));
208 title
.Printf(_("%s message"), wxTheApp
->GetAppName().c_str());
210 ::wxMessageBox(out
, title
);