// SetDropTargetRect void DragSortableListView::SetDropTargetRect(const BMessage* message, BPoint where) { if (AcceptDragMessage(message)) { bool copy = modifiers() & B_SHIFT_KEY; bool replaceAll = !message->HasPointer("list") && !copy; BRect r = Bounds(); if (replaceAll) { r.bottom--; // compensate for scrollbar offset _SetDropAnticipationRect(r); fDropIndex = -1; } else { // offset where by half of item height r = ItemFrame(0); where.y += r.Height() / 2.0; int32 index = IndexOf(where); if (index < 0) index = CountItems(); _SetDropIndex(index); const uchar* cursorData = copy ? kCopyCursor : B_HAND_CURSOR; BCursor cursor(cursorData); SetViewCursor(&cursor, true); } } }
/***************************************************************************** * DragSortableListView::MouseMoved *****************************************************************************/ void DragSortableListView::MouseMoved(BPoint where, uint32 transit, const BMessage *msg) { if ( msg && ( msg->what == B_SIMPLE_DATA || msg->what == MSG_SOUNDPLAY ) ) { bool replaceAll = !msg->HasPointer("list") && !(modifiers() & B_SHIFT_KEY); switch ( transit ) { case B_ENTERED_VIEW: // remember drag message // this is needed to react on modifier changes fDragMessageCopy = *msg; case B_INSIDE_VIEW: { if ( replaceAll ) { BRect r( Bounds() ); r.bottom--; // compensate for scrollbar offset _SetDropAnticipationRect( r ); fDropIndex = -1; } else { // offset where by half of item height BRect r( ItemFrame( 0 ) ); where.y += r.Height() / 2.0; int32 index = IndexOf( where ); if ( index < 0 ) index = CountItems(); _SetDropIndex( index ); } break; } case B_EXITED_VIEW: // forget drag message fDragMessageCopy.what = 0; case B_OUTSIDE_VIEW: _RemoveDropAnticipationRect(); break; } } else { _RemoveDropAnticipationRect(); BListView::MouseMoved(where, transit, msg); fDragMessageCopy.what = 0; } }
/***************************************************************************** * DragSortableListView::_RemoveDropAnticipationRect *****************************************************************************/ void DragSortableListView::_RemoveDropAnticipationRect() { _SetDropAnticipationRect( BRect( 0.0, 0.0, -1.0, -1.0 ) ); _SetDropIndex( -1 ); }