From 2c6afd7c0c5d28c7e45a4366c206de0d1d509eb2 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Tue, 24 Sep 2019 08:43:34 +0200 Subject: [PATCH] bugfix #73 (fixed dock sizes) use code from https://github.com/xceedsoftware/wpftoolkit/pull/1195 --- .../LayoutAnchorablePaneGroupControl.cs | 4 +- .../LayoutDocumentPaneGroupControl.cs | 4 +- .../Controls/LayoutPanelControl.cs | 72 +++--- .../Layout/ILayoutPositionableElement.cs | 5 + .../Layout/LayoutPositionableGroup.cs | 206 ++++++++++-------- 5 files changed, 165 insertions(+), 126 deletions(-) diff --git a/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutAnchorablePaneGroupControl.cs b/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutAnchorablePaneGroupControl.cs index e68770fb..9a61564d 100644 --- a/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutAnchorablePaneGroupControl.cs +++ b/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutAnchorablePaneGroupControl.cs @@ -48,7 +48,7 @@ protected override void OnFixChildrenDockLengths() for( int i = 0; i < _model.Children.Count; i++ ) { var childModel = _model.Children[ i ] as ILayoutPositionableElement; - if( !childModel.DockWidth.IsStar ) + if( childModel.ForceFixedDockSize && !childModel.DockWidth.IsStar ) { childModel.DockWidth = new GridLength( 1.0, GridUnitType.Star ); } @@ -59,7 +59,7 @@ protected override void OnFixChildrenDockLengths() for( int i = 0; i < _model.Children.Count; i++ ) { var childModel = _model.Children[ i ] as ILayoutPositionableElement; - if( !childModel.DockHeight.IsStar ) + if( childModel.ForceFixedDockSize && !childModel.DockHeight.IsStar ) { childModel.DockHeight = new GridLength( 1.0, GridUnitType.Star ); } diff --git a/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutDocumentPaneGroupControl.cs b/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutDocumentPaneGroupControl.cs index d628d8e7..3589f4fa 100644 --- a/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutDocumentPaneGroupControl.cs +++ b/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutDocumentPaneGroupControl.cs @@ -48,7 +48,7 @@ protected override void OnFixChildrenDockLengths() for( int i = 0; i < _model.Children.Count; i++ ) { var childModel = _model.Children[ i ] as ILayoutPositionableElement; - if( !childModel.DockWidth.IsStar ) + if( childModel.ForceFixedDockSize && !childModel.DockWidth.IsStar ) { childModel.DockWidth = new GridLength( 1.0, GridUnitType.Star ); } @@ -59,7 +59,7 @@ protected override void OnFixChildrenDockLengths() for( int i = 0; i < _model.Children.Count; i++ ) { var childModel = _model.Children[ i ] as ILayoutPositionableElement; - if( !childModel.DockHeight.IsStar ) + if( childModel.ForceFixedDockSize && !childModel.DockHeight.IsStar ) { childModel.DockHeight = new GridLength( 1.0, GridUnitType.Star ); } diff --git a/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutPanelControl.cs b/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutPanelControl.cs index a1ae5db9..71b680ca 100644 --- a/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutPanelControl.cs +++ b/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutPanelControl.cs @@ -59,24 +59,27 @@ protected override void OnFixChildrenDockLengths() var childContainerModel = _model.Children[ i ] as ILayoutContainer; var childPositionableModel = _model.Children[ i ] as ILayoutPositionableElement; - if( childContainerModel != null && - ( childContainerModel.IsOfType() || - childContainerModel.ContainsChildOfType() ) ) + if (childPositionableModel.ForceFixedDockSize) { - childPositionableModel.DockWidth = new GridLength( 1.0, GridUnitType.Star ); - } - else if( childPositionableModel != null && childPositionableModel.DockWidth.IsStar ) - { - var childPositionableModelWidthActualSize = childPositionableModel as ILayoutPositionableElementWithActualSize; - var childDockMinWidth = childPositionableModel.CalculatedDockMinWidth(); - var widthToSet = Math.Max( childPositionableModelWidthActualSize.ActualWidth, childDockMinWidth ); - - widthToSet = Math.Min( widthToSet, ActualWidth / 2.0 ); - widthToSet = Math.Max( widthToSet, childDockMinWidth ); - - childPositionableModel.DockWidth = new GridLength( - widthToSet, - GridUnitType.Pixel ); + if (childContainerModel != null && + (childContainerModel.IsOfType() || + childContainerModel.ContainsChildOfType())) + { + childPositionableModel.DockWidth = new GridLength(1.0, GridUnitType.Star); + } + else if (childPositionableModel != null && childPositionableModel.DockWidth.IsStar) + { + var childPositionableModelWidthActualSize = childPositionableModel as ILayoutPositionableElementWithActualSize; + var childDockMinWidth = childPositionableModel.CalculatedDockMinWidth(); + var widthToSet = Math.Max(childPositionableModelWidthActualSize.ActualWidth, childDockMinWidth); + + widthToSet = Math.Min(widthToSet, ActualWidth / 2.0); + widthToSet = Math.Max(widthToSet, childDockMinWidth); + + childPositionableModel.DockWidth = new GridLength( + widthToSet, + GridUnitType.Pixel); + } } } } @@ -85,7 +88,7 @@ protected override void OnFixChildrenDockLengths() for( int i = 0; i < _model.Children.Count; i++ ) { var childPositionableModel = _model.Children[ i ] as ILayoutPositionableElement; - if( !childPositionableModel.DockWidth.IsStar ) + if( childPositionableModel.ForceFixedDockSize && !childPositionableModel.DockWidth.IsStar ) { childPositionableModel.DockWidth = new GridLength( 1.0, GridUnitType.Star ); } @@ -101,21 +104,24 @@ protected override void OnFixChildrenDockLengths() var childContainerModel = _model.Children[ i ] as ILayoutContainer; var childPositionableModel = _model.Children[ i ] as ILayoutPositionableElement; - if( childContainerModel != null && - ( childContainerModel.IsOfType() || - childContainerModel.ContainsChildOfType() ) ) + if (childPositionableModel.ForceFixedDockSize) { - childPositionableModel.DockHeight = new GridLength( 1.0, GridUnitType.Star ); - } - else if( childPositionableModel != null && childPositionableModel.DockHeight.IsStar ) - { - var childPositionableModelWidthActualSize = childPositionableModel as ILayoutPositionableElementWithActualSize; - var childDockMinHeight = childPositionableModel.CalculatedDockMinHeight(); - var heightToSet = Math.Max( childPositionableModelWidthActualSize.ActualHeight, childDockMinHeight ); - heightToSet = Math.Min( heightToSet, ActualHeight / 2.0 ); - heightToSet = Math.Max( heightToSet, childDockMinHeight ); - - childPositionableModel.DockHeight = new GridLength( heightToSet, GridUnitType.Pixel ); + if (childContainerModel != null && + (childContainerModel.IsOfType() || + childContainerModel.ContainsChildOfType())) + { + childPositionableModel.DockHeight = new GridLength(1.0, GridUnitType.Star); + } + else if (childPositionableModel != null && childPositionableModel.DockHeight.IsStar) + { + var childPositionableModelWidthActualSize = childPositionableModel as ILayoutPositionableElementWithActualSize; + var childDockMinHeight = childPositionableModel.CalculatedDockMinHeight(); + var heightToSet = Math.Max(childPositionableModelWidthActualSize.ActualHeight, childDockMinHeight); + heightToSet = Math.Min(heightToSet, ActualHeight / 2.0); + heightToSet = Math.Max(heightToSet, childDockMinHeight); + + childPositionableModel.DockHeight = new GridLength(heightToSet, GridUnitType.Pixel); + } } } } @@ -124,7 +130,7 @@ protected override void OnFixChildrenDockLengths() for( int i = 0; i < _model.Children.Count; i++ ) { var childPositionableModel = _model.Children[ i ] as ILayoutPositionableElement; - if( !childPositionableModel.DockHeight.IsStar ) + if( childPositionableModel.ForceFixedDockSize && !childPositionableModel.DockHeight.IsStar ) { childPositionableModel.DockHeight = new GridLength( 1.0, GridUnitType.Star ); } diff --git a/source/Components/Xceed.Wpf.AvalonDock/Layout/ILayoutPositionableElement.cs b/source/Components/Xceed.Wpf.AvalonDock/Layout/ILayoutPositionableElement.cs index ce7b3be7..28a8ad0a 100644 --- a/source/Components/Xceed.Wpf.AvalonDock/Layout/ILayoutPositionableElement.cs +++ b/source/Components/Xceed.Wpf.AvalonDock/Layout/ILayoutPositionableElement.cs @@ -71,6 +71,11 @@ bool IsVisible { get; } + + bool ForceFixedDockSize + { + get; + } } diff --git a/source/Components/Xceed.Wpf.AvalonDock/Layout/LayoutPositionableGroup.cs b/source/Components/Xceed.Wpf.AvalonDock/Layout/LayoutPositionableGroup.cs index 64968322..9077fc65 100644 --- a/source/Components/Xceed.Wpf.AvalonDock/Layout/LayoutPositionableGroup.cs +++ b/source/Components/Xceed.Wpf.AvalonDock/Layout/LayoutPositionableGroup.cs @@ -44,7 +44,7 @@ public LayoutPositionableGroup() #region DockWidth - GridLength _dockWidth = new GridLength( 1.0, GridUnitType.Star ); + GridLength _dockWidth = new GridLength(1.0, GridUnitType.Star); public GridLength DockWidth { get @@ -55,16 +55,16 @@ public GridLength DockWidth } set { - if(_dockWidth != value && value.Value > 0) + if (_dockWidth != value && value.Value > 0) { if (value.IsAbsolute) { _resizableAbsoluteDockWidth = value.Value; } - RaisePropertyChanging( "DockWidth" ); + RaisePropertyChanging("DockWidth"); _dockWidth = value; - RaisePropertyChanged( "DockWidth" ); + RaisePropertyChanged("DockWidth"); OnDockWidthChanged(); } @@ -72,7 +72,7 @@ public GridLength DockWidth } public double FixedDockWidth => _dockWidth.IsAbsolute && _dockWidth.Value >= _dockMinWidth ? _dockWidth.Value : _dockMinWidth; - + private double? _resizableAbsoluteDockWidth; public double ResizableAbsoluteDockWidth @@ -89,7 +89,7 @@ public double ResizableAbsoluteDockWidth RaisePropertyChanged("DockWidth"); OnDockWidthChanged(); } - else if(value > _dockWidth.Value && _resizableAbsoluteDockWidth <_dockWidth.Value) + else if (value > _dockWidth.Value && _resizableAbsoluteDockWidth < _dockWidth.Value) { _resizableAbsoluteDockWidth = _dockWidth.Value; } @@ -101,7 +101,7 @@ public double ResizableAbsoluteDockWidth #region DockHeight - GridLength _dockHeight = new GridLength( 1.0, GridUnitType.Star ); + GridLength _dockHeight = new GridLength(1.0, GridUnitType.Star); public GridLength DockHeight { get @@ -112,16 +112,16 @@ public GridLength DockHeight } set { - if( _dockHeight != value && value.Value > 0) + if (_dockHeight != value && value.Value > 0) { if (value.IsAbsolute) { _resizableAbsoluteDockHeight = value.Value; } - RaisePropertyChanging( "DockHeight" ); + RaisePropertyChanging("DockHeight"); _dockHeight = value; - RaisePropertyChanged( "DockHeight" ); + RaisePropertyChanged("DockHeight"); OnDockHeightChanged(); } @@ -131,7 +131,7 @@ public GridLength DockHeight public double FixedDockHeight => _dockHeight.IsAbsolute && _dockHeight.Value >= _dockMinHeight ? _dockHeight.Value : _dockMinHeight; private double? _resizableAbsoluteDockHeight; - + public double ResizableAbsoluteDockHeight { get { return _resizableAbsoluteDockHeight ?? 0; } @@ -146,11 +146,11 @@ public double ResizableAbsoluteDockHeight RaisePropertyChanged("DockHeight"); OnDockHeightChanged(); } - else if(value > _dockHeight.Value && _resizableAbsoluteDockHeight <_dockHeight.Value) + else if (value > _dockHeight.Value && _resizableAbsoluteDockHeight < _dockHeight.Value) { _resizableAbsoluteDockHeight = _dockHeight.Value; } - else if(value == 0) + else if (value == 0) { _resizableAbsoluteDockHeight = DockMinHeight; } @@ -177,11 +177,11 @@ public bool AllowDuplicateContent } set { - if( _allowDuplicateContent != value ) + if (_allowDuplicateContent != value) { - RaisePropertyChanging( "AllowDuplicateContent" ); + RaisePropertyChanging("AllowDuplicateContent"); _allowDuplicateContent = value; - RaisePropertyChanged( "AllowDuplicateContent" ); + RaisePropertyChanged("AllowDuplicateContent"); } } } @@ -199,11 +199,11 @@ public bool CanRepositionItems } set { - if( _canRepositionItems != value ) + if (_canRepositionItems != value) { - RaisePropertyChanging( "CanRepositionItems" ); + RaisePropertyChanging("CanRepositionItems"); _canRepositionItems = value; - RaisePropertyChanged( "CanRepositionItems" ); + RaisePropertyChanged("CanRepositionItems"); } } } @@ -240,12 +240,12 @@ public double DockMinWidth } set { - if( _dockMinWidth != value ) + if (_dockMinWidth != value) { - MathHelper.AssertIsPositiveOrZero( value ); - RaisePropertyChanging( "DockMinWidth" ); + MathHelper.AssertIsPositiveOrZero(value); + RaisePropertyChanging("DockMinWidth"); _dockMinWidth = value; - RaisePropertyChanged( "DockMinWidth" ); + RaisePropertyChanged("DockMinWidth"); } } } @@ -258,7 +258,7 @@ public double CalculatedDockMinHeight() { double childrenDockMinHeight = 0.0; List visibleChildren = Children.OfType().Where(child => child.IsVisible).ToList(); - ILayoutOrientableGroup orientableGroup = this as ILayoutOrientableGroup; + ILayoutOrientableGroup orientableGroup = this as ILayoutOrientableGroup; if (orientableGroup != null && visibleChildren.Any()) { childrenDockMinHeight = orientableGroup.Orientation == Orientation.Vertical @@ -282,12 +282,12 @@ public double DockMinHeight } set { - if( _dockMinHeight != value ) + if (_dockMinHeight != value) { - MathHelper.AssertIsPositiveOrZero( value ); - RaisePropertyChanging( "DockMinHeight" ); + MathHelper.AssertIsPositiveOrZero(value); + RaisePropertyChanging("DockMinHeight"); _dockMinHeight = value; - RaisePropertyChanged( "DockMinHeight" ); + RaisePropertyChanged("DockMinHeight"); } } } @@ -305,11 +305,11 @@ public double FloatingWidth } set { - if( _floatingWidth != value ) + if (_floatingWidth != value) { - RaisePropertyChanging( "FloatingWidth" ); + RaisePropertyChanging("FloatingWidth"); _floatingWidth = value; - RaisePropertyChanged( "FloatingWidth" ); + RaisePropertyChanged("FloatingWidth"); } } } @@ -327,11 +327,11 @@ public double FloatingHeight } set { - if( _floatingHeight != value ) + if (_floatingHeight != value) { - RaisePropertyChanging( "FloatingHeight" ); + RaisePropertyChanging("FloatingHeight"); _floatingHeight = value; - RaisePropertyChanged( "FloatingHeight" ); + RaisePropertyChanged("FloatingHeight"); } } } @@ -349,11 +349,11 @@ public double FloatingLeft } set { - if( _floatingLeft != value ) + if (_floatingLeft != value) { - RaisePropertyChanging( "FloatingLeft" ); + RaisePropertyChanging("FloatingLeft"); _floatingLeft = value; - RaisePropertyChanged( "FloatingLeft" ); + RaisePropertyChanged("FloatingLeft"); } } } @@ -371,11 +371,11 @@ public double FloatingTop } set { - if( _floatingTop != value ) + if (_floatingTop != value) { - RaisePropertyChanging( "FloatingTop" ); + RaisePropertyChanging("FloatingTop"); _floatingTop = value; - RaisePropertyChanged( "FloatingTop" ); + RaisePropertyChanged("FloatingTop"); } } } @@ -393,10 +393,10 @@ public bool IsMaximized } set { - if( _isMaximized != value ) + if (_isMaximized != value) { _isMaximized = value; - RaisePropertyChanged( "IsMaximized" ); + RaisePropertyChanged("IsMaximized"); } } } @@ -439,61 +439,85 @@ double ILayoutPositionableElementWithActualSize.ActualHeight #endregion + #region ForceFixedDockSize + + bool _forceFixedDockSize; + public bool ForceFixedDockSize + { + get + { + return _forceFixedDockSize; + } + set + { + if (ForceFixedDockSize != value) + { + RaisePropertyChanging("ForceFixedDockSize"); + _forceFixedDockSize = value; + RaisePropertyChanging("ForceFixedDockSize"); + + OnForceFixedDockSizeChanged(); + } + } + } + + #endregion + #endregion #region Overrides - public override void WriteXml( System.Xml.XmlWriter writer ) + public override void WriteXml(System.Xml.XmlWriter writer) { - if( DockWidth.Value != 1.0 || !DockWidth.IsStar ) - writer.WriteAttributeString( "DockWidth", _gridLengthConverter.ConvertToInvariantString( DockWidth.IsAbsolute ? new GridLength(FixedDockWidth) : DockWidth ) ); - if( DockHeight.Value != 1.0 || !DockHeight.IsStar ) - writer.WriteAttributeString( "DockHeight", _gridLengthConverter.ConvertToInvariantString(DockHeight.IsAbsolute ? new GridLength(FixedDockHeight) : DockHeight ) ); - - if( DockMinWidth != 25.0 ) - writer.WriteAttributeString( "DockMinWidth", DockMinWidth.ToString( CultureInfo.InvariantCulture ) ); - if( DockMinHeight != 25.0 ) - writer.WriteAttributeString( "DockMinHeight", DockMinHeight.ToString( CultureInfo.InvariantCulture ) ); - - if( FloatingWidth != 0.0 ) - writer.WriteAttributeString( "FloatingWidth", FloatingWidth.ToString( CultureInfo.InvariantCulture ) ); - if( FloatingHeight != 0.0 ) - writer.WriteAttributeString( "FloatingHeight", FloatingHeight.ToString( CultureInfo.InvariantCulture ) ); - if( FloatingLeft != 0.0 ) - writer.WriteAttributeString( "FloatingLeft", FloatingLeft.ToString( CultureInfo.InvariantCulture ) ); - if( FloatingTop != 0.0 ) - writer.WriteAttributeString( "FloatingTop", FloatingTop.ToString( CultureInfo.InvariantCulture ) ); - if( IsMaximized ) - writer.WriteAttributeString( "IsMaximized", IsMaximized.ToString() ); - - base.WriteXml( writer ); + if (DockWidth.Value != 1.0 || !DockWidth.IsStar) + writer.WriteAttributeString("DockWidth", _gridLengthConverter.ConvertToInvariantString(DockWidth.IsAbsolute ? new GridLength(FixedDockWidth) : DockWidth)); + if (DockHeight.Value != 1.0 || !DockHeight.IsStar) + writer.WriteAttributeString("DockHeight", _gridLengthConverter.ConvertToInvariantString(DockHeight.IsAbsolute ? new GridLength(FixedDockHeight) : DockHeight)); + + if (DockMinWidth != 25.0) + writer.WriteAttributeString("DockMinWidth", DockMinWidth.ToString(CultureInfo.InvariantCulture)); + if (DockMinHeight != 25.0) + writer.WriteAttributeString("DockMinHeight", DockMinHeight.ToString(CultureInfo.InvariantCulture)); + + if (FloatingWidth != 0.0) + writer.WriteAttributeString("FloatingWidth", FloatingWidth.ToString(CultureInfo.InvariantCulture)); + if (FloatingHeight != 0.0) + writer.WriteAttributeString("FloatingHeight", FloatingHeight.ToString(CultureInfo.InvariantCulture)); + if (FloatingLeft != 0.0) + writer.WriteAttributeString("FloatingLeft", FloatingLeft.ToString(CultureInfo.InvariantCulture)); + if (FloatingTop != 0.0) + writer.WriteAttributeString("FloatingTop", FloatingTop.ToString(CultureInfo.InvariantCulture)); + if (IsMaximized) + writer.WriteAttributeString("IsMaximized", IsMaximized.ToString()); + + base.WriteXml(writer); } - public override void ReadXml( System.Xml.XmlReader reader ) + public override void ReadXml(System.Xml.XmlReader reader) { - if( reader.MoveToAttribute( "DockWidth" ) ) - _dockWidth = ( GridLength )_gridLengthConverter.ConvertFromInvariantString( reader.Value ); - if( reader.MoveToAttribute( "DockHeight" ) ) - _dockHeight = ( GridLength )_gridLengthConverter.ConvertFromInvariantString( reader.Value ); - - if( reader.MoveToAttribute( "DockMinWidth" ) ) - _dockMinWidth = double.Parse( reader.Value, CultureInfo.InvariantCulture ); - if( reader.MoveToAttribute( "DockMinHeight" ) ) - _dockMinHeight = double.Parse( reader.Value, CultureInfo.InvariantCulture ); - - if( reader.MoveToAttribute( "FloatingWidth" ) ) - _floatingWidth = double.Parse( reader.Value, CultureInfo.InvariantCulture ); - if( reader.MoveToAttribute( "FloatingHeight" ) ) - _floatingHeight = double.Parse( reader.Value, CultureInfo.InvariantCulture ); - if( reader.MoveToAttribute( "FloatingLeft" ) ) - _floatingLeft = double.Parse( reader.Value, CultureInfo.InvariantCulture ); - if( reader.MoveToAttribute( "FloatingTop" ) ) - _floatingTop = double.Parse( reader.Value, CultureInfo.InvariantCulture ); - if( reader.MoveToAttribute( "IsMaximized" ) ) - _isMaximized = bool.Parse( reader.Value ); - - base.ReadXml( reader ); + if (reader.MoveToAttribute("DockWidth")) + _dockWidth = (GridLength)_gridLengthConverter.ConvertFromInvariantString(reader.Value); + if (reader.MoveToAttribute("DockHeight")) + _dockHeight = (GridLength)_gridLengthConverter.ConvertFromInvariantString(reader.Value); + + if (reader.MoveToAttribute("DockMinWidth")) + _dockMinWidth = double.Parse(reader.Value, CultureInfo.InvariantCulture); + if (reader.MoveToAttribute("DockMinHeight")) + _dockMinHeight = double.Parse(reader.Value, CultureInfo.InvariantCulture); + + if (reader.MoveToAttribute("FloatingWidth")) + _floatingWidth = double.Parse(reader.Value, CultureInfo.InvariantCulture); + if (reader.MoveToAttribute("FloatingHeight")) + _floatingHeight = double.Parse(reader.Value, CultureInfo.InvariantCulture); + if (reader.MoveToAttribute("FloatingLeft")) + _floatingLeft = double.Parse(reader.Value, CultureInfo.InvariantCulture); + if (reader.MoveToAttribute("FloatingTop")) + _floatingTop = double.Parse(reader.Value, CultureInfo.InvariantCulture); + if (reader.MoveToAttribute("IsMaximized")) + _isMaximized = bool.Parse(reader.Value); + + base.ReadXml(reader); } #endregion @@ -508,6 +532,10 @@ protected virtual void OnDockHeightChanged() { } - #endregion + protected virtual void OnForceFixedDockSizeChanged() + { + } + + #endregion } }