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