Skip to content

Commit

Permalink
Merge branch 'master' into windows_host_drag
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes authored Mar 11, 2024
2 parents c5e3514 + ca77bde commit f419c77
Show file tree
Hide file tree
Showing 45 changed files with 945 additions and 415 deletions.
34 changes: 24 additions & 10 deletions samples/DockMvvmSample/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,36 @@
ExtendClientAreaToDecorationsHint="True"
ExtendClientAreaChromeHints="PreferSystemChrome"
ids:DockProperties.IsDragEnabled="True" ids:DockProperties.IsDropEnabled="True">
<Window.Resources>
<ExperimentalAcrylicMaterial BackgroundSource="Digger"
TintColor="{DynamicResource SystemAltHighColor}"
TintOpacity="1"
FallbackColor="{DynamicResource AcrylicFallbackColor}"
MaterialOpacity="0.55"
x:Key="AcrylicMaterial"/>
</Window.Resources>
<Design.DataContext>
<vm:MainWindowViewModel />
</Design.DataContext>
<Panel>
<ExperimentalAcrylicBorder IsHitTestVisible="False">
<ExperimentalAcrylicBorder.Material>
<ExperimentalAcrylicMaterial BackgroundSource="Digger"
TintColor="{DynamicResource SystemAltHighColor}"
TintOpacity="1"
FallbackColor="{DynamicResource AcrylicFallbackColor}"
MaterialOpacity="0.55" />
</ExperimentalAcrylicBorder.Material>
</ExperimentalAcrylicBorder>
<ExperimentalAcrylicBorder IsHitTestVisible="False" Material="{StaticResource AcrylicMaterial}" />
<Panel Margin="{Binding #MainWindowView.OffScreenMargin}">
<Panel Margin="{Binding #MainWindowView.WindowDecorationMargin}">
<views:MainView />
<views:MainView>
<views:MainView.Styles>
<Style Selector="GridSplitter">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border Background="Transparent">
<ExperimentalAcrylicBorder Material="{StaticResource AcrylicMaterial}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</views:MainView.Styles>
</views:MainView>
</Panel>
</Panel>
</Panel>
Expand Down
6 changes: 3 additions & 3 deletions samples/DockMvvmSample/Views/ProportionalStackPanelView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<TabControl>
<TabItem Header="Default">
<ProportionalStackPanel Orientation="Horizontal">
<ProportionalStackPanel ProportionalStackPanelSplitter.Proportion="0.5">
<Rectangle Fill="Red" ProportionalStackPanelSplitter.Proportion="0.5" />
<ProportionalStackPanel ProportionalStackPanel.Proportion="0.5">
<Rectangle Fill="Red" ProportionalStackPanel.Proportion="0.5" />
<ProportionalStackPanelSplitter />
<Rectangle Fill="Green" />
<ProportionalStackPanelSplitter />
Expand All @@ -35,7 +35,7 @@
<ProportionalStackPanelSplitter />
<Rectangle Fill="Blue" />
<ProportionalStackPanelSplitter />
<Rectangle Fill="Red" ProportionalStackPanelSplitter.Proportion="0.5" />
<Rectangle Fill="Red" ProportionalStackPanel.Proportion="0.5" />
</ProportionalStackPanel>
</ProportionalStackPanel>
</TabItem>
Expand Down
34 changes: 24 additions & 10 deletions samples/DockXamlSample/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,33 @@
Title="Dock Avalonia Demo" Width="800" Height="600"
ExtendClientAreaToDecorationsHint="True"
ExtendClientAreaChromeHints="PreferSystemChrome">
<Window.Resources>
<ExperimentalAcrylicMaterial BackgroundSource="Digger"
TintColor="{DynamicResource SystemAltHighColor}"
TintOpacity="1"
FallbackColor="{DynamicResource AcrylicFallbackColor}"
MaterialOpacity="0.55"
x:Key="AcrylicMaterial"/>
</Window.Resources>
<Panel>
<ExperimentalAcrylicBorder IsHitTestVisible="False">
<ExperimentalAcrylicBorder.Material>
<ExperimentalAcrylicMaterial BackgroundSource="Digger"
TintColor="{DynamicResource SystemAltHighColor}"
TintOpacity="1"
FallbackColor="{DynamicResource AcrylicFallbackColor}"
MaterialOpacity="0.55" />
</ExperimentalAcrylicBorder.Material>
</ExperimentalAcrylicBorder>
<ExperimentalAcrylicBorder IsHitTestVisible="False" Material="{StaticResource AcrylicMaterial}" />
<Panel Margin="{Binding #MainWindowView.OffScreenMargin}">
<Panel Margin="{Binding #MainWindowView.WindowDecorationMargin}">
<local:MainView />
<local:MainView>
<local:MainView.Styles>
<Style Selector="GridSplitter">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border Background="Transparent">
<ExperimentalAcrylicBorder Material="{StaticResource AcrylicMaterial}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</local:MainView.Styles>
</local:MainView>
</Panel>
</Panel>
</Panel>
Expand Down
15 changes: 15 additions & 0 deletions src/Dock.Avalonia/Controls/DockControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public class DockControl : TemplatedControl, IDockControl
public static readonly StyledProperty<IFactory?> FactoryProperty =
AvaloniaProperty.Register<DockControl, IFactory?>(nameof(Factory));

