|
|
@ -6,15 +6,13 @@ |
|
|
|
// </file>
|
|
|
|
// </file>
|
|
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
using System.Diagnostics; |
|
|
|
using System.Diagnostics; |
|
|
|
using ICSharpCode.WpfDesign.Adorners; |
|
|
|
|
|
|
|
using ICSharpCode.WpfDesign.Extensions; |
|
|
|
|
|
|
|
using System.Windows; |
|
|
|
using System.Windows; |
|
|
|
using System.Windows.Controls; |
|
|
|
using System.Windows.Controls; |
|
|
|
using System.Windows.Shapes; |
|
|
|
|
|
|
|
using System.Windows.Media; |
|
|
|
|
|
|
|
using System.Windows.Input; |
|
|
|
using System.Windows.Input; |
|
|
|
|
|
|
|
using System.Windows.Media; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using ICSharpCode.WpfDesign.Adorners; |
|
|
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.WpfDesign.Designer.Controls |
|
|
|
namespace ICSharpCode.WpfDesign.Designer.Controls |
|
|
|
{ |
|
|
|
{ |
|
|
@ -35,6 +33,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls |
|
|
|
readonly Orientation orientation; |
|
|
|
readonly Orientation orientation; |
|
|
|
|
|
|
|
|
|
|
|
public const double RailSize = 10; |
|
|
|
public const double RailSize = 10; |
|
|
|
|
|
|
|
public const double RailDistance = 6; |
|
|
|
public const double SplitterWidth = 10; |
|
|
|
public const double SplitterWidth = 10; |
|
|
|
|
|
|
|
|
|
|
|
public GridRailAdorner(DesignItem gridItem, AdornerPanel adornerPanel, Orientation orientation) |
|
|
|
public GridRailAdorner(DesignItem gridItem, AdornerPanel adornerPanel, Orientation orientation) |
|
|
@ -49,10 +48,10 @@ namespace ICSharpCode.WpfDesign.Designer.Controls |
|
|
|
|
|
|
|
|
|
|
|
if (orientation == Orientation.Horizontal) { |
|
|
|
if (orientation == Orientation.Horizontal) { |
|
|
|
this.Height = RailSize; |
|
|
|
this.Height = RailSize; |
|
|
|
previewAdorner = new GridColumnSplitterAdorner(); |
|
|
|
previewAdorner = new GridColumnSplitterAdorner(gridItem, null, null); |
|
|
|
} else { // vertical
|
|
|
|
} else { // vertical
|
|
|
|
this.Width = RailSize; |
|
|
|
this.Width = RailSize; |
|
|
|
previewAdorner = new GridRowSplitterAdorner(); |
|
|
|
previewAdorner = new GridRowSplitterAdorner(gridItem, null, null); |
|
|
|
} |
|
|
|
} |
|
|
|
previewAdorner.IsPreview = true; |
|
|
|
previewAdorner.IsPreview = true; |
|
|
|
previewAdorner.IsHitTestVisible = false; |
|
|
|
previewAdorner.IsHitTestVisible = false; |
|
|
@ -70,14 +69,14 @@ namespace ICSharpCode.WpfDesign.Designer.Controls |
|
|
|
base.OnMouseMove(e); |
|
|
|
base.OnMouseMove(e); |
|
|
|
RelativePlacement rp = new RelativePlacement(); |
|
|
|
RelativePlacement rp = new RelativePlacement(); |
|
|
|
if (orientation == Orientation.Vertical) { |
|
|
|
if (orientation == Orientation.Vertical) { |
|
|
|
rp.XOffset = -RailSize; |
|
|
|
rp.XOffset = -(RailSize + RailDistance); |
|
|
|
rp.WidthOffset = RailSize; |
|
|
|
rp.WidthOffset = RailSize + RailDistance; |
|
|
|
rp.WidthRelativeToContentWidth = 1; |
|
|
|
rp.WidthRelativeToContentWidth = 1; |
|
|
|
rp.HeightOffset = SplitterWidth; |
|
|
|
rp.HeightOffset = SplitterWidth; |
|
|
|
rp.YOffset = e.GetPosition(this).Y - SplitterWidth / 2; |
|
|
|
rp.YOffset = e.GetPosition(this).Y - SplitterWidth / 2; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
rp.YOffset = -RailSize; |
|
|
|
rp.YOffset = -(RailSize + RailDistance); |
|
|
|
rp.HeightOffset = RailSize; |
|
|
|
rp.HeightOffset = RailSize + RailDistance; |
|
|
|
rp.HeightRelativeToContentHeight = 1; |
|
|
|
rp.HeightRelativeToContentHeight = 1; |
|
|
|
rp.WidthOffset = SplitterWidth; |
|
|
|
rp.WidthOffset = SplitterWidth; |
|
|
|
rp.XOffset = e.GetPosition(this).X - SplitterWidth / 2; |
|
|
|
rp.XOffset = e.GetPosition(this).X - SplitterWidth / 2; |
|
|
@ -95,6 +94,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls |
|
|
|
{ |
|
|
|
{ |
|
|
|
base.OnMouseLeftButtonDown(e); |
|
|
|
base.OnMouseLeftButtonDown(e); |
|
|
|
e.Handled = true; |
|
|
|
e.Handled = true; |
|
|
|
|
|
|
|
Focus(); |
|
|
|
adornerPanel.Children.Remove(previewAdorner); |
|
|
|
adornerPanel.Children.Remove(previewAdorner); |
|
|
|
if (orientation == Orientation.Vertical) { |
|
|
|
if (orientation == Orientation.Vertical) { |
|
|
|
using (ChangeGroup changeGroup = gridItem.OpenGroup("Split grid row")) { |
|
|
|
using (ChangeGroup changeGroup = gridItem.OpenGroup("Split grid row")) { |
|
|
@ -119,6 +119,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls |
|
|
|
rowCollection.CollectionElements[i].Properties[RowDefinition.HeightProperty].SetValue(newLength1); |
|
|
|
rowCollection.CollectionElements[i].Properties[RowDefinition.HeightProperty].SetValue(newLength1); |
|
|
|
newRowDefinition.Properties[RowDefinition.HeightProperty].SetValue(newLength2); |
|
|
|
newRowDefinition.Properties[RowDefinition.HeightProperty].SetValue(newLength2); |
|
|
|
changeGroup.Commit(); |
|
|
|
changeGroup.Commit(); |
|
|
|
|
|
|
|
gridItem.Services.Selection.SetSelectedComponents(new DesignItem[] { newRowDefinition }, SelectionTypes.Auto); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -145,6 +146,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls |
|
|
|
newColumnDefinition.Properties[ColumnDefinition.WidthProperty].SetValue(newLength2); |
|
|
|
newColumnDefinition.Properties[ColumnDefinition.WidthProperty].SetValue(newLength2); |
|
|
|
columnCollection.CollectionElements.Insert(i + 1, newColumnDefinition); |
|
|
|
columnCollection.CollectionElements.Insert(i + 1, newColumnDefinition); |
|
|
|
changeGroup.Commit(); |
|
|
|
changeGroup.Commit(); |
|
|
|
|
|
|
|
gridItem.Services.Selection.SetSelectedComponents(new DesignItem[] { newColumnDefinition }, SelectionTypes.Auto); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -164,15 +166,126 @@ namespace ICSharpCode.WpfDesign.Designer.Controls |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class GridSplitterAdorner : Control |
|
|
|
public abstract class GridSplitterAdorner : Control |
|
|
|
{ |
|
|
|
{ |
|
|
|
public static readonly DependencyProperty IsPreviewProperty |
|
|
|
public static readonly DependencyProperty IsPreviewProperty |
|
|
|
= DependencyProperty.Register("IsPreview", typeof(bool), typeof(GridSplitterAdorner), new PropertyMetadata(SharedInstances.BoxedFalse)); |
|
|
|
= DependencyProperty.Register("IsPreview", typeof(bool), typeof(GridSplitterAdorner), new PropertyMetadata(SharedInstances.BoxedFalse)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected readonly Grid grid; |
|
|
|
|
|
|
|
protected readonly DesignItem gridItem; |
|
|
|
|
|
|
|
protected readonly DesignItem firstRow, secondRow; // can also be columns
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal GridSplitterAdorner(DesignItem gridItem, DesignItem firstRow, DesignItem secondRow) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Debug.Assert(gridItem != null); |
|
|
|
|
|
|
|
this.grid = (Grid)gridItem.Component; |
|
|
|
|
|
|
|
this.gridItem = gridItem; |
|
|
|
|
|
|
|
this.firstRow = firstRow; |
|
|
|
|
|
|
|
this.secondRow = secondRow; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public bool IsPreview { |
|
|
|
public bool IsPreview { |
|
|
|
get { return (bool)GetValue(IsPreviewProperty); } |
|
|
|
get { return (bool)GetValue(IsPreviewProperty); } |
|
|
|
set { SetValue(IsPreviewProperty, SharedInstances.Box(value)); } |
|
|
|
set { SetValue(IsPreviewProperty, SharedInstances.Box(value)); } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ChangeGroup activeChangeGroup; |
|
|
|
|
|
|
|
double mouseStartPos; |
|
|
|
|
|
|
|
bool mouseIsDown; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
e.Handled = true; |
|
|
|
|
|
|
|
if (CaptureMouse()) { |
|
|
|
|
|
|
|
Focus(); |
|
|
|
|
|
|
|
gridItem.Services.Selection.SetSelectedComponents(new DesignItem[] { secondRow }, SelectionTypes.Auto); |
|
|
|
|
|
|
|
mouseStartPos = GetCoordinate(e.GetPosition(grid)); |
|
|
|
|
|
|
|
mouseIsDown = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseMove(MouseEventArgs e) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (mouseIsDown) { |
|
|
|
|
|
|
|
double mousePos = GetCoordinate(e.GetPosition(grid)); |
|
|
|
|
|
|
|
if (activeChangeGroup == null) { |
|
|
|
|
|
|
|
if (Math.Abs(mousePos - mouseStartPos) |
|
|
|
|
|
|
|
>= GetCoordinate(new Point(SystemParameters.MinimumHorizontalDragDistance, SystemParameters.MinimumVerticalDragDistance))) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
activeChangeGroup = gridItem.OpenGroup("Change grid row/column size"); |
|
|
|
|
|
|
|
RememberOriginalSize(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (activeChangeGroup != null) { |
|
|
|
|
|
|
|
ChangeSize(mousePos - mouseStartPos); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected GridLength original1, original2; |
|
|
|
|
|
|
|
protected double originalPixelSize1, originalPixelSize2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected abstract double GetCoordinate(Point point); |
|
|
|
|
|
|
|
protected abstract void RememberOriginalSize(); |
|
|
|
|
|
|
|
protected abstract DependencyProperty RowColumnSizeProperty { get; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ChangeSize(double delta) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// delta = difference in pixels
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (delta < -originalPixelSize1) delta = -originalPixelSize1; |
|
|
|
|
|
|
|
if (delta > originalPixelSize2) delta = originalPixelSize2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// replace Auto lengths with absolute lengths if necessary
|
|
|
|
|
|
|
|
if (original1.IsAuto) original1 = new GridLength(originalPixelSize1); |
|
|
|
|
|
|
|
if (original2.IsAuto) original2 = new GridLength(originalPixelSize2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GridLength new1; |
|
|
|
|
|
|
|
if (original1.IsStar && originalPixelSize1 > 0) |
|
|
|
|
|
|
|
new1 = new GridLength(original1.Value * (originalPixelSize1 + delta) / originalPixelSize1, GridUnitType.Star); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
new1 = new GridLength(original1.Value + delta); |
|
|
|
|
|
|
|
GridLength new2; |
|
|
|
|
|
|
|
if (original2.IsStar && originalPixelSize2 > 0) |
|
|
|
|
|
|
|
new2 = new GridLength(original2.Value * (originalPixelSize2 - delta) / originalPixelSize2, GridUnitType.Star); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
new2 = new GridLength(original2.Value - delta); |
|
|
|
|
|
|
|
firstRow.Properties[RowColumnSizeProperty].SetValue(new1); |
|
|
|
|
|
|
|
secondRow.Properties[RowColumnSizeProperty].SetValue(new2); |
|
|
|
|
|
|
|
((UIElement)VisualTreeHelper.GetParent(this)).InvalidateArrange(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseUp(MouseButtonEventArgs e) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (activeChangeGroup != null) { |
|
|
|
|
|
|
|
activeChangeGroup.Commit(); |
|
|
|
|
|
|
|
activeChangeGroup = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Stop(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnLostMouseCapture(MouseEventArgs e) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Stop(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnKeyDown(KeyEventArgs e) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (e.Key == Key.Escape) { |
|
|
|
|
|
|
|
e.Handled = true; |
|
|
|
|
|
|
|
Stop(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void Stop() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ReleaseMouseCapture(); |
|
|
|
|
|
|
|
mouseIsDown = false; |
|
|
|
|
|
|
|
if (activeChangeGroup != null) { |
|
|
|
|
|
|
|
activeChangeGroup.Abort(); |
|
|
|
|
|
|
|
activeChangeGroup = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class GridRowSplitterAdorner : GridSplitterAdorner |
|
|
|
public class GridRowSplitterAdorner : GridSplitterAdorner |
|
|
@ -182,14 +295,61 @@ namespace ICSharpCode.WpfDesign.Designer.Controls |
|
|
|
DefaultStyleKeyProperty.OverrideMetadata(typeof(GridRowSplitterAdorner), new FrameworkPropertyMetadata(typeof(GridRowSplitterAdorner))); |
|
|
|
DefaultStyleKeyProperty.OverrideMetadata(typeof(GridRowSplitterAdorner), new FrameworkPropertyMetadata(typeof(GridRowSplitterAdorner))); |
|
|
|
CursorProperty.OverrideMetadata(typeof(GridRowSplitterAdorner), new FrameworkPropertyMetadata(Cursors.SizeNS)); |
|
|
|
CursorProperty.OverrideMetadata(typeof(GridRowSplitterAdorner), new FrameworkPropertyMetadata(Cursors.SizeNS)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal GridRowSplitterAdorner(DesignItem gridItem, DesignItem firstRow, DesignItem secondRow) : base(gridItem, firstRow, secondRow) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override double GetCoordinate(Point point) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return point.Y; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void RememberOriginalSize() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
RowDefinition r1 = (RowDefinition)firstRow.Component; |
|
|
|
|
|
|
|
RowDefinition r2 = (RowDefinition)secondRow.Component; |
|
|
|
|
|
|
|
original1 = (GridLength)r1.GetValue(RowDefinition.HeightProperty); |
|
|
|
|
|
|
|
original2 = (GridLength)r2.GetValue(RowDefinition.HeightProperty); |
|
|
|
|
|
|
|
originalPixelSize1 = r1.ActualHeight; |
|
|
|
|
|
|
|
originalPixelSize2 = r2.ActualHeight; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override DependencyProperty RowColumnSizeProperty { |
|
|
|
|
|
|
|
get { return RowDefinition.HeightProperty; } |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class GridColumnSplitterAdorner : GridSplitterAdorner |
|
|
|
public sealed class GridColumnSplitterAdorner : GridSplitterAdorner |
|
|
|
{ |
|
|
|
{ |
|
|
|
static GridColumnSplitterAdorner() |
|
|
|
static GridColumnSplitterAdorner() |
|
|
|
{ |
|
|
|
{ |
|
|
|
DefaultStyleKeyProperty.OverrideMetadata(typeof(GridColumnSplitterAdorner), new FrameworkPropertyMetadata(typeof(GridColumnSplitterAdorner))); |
|
|
|
DefaultStyleKeyProperty.OverrideMetadata(typeof(GridColumnSplitterAdorner), new FrameworkPropertyMetadata(typeof(GridColumnSplitterAdorner))); |
|
|
|
CursorProperty.OverrideMetadata(typeof(GridColumnSplitterAdorner), new FrameworkPropertyMetadata(Cursors.SizeWE)); |
|
|
|
CursorProperty.OverrideMetadata(typeof(GridColumnSplitterAdorner), new FrameworkPropertyMetadata(Cursors.SizeWE)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal GridColumnSplitterAdorner(DesignItem gridItem, DesignItem firstRow, DesignItem secondRow) : base(gridItem, firstRow, secondRow) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override double GetCoordinate(Point point) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return point.X; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void RememberOriginalSize() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ColumnDefinition r1 = (ColumnDefinition)firstRow.Component; |
|
|
|
|
|
|
|
ColumnDefinition r2 = (ColumnDefinition)secondRow.Component; |
|
|
|
|
|
|
|
original1 = (GridLength)r1.GetValue(ColumnDefinition.WidthProperty); |
|
|
|
|
|
|
|
original2 = (GridLength)r2.GetValue(ColumnDefinition.WidthProperty); |
|
|
|
|
|
|
|
originalPixelSize1 = r1.ActualWidth; |
|
|
|
|
|
|
|
originalPixelSize2 = r2.ActualWidth; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override DependencyProperty RowColumnSizeProperty { |
|
|
|
|
|
|
|
get { return ColumnDefinition.WidthProperty; } |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|