* Applied a changed patch by Romain that fixes the non-working double click in

BListView. This fixes bug #3919. Got rid of the _TryInitiateDrag() method,
  and let MouseMoved() do it all.
* Style cleanup of the header, automatic whitespace cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30782 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-05-17 16:49:05 +00:00
parent 68c8eecd08
commit 97970c5c26
2 changed files with 154 additions and 163 deletions
+137 -134
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006, Haiku, Inc. All Rights Reserved. * Copyright 2002-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _LIST_VIEW_H #ifndef _LIST_VIEW_H
@@ -7,9 +7,9 @@
#include <Invoker.h> #include <Invoker.h>
#include <View.h>
#include <List.h> #include <List.h>
#include <ListItem.h> #include <ListItem.h>
#include <View.h>
struct track_data; struct track_data;
@@ -21,167 +21,170 @@ enum list_view_type {
class BListView : public BView, public BInvoker { class BListView : public BView, public BInvoker {
public: public:
BListView(BRect frame, const char* name, BListView(BRect frame, const char* name,
list_view_type type = B_SINGLE_SELECTION_LIST, list_view_type type = B_SINGLE_SELECTION_LIST,
uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP, uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
BListView(const char* name, | B_NAVIGABLE);
list_view_type type = B_SINGLE_SELECTION_LIST, BListView(const char* name,
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); list_view_type type = B_SINGLE_SELECTION_LIST,
BListView(list_view_type type = B_SINGLE_SELECTION_LIST); uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
BListView(BMessage* data); | B_NAVIGABLE);
BListView(
list_view_type type = B_SINGLE_SELECTION_LIST);
BListView(BMessage* data);
virtual ~BListView() ; virtual ~BListView();
static BArchivable* Instantiate(BMessage* data); static BArchivable* Instantiate(BMessage* data);
virtual status_t Archive(BMessage* data, bool deep = true) const; virtual status_t Archive(BMessage* data, bool deep = true) const;
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
virtual void MessageReceived(BMessage* msg); virtual void MessageReceived(BMessage* message);
virtual void MouseDown(BPoint where); virtual void MouseDown(BPoint where);
virtual void KeyDown(const char* bytes, int32 numBytes); virtual void KeyDown(const char* bytes, int32 numBytes);
virtual void MakeFocus(bool state = true); virtual void MakeFocus(bool state = true);
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void FrameResized(float newWidth, float newHeight); virtual void FrameResized(float newWidth, float newHeight);
virtual void FrameMoved(BPoint newPosition); virtual void FrameMoved(BPoint newPosition);
virtual void SetFont(const BFont* font, virtual void SetFont(const BFont* font, uint32 mask = B_FONT_ALL);
uint32 mask = B_FONT_ALL); virtual void TargetedByScrollView(BScrollView* scroller);
virtual void TargetedByScrollView(BScrollView* scroller); virtual void ScrollTo(BPoint where);
virtual void ScrollTo(BPoint where); inline void ScrollTo(float x, float y);
inline void ScrollTo(float x, float y); virtual bool AddItem(BListItem* item);
virtual bool AddItem(BListItem* item); virtual bool AddItem(BListItem* item, int32 atIndex);
virtual bool AddItem(BListItem* item, int32 atIndex); virtual bool AddList(BList* newItems);
virtual bool AddList(BList* newItems); virtual bool AddList(BList* newItems, int32 atIndex);
virtual bool AddList(BList* newItems, int32 atIndex); virtual bool RemoveItem(BListItem* item);
virtual bool RemoveItem(BListItem* item); virtual BListItem* RemoveItem(int32 index);
virtual BListItem* RemoveItem(int32 index); virtual bool RemoveItems(int32 index, int32 count);
virtual bool RemoveItems(int32 index, int32 count);
virtual void SetSelectionMessage(BMessage* message); virtual void SetSelectionMessage(BMessage* message);
virtual void SetInvocationMessage(BMessage* message); virtual void SetInvocationMessage(BMessage* message);
BMessage* SelectionMessage() const; BMessage* SelectionMessage() const;
uint32 SelectionCommand() const; uint32 SelectionCommand() const;
BMessage* InvocationMessage() const; BMessage* InvocationMessage() const;
uint32 InvocationCommand() const; uint32 InvocationCommand() const;
virtual void SetListType(list_view_type type); virtual void SetListType(list_view_type type);
list_view_type ListType() const; list_view_type ListType() const;
BListItem* ItemAt(int32 index) const; BListItem* ItemAt(int32 index) const;
int32 IndexOf(BPoint point) const; int32 IndexOf(BPoint point) const;
int32 IndexOf(BListItem* item) const; int32 IndexOf(BListItem* item) const;
BListItem* FirstItem() const; BListItem* FirstItem() const;
BListItem* LastItem() const; BListItem* LastItem() const;
bool HasItem(BListItem* item) const; bool HasItem(BListItem* item) const;
int32 CountItems() const; int32 CountItems() const;
virtual void MakeEmpty(); virtual void MakeEmpty();
bool IsEmpty() const; bool IsEmpty() const;
void DoForEach(bool (*func)(BListItem* item)); void DoForEach(bool (*func)(BListItem* item));
void DoForEach(bool (*func)(BListItem* item, void* arg), void* arg); void DoForEach(bool (*func)(BListItem* item, void* arg),
const BListItem** Items() const; void* arg);
void InvalidateItem(int32 index); const BListItem** Items() const;
void ScrollToSelection(); void InvalidateItem(int32 index);
void ScrollToSelection();
void Select(int32 index, bool extend = false); void Select(int32 index, bool extend = false);
void Select(int32 from, int32 to, bool extend = false); void Select(int32 from, int32 to, bool extend = false);
bool IsItemSelected(int32 index) const; bool IsItemSelected(int32 index) const;
int32 CurrentSelection(int32 index = 0) const; int32 CurrentSelection(int32 index = 0) const;
virtual status_t Invoke(BMessage* message = NULL); virtual status_t Invoke(BMessage* message = NULL);
void DeselectAll(); void DeselectAll();
void DeselectExcept(int32 exceptFrom, int32 exceptTo); void DeselectExcept(int32 exceptFrom, int32 exceptTo);
void Deselect(int32 index); void Deselect(int32 index);
virtual void SelectionChanged(); virtual void SelectionChanged();
void SortItems(int (*cmp)(const void*, const void*)); void SortItems(int (*cmp)(const void*, const void*));
/* These functions bottleneck through DoMiscellaneous() */ /* These functions bottleneck through DoMiscellaneous() */
bool SwapItems(int32 a, int32 b); bool SwapItems(int32 a, int32 b);
bool MoveItem(int32 from, int32 to); bool MoveItem(int32 from, int32 to);
bool ReplaceItem(int32 index, BListItem* item); bool ReplaceItem(int32 index, BListItem* item);
BRect ItemFrame(int32 index); BRect ItemFrame(int32 index);
virtual BHandler* ResolveSpecifier(BMessage* message, int32 index, virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
BMessage* specifier, int32 form, const char* property); BMessage* specifier, int32 form,
virtual status_t GetSupportedSuites(BMessage* data); const char* property);
virtual status_t GetSupportedSuites(BMessage* data);
virtual status_t Perform(perform_code code, void* arg); virtual status_t Perform(perform_code code, void* arg);
virtual void WindowActivated(bool state); virtual void WindowActivated(bool state);
virtual void MouseUp(BPoint point); virtual void MouseUp(BPoint point);
virtual void MouseMoved(BPoint point, uint32 code, virtual void MouseMoved(BPoint point, uint32 code,
const BMessage *dragMessage); const BMessage* dragMessage);
virtual void DetachedFromWindow(); virtual void DetachedFromWindow();
virtual bool InitiateDrag(BPoint point, int32 itemIndex, virtual bool InitiateDrag(BPoint point, int32 itemIndex,
bool initialySelected); bool initialySelected);
virtual void ResizeToPreferred(); virtual void ResizeToPreferred();
virtual void GetPreferredSize(float* _width, float* _height); virtual void GetPreferredSize(float* _width, float* _height);
virtual void AllAttached(); virtual void AllAttached();
virtual void AllDetached(); virtual void AllDetached();
virtual BSize MinSize(); virtual BSize MinSize();
virtual BSize MaxSize(); virtual BSize MaxSize();
virtual BSize PreferredSize(); virtual BSize PreferredSize();
protected: protected:
enum MiscCode { B_NO_OP, B_REPLACE_OP, B_MOVE_OP, B_SWAP_OP }; enum MiscCode { B_NO_OP, B_REPLACE_OP, B_MOVE_OP, B_SWAP_OP };
union MiscData { union MiscData {
struct Spare { int32 data[5]; }; struct Spare { int32 data[5]; };
struct Replace { int32 index; BListItem *item; } replace; struct Replace { int32 index; BListItem *item; } replace;
struct Move { int32 from; int32 to; } move; struct Move { int32 from; int32 to; } move;
struct Swap { int32 a; int32 b; } swap; struct Swap { int32 a; int32 b; } swap;
}; };
virtual bool DoMiscellaneous(MiscCode code, MiscData *data); virtual bool DoMiscellaneous(MiscCode code, MiscData* data);
private:
friend class BOutlineListView;
virtual void _ReservedListView2(); private:
virtual void _ReservedListView3(); friend class BOutlineListView;
virtual void _ReservedListView4();
BListView& operator=(const BListView&); virtual void _ReservedListView2();
virtual void _ReservedListView3();
virtual void _ReservedListView4();
void _InitObject(list_view_type type); BListView& operator=(const BListView& other);
void _FixupScrollBar();
void _InvalidateFrom(int32 index); void _InitObject(list_view_type type);
status_t _PostMessage(BMessage* message); void _FixupScrollBar();
void _FontChanged(); void _InvalidateFrom(int32 index);
int32 _RangeCheck(int32 index); status_t _PostMessage(BMessage* message);
bool _Select(int32 index, bool extend); void _FontChanged();
bool _Select(int32 from, int32 to, bool extend); int32 _RangeCheck(int32 index);
bool _Deselect(int32 index); bool _Select(int32 index, bool extend);
// void _Deselect(int32 from, int32 to); bool _Select(int32 from, int32 to, bool extend);
bool _DeselectAll(int32 exceptFrom, int32 exceptTo); bool _Deselect(int32 index);
// void PerformDelayedSelect(); bool _DeselectAll(int32 exceptFrom, int32 exceptTo);
bool _TryInitiateDrag(BPoint where); int32 _CalcFirstSelected(int32 after);
int32 _CalcFirstSelected(int32 after); int32 _CalcLastSelected(int32 before);
int32 _CalcLastSelected(int32 before); void _RecalcItemTops(int32 start, int32 end = -1);
void _RecalcItemTops(int32 start, int32 end = -1); virtual void DrawItem(BListItem* item, BRect itemRect,
virtual void DrawItem(BListItem* item, BRect itemRect,
bool complete = false); bool complete = false);
bool _SwapItems(int32 a, int32 b); bool _SwapItems(int32 a, int32 b);
bool _MoveItem(int32 from, int32 to); bool _MoveItem(int32 from, int32 to);
bool _ReplaceItem(int32 index, BListItem* item); bool _ReplaceItem(int32 index, BListItem* item);
void _RescanSelection(int32 from, int32 to); void _RescanSelection(int32 from, int32 to);
BList fList; BList fList;
list_view_type fListType; list_view_type fListType;
int32 fFirstSelected; int32 fFirstSelected;
int32 fLastSelected; int32 fLastSelected;
int32 fAnchorIndex; int32 fAnchorIndex;
BMessage* fSelectMessage; BMessage* fSelectMessage;
BScrollView* fScrollView; BScrollView* fScrollView;
track_data* fTrack; track_data* fTrack;
uint32 _reserved[4]; uint32 _reserved[4];
}; };
inline void inline void
BListView::ScrollTo(float x, float y) BListView::ScrollTo(float x, float y)
{ {
+12 -24
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001-2008, Haiku, Inc. * Copyright (c) 2001-2009, Haiku, Inc.
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Authors: * Authors:
@@ -382,22 +382,27 @@ BListView::MouseDown(BPoint point)
void void
BListView::MouseUp(BPoint pt) BListView::MouseUp(BPoint pt)
{ {
fTrack->item_index = -1;
fTrack->try_drag = false; fTrack->try_drag = false;
} }
// MouseMoved
void void
BListView::MouseMoved(BPoint pt, uint32 code, const BMessage *msg) BListView::MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage)
{ {
if (fTrack->item_index == -1) { if (fTrack->item_index == -1 || !fTrack->try_drag) {
// mouse was not clicked above any item // mouse was not clicked above any item
// or no mouse button pressed // or no mouse button pressed
return; return;
} }
if (_TryInitiateDrag(pt)) // Initiate a drag if the mouse was moved far enough
return; 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);
}
} }
@@ -1553,23 +1558,6 @@ BListView::_DeselectAll(int32 exceptFrom, int32 exceptTo)
} }
bool
BListView::_TryInitiateDrag(BPoint where)
{
if (!fTrack->try_drag || fTrack->item_index < 0)
return false;
BPoint offset = where - fTrack->drag_start;
float dragDistance = sqrtf(offset.x * offset.x + offset.y * offset.y);
if (dragDistance > 5.0) {
fTrack->try_drag = false;
return InitiateDrag(fTrack->drag_start, fTrack->item_index, fTrack->was_selected);
}
return false;
}
int32 int32
BListView::_CalcFirstSelected(int32 after) BListView::_CalcFirstSelected(int32 after)
{ {