+ 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::OnRightClick(wxMouseEvent& event)
+{
+ if ( !event.ControlDown() )
+ {
+ event.Skip();
+ return;
+ }
+
+ int flags;
+ long subitem;
+ long item = HitTest(event.GetPosition(), flags, &subitem);
+
+ wxString where;
+ switch ( flags )
+ {
+ case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
+ case wxLIST_HITTEST_BELOW: where = _T("below"); break;
+ case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
+ case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
+ case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
+ case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
+ case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
+ case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
+ default: where = _T("not clear exactly where on"); break;
+ }
+
+ wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
+ where.c_str(), item, subitem);
+}
+
+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::OnGetItemColumnImage(long item, long column) const
+{
+ if (!column)
+ return 0;