]> git.saurik.com Git - wxWidgets.git/blame - src/common/msgout.cpp
implement GetBestSize() (patch 1386199)
[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
e12a951e
VZ
79// ----------------------------------------------------------------------------
80// wxMessageOutputBest
81// ----------------------------------------------------------------------------
82
858cab30
VZ
83#ifdef __WINDOWS__
84
85// check if we're running in a console under Windows
86static inline bool IsInConsole()
87{
88#ifdef __WXWINCE__
89 return false;
90#else // !__WXWINCE__
91 HANDLE hStdErr = ::GetStdHandle(STD_ERROR_HANDLE);
92 return hStdErr && hStdErr != INVALID_HANDLE_VALUE;
93#endif // __WXWINCE__/!__WXWINCE__
94}
95
96#endif // __WINDOWS__
97
c9f78968 98void wxMessageOutputBest::DoPrintf(const wxChar* format, ...)
e12a951e
VZ
99{
100 va_list args;
101 va_start(args, format);
102 wxString out;
103
104 out.PrintfV(format, args);
105 va_end(args);
106
107#ifdef __WINDOWS__
858cab30 108 if ( !IsInConsole() )
9d03b4ee
VZ
109 {
110 ::MessageBox(NULL, out, _T("wxWidgets"), MB_ICONINFORMATION | MB_OK);
111 }
112 else
e12a951e 113#endif // __WINDOWS__/!__WINDOWS__
9d03b4ee
VZ
114 {
115 fprintf(stderr, "%s", (const char*) out.mb_str());
116 }
e12a951e
VZ
117}
118
74698d3a
MB
119// ----------------------------------------------------------------------------
120// wxMessageOutputStderr
121// ----------------------------------------------------------------------------
122
c9f78968 123void wxMessageOutputStderr::DoPrintf(const wxChar* format, ...)
74698d3a
MB
124{
125 va_list args;
126 va_start(args, format);
127 wxString out;
128
129 out.PrintfV(format, args);
130 va_end(args);
131
401eb3de 132 fprintf(stderr, "%s", (const char*) out.mb_str());
74698d3a
MB
133}
134
135// ----------------------------------------------------------------------------
e2478fde 136// wxMessageOutputDebug
74698d3a
MB
137// ----------------------------------------------------------------------------
138
c9f78968 139void wxMessageOutputDebug::DoPrintf(const wxChar* format, ...)
74698d3a 140{
e2478fde
VZ
141 wxString out;
142
74698d3a
MB
143 va_list args;
144 va_start(args, format);
74698d3a
MB
145
146 out.PrintfV(format, args);
147 va_end(args);
148
82ef81ed 149#if defined(__WXMSW__) && !defined(__WXMICROWIN__)
311da78a 150 out.Replace(wxT("\t"), wxT(" "));
7e6f48d1 151 out.Replace(wxT("\n"), wxT("\r\n"));
e2478fde 152 ::OutputDebugString(out);
d6e6a35c 153#elif defined(__WXMAC__) && !defined(__DARWIN__)
e2478fde
VZ
154 if ( wxIsDebuggerRunning() )
155 {
156 Str255 pstr;
0ff5799a 157 wxString output = out + wxT(";g") ;
e2478fde
VZ
158 wxMacStringToPascal(output.c_str(), pstr);
159
160 #ifdef __powerc
161 DebugStr(pstr);
162 #else
163 SysBreakStr(pstr);
164 #endif
165 }
7873ca31
SC
166#else
167 wxFputs( out , stderr ) ;
168 if ( out.Right(1) != wxT("\n") )
169 wxFputs( wxT("\n") , stderr ) ;
170 fflush( stderr ) ;
e2478fde 171#endif // platform
74698d3a
MB
172}
173
74698d3a
MB
174// ----------------------------------------------------------------------------
175// wxMessageOutputLog
176// ----------------------------------------------------------------------------
177
c9f78968 178void wxMessageOutputLog::DoPrintf(const wxChar* format, ...)
74698d3a 179{
a69be60b
VZ
180 wxString out;
181
74698d3a
MB
182 va_list args;
183 va_start(args, format);
74698d3a
MB
184
185 out.PrintfV(format, args);
186 va_end(args);
187
311da78a 188 out.Replace(wxT("\t"), wxT(" "));
a69be60b 189
8887e234 190 ::wxLogMessage(wxT("%s"), out.c_str());
74698d3a 191}
e2478fde 192
ec67cff1 193#endif // wxUSE_BASE
e2478fde
VZ
194
195// ----------------------------------------------------------------------------
196// wxMessageOutputMessageBox
197// ----------------------------------------------------------------------------
198
199#if wxUSE_GUI
200
c9f78968 201void wxMessageOutputMessageBox::DoPrintf(const wxChar* format, ...)
e2478fde
VZ
202{
203 va_list args;
204 va_start(args, format);
205 wxString out;
206
207 out.PrintfV(format, args);
208 va_end(args);
209
210 // the native MSW msg box understands the TABs, others don't
211#ifndef __WXMSW__
212 out.Replace(wxT("\t"), wxT(" "));
213#endif
214
215 wxString title;
216 if ( wxTheApp )
217 title.Printf(_("%s message"), wxTheApp->GetAppName().c_str());
218
219 ::wxMessageBox(out, title);
220}
221
222#endif // wxUSE_GUI