X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a14670e28e06377ece094ab6561cf8022420963f..2e334012b4babcf063fbe79540c4c154cd54ab2b:/src/generic/logg.cpp diff --git a/src/generic/logg.cpp b/src/generic/logg.cpp index 686b7ccc4b..5d4bcc8771 100644 --- a/src/generic/logg.cpp +++ b/src/generic/logg.cpp @@ -38,6 +38,7 @@ #include "wx/sizer.h" #include "wx/statbmp.h" #include "wx/settings.h" + #include "wx/wxcrtvararg.h" #endif // WX_PRECOMP #if wxUSE_LOGGUI || wxUSE_LOGWINDOW @@ -80,7 +81,7 @@ // this function is a wrapper around strftime(3) // allows to exclude the usage of wxDateTime -static wxString TimeStamp(const wxChar *format, time_t t) +static wxString TimeStamp(const wxString& format, time_t t) { #if wxUSE_DATETIME wxChar buf[4096]; @@ -205,13 +206,13 @@ static wxFrame *gs_pFrame = NULL; // FIXME MT-unsafe // accepts an additional argument which tells to which frame the output should // be directed -void wxVLogStatus(wxFrame *pFrame, const wxChar *szFormat, va_list argptr) +void wxVLogStatus(wxFrame *pFrame, const wxString& format, va_list argptr) { wxString msg; wxLog *pLog = wxLog::GetActiveTarget(); if ( pLog != NULL ) { - msg.PrintfV(szFormat, argptr); + msg.PrintfV(format, argptr); wxASSERT( gs_pFrame == NULL ); // should be reset! gs_pFrame = pFrame; @@ -224,13 +225,25 @@ void wxVLogStatus(wxFrame *pFrame, const wxChar *szFormat, va_list argptr) } } -void wxDoLogStatus(wxFrame *pFrame, const wxChar *szFormat, ...) +#if !wxUSE_UTF8_LOCALE_ONLY +void wxDoLogStatusWchar(wxFrame *pFrame, const wxChar *format, ...) { va_list argptr; - va_start(argptr, szFormat); - wxVLogStatus(pFrame, szFormat, argptr); + va_start(argptr, format); + wxVLogStatus(pFrame, format, argptr); va_end(argptr); } +#endif // !wxUSE_UTF8_LOCALE_ONLY + +#if wxUSE_UNICODE_UTF8 +void wxDoLogStatusUtf8(wxFrame *pFrame, const char *format, ...) +{ + va_list argptr; + va_start(argptr, format); + wxVLogStatus(pFrame, format, argptr); + va_end(argptr); +} +#endif // wxUSE_UNICODE_UTF8 // ---------------------------------------------------------------------------- // wxLogGui implementation (FIXME MT-unsafe) @@ -262,15 +275,9 @@ void wxLogGui::Flush() // do it right now to block any new calls to Flush() while we're here m_bHasMessages = false; - unsigned repeatCount = 0; - if ( wxLog::GetRepetitionCounting() ) - { - repeatCount = wxLog::DoLogNumberOfRepeats(); - } + const unsigned repeatCount = LogLastRepeatIfNeeded(); - wxString appName = wxTheApp->GetAppName(); - if ( !appName.empty() ) - appName[0u] = (wxChar)wxToupper(appName[0u]); + wxString appName = wxTheApp->GetAppDisplayName(); long style; wxString titleFormat; @@ -290,7 +297,7 @@ void wxLogGui::Flush() wxString title; title.Printf(titleFormat, appName.c_str()); - size_t nMsgCount = m_aMessages.Count(); + size_t nMsgCount = m_aMessages.GetCount(); // avoid showing other log dialogs until we're done with the dialog we're // showing right now: nested modal dialogs make for really bad UI! @@ -306,7 +313,11 @@ void wxLogGui::Flush() #if wxUSE_LOG_DIALOG if ( repeatCount > 0 ) - m_aMessages[nMsgCount-1] += wxString::Format(wxT(" (%s)"), m_aMessages[nMsgCount-2].c_str()); + { + m_aMessages[nMsgCount - 1] + << " (" << m_aMessages[nMsgCount - 2] << ")"; + } + wxLogDialog dlg(NULL, m_aMessages, m_aSeverity, m_aTimes, title, style); @@ -350,7 +361,7 @@ void wxLogGui::Flush() } // log all kinds of messages -void wxLogGui::DoLog(wxLogLevel level, const wxChar *szString, time_t t) +void wxLogGui::DoLog(wxLogLevel level, const wxString& szString, time_t t) { switch ( level ) { case wxLOG_Info: @@ -394,7 +405,7 @@ void wxLogGui::DoLog(wxLogLevel level, const wxChar *szString, time_t t) // don't prepend debug/trace here: it goes to the // debug window anyhow str += wxT("\r\n"); - OutputDebugString(str); + OutputDebugString(str.wx_str()); #else // send them to stderr wxFprintf(stderr, wxT("[%s] %s\n"), @@ -456,7 +467,7 @@ class wxLogFrame : public wxFrame { public: // ctor & dtor - wxLogFrame(wxWindow *pParent, wxLogWindow *log, const wxChar *szTitle); + wxLogFrame(wxWindow *pParent, wxLogWindow *log, const wxString& szTitle); virtual ~wxLogFrame(); // menu callbacks @@ -500,7 +511,7 @@ BEGIN_EVENT_TABLE(wxLogFrame, wxFrame) EVT_CLOSE(wxLogFrame::OnCloseWindow) END_EVENT_TABLE() -wxLogFrame::wxLogFrame(wxWindow *pParent, wxLogWindow *log, const wxChar *szTitle) +wxLogFrame::wxLogFrame(wxWindow *pParent, wxLogWindow *log, const wxString& szTitle) : wxFrame(pParent, wxID_ANY, szTitle) { m_log = log; @@ -588,7 +599,7 @@ void wxLogFrame::OnSave(wxCommandEvent& WXUNUSED(event)) wxLogError(_("Can't save log contents to file.")); } else { - wxLogStatus(this, _("Log saved to the file '%s'."), filename.c_str()); + wxLogStatus((wxFrame*)this, _("Log saved to the file '%s'."), filename.c_str()); } #endif } @@ -608,7 +619,7 @@ wxLogFrame::~wxLogFrame() // ----------- wxLogWindow::wxLogWindow(wxWindow *pParent, - const wxChar *szTitle, + const wxString& szTitle, bool bShow, bool bDoPass) { @@ -625,7 +636,7 @@ void wxLogWindow::Show(bool bShow) m_pLogFrame->Show(bShow); } -void wxLogWindow::DoLog(wxLogLevel level, const wxChar *szString, time_t t) +void wxLogWindow::DoLog(wxLogLevel level, const wxString& szString, time_t t) { // first let the previous logger show it wxLogPassThrough::DoLog(level, szString, t); @@ -635,11 +646,11 @@ void wxLogWindow::DoLog(wxLogLevel level, const wxChar *szString, time_t t) case wxLOG_Status: // by default, these messages are ignored by wxLog, so process // them ourselves - if ( !wxIsEmpty(szString) ) + if ( !szString.empty() ) { wxString str; str << _("Status: ") << szString; - DoLogString(str, t); + LogString(str, t); } break; @@ -657,7 +668,7 @@ void wxLogWindow::DoLog(wxLogLevel level, const wxChar *szString, time_t t) } } -void wxLogWindow::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) +void wxLogWindow::DoLogString(const wxString& szString, time_t WXUNUSED(t)) { // put the text into our window wxTextCtrl *pText = m_pLogFrame->TextCtrl(); @@ -782,38 +793,17 @@ wxLogDialog::wxLogDialog(wxWindow *parent, wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); wxBoxSizer *sizerAll = new wxBoxSizer(isPda ? wxVERTICAL : wxHORIZONTAL); - wxBitmap bitmap; - switch ( style & wxICON_MASK ) + if (!isPda) { - case wxICON_ERROR: - bitmap = wxArtProvider::GetBitmap(wxART_ERROR, wxART_MESSAGE_BOX); -#ifdef __WXPM__ - bitmap.SetId(wxICON_SMALL_ERROR); -#endif - break; - - case wxICON_INFORMATION: - bitmap = wxArtProvider::GetBitmap(wxART_INFORMATION, wxART_MESSAGE_BOX); -#ifdef __WXPM__ - bitmap.SetId(wxICON_SMALL_INFO); -#endif - break; - - case wxICON_WARNING: - bitmap = wxArtProvider::GetBitmap(wxART_WARNING, wxART_MESSAGE_BOX); -#ifdef __WXPM__ - bitmap.SetId(wxICON_SMALL_WARNING); -#endif - break; - - default: - wxFAIL_MSG(_T("incorrect log style")); + wxStaticBitmap *icon = new wxStaticBitmap + ( + this, + wxID_ANY, + wxArtProvider::GetMessageBoxIcon(style) + ); + sizerAll->Add(icon, 0, wxALIGN_CENTRE_VERTICAL); } - if (!isPda) - sizerAll->Add(new wxStaticBitmap(this, wxID_ANY, bitmap), 0, - wxALIGN_CENTRE_VERTICAL); - // create the text sizer with a minimal size so that we are sure it won't be too small wxString message = EllipsizeString(messages.Last()); wxSizer *szText = CreateTextSizer(message); @@ -1090,7 +1080,7 @@ static int OpenLogFile(wxFile& file, wxString *pFilename, wxWindow *parent) // open file // --------- - bool bOk wxDUMMY_INITIALIZE(false); + bool bOk = false; if ( wxFile::Exists(filename) ) { bool bAppend = false; wxString strMsg; @@ -1145,7 +1135,7 @@ wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl *pTextCtrl) m_pTextCtrl = pTextCtrl; } -void wxLogTextCtrl::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) +void wxLogTextCtrl::DoLogString(const wxString& szString, time_t WXUNUSED(t)) { wxString msg; TimeStamp(&msg);