//------------------------------------------------------ // // Private Methods // //------------------------------------------------------ #region Private Methods private static void OnToolTipEvents(IntPtr hwnd, int eventId, object idProp, int idObject, int idChild) { if (idObject != NativeMethods.OBJID_WINDOW) { return; } if (!IsToolTip(hwnd)) { return; } // Raise ToolTipClosedEvent on OBJECT_HIDE WinEvents. Not raising the event for EVENT_OBJECT_DESTROY // because to do this means having to change code downstream from RaiseAutomationEvent to accept a // null src. PS #1007309 (Client-side proxies that raise events end up going through server-side // code) would be a good time to fix this issue (may then be able to pass null src). Most tool tips // currently get created, then shown and hidden, and are destroyed when the app exits so the impact // here should be minimal since the ToolTip is probaby not showing when the app exits. if (eventId == NativeMethods.EVENT_OBJECT_HIDE /*|| eventId == NativeMethods.EVENT_OBJECT_DESTROY*/) { WindowsTooltip wtv = new WindowsTooltip(hwnd, null, 0); AutomationEventArgs e = new AutomationEventArgs(AutomationElement.ToolTipClosedEvent); AutomationInteropProvider.RaiseAutomationEvent(AutomationElement.ToolTipClosedEvent, wtv, e); } }
/// <summary> /// Start GLib mainloop in its own thread just before /// winforms mainloop starts, but after gtk_init () /// has been called by MWF /// </summary> static void OnPreRun(object sender, EventArgs args) { // FIXME: Change this temporary hack to pass on the PreRun event AutomationInteropProvider.RaiseAutomationEvent(null, null, null); Application.AddKeyFilter(keyFilter); }
/// <summary> /// Responds to a selection change by raising an event. /// </summary> /// <param name="listItem">The item that has been selected.</param> public static void OnSelectionChange(CustomListItem listItem) { if (AutomationInteropProvider.ClientsAreListening) { AutomationEventArgs args = new AutomationEventArgs(SelectionItemPatternIdentifiers.ElementSelectedEvent); AutomationInteropProvider.RaiseAutomationEvent(SelectionItemPatternIdentifiers.ElementSelectedEvent, listItem.Provider, args); } }
public override void Terminate() { AutomationEventArgs args = new AutomationEventArgs(AEIds.MenuClosedEvent); AutomationInteropProvider.RaiseAutomationEvent(AEIds.MenuClosedEvent, this, args); base.Terminate(); }
public override void Initialize() { base.Initialize(); AutomationEventArgs args = new AutomationEventArgs(AEIds.MenuOpenedEvent); AutomationInteropProvider.RaiseAutomationEvent(AEIds.MenuOpenedEvent, this, args); }
// <Snippet122> /// <summary> /// Raises an event when a control is invoked. /// </summary> /// <param name="provider">The UI Automation provider for the control.</param> private void RaiseInvokeEvent(IRawElementProviderSimple provider) { if (AutomationInteropProvider.ClientsAreListening) { AutomationEventArgs args = new AutomationEventArgs(InvokePatternIdentifiers.InvokedEvent); AutomationInteropProvider.RaiseAutomationEvent(InvokePatternIdentifiers.InvokedEvent, provider, args); } }
public bool PreFilterKey(KeyFilterData key) { bool alt = (key.ModifierKeys & Keys.Alt) != 0; bool control = (key.ModifierKeys & Keys.Control) != 0; bool shift = (key.ModifierKeys & Keys.Shift) != 0; System.Windows.Automation.KeyEventArgs eventArgs = new System.Windows.Automation.KeyEventArgs(key.Down, key.keycode, key.keysym, key.str, alt, control, shift); AutomationInteropProvider.RaiseAutomationEvent(AutomationElementIdentifiers.KeyEvent, null, eventArgs); return(eventArgs.SuppressKeyPress); }
private static void HandleMenuItemInvokedEvent(ProxySimple el, IntPtr hwnd, int eventId) { // Skip the check for InvokePattern because el is just a wrapper on a dead element and // GetPatternProvider will fail to return the pattern. Later, if the caller tries to // use this element most properties and methods will throw ElementNotAvailable. if (eventId == NativeMethods.EventObjectInvoke) { AutomationInteropProvider.RaiseAutomationEvent(InvokePattern.InvokedEvent, el, new AutomationEventArgs(InvokePattern.InvokedEvent)); } }
protected void RaiseAutomationEvent() { if (AutomationInteropProvider.ClientsAreListening == true) { AutomationEventArgs args = new AutomationEventArgs(Event); AutomationInteropProvider.RaiseAutomationEvent(Event, Provider, args); } }
/// <summary> /// Responds to a button click, regardless of whether it was caused by a mouse or /// keyboard click or by InvokePattern.Invoke. /// </summary> private void OnCustomButtonClicked() { // TODO Perform program actions invoked by the control. // Raise an event. if (AutomationInteropProvider.ClientsAreListening) { AutomationEventArgs args = new AutomationEventArgs(InvokePatternIdentifiers.InvokedEvent); AutomationInteropProvider.RaiseAutomationEvent(InvokePatternIdentifiers.InvokedEvent, this, args); } }
/// <summary> /// Responds to a focus change by raising an event. /// </summary> /// <param name="listItem">The item that has received focus.</param> public static void OnFocusChange(CustomListItem listItem) { if (AutomationInteropProvider.ClientsAreListening) { AutomationEventArgs args = new AutomationEventArgs( AutomationElementIdentifiers.AutomationFocusChangedEvent); AutomationInteropProvider.RaiseAutomationEvent( AutomationElementIdentifiers.AutomationFocusChangedEvent, listItem.Provider, args); } }
/// <summary> /// Responds to a button click, regardless of whether it was caused by a mouse or /// keyboard click or by InvokePattern.Invoke. /// </summary> private void RespondToClick() { buttonState = !buttonState; this.Focus(); this.Refresh(); // Raise an event. if (AutomationInteropProvider.ClientsAreListening) { AutomationEventArgs args = new AutomationEventArgs(InvokePatternIdentifiers.InvokedEvent); AutomationInteropProvider.RaiseAutomationEvent(InvokePatternIdentifiers.InvokedEvent, this, args); } }
// DON'T USE THIS SNIPPET -- PROBABLY NOT RAISING CORRECT EVENTS // <Snippet118> /// <summary> /// Selects an item in the myItems collection. /// </summary> /// <param name="index">Index of the selected item.</param> /// <remarks> /// This is a single-selection list whose current selection is stored /// internally in mySelection. /// MyListItem is the provider class for list items. /// </remarks> public void Select(int index) { if (index >= myItems.Count) { throw new ArgumentOutOfRangeException(); } else if (index < 0) { mySelection = -1; return; } else // If within range, clear the Selected property on the current item // and set it on the new item. { MyListItem newItem; MyListItem oldItem = null; // Deselect old item, if there is one; list might not be initialized. if (mySelection >= 0) { oldItem = myItems[mySelection] as MyListItem; oldItem.Selected = false; } mySelection = index; newItem = myItems[mySelection] as MyListItem; newItem.Selected = true; // Raise events that clients can receive. if (AutomationInteropProvider.ClientsAreListening) { // Generic event for selection made. AutomationEventArgs args = new AutomationEventArgs(SelectionItemPatternIdentifiers.ElementSelectedEvent); AutomationInteropProvider.RaiseAutomationEvent(SelectionItemPattern.ElementSelectedEvent, (IRawElementProviderSimple)myItems[mySelection], args); // Property-changed event for old item's Selection property. AutomationPropertyChangedEventArgs propArgs; if (oldItem != null) { propArgs = new AutomationPropertyChangedEventArgs( SelectionItemPatternIdentifiers.IsSelectedProperty, true, false); AutomationInteropProvider.RaiseAutomationPropertyChangedEvent(oldItem, propArgs); } // Property-changed event for new item's Selection property. propArgs = new AutomationPropertyChangedEventArgs( SelectionItemPatternIdentifiers.IsSelectedProperty, false, true); AutomationInteropProvider.RaiseAutomationPropertyChangedEvent(newItem, propArgs); } } }
private static void HandleWindowInvokedEvent(ProxySimple el, IntPtr hwnd, int eventId) { IInvokeProvider invoke = el.GetPatternProvider(InvokePattern.Pattern) as IInvokeProvider; if (invoke == null) { return; } if (eventId == NativeMethods.EventSystemCaptureEnd) { AutomationInteropProvider.RaiseAutomationEvent(InvokePattern.InvokedEvent, el, new AutomationEventArgs(InvokePattern.InvokedEvent)); } }
private static void HandleElementRemovedFromSelectionEvent(ProxySimple el, IntPtr hwnd, int eventId) { ISelectionItemProvider selProvider = el.GetPatternProvider(SelectionItemPattern.Pattern) as ISelectionItemProvider; if (selProvider == null) { return; } if (eventId == NativeMethods.EventObjectSelectionRemove) { AutomationInteropProvider.RaiseAutomationEvent(SelectionItemPattern.ElementRemovedFromSelectionEvent, el, new AutomationEventArgs(SelectionItemPattern.ElementRemovedFromSelectionEvent)); } }
public virtual void RaiseActiveTextPositionChangedEvent(TextPointer rangeStart, TextPointer rangeEnd) { if (EventMap.HasRegisteredEvent(AutomationEvents.ActiveTextPositionChanged)) { IRawElementProviderSimple provider = ProviderFromPeer(this); if (provider != null) { ActiveTextPositionChangedEventArgs args = new ActiveTextPositionChangedEventArgs(TextRangeFromTextPointers(rangeStart, rangeEnd)); AutomationInteropProvider.RaiseAutomationEvent( AutomationElementIdentifiers.ActiveTextPositionChangedEvent, provider, args); } } }
private static void HandleInvokedEvent(ProxySimple el, IntPtr hwnd, int eventId) { IInvokeProvider invoke = el.GetPatternProvider(InvokePattern.Pattern) as IInvokeProvider; if (invoke == null) { return; } if (eventId == NativeMethods.EventObjectInvoke || eventId == NativeMethods.EventObjectStateChange || eventId == NativeMethods.EventObjectSelection && el is ListViewItem) { AutomationInteropProvider.RaiseAutomationEvent(InvokePattern.InvokedEvent, el, new AutomationEventArgs(InvokePattern.InvokedEvent)); } }
// fire the element seleceted event if there is a client listening for it. private void MaybeFireSelectionItemEvent(AutomationEvent eventId, Hashtable eventTable, IntPtr hwnd, int idObject, int idChild) { // if the 2-nd level table contains an entry for this property if (eventTable.ContainsKey(eventId)) { // create a provider associated with this event and check whether the provider supports the selection item pattern. MsaaNativeProvider provider = (MsaaNativeProvider)MsaaNativeProvider.Create(hwnd, idChild, idObject); if (provider != null && provider.IsPatternSupported(SelectionItemPattern.Pattern)) { // fire the event AutomationEventArgs eventArgs = new AutomationEventArgs(eventId); //Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Firing {0} for {1}", eventId, hwnd), "NativeMsaaProxy"); AutomationInteropProvider.RaiseAutomationEvent(eventId, provider, eventArgs); } } }
public void Hide(Control control) { if (AutomationInteropProvider.ClientsAreListening == true) { message = GetTextFromControl(control); //TODO: We need deeper tests in Vista because MS is generating both events Helper.RaiseStructureChangedEvent(StructureChangeType.ChildRemoved, this); AutomationEventArgs eventArgs = new AutomationEventArgs(AutomationElementIdentifiers.ToolTipClosedEvent); AutomationInteropProvider.RaiseAutomationEvent(AutomationElementIdentifiers.ToolTipClosedEvent, this, eventArgs); } }
// Raise the TextSelectionChanged event, if appropriate. private void RaiseTextSelectionEvent(int eventId, object idProp, int idObject, int idChild) { // We cannot use the generic DispatchEvents mechanism to raise // the TextSelection event, since DispatchEvents() will eventually call // EventManager.HandleTextSelectionChangedEvent(), // which will use logic inappropriate for the RichTextEdit control: // namely, that wtv._document.Selection.GetSelection() returns // an ITextRange which can *change* when e.g. backspace is pressed // in the control. To reliably detect an actual change in selection, // we have to perform a specific test of the old and new selection // endpoints and raise the event ourselves if appropriate. bool raiseTextSelectionEvent = false; EnsureTextDocument(); ITextSelection textSelection = _document.Selection; if (textSelection != null) { raiseTextSelectionEvent = (_raiseEventsOldSelectionStart != textSelection.Start || _raiseEventsOldSelectionEnd != textSelection.End); _raiseEventsOldSelectionStart = textSelection.Start; _raiseEventsOldSelectionEnd = textSelection.End; } else { raiseTextSelectionEvent = (_raiseEventsOldSelectionStart != _NO_ENDPOINT || _raiseEventsOldSelectionEnd != _NO_ENDPOINT); _raiseEventsOldSelectionStart = _NO_ENDPOINT; _raiseEventsOldSelectionEnd = _NO_ENDPOINT; } if (raiseTextSelectionEvent) { AutomationInteropProvider.RaiseAutomationEvent( TextPattern.TextSelectionChangedEvent, this, new AutomationEventArgs(TextPattern.TextSelectionChangedEvent)); } }
private static void HandleTextSelectionChangedEvent(ProxySimple el, IntPtr hwnd, int eventId) { ITextProvider textProvider = el.GetPatternProvider(TextPattern.Pattern) as ITextProvider; if (textProvider == null) { return; } if (eventId == NativeMethods.EventObjectLocationChange) { // We do not want to raise the EventObjectLocationChange when it is caused by a scroll. To do this // store the previous range and compare it to the current range. The range will not change when scrolling. ITextRangeProvider[] currentRanges = textProvider.GetSelection(); ITextRangeProvider currentRange = null; if (currentRanges != null && currentRanges.Length > 0) { currentRange = currentRanges[0]; } if (hwnd == _hwndLast && currentRange != null) { if (_lastSelection != null && !currentRange.Compare(_lastSelection)) { AutomationInteropProvider.RaiseAutomationEvent(TextPattern.TextSelectionChangedEvent, el, new AutomationEventArgs(TextPattern.TextSelectionChangedEvent)); } } else { AutomationInteropProvider.RaiseAutomationEvent(TextPattern.TextSelectionChangedEvent, el, new AutomationEventArgs(TextPattern.TextSelectionChangedEvent)); } //store the current range and window handle. _hwndLast = hwnd; _lastSelection = currentRange; } else if (eventId == NativeMethods.EventObjectTextSelectionChanged) { AutomationInteropProvider.RaiseAutomationEvent( TextPattern.TextSelectionChangedEvent, el, new AutomationEventArgs(TextPattern.TextSelectionChangedEvent)); } }
internal override void AdviseEventAdded(AutomationEvent eventId, AutomationProperty[] aidProps) { base.AdviseEventAdded(eventId, aidProps); // If the framework is advising for ToolTipOpenedEvent then go ahead and raise this event now // since the WinEvent we would listen to (usually EVENT_OBJECT_SHOW) has already occurrred // (it is why Advise is being called). No other action is necessary because when this ToolTip // goes away, AdviseEventRemoved is going to be called. In other words, this proxy gets // created when the ToolTip opens and thrown away when it closes so no need to keep state // that we want to listen for more SHOWS or CREATES - there's always one for any one instance. if (eventId == AutomationElement.ToolTipOpenedEvent) { AutomationEventArgs e = new AutomationEventArgs(AutomationElement.ToolTipOpenedEvent); AutomationInteropProvider.RaiseAutomationEvent(AutomationElement.ToolTipOpenedEvent, this, e); } else if (eventId == AutomationElement.ToolTipClosedEvent) { // subscribe to ToolTip specific events, keeping track of how many times the event has been added WinEventTracker.AddToNotificationList(IntPtr.Zero, new WinEventTracker.ProxyRaiseEvents(OnToolTipEvents), _toolTipEventIds, _toolTipEventIds.Length); _listenerCount++; } }
private static void HandleInvalidatedEvent(ProxySimple el, IntPtr hwnd, int eventId) { AutomationInteropProvider.RaiseAutomationEvent(SelectionPattern.InvalidatedEvent, el, new AutomationEventArgs(SelectionPattern.InvalidatedEvent)); }
public void PerformInvoke() { ClickCount++; AutomationInteropProvider.RaiseAutomationEvent(InvokePattern.InvokedEvent, this, new AutomationEventArgs(InvokePattern.InvokedEvent)); }