]>
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 | |
0ff5799a SC |
46 | #ifdef __WXMAC__ |
47 | #include "wx/mac/private.h" | |
48 | #endif | |
e6b02f3f | 49 | |
74698d3a MB |
50 | // =========================================================================== |
51 | // implementation | |
52 | // =========================================================================== | |
53 | ||
ec67cff1 | 54 | #if wxUSE_BASE |
e2478fde VZ |
55 | |
56 | // ---------------------------------------------------------------------------- | |
57 | // wxMessageOutput | |
58 | // ---------------------------------------------------------------------------- | |
59 | ||
74698d3a MB |
60 | wxMessageOutput* wxMessageOutput::ms_msgOut = 0; |
61 | ||
62 | wxMessageOutput* wxMessageOutput::Get() | |
63 | { | |
a69be60b | 64 | if ( !ms_msgOut && wxTheApp ) |
e02911a2 | 65 | { |
dc6d5e38 | 66 | ms_msgOut = wxTheApp->GetTraits()->CreateMessageOutput(); |
e02911a2 MB |
67 | } |
68 | ||
74698d3a MB |
69 | return ms_msgOut; |
70 | } | |
71 | ||
72 | wxMessageOutput* wxMessageOutput::Set(wxMessageOutput* msgout) | |
73 | { | |
74 | wxMessageOutput* old = ms_msgOut; | |
75 | ms_msgOut = msgout; | |
76 | return old; | |
77 | } | |
78 | ||
b5536269 | 79 | void wxMessageOutput::DoPrintf(const wxChar* format, ...) |
5b077ec7 VS |
80 | { |
81 | va_list args; | |
82 | va_start(args, format); | |
83 | wxString out; | |
84 | ||
85 | out.PrintfV(format, args); | |
86 | va_end(args); | |
87 | ||
88 | Output(out); | |
89 | } | |
90 | ||
e12a951e VZ |
91 | // ---------------------------------------------------------------------------- |
92 | // wxMessageOutputBest | |
93 | // ---------------------------------------------------------------------------- | |
94 | ||
858cab30 VZ |
95 | #ifdef __WINDOWS__ |
96 | ||
97 | // check if we're running in a console under Windows | |
98 | static inline bool IsInConsole() | |
99 | { | |
100 | #ifdef __WXWINCE__ | |
101 | return false; | |
102 | #else // !__WXWINCE__ | |
103 | HANDLE hStdErr = ::GetStdHandle(STD_ERROR_HANDLE); | |
104 | return hStdErr && hStdErr != INVALID_HANDLE_VALUE; | |
105 | #endif // __WXWINCE__/!__WXWINCE__ | |
106 | } | |
107 | ||
108 | #endif // __WINDOWS__ | |
109 | ||
5b077ec7 | 110 | void wxMessageOutputBest::Output(const wxString& str) |
e12a951e | 111 | { |
e12a951e | 112 | #ifdef __WINDOWS__ |
858cab30 | 113 | if ( !IsInConsole() ) |
9d03b4ee | 114 | { |
5b077ec7 | 115 | ::MessageBox(NULL, str, _T("wxWidgets"), MB_ICONINFORMATION | MB_OK); |
9d03b4ee VZ |
116 | } |
117 | else | |
e12a951e | 118 | #endif // __WINDOWS__/!__WINDOWS__ |
9d03b4ee | 119 | { |
8237a1c0 | 120 | const wxWX2MBbuf buf = str.mb_str(); |
5b077ec7 VS |
121 | |
122 | if ( buf ) | |
123 | fprintf(stderr, "%s", (const char*) buf); | |
124 | else // print at least something | |
125 | fprintf(stderr, "%s", (const char*) str.ToAscii()); | |
9d03b4ee | 126 | } |
e12a951e VZ |
127 | } |
128 | ||
74698d3a MB |
129 | // ---------------------------------------------------------------------------- |
130 | // wxMessageOutputStderr | |
131 | // ---------------------------------------------------------------------------- | |
132 | ||
5b077ec7 | 133 | void wxMessageOutputStderr::Output(const wxString& str) |
74698d3a | 134 | { |
8237a1c0 | 135 | const wxWX2MBbuf buf = str.mb_str(); |
74698d3a | 136 | |
5b077ec7 VS |
137 | if ( buf ) |
138 | fprintf(stderr, "%s", (const char*) buf); | |
139 | else // print at least something | |
140 | fprintf(stderr, "%s", (const char*) str.ToAscii()); | |
74698d3a MB |
141 | } |
142 | ||
143 | // ---------------------------------------------------------------------------- | |
e2478fde | 144 | // wxMessageOutputDebug |
74698d3a MB |
145 | // ---------------------------------------------------------------------------- |
146 | ||
5b077ec7 | 147 | void wxMessageOutputDebug::Output(const wxString& str) |
74698d3a | 148 | { |
5b077ec7 | 149 | wxString out(str); |
74698d3a | 150 | |
82ef81ed | 151 | #if defined(__WXMSW__) && !defined(__WXMICROWIN__) |
311da78a | 152 | out.Replace(wxT("\t"), wxT(" ")); |
7e6f48d1 | 153 | out.Replace(wxT("\n"), wxT("\r\n")); |
e2478fde | 154 | ::OutputDebugString(out); |
d6e6a35c | 155 | #elif defined(__WXMAC__) && !defined(__DARWIN__) |
e2478fde VZ |
156 | if ( wxIsDebuggerRunning() ) |
157 | { | |
158 | Str255 pstr; | |
0ff5799a | 159 | wxString output = out + wxT(";g") ; |
e2478fde VZ |
160 | wxMacStringToPascal(output.c_str(), pstr); |
161 | ||
162 | #ifdef __powerc | |
163 | DebugStr(pstr); | |
164 | #else | |
165 | SysBreakStr(pstr); | |
166 | #endif | |
167 | } | |
7873ca31 SC |
168 | #else |
169 | wxFputs( out , stderr ) ; | |
170 | if ( out.Right(1) != wxT("\n") ) | |
171 | wxFputs( wxT("\n") , stderr ) ; | |
172 | fflush( stderr ) ; | |
e2478fde | 173 | #endif // platform |
74698d3a MB |
174 | } |
175 | ||
74698d3a MB |
176 | // ---------------------------------------------------------------------------- |
177 | // wxMessageOutputLog | |
178 | // ---------------------------------------------------------------------------- | |
179 | ||
5b077ec7 | 180 | void wxMessageOutputLog::Output(const wxString& str) |
74698d3a | 181 | { |
5b077ec7 | 182 | wxString out(str); |
74698d3a | 183 | |
311da78a | 184 | out.Replace(wxT("\t"), wxT(" ")); |
a69be60b | 185 | |
8887e234 | 186 | ::wxLogMessage(wxT("%s"), out.c_str()); |
74698d3a | 187 | } |
e2478fde | 188 | |
ec67cff1 | 189 | #endif // wxUSE_BASE |
e2478fde VZ |
190 | |
191 | // ---------------------------------------------------------------------------- | |
192 | // wxMessageOutputMessageBox | |
193 | // ---------------------------------------------------------------------------- | |
194 | ||
195 | #if wxUSE_GUI | |
196 | ||
5b077ec7 | 197 | void wxMessageOutputMessageBox::Output(const wxString& str) |
e2478fde | 198 | { |
5b077ec7 | 199 | wxString out(str); |
e2478fde VZ |
200 | |
201 | // the native MSW msg box understands the TABs, others don't | |
202 | #ifndef __WXMSW__ | |
203 | out.Replace(wxT("\t"), wxT(" ")); | |
204 | #endif | |
205 | ||
206 | wxString title; | |
207 | if ( wxTheApp ) | |
208 | title.Printf(_("%s message"), wxTheApp->GetAppName().c_str()); | |
209 | ||
210 | ::wxMessageBox(out, title); | |
211 | } | |
212 | ||
213 | #endif // wxUSE_GUI |