Skip to content

Commit

Permalink
Merge pull request #194 from wieslawsoltes/IsToolWindow
Browse files Browse the repository at this point in the history
Tool window refactor
  • Loading branch information
wieslawsoltes authored May 10, 2021
2 parents 7f82023 + 8f3e210 commit a418e27
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 11 deletions.
9 changes: 7 additions & 2 deletions src/Dock.Avalonia/Controls/DockableControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,15 @@ private void SetPointerTracking(PointerEventArgs e)
}

var position = e.GetPosition(this);
var screenPosition = DockHelpers.ToDockPoint(this.PointToScreen(position).ToPoint(1.0));

if (this.VisualRoot is null)
{
return;
}
var screenPoint = DockHelpers.ToDockPoint(this.PointToScreen(position).ToPoint(1.0));

dockable.SetPointerPosition(position.X, position.Y);
dockable.SetPointerScreenPosition(screenPosition.X, screenPosition.Y);
dockable.SetPointerScreenPosition(screenPoint.X, screenPoint.Y);
}
}
}
41 changes: 37 additions & 4 deletions src/Dock.Avalonia/Controls/HostWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
xmlns:idc="clr-namespace:Dock.Avalonia.Controls;assembly=Dock.Avalonia"
xmlns:core="using:Dock.Model.Core">
<Design.PreviewWith>
<idc:HostWindow Width="300" Height="400"/>
<idc:HostWindow IsToolWindow="False" Width="300" Height="400"/>
</Design.PreviewWith>
<Style Selector="idc|HostWindow">
<Setter Property="Background" Value="{DynamicResource DockThemeBackgroundBrush}" />
<Setter Property="FontSize" Value="{DynamicResource DockFontSizeNormal}" />
<Setter Property="FontFamily" Value="{TemplateBinding FontFamily}" />
<Setter Property="TextBlock.Foreground" Value="{DynamicResource DockThemeForegroundBrush}" />
<Setter Property="SystemDecorations" Value="Full" />
<Setter Property="WindowState" Value="Normal" />
<Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="Title" Value="{Binding ActiveDockable.Title}" />
</Style>
<Style Selector="idc|HostWindow">
<Setter Property="SystemDecorations" Value="Full" />
<Setter Property="ExtendClientAreaToDecorationsHint" Value="True" />
<Setter Property="ExtendClientAreaChromeHints" Value="PreferSystemChrome" />
<Setter Property="Title" Value="{Binding ActiveDockable.Title}" />
<Setter Property="Template">
<ControlTemplate>
<Panel>
Expand All @@ -24,7 +26,7 @@
<Panel Background="Transparent" Margin="{TemplateBinding WindowDecorationMargin}" />
<VisualLayerManager>
<VisualLayerManager.ChromeOverlayLayer>
<TitleBar />
<TitleBar/>
</VisualLayerManager.ChromeOverlayLayer>
<ContentPresenter Name="PART_ContentPresenter"
ContentTemplate="{TemplateBinding ContentTemplate}"
Expand All @@ -50,5 +52,36 @@
</Style>
<Style Selector="idc|HostWindow:toolwindow">
<Setter Property="SystemDecorations" Value="BorderOnly" />
<Setter Property="ExtendClientAreaToDecorationsHint" Value="True" />
<Setter Property="ExtendClientAreaChromeHints" Value="PreferSystemChrome" />
<Setter Property="Template">
<ControlTemplate>
<Panel>
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" />
<Border Background="{TemplateBinding Background}" IsHitTestVisible="False" />
<Panel Background="Transparent" Margin="{TemplateBinding WindowDecorationMargin}" />
<VisualLayerManager>
<VisualLayerManager.ChromeOverlayLayer>
<!-- <TitleBar/> -->
</VisualLayerManager.ChromeOverlayLayer>
<ContentPresenter Name="PART_ContentPresenter"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
Margin="{TemplateBinding Padding}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</VisualLayerManager>
</Panel>
</ControlTemplate>
</Setter>
<Setter Property="Content">
<Template>
<Panel Margin="{Binding $parent[idc:HostWindow].OffScreenMargin}">
<idc:DockControl Layout="{Binding}"
x:DataType="core:IHostWindow"
x:CompileBindings="True"/>
</Panel>
</Template>
</Setter>
</Style>
</Styles>
35 changes: 34 additions & 1 deletion src/Dock.Avalonia/Controls/HostWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Reactive.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Chrome;
using Avalonia.Controls.Metadata;
using Avalonia.Input;
using Avalonia.Interactivity;
Expand All @@ -26,8 +27,23 @@ public class HostWindow : Window, IStyleable, IHostWindow
private bool _mouseDown;
private Point _startPoint;

/// <summary>
/// Define <see cref="IsToolWindow"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsToolWindowProperty =
AvaloniaProperty.Register<HostWindow, bool>(nameof(IsToolWindow));

Type IStyleable.StyleKey => typeof(HostWindow);

/// <summary>
/// Gets or sets if this is the tool window.
/// </summary>
public bool IsToolWindow
{
get => GetValue(IsToolWindowProperty);
set => SetValue(IsToolWindowProperty, value);
}

/// <inheritdoc/>
public IDockManager DockManager => _dockManager;

Expand Down Expand Up @@ -59,6 +75,7 @@ public HostWindow()
#if DEBUG
this.AttachDevTools();
#endif
UpdatePseudoClasses(IsToolWindow);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -147,7 +164,23 @@ public void AttachGrip(ToolChromeControl chromeControl)

