Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support minimizing floating windows independently of main window #276

Merged
merged 1 commit into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,54 @@ protected virtual void OnIsDraggingChanged(DependencyPropertyChangedEventArgs e)

internal bool KeepContentVisibleOnClose { get; set; }

#region OwnedByDockingManagerWindow

/// <summary><see cref="OwnedByDockingManagerWindow"/> dependency property.</summary>
public static readonly DependencyProperty OwnedByDockingManagerWindowProperty =
DependencyProperty.Register("OwnedByDockingManagerWindow", typeof(bool), typeof(LayoutFloatingWindowControl), new PropertyMetadata(true, OwnedByDockingManagerWindowPropertyChanged));

/// <summary>
/// Gets or sets a value indicating whether an undocked child window should be "owned" by the window
/// that hosts the docking manager or whether it should be an independent window.
/// </summary>
public bool OwnedByDockingManagerWindow
{
get { return (bool)GetValue(OwnedByDockingManagerWindowProperty); }
set { SetValue(OwnedByDockingManagerWindowProperty, value); }
}

private static void OwnedByDockingManagerWindowPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is LayoutFloatingWindowControl w && w.IsLoaded)
{
w.UpdateOwnership();
}
}

#endregion

#region AllowMinimize

/// <summary><see cref="AllowMinimize"/> dependency property.</summary>
public static readonly DependencyProperty AllowMinimizeProperty =
DependencyProperty.Register("AllowMinimize", typeof(bool), typeof(LayoutFloatingWindowControl), new PropertyMetadata(false));

/// <summary>
/// Gets/sets whether the floating window supports being minimized.
/// </summary>
public bool AllowMinimize
{
get { return (bool)GetValue(AllowMinimizeProperty); }
set { SetValue(AllowMinimizeProperty, value); }
}

#endregion AllowMinimize

#region IsMaximized

/// <summary><see cref="IsMaximized"/> dependency property.</summary>
public static readonly DependencyProperty IsMaximizedProperty = DependencyProperty.Register(nameof(IsMaximized), typeof(bool), typeof(LayoutFloatingWindowControl),
new FrameworkPropertyMetadata(false));
new FrameworkPropertyMetadata(false));

/// <summary>Gets/sets the <see cref="IsMaximized"/> property. This dependency property indicates if the window is maximized.</summary>
/// <remarks>Provides a secure method for setting the <see cref="IsMaximized"/> property.</remarks>
Expand Down Expand Up @@ -505,7 +548,9 @@ private static object CoerceContentValue(DependencyObject sender, object content
private void OnLoaded(object sender, RoutedEventArgs e)
{
Loaded -= OnLoaded;
this.SetParentToMainWindowOf(Model.Root.Manager);

this.UpdateOwnership();

_hwndSrc = PresentationSource.FromDependencyObject(this) as HwndSource;
_hwndSrcHook = FilterMessage;
_hwndSrc.AddHook(_hwndSrcHook);
Expand All @@ -514,6 +559,17 @@ private void OnLoaded(object sender, RoutedEventArgs e)
UpdateMaximizedState(maximized);
}

internal void UpdateOwnership()
{
// Determine whether the child window should be owned by the parent or act independently
// according to OwnedByDockingManagerWindow property.
var manager = Model?.Root?.Manager;
if (OwnedByDockingManagerWindow && manager != null)
this.SetParentToMainWindowOf(manager);
else
this.SetParentWindowToNull();
}

private void OnUnloaded(object sender, RoutedEventArgs e)
{
Unloaded -= OnUnloaded;
Expand Down Expand Up @@ -578,7 +634,18 @@ private void UpdateMaximizedState(bool isMaximized)
posElement.IsMaximized = isMaximized;
IsMaximized = isMaximized;
_isInternalChange = true;
WindowState = isMaximized ? WindowState.Maximized : WindowState.Normal;

if (isMaximized)
{
WindowState = WindowState.Maximized;
}
else if (!this.AllowMinimize || this.WindowState != WindowState.Minimized)
{
// If minimize is not supported, this prevents the window from being minimized.
// by resetting it to the normal state.
WindowState = WindowState.Normal;
}

_isInternalChange = false;
}

Expand Down
6 changes: 4 additions & 2 deletions source/Components/AvalonDock/DockingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,8 @@ internal UIElement CreateUIElementForModel(ILayoutElement model)
{
//Owner = Window.GetWindow(this)
};
newFW.SetParentToMainWindowOf(this);

newFW.UpdateOwnership();

// Fill list before calling Show (issue #254)
_fwList.Add(newFW);
Expand Down Expand Up @@ -1603,7 +1604,8 @@ internal UIElement CreateUIElementForModel(ILayoutElement model)
{
//Owner = Window.GetWindow(this)
};
newFW.SetParentToMainWindowOf(this);

newFW.UpdateOwnership();

// Fill list before calling Show (issue #254)
_fwList.Add(newFW);
Expand Down