87 elems = new ReadOnlyCollection<IGPALAutomationElement>(tmpElems);
88 return elems;
89 }
90 public static List<mUIA::System.Windows.Automation.AutomationElement> GetAllChildren(mUIA::System.Windows.Automation.AutomationElement rootElement, int idx, mUIAtypes::System.Windows.Automation.ControlType controlType)
91 {
92 mUIA::System.Windows.Automation.Condition condition = new mUIA::System.Windows.Automation.PropertyCondition(mUIA::System.Windows.Automation.AutomationElement.IsControlElementProperty, true);
93 mUIA::System.Windows.Automation.TreeWalker walker = new mUIA::System.Windows.Automation.TreeWalker(condition);
148 public static Rectangle GetBoundingRect(object managedAutomationElement)
149 {
150 return new Rectangle(new Point((int)((mUIA::System.Windows.Automation.AutomationElement)managedAutomationElement).Current.BoundingRectangle.Location.X, (int)((mUIA::System.Windows.Automation.AutomationElement)managedAutomationElement).Current.BoundingRectangle.Location.Y), new Size((int)((mUIA::System.Windows.Automation.AutomationElement)managedAutomationElement).Current.BoundingRectangle.Size.Width, (int)((mUIA::System.Windows.Automation.AutomationElement)managedAutomationElement).Current.BoundingRectangle.Size.Height));
156 if (true == GPAL.SimulateMouse || true == application.CurrentUOW.CurrentSelector?.SimulateMouse)
157 {
158 Rectangle rect = GetBoundingRect(managedAutomationElement);
159 HardwareHelper.MoveMouse(rect.X, rect.Y, 10, 10); // source didn't define values for rx, ry }
160 HardwareHelper.LeftClick(rect.X, rect.Y);
161 Thread.Sleep(250); // wait for display before trying to find elements
162 }
163 else
164 {
165 try
166 {
167 if (null != automationElement)
168 {
169 ExpandCollapsePattern pattern = automationElement.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;
170 pattern.Expand();
171 }
172 else
173 {
174 mUIA::System.Windows.Automation.ExpandCollapsePattern pattern = automationElement.GetCurrentPattern(mUIA::System.Windows.Automation.ExpandCollapsePattern.Pattern) as mUIA::System.Windows.Automation.ExpandCollapsePattern;
175 pattern.Expand();
176 }
177 }
178 catch (Exception ex)
179 {
180 GPAL.PublishSimpleEvent($"Unable to expand menuitem for Control [{automationElement.Current.LocalizedControlType}], trying InvokePattern.", application, GPALObjectType.Application, ex);
181 try
182 {
183 if (null != automationElement)
184 {
185 InvokePattern pattern = automationElement.GetCurrentPattern(ExpandCollapsePattern.Pattern) as InvokePattern;
186 pattern.Invoke();
187 }
188 else
189 {
190 mUIA::System.Windows.Automation.InvokePattern pattern = automationElement.GetCurrentPattern(mUIA::System.Windows.Automation.InvokePattern.Pattern) as mUIA::System.Windows.Automation.InvokePattern;
191 pattern.Invoke();
192 }
193 }
194 catch (Exception ex2)
195 {
196 GPAL.PublishSimpleEvent($"Unable to expand menuitem for Control [{automationElement.Current.LocalizedControlType}], using hardware fallback.", application, GPALObjectType.Application, ex2);
197
198 Random random = new Random(10007);
199
200 if (null != automationElement)
201 {
202 int offsetX = random.Next(1, (int)automationElement.Current.BoundingRectangle.Width - 2);
203 int offsetY = random.Next(1, (int)automationElement.Current.BoundingRectangle.Height - 2);
204 ElementHelper.HardwareClick(null, new GPALAutomationElement((System.Windows.Automation.AutomationElement)managedAutomationElement, null, automationElement), Enums.ClickType.LeftClick, Enums.ModifierKeys.None, offsetX, offsetY);
205 }
206 else
207 {
208 int offsetX = random.Next(1, (int)automationElement.Current.BoundingRectangle.Width - 2);
209 int offsetY = random.Next(1, (int)automationElement.Current.BoundingRectangle.Height - 2);
210 ElementHelper.HardwareClick(null, new GPALAutomationElement((System.Windows.Automation.AutomationElement)managedAutomationElement, null, automationElement), Enums.ClickType.LeftClick, Enums.ModifierKeys.None, offsetX, offsetY);
211 }
212 }
213 }
214 }
215 }
216 public static List<AutomationElement> GetAllChildren(AutomationElement rootElement, int idx, System.Windows.Automation.ControlType controlType)
217 {
218 mUIA::System.Windows.Automation.Condition condition = new mUIA::System.Windows.Automation.PropertyCondition(mUIA::System.Windows.Automation.AutomationElement.IsControlElementProperty, true);
219 mUIA::System.Windows.Automation.TreeWalker walker = new mUIA::System.Windows.Automation.TreeWalker(condition);