lost log.h fixed
[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 #ifndef __WXMSW__
101 out.Replace(wxT("\t"),wxT(" "));
102 #endif
103 ::wxMessageBox(out);
104 }
105
106 #endif // wxUSE_GUI
107
108 // ----------------------------------------------------------------------------
109 // wxMessageOutputLog
110 // ----------------------------------------------------------------------------
111
112 void wxMessageOutputLog::Printf(const wxChar* format, ...)
113 {
114 wxString out;
115
116 va_list args;
117 va_start(args, format);
118
119 out.PrintfV(format, args);
120 va_end(args);
121
122 out.Replace(wxT("\t"),wxT(" "));
123
124 ::wxLogMessage(wxT("%s"), out.c_str());
125 }