예제 #1
0
 internal static void EnsureCreated()
 {
     if (_current == null)
     {
         _current = new PopupControlService();
     }
 }
예제 #2
0
        protected override void OnPreviewClick(ExecuteRoutedEventArgs e)
        {
            var popupAnchor = PopupControlService.GetParentPopupAnchor(this);

            if ((popupAnchor != null) && (popupAnchor.IsPopupOpen && !StaysOpenOnClick))
            {
                PopupControlService.CloseAllPopups(GamePopupCloseReason.ControlClick);
            }

            base.OnPreviewClick(e);
        }
예제 #3
0
        static InfoCardService()
        {
            // Register event handlers
            EventManager.RegisterClassHandler(
                typeof(UIElement),
                FindInfoCardEvent,
                new FindInfoCardEventHandler(OnFindInfoCard));

            EventManager.RegisterClassHandler(
                typeof(ContentElement),
                FindInfoCardEvent,
                new FindInfoCardEventHandler(OnFindInfoCard));

            PopupControlService.EnsureCreated();
        }
예제 #4
0
        protected override void OnLostMouseCapture(MouseEventArgs e)
        {
            base.OnLostMouseCapture(e);

            if ((e.OriginalSource == this) && (ClickMode != ClickMode.Hover) &&
                (!_flags.GetFlag(Flags.IsSpaceKeyDown)))
            {
                if ((IsKeyboardFocused) && (!IsInMainFocusScope(this)))
                {
                    var popupAnchor = PopupControlService.GetParentPopupAnchor(this);
                    if ((popupAnchor == null) ||
                        (popupAnchor == this) ||
                        !popupAnchor.IsPopupOpen ||
                        !StaysOpenOnClick)
                    {
                        GameControl.BlurFocus(this, false);
                    }
                }
                IsPressed = false;
            }
        }
예제 #5
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (ClickMode == ClickMode.Hover)
            {
                return;
            }

            if (e.Key == Key.Space)
            {
                if (((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Alt)) != ModifierKeys.Alt) &&
                    !IsMouseCaptured &&
                    (e.OriginalSource == this))
                {
                    _flags.SetFlag(Flags.IsSpaceKeyDown, true);

                    IsPressed = true;
                    CaptureMouse();

                    if (ClickMode == ClickMode.Press)
                    {
                        RaiseClickEvent(new ExecuteRoutedEventArgs(ExecuteReason.Keyboard));
                    }

                    e.Handled = true;
                }
            }
            else if ((e.Key == Key.Return) && ((bool)GetValue(KeyboardNavigation.AcceptsReturnProperty)))
            {
                if (e.OriginalSource == this)
                {
                    _flags.SetFlag(Flags.IsSpaceKeyDown, false);

                    IsPressed = false;
                    if (IsMouseCaptured)
                    {
                        ReleaseMouseCapture();
                    }

                    RaiseClickEvent(new ExecuteRoutedEventArgs(ExecuteReason.Keyboard));

                    if ((IsKeyboardFocused) && !IsInMainFocusScope(this))
                    {
                        var popupAnchor = PopupControlService.GetParentPopupAnchor(this);
                        if ((popupAnchor == null) ||
                            (popupAnchor == this) ||
                            !popupAnchor.IsPopupOpen ||
                            !StaysOpenOnClick)
                        {
                            GameControl.BlurFocus(this, false);
                        }
                    }

                    e.Handled = true;
                }
            }
            else if (_flags.GetFlag(Flags.IsSpaceKeyDown))
            {
                IsPressed = false;

                _flags.SetFlag(Flags.IsSpaceKeyDown, false);

                if (IsMouseCaptured)
                {
                    ReleaseMouseCapture();
                }
            }
        }
예제 #6
0
        protected override void UpdateCanExecute()
        {
            var commandCanExecute = Command == null || Command == ApplicationCommands.NotACommand || GameCommand.CanExecuteCommandSource(this);

            CanExecute = commandCanExecute && (!AutoDisableWhenPopupContentIsDisabled || (PopupControlService.IsPopupAnchorPopupEnabled(this)));
        }
예제 #7
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            base.OnKeyDown(e);

            if (!e.Handled)
            {
                var key = e.Key;
                if (FlowDirection == FlowDirection.RightToLeft)
                {
                    switch (key)
                    {
                    case Key.Left:
                        key = Key.Right;
                        break;

                    case Key.Right:
                        key = Key.Left;
                        break;
                    }
                }

                switch (key)
                {
                case Key.Left:
                    if (CurrentSelection != null && CurrentSelection.IsPopupOpen)
                    {
                        // Hide a child menu item's popup
                        e.Handled = true;
                        CurrentSelection.IsPopupOpen = false;
                    }
                    else
                    {
                        var popupAnchor = PopupControlService.GetParentPopupAnchor(this);
                        if (popupAnchor != null && popupAnchor.IsPopupOpen && !PopupControlService.IsTopLevel(popupAnchor))
                        {
                            // Close the parent popup
                            e.Handled = true;
                            PopupControlService.Current.ClosePopup(popupAnchor, GamePopupCloseReason.EscapeKeyPressed);
                        }
                    }
                    break;

                case Key.Right:
                    if (CurrentSelection != null && !CurrentSelection.IsPopupOpen && CurrentSelection.HasPopup)
                    {
                        // Show a child menu item's popup
                        e.Handled = true;
                        CurrentSelection.IsPopupOpen = true;

                        // Focus the first item in a child Menu
                        Dispatcher.BeginInvoke(
                            DispatcherPriority.Send,
                            (Action)
                            (() =>
                        {
                            var menu = Keyboard.FocusedElement as GameMenu;
                            if (menu != null)
                            {
                                menu.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
                            }
                        }));
                    }
                    break;
                }
            }
        }