Exemple #1
0
 private static void HandleStructureChangedEventWindow(ProxySimple el, IntPtr hwnd, int eventId)
 {
     if (eventId == NativeMethods.EventObjectReorder)
     {
         AutomationInteropProvider.RaiseStructureChangedEvent(el, new StructureChangedEventArgs(StructureChangeType.ChildrenReordered, el.MakeRuntimeId()));
     }
 }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
 private static void RaisePropertyChangedEvent(ProxySimple el, AutomationProperty property, object propertyValue)
 {
     if (propertyValue != null && propertyValue != AutomationElement.NotSupported)
     {
         AutomationInteropProvider.RaiseAutomationPropertyChangedEvent(el, new AutomationPropertyChangedEventArgs(property, null, propertyValue));
     }
 }
Exemple #4
0
        /// <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);
        }
Exemple #5
0
        internal static void RaiseStructureChangedEvent(StructureChangeType type,
                                                        IRawElementProviderFragment provider)
        {
            if (AutomationInteropProvider.ClientsAreListening)
            {
                int [] runtimeId = null;
                if (type == StructureChangeType.ChildRemoved)
                {
                    if (provider.FragmentRoot == null)                     //FIXME: How to fix it?
                    {
                        runtimeId = provider.GetRuntimeId();
                    }
                    else
                    {
                        runtimeId = provider.FragmentRoot.GetRuntimeId();
                    }
                }
                else if (type == StructureChangeType.ChildrenBulkAdded ||
                         type == StructureChangeType.ChildrenBulkRemoved)
                {
                    runtimeId = new int[] { 0 }
                }
                ;
                else
                {
                    runtimeId = provider.GetRuntimeId();
                }

                var invalidatedArgs = new StructureChangedEventArgs(type, runtimeId);
                AutomationInteropProvider.RaiseStructureChangedEvent(provider, invalidatedArgs);
            }
        }
Exemple #6
0
        protected override void WndProc(ref Message winMessage)
        {
            const int WM_GETOBJECT = 0x003D;

            if (winMessage.Msg == WM_GETOBJECT)
            {
                if (!AutomationIsActive)
                {
                    // If no provider has been created, then create one.
                    myListProvider = new ListProvider(this);

                    // Create providers for each existing item in the list.
                    foreach (CustomListItem listItem in itemsArray)
                    {
                        listItem.Provider = new ListItemProvider(myListProvider, listItem);
                    }
                }

                winMessage.Result =
                    AutomationInteropProvider.ReturnRawElementProvider(
                        Handle, winMessage.WParam, winMessage.LParam, myListProvider);
                return;
            }
            base.WndProc(ref winMessage);
        }
Exemple #7
0
        //------------------------------------------------------
        //
        //  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);
            }
        }
Exemple #8
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Recursively Raise an Event for all the sub elements
        override internal void RecursiveRaiseEvents(object idProp, AutomationPropertyChangedEventArgs e)
        {
            AutomationInteropProvider.RaiseAutomationPropertyChangedEvent(this, e);
            for (ProxySimple el = GetFirstChild(); el != null; el = this.GetNextSibling(el))
            {
                el.RecursiveRaiseEvents(idProp, e);
            }
        }
 /// <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);
        }
Exemple #12
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WmGetobject)
            {
                m.Result = AutomationInteropProvider.ReturnRawElementProvider(m.HWnd, m.WParam, m.LParam, _controlProvider);
                return;
            }

            base.WndProc(ref m);
        }
Exemple #13
0
        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);
        }
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x3D /* WM_GETOBJECT */)
            {
                m.Result = AutomationInteropProvider.ReturnRawElementProvider(m.HWnd, m.WParam, m.LParam, RawElementProviderSimple);
                return;
            }

            base.WndProc(ref m);
        }
Exemple #15
0
 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));
     }
 }
Exemple #16
0
// </Snippet122>

