From 100f649f944be51ddbcc55216a3938186f8f0770 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 2 Jul 2005 22:14:52 +0000 Subject: [PATCH] added GetItemRect() test git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34803 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/listctrl/listtest.cpp | 48 ++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index 19469c2655..99013eec8f 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -884,6 +884,8 @@ void MyListCtrl::OnFocused(wxListEvent& event) void MyListCtrl::OnListKeyDown(wxListEvent& event) { + long item; + switch ( event.GetKeyCode() ) { case 'c': // colorize @@ -907,35 +909,45 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event) 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': { - long item = GetNextItem(-1, - wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED); - if ( item++ == GetItemCount() - 1 ) + item = event.GetIndex(); + wxRect r; + if ( !GetItemRect(item, r) ) { - item = 0; + wxLogError(_T("Failed to retrieve rect of item %ld"), item); + break; } - wxLogMessage(_T("Focusing item %ld"), item); - - SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); - EnsureVisible(item); + 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 ) { - long item = GetNextItem(-1, - wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - while ( item != -1 ) - { - DeleteItem(item); + DeleteItem(item); - wxLogMessage(_T("Item %ld deleted"), 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); - } + // -1 because the indices were shifted by DeleteItem() + item = GetNextItem(item - 1, + wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); } break; -- 2.45.2