/// <summary>
/// Defines the <see cref="IsDraggingDock"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsDraggingDockProperty =
AvaloniaProperty.Register<DockControl, bool>(nameof(IsDraggingDock));

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

Expand Down Expand Up @@ -94,6 +100,15 @@ public IFactory? Factory
set => SetValue(FactoryProperty, value);
}

/// <summary>
/// Gets or sets whether any dock is being dragged.
/// </summary>
public bool IsDraggingDock
{
get => GetValue(IsDraggingDockProperty);
set => SetValue(IsDraggingDockProperty, value);
}

/// <summary>
/// Initialize the new instance of the <see cref="DockControl"/>.
/// </summary>
Expand Down
3 changes: 0 additions & 3 deletions src/Dock.Avalonia/Controls/DockDockControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

<ControlTheme x:Key="{x:Type DockDockControl}" TargetType="DockDockControl">

<Setter Property="(ProportionalStackPanelSplitter.Proportion)" Value="{Binding Proportion}" x:DataType="core:IDock" />
<Setter Property="(ProportionalStackPanelSplitter.IsEmpty)" Value="{Binding IsEmpty}" x:DataType="core:IDock" />

<Setter Property="Template">
<ControlTemplate>
<DockableControl TrackingMode="Visible">
Expand Down
6 changes: 1 addition & 5 deletions src/Dock.Avalonia/Controls/DocumentDockControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@

<ControlTheme x:Key="{x:Type DocumentDockControl}" TargetType="DocumentDockControl">

<Setter Property="(ProportionalStackPanelSplitter.Proportion)" Value="{Binding Proportion}" x:DataType="core:IDock" />
<Setter Property="(ProportionalStackPanelSplitter.IsEmpty)" Value="{Binding IsEmpty}" x:DataType="core:IDock" />

<Setter Property="Template">
<ControlTemplate>
<DockableControl TrackingMode="Visible"
ProportionalStackPanelSplitter.Proportion="{Binding Proportion}">
<DockableControl TrackingMode="Visible">
<DocumentControl IsActive="{Binding IsActive}" />
</DockableControl>
</ControlTemplate>
Expand Down
4 changes: 3 additions & 1 deletion src/Dock.Avalonia/Controls/HostWindow.axaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:core="using:Dock.Model.Core">
xmlns:core="using:Dock.Model.Core"
xmlns:controls="clr-namespace:Dock.Model.Controls;assembly=Dock.Model">
<Design.PreviewWith>
<HostWindow IsToolWindow="False" Width="300" Height="400" />
</Design.PreviewWith>
Expand All @@ -14,6 +15,7 @@
<Setter Property="WindowState" Value="Normal" />
<Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="Title" Value="{Binding ActiveDockable.Title}" />
<Setter Property="Topmost" Value="{Binding Window.Topmost}" x:DataType="controls:IRootDock" />
<Setter Property="SystemDecorations" Value="Full" />
<Setter Property="ExtendClientAreaToDecorationsHint" Value="True" />
<Setter Property="ExtendClientAreaChromeHints" Value="PreferSystemChrome" />
Expand Down
18 changes: 11 additions & 7 deletions src/Dock.Avalonia/Controls/HostWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Linq;
using System.Runtime.InteropServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Styling;
using Avalonia.VisualTree;
using Dock.Avalonia.Internal;
using Dock.Model;
using Dock.Model.Core;
Expand Down Expand Up @@ -269,7 +271,15 @@ public void Present(bool isDialog)
Window.Factory?.OnWindowOpened(Window);
}

