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