EVT_MENU(LIST_VIRTUAL_VIEW, MyFrame::OnVirtualView)
EVT_MENU(LIST_SMALL_VIRTUAL_VIEW, MyFrame::OnSmallVirtualView)
+ EVT_MENU(LIST_GOTO, MyFrame::OnGoTo)
EVT_MENU(LIST_FOCUS_LAST, MyFrame::OnFocusLast)
EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel)
EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll)
#endif
wxMenu *menuList = new wxMenu;
+ menuList->Append(LIST_GOTO, _T("&Go to item #3\tCtrl-3"));
menuList->Append(LIST_FOCUS_LAST, _T("&Make last item current\tCtrl-L"));
menuList->Append(LIST_TOGGLE_FIRST, _T("To&ggle first item\tCtrl-G"));
menuList->Append(LIST_DESELECT_ALL, _T("&Deselect All\tCtrl-D"));
wxSystemOptions::SetOption(wxT("mac.listctrl.always_use_generic"), event.IsChecked());
}
+void MyFrame::OnGoTo(wxCommandEvent& WXUNUSED(event))
+{
+ long index = 3;
+ m_listCtrl->SetItemState(index, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
+
+ long sel = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL,
+ wxLIST_STATE_SELECTED);
+ if ( sel != -1 )
+ m_listCtrl->SetItemState(sel, 0, wxLIST_STATE_SELECTED);
+ m_listCtrl->SetItemState(index, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
+}
+
void MyFrame::OnFocusLast(wxCommandEvent& WXUNUSED(event))
{
long index = m_listCtrl->GetItemCount() - 1;
void MyListCtrl::OnEndLabelEdit(wxListEvent& event)
{
wxLogMessage( wxT("OnEndLabelEdit: %s"),
- event.IsEditCancelled() ? _T("[cancelled]")
- : event.m_item.m_text.c_str());
+ (
+ event.IsEditCancelled() ?
+ wxString("[cancelled]") :
+ event.m_item.m_text
+ ).c_str()
+ );
}
void MyListCtrl::OnDeleteItem(wxListEvent& event)
switch ( event.GetKeyCode() )
{
- case 'c': // colorize
- case 'C':
+ case 'C': // colorize
{
wxListItem info;
info.m_itemId = event.GetIndex();
}
break;
- case 'n': // next
- case 'N':
+ case 'N': // next
item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
if ( item++ == GetItemCount() - 1 )
{
EnsureVisible(item);
break;
- case 'r': // show bounding Rect
- case 'R':
+ case 'R': // show bounding rectangle
{
item = event.GetIndex();
wxRect r;
}
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 WXK_DELETE:
item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
while ( item != -1 )
case 'N':
case 'c':
case 'C':
+ case 'r':
+ case 'R':
+ case 'u':
+ case 'U':
+ case WXK_DELETE:
+ case WXK_INSERT:
// these are the keys we process ourselves
break;
{
return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
}
- else
+ else // "big" virtual control
{
return wxString::Format(_T("Column %ld of item %ld"), column, item);
}
if (!column)
return 0;
- if (!(item %3) && column == 1)
+ if (!(item % 3) && column == 1)
return 0;
return -1;
wxListItemAttr *MyListCtrl::OnGetItemAttr(long item) const
{
+ // test to check that RefreshItem() works correctly: when m_updated is
+ // set to some item and it is refreshed, we highlight the item
+ if ( item == m_updated )
+ {
+ static wxListItemAttr s_attrHighlight(*wxRED, wxNullColour, wxNullFont);
+ return &s_attrHighlight;
+ }
+
return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
}