* Updated indentation style
* Better grouping of methods * Fixed copyright +alphabranch git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32700 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+146
-128
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2009, 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
|
||||||
#define _LIST_VIEW_H
|
#define _LIST_VIEW_H
|
||||||
@@ -22,114 +22,136 @@ 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
|
||||||
uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
= B_SINGLE_SELECTION_LIST,
|
||||||
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
|
uint32 resizeMask = B_FOLLOW_LEFT
|
||||||
| B_NAVIGABLE);
|
| B_FOLLOW_TOP,
|
||||||
BListView(const char* name,
|
uint32 flags = B_WILL_DRAW
|
||||||
list_view_type type = B_SINGLE_SELECTION_LIST,
|
| B_FRAME_EVENTS | B_NAVIGABLE);
|
||||||
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
|
BListView(const char* name,
|
||||||
| B_NAVIGABLE);
|
list_view_type type
|
||||||
BListView(
|
= B_SINGLE_SELECTION_LIST,
|
||||||
list_view_type type = B_SINGLE_SELECTION_LIST);
|
uint32 flags = B_WILL_DRAW
|
||||||
BListView(BMessage* data);
|
| B_FRAME_EVENTS | 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,
|
||||||
virtual void Draw(BRect updateRect);
|
bool deep = true) const;
|
||||||
virtual void MessageReceived(BMessage* message);
|
|
||||||
virtual void MouseDown(BPoint where);
|
|
||||||
virtual void KeyDown(const char* bytes, int32 numBytes);
|
|
||||||
virtual void MakeFocus(bool state = true);
|
|
||||||
virtual void AttachedToWindow();
|
|
||||||
virtual void FrameResized(float newWidth, float newHeight);
|
|
||||||
virtual void FrameMoved(BPoint newPosition);
|
|
||||||
virtual void SetFont(const BFont* font, uint32 mask = B_FONT_ALL);
|
|
||||||
virtual void TargetedByScrollView(BScrollView* scroller);
|
|
||||||
virtual void ScrollTo(BPoint where);
|
|
||||||
inline void ScrollTo(float x, float y);
|
|
||||||
virtual bool AddItem(BListItem* item);
|
|
||||||
virtual bool AddItem(BListItem* item, int32 atIndex);
|
|
||||||
virtual bool AddList(BList* newItems);
|
|
||||||
virtual bool AddList(BList* newItems, int32 atIndex);
|
|
||||||
virtual bool RemoveItem(BListItem* item);
|
|
||||||
virtual BListItem* RemoveItem(int32 index);
|
|
||||||
virtual bool RemoveItems(int32 index, int32 count);
|
|
||||||
|
|
||||||
virtual void SetSelectionMessage(BMessage* message);
|
virtual void Draw(BRect updateRect);
|
||||||
virtual void SetInvocationMessage(BMessage* message);
|
|
||||||
|
|
||||||
BMessage* SelectionMessage() const;
|
virtual void AttachedToWindow();
|
||||||
uint32 SelectionCommand() const;
|
virtual void DetachedFromWindow();
|
||||||
BMessage* InvocationMessage() const;
|
virtual void AllAttached();
|
||||||
uint32 InvocationCommand() const;
|
virtual void AllDetached();
|
||||||
|
virtual void FrameResized(float newWidth, float newHeight);
|
||||||
|
virtual void FrameMoved(BPoint newPosition);
|
||||||
|
virtual void TargetedByScrollView(BScrollView* scroller);
|
||||||
|
virtual void WindowActivated(bool state);
|
||||||
|
|
||||||
virtual void SetListType(list_view_type type);
|
virtual void MessageReceived(BMessage* message);
|
||||||
list_view_type ListType() const;
|
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||||
|
virtual void MouseDown(BPoint where);
|
||||||
|
virtual void MouseUp(BPoint point);
|
||||||
|
virtual void MouseMoved(BPoint point, uint32 code,
|
||||||
|
const BMessage* dragMessage);
|
||||||
|
|
||||||
BListItem* ItemAt(int32 index) const;
|
virtual bool InitiateDrag(BPoint point, int32 itemIndex,
|
||||||
int32 IndexOf(BPoint point) const;
|
bool initialySelected);
|
||||||
int32 IndexOf(BListItem* item) const;
|
|
||||||
BListItem* FirstItem() const;
|
|
||||||
BListItem* LastItem() const;
|
|
||||||
bool HasItem(BListItem* item) const;
|
|
||||||
int32 CountItems() const;
|
|
||||||
virtual void MakeEmpty();
|
|
||||||
bool IsEmpty() const;
|
|
||||||
void DoForEach(bool (*func)(BListItem* item));
|
|
||||||
void DoForEach(bool (*func)(BListItem* item, void* arg),
|
|
||||||
void* arg);
|
|
||||||
const BListItem** Items() const;
|
|
||||||
void InvalidateItem(int32 index);
|
|
||||||
void ScrollToSelection();
|
|
||||||
|
|
||||||
void Select(int32 index, bool extend = false);
|
virtual void ResizeToPreferred();
|
||||||
void Select(int32 from, int32 to, bool extend = false);
|
virtual void GetPreferredSize(float* _width,
|
||||||
bool IsItemSelected(int32 index) const;
|
float* _height);
|
||||||
int32 CurrentSelection(int32 index = 0) const;
|
|
||||||
virtual status_t Invoke(BMessage* message = NULL);
|
|
||||||
|
|
||||||
void DeselectAll();
|
virtual BSize MinSize();
|
||||||
void DeselectExcept(int32 exceptFrom, int32 exceptTo);
|
virtual BSize MaxSize();
|
||||||
void Deselect(int32 index);
|
virtual BSize PreferredSize();
|
||||||
|
|
||||||
virtual void SelectionChanged();
|
virtual void MakeFocus(bool state = true);
|
||||||
|
|
||||||
void SortItems(int (*cmp)(const void*, const void*));
|
virtual void SetFont(const BFont* font, uint32 mask
|
||||||
|
= B_FONT_ALL);
|
||||||
|
virtual void ScrollTo(BPoint where);
|
||||||
|
inline void ScrollTo(float x, float y);
|
||||||
|
|
||||||
/* These functions bottleneck through DoMiscellaneous() */
|
virtual bool AddItem(BListItem* item);
|
||||||
bool SwapItems(int32 a, int32 b);
|
virtual bool AddItem(BListItem* item, int32 atIndex);
|
||||||
bool MoveItem(int32 from, int32 to);
|
virtual bool AddList(BList* newItems);
|
||||||
bool ReplaceItem(int32 index, BListItem* item);
|
virtual bool AddList(BList* newItems, int32 atIndex);
|
||||||
|
virtual bool RemoveItem(BListItem* item);
|
||||||
|
virtual BListItem* RemoveItem(int32 index);
|
||||||
|
virtual bool RemoveItems(int32 index, int32 count);
|
||||||
|
|
||||||
BRect ItemFrame(int32 index);
|
virtual void SetSelectionMessage(BMessage* message);
|
||||||
|
virtual void SetInvocationMessage(BMessage* message);
|
||||||
|
|
||||||
virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
|
BMessage* SelectionMessage() const;
|
||||||
BMessage* specifier, int32 form,
|
uint32 SelectionCommand() const;
|
||||||
const char* property);
|
BMessage* InvocationMessage() const;
|
||||||
virtual status_t GetSupportedSuites(BMessage* data);
|
uint32 InvocationCommand() const;
|
||||||
|
|
||||||
virtual status_t Perform(perform_code code, void* arg);
|
virtual void SetListType(list_view_type type);
|
||||||
|
list_view_type ListType() const;
|
||||||
|
|
||||||
virtual void WindowActivated(bool state);
|
BListItem* ItemAt(int32 index) const;
|
||||||
virtual void MouseUp(BPoint point);
|
int32 IndexOf(BPoint point) const;
|
||||||
virtual void MouseMoved(BPoint point, uint32 code,
|
int32 IndexOf(BListItem* item) const;
|
||||||
const BMessage* dragMessage);
|
BListItem* FirstItem() const;
|
||||||
virtual void DetachedFromWindow();
|
BListItem* LastItem() const;
|
||||||
virtual bool InitiateDrag(BPoint point, int32 itemIndex,
|
bool HasItem(BListItem* item) const;
|
||||||
bool initialySelected);
|
int32 CountItems() const;
|
||||||
|
virtual void MakeEmpty();
|
||||||
|
bool IsEmpty() const;
|
||||||
|
void DoForEach(bool (*func)(BListItem* item));
|
||||||
|
void DoForEach(bool (*func)(BListItem* item,
|
||||||
|
void* arg), void* arg);
|
||||||
|
const BListItem** Items() const;
|
||||||
|
void InvalidateItem(int32 index);
|
||||||
|
void ScrollToSelection();
|
||||||
|
|
||||||
virtual void ResizeToPreferred();
|
void Select(int32 index, bool extend = false);
|
||||||
virtual void GetPreferredSize(float* _width, float* _height);
|
void Select(int32 from, int32 to,
|
||||||
virtual void AllAttached();
|
bool extend = false);
|
||||||
virtual void AllDetached();
|
bool IsItemSelected(int32 index) const;
|
||||||
|
int32 CurrentSelection(int32 index = 0) const;
|
||||||
|
virtual status_t Invoke(BMessage* message = NULL);
|
||||||
|
|
||||||
virtual BSize MinSize();
|
void DeselectAll();
|
||||||
virtual BSize MaxSize();
|
void DeselectExcept(int32 exceptFrom,
|
||||||
virtual BSize PreferredSize();
|
int32 exceptTo);
|
||||||
|
void Deselect(int32 index);
|
||||||
|
|
||||||
|
virtual void SelectionChanged();
|
||||||
|
|
||||||
|
void SortItems(int (*cmp)(const void*,
|
||||||
|
const void*));
|
||||||
|
|
||||||
|
// These functions bottleneck through DoMiscellaneous()
|
||||||
|
bool SwapItems(int32 a, int32 b);
|
||||||
|
bool MoveItem(int32 from, int32 to);
|
||||||
|
bool ReplaceItem(int32 index, BListItem* item);
|
||||||
|
|
||||||
|
BRect ItemFrame(int32 index);
|
||||||
|
|
||||||
|
virtual BHandler* ResolveSpecifier(BMessage* message,
|
||||||
|
int32 index, BMessage* specifier,
|
||||||
|
int32 form, const char* property);
|
||||||
|
virtual status_t GetSupportedSuites(BMessage* data);
|
||||||
|
|
||||||
|
virtual status_t Perform(perform_code code, void* arg);
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void _ReservedListView2();
|
||||||
|
virtual void _ReservedListView3();
|
||||||
|
virtual void _ReservedListView4();
|
||||||
|
|
||||||
|
BListView& operator=(const BListView& other);
|
||||||
|
|
||||||
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 };
|
||||||
@@ -140,48 +162,44 @@ protected:
|
|||||||
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:
|
private:
|
||||||
friend class BOutlineListView;
|
friend class BOutlineListView;
|
||||||
|
|
||||||
virtual void _ReservedListView2();
|
void _InitObject(list_view_type type);
|
||||||
virtual void _ReservedListView3();
|
void _FixupScrollBar();
|
||||||
virtual void _ReservedListView4();
|
void _InvalidateFrom(int32 index);
|
||||||
|
status_t _PostMessage(BMessage* message);
|
||||||
|
void _FontChanged();
|
||||||
|
int32 _RangeCheck(int32 index);
|
||||||
|
bool _Select(int32 index, bool extend);
|
||||||
|
bool _Select(int32 from, int32 to, bool extend);
|
||||||
|
bool _Deselect(int32 index);
|
||||||
|
bool _DeselectAll(int32 exceptFrom, int32 exceptTo);
|
||||||
|
int32 _CalcFirstSelected(int32 after);
|
||||||
|
int32 _CalcLastSelected(int32 before);
|
||||||
|
void _RecalcItemTops(int32 start, int32 end = -1);
|
||||||
|
|
||||||
BListView& operator=(const BListView& other);
|
virtual void DrawItem(BListItem* item, BRect itemRect,
|
||||||
|
bool complete = false);
|
||||||
|
|
||||||
void _InitObject(list_view_type type);
|
bool _SwapItems(int32 a, int32 b);
|
||||||
void _FixupScrollBar();
|
bool _MoveItem(int32 from, int32 to);
|
||||||
void _InvalidateFrom(int32 index);
|
bool _ReplaceItem(int32 index, BListItem* item);
|
||||||
status_t _PostMessage(BMessage* message);
|
void _RescanSelection(int32 from, int32 to);
|
||||||
void _FontChanged();
|
|
||||||
int32 _RangeCheck(int32 index);
|
|
||||||
bool _Select(int32 index, bool extend);
|
|
||||||
bool _Select(int32 from, int32 to, bool extend);
|
|
||||||
bool _Deselect(int32 index);
|
|
||||||
bool _DeselectAll(int32 exceptFrom, int32 exceptTo);
|
|
||||||
int32 _CalcFirstSelected(int32 after);
|
|
||||||
int32 _CalcLastSelected(int32 before);
|
|
||||||
void _RecalcItemTops(int32 start, int32 end = -1);
|
|
||||||
virtual void DrawItem(BListItem* item, BRect itemRect,
|
|
||||||
bool complete = false);
|
|
||||||
|
|
||||||
bool _SwapItems(int32 a, int32 b);
|
private:
|
||||||
bool _MoveItem(int32 from, int32 to);
|
BList fList;
|
||||||
bool _ReplaceItem(int32 index, BListItem* item);
|
list_view_type fListType;
|
||||||
void _RescanSelection(int32 from, int32 to);
|
int32 fFirstSelected;
|
||||||
|
int32 fLastSelected;
|
||||||
|
int32 fAnchorIndex;
|
||||||
|
BMessage* fSelectMessage;
|
||||||
|
BScrollView* fScrollView;
|
||||||
|
track_data* fTrack;
|
||||||
|
|
||||||
BList fList;
|
uint32 _reserved[4];
|
||||||
list_view_type fListType;
|
|
||||||
int32 fFirstSelected;
|
|
||||||
int32 fLastSelected;
|
|
||||||
int32 fAnchorIndex;
|
|
||||||
BMessage* fSelectMessage;
|
|
||||||
BScrollView* fScrollView;
|
|
||||||
track_data* fTrack;
|
|
||||||
|
|
||||||
uint32 _reserved[4];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -191,4 +209,4 @@ BListView::ScrollTo(float x, float y)
|
|||||||
ScrollTo(BPoint(x, y));
|
ScrollTo(BPoint(x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _LIST_VIEW_H */
|
#endif // _LIST_VIEW_H
|
||||||
|
|||||||
+234
-206
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2001-2009, Haiku, Inc.
|
* Copyright 2001-2009, Haiku, Inc. All rights resrerved.
|
||||||
* Distributed under the terms of the MIT license.
|
* Distributed under the terms of the MIT license.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -135,6 +135,9 @@ BListView::~BListView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
BArchivable*
|
BArchivable*
|
||||||
BListView::Instantiate(BMessage* archive)
|
BListView::Instantiate(BMessage* archive)
|
||||||
{
|
{
|
||||||
@@ -178,6 +181,9 @@ BListView::Archive(BMessage* archive, bool deep) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BListView::Draw(BRect updateRect)
|
BListView::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
@@ -198,6 +204,71 @@ BListView::Draw(BRect updateRect)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BListView::AttachedToWindow()
|
||||||
|
{
|
||||||
|
BView::AttachedToWindow();
|
||||||
|
_FontChanged();
|
||||||
|
|
||||||
|
if (!Messenger().IsValid())
|
||||||
|
SetTarget(Window(), NULL);
|
||||||
|
|
||||||
|
_FixupScrollBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BListView::DetachedFromWindow()
|
||||||
|
{
|
||||||
|
BView::DetachedFromWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BListView::AllAttached()
|
||||||
|
{
|
||||||
|
BView::AllAttached();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BListView::AllDetached()
|
||||||
|
{
|
||||||
|
BView::AllDetached();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BListView::FrameResized(float width, float height)
|
||||||
|
{
|
||||||
|
_FixupScrollBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BListView::FrameMoved(BPoint new_position)
|
||||||
|
{
|
||||||
|
BView::FrameMoved(new_position);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BListView::TargetedByScrollView(BScrollView *view)
|
||||||
|
{
|
||||||
|
fScrollView = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BListView::WindowActivated(bool state)
|
||||||
|
{
|
||||||
|
BView::WindowActivated(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BListView::MessageReceived(BMessage* msg)
|
BListView::MessageReceived(BMessage* msg)
|
||||||
{
|
{
|
||||||
@@ -215,7 +286,8 @@ BListView::MessageReceived(BMessage* msg)
|
|||||||
|| specifier.FindString("property", &property) != B_OK)
|
|| specifier.FindString("property", &property) != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (propInfo.FindMatch(msg, 0, &specifier, msg->what, property)) {
|
switch (propInfo.FindMatch(msg, 0, &specifier, msg->what,
|
||||||
|
property)) {
|
||||||
case B_ERROR:
|
case B_ERROR:
|
||||||
BView::MessageReceived(msg);
|
BView::MessageReceived(msg);
|
||||||
break;
|
break;
|
||||||
@@ -301,6 +373,96 @@ BListView::MessageReceived(BMessage* msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BListView::KeyDown(const char *bytes, int32 numBytes)
|
||||||
|
{
|
||||||
|
bool extend
|
||||||
|
= fListType == B_MULTIPLE_SELECTION_LIST
|
||||||
|
&& (modifiers() & B_SHIFT_KEY) != 0;
|
||||||
|
|
||||||
|
switch (bytes[0]) {
|
||||||
|
case B_UP_ARROW:
|
||||||
|
{
|
||||||
|
if (fFirstSelected == -1) {
|
||||||
|
// if nothing is selected yet, always select the first item
|
||||||
|
Select(0);
|
||||||
|
} else {
|
||||||
|
if (fAnchorIndex > 0) {
|
||||||
|
if (!extend || fAnchorIndex <= fFirstSelected)
|
||||||
|
Select(fAnchorIndex - 1, extend);
|
||||||
|
else
|
||||||
|
Deselect(fAnchorIndex--);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ScrollToSelection();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case B_DOWN_ARROW:
|
||||||
|
{
|
||||||
|
if (fFirstSelected == -1) {
|
||||||
|
// if nothing is selected yet, always select the first item
|
||||||
|
Select(0);
|
||||||
|
} else {
|
||||||
|
if (fAnchorIndex < CountItems() - 1) {
|
||||||
|
if (!extend || fAnchorIndex >= fLastSelected)
|
||||||
|
Select(fAnchorIndex + 1, extend);
|
||||||
|
else
|
||||||
|
Deselect(fAnchorIndex++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ScrollToSelection();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case B_HOME:
|
||||||
|
if (extend) {
|
||||||
|
Select(0, fAnchorIndex, true);
|
||||||
|
fAnchorIndex = 0;
|
||||||
|
} else
|
||||||
|
Select(0, false);
|
||||||
|
ScrollToSelection();
|
||||||
|
break;
|
||||||
|
case B_END:
|
||||||
|
if (extend) {
|
||||||
|
Select(fAnchorIndex, CountItems() - 1, true);
|
||||||
|
fAnchorIndex = CountItems() - 1;
|
||||||
|
} else
|
||||||
|
Select(CountItems() - 1, false);
|
||||||
|
ScrollToSelection();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_PAGE_UP:
|
||||||
|
{
|
||||||
|
BPoint scrollOffset(LeftTop());
|
||||||
|
scrollOffset.y = max_c(0, scrollOffset.y - Bounds().Height());
|
||||||
|
ScrollTo(scrollOffset);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case B_PAGE_DOWN:
|
||||||
|
{
|
||||||
|
BPoint scrollOffset(LeftTop());
|
||||||
|
if (BListItem* item = LastItem()) {
|
||||||
|
scrollOffset.y += Bounds().Height();
|
||||||
|
scrollOffset.y = min_c(item->Bottom() - Bounds().Height(),
|
||||||
|
scrollOffset.y);
|
||||||
|
}
|
||||||
|
ScrollTo(scrollOffset);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case B_RETURN:
|
||||||
|
case B_SPACE:
|
||||||
|
Invoke();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
BView::KeyDown(bytes, numBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BListView::MouseDown(BPoint point)
|
BListView::MouseDown(BPoint point)
|
||||||
{
|
{
|
||||||
@@ -408,96 +570,74 @@ BListView::MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
bool
|
||||||
BListView::KeyDown(const char *bytes, int32 numBytes)
|
BListView::InitiateDrag(BPoint point, int32 index, bool wasSelected)
|
||||||
{
|
{
|
||||||
bool extend
|
return false;
|
||||||
= fListType == B_MULTIPLE_SELECTION_LIST
|
}
|
||||||
&& (modifiers() & B_SHIFT_KEY) != 0;
|
|
||||||
|
|
||||||
switch (bytes[0]) {
|
|
||||||
case B_UP_ARROW:
|
|
||||||
{
|
|
||||||
if (fFirstSelected == -1) {
|
|
||||||
// if nothing is selected yet, always select the first item
|
|
||||||
Select(0);
|
|
||||||
} else {
|
|
||||||
if (fAnchorIndex > 0) {
|
|
||||||
if (!extend || fAnchorIndex <= fFirstSelected)
|
|
||||||
Select(fAnchorIndex - 1, extend);
|
|
||||||
else
|
|
||||||
Deselect(fAnchorIndex--);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ScrollToSelection();
|
// #pragma mark -
|
||||||
break;
|
|
||||||
}
|
|
||||||
case B_DOWN_ARROW:
|
|
||||||
{
|
|
||||||
if (fFirstSelected == -1) {
|
|
||||||
// if nothing is selected yet, always select the first item
|
|
||||||
Select(0);
|
|
||||||
} else {
|
|
||||||
if (fAnchorIndex < CountItems() - 1) {
|
|
||||||
if (!extend || fAnchorIndex >= fLastSelected)
|
|
||||||
Select(fAnchorIndex + 1, extend);
|
|
||||||
else
|
|
||||||
Deselect(fAnchorIndex++);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ScrollToSelection();
|
|
||||||
break;
|
void
|
||||||
|
BListView::ResizeToPreferred()
|
||||||
|
{
|
||||||
|
BView::ResizeToPreferred();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BListView::GetPreferredSize(float* _width, float* _height)
|
||||||
|
{
|
||||||
|
int32 count = CountItems();
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
float maxWidth = 0.0;
|
||||||
|
for (int32 i = 0; i < count; i++) {
|
||||||
|
float itemWidth = ItemAt(i)->Width();
|
||||||
|
if (itemWidth > maxWidth)
|
||||||
|
maxWidth = itemWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
case B_HOME:
|
if (_width != NULL)
|
||||||
if (extend) {
|
*_width = maxWidth;
|
||||||
Select(0, fAnchorIndex, true);
|
if (_height != NULL)
|
||||||
fAnchorIndex = 0;
|
*_height = ItemAt(count - 1)->Bottom();
|
||||||
} else
|
} else {
|
||||||
Select(0, false);
|
BView::GetPreferredSize(_width, _height);
|
||||||
ScrollToSelection();
|
|
||||||
break;
|
|
||||||
case B_END:
|
|
||||||
if (extend) {
|
|
||||||
Select(fAnchorIndex, CountItems() - 1, true);
|
|
||||||
fAnchorIndex = CountItems() - 1;
|
|
||||||
} else
|
|
||||||
Select(CountItems() - 1, false);
|
|
||||||
ScrollToSelection();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case B_PAGE_UP:
|
|
||||||
{
|
|
||||||
BPoint scrollOffset(LeftTop());
|
|
||||||
scrollOffset.y = max_c(0, scrollOffset.y - Bounds().Height());
|
|
||||||
ScrollTo(scrollOffset);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case B_PAGE_DOWN:
|
|
||||||
{
|
|
||||||
BPoint scrollOffset(LeftTop());
|
|
||||||
if (BListItem* item = LastItem()) {
|
|
||||||
scrollOffset.y += Bounds().Height();
|
|
||||||
scrollOffset.y = min_c(item->Bottom() - Bounds().Height(),
|
|
||||||
scrollOffset.y);
|
|
||||||
}
|
|
||||||
ScrollTo(scrollOffset);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case B_RETURN:
|
|
||||||
case B_SPACE:
|
|
||||||
Invoke();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
BView::KeyDown(bytes, numBytes);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
BListView::MinSize()
|
||||||
|
{
|
||||||
|
// We need a stable min size: the BView implementation uses
|
||||||
|
// GetPreferredSize(), which by default just returns the current size.
|
||||||
|
return BLayoutUtils::ComposeSize(ExplicitMinSize(), BSize(10, 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
BListView::MaxSize()
|
||||||
|
{
|
||||||
|
return BView::MaxSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
BListView::PreferredSize()
|
||||||
|
{
|
||||||
|
// We need a stable preferred size: the BView implementation uses
|
||||||
|
// GetPreferredSize(), which by default just returns the current size.
|
||||||
|
return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), BSize(100, 50));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BListView::MakeFocus(bool focused)
|
BListView::MakeFocus(bool focused)
|
||||||
{
|
{
|
||||||
@@ -511,33 +651,6 @@ BListView::MakeFocus(bool focused)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BListView::AttachedToWindow()
|
|
||||||
{
|
|
||||||
BView::AttachedToWindow();
|
|
||||||
_FontChanged();
|
|
||||||
|
|
||||||
if (!Messenger().IsValid())
|
|
||||||
SetTarget(Window(), NULL);
|
|
||||||
|
|
||||||
_FixupScrollBar();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BListView::FrameResized(float width, float height)
|
|
||||||
{
|
|
||||||
_FixupScrollBar();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BListView::FrameMoved(BPoint new_position)
|
|
||||||
{
|
|
||||||
BView::FrameMoved(new_position);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BListView::SetFont(const BFont* font, uint32 mask)
|
BListView::SetFont(const BFont* font, uint32 mask)
|
||||||
{
|
{
|
||||||
@@ -546,13 +659,6 @@ BListView::SetFont(const BFont* font, uint32 mask)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BListView::TargetedByScrollView(BScrollView *view)
|
|
||||||
{
|
|
||||||
fScrollView = view;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BListView::ScrollTo(BPoint point)
|
BListView::ScrollTo(BPoint point)
|
||||||
{
|
{
|
||||||
@@ -560,6 +666,9 @@ BListView::ScrollTo(BPoint point)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - List ops
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BListView::AddItem(BListItem *item, int32 index)
|
BListView::AddItem(BListItem *item, int32 index)
|
||||||
{
|
{
|
||||||
@@ -1119,6 +1228,9 @@ BListView::ItemFrame(int32 index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
BHandler*
|
BHandler*
|
||||||
BListView::ResolveSpecifier(BMessage* message, int32 index,
|
BListView::ResolveSpecifier(BMessage* message, int32 index,
|
||||||
BMessage* specifier, int32 form, const char* property)
|
BMessage* specifier, int32 form, const char* property)
|
||||||
@@ -1210,96 +1322,6 @@ BListView::Perform(perform_code code, void* _data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BListView::WindowActivated(bool state)
|
|
||||||
{
|
|
||||||
BView::WindowActivated(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BListView::DetachedFromWindow()
|
|
||||||
{
|
|
||||||
BView::DetachedFromWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
BListView::InitiateDrag(BPoint point, int32 index, bool wasSelected)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BListView::ResizeToPreferred()
|
|
||||||
{
|
|
||||||
BView::ResizeToPreferred();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BListView::GetPreferredSize(float* _width, float* _height)
|
|
||||||
{
|
|
||||||
int32 count = CountItems();
|
|
||||||
|
|
||||||
if (count > 0) {
|
|
||||||
float maxWidth = 0.0;
|
|
||||||
for (int32 i = 0; i < count; i++) {
|
|
||||||
float itemWidth = ItemAt(i)->Width();
|
|
||||||
if (itemWidth > maxWidth)
|
|
||||||
maxWidth = itemWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_width != NULL)
|
|
||||||
*_width = maxWidth;
|
|
||||||
if (_height != NULL)
|
|
||||||
*_height = ItemAt(count - 1)->Bottom();
|
|
||||||
} else {
|
|
||||||
BView::GetPreferredSize(_width, _height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BListView::AllAttached()
|
|
||||||
{
|
|
||||||
BView::AllAttached();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BListView::AllDetached()
|
|
||||||
{
|
|
||||||
BView::AllDetached();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BSize
|
|
||||||
BListView::MinSize()
|
|
||||||
{
|
|
||||||
// We need a stable min size: the BView implementation uses
|
|
||||||
// GetPreferredSize(), which by default just returns the current size.
|
|
||||||
return BLayoutUtils::ComposeSize(ExplicitMinSize(), BSize(10, 10));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BSize
|
|
||||||
BListView::MaxSize()
|
|
||||||
{
|
|
||||||
return BView::MaxSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BSize
|
|
||||||
BListView::PreferredSize()
|
|
||||||
{
|
|
||||||
// We need a stable preferred size: the BView implementation uses
|
|
||||||
// GetPreferredSize(), which by default just returns the current size.
|
|
||||||
return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), BSize(100, 50));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BListView::DoMiscellaneous(MiscCode code, MiscData* data)
|
BListView::DoMiscellaneous(MiscCode code, MiscData* data)
|
||||||
{
|
{
|
||||||
@@ -1324,6 +1346,9 @@ BListView::DoMiscellaneous(MiscCode code, MiscData* data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
void BListView::_ReservedListView2() {}
|
void BListView::_ReservedListView2() {}
|
||||||
void BListView::_ReservedListView3() {}
|
void BListView::_ReservedListView3() {}
|
||||||
void BListView::_ReservedListView4() {}
|
void BListView::_ReservedListView4() {}
|
||||||
@@ -1336,6 +1361,9 @@ BListView::operator=(const BListView& /*other*/)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BListView::_InitObject(list_view_type type)
|
BListView::_InitObject(list_view_type type)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user