Esempio n. 1
0
        /// <summary>
        /// Server uses this to return an element in response to WM_GETOBJECT.
        /// </summary>
        /// <param name="hwnd">hwnd from the WM_GETOBJECT message</param>
        /// <param name="wParam">wParam from the WM_GETOBJECT message</param>
        /// <param name="lParam">lParam from the WM_GETOBJECT message</param>
        /// <param name="el">element to return</param>
        /// <returns>Server should return the return value as the lresult return value to the WM_GETOBJECT windows message</returns>
        public static IntPtr ReturnRawElementProvider(IntPtr hwnd, IntPtr wParam, IntPtr lParam, IRawElementProviderSimple el)
        {
            ValidateArgument(hwnd != IntPtr.Zero, nameof(SRID.HwndMustBeNonNULL));
            ValidateArgumentNonNull(el, "el");

            return(UiaCoreProviderApi.UiaReturnRawElementProvider(hwnd, wParam, lParam, el));
        }
        /// <summary>
        /// Called to notify listeners of a pattern or custom event.  This could could be called by a server implementation or by a proxy's event
        /// translator.
        /// </summary>
        /// <param name="eventId">An AutomationEvent representing this event.</param>
        /// <param name="provider">The actual server-side element associated with this event.</param>
        /// <param name="e">Contains information about the event (may be null).</param>
        public static void RaiseAutomationEvent(AutomationEvent eventId, IRawElementProviderSimple provider, AutomationEventArgs e)
        {
            ValidateArgumentNonNull(eventId, "eventId");
            ValidateArgumentNonNull(provider, "provider");
            ValidateArgumentNonNull(e, "e");

            // PRESHARP will flag this as warning 56506/6506:Parameter 'e' to this public method must be validated: A null-dereference can occur here.
            // False positive, e is checked, see above
#pragma warning suppress 6506
            if (e.EventId == AutomationElementIdentifiers.AsyncContentLoadedEvent)
            {
                AsyncContentLoadedEventArgs asyncArgs = e as AsyncContentLoadedEventArgs;
                if (asyncArgs == null)
                {
                    ThrowInvalidArgument("e");
                }

                UiaCoreProviderApi.UiaRaiseAsyncContentLoadedEvent(provider, asyncArgs.AsyncContentLoadedState, asyncArgs.PercentComplete);
                return;
            }
            // PRESHARP will flag this as warning 56506/6506:Parameter 'e' to this public method must be validated: A null-dereference can occur here.
            // False positive, e is checked, see above
#pragma warning suppress 6506
            if (e.EventId == WindowPatternIdentifiers.WindowClosedEvent && !(e is WindowClosedEventArgs))
            {
                ThrowInvalidArgument("e");
            }

            // fire to all clients
            // PRESHARP will flag this as warning 56506/6506:Parameter 'eventId' to this public method must be validated: A null-dereference can occur here.
            // False positive, eventId is checked, see above
#pragma warning suppress 6506
            UiaCoreProviderApi.UiaRaiseAutomationEvent(provider, eventId.Id);
        }
Esempio n. 3
0
        /// <summary>
        /// Called by a server to notify the UIAccess server of a AutomationPropertyChangedEvent event.
        /// </summary>
        /// <param name="element">The actual server-side element associated with this event.</param>
        /// <param name="e">Contains information about the property that changed.</param>
        public static void RaiseAutomationPropertyChangedEvent(IRawElementProviderSimple element, AutomationPropertyChangedEventArgs e)
        {
            ValidateArgumentNonNull(element, "element");
            ValidateArgumentNonNull(e, "e");

            // PRESHARP will flag this as warning 56506/6506:Parameter 'e' to this public method must be validated: A null-dereference can occur here.
            // False positive, e is checked, see above
#pragma warning suppress 6506
            UiaCoreProviderApi.UiaRaiseAutomationPropertyChangedEvent(element, e.Property.Id, e.OldValue, e.NewValue);
        }
