private void CloseAllPopupsCore(GamePopupCloseReason closeReason) { while (_popupAnchors.Count > 0) { if (!CloseTopmostPopup(closeReason)) { return; } } }
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; }
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); }
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); }
public static void CloseAllPopups(GamePopupCloseReason closeReason) { Current.CloseAllPopupsCore(closeReason); }