]> git.saurik.com Git - wxWidgets.git/blame - src/common/msgout.cpp
remove unused static function (avoids a warning about it)
[wxWidgets.git] / src / common / msgout.cpp
CommitLineData
74698d3a 1/////////////////////////////////////////////////////////////////////////////
e4db172a 2// Name: src/common/msgout.cpp
74698d3a
MB
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
74698d3a
MB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#if defined(__BORLANDC__)
24 #pragma hdrstop
25#endif
26
27#ifndef WX_PRECOMP
28 #include "wx/string.h"
29 #include "wx/ffile.h"
30 #include "wx/app.h"
a90253f0 31 #include "wx/intl.h"
e4db172a 32 #include "wx/log.h"
74698d3a
MB
33 #if wxUSE_GUI
34 #include "wx/msgdlg.h"
35 #endif // wxUSE_GUI
36#endif
37
38#include "wx/msgout.h"
7219fc4f 39#include "wx/apptrait.h"
74698d3a
MB
40#include <stdarg.h>
41#include <stdio.h>
42
532d575b 43#if defined(__WINDOWS__)
e6b02f3f
VS
44 #include "wx/msw/private.h"
45#endif
0ff5799a
SC
46#ifdef __WXMAC__
47 #include "wx/mac/private.h"
48#endif
e6b02f3f 49
74698d3a
MB
50// ===========================================================================
51// implementation
52// ===========================================================================
53
ec67cff1 54#if wxUSE_BASE
e2478fde
VZ
55
56// ----------------------------------------------------------------------------
57// wxMessageOutput
58// ----------------------------------------------------------------------------
59
74698d3a
MB
60wxMessageOutput* wxMessageOutput::ms_msgOut = 0;
61
62wxMessageOutput* wxMessageOutput::Get()
63{
a69be60b 64 if ( !ms_msgOut && wxTheApp )
e02911a2 65 {
dc6d5e38 66 ms_msgOut = wxTheApp->GetTraits()->CreateMessageOutput();
e02911a2
MB
67 }
68
74698d3a
MB
69 return ms_msgOut;
70}
71
72wxMessageOutput* wxMessageOutput::Set(wxMessageOutput* msgout)
73{
74 wxMessageOutput* old = ms_msgOut;
75 ms_msgOut = msgout;
76 return old;
77}
78
d1f6e2cf
VS
79#if !wxUSE_UTF8_LOCALE_ONLY
80void wxMessageOutput::DoPrintfWchar(const wxChar *format, ...)
5b077ec7
VS
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 Output(out);
90}
d1f6e2cf
VS
91#endif // !wxUSE_UTF8_LOCALE_ONLY
92
93#if wxUSE_UNICODE_UTF8
94void wxMessageOutput::DoPrintfUtf8(const char *format, ...)
95{
96 va_list args;
97 va_start(args, format);
98 wxString out;
99
100 out.PrintfV(format, args);
101 va_end(args);
102
103 Output(out);
104}
105#endif // wxUSE_UNICODE_UTF8
5b077ec7 106
e12a951e
VZ
107// ----------------------------------------------------------------------------
108// wxMessageOutputBest
109// ----------------------------------------------------------------------------
110
858cab30
VZ
111#ifdef __WINDOWS__
112
113// check if we're running in a console under Windows
114static inline bool IsInConsole()
115{
116#ifdef __WXWINCE__
117 return false;
118#else // !__WXWINCE__
119 HANDLE hStdErr = ::GetStdHandle(STD_ERROR_HANDLE);
120 return hStdErr && hStdErr != INVALID_HANDLE_VALUE;
121#endif // __WXWINCE__/!__WXWINCE__
122}
123
124#endif // __WINDOWS__
125
5b077ec7 126void wxMessageOutputBest::Output(const wxString& str)
e12a951e 127{
e12a951e 128#ifdef __WINDOWS__
858cab30 129 if ( !IsInConsole() )
9d03b4ee 130 {
5b077ec7 131 ::MessageBox(NULL, str, _T("wxWidgets"), MB_ICONINFORMATION | MB_OK);
9d03b4ee
VZ
132 }
133 else
e12a951e 134#endif // __WINDOWS__/!__WINDOWS__
9d03b4ee 135 {
8237a1c0 136 const wxWX2MBbuf buf = str.mb_str();
5b077ec7
VS
137
138 if ( buf )
139 fprintf(stderr, "%s", (const char*) buf);
140 else // print at least something
141 fprintf(stderr, "%s", (const char*) str.ToAscii());
9d03b4ee 142 }
e12a951e
VZ
143}
144
74698d3a
MB
145// ----------------------------------------------------------------------------
146// wxMessageOutputStderr
147// ----------------------------------------------------------------------------
148
5b077ec7 149void wxMessageOutputStderr::Output(const wxString& str)
74698d3a 150{
8237a1c0 151 const wxWX2MBbuf buf = str.mb_str();
74698d3a 152
5b077ec7
VS
153 if ( buf )
154 fprintf(stderr, "%s", (const char*) buf);
155 else // print at least something
156 fprintf(stderr, "%s", (const char*) str.ToAscii());
74698d3a
MB
157}
158
159// ----------------------------------------------------------------------------
e2478fde 160// wxMessageOutputDebug
74698d3a
MB
161// ----------------------------------------------------------------------------
162
5b077ec7 163void wxMessageOutputDebug::Output(const wxString& str)
74698d3a 164{
5b077ec7 165 wxString out(str);
74698d3a 166
82ef81ed 167#if defined(__WXMSW__) && !defined(__WXMICROWIN__)
311da78a 168 out.Replace(wxT("\t"), wxT(" "));
7e6f48d1 169 out.Replace(wxT("\n"), wxT("\r\n"));
e2478fde 170 ::OutputDebugString(out);
d6e6a35c 171#elif defined(__WXMAC__) && !defined(__DARWIN__)
e2478fde
VZ
172 if ( wxIsDebuggerRunning() )
173 {
174 Str255 pstr;
0ff5799a 175 wxString output = out + wxT(";g") ;
e2478fde
VZ
176 wxMacStringToPascal(output.c_str(), pstr);
177
178 #ifdef __powerc
179 DebugStr(pstr);
180 #else
181 SysBreakStr(pstr);
182 #endif
183 }
7873ca31
SC
184#else
185 wxFputs( out , stderr ) ;
186 if ( out.Right(1) != wxT("\n") )
187 wxFputs( wxT("\n") , stderr ) ;
188 fflush( stderr ) ;
e2478fde 189#endif // platform
74698d3a
MB
190}
191
74698d3a
MB
192// ----------------------------------------------------------------------------
193// wxMessageOutputLog
194// ----------------------------------------------------------------------------
195
5b077ec7 196void wxMessageOutputLog::Output(const wxString& str)
74698d3a 197{
5b077ec7 198 wxString out(str);
74698d3a 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
5b077ec7 213void wxMessageOutputMessageBox::Output(const wxString& str)
e2478fde 214{
5b077ec7 215 wxString out(str);
e2478fde
VZ
216
217 // the native MSW msg box understands the TABs, others don't
218#ifndef __WXMSW__
219 out.Replace(wxT("\t"), wxT(" "));
220#endif
221
222 wxString title;
223 if ( wxTheApp )
224 title.Printf(_("%s message"), wxTheApp->GetAppName().c_str());
225
226 ::wxMessageBox(out, title);
227}
228
229#endif // wxUSE_GUI