Esempio n. 1
0
        /// <summary>
        /// Selects the specified item in the combobox by clicking it
        /// </summary>
        /// <param name="item">The item to select</param>
        public void SingleClickItem(string item)
        {
            Stopwatch timer;

            // Check if its already selected
            if (SelectedItemText() == item)
            {
                GUI.Log("Ensure " + Identity.Description + " is set to " + item, LogItemType.Action);
                return;
            }

            GUI.Log("Select [" + item + "] from " + Identity.Description, LogItemType.Action);

            int itemIndex = IndexOfItem(item);

            if (itemIndex == -1)
            {
                throw GUI.ApeException("Item " + item + " does not exist in the " + Description);
            }

            if (!IsDropped())
            {
                base.SingleClickInternal(Width - 5, 5, MouseButton.Left, MouseKeyModifier.None);
            }

            GUIForm dropDownForm = new GUIForm("drop down form", new Identifier(Identifiers.Name, "frmList"));

            //TODO scroll the item into view if need be

            GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, IntPtr.Zero, dropDownForm.Handle);
            GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "ItemHeight", MemberTypes.Property);
            GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store1);
            GUI.m_APE.SendMessages(EventSet.APE);
            GUI.m_APE.WaitForMessages(EventSet.APE);
            //Get the value(s) returned MUST be done straight after the WaitForMessages call
            int itemHeight = (int)GUI.m_APE.GetValueFromMessage();

            int x = dropDownForm.Width / 2;
            int y = (itemHeight * itemIndex) + (itemHeight / 2);

            dropDownForm.SingleClickInternal(x, y, MouseButton.Left, MouseKeyModifier.None);

            timer = Stopwatch.StartNew();
            while (true)
            {
                if (SelectedItemText() == item)
                {
                    break;
                }

                if (timer.ElapsedMilliseconds > 5000)
                {
                    throw GUI.ApeException("Failed to select item " + item + " in the " + Description);
                }

                Thread.Sleep(50);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Selects the specified item in the combobox by clicking on it
        /// </summary>
        /// <param name="itemText">The item to select</param>
        /// <param name="caseSensitivity">Whether to include the case of the item in the comparison</param>
        /// <param name="checkSelected">Whether to check the item selected is the current item after selecting</param>
        public void SingleClickItem(string itemText, CaseSensitivity caseSensitivity, bool checkSelected)
        {
            Stopwatch timer;

            //Check if its already selected
            switch (caseSensitivity)
            {
            case CaseSensitivity.Sensitive:
                if (CurrentItemText() == itemText)
                {
                    GUI.Log("Ensure " + Identity.Description + " is set to " + itemText, LogItemType.Action);
                    return;
                }
                break;

            case CaseSensitivity.Insensitive:
                if (CurrentItemText().ToLower() == itemText.ToLower())
                {
                    GUI.Log("Ensure " + Identity.Description + " is set to " + itemText, LogItemType.Action);
                    return;
                }
                break;

            default:
                throw GUI.ApeException("Unsupported CaseSensitivity value: " + caseSensitivity.ToString());
            }

            GUI.Log("Select [" + itemText + "] from " + Identity.Description, LogItemType.Action);

            //Get the style
            Input.WaitForInputIdle(Identity.Handle, GUI.m_APE.TimeOut);
            string style = GetComboBoxStyle(out dynamic droppedDown);

            IntPtr listBox = IntPtr.Zero;

            NM.COMBOBOXINFO cbi = new NM.COMBOBOXINFO();
            cbi.cbSize = Marshal.SizeOf(cbi);

            Input.Block();
            try
            {
                GUIComboBox actualComboBox;
                if ((Identity.TechnologyType == "Windows ActiveX" && Identity.TypeName == "ImageCombo") || (Identity.TechnologyType == "Windows Native" && Identity.TypeName.StartsWith("ImageCombo")))
                {
                    IntPtr sendResult;
                    IntPtr messageResult;
                    sendResult = NM.SendMessageTimeout(Identity.Handle, NM.CBEM_GETCOMBOCONTROL, IntPtr.Zero, IntPtr.Zero, NM.SendMessageTimeoutFlags.SMTO_NORMAL, GUI.m_APE.TimeOut, out messageResult);
                    if (sendResult == IntPtr.Zero)
                    {
                        throw GUI.ApeException("Failed to access the " + Description);
                    }

                    if (messageResult == IntPtr.Zero)
                    {
                        throw GUI.ApeException("Failed to find the " + Description + " actual combobox");
                    }

                    actualComboBox = new GUIComboBox(this.ParentForm, Description + " actual combobox", new Identifier(Identifiers.Handle, messageResult));
                }
                else
                {
                    actualComboBox = this;
                }

                if (style == "Simple")
                {
                    //get the Simple mode listbox child window
                    NM.GetComboBoxInfo(actualComboBox.Handle, ref cbi);
                    listBox = cbi.hwndList;
                }
                else
                {
                    if (droppedDown == null)
                    {
                        Thread.Sleep(250);
                        style = GetComboBoxStyle(out droppedDown);
                        if (droppedDown == null)
                        {
                            throw GUI.ApeException("Failed to determine the dropdown state of the " + Description);
                        }
                    }

                    if (!droppedDown)
                    {
                        actualComboBox.SingleClickInternal(Width - 5, -1, MouseButton.Left, MouseKeyModifier.None);
                    }

                    //find the dropdown
                    Input.WaitForInputIdle(actualComboBox.Handle, GUI.m_APE.TimeOut);

                    NM.GetComboBoxInfo(actualComboBox.Handle, ref cbi);
                    listBox = cbi.hwndList;
                    if (listBox == IntPtr.Zero)
                    {
                        throw GUI.ApeException("Failed to find the " + Description + " dropdown");
                    }
                }

                //locate the item
                timer = Stopwatch.StartNew();
                int index;
                while (true)
                {
                    index = ItemIndex(itemText, caseSensitivity);
                    if (index != NM.CB_ERR)
                    {
                        break;
                    }

                    if (timer.ElapsedMilliseconds > GUI.m_APE.TimeOut)
                    {
                        throw GUI.ApeException("Failed to find the " + Description + " item");
                    }

                    Thread.Sleep(50);
                }

                NM.tagRect ClientRect;
                NM.GetClientRect(listBox, out ClientRect);

                //Locate the rectangle of the item
                Rectangle itemRectangle = GetItemRectangle(listBox, index);

                //scroll the item into view if needed and then locate the rectangle
                if ((itemRectangle.Height / 2) + itemRectangle.Top > ClientRect.bottom || (itemRectangle.Height / 2) + itemRectangle.Top < ClientRect.top)
                {
                    SetTopIndex(listBox, index);
                    itemRectangle = GetItemRectangle(listBox, index);
                }

                //click the item
                GUIForm comboBoxDropdown = new GUIForm(ParentForm, Description + " dropdown", new Identifier(Identifiers.Handle, listBox), new Identifier(Identifiers.TechnologyType, "Windows Native"));
                //WaitForAnimation(comboBoxDropdown.Handle, false, AnimationUtils.WaitForAnimationSource.ComboBoxDropdown);

                comboBoxDropdown.SingleClickInternal(-1, (itemRectangle.Height / 2) + itemRectangle.Top, MouseButton.Left, MouseKeyModifier.None);

                if (checkSelected)
                {
                    //wait for CurrentItemText() to == text
                    bool selected = false;
                    timer = Stopwatch.StartNew();

                    while (true)
                    {
                        switch (caseSensitivity)
                        {
                        case CaseSensitivity.Sensitive:
                            if (CurrentItemText() == itemText)
                            {
                                selected = true;
                            }
                            break;

                        case CaseSensitivity.Insensitive:
                            if (CurrentItemText().ToLower() == itemText.ToLower())
                            {
                                selected = true;
                            }
                            break;

                        default:
                            throw GUI.ApeException("Unsupported CaseSensitivity value: " + caseSensitivity.ToString());
                        }

                        if (selected)
                        {
                            break;
                        }

                        if (timer.ElapsedMilliseconds > GUI.m_APE.TimeOut)
                        {
                            throw GUI.ApeException("Failed to select the item in the " + Description);
                        }

                        Thread.Sleep(15);
                    }
                }
            }
            catch when(Input.ResetInputFilter())
            {
                // Will never be reached as ResetInputFilter always returns false
            }
            finally
            {
                Input.Unblock();
            }
        }