]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/msgout.cpp
invalidate the best size when adding or deleting items
[wxWidgets.git] / src / common / msgout.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/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 wxWidgets team
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
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"
31 #include "wx/intl.h"
32 #include "wx/log.h"
33 #if wxUSE_GUI
34 #include "wx/msgdlg.h"
35 #endif // wxUSE_GUI
36#endif
37
38#include "wx/msgout.h"
39#include "wx/apptrait.h"
40#include <stdarg.h>
41#include <stdio.h>
42
43#if defined(__WINDOWS__)
44 #include "wx/msw/private.h"
45#endif
46#ifdef __WXMAC__
47 #include "wx/mac/private.h"
48#endif
49
50// ===========================================================================
51// implementation
52// ===========================================================================
53
54#if wxUSE_BASE
55
56// ----------------------------------------------------------------------------
57// wxMessageOutput
58// ----------------------------------------------------------------------------
59
60wxMessageOutput* wxMessageOutput::ms_msgOut = 0;
61
62wxMessageOutput* wxMessageOutput::Get()
63{
64 if ( !ms_msgOut && wxTheApp )
65 {
66 ms_msgOut = wxTheApp->GetTraits()->CreateMessageOutput();
67 }
68
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
79void wxMessageOutput::DoPrintf(const wxChar* format, ...)
80{
81 va_list args;
82 va_start(args, format);
83 wxString out;
84
85 out.PrintfV(format, args);
86 va_end(args);
87
88 Output(out);
89}
90
91// ----------------------------------------------------------------------------
92// wxMessageOutputBest
93// ----------------------------------------------------------------------------
94
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
110void wxMessageOutputBest::Output(const wxString& str)
111{
112#ifdef __WINDOWS__
113 if ( !IsInConsole() )
114 {
115 ::MessageBox(NULL, str, _T("wxWidgets"), MB_ICONINFORMATION | MB_OK);
116 }
117 else
118#endif // __WINDOWS__/!__WINDOWS__
119 {
120 const wxWX2MBbuf buf = str.mb_str();
121
122 if ( buf )
123 fprintf(stderr, "%s", (const char*) buf);
124 else // print at least something
125 fprintf(stderr, "%s", (const char*) str.ToAscii());
126 }
127}
128
129// ----------------------------------------------------------------------------
130// wxMessageOutputStderr
131// ----------------------------------------------------------------------------
132
133void wxMessageOutputStderr::Output(const wxString& str)
134{
135 const wxWX2MBbuf buf = str.mb_str();
136
137 if ( buf )
138 fprintf(stderr, "%s", (const char*) buf);
139 else // print at least something
140 fprintf(stderr, "%s", (const char*) str.ToAscii());
141}
142
143// ----------------------------------------------------------------------------
144// wxMessageOutputDebug
145// ----------------------------------------------------------------------------
146
147void wxMessageOutputDebug::Output(const wxString& str)
148{
149 wxString out(str);
150
151#if defined(__WXMSW__) && !defined(__WXMICROWIN__)
152 out.Replace(wxT("\t"), wxT(" "));
153 out.Replace(wxT("\n"), wxT("\r\n"));
154 ::OutputDebugString(out);
155#elif defined(__WXMAC__) && !defined(__DARWIN__)
156 if ( wxIsDebuggerRunning() )
157 {
158 Str255 pstr;
159 wxString output = out + wxT(";g") ;
160 wxMacStringToPascal(output.c_str(), pstr);
161
162 #ifdef __powerc
163 DebugStr(pstr);
164 #else
165 SysBreakStr(pstr);
166 #endif
167 }
168#else
169 wxFputs( out , stderr ) ;
170 if ( out.Right(1) != wxT("\n") )
171 wxFputs( wxT("\n") , stderr ) ;
172 fflush( stderr ) ;
173#endif // platform
174}
175
176// ----------------------------------------------------------------------------
177// wxMessageOutputLog
178// ----------------------------------------------------------------------------
179
180void wxMessageOutputLog::Output(const wxString& str)
181{
182 wxString out(str);
183
184 out.Replace(wxT("\t"), wxT(" "));
185
186 ::wxLogMessage(wxT("%s"), out.c_str());
187}
188
189#endif // wxUSE_BASE
190
191// ----------------------------------------------------------------------------
192// wxMessageOutputMessageBox
193// ----------------------------------------------------------------------------
194
195#if wxUSE_GUI
196
197void wxMessageOutputMessageBox::Output(const wxString& str)
198{
199 wxString out(str);
200
201 // the native MSW msg box understands the TABs, others don't
202#ifndef __WXMSW__
203 out.Replace(wxT("\t"), wxT(" "));
204#endif
205
206 wxString title;
207 if ( wxTheApp )
208 title.Printf(_("%s message"), wxTheApp->GetAppName().c_str());
209
210 ::wxMessageBox(out, title);
211}
212
213#endif // wxUSE_GUI