]> git.saurik.com Git - wxWidgets.git/blame - src/common/msgout.cpp
one more fix for tree selection
[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$
77ffb593 8// Copyright: (c) the wxWidgets team
65571936 9// Licence: wxWindows licence
74698d3a
MB
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
e4844687
SN
20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && !defined(__EMX__)
21// Some older compilers (such as EMX) cannot handle
4e32eea1 22// #pragma interface/implementation correctly, iff
e4844687
SN
23// #pragma implementation is used in _two_ translation
24// units (as created by e.g. event.cpp compiled for
25// libwx_base and event.cpp compiled for libwx_gui_core).
26// So we must not use those pragmas for those compilers in
27// such files.
74698d3a
MB
28 #pragma implementation "msgout.h"
29#endif
30
31// For compilers that support precompilation, includes "wx.h".
32#include "wx/wxprec.h"
33
34#if defined(__BORLANDC__)
35 #pragma hdrstop
36#endif
37
38#ifndef WX_PRECOMP
39 #include "wx/string.h"
40 #include "wx/ffile.h"
41 #include "wx/app.h"
a90253f0 42 #include "wx/intl.h"
74698d3a
MB
43 #if wxUSE_GUI
44 #include "wx/msgdlg.h"
45 #endif // wxUSE_GUI
46#endif
47
48#include "wx/msgout.h"
7219fc4f 49#include "wx/apptrait.h"
1303a240 50#include "wx/log.h"
f7a75af1 51
74698d3a
MB
52#include <stdarg.h>
53#include <stdio.h>
54
532d575b 55#if defined(__WINDOWS__)
e6b02f3f
VS
56 #include "wx/msw/private.h"
57#endif
0ff5799a
SC
58#ifdef __WXMAC__
59 #include "wx/mac/private.h"
60#endif
e6b02f3f 61
74698d3a
MB
62// ===========================================================================
63// implementation
64// ===========================================================================
65
ec67cff1 66#if wxUSE_BASE
e2478fde
VZ
67
68// ----------------------------------------------------------------------------
69// wxMessageOutput
70// ----------------------------------------------------------------------------
71
74698d3a
MB
72wxMessageOutput* wxMessageOutput::ms_msgOut = 0;
73
74wxMessageOutput* wxMessageOutput::Get()
75{
a69be60b 76 if ( !ms_msgOut && wxTheApp )
e02911a2 77 {
dc6d5e38 78 ms_msgOut = wxTheApp->GetTraits()->CreateMessageOutput();
e02911a2
MB
79 }
80
74698d3a
MB
81 return ms_msgOut;
82}
83
84wxMessageOutput* wxMessageOutput::Set(wxMessageOutput* msgout)
85{
86 wxMessageOutput* old = ms_msgOut;
87 ms_msgOut = msgout;
88 return old;
89}
90
e12a951e
VZ
91// ----------------------------------------------------------------------------
92// wxMessageOutputBest
93// ----------------------------------------------------------------------------
94
858cab30
VZ
95#ifdef __WINDOWS__
96
97// check if we're running in a console under Windows
98static inline bool IsInConsole()
99{
100#ifdef __WXWINCE__
101 return false;
102#else // !__WXWINCE__
103 HANDLE hStdErr = ::GetStdHandle(STD_ERROR_HANDLE);
104 return hStdErr && hStdErr != INVALID_HANDLE_VALUE;
105#endif // __WXWINCE__/!__WXWINCE__
106}
107
108#endif // __WINDOWS__
109
e12a951e
VZ
110void wxMessageOutputBest::Printf(const wxChar* format, ...)
111{
112 va_list args;
113 va_start(args, format);
114 wxString out;
115
116 out.PrintfV(format, args);
117 va_end(args);
118
119#ifdef __WINDOWS__
858cab30 120 if ( !IsInConsole() )
9d03b4ee
VZ
121 {
122 ::MessageBox(NULL, out, _T("wxWidgets"), MB_ICONINFORMATION | MB_OK);
123 }
124 else
e12a951e 125#endif // __WINDOWS__/!__WINDOWS__
9d03b4ee
VZ
126 {
127 fprintf(stderr, "%s", (const char*) out.mb_str());
128 }
e12a951e
VZ
129}
130
74698d3a
MB
131// ----------------------------------------------------------------------------
132// wxMessageOutputStderr
133// ----------------------------------------------------------------------------
134
135void wxMessageOutputStderr::Printf(const wxChar* format, ...)
136{
137 va_list args;
138 va_start(args, format);
139 wxString out;
140
141 out.PrintfV(format, args);
142 va_end(args);
143
401eb3de 144 fprintf(stderr, "%s", (const char*) out.mb_str());
74698d3a
MB
145}
146
147// ----------------------------------------------------------------------------
e2478fde 148// wxMessageOutputDebug
74698d3a
MB
149// ----------------------------------------------------------------------------
150
e2478fde 151void wxMessageOutputDebug::Printf(const wxChar* format, ...)
74698d3a 152{
e2478fde
VZ
153 wxString out;
154
74698d3a
MB
155 va_list args;
156 va_start(args, format);
74698d3a
MB
157
158 out.PrintfV(format, args);
159 va_end(args);
160
82ef81ed 161#if defined(__WXMSW__) && !defined(__WXMICROWIN__)
311da78a 162 out.Replace(wxT("\t"), wxT(" "));
7e6f48d1 163 out.Replace(wxT("\n"), wxT("\r\n"));
e2478fde 164 ::OutputDebugString(out);
d6e6a35c 165#elif defined(__WXMAC__) && !defined(__DARWIN__)
e2478fde
VZ
166 if ( wxIsDebuggerRunning() )
167 {
168 Str255 pstr;
0ff5799a 169 wxString output = out + wxT(";g") ;
e2478fde
VZ
170 wxMacStringToPascal(output.c_str(), pstr);
171
172 #ifdef __powerc
173 DebugStr(pstr);
174 #else
175 SysBreakStr(pstr);
176 #endif
177 }
7873ca31
SC
178#else
179 wxFputs( out , stderr ) ;
180 if ( out.Right(1) != wxT("\n") )
181 wxFputs( wxT("\n") , stderr ) ;
182 fflush( stderr ) ;
e2478fde 183#endif // platform
74698d3a
MB
184}
185
74698d3a
MB
186// ----------------------------------------------------------------------------
187// wxMessageOutputLog
188// ----------------------------------------------------------------------------
189
74698d3a
MB
190void wxMessageOutputLog::Printf(const wxChar* format, ...)
191{
a69be60b
VZ
192 wxString out;
193
74698d3a
MB
194 va_list args;
195 va_start(args, format);
74698d3a
MB
196
197 out.PrintfV(format, args);
198 va_end(args);
199
311da78a 200 out.Replace(wxT("\t"), wxT(" "));
a69be60b 201
8887e234 202 ::wxLogMessage(wxT("%s"), out.c_str());
74698d3a 203}
e2478fde 204
ec67cff1 205#endif // wxUSE_BASE
e2478fde
VZ
206
207// ----------------------------------------------------------------------------
208// wxMessageOutputMessageBox
209// ----------------------------------------------------------------------------
210
211#if wxUSE_GUI
212
213void wxMessageOutputMessageBox::Printf(const wxChar* format, ...)
214{
215 va_list args;
216 va_start(args, format);
217 wxString out;
218
219 out.PrintfV(format, args);
220 va_end(args);
221
222 // the native MSW msg box understands the TABs, others don't
223#ifndef __WXMSW__
224 out.Replace(wxT("\t"), wxT(" "));
225#endif
226
227 wxString title;
228 if ( wxTheApp )
229 title.Printf(_("%s message"), wxTheApp->GetAppName().c_str());
230
231 ::wxMessageBox(out, title);
232}
233
234#endif // wxUSE_GUI
235