]>
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$ | |
8 | // Copyright: (c) the wxWindows team | |
9 | // Licence: wxWindows licence | |
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 | |
22 | // #pragma interface/implementation correctly, iff | |
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 | ||
e6b02f3f VS |
55 | #ifdef __WXMSW__ |
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 | ||
91 | // ---------------------------------------------------------------------------- | |
92 | // wxMessageOutputStderr | |
93 | // ---------------------------------------------------------------------------- | |
94 | ||
95 | void wxMessageOutputStderr::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 | ||
401eb3de | 104 | fprintf(stderr, "%s", (const char*) out.mb_str()); |
74698d3a MB |
105 | } |
106 | ||
107 | // ---------------------------------------------------------------------------- | |
e2478fde | 108 | // wxMessageOutputDebug |
74698d3a MB |
109 | // ---------------------------------------------------------------------------- |
110 | ||
e2478fde | 111 | void wxMessageOutputDebug::Printf(const wxChar* format, ...) |
74698d3a | 112 | { |
e2478fde VZ |
113 | wxString out; |
114 | ||
74698d3a MB |
115 | va_list args; |
116 | va_start(args, format); | |
74698d3a MB |
117 | |
118 | out.PrintfV(format, args); | |
119 | va_end(args); | |
120 | ||
e2478fde | 121 | #if defined(__WXMSW__) && !defined(__WXMICROWIN__) |
311da78a | 122 | out.Replace(wxT("\t"), wxT(" ")); |
e2478fde VZ |
123 | ::OutputDebugString(out); |
124 | #elif defined(__WXMAC__) && !defined(__DARWIN__) | |
125 | if ( wxIsDebuggerRunning() ) | |
126 | { | |
127 | Str255 pstr; | |
0ff5799a | 128 | wxString output = out + wxT(";g") ; |
e2478fde VZ |
129 | wxMacStringToPascal(output.c_str(), pstr); |
130 | ||
131 | #ifdef __powerc | |
132 | DebugStr(pstr); | |
133 | #else | |
134 | SysBreakStr(pstr); | |
135 | #endif | |
136 | } | |
137 | #else // !MSW, !Mac | |
46446cc2 VZ |
138 | // FIXME: why is wxFputs() not defined under Linux? |
139 | fputs(out.mb_str(), stderr); | |
e2478fde VZ |
140 | fflush(stderr); |
141 | #endif // platform | |
74698d3a MB |
142 | } |
143 | ||
74698d3a MB |
144 | // ---------------------------------------------------------------------------- |
145 | // wxMessageOutputLog | |
146 | // ---------------------------------------------------------------------------- | |
147 | ||
74698d3a MB |
148 | void wxMessageOutputLog::Printf(const wxChar* format, ...) |
149 | { | |
a69be60b VZ |
150 | wxString out; |
151 | ||
74698d3a MB |
152 | va_list args; |
153 | va_start(args, format); | |
74698d3a MB |
154 | |
155 | out.PrintfV(format, args); | |
156 | va_end(args); | |
157 | ||
311da78a | 158 | out.Replace(wxT("\t"), wxT(" ")); |
a69be60b | 159 | |
8887e234 | 160 | ::wxLogMessage(wxT("%s"), out.c_str()); |
74698d3a | 161 | } |
e2478fde | 162 | |
ec67cff1 | 163 | #endif // wxUSE_BASE |
e2478fde VZ |
164 | |
165 | // ---------------------------------------------------------------------------- | |
166 | // wxMessageOutputMessageBox | |
167 | // ---------------------------------------------------------------------------- | |
168 | ||
169 | #if wxUSE_GUI | |
170 | ||
171 | void wxMessageOutputMessageBox::Printf(const wxChar* format, ...) | |
172 | { | |
173 | va_list args; | |
174 | va_start(args, format); | |
175 | wxString out; | |
176 | ||
177 | out.PrintfV(format, args); | |
178 | va_end(args); | |
179 | ||
180 | // the native MSW msg box understands the TABs, others don't | |
181 | #ifndef __WXMSW__ | |
182 | out.Replace(wxT("\t"), wxT(" ")); | |
183 | #endif | |
184 | ||
185 | wxString title; | |
186 | if ( wxTheApp ) | |
187 | title.Printf(_("%s message"), wxTheApp->GetAppName().c_str()); | |
188 | ||
189 | ::wxMessageBox(out, title); | |
190 | } | |
191 | ||
192 | #endif // wxUSE_GUI | |
193 |