// event handlers
void OnOk(wxCommandEvent& event);
void OnDetails(wxCommandEvent& event);
+ void OnListSelect(wxListEvent& event);
private:
// the data for the listctrl
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
style = wxICON_INFORMATION;
}
-#if wxUSE_LOG_DIALOG
- wxLogDialog dlg(wxTheApp->GetTopWindow(),
- m_aMessages, m_aSeverity, m_aTimes,
- title, style);
+ // this is the best we can do here
+ wxWindow *parent = wxTheApp->GetTopWindow();
- // clear the message list before showing the dialog because while it's
- // shown some new messages may appear
- Clear();
+ size_t nMsgCount = m_aMessages.Count();
+
+ wxString str;
+ 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);
- (void)dlg.ShowModal();
+ // clear the message list before showing the dialog because while it's
+ // shown some new messages may appear
+ Clear();
+ (void)dlg.ShowModal();
#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();
+ // concatenate all strings (but not too many to not overfill the msg box)
+ size_t nLines = 0;
- // 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;
+ // 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;
- nLines += (m_aMessages[n - 1].Len() + nMsgLineWidth - 1) / nMsgLineWidth;
+ nLines += (m_aMessages[n - 1].Len() + nMsgLineWidth - 1) / nMsgLineWidth;
- if ( nLines > 25 ) // don't put too many lines in message box
- break;
+ if ( nLines > 25 ) // don't put too many lines in message box
+ break;
- str << m_aMessages[n - 1] << wxT("\n");
+ str << m_aMessages[n - 1] << wxT("\n");
+ }
+#endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
}
- wxMessageBox(str, title, wxOK | style);
+ // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any
+ // situation without it
+ if ( !!str )
+ {
+ wxMessageBox(str, title, wxOK | style, parent);
- // no undisplayed messages whatsoever
- Clear();
-#endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
+ // no undisplayed messages whatsoever
+ Clear();
+ }
// do it here again
m_bHasMessages = FALSE;
}
-// 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 ) {
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
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 )
{
+ 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;
btnOk->SetFocus();
- if ( m_messages.GetCount() == 1 )
+ // 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);
wxDefaultPosition, wxDefaultSize,
wxSUNKEN_BORDER |
wxLC_REPORT |
- wxLC_NO_HEADER );
+ wxLC_NO_HEADER |
+ wxLC_SINGLE_SEL);
m_listctrl->InsertColumn(0, _("Message"));
m_listctrl->InsertColumn(1, _("Time"));