private void HandleStructureChangedEvent(object sender, UIA.StructureChangedEventArgs structureChangedEventArgs) { var basicAutomationElement = new UIA2BasicAutomationElement((UIA2Automation)Automation, (UIA.AutomationElement)sender); var senderElement = new AutomationElement(basicAutomationElement); HandleStructureChangedEvent(senderElement, (StructureChangeType)structureChangedEventArgs.StructureChangeType, structureChangedEventArgs.GetRuntimeId()); }
public void RaiseStructureChangedEvent (object provider, StructureChangedEventArgs e) { var providerSimple = provider as IRawElementProviderSimple; if (providerSimple == null) return; ClientEventManager.RaiseStructureChangedEvent (providerSimple, e); }
public void ValuesTest () { int[] fakeRuntimeId = { 0 }; StructureChangeType sct = StructureChangeType.ChildrenBulkAdded; StructureChangedEventArgs args = new StructureChangedEventArgs (sct, fakeRuntimeId); Assert.AreEqual (AutomationElementIdentifiers.StructureChangedEvent, args.EventId, "Check Event Id"); Assert.AreEqual (sct, args.StructureChangeType, "Check StructureChangeType member"); }
public override void RaiseStructureChangedEvent (object childProvider, StructureChangedEventArgs e) { /*IRawElementProviderSimple simpleChildProvider = (IRawElementProviderSimple) childProvider; //TODO: remove elements if (e.StructureChangeType == StructureChangeType.ChildrenBulkAdded) { int controlTypeId = (int) simpleChildProvider.GetPropertyValue (AutomationElementIdentifiers.ControlTypeProperty.Id); if (controlTypeId == ControlType.Button.Id) { // TODO: Consider generalizing... Button button = new Button ((IInvokeProvider) childProvider); AddOneChild (button); AddRelationship (Atk.RelationType.Embeds, button); //TODO: add to mappings } }*/ }
public override void RaiseAutomationPropertyChangedEvent (AutomationPropertyChangedEventArgs e) { if (e.Property == AutomationElementIdentifiers.ControlTypeProperty) { //We remove the current Adapter and add it again to reflect the ControlType change StructureChangedEventArgs args = new StructureChangedEventArgs (StructureChangeType.ChildRemoved, new int[] { 0 }); //TODO: Fix ? AutomationInteropProvider.RaiseStructureChangedEvent (Provider, args); args = new StructureChangedEventArgs (StructureChangeType.ChildAdded, new int[] { 0 }); //TODO: Fix ? AutomationInteropProvider.RaiseStructureChangedEvent (Provider, args); } else base.RaiseAutomationPropertyChangedEvent (e); }
private void OnStructureChanged(object sender, StructureChangedEventArgs e) { Debug.WriteLine("\n\n----------------------------\nOnStructureChanged\n-----------------------------\n" + "e.StructureChangeType = " + Enum.GetName(typeof(StructureChangeType), e.StructureChangeType) + "\ne.EventId.ProgrammaticName = " + e.EventId.ProgrammaticName + "\n\n"); if (this._node.TreeNode.TreeView == null) //if tree currentTestTypeRootNode was removed then stop listening Stop(); else { //we will refresh child nodes this._node.RefreshChildrenNodes(); //and make sure that children children nodes are populated foreach (AutomationElementTreeNode childNode in this._node.Children) { childNode.EnsureChildrenNodesPopulated(true); } } }
void UIAutomationClient.IUIAutomationStructureChangedEventHandler.HandleStructureChangedEvent(UIAutomationClient.IUIAutomationElement sender, UIAutomationClient.StructureChangeType changeType, Array runtimeId) { StructureChangedEventArgs args = new StructureChangedEventArgs( (StructureChangeType)changeType, (int[])runtimeId); this._structureChangeHandler(AutomationElement.Wrap(sender), args); }
private void OnStructureChanged(object sender, StructureChangedEventArgs e) { MessageBox.Show($"e.StructureChangeType: {e.StructureChangeType}" + L.f + $"e.EventId: {e.EventId}"); }
private void OnStructureChange(object sender, StructureChangedEventArgs e) { Console.WriteLine($"OnStructureChange {e.StructureChangeType}, {e.EventId}, {e.GetRuntimeId()}"); var automationElement = AutomationElement.FromHandle(_process.MainWindowHandle); _automationElements = automationElement.FindAll(TreeScope.Subtree, Condition.TrueCondition); }
private void EnsureStructureEventsSetUp (DCI.IApplication app, string busName) { if (!structureEventBusNames.Contains (busName)) { structureEventBusNames.Add (busName); app.StructureChanged += delegate (int hId, int evtId, string providerPath, StructureChangeType changeType) { var handler = eventHandlerManager.GetStructureEventHandlerById (hId); if (handler != null) { UiaDbusElement elem = GetOrCreateElement (busName, providerPath); AutomationElement ae = SourceManager.GetOrCreateAutomationElement (elem); var args = new StructureChangedEventArgs (changeType, elem.RuntimeId); handler (ae, args); } }; } }
// OnWindowShowOrOpen - Called by the WindowShowOrOpenTracker class when UI is shown or created private static void OnWindowShowOrOpen( IntPtr hwnd, AutomationElement rawEl ) { bool doWindowOpenedEvent = false; bool doStructureChangedEvent = false; lock ( _classLock ) { if (_listeners != null) { // if rawEl is w/in the scope of any listeners then register for events in the new UI for (int i = 0; i < _listeners.Count; i++) { EventListenerClientSide ec = (EventListenerClientSide)_listeners[i]; EventListener l = ec.EventListener; if ( l.EventId == WindowPattern.WindowOpenedEvent ) doWindowOpenedEvent = true; if ( l.EventId == AutomationElement.StructureChangedEvent ) doStructureChangedEvent = true; // Only advise UI contexts if the provider might raise that event. if (!ShouldAdviseProviders( l.EventId )) continue; // Only advise UI contexts if the element is w/in scope of the reference element if (!ec.WithinScope( rawEl )) continue; // Notify the server side UiaCoreApi.UiaEventAddWindow(ec.EventHandle, hwnd); } } } // Piggy-back on the listener for Windows hiding or closing to raise WindowClosed and StructureChanged events. if ( doWindowOpenedEvent ) { if ( HwndProxyElementProvider.IsWindowPatternWindow( NativeMethods.HWND.Cast( hwnd ) ) ) { // Go ahead and raise a client-side only WindowOpenedEvent (if anyone is listening) AutomationEventArgs e = new AutomationEventArgs( WindowPattern.WindowOpenedEvent ); RaiseEventInThisClientOnly( WindowPattern.WindowOpenedEvent, rawEl, e); } } if ( doStructureChangedEvent ) { // Filter on the control elements. Otherwise, this is extremely noisy. Consider not filtering if there is feedback. //ControlType ct = (ControlType)rawEl.GetPropertyValue( AutomationElement.ControlTypeProperty ); //if ( ct != null ) { // Last,raise an event for structure changed StructureChangedEventArgs e = new StructureChangedEventArgs( StructureChangeType.ChildAdded, rawEl.GetRuntimeId() ); RaiseEventInThisClientOnly(AutomationElement.StructureChangedEvent, rawEl, e); } } }
public override void RaiseStructureChangedEvent (object childProvider, StructureChangedEventArgs e) { // TODO }
// fire the structure change event if there is a client listening for it. private void MaybeFireStructureChangeEvent(int eventId, Hashtable eventTable, IntPtr hwnd, int idObject, int idChild) { // if the 2-nd level table contains an entry for this event and element is not the root // (the host hwnd provider takes care of structure changed events for the root.) if (eventTable.ContainsKey(AutomationElement.StructureChangedEvent) && !IsClientObject(idObject, idChild)) { // // the type of structure changed event that we will fire depends on which event we are receiving. // the type then determines the src element -- either the parent or the child -- and the runtime id // -- either the parent or the child -- for the event arguments. IRawElementProviderFragment srcElement; int[] runtimeId = null; StructureChangeType type = StructureChangeType.ChildAdded; // Actual value is assigned below; any value will do here, to init the var switch(eventId) { case NativeMethods.EVENT_OBJECT_CREATE: case NativeMethods.EVENT_OBJECT_SHOW: // src element is child. runtime id is child. srcElement = (IRawElementProviderFragment)MsaaNativeProvider.Create(hwnd, idChild, idObject); if(srcElement != null) { runtimeId = srcElement.GetRuntimeId(); type = StructureChangeType.ChildAdded; } break; //case NativeMethods.EVENT_OBJECT_DESTROY: // src element is parent. runtime id is child. // There is nothing we can do in this case. Since the object is destroyed we can't instantiate // it in order to get its runtime ID. Even if it had a non-zero child id such that we could // instantiate its parent we still couldn't determine the runtime ID of the child that was destroyed. // There's also no guarantee that an EVENT_OBJECT_DESTROY will have a corresponding EVENT_OBJECT_CREATE // and even if it did it might use a different object id so we can't cache the information either. // (Trident for example uses a cyclic counter to generate object ids so the object id can vary for // the same object from one event to the next!) case NativeMethods.EVENT_OBJECT_HIDE: // src element is parent. runtime id is child. srcElement = (IRawElementProviderFragment)MsaaNativeProvider.Create(hwnd, idChild, idObject); if(srcElement != null) { runtimeId = srcElement.GetRuntimeId(); srcElement = (IRawElementProviderFragment)srcElement.Navigate(NavigateDirection.Parent); type = StructureChangeType.ChildRemoved; } break; default: Debug.Assert(eventId == NativeMethods.EVENT_OBJECT_REORDER); // src element is parent. runtime id is parent. srcElement = (IRawElementProviderFragment)MsaaNativeProvider.Create(hwnd, idChild, idObject); if(srcElement != null) { runtimeId = srcElement.GetRuntimeId(); type = StructureChangeType.ChildrenReordered; } break; } if (srcElement != null) { // fire the event StructureChangedEventArgs eventArgs = new StructureChangedEventArgs(type, runtimeId); //Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Firing structure change event for {0}", hwnd), "NativeMsaaProxy"); AutomationInteropProvider.RaiseStructureChangedEvent(srcElement, eventArgs); } } }
public override void RaiseStructureChangedEvent (object childProvider, StructureChangedEventArgs e) { // TODO Log.Warn ("ScrollBar: RaiseStructureChangedEvent not implemented."); }
public void RaiseStructureChangedEvent (object provider, StructureChangedEventArgs e) { IRawElementProviderSimple simpleProvider = provider as IRawElementProviderSimple; if (e.StructureChangeType == StructureChangeType.ChildAdded) { if (simpleProvider == null) return; object providerHandleObj = simpleProvider.GetPropertyValue (AEIds.NativeWindowHandleProperty.Id); IntPtr providerHandle = providerHandleObj != null ? (IntPtr) providerHandleObj : IntPtr.Zero; bool isRootWindow = false; if (ControlType.Window.Id == (int) simpleProvider.GetPropertyValue (AEIds.ControlTypeProperty.Id)) { var fragmentProvider = simpleProvider as IRawElementProviderFragment; isRootWindow = fragmentProvider != null && fragmentProvider == fragmentProvider.Navigate (NavigateDirection.Parent); } ProviderElementWrapper element = new ProviderElementWrapper (simpleProvider); element.Register (SessionBus); lock (providerWrapperMapping) providerWrapperMapping [simpleProvider] = element; if (providerHandle != IntPtr.Zero) lock (pointerProviderMapping) { #if DEBUG if (pointerProviderMapping.ContainsKey (providerHandle)) { Log.Error ("Duplicate provider handle, {0}, {1}", simpleProvider.GetPropertyValue (AEIds.NameProperty.Id), simpleProvider.GetPropertyValue (AEIds.LocalizedControlTypeProperty.Id)); } #endif pointerProviderMapping [providerHandle] = simpleProvider; } if (isRootWindow) app.AddRootElement (element); //The event shall be raised after the provider is added to providerWrapperMapping app.RaiseStructureChangedEvent (simpleProvider, e); } else if (e.StructureChangeType == StructureChangeType.ChildRemoved) { //The event shall be raised before the provider is deleted from providerWrapperMapping app.RaiseStructureChangedEvent (simpleProvider, e); HandleTotalElementRemoval (simpleProvider); } else { app.RaiseStructureChangedEvent (simpleProvider, e); } }
public override void RaiseAutomationPropertyChangedEvent (AutomationPropertyChangedEventArgs e) { if (e.Property == AutomationElementIdentifiers.ControlTypeProperty) { //We remove the current Adapter and add it again to reflect the ControlType change StructureChangedEventArgs args = new StructureChangedEventArgs (StructureChangeType.ChildRemoved, new int[] { 0 }); //TODO: Fix ? AutomationInteropProvider.RaiseStructureChangedEvent (Provider, args); args = new StructureChangedEventArgs (StructureChangeType.ChildAdded, new int[] { 0 }); //TODO: Fix ? AutomationInteropProvider.RaiseStructureChangedEvent (Provider, args); } if (e.Property == TogglePatternIdentifiers.ToggleStateProperty) { //if it's a toggle, it should not be a basic Button class, but CheckBox or other throw new NotSupportedException ("Toggle events should not land here (should not be reached)"); } else base.RaiseAutomationPropertyChangedEvent (e); }
/// <summary> /// Method called if a Structure Change event is raised. /// </summary> /// <param name="sender">The AutomationElement that raised the event.</param> /// <param name="e">The event arguments including structure change type.</param> private void OnStructureChanged(object sender, StructureChangedEventArgs e) { AutomationElement element = sender as AutomationElement; if (e.StructureChangeType == StructureChangeType.ChildAdded) { int processId = element.Current.ProcessId; AutomationElement ae = AEHelper.GetGhostCastServerWindow(processId); GhostCastSession gcs = ScrapeGhostCastSession(ae); if (Alert.RegisteredEmailAlerts.Count > 0) { Alert alert = Alert.RegisteredEmailAlerts.Find(p => p.ProcessId == processId); if (alert != null && !String.IsNullOrWhiteSpace(alert.EmailAddress)) { Alert.RegisteredEmailAlerts.Remove(alert); Log.Write(String.Format("Alert Registration Removed: PID {0} Email {1} Close {2}", alert.ProcessId, alert.EmailAddress, alert.CloseOnCompletion)); Emailer.SendAlertEmail(alert.EmailAddress, gcs); if (alert.CloseOnCompletion) { CloseGhostCastSession(processId); } } } } }
/// ------------------------------------------------------------------- /// <summary> /// Method registered by AddEventHandler() as an event handler /// </summary> /// ------------------------------------------------------------------- public virtual void OnEvent(object element, StructureChangedEventArgs argument) { base.OnEvent(((AutomationElement)(element)), ((object)(argument))); }
public override void RaiseStructureChangedEvent (object provider, StructureChangedEventArgs e) { // TODO base.RaiseStructureChangedEvent (provider, e); }
public void HandleEvent(object sender, StructureChangedEventArgs e) { OnMatchingEvent((AutomationElement)sender); }
public static void RaiseStructureChangedEvent (IRawElementProviderSimple provider, StructureChangedEventArgs e) { lock (structureChangedEventEntries) foreach (var entry in structureChangedEventEntries) if (IsProviderInScope (provider, entry.Provider, entry.Scope)) { var clientElement = ClientAutomationSource.Instance.GetOrCreateElement (provider); var element = SourceManager.GetOrCreateAutomationElement (clientElement); entry.Handler (element, e); } }
public override void RaiseAutomationPropertyChangedEvent (AutomationPropertyChangedEventArgs e) { if (e.Property == AutomationElementIdentifiers.ControlTypeProperty) { //We remove the current Adapter and add it again to reflect the ControlType change StructureChangedEventArgs args = new StructureChangedEventArgs (StructureChangeType.ChildRemoved, new int[] { 0 }); //TODO: Fix ? AutomationInteropProvider.RaiseStructureChangedEvent (Provider, args); args = new StructureChangedEventArgs (StructureChangeType.ChildAdded, new int[] { 0 }); //TODO: Fix ? AutomationInteropProvider.RaiseStructureChangedEvent (Provider, args); } else if (e.Property == TogglePatternIdentifiers.ToggleStateProperty) { //if it's a toggle, it should not be a basic Button class, but CheckBox or other Log.Error ("Tree: Toggle events should not land here (should not be reached)"); } else if (e.Property == AutomationElementIdentifiers.HasKeyboardFocusProperty) { hasFocus = (bool)e.NewValue; base.RaiseAutomationPropertyChangedEvent (e); } else base.RaiseAutomationPropertyChangedEvent (e); }
public static void RaiseStructureChangedEvent (IRawElementProviderSimple provider, StructureChangedEventArgs e) { foreach (var bridge in bridges) bridge.RaiseStructureChangedEvent (provider, e); }
// OnWindowHideOrClose - Called by the WindowHideOrCloseTracker class when UI is hidden or destroyed private static void OnWindowHideOrClose( IntPtr hwnd, AutomationElement rawEl, int [] runtimeId ) { bool doWindowClosedEvent = false; bool doStructureChangedEvent = false; lock ( _classLock ) { if (_listeners != null) { // if an hwnd is hidden or closed remove event listeners for the window's provider for (int i = 0; i < _listeners.Count; i++) { EventListenerClientSide ec = (EventListenerClientSide)_listeners[i]; EventListener l = ec.EventListener; if ( l.EventId == WindowPattern.WindowClosedEvent ) doWindowClosedEvent = true; if ( l.EventId == AutomationElement.StructureChangedEvent ) doStructureChangedEvent = true; // Only advise UI contexts if the provider still exists // (but keep looking to see if need to do a WindowClosedEvent) if (rawEl == null) continue; // Only advise UI contexts if the provider might raise that event. if (!ShouldAdviseProviders(l.EventId)) continue; // Only advise UI contexts if the element is w/in scope of the reference element if (!ec.WithinScope(rawEl)) continue; // Notify the server-side that this event is no longer interesting UiaCoreApi.UiaEventRemoveWindow(ec.EventHandle, hwnd); } } } // Piggy-back on the listener for Windows hiding or closing to raise WindowClosed and StructureChanged events. // When the hwnd behind rawEl is being destroyed, it can't be determined that rawEl once had the // WindowPattern interface. Therefore raise an event for any window close. if ( doWindowClosedEvent ) { // When the hwnd is just hidden, rawEl will not be null, so can test if this would support WindowPattern // and throw this event away if the window doesn't support that CP if ( rawEl != null && !HwndProxyElementProvider.IsWindowPatternWindow( NativeMethods.HWND.Cast( hwnd ) ) ) return; // Go ahead and raise a client-side only WindowClosedEvent (if anyone is listening) WindowClosedEventArgs e = new WindowClosedEventArgs( runtimeId ); RaiseEventInThisClientOnly(WindowPattern.WindowClosedEvent, runtimeId, e); } if ( doStructureChangedEvent ) { // Raise an event for structure changed. This element has essentially gone away so there isn't an // opportunity to do filtering here. So, just like WindowClosed, this event will be very noisy. StructureChangedEventArgs e = new StructureChangedEventArgs( StructureChangeType.ChildRemoved, runtimeId ); RaiseEventInThisClientOnly(AutomationElement.StructureChangedEvent, runtimeId, e); } }
// Invalidate LV tree structure static internal void RaiseLogicalChangedEvent (IntPtr hwnd) { // remove groupmanager from collection _groupsCollection.Remove (hwnd); // Raise logical structure changed event IRawElementProviderFragment wlv = (IRawElementProviderFragment) new WindowsListView (hwnd, null, -1); // Note we're using MakeRuntimeId() vs IRawElementProviderFragment.GetRuntimeId(). GetRuntimeId // only returns the part of the RuntimeId for the subtree this provider is handling. When returning // RuntimeId for an event the entire RuntimeId is required so use MakeRuntimeId(). StructureChangedEventArgs change = new StructureChangedEventArgs( StructureChangeType.ChildrenInvalidated, ( (WindowsListView)wlv ).MakeRuntimeId() ); AutomationInteropProvider.RaiseStructureChangedEvent(wlv, change); }
protected void OnUIStructureChangedEvent(object src, StructureChangedEventArgs e) { if (!checkNotNull(src, e)) return; // StructureChangeType if ((e.StructureChangeType == StructureChangeType.ChildAdded && this.Child.ChildAdded) || (e.StructureChangeType == StructureChangeType.ChildRemoved && this.Child.ChildRemoved) || (e.StructureChangeType == StructureChangeType.ChildrenBulkAdded && this.Child.ChildrenBulkAdded) || (e.StructureChangeType == StructureChangeType.ChildrenBulkRemoved && this.Child.ChildrenBulkRemoved) || (e.StructureChangeType == StructureChangeType.ChildrenInvalidated && this.Child.ChildrenInvalidated) || (e.StructureChangeType == StructureChangeType.ChildrenReordered && this.Child.ChildrenReordered)) { RunEventScriptBlocks(this); } try { WriteVerbose(this, e.EventId + " on " + (src as AutomationElement) + " fired"); } catch { } }
public override void RaiseStructureChangedEvent (object provider, StructureChangedEventArgs e) { }
// StructureChanged events are handled entirely in // AutomationBridge.cs, so this currently is unused. public abstract void RaiseStructureChangedEvent (object provider, StructureChangedEventArgs e);
/// -------------------------------------------------------------------- /// <summary> /// Listens for a structure changed event in the target. /// </summary> /// <param name="sender">The object that raised the event.</param> /// <param name="e">Event arguments.</param> /// <remarks> /// Since the events are happening on a different thread than the /// client we need to use a Dispatcher delegate to handle them. /// </remarks> /// -------------------------------------------------------------------- private void ChildElementsAdded(object sender, StructureChangedEventArgs e) { _clientWindow.Dispatcher.BeginInvoke( DispatcherPriority.Background, new DispatcherOperationCallback(NotifyChildElementsAdded), null); }
// TODO: This should be exposed as an event and popup resize should be elsewhere private void PopupListStructureChangedHandler(object sender, StructureChangedEventArgs e) { _syncContext.Post(delegate { Debug.WriteLine(">>> PopupList structure changed - " + e.StructureChangeType.ToString()); // CONSIDER: Others too? if (e.StructureChangeType == StructureChangeType.ChildAdded) { var functionList = sender as AutomationElement; var listRect = (Rect)functionList.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty); var listElement = functionList.FindFirst(TreeScope.Children, Condition.TrueCondition); if (listElement != null) { _popupListList = listElement; // TODO: Move this code! TestMoveWindow(_popupListList, (int)listRect.X, (int)listRect.Y); TestMoveWindow(functionList, 0, 0); var selPat = listElement.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern; Automation.AddAutomationEventHandler( SelectionItemPattern.ElementSelectedEvent, listElement, TreeScope.Children, PopupListElementSelectedHandler); // Update the current selection, if any var curSel = selPat.Current.GetSelection(); if (curSel.Length > 0) { try { UpdateSelectedItem(curSel[0]); } catch (Exception ex) { Debug.Print("Error during UpdateSelected! " + ex); } } } else { Debug.WriteLine("ERROR!!! Structure changed but no children anymore."); } } else if (e.StructureChangeType == StructureChangeType.ChildRemoved) { if (_popupListList != null) { Automation.RemoveAutomationEventHandler(SelectionItemPattern.ElementSelectedEvent, _popupListList, PopupListElementSelectedHandler); _popupListList = null; } SelectedItemText = String.Empty; SelectedItemBounds = Rect.Empty; SelectedItemChanged(this, EventArgs.Empty); } }, null); }
internal static void RaiseStructureChangedEvent (IElement element, StructureChangeType type) { StructureChangedEventArgs e; int [] runtimeId = (element != null ? element.RuntimeId : new int [0]); e = new StructureChangedEventArgs (type, runtimeId); foreach (StructureChangedEventHandlerData handler in structureEventHandlers) { if (IsElementInScope (element, handler.Element, handler.Scope)) { handler.EventHandler (SourceManager.GetOrCreateAutomationElement (element), e); break; } } }