From f0eab45bd7b122505da1707e3ec834b2b36308ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 5 May 2012 16:24:33 +0200 Subject: [PATCH] Made it easier for derived classes to handle the drop message. --- .../icon-o-matic/generic/gui/ListViews.cpp | 52 ++++++++++++------- src/apps/icon-o-matic/generic/gui/ListViews.h | 4 +- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/apps/icon-o-matic/generic/gui/ListViews.cpp b/src/apps/icon-o-matic/generic/gui/ListViews.cpp index bc009e4f16..afa64d2147 100644 --- a/src/apps/icon-o-matic/generic/gui/ListViews.cpp +++ b/src/apps/icon-o-matic/generic/gui/ListViews.cpp @@ -324,25 +324,11 @@ void DragSortableListView::MessageReceived(BMessage* message) { if (message->what == fDragCommand) { - DragSortableListView *list = NULL; - if (message->FindPointer("list", (void **)&list) == B_OK - && list == this) { - int32 count = CountItems(); - if (fDropIndex < 0 || fDropIndex > count) - fDropIndex = count; - BList items; - 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; - } + int32 count = CountItems(); + if (fDropIndex < 0 || fDropIndex > count) + fDropIndex = count; + HandleDropMessage(message, fDropIndex); + fDropIndex = -1; } else { switch (message->what) { 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 void DragSortableListView::SetAutoScrolling(bool enable) diff --git a/src/apps/icon-o-matic/generic/gui/ListViews.h b/src/apps/icon-o-matic/generic/gui/ListViews.h index f4721b8d5d..c8c33028aa 100644 --- a/src/apps/icon-o-matic/generic/gui/ListViews.h +++ b/src/apps/icon-o-matic/generic/gui/ListViews.h @@ -111,8 +111,10 @@ class DragSortableListView : public MouseWheelTarget, 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); + BPoint where); // autoscrolling void SetAutoScrolling(bool enable);