+void MyListCtrl::OnListKeyDown(wxListEvent& event)
+{
+ long item;
+
+ switch ( event.GetKeyCode() )
+ {
+ case 'C': // colorize
+ {
+ wxListItem info;
+ info.m_itemId = event.GetIndex();
+ if ( info.m_itemId == -1 )
+ {
+ // no item
+ break;
+ }
+
+ GetItem(info);
+
+ wxListItemAttr *attr = info.GetAttributes();
+ if ( !attr || !attr->HasTextColour() )
+ {
+ info.SetTextColour(*wxCYAN);
+
+ SetItem(info);
+
+ RefreshItem(info.m_itemId);
+ }
+ }
+ break;
+
+ case 'N': // next
+ item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
+ if ( item++ == GetItemCount() - 1 )
+ {
+ item = 0;
+ }
+
+ wxLogMessage(wxT("Focusing item %ld"), item);
+
+ SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
+ EnsureVisible(item);
+ break;
+
+ case 'R': // show bounding rectangle
+ {
+ item = event.GetIndex();
+ wxRect r;
+ if ( !GetItemRect(item, r) )
+ {
+ wxLogError(wxT("Failed to retrieve rect of item %ld"), item);
+ break;
+ }
+
+ wxLogMessage(wxT("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 '1': // show sub item bounding rectangle for the given column
+ case '2': // (and icon/label rectangle if Shift/Ctrl is pressed)
+ case '3':
+ case '4': // this column is invalid but we want to test it too
+ if ( InReportView() )
+ {
+ int subItem = event.GetKeyCode() - '1';
+ item = event.GetIndex();
+ wxRect r;
+
+ int code = wxLIST_RECT_BOUNDS;
+ if ( wxGetKeyState(WXK_SHIFT) )
+ code = wxLIST_RECT_ICON;
+ else if ( wxGetKeyState(WXK_CONTROL) )
+ code = wxLIST_RECT_LABEL;
+
+ if ( !GetSubItemRect(item, subItem, r, code) )
+ {
+ wxLogError(wxT("Failed to retrieve rect of item %ld column %d"), item, subItem + 1);
+ break;
+ }
+
+ wxLogMessage(wxT("Bounding rect of item %ld column %d is (%d, %d)-(%d, %d)"),
+ item, subItem + 1,
+ r.x, r.y, r.x + r.width, r.y + r.height);
+ }
+ break;
+
+ case 'U': // update
+ if ( !IsVirtual() )
+ break;
+
+ if ( m_updated != -1 )
+ RefreshItem(m_updated);
+
+ m_updated = event.GetIndex();
+ if ( m_updated != -1 )
+ {
+ // we won't see changes to this item as it's selected, update
+ // the next one (or the first one if we're on the last item)
+ if ( ++m_updated == GetItemCount() )
+ m_updated = 0;
+
+ wxLogMessage("Updating colour of the item %ld", m_updated);
+ RefreshItem(m_updated);
+ }
+ break;
+
+ case 'D': // delete
+ item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ while ( item != -1 )
+ {
+ DeleteItem(item);
+
+ wxLogMessage(wxT("Item %ld deleted"), item);
+
+ // -1 because the indices were shifted by DeleteItem()
+ item = GetNextItem(item - 1,
+ wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ }
+ break;
+
+ case 'I': // insert
+ if ( GetWindowStyle() & wxLC_REPORT )
+ {
+ if ( GetWindowStyle() & wxLC_VIRTUAL )
+ {
+ SetItemCount(GetItemCount() + 1);
+ }
+ else // !virtual
+ {
+ InsertItemInReportView(event.GetIndex());
+ }
+ }
+ //else: fall through
+
+ default:
+ LogEvent(event, wxT("OnListKeyDown"));
+
+ event.Skip();
+ }
+}
+