Esempio n. 4
0
        /// <summary>
        /// Called by a server to notify the UIAccess server of a tree change event.
        /// </summary>
        /// <param name="provider">The actual server-side element associated with this event.</param>
        /// <param name="e">Contains information about the event.</param>
        public static void RaiseStructureChangedEvent(IRawElementProviderSimple provider, StructureChangedEventArgs e)
        {
            ValidateArgumentNonNull(provider, "provider");
            ValidateArgumentNonNull(e, "e");

            // PRESHARP will flag this as warning 56506/6506:Parameter 'e' to this public method must be validated: A null-dereference can occur here.
            // False positive, e is checked, see above
#pragma warning suppress 6506
            UiaCoreProviderApi.UiaRaiseStructureChangedEvent(provider, e.StructureChangeType, e.GetRuntimeId());
        }
Esempio n. 5
0
 public static void RaiseAutomationEvent(AutomationEvent eventId, IRawElementProviderSimple provider, AutomationEventArgs e)
 {
     AutomationInteropProvider.ValidateArgumentNonNull(eventId, "eventId");
     AutomationInteropProvider.ValidateArgumentNonNull(provider, "provider");
     AutomationInteropProvider.ValidateArgumentNonNull(e, "e");
     if (e.EventId == AutomationElementIdentifiers.AsyncContentLoadedEvent)
     {
         AsyncContentLoadedEventArgs asyncContentLoadedEventArgs = e as AsyncContentLoadedEventArgs;
         if (asyncContentLoadedEventArgs == null)
         {
             AutomationInteropProvider.ThrowInvalidArgument("e");
         }
         UiaCoreProviderApi.UiaRaiseAsyncContentLoadedEvent(provider, asyncContentLoadedEventArgs.AsyncContentLoadedState, asyncContentLoadedEventArgs.PercentComplete);
         return;
     }
     if (e.EventId == WindowPatternIdentifiers.WindowClosedEvent && !(e is WindowClosedEventArgs))
     {
         AutomationInteropProvider.ThrowInvalidArgument("e");
     }
     UiaCoreProviderApi.UiaRaiseAutomationEvent(provider, eventId.Id);
 }
Esempio n. 6
0
 public static void RaiseAutomationEvent(AutomationEvent eventId, IRawElementProviderSimple provider, AutomationEventArgs e)
 {
     Utility.ValidateArgumentNonNull(eventId, "eventId");
     Utility.ValidateArgumentNonNull(provider, "provider");
     Utility.ValidateArgumentNonNull(e, "e");
     if (e.EventId == AutomationElementIdentifiers.AsyncContentLoadedEvent)
     {
         AsyncContentLoadedEventArgs args = e as AsyncContentLoadedEventArgs;
         if (args == null)
         {
             throw new ArgumentException("e");
         }
         UiaCoreProviderApi.UiaRaiseAsyncContentLoadedEvent(provider, args.AsyncContentLoadedState, args.PercentComplete);
     }
     else
     {
         if ((e.EventId == WindowPatternIdentifiers.WindowClosedEvent) && !(e is WindowClosedEventArgs))
         {
             throw new ArgumentException("e");
         }
         UiaCoreProviderApi.UiaRaiseAutomationEvent(provider, eventId.Id);
     }
 }
Esempio n. 7
0
 public static IntPtr ReturnRawElementProvider(IntPtr hwnd, IntPtr wParam, IntPtr lParam, IRawElementProviderSimple el)
 {
     Utility.ValidateArgument(hwnd != IntPtr.Zero, "HWND must not be null");
     Utility.ValidateArgumentNonNull(el, "el");
     return(UiaCoreProviderApi.UiaReturnRawElementProvider(hwnd, wParam, lParam, el));
 }
Esempio n. 8
0
 public static void RaiseStructureChangedEvent(IRawElementProviderSimple provider, StructureChangedEventArgs e)
 {
     Utility.ValidateArgumentNonNull(provider, "provider");
     Utility.ValidateArgumentNonNull(e, "e");
     UiaCoreProviderApi.UiaRaiseStructureChangedEvent(provider, (UIAutomationClient.StructureChangeType)e.StructureChangeType, e.GetRuntimeId());
 }
Esempio n. 9
0
 public static void RaiseAutomationPropertyChangedEvent(IRawElementProviderSimple element, AutomationPropertyChangedEventArgs e)
 {
     Utility.ValidateArgumentNonNull(element, "element");
     Utility.ValidateArgumentNonNull(e, "e");
     UiaCoreProviderApi.UiaRaiseAutomationPropertyChangedEvent(element, e.Property.Id, e.OldValue, e.NewValue);
 }
