public virtual void Attach(IMenu menu)
        {
            if (Menu != null)
            {
                throw new NotSupportedException("DefaultMenuInteractionHandler is already attached.");
            }

            Menu                  = menu;
            Menu.GotFocus        += GotFocus;
            Menu.LostFocus       += LostFocus;
            Menu.KeyDown         += KeyDown;
            Menu.PointerPressed  += PointerPressed;
            Menu.PointerReleased += PointerReleased;
            Menu.AddHandler(AccessKeyHandler.AccessKeyPressedEvent, AccessKeyPressed);
            Menu.AddHandler(Avalonia.Controls.Menu.MenuOpenedEvent, this.MenuOpened);
            Menu.AddHandler(MenuItem.PointerEnterItemEvent, PointerEnter);
            Menu.AddHandler(MenuItem.PointerLeaveItemEvent, PointerLeave);

            _root = Menu.VisualRoot;

            if (_root is InputElement inputRoot)
            {
                inputRoot.AddHandler(InputElement.PointerPressedEvent, RootPointerPressed, RoutingStrategies.Tunnel);
            }

            if (_root is WindowBase window)
            {
                window.Deactivated += WindowDeactivated;
            }

            _inputManagerSubscription = InputManager?.Process.Subscribe(RawInput);
        }
Example #2
0
        public virtual void Attach(IMenu menu)
        {
            if (Menu != null)
            {
                throw new NotSupportedException("DefaultMenuInteractionHandler is already attached.");
            }

            Menu                  = menu;
            Menu.GotFocus        += GotFocus;
            Menu.LostFocus       += LostFocus;
            Menu.KeyDown         += KeyDown;
            Menu.PointerPressed  += PointerPressed;
            Menu.PointerReleased += PointerReleased;
            Menu.AddHandler(AccessKeyHandler.AccessKeyPressedEvent, AccessKeyPressed);
            Menu.AddHandler(MenuBase.MenuOpenedEvent, MenuOpened);
            Menu.AddHandler(MenuItem.PointerEnteredItemEvent, PointerEntered);
            Menu.AddHandler(MenuItem.PointerExitedItemEvent, PointerExited);
            Menu.AddHandler(InputElement.PointerMovedEvent, PointerMoved);

            _root = Menu.VisualRoot;

            if (_root is InputElement inputRoot)
            {
                inputRoot.AddHandler(InputElement.PointerPressedEvent, RootPointerPressed, RoutingStrategies.Tunnel);
            }

            if (_root is WindowBase window)
            {
                window.Deactivated += WindowDeactivated;
            }

            if (_root is TopLevel tl && tl.PlatformImpl is ITopLevelImpl pimpl)
            {
                pimpl.LostFocus += TopLevelLostPlatformFocus;
            }

            _inputManagerSubscription = InputManager?.Process.Subscribe(RawInput);
        }