| 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 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
| 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/apptrait.h" |
| 43 | #include "wx/log.h" |
| 44 | |
| 45 | #include <stdarg.h> |
| 46 | #include <stdio.h> |
| 47 | |
| 48 | #ifdef __WXMSW__ |
| 49 | #include "wx/msw/private.h" |
| 50 | #endif |
| 51 | #ifdef __WXMAC__ |
| 52 | #include "wx/mac/private.h" |
| 53 | #endif |
| 54 | |
| 55 | // =========================================================================== |
| 56 | // implementation |
| 57 | // =========================================================================== |
| 58 | |
| 59 | #if wxUSE_BASE |
| 60 | |
| 61 | // ---------------------------------------------------------------------------- |
| 62 | // wxMessageOutput |
| 63 | // ---------------------------------------------------------------------------- |
| 64 | |
| 65 | wxMessageOutput* wxMessageOutput::ms_msgOut = 0; |
| 66 | |
| 67 | wxMessageOutput* wxMessageOutput::Get() |
| 68 | { |
| 69 | if ( !ms_msgOut && wxTheApp ) |
| 70 | { |
| 71 | ms_msgOut = wxTheApp->GetTraits()->CreateMessageOutput(); |
| 72 | } |
| 73 | |
| 74 | return ms_msgOut; |
| 75 | } |
| 76 | |
| 77 | wxMessageOutput* wxMessageOutput::Set(wxMessageOutput* msgout) |
| 78 | { |
| 79 | wxMessageOutput* old = ms_msgOut; |
| 80 | ms_msgOut = msgout; |
| 81 | return old; |
| 82 | } |
| 83 | |
| 84 | // ---------------------------------------------------------------------------- |
| 85 | // wxMessageOutputStderr |
| 86 | // ---------------------------------------------------------------------------- |
| 87 | |
| 88 | void wxMessageOutputStderr::Printf(const wxChar* format, ...) |
| 89 | { |
| 90 | va_list args; |
| 91 | va_start(args, format); |
| 92 | wxString out; |
| 93 | |
| 94 | out.PrintfV(format, args); |
| 95 | va_end(args); |
| 96 | |
| 97 | fprintf(stderr, "%s", (const char*) out.mb_str()); |
| 98 | } |
| 99 | |
| 100 | // ---------------------------------------------------------------------------- |
| 101 | // wxMessageOutputDebug |
| 102 | // ---------------------------------------------------------------------------- |
| 103 | |
| 104 | void wxMessageOutputDebug::Printf(const wxChar* format, ...) |
| 105 | { |
| 106 | wxString out; |
| 107 | |
| 108 | va_list args; |
| 109 | va_start(args, format); |
| 110 | |
| 111 | out.PrintfV(format, args); |
| 112 | va_end(args); |
| 113 | |
| 114 | #if defined(__WXMSW__) && !defined(__WXMICROWIN__) |
| 115 | out.Replace(wxT("\t"), wxT(" ")); |
| 116 | out += _T("\r\n"); |
| 117 | ::OutputDebugString(out); |
| 118 | #elif defined(__WXMAC__) && !defined(__DARWIN__) |
| 119 | if ( wxIsDebuggerRunning() ) |
| 120 | { |
| 121 | Str255 pstr; |
| 122 | wxString output = out + wxT(";g") ; |
| 123 | wxMacStringToPascal(output.c_str(), pstr); |
| 124 | |
| 125 | #ifdef __powerc |
| 126 | DebugStr(pstr); |
| 127 | #else |
| 128 | SysBreakStr(pstr); |
| 129 | #endif |
| 130 | } |
| 131 | #else // !MSW, !Mac |
| 132 | // FIXME: why is wxFputs() not defined under Linux? |
| 133 | fputs(out.mb_str(), stderr); |
| 134 | fflush(stderr); |
| 135 | #endif // platform |
| 136 | } |
| 137 | |
| 138 | // ---------------------------------------------------------------------------- |
| 139 | // wxMessageOutputLog |
| 140 | // ---------------------------------------------------------------------------- |
| 141 | |
| 142 | void wxMessageOutputLog::Printf(const wxChar* format, ...) |
| 143 | { |
| 144 | wxString out; |
| 145 | |
| 146 | va_list args; |
| 147 | va_start(args, format); |
| 148 | |
| 149 | out.PrintfV(format, args); |
| 150 | va_end(args); |
| 151 | |
| 152 | out.Replace(wxT("\t"), wxT(" ")); |
| 153 | |
| 154 | ::wxLogMessage(wxT("%s"), out.c_str()); |
| 155 | } |
| 156 | |
| 157 | #endif // wxUSE_BASE |
| 158 | |
| 159 | // ---------------------------------------------------------------------------- |
| 160 | // wxMessageOutputMessageBox |
| 161 | // ---------------------------------------------------------------------------- |
| 162 | |
| 163 | #if wxUSE_GUI |
| 164 | |
| 165 | void wxMessageOutputMessageBox::Printf(const wxChar* format, ...) |
| 166 | { |
| 167 | va_list args; |
| 168 | va_start(args, format); |
| 169 | wxString out; |
| 170 | |
| 171 | out.PrintfV(format, args); |
| 172 | va_end(args); |
| 173 | |
| 174 | // the native MSW msg box understands the TABs, others don't |
| 175 | #ifndef __WXMSW__ |
| 176 | out.Replace(wxT("\t"), wxT(" ")); |
| 177 | #endif |
| 178 | |
| 179 | wxString title; |
| 180 | if ( wxTheApp ) |
| 181 | title.Printf(_("%s message"), wxTheApp->GetAppName().c_str()); |
| 182 | |
| 183 | ::wxMessageBox(out, title); |
| 184 | } |
| 185 | |
| 186 | #endif // wxUSE_GUI |
| 187 | |