private static void NativeSetSelectedIndexes(BaseProdControl control, IEnumerable <int> indexes)
 {
     foreach (int index in indexes)
     {
         ProdListBoxNative.SetSelectedIndexNative((IntPtr)control.UIAElement.Current.NativeWindowHandle, index);
     }
 }
 public static int GetSelectedIndex(IntPtr controlHandle)
 {
     try
     {
         AutomationElement   control = CommonUIAPatternHelpers.Prologue(SelectionPattern.Pattern, controlHandle);
         AutomationElement[] element = SelectionPatternHelper.GetSelection(control);
         int ret = SelectionItemPatternHelper.FindIndexByItem(control, element[0].Current.Name);
         if (ret == -1)
         {
             /* Call native function */
             ret = ProdListBoxNative.GetSelectedIndexNative(controlHandle);
         }
         LogController.ReceiveLogMessage(new LogMessage(ret.ToString(CultureInfo.InvariantCulture)));
         return(ret);
     }
     catch (InvalidOperationException err)
     {
         throw new ProdOperationException(err.Message, err);
     }
     catch (ElementNotAvailableException err)
     {
         throw new ProdOperationException(err.Message, err);
     }
     catch (ArgumentException err)
     {
         throw new ProdOperationException(err.Message, err);
     }
 }
        public static void SetSelectedItems(IntPtr controlHandle, Collection <string> items)
        {
            try
            {
                CommonUIAPatternHelpers.Prologue(SelectionPattern.Pattern, controlHandle);
                if (!CanSelectMultiple(controlHandle))
                {
                    return;
                }

                foreach (string item in items)
                {
                    AddToSelection(controlHandle, item);
                }
                List <object>       itemList = new List <object>(items);
                Collection <object> retList  = new Collection <object>(itemList);
                LogController.ReceiveLogMessage(new LogMessage("List items Selected: ", retList));
            }
            catch (InvalidOperationException)
            {
                /* Call native function */
                foreach (string item in items)
                {
                    ProdListBoxNative.AddSelectedItemNative(controlHandle, item);
                }
            }
            catch (ElementNotAvailableException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ArgumentException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
        }
        public static void DeselectItem(IntPtr controlHandle, string itemText)
        {
            try
            {
                AutomationElement control      = CommonUIAPatternHelpers.Prologue(SelectionPattern.Pattern, controlHandle);
                AutomationElement itemToSelect = SelectionItemPatternHelper.FindItemByText(control, itemText);

                StaticEvents.RegisterEvent(SelectionItemPattern.ElementRemovedFromSelectionEvent, control);
                SelectionItemPatternHelper.RemoveFromSelection(itemToSelect);

                LogController.ReceiveLogMessage(new LogMessage("List Item deselected: " + itemText));
            }
            catch (InvalidOperationException)
            {
                /* Call native function */
                ProdListBoxNative.DeSelectItemNative(controlHandle, itemText);
            }
            catch (ElementNotAvailableException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ArgumentException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
        }
        public static void AddToSelection(IntPtr controlHandle, int index)
        {
            try
            {
                AutomationElement control = CommonUIAPatternHelpers.Prologue(SelectionPattern.Pattern, controlHandle);

                StaticEvents.RegisterEvent(SelectionItemPattern.ElementAddedToSelectionEvent, control);
                SelectionItemPatternHelper.AddToSelection(control, index);

                LogController.ReceiveLogMessage(new LogMessage(control.Current.Name));
            }
            catch (InvalidOperationException)
            {
                /* Call native function */
                ProdListBoxNative.AddSelectedItemNative(controlHandle, index);
            }
            catch (ElementNotAvailableException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ArgumentException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
        }
        public static void SetSelectedItem(IntPtr controlHandle, string itemText)
        {
            try
            {
                AutomationElement control = CommonUIAPatternHelpers.Prologue(SelectionPattern.Pattern, controlHandle);
                StaticEvents.RegisterEvent(SelectionItemPattern.ElementSelectedEvent, control);

                AutomationElement indexedItem = SelectionItemPatternHelper.FindItemByText(control, itemText);
                SelectionItemPatternHelper.SelectItem(indexedItem);

                LogController.ReceiveLogMessage(new LogMessage(itemText));
            }
            catch (InvalidOperationException)
            {
                ProdListBoxNative.SelectItemNative(controlHandle, itemText);
            }
            catch (ElementNotAvailableException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ArgumentException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
        }
        public static Collection <object> GetItems(IntPtr controlHandle)
        {
            try
            {
                AutomationElement           control = CommonUIAPatternHelpers.Prologue(SelectionPattern.Pattern, controlHandle);
                AutomationElementCollection convRet = SelectionItemPatternHelper.GetListItems(control);

                Collection <object> ret = InternalUtilities.AutomationCollToObjectList(convRet);

                if (ret == null)
                {
                    ProdListBoxNative.GetItemsNative(controlHandle);
                }

                LogController.ReceiveLogMessage(new LogMessage(control.Current.Name, ret));
                return(ret);
            }
            catch (InvalidOperationException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ElementNotAvailableException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ArgumentException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
        }
        public static int GetItemCount(IntPtr controlHandle)
        {
            try
            {
                AutomationElement control = CommonUIAPatternHelpers.Prologue(SelectionPattern.Pattern, controlHandle);
                int ret = SelectionItemPatternHelper.GetListItemCount(control);

                if (ret == -1)
                {
                    if (control.Current.ControlType == ControlType.ComboBox)
                    {
                        ProdComboBoxNative.GetItemCountNative(controlHandle);
                    }
                    else
                    {
                        ProdListBoxNative.GetItemCountNative(controlHandle);
                    }
                }

                LogController.ReceiveLogMessage(new LogMessage(ret.ToString(CultureInfo.InvariantCulture)));
                return(ret);
            }
            catch (InvalidOperationException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ElementNotAvailableException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ArgumentException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
        }
        private static int NativeSelectedIndex(BaseProdControl control)
        {
            if (control.UIAElement.Current.ControlType == ControlType.ComboBox)
            {
                return(ProdComboBoxNative.GetSelectedIndexNative((IntPtr)control.UIAElement.Current.NativeWindowHandle));
            }

            return(ProdListBoxNative.GetSelectedIndexNative((IntPtr)control.UIAElement.Current.NativeWindowHandle));
        }
        /// <summary>
        /// Natives the get items.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <returns></returns>
        private static Collection <object> NativeGetItems(BaseProdControl control)
        {
            if (control.UIAElement.Current.ControlType == ControlType.ComboBox)
            {
                return(ProdComboBoxNative.GetItemsNative((IntPtr)control.UIAElement.Current.NativeWindowHandle));
            }

            return(ProdListBoxNative.GetItemsNative((IntPtr)control.UIAElement.Current.NativeWindowHandle));
        }
        private static void NativeSetSelectedItem(BaseProdControl control, string itemText)
        {
            if (control.UIAElement.Current.ControlType == ControlType.ComboBox)
            {
                ProdComboBoxNative.SelectItemNative((IntPtr)control.UIAElement.Current.NativeWindowHandle, itemText);
            }

            ProdListBoxNative.SelectItemNative((IntPtr)control.UIAElement.Current.NativeWindowHandle, itemText);
        }
        private static int NativeGetItemCount(BaseProdControl control)
        {
            if (control.UIAElement.Current.ControlType == ControlType.Tab)
            {
                return(ProdTabNative.GetTabCount((IntPtr)control.UIAElement.Current.NativeWindowHandle));
            }
            if (control.UIAElement.Current.ControlType == ControlType.ComboBox)
            {
                ProdComboBoxNative.GetItemCountNative((IntPtr)control.UIAElement.Current.NativeWindowHandle);
            }

            return(ProdListBoxNative.GetItemCountNative((IntPtr)control.UIAElement.Current.NativeWindowHandle));
        }
        public static void SetSelectedIndexes(IntPtr controlHandle, Collection <int> indexes)
        {
            if (!CanSelectMultiple(controlHandle))
            {
                return;
            }

            try
            {
                AutomationElement control = CommonUIAPatternHelpers.Prologue(SelectionPattern.Pattern, controlHandle);
                if (!CanSelectMultiple((IntPtr)control.Current.NativeWindowHandle))
                {
                    return;
                }

                foreach (int index in indexes)
                {
                    AddToSelection(controlHandle, index);
                }

                Collection <object> retList = new Collection <object> {
                    indexes
                };
                LogController.ReceiveLogMessage(new LogMessage("List items Selected: ", retList));
            }
            catch (InvalidOperationException)
            {
                /* Call native function */
                foreach (int item in indexes)
                {
                    ProdListBoxNative.AddSelectedItemNative(controlHandle, item);
                }
            }
            catch (ElementNotAvailableException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ArgumentException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
        }
        public static int SelectedItemCount(IntPtr controlHandle)
        {
            try
            {
                AutomationElement control = CommonUIAPatternHelpers.Prologue(SelectionPattern.Pattern, controlHandle);
                if (!SelectionPatternHelper.CanSelectMultiple(control))
                {
                    return(-1);
                }

                AutomationElement[] selectedItems = SelectionPatternHelper.GetSelection(control);

                if (selectedItems == null)
                {
                    if (CanSelectMultiple(controlHandle))
                    {
                        /* Call native function */
                        return(ProdListBoxNative.GetSelectedItemCountNative(controlHandle));
                    }
                }

                if (selectedItems == null)
                {
                    return(-1);
                }
                LogController.ReceiveLogMessage(new LogMessage("List selection count: " + selectedItems.Length));
                return(selectedItems.Length);
            }
            catch (InvalidOperationException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ElementNotAvailableException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ArgumentException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
        }
 private static void NativeSelectAll(BaseProdControl control)
 {
     ProdListBoxNative.SelectAll((IntPtr)control.UIAElement.Current.NativeWindowHandle);
 }
 private static void NativeRemoveFromSelection(BaseProdControl control, string itemText)
 {
     ProdListBoxNative.DeSelectItemNative((IntPtr)control.UIAElement.Current.NativeWindowHandle, itemText);
 }
 private static int NativeGetSelectedItemCount(BaseProdControl control)
 {
     return(ProdListBoxNative.GetSelectedItemCountNative((IntPtr)control.UIAElement.Current.NativeWindowHandle));
 }
 /// <summary>
 /// Gets the selected indexes using SendMessage
 /// </summary>
 /// <param name="control">The base ProdUI control</param>
 /// <returns>
 /// A List of all the indexes of currently selected list items.
 /// </returns>
 private static Collection <int> NativeGetSelectedIndexes(BaseProdControl control)
 {
     return(ProdListBoxNative.GetSelectedIndexesNative((IntPtr)control.UIAElement.Current.NativeWindowHandle));
 }
 /// <summary>
 /// Adds the list item to the current selection using SendMessage
 /// </summary>
 /// <param name="control">The base ProdUI control.</param>
 /// <param name="index">Zero based index of the item.</param>
 private static void NativeAddToSelection(BaseProdControl control, int index)
 {
     ProdListBoxNative.AddSelectedItemNative((IntPtr)control.UIAElement.Current.NativeWindowHandle, index);
 }
 private static AutomationElement NativeGetSelectedItem(BaseProdControl control)
 {
     ProdListBoxNative.GetSelectedItemNative((IntPtr)control.UIAElement.Current.NativeWindowHandle);
     //Note: This can not return an AutomationElement...
     return(control.UIAElement);
 }