]>
Commit | Line | Data |
---|---|---|
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 | #include "wx/intl.h" | |
36 | #if wxUSE_GUI | |
37 | #include "wx/msgdlg.h" | |
38 | #endif // wxUSE_GUI | |
39 | #endif | |
40 | ||
41 | #include "wx/msgout.h" | |
42 | #include "wx/log.h" | |
43 | ||
44 | #include <stdarg.h> | |
45 | #include <stdio.h> | |
46 | ||
47 | // =========================================================================== | |
48 | // implementation | |
49 | // =========================================================================== | |
50 | ||
51 | wxMessageOutput* wxMessageOutput::ms_msgOut = 0; | |
52 | ||
53 | wxMessageOutput* wxMessageOutput::Get() | |
54 | { | |
55 | if ( !ms_msgOut && wxTheApp ) | |
56 | { | |
57 | ms_msgOut = wxTheApp->CreateMessageOutput(); | |
58 | } | |
59 | ||
60 | return ms_msgOut; | |
61 | } | |
62 | ||
63 | wxMessageOutput* wxMessageOutput::Set(wxMessageOutput* msgout) | |
64 | { | |
65 | wxMessageOutput* old = ms_msgOut; | |
66 | ms_msgOut = msgout; | |
67 | return old; | |
68 | } | |
69 | ||
70 | // ---------------------------------------------------------------------------- | |
71 | // wxMessageOutputStderr | |
72 | // ---------------------------------------------------------------------------- | |
73 | ||
74 | void wxMessageOutputStderr::Printf(const wxChar* format, ...) | |
75 | { | |
76 | va_list args; | |
77 | va_start(args, format); | |
78 | wxString out; | |
79 | ||
80 | out.PrintfV(format, args); | |
81 | va_end(args); | |
82 | ||
83 | fprintf(stderr, "%s", (const char*) out.mb_str()); | |
84 | } | |
85 | ||
86 | // ---------------------------------------------------------------------------- | |
87 | // wxMessageOutputMessageBox | |
88 | // ---------------------------------------------------------------------------- | |
89 | ||
90 | #if wxUSE_GUI | |
91 | ||
92 | void wxMessageOutputMessageBox::Printf(const wxChar* format, ...) | |
93 | { | |
94 | va_list args; | |
95 | va_start(args, format); | |
96 | wxString out; | |
97 | ||
98 | out.PrintfV(format, args); | |
99 | va_end(args); | |
100 | ||
101 | // the native MSW msg box understands the TABs, others don't | |
102 | #ifndef __WXMSW__ | |
103 | out.Replace(wxT("\t"), wxT(" ")); | |
104 | #endif | |
105 | ||
106 | wxString title; | |
107 | if ( wxTheApp ) | |
108 | title.Printf(_("%s message"), wxTheApp->GetAppName().c_str()); | |
109 | ||
110 | ::wxMessageBox(out, title); | |
111 | } | |
112 | ||
113 | #endif // wxUSE_GUI | |
114 | ||
115 | // ---------------------------------------------------------------------------- | |
116 | // wxMessageOutputLog | |
117 | // ---------------------------------------------------------------------------- | |
118 | ||
119 | void wxMessageOutputLog::Printf(const wxChar* format, ...) | |
120 | { | |
121 | wxString out; | |
122 | ||
123 | va_list args; | |
124 | va_start(args, format); | |
125 | ||
126 | out.PrintfV(format, args); | |
127 | va_end(args); | |
128 | ||
129 | out.Replace(wxT("\t"), wxT(" ")); | |
130 | ||
131 | ::wxLogMessage(wxT("%s"), out.c_str()); | |
132 | } |