예제 #1
0
        // ------------------------------------------------------
        //
        // ISelectionProvider interface implementation
        //
        // ------------------------------------------------------

        // Returns an enumerator over the current selection.
        IRawElementProviderSimple[] ISelectionProvider.GetSelection()
        {
            int count          = Length;
            int countSelection = IsMultipleSelection() ? GetSelectionCount() : 1;

            if (count <= 0 || countSelection <= 0)
            {
                return(null);
            }

            IRawElementProviderSimple[] selection = new IRawElementProviderSimple[countSelection];

            int index = 0;

            for (int itemPos = 0; itemPos < count; itemPos++)
            {
                if (ListboxItem.IsSelected(_hwnd, itemPos))
                {
                    selection[index] = CreateListboxItem(itemPos);
                    index++;
                }
            }

            if (index == 0)
            {
                return(null);
            }

            return(selection);
        }
예제 #2
0
        // Detect if there any selections in
        // This is used by the WindowsListBoxItem class
        // returns true if any items are selected
        private bool HasSelection()
        {
            int i, count;

            for (i = 0, count = Length; i < count && !ListboxItem.IsSelected(_hwnd, i); i++)
            {
                ;
            }

            return(i < count);
        }
예제 #3
0
        // Detect if listbox has any element except skipItem selected
        // This is used by the WindowsListBoxItem class
        // returns true if any items
        private bool HasOtherSelections(int skipItem)
        {
            for (int i = 0, count = Length; i < count; i++)
            {
                if (i != skipItem && ListboxItem.IsSelected(_hwnd, i))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #4
0
        private int GetOtherSelection(int skipItem)
        {
            for (int i = 0, count = Length; i < count; i++)
            {
                if (i != skipItem && ListboxItem.IsSelected(_hwnd, i))
                {
                    // Win32 listbox items are 0 based, UIAutomation listbox items are 1 based.
                    return(i + 1);
                }
            }

            return(NativeMethods.LB_ERR);
        }
예제 #5
0
            // Adds this element to the selection
            void ISelectionItemProvider.AddToSelection()
            {
                // Check that control can be interacted with.
                // This state could change anytime
                if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
                {
                    throw new ElementNotEnabledException();
                }

                // check if item already selected
                if (ListboxItem.IsSelected(_hwnd, _item) && !_listBox.IsParentedByCombo())
                {
                    // if it is a combo, then always perform the selection otherwise the listbox won't disappear
                    return;
                }

                bool multipleSelection = _listBox.IsMultipleSelection();

                // object does not support multi-selection
                if (!multipleSelection)
                {
                    IRawElementProviderSimple container = ((ISelectionItemProvider)this).SelectionContainer;
                    bool selectionRequired = container != null ? ((ISelectionProvider)container).IsSelectionRequired : true;

                    // For single selection containers that IsSelectionRequired == false and nothing is selected
                    // an AddToSelection is valid.
                    if (selectionRequired || _listBox.HasSelection())
                    {
                        throw new InvalidOperationException(SR.Get(SRID.DoesNotSupportMultipleSelection));
                    }
                }

                if (_listBox.IsParentedByCombo())
                {
                    // if this is a combo and the listbox is not displayed the selection will not stick, so
                    // display the listbox before doing the select.
                    if (((IExpandCollapseProvider)_listBox._parent).ExpandCollapseState == ExpandCollapseState.Collapsed)
                    {
                        ((IExpandCollapseProvider)_listBox._parent).Expand();
                    }
                }

                // At this point we know: Item either supports multiple selection or nothing
                // is selected in the list
                // Try to select an item
                if (!Select(multipleSelection))
                {
                    throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
                }
            }