]>
Commit | Line | Data |
---|---|---|
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$ | |
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" | |
1303a240 | 41 | #include "wx/log.h" |
f7a75af1 | 42 | |
74698d3a MB |
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 | { | |
a69be60b | 54 | if ( !ms_msgOut && wxTheApp ) |
e02911a2 | 55 | { |
a69be60b | 56 | ms_msgOut = wxTheApp->CreateMessageOutput(); |
e02911a2 MB |
57 | } |
58 | ||
74698d3a MB |
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 | ||
401eb3de | 82 | fprintf(stderr, "%s", (const char*) out.mb_str()); |
74698d3a MB |
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 | ||
311da78a | 100 | // the native MSW msg box understands the TABs, others don't |
74698d3a | 101 | #ifndef __WXMSW__ |
311da78a | 102 | out.Replace(wxT("\t"), wxT(" ")); |
74698d3a | 103 | #endif |
311da78a VZ |
104 | |
105 | wxString title; | |
106 | if ( wxTheApp ) | |
107 | title.Printf(_("%s message"), wxTheApp->GetAppName().c_str()); | |
108 | ||
109 | ::wxMessageBox(out, title); | |
74698d3a MB |
110 | } |
111 | ||
112 | #endif // wxUSE_GUI | |
113 | ||
114 | // ---------------------------------------------------------------------------- | |
115 | // wxMessageOutputLog | |
116 | // ---------------------------------------------------------------------------- | |
117 | ||
74698d3a MB |
118 | void wxMessageOutputLog::Printf(const wxChar* format, ...) |
119 | { | |
a69be60b VZ |
120 | wxString out; |
121 | ||
74698d3a MB |
122 | va_list args; |
123 | va_start(args, format); | |
74698d3a MB |
124 | |
125 | out.PrintfV(format, args); | |
126 | va_end(args); | |
127 | ||
311da78a | 128 | out.Replace(wxT("\t"), wxT(" ")); |
a69be60b | 129 | |
8887e234 | 130 | ::wxLogMessage(wxT("%s"), out.c_str()); |
74698d3a | 131 | } |