Show();
var ownerDockControl = Window?.Layout?.Factory?.DockControls.FirstOrDefault();
if (ownerDockControl is Control control && control.GetVisualRoot() is Window parentWindow)
{
Show(parentWindow);
}
else
{
Show();
}
}
}
}
Expand Down Expand Up @@ -327,12 +337,6 @@ public void GetSize(out double width, out double height)
height = Height;
}

/// <inheritdoc/>
public void SetTopmost(bool topmost)
{
Topmost = topmost;
}

/// <inheritdoc/>
public void SetTitle(string title)
{
Expand Down
40 changes: 40 additions & 0 deletions src/Dock.Avalonia/Controls/PinnedDockControl.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dmc="clr-namespace:Dock.Model.Controls;assembly=Dock.Model">
<Design.PreviewWith>
<Border>
<PinnedDockControl />
</Border>
</Design.PreviewWith>

<ControlTheme x:Key="{x:Type PinnedDockControl}" TargetType="PinnedDockControl">

<Setter Property="PinnedDockAlignment" Value="{CompiledBinding PinnedDock.Alignment}" x:DataType="dmc:IRootDock" />

<Setter Property="Template">
<ControlTemplate>
<Grid Name="PART_PinnedDockGrid"
IsVisible="{Binding !PinnedDock.IsEmpty, FallbackValue=False}"
x:DataType="dmc:IRootDock"
x:CompileBindings="True">
<ContentControl Content="{Binding PinnedDock}" Name="PART_PinnedDock">
<ContentControl.Styles>
<Style Selector="ToolDockControl">
<Setter Property="Background">
<MultiBinding Converter="{x:Static EitherNotNullConverter.Instance}">
<CompiledBinding Path="$parent[Window].Background" />
<CompiledBinding Path="$parent[Window].TransparencyBackgroundFallback" />
</MultiBinding>
</Setter>
</Style>
<Style Selector="ToolControl">
<Setter Property="IsHitTestVisible" Value="{CompiledBinding !$parent[DockControl].IsDraggingDock}" />
</Style>
</ContentControl.Styles>
</ContentControl>
<GridSplitter Grid.Column="1" Grid.Row="1" Background="{CompiledBinding $parent[Window].Background, TargetNullValue={x:Static Brushes.Transparent}}" />
</Grid>
</ControlTemplate>
</Setter>
</ControlTheme>
</ResourceDictionary>
91 changes: 91 additions & 0 deletions src/Dock.Avalonia/Controls/PinnedDockControl.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Dock.Model.Core;

namespace Dock.Avalonia.Controls;

/// <summary>
/// Interaction logic for <see cref="PinnedDockControl"/> xaml.
/// </summary>
[TemplatePart("PART_PinnedDock", typeof(ContentControl)/*, IsRequired = true*/)]
[TemplatePart("PART_PinnedDockGrid", typeof(Grid)/*, IsRequired = true*/)]
public class PinnedDockControl : TemplatedControl
{
/// <summary>
/// Define the <see cref="PinnedDockAlignment"/> property.
/// </summary>
public static readonly StyledProperty<Alignment> PinnedDockAlignmentProperty = AvaloniaProperty.Register<PinnedDockControl, Alignment>(nameof(PinnedDockAlignment));

/// <summary>
/// Gets or sets pinned dock alignment
/// </summary>
public Alignment PinnedDockAlignment
{
get => GetValue(PinnedDockAlignmentProperty);
set => SetValue(PinnedDockAlignmentProperty, value);
}

private Grid? _pinnedDockGrid;
private ContentControl? _pinnedDock;

static PinnedDockControl()
{
PinnedDockAlignmentProperty.Changed.AddClassHandler<PinnedDockControl>((control, e) => control.UpdateGrid());
}

private void UpdateGrid()
{
if (_pinnedDockGrid == null || _pinnedDock == null)
return;

_pinnedDockGrid.RowDefinitions.Clear();
_pinnedDockGrid.ColumnDefinitions.Clear();
switch (PinnedDockAlignment)
{
case Alignment.Unset:
case Alignment.Left:
_pinnedDockGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Auto) { MinWidth = 50 });
_pinnedDockGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Auto));
_pinnedDockGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star) { MinWidth = 50 });
Grid.SetColumn(_pinnedDock, 0);
Grid.SetRow(_pinnedDock, 0);
break;
case Alignment.Bottom:
_pinnedDockGrid.RowDefinitions.Add(new RowDefinition(GridLength.Star) { MinHeight = 50 });
_pinnedDockGrid.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
_pinnedDockGrid.RowDefinitions.Add(new RowDefinition(GridLength.Auto) { MinHeight = 50 });
Grid.SetColumn(_pinnedDock, 0);
Grid.SetRow(_pinnedDock, 2);
break;
case Alignment.Right:
_pinnedDockGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star) { MinWidth = 50 });
_pinnedDockGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Auto));
_pinnedDockGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Auto) { MinWidth = 50 });
Grid.SetColumn(_pinnedDock, 2);
Grid.SetRow(_pinnedDock, 0);
break;
case Alignment.Top:
_pinnedDockGrid.RowDefinitions.Add(new RowDefinition(GridLength.Auto) { MinHeight = 50 });
_pinnedDockGrid.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
_pinnedDockGrid.RowDefinitions.Add(new RowDefinition(GridLength.Star) { MinHeight = 50 });
Grid.SetColumn(_pinnedDock, 1);
Grid.SetRow(_pinnedDock, 0);
break;
default:
throw new ArgumentOutOfRangeException();
}
}

