]>
Commit | Line | Data |
---|---|---|
74698d3a | 1 | ///////////////////////////////////////////////////////////////////////////// |
e4db172a | 2 | // Name: src/common/msgout.cpp |
74698d3a MB |
3 | // Purpose: wxMessageOutput implementation |
4 | // Author: Mattia Barbon | |
5 | // Modified by: | |
6 | // Created: 17.07.02 | |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) the wxWidgets team |
65571936 | 9 | // Licence: wxWindows licence |
74698d3a MB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
74698d3a MB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #if defined(__BORLANDC__) | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #ifndef WX_PRECOMP | |
28 | #include "wx/string.h" | |
29 | #include "wx/ffile.h" | |
30 | #include "wx/app.h" | |
a90253f0 | 31 | #include "wx/intl.h" |
e4db172a | 32 | #include "wx/log.h" |
74698d3a MB |
33 | #if wxUSE_GUI |
34 | #include "wx/msgdlg.h" | |
35 | #endif // wxUSE_GUI | |
36 | #endif | |
37 | ||
38 | #include "wx/msgout.h" | |
7219fc4f | 39 | #include "wx/apptrait.h" |
74698d3a MB |
40 | #include <stdarg.h> |
41 | #include <stdio.h> | |
42 | ||
532d575b | 43 | #if defined(__WINDOWS__) |
e6b02f3f VS |
44 | #include "wx/msw/private.h" |
45 | #endif | |
46 | ||
74698d3a MB |
47 | // =========================================================================== |
48 | // implementation | |
49 | // =========================================================================== | |
50 | ||
ec67cff1 | 51 | #if wxUSE_BASE |
e2478fde VZ |
52 | |
53 | // ---------------------------------------------------------------------------- | |
54 | // wxMessageOutput | |
55 | // ---------------------------------------------------------------------------- | |
56 | ||
74698d3a MB |
57 | wxMessageOutput* wxMessageOutput::ms_msgOut = 0; |
58 | ||
59 | wxMessageOutput* wxMessageOutput::Get() | |
60 | { | |
a69be60b | 61 | if ( !ms_msgOut && wxTheApp ) |
e02911a2 | 62 | { |
dc6d5e38 | 63 | ms_msgOut = wxTheApp->GetTraits()->CreateMessageOutput(); |
e02911a2 MB |
64 | } |
65 | ||
74698d3a MB |
66 | return ms_msgOut; |
67 | } | |
68 | ||
69 | wxMessageOutput* wxMessageOutput::Set(wxMessageOutput* msgout) | |
70 | { | |
71 | wxMessageOutput* old = ms_msgOut; | |
72 | ms_msgOut = msgout; | |
73 | return old; | |
74 | } | |
75 | ||
d1f6e2cf VS |
76 | #if !wxUSE_UTF8_LOCALE_ONLY |
77 | void wxMessageOutput::DoPrintfWchar(const wxChar *format, ...) | |
5b077ec7 VS |
78 | { |
79 | va_list args; | |
80 | va_start(args, format); | |
81 | wxString out; | |
82 | ||
83 | out.PrintfV(format, args); | |
84 | va_end(args); | |
85 | ||
86 | Output(out); | |
87 | } | |
d1f6e2cf VS |
88 | #endif // !wxUSE_UTF8_LOCALE_ONLY |
89 | ||
90 | #if wxUSE_UNICODE_UTF8 | |
91 | void wxMessageOutput::DoPrintfUtf8(const char *format, ...) | |
92 | { | |
93 | va_list args; | |
94 | va_start(args, format); | |
95 | wxString out; | |
96 | ||
97 | out.PrintfV(format, args); | |
98 | va_end(args); | |
99 | ||
100 | Output(out); | |
101 | } | |
102 | #endif // wxUSE_UNICODE_UTF8 | |
5b077ec7 | 103 | |
e12a951e VZ |
104 | // ---------------------------------------------------------------------------- |
105 | // wxMessageOutputBest | |
106 | // ---------------------------------------------------------------------------- | |
107 | ||
5b077ec7 | 108 | void wxMessageOutputBest::Output(const wxString& str) |
e12a951e | 109 | { |
e12a951e | 110 | #ifdef __WINDOWS__ |
784ee7d5 VZ |
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; | |
114 | ||
115 | if ( !(m_flags & wxMSGOUT_PREFER_MSGBOX) ) | |
9d03b4ee | 116 | { |
784ee7d5 VZ |
117 | if ( hasStderr && traits->WriteToStderr(AppendLineFeedIfNeeded(str)) ) |
118 | return; | |
9d03b4ee | 119 | } |
5b077ec7 | 120 | |
dc874fb4 | 121 | ::MessageBox(NULL, str.t_str(), NULL, MB_ICONINFORMATION | MB_OK); |
784ee7d5 VZ |
122 | #else // !__WINDOWS__ |
123 | // TODO: use the native message box for the other ports too | |
124 | wxMessageOutputStderr::Output(str); | |
125 | #endif // __WINDOWS__/!__WINDOWS__ | |
e12a951e VZ |
126 | } |
127 | ||
74698d3a MB |
128 | // ---------------------------------------------------------------------------- |
129 | // wxMessageOutputStderr | |
130 | // ---------------------------------------------------------------------------- | |
131 | ||
784ee7d5 VZ |
132 | wxString wxMessageOutputStderr::AppendLineFeedIfNeeded(const wxString& str) |
133 | { | |
134 | wxString strLF(str); | |
135 | if ( strLF.empty() || *strLF.rbegin() != '\n' ) | |
136 | strLF += '\n'; | |
137 | ||
138 | return strLF; | |
139 | } | |
140 | ||
5b077ec7 | 141 | void wxMessageOutputStderr::Output(const wxString& str) |
74698d3a | 142 | { |
7f173c33 VZ |
143 | const wxString strWithLF = AppendLineFeedIfNeeded(str); |
144 | const wxWX2MBbuf buf = strWithLF.mb_str(); | |
74698d3a | 145 | |
5b077ec7 VS |
146 | if ( buf ) |
147 | fprintf(stderr, "%s", (const char*) buf); | |
148 | else // print at least something | |
7f173c33 | 149 | fprintf(stderr, "%s", (const char*) strWithLF.ToAscii()); |
74698d3a MB |
150 | } |
151 | ||
152 | // ---------------------------------------------------------------------------- | |
e2478fde | 153 | // wxMessageOutputDebug |
74698d3a MB |
154 | // ---------------------------------------------------------------------------- |
155 | ||
5b077ec7 | 156 | void wxMessageOutputDebug::Output(const wxString& str) |
74698d3a | 157 | { |
82ef81ed | 158 | #if defined(__WXMSW__) && !defined(__WXMICROWIN__) |
784ee7d5 | 159 | wxString out(AppendLineFeedIfNeeded(str)); |
311da78a | 160 | out.Replace(wxT("\t"), wxT(" ")); |
7e6f48d1 | 161 | out.Replace(wxT("\n"), wxT("\r\n")); |
dc874fb4 | 162 | ::OutputDebugString(out.t_str()); |
7873ca31 | 163 | #else |
784ee7d5 VZ |
164 | // TODO: use native debug output function for the other ports too |
165 | wxMessageOutputStderr::Output(str); | |
e2478fde | 166 | #endif // platform |
74698d3a MB |
167 | } |
168 | ||
74698d3a MB |
169 | // ---------------------------------------------------------------------------- |
170 | // wxMessageOutputLog | |
171 | // ---------------------------------------------------------------------------- | |
172 | ||
5b077ec7 | 173 | void wxMessageOutputLog::Output(const wxString& str) |
74698d3a | 174 | { |
5b077ec7 | 175 | wxString out(str); |
74698d3a | 176 | |
311da78a | 177 | out.Replace(wxT("\t"), wxT(" ")); |
a69be60b | 178 | |
8887e234 | 179 | ::wxLogMessage(wxT("%s"), out.c_str()); |
74698d3a | 180 | } |
e2478fde | 181 | |
ec67cff1 | 182 | #endif // wxUSE_BASE |
e2478fde VZ |
183 | |
184 | // ---------------------------------------------------------------------------- | |
185 | // wxMessageOutputMessageBox | |
186 | // ---------------------------------------------------------------------------- | |
187 | ||
fae86641 | 188 | #if wxUSE_GUI && wxUSE_MSGDLG |
e2478fde | 189 | |
5b077ec7 | 190 | void wxMessageOutputMessageBox::Output(const wxString& str) |
e2478fde | 191 | { |
5b077ec7 | 192 | wxString out(str); |
e2478fde VZ |
193 | |
194 | // the native MSW msg box understands the TABs, others don't | |
195 | #ifndef __WXMSW__ | |
196 | out.Replace(wxT("\t"), wxT(" ")); | |
197 | #endif | |
198 | ||
997c7e46 CE |
199 | wxString title = wxT("wxWidgets") ; |
200 | if (wxTheApp) title = wxTheApp->GetAppDisplayName(); | |
e2478fde VZ |
201 | |
202 | ::wxMessageBox(out, title); | |
203 | } | |
204 | ||
205 | #endif // wxUSE_GUI |