Exemple #1
0
        // OnEventSystemMenuPopupStart - process an EventSystemMenuPopupStart WinEvent.
        private void OnEventSystemMenuPopupStart(int eventId, IntPtr hwnd, int idObject, int idChild, uint eventTime)
        {
            Accessible acc = Accessible.Create(hwnd, idObject, idChild);

            if (acc == null)
            {
                return;
            }

            HandleFocusChange(hwnd, acc, idObject, idChild, eventTime);
        }
Exemple #2
0
        // OnEventObjectFocus - process an EventObjectFocus WinEvent.
        private void OnEventObjectFocus(int eventId, IntPtr hwnd, int idObject, int idChild, uint eventTime)
        {
            Accessible acc = Accessible.Create(hwnd, idObject, idChild);

            if (acc == null)
            {
                return;
            }

            // Keep track of last focused non-menu item, so we can restore focus when we leave menu mode
            if (!_fInMenu)
            {
                _accLastBeforeMenu  = acc;
                _hwndLastBeforeMenu = hwnd;
                _idLastObject       = idObject;
                _idLastChild        = idChild;
            }

            HandleFocusChange(hwnd, acc, idObject, idChild, eventTime);
        }
Exemple #3
0
        // OnEventSystemCaptureEnd - process an EventSystemCaptureEnd WinEvent.
        private void OnEventSystemCaptureEnd(int eventId, IntPtr hwnd, int idObject, int idChild, uint eventTime)
        {
            // Deal only with Combolbox dropdowns...
            if (Accessible.IsComboDropdown(hwnd))
            {
                SafeNativeMethods.GUITHREADINFO guiThreadInfo = new SafeNativeMethods.GUITHREADINFO();

                if (!Misc.GetGUIThreadInfo(0, ref guiThreadInfo))
                {
                    return;
                }

                Accessible acc = Accessible.Create(guiThreadInfo.hwndFocus, UnsafeNativeMethods.OBJID_CLIENT, 0);
                if (acc == null)
                {
                    return;
                }

                HandleFocusChange(hwnd, acc, idObject, idChild, eventTime);
            }
        }
Exemple #4
0
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------
 
        #region Private Methods

        // HandleFocusChange - Called when a WinEvent we're listening to indicates the
        // focus has changed.  This is where the callback to the client is queued.
        private void HandleFocusChange(IntPtr hwnd, Accessible acc, int idObject, int idChild, uint eventTime)
        {
            // If there is an hwnd then notify of a focus change
            if (hwnd != IntPtr.Zero)
            {
                Debug.Assert(acc != null, "HandleFocusChange got hwnd and null IAccessible");

                // Create an event args and get the source logical element
                AutomationFocusChangedEventArgs e = new InternalAutomationFocusChangedEventArgs(idObject, idChild, eventTime);
                AutomationElement srcEl = GetFocusedElementFromWinEvent(hwnd, idObject, idChild);
                if (srcEl == null)
                {
                    // Don't raise focus change events for UI that is gone.  This has been seen when toolbar menus are
                    // being manipulated (e.g. mnu.SubMenu("File").MenuItems("Close").Click() in MITA).  We should be
                    // seeing another focus change soon and with that event we can re-establish focus. 
                    return;
                }

                // Check that item is actually focused
                // Don't do this for statics - the controls in the color picker are statics, and
                // they get focus, but OLEACC assumes statics don't get focus, so never sets the
                // focus bit. So, for now, assume statics that send focus do actually have focus.
                if (!Accessible.IsStatic(hwnd) && !Accessible.IsComboDropdown(hwnd))
                {
                    // instead of depending on oleacc to see if something has focus ask provider
                    if (!(bool)srcEl.GetCurrentPropertyValue(AutomationElement.HasKeyboardFocusProperty))
                    {
                        return;
                    }
                }
                
                // Do notifies
                ClientEventManager.RaiseEventInThisClientOnly(AutomationElement.AutomationFocusChangedEvent, srcEl, e);
            }

            // Keep track of where we are right now (may be unknown/null)
            _accCurrent = acc;
        }
Exemple #5
0
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        // HandleFocusChange - Called when a WinEvent we're listening to indicates the
        // focus has changed.  This is where the callback to the client is queued.
        private void HandleFocusChange(IntPtr hwnd, Accessible acc, int idObject, int idChild, uint eventTime)
        {
            // If there is an hwnd then notify of a focus change
            if (hwnd != IntPtr.Zero)
            {
                Debug.Assert(acc != null, "HandleFocusChange got hwnd and null IAccessible");

                // Create an event args and get the source logical element
                AutomationFocusChangedEventArgs e = new InternalAutomationFocusChangedEventArgs(idObject, idChild, eventTime);
                AutomationElement srcEl           = GetFocusedElementFromWinEvent(hwnd, idObject, idChild);
                if (srcEl == null)
                {
                    // Don't raise focus change events for UI that is gone.  This has been seen when toolbar menus are
                    // being manipulated (e.g. mnu.SubMenu("File").MenuItems("Close").Click() in MITA).  We should be
                    // seeing another focus change soon and with that event we can re-establish focus.
                    return;
                }

                // Check that item is actually focused
                // Don't do this for statics - the controls in the color picker are statics, and
                // they get focus, but OLEACC assumes statics don't get focus, so never sets the
                // focus bit. So, for now, assume statics that send focus do actually have focus.
                if (!Accessible.IsStatic(hwnd) && !Accessible.IsComboDropdown(hwnd))
                {
                    // instead of depending on oleacc to see if something has focus ask provider
                    if (!(bool)srcEl.GetCurrentPropertyValue(AutomationElement.HasKeyboardFocusProperty))
                    {
                        return;
                    }
                }

                // Do notifies
                ClientEventManager.RaiseEventInThisClientOnly(AutomationElement.AutomationFocusChangedEvent, srcEl, e);
            }

            // Keep track of where we are right now (may be unknown/null)
            _accCurrent = acc;
        }
Exemple #6
0
        // OnEventSystemCaptureStart - process an EventSystemCaptureStart WinEvent.
        private void OnEventSystemCaptureStart(int eventId, IntPtr hwnd, int idObject, int idChild, uint eventTime)
        {
            // Deal only with Combolbox dropdowns...
            if (Accessible.IsComboDropdown(hwnd))
            {
                // Need to get id of focused item...
                try
                {
                    IntPtr     i   = Misc.SendMessageTimeout(NativeMethods.HWND.Cast(hwnd), UnsafeNativeMethods.LB_GETCURSEL, IntPtr.Zero, IntPtr.Zero);
                    Accessible acc = Accessible.Create(hwnd, UnsafeNativeMethods.OBJID_CLIENT, i.ToInt32() + 1);
                    if (acc == null)
                    {
                        return;
                    }

                    HandleFocusChange(hwnd, acc, idObject, idChild, eventTime);
                }
                catch (TimeoutException)
                {
                    // Ignore
                }
            }
        }