void BListView::_Track(BPoint where, uint32) { if (fTrack->item_index >= 0 && fTrack->try_drag) { // initiate a drag if the mouse was moved far enough BPoint offset = where - fTrack->drag_start; float dragDistance = sqrtf(offset.x * offset.x + offset.y * offset.y); if (dragDistance >= 5.0f) { fTrack->try_drag = false; fTrack->is_dragging = InitiateDrag(fTrack->drag_start, fTrack->item_index, fTrack->was_selected); } } if (!fTrack->is_dragging) { // do selection only if a drag was not initiated int32 index = IndexOf(where); BListItem* item = ItemAt(index); if (item != NULL && !item->IsSelected() && item->IsEnabled()) { Select(index, fListType == B_MULTIPLE_SELECTION_LIST && (modifiers() & B_SHIFT_KEY) != 0); ScrollToSelection(); } } }
void BListView::MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage) { if (fTrack->item_index == -1 || !fTrack->try_drag) { // mouse was not clicked above any item // or no mouse button pressed return; } // Initiate a drag if the mouse was moved far enough BPoint offset = where - fTrack->drag_start; float dragDistance = sqrtf(offset.x * offset.x + offset.y * offset.y); if (dragDistance >= 5.0f) { fTrack->try_drag = false; InitiateDrag(fTrack->drag_start, fTrack->item_index, fTrack->was_selected); } }
void DataView::MouseDown(BPoint where) { MakeFocus(true); BMessage *message = Looper()->CurrentMessage(); int32 buttons; if (message == NULL || message->FindInt32("buttons", &buttons) != B_OK) return; view_focus newFocus; int32 position = PositionAt(kNoFocus, where, &newFocus); if ((buttons & B_SECONDARY_MOUSE_BUTTON) != 0 && position >= fStart && position <= fEnd) { InitiateDrag(newFocus); return; } if ((buttons & B_PRIMARY_MOUSE_BUTTON) == 0) return; int32 modifiers = message->FindInt32("modifiers"); fMouseSelectionStart = position; if (fMouseSelectionStart == -1) { // "where" is outside the valid frame return; } int32 selectionEnd = fMouseSelectionStart; if (modifiers & B_SHIFT_KEY) { // enlarge the current selection if (fStart < selectionEnd) fMouseSelectionStart = fStart; else if (fEnd > selectionEnd) fMouseSelectionStart = fEnd; } SetSelection(fMouseSelectionStart, selectionEnd, newFocus); SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY | B_SUSPEND_VIEW_FOCUS | B_LOCK_WINDOW_FOCUS); }