+/*****************************************************************************
+ * DragSortableListView::ModifiersChaned
+ *****************************************************************************/
+void
+DragSortableListView::ModifiersChanged()
+{
+ BPoint where;
+ uint32 buttons;
+ GetMouse( &where, &buttons, false );
+ uint32 transit = Bounds().Contains( where ) ? B_INSIDE_VIEW : B_OUTSIDE_VIEW;
+ MouseMoved( where, transit, &fDragMessageCopy );
+}
+
+/*****************************************************************************
+ * DragSortableListView::MoveItems
+ *****************************************************************************/
+void
+DragSortableListView::MoveItems( BList& items, int32 index )
+{
+ DeselectAll();
+ // we remove the items while we look at them, the insertion index is decreased
+ // when the items index is lower, so that we insert at the right spot after
+ // removal
+ BList removedItems;
+ int32 count = items.CountItems();
+ for ( int32 i = 0; i < count; i++ )
+ {
+ BListItem* item = (BListItem*)items.ItemAt( i );
+ int32 removeIndex = IndexOf( item );
+ if ( RemoveItem( item ) && removedItems.AddItem( (void*)item ) )
+ {
+ if ( removeIndex < index )
+ index--;
+ }
+ // else ??? -> blow up
+ }
+ for ( int32 i = 0; BListItem* item = (BListItem*)removedItems.ItemAt( i ); i++ )
+ {
+ if ( AddItem( item, index ) )
+ {
+ // after we're done, the newly inserted items will be selected
+ Select( index, true );
+ // next items will be inserted after this one
+ index++;
+ }
+ else
+ delete item;
+ }
+}
+
+/*****************************************************************************
+ * DragSortableListView::CopyItems
+ *****************************************************************************/
+void
+DragSortableListView::CopyItems( BList& items, int32 index )
+{
+ DeselectAll();
+ // by inserting the items after we copied all items first, we avoid
+ // cloning an item we already inserted and messing everything up
+ // in other words, don't touch the list before we know which items
+ // need to be cloned
+ BList clonedItems;
+ int32 count = items.CountItems();
+ for ( int32 i = 0; i < count; i++ )
+ {
+ BListItem* item = CloneItem( IndexOf( (BListItem*)items.ItemAt( i ) ) );
+ if ( item && !clonedItems.AddItem( (void*)item ) )
+ delete item;
+ }
+ for ( int32 i = 0; BListItem* item = (BListItem*)clonedItems.ItemAt( i ); i++ )
+ {
+ if ( AddItem( item, index ) )
+ {
+ // after we're done, the newly inserted items will be selected
+ Select( index, true );
+ // next items will be inserted after this one
+ index++;
+ }
+ else
+ delete item;
+ }
+}
+
+/*****************************************************************************
+ * DragSortableListView::RemoveItemList
+ *****************************************************************************/
+void
+DragSortableListView::RemoveItemList( BList& items )
+{
+ int32 count = items.CountItems();
+ for ( int32 i = 0; i < count; i++ )
+ {
+ BListItem* item = (BListItem*)items.ItemAt( i );
+ if ( RemoveItem( item ) )
+ delete item;
+ }
+}
+
+/*****************************************************************************
+ * DragSortableListView::RemoveSelected
+ *****************************************************************************/
+void
+DragSortableListView::RemoveSelected()
+{
+ BList items;
+ for ( int32 i = 0; BListItem* item = ItemAt( CurrentSelection( i ) ); i++ )
+ items.AddItem( (void*)item );
+ RemoveItemList( items );
+}
+
+/*****************************************************************************
+ * DragSortableListView::_SetDropAnticipationRect
+ *****************************************************************************/
+void
+DragSortableListView::_SetDropAnticipationRect( BRect r )
+{
+ if ( fDropRect != r )
+ {
+ if ( fDropRect.IsValid() )
+ Invalidate( fDropRect );
+ fDropRect = r;
+ if ( fDropRect.IsValid() )
+ Invalidate( fDropRect );
+ }
+}
+
+/*****************************************************************************
+ * DragSortableListView::_SetDropAnticipationRect
+ *****************************************************************************/
+void
+DragSortableListView::_SetDropIndex( int32 index )
+{
+ if ( fDropIndex != index )
+ {
+ fDropIndex = index;
+ if ( fDropIndex == -1 )
+ _SetDropAnticipationRect( BRect( 0.0, 0.0, -1.0, -1.0 ) );
+ else
+ {
+ int32 count = CountItems();
+ if ( fDropIndex == count )
+ {
+ BRect r;
+ if ( BListItem* item = ItemAt( count - 1 ) )
+ {
+ r = ItemFrame( count - 1 );
+ r.top = r.bottom + 1.0;
+ r.bottom = r.top + 1.0;
+ }
+ else
+ {
+ r = Bounds();
+ r.bottom--; // compensate for scrollbars moved slightly out of window
+ }
+ _SetDropAnticipationRect( r );
+ }
+ else
+ {
+ BRect r = ItemFrame( fDropIndex );
+ r.bottom = r.top + 1.0;
+ _SetDropAnticipationRect( r );
+ }
+ }
+ }
+}
+
+/*****************************************************************************
+ * DragSortableListView::_RemoveDropAnticipationRect
+ *****************************************************************************/
+void
+DragSortableListView::_RemoveDropAnticipationRect()
+{
+ _SetDropAnticipationRect( BRect( 0.0, 0.0, -1.0, -1.0 ) );
+ _SetDropIndex( -1 );
+}
+