X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f1df09276caf8575eed4e9bf2689c69903a749a9..c6e7d14fa96da41236095a18ee8c1e3ad13d3dd0:/src/generic/logg.cpp diff --git a/src/generic/logg.cpp b/src/generic/logg.cpp index e158cec030..c041955c5e 100644 --- a/src/generic/logg.cpp +++ b/src/generic/logg.cpp @@ -38,6 +38,7 @@ #include "wx/menu.h" #include "wx/frame.h" #include "wx/filedlg.h" + #include "wx/msgdlg.h" #include "wx/textctrl.h" #include "wx/sizer.h" #include "wx/statbmp.h" @@ -83,12 +84,13 @@ public: // event handlers void OnOk(wxCommandEvent& event); void OnDetails(wxCommandEvent& event); + void OnListSelect(wxListEvent& event); private: // the data for the listctrl - const wxArrayString& m_messages; - const wxArrayInt& m_severity; - const wxArrayLong& m_times; + wxArrayString m_messages; + wxArrayInt m_severity; + wxArrayLong m_times; // the "toggle" button and its state wxButton *m_btnDetails; @@ -97,12 +99,16 @@ private: // the listctrl (not shown initially) wxListCtrl *m_listctrl; + // the translated "Details" string + static wxString ms_details; + DECLARE_EVENT_TABLE() }; BEGIN_EVENT_TABLE(wxLogDialog, wxDialog) EVT_BUTTON(wxID_OK, wxLogDialog::OnOk) EVT_BUTTON(wxID_MORE, wxLogDialog::OnDetails) + EVT_LIST_ITEM_SELECTED(-1, wxLogDialog::OnListSelect) END_EVENT_TABLE() #endif // wxUSE_LOG_DIALOG @@ -167,12 +173,22 @@ void wxLogTextCtrl::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) wxLogGui::wxLogGui() { + // we must translate them here in the very beginning or we risk to have + // reentrancy problems when called from inside wxGetTranslation() leading + // to inifnite recursion + m_error = _("Error"); + m_warning = _("Warning"); + m_info = _("Information"); + Clear(); } void wxLogGui::Clear() { - m_bErrors = m_bWarnings = FALSE; + m_bErrors = + m_bWarnings = + m_bHasMessages = FALSE; + m_aMessages.Empty(); m_aSeverity.Empty(); m_aTimes.Empty(); @@ -195,55 +211,71 @@ void wxLogGui::Flush() long style; if ( m_bErrors ) { - title += _("Error"); + title += m_error; style = wxICON_STOP; } else if ( m_bWarnings ) { - title += _("Warning"); + title += m_warning; style = wxICON_EXCLAMATION; } else { - title += _("Information"); + title += m_info; style = wxICON_INFORMATION; } -#if wxUSE_LOG_DIALOG - wxLogDialog dlg(wxTheApp->GetTopWindow(), - m_aMessages, m_aSeverity, m_aTimes, - title, style); - (void)dlg.ShowModal(); + // this is the best we can do here + wxWindow *parent = wxTheApp->GetTopWindow(); + + size_t nMsgCount = m_aMessages.Count(); -#else // !wxUSE_LOG_DIALOG - // concatenate all strings (but not too many to not overfill the msg box) wxString str; - size_t nLines = 0, - nMsgCount = m_aMessages.Count(); + if ( nMsgCount == 1 ) + { + str = m_aMessages[0]; + } + else // more than one message + { +#if wxUSE_LOG_DIALOG + wxLogDialog dlg(parent, + m_aMessages, m_aSeverity, m_aTimes, + title, style); - // start from the most recent message - for ( size_t n = nMsgCount; n > 0; n-- ) { - // for Windows strings longer than this value are wrapped (NT 4.0) - const size_t nMsgLineWidth = 156; + // clear the message list before showing the dialog because while it's + // shown some new messages may appear + Clear(); - nLines += (m_aMessages[n - 1].Len() + nMsgLineWidth - 1) / nMsgLineWidth; + (void)dlg.ShowModal(); +#else // !wxUSE_LOG_DIALOG + // concatenate all strings (but not too many to not overfill the msg box) + size_t nLines = 0; - if ( nLines > 25 ) // don't put too many lines in message box - break; + // start from the most recent message + for ( size_t n = nMsgCount; n > 0; n-- ) { + // for Windows strings longer than this value are wrapped (NT 4.0) + const size_t nMsgLineWidth = 156; - str << m_aMessages[n - 1] << wxT("\n"); - } + nLines += (m_aMessages[n - 1].Len() + nMsgLineWidth - 1) / nMsgLineWidth; - wxMessageBox(str, title, wxOK | style); + if ( nLines > 25 ) // don't put too many lines in message box + break; + + str << m_aMessages[n - 1] << wxT("\n"); + } #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG + } - // no undisplayed messages whatsoever - Clear(); + // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any + // situation without it + if ( !!str ) + { + wxMessageBox(str, title, wxOK | style, parent); - // do it here again - m_bHasMessages = FALSE; + // no undisplayed messages whatsoever + Clear(); + } } -// the default behaviour is to discard all informational messages if there -// are any errors/warnings. +// log all kinds of messages void wxLogGui::DoLog(wxLogLevel level, const wxChar *szString, time_t t) { switch ( level ) { @@ -305,6 +337,7 @@ void wxLogGui::DoLog(wxLogLevel level, const wxChar *szString, time_t t) case wxLOG_FatalError: // show this one immediately wxMessageBox(szString, _("Fatal error"), wxICON_HAND); + wxExit(); break; case wxLOG_Error: @@ -328,7 +361,7 @@ void wxLogGui::DoLog(wxLogLevel level, const wxChar *szString, time_t t) } m_aMessages.Add(szString); - m_aSeverity.Add(level); + m_aSeverity.Add((int)level); m_aTimes.Add((long)t); m_bHasMessages = TRUE; break; @@ -362,11 +395,12 @@ public: wxTextCtrl *TextCtrl() const { return m_pTextCtrl; } private: + // use standard ids for our commands! enum { - Menu_Close = 100, - Menu_Save, - Menu_Clear + Menu_Close = wxID_CLOSE, + Menu_Save = wxID_SAVE, + Menu_Clear = wxID_CLEAR }; // instead of closing just hide the window to be able to Show() it later @@ -629,15 +663,42 @@ wxLogWindow::~wxLogWindow() static const size_t MARGIN = 10; +wxString wxLogDialog::ms_details; + wxLogDialog::wxLogDialog(wxWindow *parent, const wxArrayString& messages, const wxArrayInt& severity, const wxArrayLong& times, const wxString& caption, long style) - : wxDialog(parent, -1, caption), - m_messages(messages), m_severity(severity), m_times(times) + : wxDialog(parent, -1, caption ) { + if ( ms_details ) + { + // ensure that we won't try to call wxGetTranslation() twice + ms_details = _T("&Details"); + ms_details = wxGetTranslation(ms_details); + } + + size_t count = messages.GetCount(); + m_messages.Alloc(count); + m_severity.Alloc(count); + m_times.Alloc(count); + + for ( size_t n = 0; n < count; n++ ) + { + wxString msg = messages[n]; + do + { + m_messages.Add(msg.BeforeFirst(_T('\n'))); + msg = msg.AfterFirst(_T('\n')); + + m_severity.Add(severity[n]); + m_times.Add(times[n]); + } + while ( !!msg ); + } + m_showingDetails = FALSE; // not initially m_listctrl = (wxListCtrl *)NULL; @@ -648,12 +709,12 @@ wxLogDialog::wxLogDialog(wxWindow *parent, wxBoxSizer *sizerButtons = new wxBoxSizer(wxVERTICAL); wxBoxSizer *sizerAll = new wxBoxSizer(wxHORIZONTAL); - wxButton *btnOk = new wxButton(this, wxID_OK, _T("Ok")); - m_btnDetails = new wxButton(this, wxID_MORE, _T("&Details >>")); + wxButton *btnOk = new wxButton(this, wxID_OK, _("OK")); sizerButtons->Add(btnOk, 0, wxCENTRE|wxBOTTOM, MARGIN/2); + m_btnDetails = new wxButton(this, wxID_MORE, ms_details + _T(" >>")); sizerButtons->Add(m_btnDetails, 0, wxCENTRE|wxTOP, MARGIN/2 - 1); - wxIcon icon = wxTheApp->GetStdIcon(style & wxICON_MASK); + wxIcon icon = wxTheApp->GetStdIcon((int)(style & wxICON_MASK)); sizerAll->Add(new wxStaticBitmap(this, -1, icon), 0, wxCENTRE); const wxString& message = messages.Last(); sizerAll->Add(CreateTextSizer(message), 0, wxCENTRE|wxLEFT|wxRIGHT, MARGIN); @@ -669,9 +730,27 @@ wxLogDialog::wxLogDialog(wxWindow *parent, btnOk->SetFocus(); + // this can't happen any more as we don't use this dialog in this case +#if 0 + if ( count == 1 ) + { + // no details... it's easier to disable a button than to change the + // dialog layout depending on whether we have details or not + m_btnDetails->Disable(); + } +#endif // 0 + Centre(); } +void wxLogDialog::OnListSelect(wxListEvent& event) +{ + // we can't just disable the control because this looks ugly under Windows + // (wrong bg colour, no scrolling...), but we still want to disable + // selecting items - it makes no sense here + m_listctrl->SetItemState(event.GetIndex(), 0, wxLIST_STATE_SELECTED); +} + void wxLogDialog::OnOk(wxCommandEvent& WXUNUSED(event)) { EndModal(wxID_OK); @@ -683,22 +762,27 @@ void wxLogDialog::OnDetails(wxCommandEvent& WXUNUSED(event)) if ( m_showingDetails ) { - m_btnDetails->SetLabel(_T("&Details >>")); + m_btnDetails->SetLabel(ms_details + _T(">>")); sizer->Remove(m_listctrl); } else // show details now { - m_btnDetails->SetLabel(_T("<< &Details")); + m_btnDetails->SetLabel(wxString(_T("<< ")) + ms_details); if ( !m_listctrl ) { // create it now m_listctrl = new wxListCtrl(this, -1, wxDefaultPosition, wxDefaultSize, - wxLC_REPORT | wxLC_NO_HEADER); - m_listctrl->InsertColumn(0, _("Message")); - m_listctrl->InsertColumn(1, _("Time")); + wxSUNKEN_BORDER | + wxLC_REPORT | + wxLC_NO_HEADER | + wxLC_SINGLE_SEL); + // no need to translate these strings as they're not shown to the + // user anyhow (we use wxLC_NO_HEADER style) + m_listctrl->InsertColumn(0, _T("Message")); + m_listctrl->InsertColumn(1, _T("Time")); // prepare the imagelist static const int ICON_SIZE = 16; @@ -753,7 +837,7 @@ void wxLogDialog::OnDetails(wxCommandEvent& WXUNUSED(event)) wxDateTime((time_t)m_times[n]).Format(fmt)); } - // let the columns size themselves (TODO does this work under GTK?) + // let the columns size themselves m_listctrl->SetColumnWidth(0, wxLIST_AUTOSIZE); m_listctrl->SetColumnWidth(1, wxLIST_AUTOSIZE); @@ -774,6 +858,7 @@ void wxLogDialog::OnDetails(wxCommandEvent& WXUNUSED(event)) m_showingDetails = !m_showingDetails; // in any case, our size changed - update + sizer->SetSizeHints(this); sizer->Fit(this); }