]> git.saurik.com Git - wxWidgets.git/blame - src/common/msgout.cpp
Only update the size if the parent is a frame and the frame is
[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
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"
74698d3a
MB
32 #if wxUSE_GUI
33 #include "wx/msgdlg.h"
34 #endif // wxUSE_GUI
35#endif
36
37#include "wx/msgout.h"
7219fc4f 38#include "wx/apptrait.h"
1303a240 39#include "wx/log.h"
f7a75af1 40
74698d3a
MB
41#include <stdarg.h>
42#include <stdio.h>
43
532d575b 44#if defined(__WINDOWS__)
e6b02f3f
VS
45 #include "wx/msw/private.h"
46#endif
0ff5799a
SC
47#ifdef __WXMAC__
48 #include "wx/mac/private.h"
49#endif
e6b02f3f 50
74698d3a
MB
51// ===========================================================================
52// implementation
53// ===========================================================================
54
ec67cff1 55#if wxUSE_BASE
e2478fde
VZ
56
57// ----------------------------------------------------------------------------
58// wxMessageOutput
59// ----------------------------------------------------------------------------
60
74698d3a
MB
61wxMessageOutput* wxMessageOutput::ms_msgOut = 0;
62
63wxMessageOutput* wxMessageOutput::Get()
64{
a69be60b 65 if ( !ms_msgOut && wxTheApp )
e02911a2 66 {
dc6d5e38 67 ms_msgOut = wxTheApp->GetTraits()->CreateMessageOutput();
e02911a2
MB
68 }
69
74698d3a
MB
70 return ms_msgOut;
71}
72
73wxMessageOutput* wxMessageOutput::Set(wxMessageOutput* msgout)
74{
75 wxMessageOutput* old = ms_msgOut;
76 ms_msgOut = msgout;
77 return old;
78}
79
e12a951e
VZ
80// ----------------------------------------------------------------------------
81// wxMessageOutputBest
82// ----------------------------------------------------------------------------
83
858cab30
VZ
84#ifdef __WINDOWS__
85
86// check if we're running in a console under Windows
87static inline bool IsInConsole()
88{
89#ifdef __WXWINCE__
90 return false;
91#else // !__WXWINCE__
92 HANDLE hStdErr = ::GetStdHandle(STD_ERROR_HANDLE);
93 return hStdErr && hStdErr != INVALID_HANDLE_VALUE;
94#endif // __WXWINCE__/!__WXWINCE__
95}
96
97#endif // __WINDOWS__
98
e12a951e
VZ
99void wxMessageOutputBest::Printf(const wxChar* format, ...)
100{
101 va_list args;
102 va_start(args, format);
103 wxString out;
104
105 out.PrintfV(format, args);
106 va_end(args);
107
108#ifdef __WINDOWS__
858cab30 109 if ( !IsInConsole() )
9d03b4ee
VZ
110 {
111 ::MessageBox(NULL, out, _T("wxWidgets"), MB_ICONINFORMATION | MB_OK);
112 }
113 else
e12a951e 114#endif // __WINDOWS__/!__WINDOWS__
9d03b4ee
VZ
115 {
116 fprintf(stderr, "%s", (const char*) out.mb_str());
117 }
e12a951e
VZ
118}
119
74698d3a
MB
120// ----------------------------------------------------------------------------
121// wxMessageOutputStderr
122// ----------------------------------------------------------------------------
123
124void wxMessageOutputStderr::Printf(const wxChar* format, ...)
125{
126 va_list args;
127 va_start(args, format);
128 wxString out;
129
130 out.PrintfV(format, args);
131 va_end(args);
132
401eb3de 133 fprintf(stderr, "%s", (const char*) out.mb_str());
74698d3a
MB
134}
135
136// ----------------------------------------------------------------------------
e2478fde 137// wxMessageOutputDebug
74698d3a
MB
138// ----------------------------------------------------------------------------
139
e2478fde 140void wxMessageOutputDebug::Printf(const wxChar* format, ...)
74698d3a 141{
e2478fde
VZ
142 wxString out;
143
74698d3a
MB
144 va_list args;
145 va_start(args, format);
74698d3a
MB
146
147 out.PrintfV(format, args);
148 va_end(args);
149
82ef81ed 150#if defined(__WXMSW__) && !defined(__WXMICROWIN__)
311da78a 151 out.Replace(wxT("\t"), wxT(" "));
7e6f48d1 152 out.Replace(wxT("\n"), wxT("\r\n"));
e2478fde 153 ::OutputDebugString(out);
d6e6a35c 154#elif defined(__WXMAC__) && !defined(__DARWIN__)
e2478fde
VZ
155 if ( wxIsDebuggerRunning() )
156 {
157 Str255 pstr;
0ff5799a 158 wxString output = out + wxT(";g") ;
e2478fde
VZ
159 wxMacStringToPascal(output.c_str(), pstr);
160
161 #ifdef __powerc
162 DebugStr(pstr);
163 #else
164 SysBreakStr(pstr);
165 #endif
166 }
7873ca31
SC
167#else
168 wxFputs( out , stderr ) ;
169 if ( out.Right(1) != wxT("\n") )
170 wxFputs( wxT("\n") , stderr ) ;
171 fflush( stderr ) ;
e2478fde 172#endif // platform
74698d3a
MB
173}
174
74698d3a
MB
175// ----------------------------------------------------------------------------
176// wxMessageOutputLog
177// ----------------------------------------------------------------------------
178
74698d3a
MB
179void wxMessageOutputLog::Printf(const wxChar* format, ...)
180{
a69be60b
VZ
181 wxString out;
182
74698d3a
MB
183 va_list args;
184 va_start(args, format);
74698d3a
MB
185
186 out.PrintfV(format, args);
187 va_end(args);
188
311da78a 189 out.Replace(wxT("\t"), wxT(" "));
a69be60b 190
8887e234 191 ::wxLogMessage(wxT("%s"), out.c_str());
74698d3a 192}
e2478fde 193
ec67cff1 194#endif // wxUSE_BASE
e2478fde
VZ
195
196// ----------------------------------------------------------------------------
197// wxMessageOutputMessageBox
198// ----------------------------------------------------------------------------
199
200#if wxUSE_GUI
201
202void wxMessageOutputMessageBox::Printf(const wxChar* format, ...)
203{
204 va_list args;
205 va_start(args, format);
206 wxString out;
207
208 out.PrintfV(format, args);
209 va_end(args);
210
211 // the native MSW msg box understands the TABs, others don't
212#ifndef __WXMSW__
213 out.Replace(wxT("\t"), wxT(" "));
214#endif
215
216 wxString title;
217 if ( wxTheApp )
218 title.Printf(_("%s message"), wxTheApp->GetAppName().c_str());
219
220 ::wxMessageBox(out, title);
221}
222
223#endif // wxUSE_GUI
224