_chromeGrip = chromeControl.Grip;
((IPseudoClasses)chromeControl.Classes).Add(":floating");
PseudoClasses.Set(":toolwindow", true);
IsToolWindow = true;
}

/// <inheritdoc/>
protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{
base.OnPropertyChanged(change);

if (change.Property == IsToolWindowProperty)
{
UpdatePseudoClasses(change.NewValue.GetValueOrDefault<bool>());
}
}

private void UpdatePseudoClasses(bool isToolWindow)
{
PseudoClasses.Set(":toolwindow", isToolWindow);
}

/// <inheritdoc/>
Expand Down
29 changes: 27 additions & 2 deletions src/Dock.Avalonia/Internal/DockControlState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ private bool Validate(Point point, DockOperation operation, DragAction dragActio
if (_dragControl.DataContext is IDockable sourceDockable && _dropControl.DataContext is IDockable targetDockable)
{
DockManager.Position = DockHelpers.ToDockPoint(point);
DockManager.ScreenPosition = DockHelpers.ToDockPoint(relativeTo.PointToScreen(point).ToPoint(1.0));

if (relativeTo.VisualRoot is null)
{
return false;
}

var screenPoint = relativeTo.PointToScreen(point).ToPoint(1.0);
DockManager.ScreenPosition = DockHelpers.ToDockPoint(screenPoint);

return DockManager.ValidateDockable(sourceDockable, targetDockable, dragAction, operation, bExecute: false);
}

Expand All @@ -105,7 +113,14 @@ private void Execute(Point point, DockOperation operation, DragAction dragAction
if (_dragControl.DataContext is IDockable sourceDockable && _dropControl.DataContext is IDockable targetDockable)
{
DockManager.Position = DockHelpers.ToDockPoint(point);
DockManager.ScreenPosition = DockHelpers.ToDockPoint(relativeTo.PointToScreen(point).ToPoint(1.0));

if (relativeTo.VisualRoot is null)
{
return;
}
var relativePoint = relativeTo.PointToScreen(point).ToPoint(1.0);
DockManager.ScreenPosition = DockHelpers.ToDockPoint(relativePoint);

DockManager.ValidateDockable(sourceDockable, targetDockable, dragAction, operation, true);
}
}
Expand Down Expand Up @@ -214,8 +229,18 @@ public void Process(Point point, Vector delta, EventType eventType, DragAction d
{
if (dockControl is IInputElement inputDockControl && inputDockControl != inputActiveDockControl)
{
if (inputActiveDockControl.VisualRoot is null)
{
continue;
}
var screenPoint = inputActiveDockControl.PointToScreen(point);

if (inputDockControl.VisualRoot is null)
{
continue;
}
var dockControlPoint = inputDockControl.PointToClient(screenPoint);

dropControl = DockHelpers.GetControl(inputDockControl, dockControlPoint, DockProperties.IsDropAreaProperty);
if (dropControl is { })
{
Expand Down
22 changes: 20 additions & 2 deletions src/Dock.Avalonia/Internal/HostWindowState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ private bool Validate(Point point, DockOperation operation, DragAction dragActio
if (layout?.ActiveDockable is { } sourceDockable && _targetDropControl.DataContext is IDockable targetDockable)
{
DockManager.Position = DockHelpers.ToDockPoint(point);
DockManager.ScreenPosition = DockHelpers.ToDockPoint(relativeTo.PointToScreen(point).ToPoint(1.0));

if (relativeTo.VisualRoot is null)
{
return false;
}
var screenPoint = relativeTo.PointToScreen(point).ToPoint(1.0);
DockManager.ScreenPosition = DockHelpers.ToDockPoint(screenPoint);

return DockManager.ValidateDockable(sourceDockable, targetDockable, dragAction, operation, bExecute: false);
}

Expand All @@ -115,7 +122,14 @@ private void Execute(Point point, DockOperation operation, DragAction dragAction
if (layout?.ActiveDockable is { } sourceDockable && _targetDropControl.DataContext is IDockable targetDockable)
{
DockManager.Position = DockHelpers.ToDockPoint(point);
DockManager.ScreenPosition = DockHelpers.ToDockPoint(relativeTo.PointToScreen(point).ToPoint(1.0));

if (relativeTo.VisualRoot is null)
{
return;
}
var screenPoint = relativeTo.PointToScreen(point).ToPoint(1.0);
DockManager.ScreenPosition = DockHelpers.ToDockPoint(screenPoint);

DockManager.ValidateDockable(sourceDockable, targetDockable, dragAction, operation, bExecute: true);
}
}
Expand Down Expand Up @@ -205,6 +219,10 @@ public void Process(Point point, EventType eventType)
{
var position = point + _dragStartPoint;
var screenPoint = new PixelPoint((int)position.X, (int)position.Y);
if (dockControl.GetVisualRoot() is null)
{
continue;
}
var dockControlPoint = dockControl.PointToClient(screenPoint);
var dropControl = DockHelpers.GetControl(dockControl, dockControlPoint, DockProperties.IsDropAreaProperty);
if (dropControl is { })
Expand Down
4 changes: 4 additions & 0 deletions src/Dock.Model/FactoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,10 @@ public virtual void SplitToDock(IDock dock, IDockable dockable, DockOperation op
if (target is IDock dock)
{
dock.VisibleDockables = CreateList<IDockable>();
if (dockable.Owner is IDocumentDock sourceDocumentDock)
{
((target as IDocumentDock)!).CanCreateDocument = sourceDocumentDock.CanCreateDocument;
}
if (dock.VisibleDockables is not null)
{
dock.VisibleDockables.Add(dockable);
Expand Down

0 comments on commit a418e27

Please sign in to comment.