From 7687a6ef13359dbac63eaae0b40cb6875873ea71 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Mon, 29 Aug 2016 10:50:35 -0700 Subject: [PATCH] ListView: Don't change selection while dragging This allows you to drag and drop list items more easily, but, removes the ability to drag and drop color squares in Appearance from one list item to another. Changing selected list items while dragging was more of a helpful side-effect for Appearance but isless reasonable default behavior. Fixes #12990 Partially regression on #8618 --- src/kits/interface/ListView.cpp | 48 ++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/kits/interface/ListView.cpp b/src/kits/interface/ListView.cpp index f26e2e7484..5cd11ac8a9 100644 --- a/src/kits/interface/ListView.cpp +++ b/src/kits/interface/ListView.cpp @@ -33,6 +33,7 @@ struct track_data { int32 item_index; bool was_selected; bool try_drag; + bool is_dragging; bigtime_t last_click_time; }; @@ -290,6 +291,11 @@ void BListView::MessageReceived(BMessage* message) { switch (message->what) { + case B_MOUSE_WHEEL_CHANGED: + if (!fTrack->is_dragging) + BView::MessageReceived(message); + break; + case B_COUNT_PROPERTIES: case B_EXECUTE_PROPERTY: case B_GET_PROPERTY: @@ -1453,6 +1459,7 @@ BListView::_InitObject(list_view_type type) fTrack->item_index = -1; fTrack->was_selected = false; fTrack->try_drag = false; + fTrack->is_dragging = false; fTrack->last_click_time = 0; SetViewUIColor(B_LIST_BACKGROUND_COLOR); @@ -1944,35 +1951,32 @@ void BListView::_DoneTracking(BPoint where) { fTrack->try_drag = false; + fTrack->is_dragging = false; } void BListView::_Track(BPoint where, uint32) { - int32 index = IndexOf(where); - BListItem* item = ItemAt(index); - - if (item != NULL && !item->IsSelected() && item->IsEnabled()) { - Select(index, fListType == B_MULTIPLE_SELECTION_LIST - && (modifiers() & B_SHIFT_KEY) != 0); - ScrollToSelection(); - fTrack->try_drag = false; - // don't try to initiate a drag once selection changes + if (fTrack->item_index > 0 && fTrack->try_drag) { + // initiate a drag if the mouse was moved far enough + BPoint offset = where - fTrack->drag_start; + float dragDistance = sqrtf(offset.x * offset.x + offset.y * offset.y); + if (dragDistance >= 5.0f) { + fTrack->try_drag = false; + fTrack->is_dragging = InitiateDrag(fTrack->drag_start, + fTrack->item_index, fTrack->was_selected); + } } - if (fTrack->item_index < 0 || !fTrack->try_drag) { - // mouse was not clicked above any item - // or no mouse button pressed - return; - } - - // Initiate a drag if the mouse was moved far enough - BPoint offset = where - fTrack->drag_start; - float dragDistance = sqrtf(offset.x * offset.x + offset.y * offset.y); - if (dragDistance >= 5.0f) { - fTrack->try_drag = false; - InitiateDrag(fTrack->drag_start, fTrack->item_index, - fTrack->was_selected); + if (!fTrack->is_dragging) { + // do selection only if a drag was not initiated + int32 index = IndexOf(where); + BListItem* item = ItemAt(index); + if (item != NULL && !item->IsSelected() && item->IsEnabled()) { + Select(index, fListType == B_MULTIPLE_SELECTION_LIST + && (modifiers() & B_SHIFT_KEY) != 0); + ScrollToSelection(); + } } }