Compilation fix
[wxWidgets.git] / src / common / msgout.cpp
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$
8 // Copyright: (c) the wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "msgout.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #if defined(__BORLANDC__)
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/string.h"
33 #include "wx/ffile.h"
34 #include "wx/app.h"
35 #if wxUSE_GUI
36 #include "wx/msgdlg.h"
37 #endif // wxUSE_GUI
38 #endif
39
40 #include "wx/msgout.h"
41 #include "wx/log.h"
42
43 #include <stdarg.h>
44 #include <stdio.h>
45
46 // ===========================================================================
47 // implementation
48 // ===========================================================================
49
50 wxMessageOutput* wxMessageOutput::ms_msgOut = 0;
51
52 wxMessageOutput* wxMessageOutput::Get()
53 {
54 if ( !ms_msgOut && wxTheApp )
55 {
56 ms_msgOut = wxTheApp->CreateMessageOutput();
57 }
58
59 return ms_msgOut;
60 }
61
62 wxMessageOutput* wxMessageOutput::Set(wxMessageOutput* msgout)
63 {
64 wxMessageOutput* old = ms_msgOut;
65 ms_msgOut = msgout;
66 return old;
67 }
68
69 // ----------------------------------------------------------------------------
70 // wxMessageOutputStderr
71 // ----------------------------------------------------------------------------
72
73 void wxMessageOutputStderr::Printf(const wxChar* format, ...)
74 {
75 va_list args;
76 va_start(args, format);
77 wxString out;
78
79 out.PrintfV(format, args);
80 va_end(args);
81
82 fprintf(stderr, "%s", (const char*) out.mb_str());
83 }
84
85 // ----------------------------------------------------------------------------
86 // wxMessageOutputMessageBox
87 // ----------------------------------------------------------------------------
88
89 #if wxUSE_GUI
90
91 void wxMessageOutputMessageBox::Printf(const wxChar* format, ...)
92 {
93 va_list args;
94 va_start(args, format);
95 wxString out;
96
97 out.PrintfV(format, args);
98 va_end(args);
99
100 // the native MSW msg box understands the TABs, others don't
101 #ifndef __WXMSW__
102 out.Replace(wxT("\t"), wxT(" "));
103 #endif
104
105 wxString title;
106 if ( wxTheApp )
107 title.Printf(_T("%s message"), wxTheApp->GetAppName().c_str());
108
109 ::wxMessageBox(out, title);
110 }
111
112 #endif // wxUSE_GUI
113
114 // ----------------------------------------------------------------------------
115 // wxMessageOutputLog
116 // ----------------------------------------------------------------------------
117
118 void wxMessageOutputLog::Printf(const wxChar* format, ...)
119 {
120 wxString out;
121
122 va_list args;
123 va_start(args, format);
124
125 out.PrintfV(format, args);
126 va_end(args);
127
128 out.Replace(wxT("\t"), wxT(" "));
129
130 ::wxLogMessage(wxT("%s"), out.c_str());
131 }