Esempio n. 10
0
 public static IRawElementProviderSimple HostProviderFromHandle(IntPtr hwnd)
 {
     Utility.ValidateArgument(hwnd != IntPtr.Zero, "HWND must not be null");
     return(UiaCoreProviderApi.UiaHostProviderFromHwnd(hwnd));
 }
Esempio n. 11
0
        protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            const double      wheelDelta      = 120.0;
            const long        UiaRootObjectId = -25;
            uint              timestamp       = unchecked ((uint)GetMessageTime());
            RawInputEventArgs e = null;
            var shouldTakeFocus = false;

            switch ((WindowsMessage)msg)
            {
            case WindowsMessage.WM_ACTIVATE:
            {
                var wa = (WindowActivate)(ToInt32(wParam) & 0xffff);

                switch (wa)
                {
                case WindowActivate.WA_ACTIVE:
                case WindowActivate.WA_CLICKACTIVE:
                {
                    Activated?.Invoke();
                    UpdateInputMethod(GetKeyboardLayout(0));
                    break;
                }

                case WindowActivate.WA_INACTIVE:
                {
                    Deactivated?.Invoke();
                    break;
                }
                }

                return(IntPtr.Zero);
            }

            case WindowsMessage.WM_NCCALCSIZE:
            {
                if (ToInt32(wParam) == 1 && !HasFullDecorations || _isClientAreaExtended)
                {
                    return(IntPtr.Zero);
                }

                break;
            }

            case WindowsMessage.WM_CLOSE:
            {
                bool?preventClosing = Closing?.Invoke();
                if (preventClosing == true)
                {
                    return(IntPtr.Zero);
                }

                BeforeCloseCleanup(false);

                // Used to distinguish between programmatic and regular close requests.
                _isCloseRequested = true;

                break;
            }

            case WindowsMessage.WM_DESTROY:
            {
                UiaCoreProviderApi.UiaReturnRawElementProvider(_hwnd, IntPtr.Zero, IntPtr.Zero, null);

                // We need to release IMM context and state to avoid leaks.
                if (Imm32InputMethod.Current.HWND == _hwnd)
                {
                    Imm32InputMethod.Current.ClearLanguageAndWindow();
                }

                //Window doesn't exist anymore
                _hwnd = IntPtr.Zero;
                //Remove root reference to this class, so unmanaged delegate can be collected
                s_instances.Remove(this);
                Closed?.Invoke();

                _mouseDevice.Dispose();
                _touchDevice?.Dispose();
                //Free other resources
                Dispose();
                return(IntPtr.Zero);
            }

            case WindowsMessage.WM_DPICHANGED:
            {
                var dpi            = ToInt32(wParam) & 0xffff;
                var newDisplayRect = Marshal.PtrToStructure <RECT>(lParam);
                _scaling = dpi / 96.0;
                ScalingChanged?.Invoke(_scaling);

                using (SetResizeReason(PlatformResizeReason.DpiChange))
                {
                    SetWindowPos(hWnd,
                                 IntPtr.Zero,
                                 newDisplayRect.left,
                                 newDisplayRect.top,
                                 newDisplayRect.right - newDisplayRect.left,
                                 newDisplayRect.bottom - newDisplayRect.top,
                                 SetWindowPosFlags.SWP_NOZORDER |
                                 SetWindowPosFlags.SWP_NOACTIVATE);
                }

                return(IntPtr.Zero);
            }

            case WindowsMessage.WM_KEYDOWN:
            case WindowsMessage.WM_SYSKEYDOWN:
            {
                e = new RawKeyEventArgs(
                    WindowsKeyboardDevice.Instance,
                    timestamp,
                    _owner,
                    RawKeyEventType.KeyDown,
                    KeyInterop.KeyFromVirtualKey(ToInt32(wParam), ToInt32(lParam)),
                    WindowsKeyboardDevice.Instance.Modifiers);
                break;
            }

            case WindowsMessage.WM_SYSCOMMAND:
                // Disable system handling of Alt/F10 menu keys.
                if ((SysCommands)wParam == SysCommands.SC_KEYMENU && HighWord(ToInt32(lParam)) <= 0)
                {
                    return(IntPtr.Zero);
                }
                break;

            case WindowsMessage.WM_MENUCHAR:
            {
                // mute the system beep
                return((IntPtr)((int)MenuCharParam.MNC_CLOSE << 16));
            }

            case WindowsMessage.WM_KEYUP:
            case WindowsMessage.WM_SYSKEYUP:
            {
                e = new RawKeyEventArgs(
                    WindowsKeyboardDevice.Instance,
                    timestamp,
                    _owner,
                    RawKeyEventType.KeyUp,
                    KeyInterop.KeyFromVirtualKey(ToInt32(wParam), ToInt32(lParam)),
                    WindowsKeyboardDevice.Instance.Modifiers);
                break;
            }

            case WindowsMessage.WM_CHAR:
            {
                // Ignore control chars and chars that were handled in WM_KEYDOWN.
                if (ToInt32(wParam) >= 32 && !_ignoreWmChar)
                {
                    e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp, _owner,
                                                  new string((char)ToInt32(wParam), 1));
                }

                break;
            }

            case WindowsMessage.WM_LBUTTONDOWN:
            case WindowsMessage.WM_RBUTTONDOWN:
            case WindowsMessage.WM_MBUTTONDOWN:
            case WindowsMessage.WM_XBUTTONDOWN:
            {
                shouldTakeFocus = ShouldTakeFocusOnClick;
                if (ShouldIgnoreTouchEmulatedMessage())
                {
                    break;
                }

                e = new RawPointerEventArgs(
                    _mouseDevice,
                    timestamp,
                    _owner,
                    (WindowsMessage)msg switch
                    {
                        WindowsMessage.WM_LBUTTONDOWN => RawPointerEventType.LeftButtonDown,
                        WindowsMessage.WM_RBUTTONDOWN => RawPointerEventType.RightButtonDown,
                        WindowsMessage.WM_MBUTTONDOWN => RawPointerEventType.MiddleButtonDown,
                        WindowsMessage.WM_XBUTTONDOWN =>
                        HighWord(ToInt32(wParam)) == 1 ?
                        RawPointerEventType.XButton1Down :
                        RawPointerEventType.XButton2Down
                    },
                    DipFromLParam(lParam), GetMouseModifiers(wParam));
                break;
            }
