コード例 #1
0
 private void CloseAllPopupsCore(GamePopupCloseReason closeReason)
 {
     while (_popupAnchors.Count > 0)
     {
         if (!CloseTopmostPopup(closeReason))
         {
             return;
         }
     }
 }
コード例 #2
0
        private void ClosePopupCore(IGamePopupAnchor popupAnchor, GamePopupCloseReason closeReason)
        {
            // Update the close reason (must happen before changing mouse capture)
            if (popupAnchor.LastCloseReason == GamePopupCloseReason.Unknown)
            {
                popupAnchor.LastCloseReason = closeReason;
            }

            // Get the popup host
            var popupHost = GetPopupHost(popupAnchor);

            // Update the captured popup
            if ((popupHost != null) && (Mouse.Captured == popupHost))
            {
                if (_popupAnchors.Count > 0)
                {
                    Mouse.Capture(GetPopupHost(_popupAnchors[_popupAnchors.Count - 1]), CaptureMode.SubTree);
                }
                else
                {
                    Mouse.Capture(null);
                }
            }

            if (popupAnchor.IsPopupOpen)
            {
                popupAnchor.IsPopupOpen = false;
            }

            if (popupHost != null)
            {
                popupHost.KeyDown          -= OnKeyDown;
                popupHost.LostMouseCapture -= OnLostMouseCapture;
                popupHost.PreviewKeyDown   -= OnPreviewKeyDown;

                popupHost.RemoveHandler(
                    Mouse.PreviewMouseDownOutsideCapturedElementEvent,
                    (MouseButtonEventHandler)OnClickThrough);

                popupHost.RemoveHandler(
                    Mouse.PreviewMouseUpOutsideCapturedElementEvent,
                    (MouseButtonEventHandler)OnClickThrough);
            }

            var popupAnchorElement = popupAnchor as UIElement;

            if ((popupAnchorElement != null) && (_popupAnchors.Count == 0))
            {
                popupAnchorElement.IsKeyboardFocusWithinChanged -= OnIsKeyboardFocusWithinChanged;
            }

            return;
        }
コード例 #3
0
        internal bool CloseTopmostPopup(GamePopupCloseReason closeReason)
        {
            // Quit if there are no open popups
            if (_popupAnchors.Count == 0)
            {
                return(false);
            }

            // Get the topmost popup
            var popupAnchor = _popupAnchors[0];

            _popupAnchors.RemoveAt(0);
            ClosePopupCore(popupAnchor, closeReason);

            return(true);
        }
コード例 #4
0
        internal bool ClosePopup(IGamePopupAnchor popupAnchor, GamePopupCloseReason closeReason)
        {
            // If the popup is not currently being managed, simply call the core close code on it
            if (!_popupAnchors.Contains(popupAnchor))
            {
                return(false);
            }

            while (_popupAnchors.Count > 0)
            {
                var isRootPopupAnchor   = (RootPopupAnchor == popupAnchor);
                var isTargetPopupAnchor = (TopmostPopupAnchor == popupAnchor);

                if (!CloseTopmostPopup(closeReason))
                {
                    return(false);
                }

                if (!isTargetPopupAnchor)
                {
                    continue;
                }

                // Focus the anchor if the escape key was pressed and the popup was not originally opened with the mouse
                if ((closeReason == GamePopupCloseReason.EscapeKeyPressed) &&
                    (!isRootPopupAnchor || !popupAnchor.PopupOpenedWithMouse) &&
                    popupAnchor.Focusable)
                {
                    popupAnchor.Focus();
                }

                return(true);
            }

            return(false);
        }
コード例 #5
0
 public static void CloseAllPopups(GamePopupCloseReason closeReason)
 {
     Current.CloseAllPopupsCore(closeReason);
 }