/// <summary> /// Execute handler for the MdiCommands.MinimizeWindow command. /// </summary> private void ExecuteMinimizeWindow(ExecutedRoutedEventArgs e) { MdiWindow window = Content as MdiWindow; Debug.Assert(window != null && MdiPanel.GetWindowState(window) != WindowState.Minimized); MinimizeWindow(window); }
/// <summary> /// Execute handler for the MdiCommands.RestoreWindow command. /// </summary> private void ExecuteRestoreWindow(ExecutedRoutedEventArgs e) { MdiWindow window = Content as MdiWindow; Debug.Assert(window != null && MdiPanel.GetWindowState(window) != WindowState.Normal); RestoreWindow(window); }
/// <summary> /// Execute handler for the MdiCommands.AdjustWindowRect command. /// </summary> private void ExecuteAdjustWindowRect(ExecutedRoutedEventArgs e) { UIElement originalSource = (UIElement)e.OriginalSource; AdjustWindowRectParameter swp = (AdjustWindowRectParameter)e.Parameter; MdiWindow window = Content as MdiWindow; Debug.Assert(window != null && MdiPanel.GetWindowState(window) == WindowState.Normal); Vector delta = originalSource.TransformElementToElement(swp.Delta, window); AdjustWindowRect(window, delta, swp.InteractiveEdges); }
// Bring to the front of the windows in the specified state. public void BringToFront(MdiWindow window, WindowState windowState) { int oldIndex = IndexOf(window); int newIndex = Count - 1; if (windowState == WindowState.Minimized) { bool foundSelf = false; for (newIndex = 0; newIndex < (Count - 1); newIndex++) { if (Items[newIndex] == window) { foundSelf = true; } if (MdiPanel.GetWindowState(Items[newIndex]) != WindowState.Minimized) { break; } } if (foundSelf) { newIndex--; } } Move(oldIndex, newIndex); // HACK: how to coordinate Win32 ZOrder with WPF ZOrder? This works, but assumes to many implementation details. if (VisualTreeHelper.GetChildrenCount(window) > 0) { AirspaceDecorator hwndClipper = VisualTreeHelper.GetChild(window, 0) as AirspaceDecorator; if (hwndClipper != null) { if (VisualTreeHelper.GetChildrenCount(hwndClipper) > 0) { HwndSourceHost hwndSourceHost = VisualTreeHelper.GetChild(hwndClipper, 0) as HwndSourceHost; if (hwndSourceHost != null) { HWND hwnd = new HWND(hwndSourceHost.Handle); NativeMethods.SetWindowPos(hwnd, HWND.TOP, 0, 0, 0, 0, SWP.NOMOVE | SWP.NOSIZE); } } } } }
private static object CoerceWindowRect(DependencyObject d, object baseValue) { MdiPanel panel = VisualTreeHelper.GetParent(d) as MdiPanel; FrameworkElement child = d as FrameworkElement; Rect windowRect = (Rect)baseValue; if (panel != null && d != null) { // Record the base value since we will be using for internal // calculations. d.SetValue(BaseWindowRectPropertyKey, windowRect); // The window rect size must at least be as large as the // child's minimum size. windowRect.Width = Math.Max(windowRect.Width, child.MinWidth); windowRect.Height = Math.Max(windowRect.Height, child.MinHeight); // The window rect is constrained to the panel bounds. windowRect = windowRect.ConstrainWithin(panel.Extents); } return(windowRect); }
/// <summary> /// Adjust the window rect of a window. /// </summary> public void AdjustWindowRect(MdiWindow window, Vector delta, MdiWindowEdge interactiveEdges) { if (window == null) { throw new ArgumentNullException("window"); } if (Content != window) { throw new ArgumentException("Window does not belong to this floater.", "window"); } Rect screenRect = MdiPanel.GetWindowRect(window); if (interactiveEdges == MdiWindowEdge.None) { screenRect.X += delta.X; screenRect.Y += delta.Y; } else { if ((interactiveEdges & MdiWindowEdge.Left) != 0) { // Can't size smaller than the minimum size. double constrainedDelta = Math.Min(delta.X, (screenRect.Width - window.MinWidth)); screenRect.X += constrainedDelta; screenRect.Width -= constrainedDelta; } if ((interactiveEdges & MdiWindowEdge.Right) != 0) { // Can't size smaller than the minimum size. double constrainedDelta = Math.Max(delta.X, -(screenRect.Width - window.MinWidth)); screenRect.Width += constrainedDelta; } if ((interactiveEdges & MdiWindowEdge.Top) != 0) { // Can't size smaller than the minimum size. double constrainedDelta = Math.Min(delta.Y, (screenRect.Height - window.MinHeight)); screenRect.Y += constrainedDelta; screenRect.Height -= constrainedDelta; } if ((interactiveEdges & MdiWindowEdge.Bottom) != 0) { // Can't size smaller than the minimum size. double constrainedDelta = Math.Max(delta.Y, -(screenRect.Height - window.MinHeight)); screenRect.Height += constrainedDelta; } } if (window.MinWidth > screenRect.Width) { if ((interactiveEdges & MdiWindowEdge.Left) != 0) { screenRect.X = screenRect.Right - window.MinWidth; } screenRect.Width = window.MinWidth; } if (window.MinHeight > screenRect.Height) { if ((interactiveEdges & MdiWindowEdge.Top) != 0) { screenRect.Y = screenRect.Bottom - window.MinHeight; } screenRect.Height = window.MinHeight; } MdiPanel.SetWindowRect(window, screenRect); this.Left = screenRect.Left; this.Top = screenRect.Top; this.Width = screenRect.Width; this.Height = screenRect.Height; }
/// <summary> /// CanExecute handler for the MdiCommands.RestoreWindow command. /// </summary> private void CanExecuteRestoreWindow(CanExecuteRoutedEventArgs e) { MdiWindow window = Content as MdiWindow; e.CanExecute = (window != null && MdiPanel.GetWindowState(window) != WindowState.Normal); }
/// <summary> /// CanExecute handler for the MdiCommands.MinimizeWindow command. /// </summary> private void CanExecuteMinimizeWindow(CanExecuteRoutedEventArgs e) { MdiWindow window = Content as MdiWindow; e.CanExecute = (window != null && MdiPanel.GetWindowState(window) != WindowState.Minimized); }
/// <summary> /// CanExecute handler for the MdiCommands.AdjustWindowRect command. /// </summary> private void CanExecuteAdjustWindowRect(CanExecuteRoutedEventArgs e) { MdiWindow window = Content as MdiWindow; e.CanExecute = (window != null && MdiPanel.GetWindowState(window) == WindowState.Normal); }