/// <inheritdoc/>
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_pinnedDockGrid = e.NameScope.Get<Grid>("PART_PinnedDockGrid");
_pinnedDock = e.NameScope.Get<ContentControl>("PART_PinnedDock");
UpdateGrid();
}
}

18 changes: 11 additions & 7 deletions src/Dock.Avalonia/Controls/ProportionalDockControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@

<ControlTheme x:Key="{x:Type ProportionalDockControl}" TargetType="ProportionalDockControl">

<Setter Property="(ProportionalStackPanelSplitter.Proportion)" Value="{Binding Proportion}" x:DataType="core:IDock" />
<Setter Property="(ProportionalStackPanelSplitter.IsEmpty)" Value="{Binding IsEmpty}" x:DataType="core:IDock" />

<Setter Property="Template">
<ControlTemplate>
<DockableControl TrackingMode="Visible"
ProportionalStackPanelSplitter.Proportion="{Binding Proportion}">
<DockableControl TrackingMode="Visible">
<ItemsControl ItemsSource="{Binding VisibleDockables}">
<ItemsControl.Styles>
<Style Selector="ItemsControl > ContentPresenter > :is(core|IDock)" x:DataType="core:IDock">
<Setter Property="(ProportionalStackPanelSplitter.Proportion)" Value="{Binding Proportion}" />
<Style Selector="ItemsControl > ContentPresenter">
<Setter x:DataType="core:IDock" Property="(ProportionalStackPanel.Proportion)" Value="{Binding Proportion}" />
<Setter Property="(ProportionalStackPanel.IsCollapsed)">
<Setter.Value>
<MultiBinding Converter="{x:Static BoolConverters.And}" x:DataType="core:IDock">
<CompiledBinding Path="IsCollapsable" />
<CompiledBinding Path="IsEmpty" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</ItemsControl.Styles>
<ItemsControl.ItemsPanel>
Expand Down
Loading

0 comments on commit f419c77

Please sign in to comment.