#ifndef LIST_VIEWS_H
#define LIST_VIEWS_H
#include <ListItem.h>
#include <ListView.h>
#include <Message.h>
#include "MouseWheelFilter.h"
#include "Observer.h"
#define SCROLL_AREA 0.1
class BMessageFilter;
class BMessageRunner;
class BScrollView;
class Selectable;
class Selection;
class SimpleItem : public BStringItem
{
public:
SimpleItem(const char* name);
virtual ~SimpleItem();
virtual void DrawItem(BView*, BRect, bool even = false);
virtual void DrawBackground(BView*, BRect, bool even);
};
class DragSortableListView : public BListView,
public MouseWheelTarget, public Observer {
public:
DragSortableListView(BRect frame,
const char* name,
list_view_type type = B_SINGLE_SELECTION_LIST,
uint32 resizingMode
= B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE
| B_FRAME_EVENTS);
virtual ~DragSortableListView();
virtual void AttachedToWindow();
virtual void DetachedFromWindow();
virtual void FrameResized(float width, float height);
virtual void TargetedByScrollView(BScrollView*);
virtual void MessageReceived(BMessage* message);
virtual void KeyDown(const char* bytes, int32 numBytes);
virtual void MouseDown(BPoint where);
virtual void MouseMoved(BPoint where, uint32, const BMessage*);
virtual void MouseUp(BPoint where);
virtual void WindowActivated(bool active);
virtual bool MouseWheelChanged(float x, float y);
virtual void ObjectChanged(const Observable* object);
virtual void SetDragCommand(uint32 command);
virtual void ModifiersChanged();
virtual void DoubleClicked(int32 index) {}
virtual void SetItemFocused(int32 index);
virtual bool AcceptDragMessage(const BMessage* message) const;
virtual bool HandleDropMessage(const BMessage* message,
int32 dropIndex);
virtual void SetDropTargetRect(const BMessage* message,
BPoint where);
bool DoesAutoScrolling() const;
BScrollView* ScrollView() const
{ return fScrollView; }
virtual void MoveItems(BList& items, int32 toIndex);
virtual void CopyItems(BList& items, int32 toIndex);
virtual void RemoveItemList(BList& indices);
void RemoveSelected();
virtual bool DeleteItem(int32 index);
void SetSelection(Selection* selection);
virtual int32 IndexOfSelectable(Selectable* selectable) const;
virtual Selectable* SelectableFor(BListItem* item) const;
void SetDeselectAllInGlobalSelection(bool deselect);
void SelectAll();
int32 CountSelectedItems() const;
virtual void SelectionChanged();
virtual BListItem* CloneItem(int32 atIndex) const = 0;
virtual void MakeDragMessage(BMessage* message) const = 0;
protected:
void InvalidateDropRect();
void SetDragMessage(const BMessage* message);
BRect fDropRect;
BMessage fDragMessageCopy;
BMessageFilter* fMouseWheelFilter;
BMessageRunner* fScrollPulse;
BPoint fLastMousePos;
protected:
void SetDropRect(BRect rect);
void SetDropIndex(int32 index);
int32 fDropIndex;
BListItem* fLastClickedItem;
BScrollView* fScrollView;
uint32 fDragCommand;
int32 fFocusedIndex;
Selection* fSelection;
bool fSyncingToSelection;
bool fModifyingSelection;
};
class SimpleListView : public DragSortableListView {
public:
SimpleListView(BRect frame,
BMessage* selectionChanged = NULL);
SimpleListView(BRect frame, const char* name,
BMessage* selectionChanged = NULL,
list_view_type type
= B_MULTIPLE_SELECTION_LIST,
uint32 resizingMode = B_FOLLOW_ALL_SIDES,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE
| B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE);
~SimpleListView();
virtual void DetachedFromWindow();
virtual void Draw(BRect updateRect);
virtual bool InitiateDrag(BPoint, int32, bool);
virtual void MessageReceived(BMessage* message);
virtual BListItem* CloneItem(int32 atIndex) const;
virtual status_t ArchiveSelection(BMessage*, bool = true) const = 0;
virtual bool InstantiateSelection(const BMessage*, int32) = 0;
virtual void MakeDragMessage(BMessage* message) const;
virtual bool HandleDropMessage(const BMessage* message,
int32 dropIndex);
bool HandlePaste(const BMessage* archive);
protected:
void _MakeEmpty();
private:
BMessage* fSelectionChangeMessage;
};
#endif