From 10443b3306248992b268f4062e0277db214081bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 26 Feb 2006 17:47:02 +0000 Subject: [PATCH] fixed mouse tracking to not initiate a drag after mouse up git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16512 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/ListView.cpp | 61 ++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/src/kits/interface/ListView.cpp b/src/kits/interface/ListView.cpp index 6b81cfabeb..b86d015548 100644 --- a/src/kits/interface/ListView.cpp +++ b/src/kits/interface/ListView.cpp @@ -161,10 +161,10 @@ void BListView::Draw(BRect updateRect) { for (int i = 0; i < CountItems(); i++) { - BRect item_frame = ItemFrame(i); + BRect itemFrame = ItemFrame(i); - if (item_frame.Intersects(updateRect)) - DrawItem(((BListItem*)ItemAt(i)), item_frame); + if (itemFrame.Intersects(updateRect)) + DrawItem(((BListItem*)ItemAt(i)), itemFrame); } } @@ -326,6 +326,33 @@ BListView::MouseDown(BPoint point) } } +// MouseUp +void +BListView::MouseUp(BPoint pt) +{ + if (fWidth == 0) + return; + + DoMouseMoved(pt); + DoMouseUp(pt); + + fTrack->item_index = -1; + fTrack->try_drag = false; +} + +// MouseMoved +void +BListView::MouseMoved(BPoint pt, uint32 code, const BMessage *msg) +{ + if (fTrack->item_index == -1) + return; + + if (_TryInitiateDrag(pt)) + return; + + DoMouseMoved(pt); +} + // KeyDown void BListView::KeyDown(const char *bytes, int32 numBytes) @@ -986,11 +1013,12 @@ BListView::ItemFrame(int32 index) if (index < 0 || index >= CountItems()) return frame; + // TODO: this is very expensive, the (last) offsets could be cached for (int32 i = 0; i <= index; i++) { frame.top = frame.bottom + 1; frame.bottom += (float)ceil(ItemAt(i)->Height()); } - + return frame; } @@ -1040,30 +1068,6 @@ BListView::WindowActivated(bool state) } } -// MouseUp -void -BListView::MouseUp(BPoint pt) -{ - if (fWidth == 0) - return; - - DoMouseMoved(pt); - DoMouseUp(pt); -} - -// MouseMoved -void -BListView::MouseMoved(BPoint pt, uint32 code, const BMessage *msg) -{ - if (fTrack == NULL) - return; - - if (_TryInitiateDrag(pt)) - return; - - DoMouseMoved(pt); -} - // DetachedFromWindow void BListView::DetachedFromWindow() @@ -1158,6 +1162,7 @@ BListView::_InitObject(list_view_type type) fScrollView = NULL; fTrack = new track_data; fTrack->try_drag = false; + fTrack->item_index = -1; } // _FixupScrollBar