1 /* 2 * Copyright 2006-2007, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 #ifndef LIST_VIEWS_H 9 #define LIST_VIEWS_H 10 11 #include <ListItem.h> 12 #include <ListView.h> 13 #include <Message.h> 14 15 enum { 16 FLAGS_NONE = 0x00, 17 FLAGS_TINTED_LINE = 0x01, 18 FLAGS_FOCUSED = 0x02, 19 }; 20 21 // portion of the listviews height that triggers autoscrolling 22 // when the mouse is over it with a dragmessage 23 #define SCROLL_AREA 0.1 24 25 class BMessageRunner; 26 class BMessageFilter; 27 class InterfaceWindow; 28 class BScrollView; 29 30 // SimpleItem 31 class SimpleItem : public BStringItem { 32 public: 33 SimpleItem(const char* name); 34 virtual ~SimpleItem(); 35 36 virtual void Draw(BView* owner, BRect frame, 37 uint32 flags); 38 virtual void DrawBackground(BView* owner, BRect frame, 39 uint32 flags); 40 }; 41 42 // DragSortableListView 43 class DragSortableListView : public BListView { 44 public: 45 DragSortableListView(BRect frame, const char* name, 46 list_view_type type = B_SINGLE_SELECTION_LIST, 47 uint32 resizingMode = B_FOLLOW_LEFT 48 | B_FOLLOW_TOP, 49 uint32 flags = B_WILL_DRAW | B_NAVIGABLE 50 | B_FRAME_EVENTS); 51 virtual ~DragSortableListView(); 52 53 // BListView interface 54 virtual void AttachedToWindow(); 55 virtual void DetachedFromWindow(); 56 virtual void FrameResized(float width, float height); 57 virtual void Draw(BRect updateRect); 58 virtual void ScrollTo(BPoint where); 59 virtual void TargetedByScrollView(BScrollView* scrollView); 60 virtual bool InitiateDrag(BPoint point, int32 index, 61 bool wasSelected); 62 virtual void MessageReceived(BMessage* message); 63 virtual void KeyDown(const char* bytes, int32 numBytes); 64 virtual void MouseDown(BPoint where); 65 virtual void MouseMoved(BPoint where, uint32 transit, 66 const BMessage* dragMessage); 67 virtual void MouseUp(BPoint where); 68 virtual void WindowActivated(bool active); 69 virtual void DrawItem(BListItem *item, BRect itemFrame, 70 bool complete = false); 71 72 // DragSortableListView 73 virtual void SetDragCommand(uint32 command); 74 virtual void ModifiersChanged(); // called by window 75 virtual void DoubleClicked(int32 index) {} 76 77 virtual void SetItemFocused(int32 index); 78 79 virtual bool AcceptDragMessage(const BMessage* message) const; 80 virtual void SetDropTargetRect(const BMessage* message, 81 BPoint where); 82 83 // autoscrolling 84 void SetAutoScrolling(bool enable); 85 bool DoesAutoScrolling() const; 86 BScrollView* ScrollView() const 87 { return fScrollView; } 88 void ScrollTo(int32 index); 89 90 bool MouseWheelChanged(float x, float y); 91 92 virtual void MoveItems(BList& indices, int32 toIndex); 93 virtual void CopyItems(BList& indices, int32 toIndex); 94 virtual void RemoveItemList(BList& indices); 95 void RemoveSelected(); // uses RemoveItemList() 96 int32 CountSelectedItems() const; 97 void SelectAll(); 98 virtual bool DeleteItem(int32 index); 99 100 virtual BListItem* CloneItem(int32 atIndex) const = 0; 101 virtual void DrawListItem(BView* owner, int32 index, 102 BRect itemFrame) const = 0; 103 virtual void MakeDragMessage(BMessage* message) const = 0; 104 105 private: 106 void _RemoveDropAnticipationRect(); 107 void _SetDragMessage(const BMessage* message); 108 109 BRect fDropRect; 110 BMessage fDragMessageCopy; 111 BMessageRunner* fScrollPulse; 112 BPoint fLastMousePos; 113 114 protected: 115 void _SetDropAnticipationRect(BRect r); 116 void _SetDropIndex(int32 index); 117 118 int32 fDropIndex; 119 BListItem* fLastClickedItem; 120 BScrollView* fScrollView; 121 uint32 fDragCommand; 122 int32 fFocusedIndex; 123 }; 124 125 // SimpleListView 126 class SimpleListView : public DragSortableListView { 127 public: 128 SimpleListView(BRect frame, 129 BMessage* selectionChangeMessage = NULL); 130 SimpleListView(BRect frame, const char* name, 131 BMessage* selectionChangeMessage = NULL, 132 list_view_type type = B_MULTIPLE_SELECTION_LIST, 133 uint32 resizingMode = B_FOLLOW_ALL_SIDES, 134 uint32 flags = B_WILL_DRAW | B_NAVIGABLE 135 | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE); 136 ~SimpleListView(); 137 138 // DragSortableListView interface 139 virtual void MessageReceived(BMessage* message); 140 virtual void SelectionChanged(); 141 142 virtual BListItem* CloneItem(int32 atIndex) const; 143 virtual void DrawListItem(BView* owner, int32 index, 144 BRect itemFrame) const; 145 virtual void MakeDragMessage(BMessage* message) const; 146 147 private: 148 149 BMessage* fSelectionChangeMessage; 150 }; 151 152 #endif // LIST_VIEWS_H 153