Пример #1
0
        private GUITextBox GetTextBox()
        {
            //Get the style
            string style = GetComboBoxStyle(out dynamic droppedDown);

            if (style == "DropDownList")
            {
                throw GUI.ApeException("Style of the " + Description + " is not an editable style");
            }

            IntPtr editBox;

            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_GETEDITCONTROL, 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);
                }
                editBox = messageResult;
            }
            else
            {
                NM.COMBOBOXINFO cbi = new NM.COMBOBOXINFO();
                cbi.cbSize = Marshal.SizeOf(cbi);

                NM.GetComboBoxInfo(Identity.Handle, ref cbi);
                editBox = cbi.hwndEdit;
            }

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

            return(new GUITextBox(ParentForm, Identity.Description + " textbox", new Identifier(Identifiers.Handle, editBox), new Identifier(Identifiers.TechnologyType, "Windows Native")));
        }
Пример #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();
            }
        }