]>
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 // ----------------------------------------------------------------------------
108 void wxMessageOutputBest::Output(const wxString
& str
)
111 // decide whether to use console output or not
112 wxAppTraits
* const traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
113 const bool hasStderr
= traits
? traits
->CanUseStderr() : false;
115 if ( !(m_flags
& wxMSGOUT_PREFER_MSGBOX
) )
117 if ( hasStderr
&& traits
->WriteToStderr(AppendLineFeedIfNeeded(str
)) )
123 title
= wxTheApp
->GetAppDisplayName();
124 else // Use some title to avoid default "Error"
125 title
= _("Message");
127 ::MessageBox(NULL
, str
.t_str(), title
.t_str(), MB_ICONINFORMATION
| MB_OK
);
128 #else // !__WINDOWS__
129 wxUnusedVar(m_flags
);
131 // TODO: use the native message box for the other ports too
132 wxMessageOutputStderr::Output(str
);
133 #endif // __WINDOWS__/!__WINDOWS__
136 // ----------------------------------------------------------------------------
137 // wxMessageOutputStderr
138 // ----------------------------------------------------------------------------
140 wxString
wxMessageOutputStderr::AppendLineFeedIfNeeded(const wxString
& str
)
143 if ( strLF
.empty() || *strLF
.rbegin() != '\n' )
149 void wxMessageOutputStderr::Output(const wxString
& str
)
151 const wxString strWithLF
= AppendLineFeedIfNeeded(str
);
152 const wxWX2MBbuf buf
= strWithLF
.mb_str();
155 fprintf(m_fp
, "%s", (const char*) buf
);
156 else // print at least something
157 fprintf(m_fp
, "%s", (const char*) strWithLF
.ToAscii());
162 // ----------------------------------------------------------------------------
163 // wxMessageOutputDebug
164 // ----------------------------------------------------------------------------
166 void wxMessageOutputDebug::Output(const wxString
& str
)
168 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
169 wxString
out(AppendLineFeedIfNeeded(str
));
170 out
.Replace(wxT("\t"), wxT(" "));
171 out
.Replace(wxT("\n"), wxT("\r\n"));
172 ::OutputDebugString(out
.t_str());
174 // TODO: use native debug output function for the other ports too
175 wxMessageOutputStderr::Output(str
);
179 // ----------------------------------------------------------------------------
180 // wxMessageOutputLog
181 // ----------------------------------------------------------------------------
183 void wxMessageOutputLog::Output(const wxString
& str
)
187 out
.Replace(wxT("\t"), wxT(" "));
189 wxLogMessage(wxT("%s"), out
.c_str());
194 // ----------------------------------------------------------------------------
195 // wxMessageOutputMessageBox
196 // ----------------------------------------------------------------------------
198 #if wxUSE_GUI && wxUSE_MSGDLG
200 extern WXDLLEXPORT_DATA(const char) wxMessageBoxCaptionStr
[] = "Message";
202 void wxMessageOutputMessageBox::Output(const wxString
& str
)
206 // the native MSW msg box understands the TABs, others don't
208 out
.Replace(wxT("\t"), wxT(" "));
211 wxString title
= wxT("wxWidgets") ;
212 if (wxTheApp
) title
= wxTheApp
->GetAppDisplayName();
214 ::wxMessageBox(out
, title
);