X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e16417726c4aacbcbdd107724ec16fa898b211d0..a39d7501685ff2a5e6623cec751c988726ed1874:/samples/listctrl/listtest.cpp diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index c2502a7096..23ee183e1e 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -75,6 +75,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) 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) @@ -225,6 +226,7 @@ MyFrame::MyFrame(const wxChar *title) #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")); @@ -346,6 +348,18 @@ void MyFrame::OnToggleMacUseGeneric(wxCommandEvent& event) 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; @@ -821,8 +835,12 @@ void MyListCtrl::OnBeginLabelEdit(wxListEvent& event) 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) @@ -881,8 +899,7 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event) switch ( event.GetKeyCode() ) { - case 'c': // colorize - case 'C': + case 'C': // colorize { wxListItem info; info.m_itemId = event.GetIndex(); @@ -906,8 +923,7 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event) } break; - case 'n': // next - case 'N': + case 'N': // next item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED); if ( item++ == GetItemCount() - 1 ) { @@ -920,8 +936,7 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event) EnsureVisible(item); break; - case 'r': // show bounding Rect - case 'R': + case 'R': // show bounding rectangle { item = event.GetIndex(); wxRect r; @@ -936,6 +951,26 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event) } 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 ) @@ -981,6 +1016,12 @@ void MyListCtrl::OnChar(wxKeyEvent& event) 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; @@ -1032,7 +1073,7 @@ wxString MyListCtrl::OnGetItemText(long item, long column) const { return SMALL_VIRTUAL_VIEW_ITEMS[item][column]; } - else + else // "big" virtual control { return wxString::Format(_T("Column %ld of item %ld"), column, item); } @@ -1043,7 +1084,7 @@ int MyListCtrl::OnGetItemColumnImage(long item, long column) const if (!column) return 0; - if (!(item %3) && column == 1) + if (!(item % 3) && column == 1) return 0; return -1; @@ -1051,6 +1092,14 @@ int MyListCtrl::OnGetItemColumnImage(long item, long column) const 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; }