]>
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" | |
41 | ||
42 | #include <stdarg.h> | |
43 | #include <stdio.h> | |
44 | ||
45 | // =========================================================================== | |
46 | // implementation | |
47 | // =========================================================================== | |
48 | ||
49 | wxMessageOutput* wxMessageOutput::ms_msgOut = 0; | |
50 | ||
51 | wxMessageOutput* wxMessageOutput::Get() | |
52 | { | |
e02911a2 MB |
53 | // FIXME this is an hack |
54 | static bool inGet = FALSE; | |
55 | ||
56 | if(!ms_msgOut && wxTheApp && !inGet) | |
57 | { | |
58 | inGet = TRUE; | |
59 | wxTheApp->DoInit(); | |
60 | } | |
61 | ||
62 | inGet = FALSE; | |
74698d3a MB |
63 | return ms_msgOut; |
64 | } | |
65 | ||
66 | wxMessageOutput* wxMessageOutput::Set(wxMessageOutput* msgout) | |
67 | { | |
68 | wxMessageOutput* old = ms_msgOut; | |
69 | ms_msgOut = msgout; | |
70 | return old; | |
71 | } | |
72 | ||
73 | // ---------------------------------------------------------------------------- | |
74 | // wxMessageOutputStderr | |
75 | // ---------------------------------------------------------------------------- | |
76 | ||
77 | void wxMessageOutputStderr::Printf(const wxChar* format, ...) | |
78 | { | |
79 | va_list args; | |
80 | va_start(args, format); | |
81 | wxString out; | |
82 | ||
83 | out.PrintfV(format, args); | |
84 | va_end(args); | |
85 | ||
401eb3de | 86 | fprintf(stderr, "%s", (const char*) out.mb_str()); |
74698d3a MB |
87 | } |
88 | ||
89 | // ---------------------------------------------------------------------------- | |
90 | // wxMessageOutputMessageBox | |
91 | // ---------------------------------------------------------------------------- | |
92 | ||
93 | #if wxUSE_GUI | |
94 | ||
95 | void wxMessageOutputMessageBox::Printf(const wxChar* format, ...) | |
96 | { | |
97 | va_list args; | |
98 | va_start(args, format); | |
99 | wxString out; | |
100 | ||
101 | out.PrintfV(format, args); | |
102 | va_end(args); | |
103 | ||
104 | #ifndef __WXMSW__ | |
401eb3de | 105 | out.Replace(wxT("\t"),wxT(" ")); |
74698d3a MB |
106 | #endif |
107 | ::wxMessageBox(out); | |
108 | } | |
109 | ||
110 | #endif // wxUSE_GUI | |
111 | ||
112 | // ---------------------------------------------------------------------------- | |
113 | // wxMessageOutputLog | |
114 | // ---------------------------------------------------------------------------- | |
115 | ||
74698d3a MB |
116 | void wxMessageOutputLog::Printf(const wxChar* format, ...) |
117 | { | |
118 | va_list args; | |
119 | va_start(args, format); | |
120 | wxString out; | |
121 | ||
122 | out.PrintfV(format, args); | |
123 | va_end(args); | |
124 | ||
8887e234 | 125 | out.Replace(wxT("\t"),wxT(" ")); |
74698d3a MB |
126 | // under Motif, wxMessageDialog needs a parent window, so we use |
127 | // wxLog, which is better than nothing | |
8887e234 | 128 | ::wxLogMessage(wxT("%s"), out.c_str()); |
74698d3a | 129 | } |