]>
Commit | Line | Data |
---|---|---|
74698d3a MB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: common/msgout.cpp | |
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 | ||
e4844687 SN |
20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && !defined(__EMX__) |
21 | // Some older compilers (such as EMX) cannot handle | |
4e32eea1 | 22 | // #pragma interface/implementation correctly, iff |
e4844687 SN |
23 | // #pragma implementation is used in _two_ translation |
24 | // units (as created by e.g. event.cpp compiled for | |
25 | // libwx_base and event.cpp compiled for libwx_gui_core). | |
26 | // So we must not use those pragmas for those compilers in | |
27 | // such files. | |
74698d3a MB |
28 | #pragma implementation "msgout.h" |
29 | #endif | |
30 | ||
31 | // For compilers that support precompilation, includes "wx.h". | |
32 | #include "wx/wxprec.h" | |
33 | ||
34 | #if defined(__BORLANDC__) | |
35 | #pragma hdrstop | |
36 | #endif | |
37 | ||
38 | #ifndef WX_PRECOMP | |
39 | #include "wx/string.h" | |
40 | #include "wx/ffile.h" | |
41 | #include "wx/app.h" | |
a90253f0 | 42 | #include "wx/intl.h" |
74698d3a MB |
43 | #if wxUSE_GUI |
44 | #include "wx/msgdlg.h" | |
45 | #endif // wxUSE_GUI | |
46 | #endif | |
47 | ||
48 | #include "wx/msgout.h" | |
7219fc4f | 49 | #include "wx/apptrait.h" |
1303a240 | 50 | #include "wx/log.h" |
f7a75af1 | 51 | |
74698d3a MB |
52 | #include <stdarg.h> |
53 | #include <stdio.h> | |
54 | ||
82ef81ed | 55 | #if defined(__WXMSW__) |
e6b02f3f VS |
56 | #include "wx/msw/private.h" |
57 | #endif | |
0ff5799a SC |
58 | #ifdef __WXMAC__ |
59 | #include "wx/mac/private.h" | |
60 | #endif | |
e6b02f3f | 61 | |
74698d3a MB |
62 | // =========================================================================== |
63 | // implementation | |
64 | // =========================================================================== | |
65 | ||
ec67cff1 | 66 | #if wxUSE_BASE |
e2478fde VZ |
67 | |
68 | // ---------------------------------------------------------------------------- | |
69 | // wxMessageOutput | |
70 | // ---------------------------------------------------------------------------- | |
71 | ||
74698d3a MB |
72 | wxMessageOutput* wxMessageOutput::ms_msgOut = 0; |
73 | ||
74 | wxMessageOutput* wxMessageOutput::Get() | |
75 | { | |
a69be60b | 76 | if ( !ms_msgOut && wxTheApp ) |
e02911a2 | 77 | { |
dc6d5e38 | 78 | ms_msgOut = wxTheApp->GetTraits()->CreateMessageOutput(); |
e02911a2 MB |
79 | } |
80 | ||
74698d3a MB |
81 | return ms_msgOut; |
82 | } | |
83 | ||
84 | wxMessageOutput* wxMessageOutput::Set(wxMessageOutput* msgout) | |
85 | { | |
86 | wxMessageOutput* old = ms_msgOut; | |
87 | ms_msgOut = msgout; | |
88 | return old; | |
89 | } | |
90 | ||
e12a951e VZ |
91 | // ---------------------------------------------------------------------------- |
92 | // wxMessageOutputBest | |
93 | // ---------------------------------------------------------------------------- | |
94 | ||
95 | void wxMessageOutputBest::Printf(const wxChar* format, ...) | |
96 | { | |
97 | va_list args; | |
98 | va_start(args, format); | |
99 | wxString out; | |
100 | ||
101 | out.PrintfV(format, args); | |
102 | va_end(args); | |
103 | ||
104 | #ifdef __WINDOWS__ | |
9d03b4ee VZ |
105 | // check if we're running in a console |
106 | HANDLE hStdErr = ::GetStdHandle(STD_ERROR_HANDLE); | |
107 | if ( !hStdErr || hStdErr == INVALID_HANDLE_VALUE ) | |
108 | { | |
109 | ::MessageBox(NULL, out, _T("wxWidgets"), MB_ICONINFORMATION | MB_OK); | |
110 | } | |
111 | else | |
e12a951e | 112 | #endif // __WINDOWS__/!__WINDOWS__ |
9d03b4ee VZ |
113 | { |
114 | fprintf(stderr, "%s", (const char*) out.mb_str()); | |
115 | } | |
e12a951e VZ |
116 | } |
117 | ||
74698d3a MB |
118 | // ---------------------------------------------------------------------------- |
119 | // wxMessageOutputStderr | |
120 | // ---------------------------------------------------------------------------- | |
121 | ||
122 | void wxMessageOutputStderr::Printf(const wxChar* format, ...) | |
123 | { | |
124 | va_list args; | |
125 | va_start(args, format); | |
126 | wxString out; | |
127 | ||
128 | out.PrintfV(format, args); | |
129 | va_end(args); | |
130 | ||
401eb3de | 131 | fprintf(stderr, "%s", (const char*) out.mb_str()); |
74698d3a MB |
132 | } |
133 | ||
134 | // ---------------------------------------------------------------------------- | |
e2478fde | 135 | // wxMessageOutputDebug |
74698d3a MB |
136 | // ---------------------------------------------------------------------------- |
137 | ||
e2478fde | 138 | void wxMessageOutputDebug::Printf(const wxChar* format, ...) |
74698d3a | 139 | { |
e2478fde VZ |
140 | wxString out; |
141 | ||
74698d3a MB |
142 | va_list args; |
143 | va_start(args, format); | |
74698d3a MB |
144 | |
145 | out.PrintfV(format, args); | |
146 | va_end(args); | |
147 | ||
82ef81ed | 148 | #if defined(__WXMSW__) && !defined(__WXMICROWIN__) |
311da78a | 149 | out.Replace(wxT("\t"), wxT(" ")); |
7e6f48d1 | 150 | out.Replace(wxT("\n"), wxT("\r\n")); |
e2478fde | 151 | ::OutputDebugString(out); |
d6e6a35c | 152 | #elif defined(__WXMAC__) && !defined(__DARWIN__) |
e2478fde VZ |
153 | if ( wxIsDebuggerRunning() ) |
154 | { | |
155 | Str255 pstr; | |
0ff5799a | 156 | wxString output = out + wxT(";g") ; |
e2478fde VZ |
157 | wxMacStringToPascal(output.c_str(), pstr); |
158 | ||
159 | #ifdef __powerc | |
160 | DebugStr(pstr); | |
161 | #else | |
162 | SysBreakStr(pstr); | |
163 | #endif | |
164 | } | |
7873ca31 SC |
165 | #else |
166 | wxFputs( out , stderr ) ; | |
167 | if ( out.Right(1) != wxT("\n") ) | |
168 | wxFputs( wxT("\n") , stderr ) ; | |
169 | fflush( stderr ) ; | |
e2478fde | 170 | #endif // platform |
74698d3a MB |
171 | } |
172 | ||
74698d3a MB |
173 | // ---------------------------------------------------------------------------- |
174 | // wxMessageOutputLog | |
175 | // ---------------------------------------------------------------------------- | |
176 | ||
74698d3a MB |
177 | void wxMessageOutputLog::Printf(const wxChar* format, ...) |
178 | { | |
a69be60b VZ |
179 | wxString out; |
180 | ||
74698d3a MB |
181 | va_list args; |
182 | va_start(args, format); | |
74698d3a MB |
183 | |
184 | out.PrintfV(format, args); | |
185 | va_end(args); | |
186 | ||
311da78a | 187 | out.Replace(wxT("\t"), wxT(" ")); |
a69be60b | 188 | |
8887e234 | 189 | ::wxLogMessage(wxT("%s"), out.c_str()); |
74698d3a | 190 | } |
e2478fde | 191 | |
ec67cff1 | 192 | #endif // wxUSE_BASE |
e2478fde VZ |
193 | |
194 | // ---------------------------------------------------------------------------- | |
195 | // wxMessageOutputMessageBox | |
196 | // ---------------------------------------------------------------------------- | |
197 | ||
198 | #if wxUSE_GUI | |
199 | ||
200 | void wxMessageOutputMessageBox::Printf(const wxChar* format, ...) | |
201 | { | |
202 | va_list args; | |
203 | va_start(args, format); | |
204 | wxString out; | |
205 | ||
206 | out.PrintfV(format, args); | |
207 | va_end(args); | |
208 | ||
209 | // the native MSW msg box understands the TABs, others don't | |
210 | #ifndef __WXMSW__ | |
211 | out.Replace(wxT("\t"), wxT(" ")); | |
212 | #endif | |
213 | ||
214 | wxString title; | |
215 | if ( wxTheApp ) | |
216 | title.Printf(_("%s message"), wxTheApp->GetAppName().c_str()); | |
217 | ||
218 | ::wxMessageBox(out, title); | |
219 | } | |
220 | ||
221 | #endif // wxUSE_GUI | |
222 |