From b720b86bfb26d2ae18f3ecccf3262f2538217192 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 11 Feb 2008 20:16:23 +0000 Subject: [PATCH] set selection anchor to the focused item in SetItemState() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51661 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/listctrl.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 84eafb3d90..a32c136696 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -934,14 +934,15 @@ bool wxListCtrl::SetItemState(long item, long state, long stateMask) wxConvertToMSWFlags(state, stateMask, lvItem); + const bool changingFocus = (stateMask & wxLIST_STATE_FOCUSED) && + (state & wxLIST_STATE_FOCUSED); + // for the virtual list controls we need to refresh the previously focused // item manually when changing focus without changing selection // programmatically because otherwise it keeps its focus rectangle until // next repaint (yet another comctl32 bug) long focusOld; - if ( IsVirtual() && - (stateMask & wxLIST_STATE_FOCUSED) && - (state & wxLIST_STATE_FOCUSED) ) + if ( IsVirtual() && changingFocus ) { focusOld = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED); } @@ -969,6 +970,16 @@ bool wxListCtrl::SetItemState(long item, long state, long stateMask) } } + // we expect the selection anchor, i.e. the item from which multiple + // selection (such as performed with e.g. Shift-arrows) starts, to be the + // same as the currently focused item but the native control doesn't update + // it when we change focus and leaves at the last item it set itself focus + // to, so do it explicitly + if ( changingFocus && !HasFlag(wxLC_SINGLE_SEL) ) + { + ListView_SetSelectionMark(GetHwnd(), item); + } + return true; } -- 2.45.2