moved vararg handling code in wxMessageOutput to single method and added simple Output(wxString) virtual method instead of DoPrintf(format,...)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45432 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík 2007-04-12 21:13:05 +00:00
parent 7e173fdcef
commit 5b077ec744
2 changed files with 39 additions and 47 deletions

View File

@ -40,7 +40,8 @@ public:
WX_DEFINE_VARARG_FUNC_VOID(Printf, DoPrintf) WX_DEFINE_VARARG_FUNC_VOID(Printf, DoPrintf)
protected: protected:
virtual void DoPrintf(const wxChar* format, ...) ATTRIBUTE_PRINTF_2 = 0; void DoPrintf(const wxChar* format, ...) ATTRIBUTE_PRINTF_2;
virtual void Output(const wxString& str) = 0;
}; };
#ifdef __VISUALC__ #ifdef __VISUALC__
@ -81,7 +82,7 @@ public:
wxMessageOutputBest() { } wxMessageOutputBest() { }
protected: protected:
virtual void DoPrintf(const wxChar* format, ...) ATTRIBUTE_PRINTF_2; virtual void Output(const wxString& str);
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -94,7 +95,7 @@ public:
wxMessageOutputStderr() { } wxMessageOutputStderr() { }
protected: protected:
virtual void DoPrintf(const wxChar* format, ...) ATTRIBUTE_PRINTF_2; virtual void Output(const wxString& str);
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -109,7 +110,7 @@ public:
wxMessageOutputMessageBox() { } wxMessageOutputMessageBox() { }
protected: protected:
virtual void DoPrintf(const wxChar* format, ...) ATTRIBUTE_PRINTF_2; virtual void Output(const wxString& str);
}; };
#endif // wxUSE_GUI #endif // wxUSE_GUI
@ -124,7 +125,7 @@ public:
wxMessageOutputDebug() { } wxMessageOutputDebug() { }
protected: protected:
virtual void DoPrintf(const wxChar* format, ...) ATTRIBUTE_PRINTF_2; virtual void Output(const wxString& str);
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -137,7 +138,7 @@ public:
wxMessageOutputLog() { } wxMessageOutputLog() { }
protected: protected:
virtual void DoPrintf(const wxChar* format, ...) ATTRIBUTE_PRINTF_2; virtual void Output(const wxString& str);
}; };
#endif #endif

View File

@ -76,6 +76,18 @@ wxMessageOutput* wxMessageOutput::Set(wxMessageOutput* msgout)
return old; return old;
} }
void wxMessageOutputBase::DoPrintf(const wxChar* format, ...)
{
va_list args;
va_start(args, format);
wxString out;
out.PrintfV(format, args);
va_end(args);
Output(out);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxMessageOutputBest // wxMessageOutputBest
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -95,24 +107,22 @@ static inline bool IsInConsole()
#endif // __WINDOWS__ #endif // __WINDOWS__
void wxMessageOutputBest::DoPrintf(const wxChar* format, ...) void wxMessageOutputBest::Output(const wxString& str)
{ {
va_list args;
va_start(args, format);
wxString out;
out.PrintfV(format, args);
va_end(args);
#ifdef __WINDOWS__ #ifdef __WINDOWS__
if ( !IsInConsole() ) if ( !IsInConsole() )
{ {
::MessageBox(NULL, out, _T("wxWidgets"), MB_ICONINFORMATION | MB_OK); ::MessageBox(NULL, str, _T("wxWidgets"), MB_ICONINFORMATION | MB_OK);
} }
else else
#endif // __WINDOWS__/!__WINDOWS__ #endif // __WINDOWS__/!__WINDOWS__
{ {
fprintf(stderr, "%s", (const char*) out.mb_str()); const wxWX2MBbuf buf(str.mb_str());
if ( buf )
fprintf(stderr, "%s", (const char*) buf);
else // print at least something
fprintf(stderr, "%s", (const char*) str.ToAscii());
} }
} }
@ -120,31 +130,23 @@ void wxMessageOutputBest::DoPrintf(const wxChar* format, ...)
// wxMessageOutputStderr // wxMessageOutputStderr
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxMessageOutputStderr::DoPrintf(const wxChar* format, ...) void wxMessageOutputStderr::Output(const wxString& str)
{ {
va_list args; const wxWX2MBbuf buf(str.mb_str());
va_start(args, format);
wxString out;
out.PrintfV(format, args); if ( buf )
va_end(args); fprintf(stderr, "%s", (const char*) buf);
else // print at least something
fprintf(stderr, "%s", (const char*) out.mb_str()); fprintf(stderr, "%s", (const char*) str.ToAscii());
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxMessageOutputDebug // wxMessageOutputDebug
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxMessageOutputDebug::DoPrintf(const wxChar* format, ...) void wxMessageOutputDebug::Output(const wxString& str)
{ {
wxString out; wxString out(str);
va_list args;
va_start(args, format);
out.PrintfV(format, args);
va_end(args);
#if defined(__WXMSW__) && !defined(__WXMICROWIN__) #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
out.Replace(wxT("\t"), wxT(" ")); out.Replace(wxT("\t"), wxT(" "));
@ -175,15 +177,9 @@ void wxMessageOutputDebug::DoPrintf(const wxChar* format, ...)
// wxMessageOutputLog // wxMessageOutputLog
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxMessageOutputLog::DoPrintf(const wxChar* format, ...) void wxMessageOutputLog::Output(const wxString& str)
{ {
wxString out; wxString out(str);
va_list args;
va_start(args, format);
out.PrintfV(format, args);
va_end(args);
out.Replace(wxT("\t"), wxT(" ")); out.Replace(wxT("\t"), wxT(" "));
@ -198,14 +194,9 @@ void wxMessageOutputLog::DoPrintf(const wxChar* format, ...)
#if wxUSE_GUI #if wxUSE_GUI
void wxMessageOutputMessageBox::DoPrintf(const wxChar* format, ...) void wxMessageOutputMessageBox::Output(const wxString& str)
{ {
va_list args; wxString out(str);
va_start(args, format);
wxString out;
out.PrintfV(format, args);
va_end(args);
// the native MSW msg box understands the TABs, others don't // the native MSW msg box understands the TABs, others don't
#ifndef __WXMSW__ #ifndef __WXMSW__