]>
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
7 // Copyright: (c) the wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
22 #if defined(__BORLANDC__)
27 #include "wx/string.h"
33 #include "wx/msgdlg.h"
37 #include "wx/msgout.h"
38 #include "wx/apptrait.h"
42 #if defined(__WINDOWS__)
43 #include "wx/msw/private.h"
46 // ===========================================================================
48 // ===========================================================================
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 wxMessageOutput
* wxMessageOutput::ms_msgOut
= 0;
58 wxMessageOutput
* wxMessageOutput::Get()
60 if ( !ms_msgOut
&& wxTheApp
)
62 ms_msgOut
= wxTheApp
->GetTraits()->CreateMessageOutput();
68 wxMessageOutput
* wxMessageOutput::Set(wxMessageOutput
* msgout
)
70 wxMessageOutput
* old
= ms_msgOut
;
75 #if !wxUSE_UTF8_LOCALE_ONLY
76 void wxMessageOutput::DoPrintfWchar(const wxChar
*format
, ...)
79 va_start(args
, format
);
82 out
.PrintfV(format
, args
);
87 #endif // !wxUSE_UTF8_LOCALE_ONLY
89 #if wxUSE_UNICODE_UTF8
90 void wxMessageOutput::DoPrintfUtf8(const char *format
, ...)
93 va_start(args
, format
);
96 out
.PrintfV(format
, args
);
101 #endif // wxUSE_UNICODE_UTF8
103 // ----------------------------------------------------------------------------
104 // wxMessageOutputBest
105 // ----------------------------------------------------------------------------
107 void wxMessageOutputBest::Output(const wxString
& str
)
110 // decide whether to use console output or not
111 wxAppTraits
* const traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
112 const bool hasStderr
= traits
? traits
->CanUseStderr() : false;
114 if ( !(m_flags
& wxMSGOUT_PREFER_MSGBOX
) )
116 if ( hasStderr
&& traits
->WriteToStderr(AppendLineFeedIfNeeded(str
)) )
122 title
= wxTheApp
->GetAppDisplayName();
123 else // Use some title to avoid default "Error"
124 title
= _("Message");
126 ::MessageBox(NULL
, str
.t_str(), title
.t_str(), MB_ICONINFORMATION
| MB_OK
);
127 #else // !__WINDOWS__
128 wxUnusedVar(m_flags
);
130 // TODO: use the native message box for the other ports too
131 wxMessageOutputStderr::Output(str
);
132 #endif // __WINDOWS__/!__WINDOWS__
135 // ----------------------------------------------------------------------------
136 // wxMessageOutputStderr
137 // ----------------------------------------------------------------------------
139 wxString
wxMessageOutputStderr::AppendLineFeedIfNeeded(const wxString
& str
)
142 if ( strLF
.empty() || *strLF
.rbegin() != '\n' )
148 void wxMessageOutputStderr::Output(const wxString
& str
)
150 const wxString strWithLF
= AppendLineFeedIfNeeded(str
);
151 const wxWX2MBbuf buf
= strWithLF
.mb_str();
154 fprintf(m_fp
, "%s", (const char*) buf
);
155 else // print at least something
156 fprintf(m_fp
, "%s", (const char*) strWithLF
.ToAscii());
161 // ----------------------------------------------------------------------------
162 // wxMessageOutputDebug
163 // ----------------------------------------------------------------------------
165 void wxMessageOutputDebug::Output(const wxString
& str
)
167 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
168 wxString
out(AppendLineFeedIfNeeded(str
));
169 out
.Replace(wxT("\t"), wxT(" "));
170 out
.Replace(wxT("\n"), wxT("\r\n"));
171 ::OutputDebugString(out
.t_str());
173 // TODO: use native debug output function for the other ports too
174 wxMessageOutputStderr::Output(str
);
178 // ----------------------------------------------------------------------------
179 // wxMessageOutputLog
180 // ----------------------------------------------------------------------------
182 void wxMessageOutputLog::Output(const wxString
& str
)
186 out
.Replace(wxT("\t"), wxT(" "));
188 wxLogMessage(wxT("%s"), out
.c_str());
193 // ----------------------------------------------------------------------------
194 // wxMessageOutputMessageBox
195 // ----------------------------------------------------------------------------
197 #if wxUSE_GUI && wxUSE_MSGDLG
199 extern WXDLLEXPORT_DATA(const char) wxMessageBoxCaptionStr
[] = "Message";
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(" "));
210 wxString title
= wxT("wxWidgets") ;
211 if (wxTheApp
) title
= wxTheApp
->GetAppDisplayName();
213 ::wxMessageBox(out
, title
);