ListView: fix track session handling
Fix various track session handling related bugs like unexpected selected item change when mouse button was not pressed inside list view or not currently pressed at all. Use `fTrack->is_active` to indicate that track session is active. Remove `fTrack->buttons` because exact mouse button is never checked in code. Remove some redundant conditions. Remove now not needed workaround in `BColorListView::MouseUp`. Change-Id: Ic4ac846019bd71af008c936dd8d7d265326cba9a Reviewed-on: https://review.haiku-os.org/c/haiku/+/10968 Haiku-Format: Haiku-format Bot <[email protected]> Tested-by: Commit checker robot <[email protected]> Reviewed-by: John Scipione <[email protected]>
This commit is contained in:
@@ -24,7 +24,6 @@ public:
|
|||||||
virtual ~BColorListView();
|
virtual ~BColorListView();
|
||||||
|
|
||||||
virtual bool InitiateDrag(BPoint where, int32 index, bool wasSelected);
|
virtual bool InitiateDrag(BPoint where, int32 index, bool wasSelected);
|
||||||
virtual void MouseUp(BPoint where);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,8 @@
|
|||||||
struct track_data {
|
struct track_data {
|
||||||
BPoint drag_start;
|
BPoint drag_start;
|
||||||
int32 item_index;
|
int32 item_index;
|
||||||
int32 buttons;
|
|
||||||
uint32 selected_click_count;
|
uint32 selected_click_count;
|
||||||
|
bool is_active;
|
||||||
bool was_selected;
|
bool was_selected;
|
||||||
bool try_drag;
|
bool try_drag;
|
||||||
bool is_dragging;
|
bool is_dragging;
|
||||||
@@ -621,19 +621,15 @@ BListView::KeyDown(const char* bytes, int32 numBytes)
|
|||||||
void
|
void
|
||||||
BListView::MouseDown(BPoint where)
|
BListView::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
|
if (fTrack->is_active)
|
||||||
|
return BView::MouseDown(where);
|
||||||
|
|
||||||
if (!IsFocus()) {
|
if (!IsFocus()) {
|
||||||
MakeFocus();
|
MakeFocus();
|
||||||
Sync();
|
Sync();
|
||||||
Window()->UpdateIfNeeded();
|
Window()->UpdateIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 buttons = 0;
|
|
||||||
if (Window() != NULL) {
|
|
||||||
BMessage* currentMessage = Window()->CurrentMessage();
|
|
||||||
if (currentMessage != NULL)
|
|
||||||
currentMessage->FindInt32("buttons", &buttons);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32 index = IndexOf(where);
|
int32 index = IndexOf(where);
|
||||||
|
|
||||||
// If the user double (or more) clicked within the current selection,
|
// If the user double (or more) clicked within the current selection,
|
||||||
@@ -663,6 +659,7 @@ BListView::MouseDown(BPoint where)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!doubleClick) {
|
if (!doubleClick) {
|
||||||
|
fTrack->is_active = true;
|
||||||
fTrack->drag_start = where;
|
fTrack->drag_start = where;
|
||||||
fTrack->last_click_time = system_time();
|
fTrack->last_click_time = system_time();
|
||||||
fTrack->item_index = index;
|
fTrack->item_index = index;
|
||||||
@@ -673,8 +670,7 @@ BListView::MouseDown(BPoint where)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// increment/reset selected click count
|
// increment/reset selected click count
|
||||||
fTrack->buttons = buttons;
|
if (fTrack->was_selected)
|
||||||
if (fTrack->buttons > 0 && fTrack->was_selected)
|
|
||||||
fTrack->selected_click_count++;
|
fTrack->selected_click_count++;
|
||||||
else
|
else
|
||||||
fTrack->selected_click_count = 0;
|
fTrack->selected_click_count = 0;
|
||||||
@@ -688,10 +684,13 @@ BListView::MouseDown(BPoint where)
|
|||||||
void
|
void
|
||||||
BListView::MouseUp(BPoint where)
|
BListView::MouseUp(BPoint where)
|
||||||
{
|
{
|
||||||
|
if (!fTrack->is_active)
|
||||||
|
return BView::MouseUp(where);
|
||||||
|
|
||||||
bool wasDragging = fTrack->is_dragging;
|
bool wasDragging = fTrack->is_dragging;
|
||||||
|
|
||||||
// drag is over
|
// drag is over
|
||||||
fTrack->buttons = 0;
|
fTrack->is_active = false;
|
||||||
fTrack->try_drag = false;
|
fTrack->try_drag = false;
|
||||||
fTrack->is_dragging = false;
|
fTrack->is_dragging = false;
|
||||||
|
|
||||||
@@ -728,6 +727,9 @@ BListView::MouseUp(BPoint where)
|
|||||||
void
|
void
|
||||||
BListView::MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage)
|
BListView::MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage)
|
||||||
{
|
{
|
||||||
|
if (!fTrack->is_active)
|
||||||
|
return BView::MouseMoved(where, code, dragMessage);
|
||||||
|
|
||||||
if (fTrack->item_index >= 0 && fTrack->try_drag) {
|
if (fTrack->item_index >= 0 && fTrack->try_drag) {
|
||||||
// initiate a drag if the mouse was moved far enough
|
// initiate a drag if the mouse was moved far enough
|
||||||
BPoint offset = where - fTrack->drag_start;
|
BPoint offset = where - fTrack->drag_start;
|
||||||
@@ -749,9 +751,9 @@ BListView::MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage)
|
|||||||
index = CountItems() - 1;
|
index = CountItems() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't scroll if button not pressed or index is invalid
|
// don't scroll if index is invalid
|
||||||
int32 lastIndex = fFirstSelected;
|
int32 lastIndex = fFirstSelected;
|
||||||
if (fTrack->buttons == 0 || index == -1)
|
if (index == -1)
|
||||||
return BView::MouseMoved(where, code, dragMessage);
|
return BView::MouseMoved(where, code, dragMessage);
|
||||||
|
|
||||||
// don't scroll if mouse is left or right of the view
|
// don't scroll if mouse is left or right of the view
|
||||||
@@ -1616,8 +1618,8 @@ BListView::_InitObject(list_view_type type)
|
|||||||
fTrack = new track_data;
|
fTrack = new track_data;
|
||||||
fTrack->drag_start = B_ORIGIN;
|
fTrack->drag_start = B_ORIGIN;
|
||||||
fTrack->item_index = -1;
|
fTrack->item_index = -1;
|
||||||
fTrack->buttons = 0;
|
|
||||||
fTrack->selected_click_count = 0;
|
fTrack->selected_click_count = 0;
|
||||||
|
fTrack->is_active = false;
|
||||||
fTrack->was_selected = false;
|
fTrack->was_selected = false;
|
||||||
fTrack->try_drag = false;
|
fTrack->try_drag = false;
|
||||||
fTrack->is_dragging = false;
|
fTrack->is_dragging = false;
|
||||||
|
|||||||
@@ -115,12 +115,4 @@ BColorListView::InitiateDrag(BPoint where, int32 index, bool wasSelected)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BColorListView::MouseUp(BPoint where)
|
|
||||||
{
|
|
||||||
// TODO drag and drop from an external view should not alter selection
|
|
||||||
BView::MouseUp(where);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|||||||
Reference in New Issue
Block a user