]> git.saurik.com Git - wxWidgets.git/blame - src/common/msgout.cpp
compilation fix for wxMSW
[wxWidgets.git] / src / common / msgout.cpp
CommitLineData
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
47// ===========================================================================
48// implementation
49// ===========================================================================
50
ec67cff1 51#if wxUSE_BASE
e2478fde
VZ
52
53// ----------------------------------------------------------------------------
54// wxMessageOutput
55// ----------------------------------------------------------------------------
56
74698d3a
MB
57wxMessageOutput* wxMessageOutput::ms_msgOut = 0;
58
59wxMessageOutput* wxMessageOutput::Get()
60{
a69be60b 61 if ( !ms_msgOut && wxTheApp )
e02911a2 62 {
a69be60b 63 ms_msgOut = wxTheApp->CreateMessageOutput();
e02911a2
MB
64 }
65
74698d3a
MB
66 return ms_msgOut;
67}
68
69wxMessageOutput* wxMessageOutput::Set(wxMessageOutput* msgout)
70{
71 wxMessageOutput* old = ms_msgOut;
72 ms_msgOut = msgout;
73 return old;
74}
75
76// ----------------------------------------------------------------------------
77// wxMessageOutputStderr
78// ----------------------------------------------------------------------------
79
80void 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
401eb3de 89 fprintf(stderr, "%s", (const char*) out.mb_str());
74698d3a
MB
90}
91
92// ----------------------------------------------------------------------------
e2478fde 93// wxMessageOutputDebug
74698d3a
MB
94// ----------------------------------------------------------------------------
95
e2478fde 96void wxMessageOutputDebug::Printf(const wxChar* format, ...)
74698d3a 97{
e2478fde
VZ
98 wxString out;
99
74698d3a
MB
100 va_list args;
101 va_start(args, format);
74698d3a
MB
102
103 out.PrintfV(format, args);
104 va_end(args);
105
e2478fde 106#if defined(__WXMSW__) && !defined(__WXMICROWIN__)
311da78a 107 out.Replace(wxT("\t"), wxT(" "));
e2478fde
VZ
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
46446cc2
VZ
124 // FIXME: why is wxFputs() not defined under Linux?
125 fputs(out.mb_str(), stderr);
e2478fde
VZ
126 fflush(stderr);
127#endif // platform
74698d3a
MB
128}
129
74698d3a
MB
130// ----------------------------------------------------------------------------
131// wxMessageOutputLog
132// ----------------------------------------------------------------------------
133
74698d3a
MB
134void wxMessageOutputLog::Printf(const wxChar* format, ...)
135{
a69be60b
VZ
136 wxString out;
137
74698d3a
MB
138 va_list args;
139 va_start(args, format);
74698d3a
MB
140
141 out.PrintfV(format, args);
142 va_end(args);
143
311da78a 144 out.Replace(wxT("\t"), wxT(" "));
a69be60b 145
8887e234 146 ::wxLogMessage(wxT("%s"), out.c_str());
74698d3a 147}
e2478fde 148
ec67cff1 149#endif // wxUSE_BASE
e2478fde
VZ
150
151// ----------------------------------------------------------------------------
152// wxMessageOutputMessageBox
153// ----------------------------------------------------------------------------
154
155#if wxUSE_GUI
156
157void 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