]>
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 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
74698d3a MB |
21 | #pragma implementation "msgout.h" |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #if defined(__BORLANDC__) | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #include "wx/string.h" | |
33 | #include "wx/ffile.h" | |
34 | #include "wx/app.h" | |
a90253f0 | 35 | #include "wx/intl.h" |
74698d3a MB |
36 | #if wxUSE_GUI |
37 | #include "wx/msgdlg.h" | |
38 | #endif // wxUSE_GUI | |
39 | #endif | |
40 | ||
41 | #include "wx/msgout.h" | |
7219fc4f | 42 | #include "wx/apptrait.h" |
1303a240 | 43 | #include "wx/log.h" |
f7a75af1 | 44 | |
74698d3a MB |
45 | #include <stdarg.h> |
46 | #include <stdio.h> | |
47 | ||
e6b02f3f VS |
48 | #ifdef __WXMSW__ |
49 | #include "wx/msw/private.h" | |
50 | #endif | |
0ff5799a SC |
51 | #ifdef __WXMAC__ |
52 | #include "wx/mac/private.h" | |
53 | #endif | |
e6b02f3f | 54 | |
74698d3a MB |
55 | // =========================================================================== |
56 | // implementation | |
57 | // =========================================================================== | |
58 | ||
ec67cff1 | 59 | #if wxUSE_BASE |
e2478fde VZ |
60 | |
61 | // ---------------------------------------------------------------------------- | |
62 | // wxMessageOutput | |
63 | // ---------------------------------------------------------------------------- | |
64 | ||
74698d3a MB |
65 | wxMessageOutput* wxMessageOutput::ms_msgOut = 0; |
66 | ||
67 | wxMessageOutput* wxMessageOutput::Get() | |
68 | { | |
a69be60b | 69 | if ( !ms_msgOut && wxTheApp ) |
e02911a2 | 70 | { |
dc6d5e38 | 71 | ms_msgOut = wxTheApp->GetTraits()->CreateMessageOutput(); |
e02911a2 MB |
72 | } |
73 | ||
74698d3a MB |
74 | return ms_msgOut; |
75 | } | |
76 | ||
77 | wxMessageOutput* wxMessageOutput::Set(wxMessageOutput* msgout) | |
78 | { | |
79 | wxMessageOutput* old = ms_msgOut; | |
80 | ms_msgOut = msgout; | |
81 | return old; | |
82 | } | |
83 | ||
84 | // ---------------------------------------------------------------------------- | |
85 | // wxMessageOutputStderr | |
86 | // ---------------------------------------------------------------------------- | |
87 | ||
88 | void wxMessageOutputStderr::Printf(const wxChar* format, ...) | |
89 | { | |
90 | va_list args; | |
91 | va_start(args, format); | |
92 | wxString out; | |
93 | ||
94 | out.PrintfV(format, args); | |
95 | va_end(args); | |
96 | ||
401eb3de | 97 | fprintf(stderr, "%s", (const char*) out.mb_str()); |
74698d3a MB |
98 | } |
99 | ||
100 | // ---------------------------------------------------------------------------- | |
e2478fde | 101 | // wxMessageOutputDebug |
74698d3a MB |
102 | // ---------------------------------------------------------------------------- |
103 | ||
e2478fde | 104 | void wxMessageOutputDebug::Printf(const wxChar* format, ...) |
74698d3a | 105 | { |
e2478fde VZ |
106 | wxString out; |
107 | ||
74698d3a MB |
108 | va_list args; |
109 | va_start(args, format); | |
74698d3a MB |
110 | |
111 | out.PrintfV(format, args); | |
112 | va_end(args); | |
113 | ||
e2478fde | 114 | #if defined(__WXMSW__) && !defined(__WXMICROWIN__) |
311da78a | 115 | out.Replace(wxT("\t"), wxT(" ")); |
e2478fde VZ |
116 | out += _T("\r\n"); |
117 | ::OutputDebugString(out); | |
118 | #elif defined(__WXMAC__) && !defined(__DARWIN__) | |
119 | if ( wxIsDebuggerRunning() ) | |
120 | { | |
121 | Str255 pstr; | |
0ff5799a | 122 | wxString output = out + wxT(";g") ; |
e2478fde VZ |
123 | wxMacStringToPascal(output.c_str(), pstr); |
124 | ||
125 | #ifdef __powerc | |
126 | DebugStr(pstr); | |
127 | #else | |
128 | SysBreakStr(pstr); | |
129 | #endif | |
130 | } | |
131 | #else // !MSW, !Mac | |
46446cc2 VZ |
132 | // FIXME: why is wxFputs() not defined under Linux? |
133 | fputs(out.mb_str(), stderr); | |
e2478fde VZ |
134 | fflush(stderr); |
135 | #endif // platform | |
74698d3a MB |
136 | } |
137 | ||
74698d3a MB |
138 | // ---------------------------------------------------------------------------- |
139 | // wxMessageOutputLog | |
140 | // ---------------------------------------------------------------------------- | |
141 | ||
74698d3a MB |
142 | void wxMessageOutputLog::Printf(const wxChar* format, ...) |
143 | { | |
a69be60b VZ |
144 | wxString out; |
145 | ||
74698d3a MB |
146 | va_list args; |
147 | va_start(args, format); | |
74698d3a MB |
148 | |
149 | out.PrintfV(format, args); | |
150 | va_end(args); | |
151 | ||
311da78a | 152 | out.Replace(wxT("\t"), wxT(" ")); |
a69be60b | 153 | |
8887e234 | 154 | ::wxLogMessage(wxT("%s"), out.c_str()); |
74698d3a | 155 | } |
e2478fde | 156 | |
ec67cff1 | 157 | #endif // wxUSE_BASE |
e2478fde VZ |
158 | |
159 | // ---------------------------------------------------------------------------- | |
160 | // wxMessageOutputMessageBox | |
161 | // ---------------------------------------------------------------------------- | |
162 | ||
163 | #if wxUSE_GUI | |
164 | ||
165 | void wxMessageOutputMessageBox::Printf(const wxChar* format, ...) | |
166 | { | |
167 | va_list args; | |
168 | va_start(args, format); | |
169 | wxString out; | |
170 | ||
171 | out.PrintfV(format, args); | |
172 | va_end(args); | |
173 | ||
174 | // the native MSW msg box understands the TABs, others don't | |
175 | #ifndef __WXMSW__ | |
176 | out.Replace(wxT("\t"), wxT(" ")); | |
177 | #endif | |
178 | ||
179 | wxString title; | |
180 | if ( wxTheApp ) | |
181 | title.Printf(_("%s message"), wxTheApp->GetAppName().c_str()); | |
182 | ||
183 | ::wxMessageBox(out, title); | |
184 | } | |
185 | ||
186 | #endif // wxUSE_GUI | |
187 |