Esempio n. 12
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        /// <summary>
        /// Servers that are slotting into the HWND tree can use this to get a base implementation.
        /// </summary>
        /// <param name="hwnd">HWND that server is slotting in over</param>
        /// <returns>base raw element for specified window</returns>
        public static IRawElementProviderSimple HostProviderFromHandle(IntPtr hwnd)
        {
            ValidateArgument(hwnd != IntPtr.Zero, nameof(SRID.HwndMustBeNonNULL));
            return(UiaCoreProviderApi.UiaHostProviderFromHwnd(hwnd));
        }
Esempio n. 13
0
 public static IRawElementProviderSimple HostProviderFromHandle(IntPtr hwnd)
 {
     AutomationInteropProvider.ValidateArgument(hwnd != IntPtr.Zero, "HwndMustBeNonNULL");
     return(UiaCoreProviderApi.UiaHostProviderFromHwnd(hwnd));
 }
Esempio n. 14
0
 public static void RaiseStructureChangedEvent(IRawElementProviderSimple provider, StructureChangedEventArgs e)
 {
     AutomationInteropProvider.ValidateArgumentNonNull(provider, "provider");
     AutomationInteropProvider.ValidateArgumentNonNull(e, "e");
     UiaCoreProviderApi.UiaRaiseStructureChangedEvent(provider, e.StructureChangeType, e.GetRuntimeId());
 }
Esempio n. 15
0
 public static IntPtr ReturnRawElementProvider(IntPtr hwnd, IntPtr wParam, IntPtr lParam, IRawElementProviderSimple el)
 {
     AutomationInteropProvider.ValidateArgument(hwnd != IntPtr.Zero, "HwndMustBeNonNULL");
     AutomationInteropProvider.ValidateArgumentNonNull(el, "el");
     return(UiaCoreProviderApi.UiaReturnRawElementProvider(hwnd, wParam, lParam, el));
 }