From b293119a9335924c0ee2911b7e6fadb1c1666ef7 Mon Sep 17 00:00:00 2001 From: Kevin Ollivier Date: Sun, 22 Apr 2007 00:18:10 +0000 Subject: [PATCH] Backport of key handling and selection fixes. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@45575 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/listctrl_mac.cpp | 44 ++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/mac/carbon/listctrl_mac.cpp b/src/mac/carbon/listctrl_mac.cpp index 3b4941dc08..4e80407df1 100644 --- a/src/mac/carbon/listctrl_mac.cpp +++ b/src/mac/carbon/listctrl_mac.cpp @@ -654,6 +654,8 @@ void wxListCtrl::FireMouseEvent(wxEventType eventType, wxPoint position) void wxListCtrl::OnChar(wxKeyEvent& event) { + + if (m_dbImpl) { wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetId() ); @@ -661,6 +663,35 @@ void wxListCtrl::OnChar(wxKeyEvent& event) le.m_code = event.GetKeyCode(); le.m_itemIndex = -1; + if (m_current == -1) + { + // if m_current isn't set, check if there's been a selection + // made before continuing + m_current = GetNextItem(-1, wxLIST_NEXT_BELOW, wxLIST_STATE_SELECTED); + } + + // We need to determine m_current ourselves when navigation keys + // are used. Note that PAGEUP and PAGEDOWN do not alter the current + // item on native Mac ListCtrl, so we only handle up and down keys. + switch ( event.GetKeyCode() ) + { + case WXK_UP: + if ( m_current > 0 ) + m_current -= 1; + else + m_current = 0; + + break; + + case WXK_DOWN: + if ( m_current < GetItemCount() - 1 ) + m_current += 1; + else + m_current = GetItemCount() - 1; + + break; + } + if (m_current != -1) { le.m_itemIndex = m_current; @@ -1174,7 +1205,7 @@ bool wxListCtrl::SetItemState(long item, long state, long stateMask) if (m_dbImpl) { DataBrowserSetOption option = kDataBrowserItemsAdd; - if ( stateMask == wxLIST_STATE_SELECTED && state == 0 ) + if ( (stateMask & wxLIST_STATE_SELECTED) && state == 0 ) option = kDataBrowserItemsRemove; if (item == -1) @@ -1202,8 +1233,15 @@ bool wxListCtrl::SetItemState(long item, long state, long stateMask) if ( HasFlag(wxLC_VIRTUAL) ) { long itemID = item+1; + bool isSelected = IsDataBrowserItemSelected(m_dbImpl->GetControlRef(), (DataBrowserItemID)itemID ); + bool isSelectedState = (state == wxLIST_STATE_SELECTED); + + // toggle the selection state if wxListInfo state and actual state don't match. + if ( (stateMask & wxLIST_STATE_SELECTED) && isSelected != isSelectedState ) + { SetDataBrowserSelectedItems(m_dbImpl->GetControlRef(), 1, (DataBrowserItemID*)&itemID, option); } + } else { wxListItem info; @@ -1578,8 +1616,8 @@ long wxListCtrl::GetNextItem(long item, int geom, int state) const return line; } } - - if ( geom == wxLIST_NEXT_ALL || geom == wxLIST_NEXT_ABOVE ) + + if ( geom == wxLIST_NEXT_ABOVE ) { int item2 = item; if ( item2 == -1 )