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