From: Vadim Zeitlin Date: Sun, 16 Mar 2008 00:04:51 +0000 (+0000) Subject: added test of focusing/selecting another item X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6ef2b230567a8b1a48a2fcda5fa435090cd6428f added test of focusing/selecting another item git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52556 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index ebfa7accb6..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; diff --git a/samples/listctrl/listtest.h b/samples/listctrl/listtest.h index 2126c4b4b7..18066ea992 100644 --- a/samples/listctrl/listtest.h +++ b/samples/listctrl/listtest.h @@ -120,6 +120,7 @@ protected: void OnVirtualView(wxCommandEvent& event); void OnSmallVirtualView(wxCommandEvent& event); + void OnGoTo(wxCommandEvent& event); void OnFocusLast(wxCommandEvent& event); void OnToggleFirstSel(wxCommandEvent& event); void OnDeselectAll(wxCommandEvent& event); @@ -201,6 +202,7 @@ enum LIST_TOGGLE_FIRST, LIST_SHOW_COL_INFO, LIST_SHOW_SEL_INFO, + LIST_GOTO, LIST_FOCUS_LAST, LIST_FREEZE, LIST_THAW,