+void MyListCtrl::OnEndLabelEdit(wxListEvent& event)
+{
+ wxLogMessage( wxT("OnEndLabelEdit: %s"),
+ event.IsEditCancelled() ? _T("[cancelled]")
+ : event.m_item.m_text.c_str());
+}
+
+void MyListCtrl::OnDeleteItem(wxListEvent& event)
+{
+ LogEvent(event, _T("OnDeleteItem"));
+}
+
+void MyListCtrl::OnDeleteAllItems(wxListEvent& event)
+{
+ LogEvent(event, _T("OnDeleteAllItems"));
+}
+
+#if WXWIN_COMPATIBILITY_2_4
+void MyListCtrl::OnGetInfo(wxListEvent& event)
+{
+ wxString msg;
+
+ msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")");
+ if ( event.m_item.m_mask & wxLIST_MASK_STATE )
+ msg << _T(" wxLIST_MASK_STATE");
+ if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
+ msg << _T(" wxLIST_MASK_TEXT");
+ if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
+ msg << _T(" wxLIST_MASK_IMAGE");
+ if ( event.m_item.m_mask & wxLIST_MASK_DATA )
+ msg << _T(" wxLIST_MASK_DATA");
+ if ( event.m_item.m_mask & wxLIST_SET_ITEM )
+ msg << _T(" wxLIST_SET_ITEM");
+ if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
+ msg << _T(" wxLIST_MASK_WIDTH");
+ if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
+ msg << _T(" wxLIST_MASK_WIDTH");
+
+ if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
+ {
+ event.m_item.m_text = _T("My callback text");
+ }
+
+ wxLogMessage(msg);
+}
+
+void MyListCtrl::OnSetInfo(wxListEvent& event)
+{
+ LogEvent(event, _T("OnSetInfo"));
+}
+#endif
+
+void MyListCtrl::OnSelected(wxListEvent& event)
+{
+ LogEvent(event, _T("OnSelected"));
+
+ if ( GetWindowStyle() & wxLC_REPORT )
+ {
+ wxListItem info;
+ info.m_itemId = event.m_itemIndex;
+ info.m_col = 1;
+ info.m_mask = wxLIST_MASK_TEXT;
+ if ( GetItem(info) )
+ {
+ wxLogMessage(wxT("Value of the 2nd field of the selected item: %s"),
+ info.m_text.c_str());
+ }
+ else
+ {
+ wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
+ }
+ }
+}
+
+void MyListCtrl::OnDeselected(wxListEvent& event)
+{
+ LogEvent(event, _T("OnDeselected"));
+}
+
+void MyListCtrl::OnActivated(wxListEvent& event)
+{
+ LogEvent(event, _T("OnActivated"));
+}
+
+void MyListCtrl::OnFocused(wxListEvent& event)
+{
+ LogEvent(event, _T("OnFocused"));
+
+ event.Skip();
+}
+
+void MyListCtrl::OnListKeyDown(wxListEvent& event)
+{
+ long item;
+
+ switch ( event.GetKeyCode() )
+ {
+ case 'c': // colorize
+ case 'C':
+ {
+ wxListItem info;
+ info.m_itemId = event.GetIndex();
+ GetItem(info);
+
+ wxListItemAttr *attr = info.GetAttributes();
+ if ( !attr || !attr->HasTextColour() )
+ {
+ info.SetTextColour(*wxCYAN);
+
+ SetItem(info);
+
+ RefreshItem(info.m_itemId);
+ }
+ }
+ break;
+
+ case 'n': // next
+ case 'N':
+ item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
+ if ( item++ == GetItemCount() - 1 )
+ {
+ item = 0;
+ }
+
+ wxLogMessage(_T("Focusing item %ld"), item);
+
+ SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
+ EnsureVisible(item);
+ break;
+
+ case 'r': // show bounding Rect
+ case 'R':
+ {
+ item = event.GetIndex();
+ wxRect r;
+ if ( !GetItemRect(item, r) )
+ {
+ wxLogError(_T("Failed to retrieve rect of item %ld"), item);
+ break;
+ }
+
+ wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
+ item, r.x, r.y, r.x + r.width, r.y + r.height);
+ }
+ break;
+
+ case WXK_DELETE:
+ item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ while ( item != -1 )
+ {
+ DeleteItem(item);
+
+ wxLogMessage(_T("Item %ld deleted"), item);
+
+ // -1 because the indices were shifted by DeleteItem()
+ item = GetNextItem(item - 1,
+ wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ }
+ break;
+
+ case WXK_INSERT:
+ if ( GetWindowStyle() & wxLC_REPORT )
+ {
+ if ( GetWindowStyle() & wxLC_VIRTUAL )
+ {
+ SetItemCount(GetItemCount() + 1);
+ }
+ else // !virtual
+ {
+ InsertItemInReportView(event.GetIndex());
+ }
+ }
+ //else: fall through
+
+ default:
+ LogEvent(event, _T("OnListKeyDown"));
+
+ event.Skip();
+ }
+}
+
+void MyListCtrl::OnChar(wxKeyEvent& event)
+{
+ wxLogMessage(_T("Got char event."));
+
+ switch ( event.GetKeyCode() )
+ {
+ case 'n':
+ case 'N':
+ case 'c':
+ case 'C':
+ // these are the keys we process ourselves
+ break;
+
+ default:
+ event.Skip();
+ }
+}
+
+void MyListCtrl::LogEvent(const wxListEvent& event, const wxChar *eventName)
+{
+ wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
+ event.GetIndex(), eventName,
+ event.GetText().c_str(), event.GetData());
+}
+
+wxString MyListCtrl::OnGetItemText(long item, long column) const
+{
+ if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
+ {
+ return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
+ }
+ else
+ {
+ return wxString::Format(_T("Column %ld of item %ld"), column, item);
+ }
+}
+
+int MyListCtrl::OnGetItemImage(long WXUNUSED(item)) const
+{
+ return 0;
+}
+
+wxListItemAttr *MyListCtrl::OnGetItemAttr(long item) const
+{
+ return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
+}
+
+void MyListCtrl::InsertItemInReportView(int i)
+{
+ wxString buf;
+ buf.Printf(_T("This is item %d"), i);
+ long tmp = InsertItem(i, buf, 0);
+ SetItemData(tmp, i);
+
+ buf.Printf(_T("Col 1, item %d"), i);
+ SetItem(i, 1, buf);
+
+ buf.Printf(_T("Item %d in column 2"), i);
+ SetItem(i, 2, buf);
+}