Exemplo n.º 1
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;
    }

    item->Select();
    if (Window() != NULL)
        InvalidateItem(index);

    return true;
}
Exemplo n.º 2
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 && !item->IsSelected()) {
			item->Select();
			if (Window())
				InvalidateItem(i);
			changed = true;
		}
	}

	return changed;
}