// _SetDropIndex void DragSortableListView::_SetDropIndex(int32 index) { if (fDropIndex != index) { fDropIndex = index; if (fDropIndex >= 0) { int32 count = CountItems(); if (fDropIndex == count) { BRect r; if (ItemAt(count - 1)) { r = ItemFrame(count - 1); r.top = r.bottom; 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.top--; r.bottom = r.top + 1.0; _SetDropAnticipationRect(r); } } } }
// 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::MouseUp *****************************************************************************/ void DragSortableListView::MouseUp( BPoint where ) { // remove drop mark _SetDropAnticipationRect( BRect( 0.0, 0.0, -1.0, -1.0 ) ); // be sure to forget drag message fDragMessageCopy.what = 0; BListView::MouseUp( where ); }
// MouseUp void DragSortableListView::MouseUp(BPoint where) { // remove drop mark _SetDropAnticipationRect(BRect(0.0, 0.0, -1.0, -1.0)); SetAutoScrolling(false); // be sure to forget drag message _SetDragMessage(NULL); BListView::MouseUp(where); BCursor cursor(B_HAND_CURSOR); 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; } }
// _RemoveDropAnticipationRect void DragSortableListView::_RemoveDropAnticipationRect() { _SetDropAnticipationRect(BRect(0.0, 0.0, -1.0, -1.0)); // _SetDropIndex(-1); }