Exemple #1
0
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();
        }
    }
}
Exemple #2
0
/*!	Selects the item at the specified \a index, and returns \c true in
	case the selection was changed because of this method.
	If \a extend is \c false, all previously selected items are deselected.
*/
bool
BListView::_Select(int32 index, bool extend)
{
	if (index < 0 || index >= CountItems())
		return false;

	// only lock the window when there is one
	BAutolock locker(Window());
	if (Window() != NULL && !locker.IsLocked())
		return false;

	bool changed = false;

	if (!extend && fFirstSelected != -1)
		changed = _DeselectAll(index, index);

	fAnchorIndex = index;

	BListItem* item = ItemAt(index);
	if (!item->IsEnabled() || item->IsSelected()) {
		// if the item is already selected, or can't be selected,
		// we're done here
		return changed;
	}

	// keep track of first and last selected item
	if (fFirstSelected == -1) {
		// no previous selection
		fFirstSelected = index;
		fLastSelected = index;
	} else if (index < fFirstSelected) {
		fFirstSelected = index;
	} else if (index > fLastSelected) {
		fLastSelected = index;
	}

	ItemAt(index)->Select();
	if (Window())
		InvalidateItem(index);

	return true;
}
Exemple #3
0
/*!
	Selects the items between \a from and \a to, and returns \c true in
	case the selection was changed because of this method.
	If \a extend is \c false, all previously selected items are deselected.
*/
bool
BListView::_Select(int32 from, int32 to, bool extend)
{
    if (to < from)
        return false;

    BAutolock locker(Window());
    if (Window() && !locker.IsLocked())
        return false;

    bool changed = false;

    if (fFirstSelected != -1 && !extend)
        changed = _DeselectAll(from, to);

    if (fFirstSelected == -1) {
        fFirstSelected = from;
        fLastSelected = to;
    } else {
        if (from < fFirstSelected)
            fFirstSelected = from;
        if (to > fLastSelected)
            fLastSelected = to;
    }

    for (int32 i = from; i <= to; ++i) {
        BListItem* item = ItemAt(i);
        if (item != NULL && !item->IsSelected() && item->IsEnabled()) {
            item->Select();
            if (Window() != NULL)
                InvalidateItem(i);
            changed = true;
        }
    }

    return changed;
}