Made it easier for derived classes to handle the drop message.
This commit is contained in:
@@ -324,25 +324,11 @@ void
|
|||||||
DragSortableListView::MessageReceived(BMessage* message)
|
DragSortableListView::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
if (message->what == fDragCommand) {
|
if (message->what == fDragCommand) {
|
||||||
DragSortableListView *list = NULL;
|
|
||||||
if (message->FindPointer("list", (void **)&list) == B_OK
|
|
||||||
&& list == this) {
|
|
||||||
int32 count = CountItems();
|
int32 count = CountItems();
|
||||||
if (fDropIndex < 0 || fDropIndex > count)
|
if (fDropIndex < 0 || fDropIndex > count)
|
||||||
fDropIndex = count;
|
fDropIndex = count;
|
||||||
BList items;
|
HandleDropMessage(message, fDropIndex);
|
||||||
int32 index;
|
|
||||||
for (int32 i = 0; message->FindInt32("index", i, &index) == B_OK; i++)
|
|
||||||
if (BListItem* item = ItemAt(index))
|
|
||||||
items.AddItem((void*)item);
|
|
||||||
if (items.CountItems() > 0) {
|
|
||||||
if (modifiers() & B_SHIFT_KEY)
|
|
||||||
CopyItems(items, fDropIndex);
|
|
||||||
else
|
|
||||||
MoveItems(items, fDropIndex);
|
|
||||||
}
|
|
||||||
fDropIndex = -1;
|
fDropIndex = -1;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case MSG_TICK: {
|
case MSG_TICK: {
|
||||||
@@ -633,6 +619,34 @@ DragSortableListView::SetDropTargetRect(const BMessage* message, BPoint where)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
DragSortableListView::HandleDropMessage(const BMessage* message,
|
||||||
|
int32 dropIndex)
|
||||||
|
{
|
||||||
|
DragSortableListView *list = NULL;
|
||||||
|
if (message->FindPointer("list", (void **)&list) != B_OK || list != this)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
BList items;
|
||||||
|
int32 index;
|
||||||
|
for (int32 i = 0; message->FindInt32("index", i, &index) == B_OK; i++) {
|
||||||
|
BListItem* item = ItemAt(index);
|
||||||
|
if (item != NULL)
|
||||||
|
items.AddItem((void*)item);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (items.CountItems() == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (modifiers() & B_SHIFT_KEY)
|
||||||
|
CopyItems(items, index);
|
||||||
|
else
|
||||||
|
MoveItems(items, index);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// SetAutoScrolling
|
// SetAutoScrolling
|
||||||
void
|
void
|
||||||
DragSortableListView::SetAutoScrolling(bool enable)
|
DragSortableListView::SetAutoScrolling(bool enable)
|
||||||
|
|||||||
@@ -111,6 +111,8 @@ class DragSortableListView : public MouseWheelTarget,
|
|||||||
virtual void SetItemFocused(int32 index);
|
virtual void SetItemFocused(int32 index);
|
||||||
|
|
||||||
virtual bool AcceptDragMessage(const BMessage* message) const;
|
virtual bool AcceptDragMessage(const BMessage* message) const;
|
||||||
|
virtual bool HandleDropMessage(const BMessage* message,
|
||||||
|
int32 dropIndex);
|
||||||
virtual void SetDropTargetRect(const BMessage* message,
|
virtual void SetDropTargetRect(const BMessage* message,
|
||||||
BPoint where);
|
BPoint where);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user