wxBase/GUI separation: 1st step, wxMSW should build, all the rest is broken
[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 wxFputs(out, stderr);
125 fflush(stderr);
126 #endif // platform
127 }
128
129 // ----------------------------------------------------------------------------
130 // wxMessageOutputLog
131 // ----------------------------------------------------------------------------
132
133 void wxMessageOutputLog::Printf(const wxChar* format, ...)
134 {
135 wxString out;
136
137 va_list args;
138 va_start(args, format);
139
140 out.PrintfV(format, args);
141 va_end(args);
142
143 out.Replace(wxT("\t"), wxT(" "));
144
145 ::wxLogMessage(wxT("%s"), out.c_str());
146 }
147
148 #endif // __WXBASE__
149
150 // ----------------------------------------------------------------------------
151 // wxMessageOutputMessageBox
152 // ----------------------------------------------------------------------------
153
154 #if wxUSE_GUI
155
156 void wxMessageOutputMessageBox::Printf(const wxChar* format, ...)
157 {
158 va_list args;
159 va_start(args, format);
160 wxString out;
161
162 out.PrintfV(format, args);
163 va_end(args);
164
165 // the native MSW msg box understands the TABs, others don't
166 #ifndef __WXMSW__
167 out.Replace(wxT("\t"), wxT(" "));
168 #endif
169
170 wxString title;
171 if ( wxTheApp )
172 title.Printf(_("%s message"), wxTheApp->GetAppName().c_str());
173
174 ::wxMessageBox(out, title);
175 }
176
177 #endif // wxUSE_GUI
178