// <Snippet123>
        /// <summary>
        /// Raises an event when the IsEnabled property on a control is changed.
        /// </summary>
        /// <param name="provider">The UI Automation provider for the control.</param>
        /// <param name="newValue">The current enabled state.</param>
        private void RaiseEnabledEvent(IRawElementProviderSimple provider, bool newValue)
        {
            if (AutomationInteropProvider.ClientsAreListening)
            {
                AutomationPropertyChangedEventArgs args =
                    new AutomationPropertyChangedEventArgs(AutomationElement.IsEnabledProperty,
                                                           !newValue, newValue);
                AutomationInteropProvider.RaiseAutomationPropertyChangedEvent(provider, args);
            }
        }
Exemple #17
0
 // <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);
     }
 }
 protected void RaiseAutomationEvent()
 {
     if (AutomationInteropProvider.ClientsAreListening == true)
     {
         AutomationEventArgs args =
             new AutomationEventArgs(Event);
         AutomationInteropProvider.RaiseAutomationEvent(Event,
                                                        Provider,
                                                        args);
     }
 }
        static void CheckProviderFromHandle(int handle, string name)
        {
            var provider =
                AutomationInteropProvider.HostProviderFromHandle(new IntPtr(handle));

            Assert.IsNotNull(provider, string.Format("{0}'s provider", name));
            Assert.AreEqual(
                provider.GetPropertyValue(AEIds.NativeWindowHandleProperty.Id),
                new IntPtr(handle),
                string.Format("{0}'s handle", name));
        }
Exemple #20
0
 protected override void WndProc(ref Message m)
 {
     // 0x3D == WM_GETOBJECT
     if ((m.Msg == 0x3D) && (m.LParam.ToInt32() == AutomationInteropProvider.RootObjectId))
     {
         m.Result = AutomationInteropProvider.ReturnRawElementProvider(
             Handle, m.WParam, m.LParam, (IRawElementProviderSimple)this);
         return;
     }
     base.WndProc(ref m);
 }
Exemple #21
0
        /// <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);
     }
 }
Exemple #23
0
        private IntPtr OnWmGetObject(IntPtr wparam, IntPtr lparam)
        {
            IntPtr         result         = IntPtr.Zero;
            AutomationPeer automationPeer = UIElementAutomationPeer.CreatePeerForElement(this);

            if (automationPeer != null)
            {
                IRawElementProviderSimple interopChild = automationPeer.GetInteropChild();
                result = AutomationInteropProvider.ReturnRawElementProvider(this.CriticalHandle, wparam, lparam, interopChild);
            }
            return(result);
        }
 /// <summary>
 /// Responds to a removal from the UI Automation tree structure
 /// by raising an event.
 /// </summary>
 /// <param name="list">
 /// The list from which the item was removed.
 /// </param>
 /// <remarks>
 /// For the runtime Id of the list, pass 0 because the provider cannot know
 /// what its actual runtime ID is.
 /// </remarks>
 public static void OnStructureChangeRemove(CustomListControl list)
 {
     if (AutomationInteropProvider.ClientsAreListening)
     {
         int[] fakeRuntimeId            = { 0 };
         StructureChangedEventArgs args =
             new StructureChangedEventArgs(StructureChangeType.ChildrenBulkRemoved,
                                           fakeRuntimeId);
         AutomationInteropProvider.RaiseStructureChangedEvent(
             (IRawElementProviderSimple)list.Provider, args);
     }
 }
Exemple #25
0
        /// <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);
            }
        }
Exemple #26
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_GETOBJECT &&
                (int)m.LParam == AutomationInteropProvider.RootObjectId)
            {
                m.Result = AutomationInteropProvider.ReturnRawElementProvider(
                    this.Handle, m.WParam, m.LParam,
                    (IRawElementProviderSimple)this);
                return;
            }

            base.WndProc(ref m);
        }
Exemple #27
0
        // 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);
                }
            }
        }
Exemple #28
0
        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));
            }
        }
Exemple #29
0
        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));
            }
        }
Exemple #30
0
        private IntPtr OnWmGetObject(IntPtr wparam, IntPtr lparam)
        {
            IntPtr result = IntPtr.Zero;

            AutomationPeer containerPeer = UIElementAutomationPeer.CreatePeerForElement(this);

            if (containerPeer != null)
            {
                // get the element proxy
                IRawElementProviderSimple el = containerPeer.GetInteropChild();
                result = AutomationInteropProvider.ReturnRawElementProvider(CriticalHandle, wparam, lparam, el);
            }
            return(result);
        }