Browse Source

- Fix various issues related to alignments,width and height.

- Fix margin of the elements when creating new Rows/Columns in Grid.
- Fix possible null reference in QuickOperationMenuExtension.cs

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6344 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Kumar Devvrat 16 years ago
parent
commit
958d12d508
  1. 348
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/GridAdorner.cs
  2. 28
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs
  3. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs

348
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/GridAdorner.cs

@ -39,13 +39,13 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
readonly Orientation orientation; readonly Orientation orientation;
readonly GridUnitSelector unitSelector; readonly GridUnitSelector unitSelector;
static readonly SolidColorBrush bgBrush; static readonly SolidColorBrush bgBrush;
public const double RailSize = 10; public const double RailSize = 10;
public const double RailDistance = 6; public const double RailDistance = 6;
public const double SplitterWidth = 10; public const double SplitterWidth = 10;
bool displayUnitSelector; // Indicates whether Grid UnitSeletor should be displayed. bool displayUnitSelector; // Indicates whether Grid UnitSeletor should be displayed.
public GridRailAdorner(DesignItem gridItem, AdornerPanel adornerPanel, Orientation orientation) public GridRailAdorner(DesignItem gridItem, AdornerPanel adornerPanel, Orientation orientation)
{ {
@ -70,10 +70,10 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
unitSelector.Orientation = orientation; unitSelector.Orientation = orientation;
previewAdorner.IsPreview = true; previewAdorner.IsPreview = true;
previewAdorner.IsHitTestVisible = false; previewAdorner.IsHitTestVisible = false;
unitSelector.Visibility = Visibility.Hidden; unitSelector.Visibility = Visibility.Hidden;
} }
protected override void OnRender(DrawingContext drawingContext) protected override void OnRender(DrawingContext drawingContext)
{ {
base.OnRender(drawingContext); base.OnRender(drawingContext);
@ -115,143 +115,143 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
protected override void OnMouseEnter(MouseEventArgs e) protected override void OnMouseEnter(MouseEventArgs e)
{ {
base.OnMouseEnter(e); base.OnMouseEnter(e);
this.Cursor = Cursors.Cross; this.Cursor = Cursors.Cross;
RelativePlacement rpUnitSelector = new RelativePlacement(); RelativePlacement rpUnitSelector = new RelativePlacement();
if (orientation == Orientation.Vertical) if (orientation == Orientation.Vertical)
{ {
double insertionPosition = e.GetPosition(this).Y; double insertionPosition = e.GetPosition(this).Y;
RowDefinition current = grid.RowDefinitions RowDefinition current = grid.RowDefinitions
.FirstOrDefault(r => insertionPosition >= r.Offset && .FirstOrDefault(r => insertionPosition >= r.Offset &&
insertionPosition <= (r.Offset + r.ActualHeight)); insertionPosition <= (r.Offset + r.ActualHeight));
if (current != null) if (current != null)
{ {
DesignItem component = this.gridItem.Services.Component.GetDesignItem(current); DesignItem component = this.gridItem.Services.Component.GetDesignItem(current);
rpUnitSelector.XOffset = -(RailSize + RailDistance) * 2.75; rpUnitSelector.XOffset = -(RailSize + RailDistance) * 2.75;
rpUnitSelector.WidthOffset = RailSize + RailDistance; rpUnitSelector.WidthOffset = RailSize + RailDistance;
rpUnitSelector.WidthRelativeToContentWidth = 1; rpUnitSelector.WidthRelativeToContentWidth = 1;
rpUnitSelector.HeightOffset = 55; rpUnitSelector.HeightOffset = 55;
rpUnitSelector.YOffset = current.Offset + current.ActualHeight / 2 - 25; rpUnitSelector.YOffset = current.Offset + current.ActualHeight / 2 - 25;
unitSelector.SelectedItem = component; unitSelector.SelectedItem = component;
unitSelector.Unit = ((GridLength)component.Properties[RowDefinition.HeightProperty].ValueOnInstance).GridUnitType; unitSelector.Unit = ((GridLength)component.Properties[RowDefinition.HeightProperty].ValueOnInstance).GridUnitType;
displayUnitSelector = true; displayUnitSelector = true;
} }
else else
{ {
displayUnitSelector = false; displayUnitSelector = false;
} }
} }
else else
{ {
double insertionPosition = e.GetPosition(this).X; double insertionPosition = e.GetPosition(this).X;
ColumnDefinition current = grid.ColumnDefinitions ColumnDefinition current = grid.ColumnDefinitions
.FirstOrDefault(r => insertionPosition >= r.Offset && .FirstOrDefault(r => insertionPosition >= r.Offset &&
insertionPosition <= (r.Offset + r.ActualWidth)); insertionPosition <= (r.Offset + r.ActualWidth));
if (current != null) if (current != null)
{ {
DesignItem component = this.gridItem.Services.Component.GetDesignItem(current); DesignItem component = this.gridItem.Services.Component.GetDesignItem(current);
Debug.Assert(component != null); Debug.Assert(component != null);
rpUnitSelector.YOffset = -(RailSize + RailDistance) * 2.20; rpUnitSelector.YOffset = -(RailSize + RailDistance) * 2.20;
rpUnitSelector.HeightOffset = RailSize + RailDistance; rpUnitSelector.HeightOffset = RailSize + RailDistance;
rpUnitSelector.HeightRelativeToContentHeight = 1; rpUnitSelector.HeightRelativeToContentHeight = 1;
rpUnitSelector.WidthOffset = 75; rpUnitSelector.WidthOffset = 75;
rpUnitSelector.XOffset = current.Offset + current.ActualWidth / 2 - 35; rpUnitSelector.XOffset = current.Offset + current.ActualWidth / 2 - 35;
unitSelector.SelectedItem = component; unitSelector.SelectedItem = component;
unitSelector.Unit = ((GridLength)component.Properties[ColumnDefinition.WidthProperty].ValueOnInstance).GridUnitType; unitSelector.Unit = ((GridLength)component.Properties[ColumnDefinition.WidthProperty].ValueOnInstance).GridUnitType;
displayUnitSelector = true; displayUnitSelector = true;
} }
else else
{ {
displayUnitSelector = false; displayUnitSelector = false;
} }
} }
if(displayUnitSelector) if(displayUnitSelector)
unitSelector.Visibility = Visibility.Visible; unitSelector.Visibility = Visibility.Visible;
if(!adornerPanel.Children.Contains(previewAdorner)) if(!adornerPanel.Children.Contains(previewAdorner))
adornerPanel.Children.Add(previewAdorner); adornerPanel.Children.Add(previewAdorner);
} }
protected override void OnMouseMove(MouseEventArgs e) protected override void OnMouseMove(MouseEventArgs e)
{ {
base.OnMouseMove(e); base.OnMouseMove(e);
RelativePlacement rp = new RelativePlacement(); RelativePlacement rp = new RelativePlacement();
RelativePlacement rpUnitSelector = new RelativePlacement(); RelativePlacement rpUnitSelector = new RelativePlacement();
if (orientation == Orientation.Vertical) if (orientation == Orientation.Vertical)
{ {
double insertionPosition = e.GetPosition(this).Y; double insertionPosition = e.GetPosition(this).Y;
RowDefinition current = grid.RowDefinitions RowDefinition current = grid.RowDefinitions
.FirstOrDefault(r => insertionPosition >= r.Offset && .FirstOrDefault(r => insertionPosition >= r.Offset &&
insertionPosition <= (r.Offset + r.ActualHeight)); insertionPosition <= (r.Offset + r.ActualHeight));
rp.XOffset = -(RailSize + RailDistance); rp.XOffset = -(RailSize + RailDistance);
rp.WidthOffset = RailSize + RailDistance; 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;
if (current != null) if (current != null)
{ {
DesignItem component = this.gridItem.Services.Component.GetDesignItem(current); DesignItem component = this.gridItem.Services.Component.GetDesignItem(current);
rpUnitSelector.XOffset = -(RailSize + RailDistance) * 2.75; rpUnitSelector.XOffset = -(RailSize + RailDistance) * 2.75;
rpUnitSelector.WidthOffset = RailSize + RailDistance; rpUnitSelector.WidthOffset = RailSize + RailDistance;
rpUnitSelector.WidthRelativeToContentWidth = 1; rpUnitSelector.WidthRelativeToContentWidth = 1;
rpUnitSelector.HeightOffset = 55; rpUnitSelector.HeightOffset = 55;
rpUnitSelector.YOffset = current.Offset + current.ActualHeight / 2 - 25; rpUnitSelector.YOffset = current.Offset + current.ActualHeight / 2 - 25;
unitSelector.SelectedItem = component; unitSelector.SelectedItem = component;
unitSelector.Unit = ((GridLength)component.Properties[RowDefinition.HeightProperty].ValueOnInstance).GridUnitType; unitSelector.Unit = ((GridLength)component.Properties[RowDefinition.HeightProperty].ValueOnInstance).GridUnitType;
displayUnitSelector = true; displayUnitSelector = true;
} }
else else
{ {
displayUnitSelector = false; displayUnitSelector = false;
} }
} }
else else
{ {
double insertionPosition = e.GetPosition(this).X; double insertionPosition = e.GetPosition(this).X;
ColumnDefinition current = grid.ColumnDefinitions ColumnDefinition current = grid.ColumnDefinitions
.FirstOrDefault(r => insertionPosition >= r.Offset && .FirstOrDefault(r => insertionPosition >= r.Offset &&
insertionPosition <= (r.Offset + r.ActualWidth)); insertionPosition <= (r.Offset + r.ActualWidth));
rp.YOffset = -(RailSize + RailDistance); rp.YOffset = -(RailSize + RailDistance);
rp.HeightOffset = RailSize + RailDistance; 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;
if (current != null) if (current != null)
{ {
DesignItem component = this.gridItem.Services.Component.GetDesignItem(current); DesignItem component = this.gridItem.Services.Component.GetDesignItem(current);
Debug.Assert(component != null); Debug.Assert(component != null);
rpUnitSelector.YOffset = -(RailSize + RailDistance) * 2.20; rpUnitSelector.YOffset = -(RailSize + RailDistance) * 2.20;
rpUnitSelector.HeightOffset = RailSize + RailDistance; rpUnitSelector.HeightOffset = RailSize + RailDistance;
rpUnitSelector.HeightRelativeToContentHeight = 1; rpUnitSelector.HeightRelativeToContentHeight = 1;
rpUnitSelector.WidthOffset = 75; rpUnitSelector.WidthOffset = 75;
rpUnitSelector.XOffset = current.Offset + current.ActualWidth / 2 - 35; rpUnitSelector.XOffset = current.Offset + current.ActualWidth / 2 - 35;
unitSelector.SelectedItem = component; unitSelector.SelectedItem = component;
unitSelector.Unit = ((GridLength)component.Properties[ColumnDefinition.WidthProperty].ValueOnInstance).GridUnitType; unitSelector.Unit = ((GridLength)component.Properties[ColumnDefinition.WidthProperty].ValueOnInstance).GridUnitType;
displayUnitSelector = true; displayUnitSelector = true;
} }
else else
{ {
displayUnitSelector = false; displayUnitSelector = false;
} }
} }
AdornerPanel.SetPlacement(previewAdorner, rp); AdornerPanel.SetPlacement(previewAdorner, rp);
if (displayUnitSelector) if (displayUnitSelector)
AdornerPanel.SetPlacement(unitSelector, rpUnitSelector); AdornerPanel.SetPlacement(unitSelector, rpUnitSelector);
} }
protected override void OnMouseLeave(MouseEventArgs e) protected override void OnMouseLeave(MouseEventArgs e)
{ {
base.OnMouseLeave(e); base.OnMouseLeave(e);
Mouse.UpdateCursor(); Mouse.UpdateCursor();
if (!unitSelector.IsMouseOver) if (!unitSelector.IsMouseOver)
{ {
unitSelector.Visibility = Visibility.Hidden; unitSelector.Visibility = Visibility.Hidden;
displayUnitSelector = false; displayUnitSelector = false;
} }
if(adornerPanel.Children.Contains(previewAdorner)) if(adornerPanel.Children.Contains(previewAdorner))
adornerPanel.Children.Remove(previewAdorner); adornerPanel.Children.Remove(previewAdorner);
} }
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
@ -284,7 +284,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
if (currentRow == null) if (currentRow == null)
currentRow = gridItem.Services.Component.GetDesignItem(grid.RowDefinitions.Last()); currentRow = gridItem.Services.Component.GetDesignItem(grid.RowDefinitions.Last());
unitSelector.SelectedItem = currentRow; unitSelector.SelectedItem = currentRow;
for (int i = 0; i < grid.RowDefinitions.Count; i++) { for (int i = 0; i < grid.RowDefinitions.Count; i++) {
RowDefinition row = grid.RowDefinitions[i]; RowDefinition row = grid.RowDefinitions[i];
if (row.Offset > insertionPosition) continue; if (row.Offset > insertionPosition) continue;
@ -298,11 +298,11 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
rowCollection.CollectionElements.Insert(i + 1, newRowDefinition); rowCollection.CollectionElements.Insert(i + 1, newRowDefinition);
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);
grid.UpdateLayout();
FixIndicesAfterSplit(i, Grid.RowProperty, Grid.RowSpanProperty); FixIndicesAfterSplit(i, Grid.RowProperty, Grid.RowSpanProperty,insertionPosition);
grid.UpdateLayout(); grid.UpdateLayout();
changeGroup.Commit(); changeGroup.Commit();
break; break;
} }
} }
} else { } else {
@ -343,28 +343,79 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
columnCollection.CollectionElements.Insert(i + 1, newColumnDefinition); columnCollection.CollectionElements.Insert(i + 1, newColumnDefinition);
columnCollection.CollectionElements[i].Properties[ColumnDefinition.WidthProperty].SetValue(newLength1); columnCollection.CollectionElements[i].Properties[ColumnDefinition.WidthProperty].SetValue(newLength1);
newColumnDefinition.Properties[ColumnDefinition.WidthProperty].SetValue(newLength2); newColumnDefinition.Properties[ColumnDefinition.WidthProperty].SetValue(newLength2);
FixIndicesAfterSplit(i, Grid.ColumnProperty, Grid.ColumnSpanProperty); grid.UpdateLayout();
FixIndicesAfterSplit(i, Grid.ColumnProperty, Grid.ColumnSpanProperty,insertionPosition);
changeGroup.Commit(); changeGroup.Commit();
grid.UpdateLayout(); grid.UpdateLayout();
break; break;
} }
} }
} }
InvalidateVisual(); InvalidateVisual();
} }
void FixIndicesAfterSplit(int splitIndex, DependencyProperty idxProperty, DependencyProperty spanProperty) private void FixIndicesAfterSplit(int splitIndex, DependencyProperty idxProperty, DependencyProperty spanProperty, double insertionPostion)
{ {
// increment ColSpan of all controls in the split column, increment Column of all controls in later columns: if (orientation == Orientation.Horizontal) {
foreach (DesignItem child in gridItem.Properties["Children"].CollectionElements) { // increment ColSpan of all controls in the split column, increment Column of all controls in later columns:
int start = (int)child.Properties.GetAttachedProperty(idxProperty).ValueOnInstance; foreach (DesignItem child in gridItem.Properties["Children"].CollectionElements) {
int span = (int)child.Properties.GetAttachedProperty(spanProperty).ValueOnInstance; Point topLeft = child.View.TranslatePoint(new Point(0, 0), grid);
if (start <= splitIndex && splitIndex < start + span) { var margin = (Thickness) child.Properties[FrameworkElement.MarginProperty].ValueOnInstance;
child.Properties.GetAttachedProperty(spanProperty).SetValue(span + 1); var start = (int) child.Properties.GetAttachedProperty(idxProperty).ValueOnInstance;
} else if (start > splitIndex) { var span = (int) child.Properties.GetAttachedProperty(spanProperty).ValueOnInstance;
child.Properties.GetAttachedProperty(idxProperty).SetValue(start + 1); if (start <= splitIndex && splitIndex < start + span) {
var width = (double) child.Properties[FrameworkElement.ActualWidthProperty].ValueOnInstance;
if (insertionPostion >= topLeft.X + width) {
continue;
}
if (insertionPostion > topLeft.X)
child.Properties.GetAttachedProperty(spanProperty).SetValue(span + 1);
else {
child.Properties.GetAttachedProperty(idxProperty).SetValue(start + 1);
margin.Left = topLeft.X - insertionPostion;
child.Properties[FrameworkElement.MarginProperty].SetValue(margin);
}
}
else if (start > splitIndex)
{
child.Properties.GetAttachedProperty(idxProperty).SetValue(start + 1);
}
}
}
else
{
foreach (DesignItem child in gridItem.Properties["Children"].CollectionElements)
{
Point topLeft = child.View.TranslatePoint(new Point(0, 0), grid);
var margin = (Thickness)child.Properties[FrameworkElement.MarginProperty].ValueOnInstance;
var start = (int)child.Properties.GetAttachedProperty(idxProperty).ValueOnInstance;
var span = (int)child.Properties.GetAttachedProperty(spanProperty).ValueOnInstance;
if (start <= splitIndex && splitIndex < start + span)
{
var height = (double)child.Properties[FrameworkElement.ActualHeightProperty].ValueOnInstance;
if (insertionPostion >= topLeft.Y + height)
continue;
if (insertionPostion > topLeft.Y)
child.Properties.GetAttachedProperty(spanProperty).SetValue(span + 1);
else {
child.Properties.GetAttachedProperty(idxProperty).SetValue(start + 1);
margin.Top=topLeft.Y-insertionPostion;
child.Properties[FrameworkElement.MarginProperty].SetValue(margin);
}
}
else if (start > splitIndex)
{
child.Properties.GetAttachedProperty(idxProperty).SetValue(start + 1);
}
} }
} }
if (gridItem.Properties["Children"].CollectionElements.Count > 0) {
var operation = PlacementOperation.Start(gridItem.Properties["Children"].CollectionElements, PlacementType.Move);
foreach (var info in operation.PlacedItems) {
operation.CurrentContainerBehavior.SetPosition(info);
}
operation.Commit();
}
} }
static void SplitLength(GridLength oldLength, double insertionPosition, double oldActualValue, static void SplitLength(GridLength oldLength, double insertionPosition, double oldActualValue,
@ -378,7 +429,8 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
newLength2 = new GridLength(oldLength.Value - newLength1.Value, oldLength.GridUnitType); newLength2 = new GridLength(oldLength.Value - newLength1.Value, oldLength.GridUnitType);
} }
#endregion #endregion
string GridLengthToText(GridLength len)
string GridLengthToText(GridLength len)
{ {
switch (len.GridUnitType) { switch (len.GridUnitType) {
case GridUnitType.Auto: case GridUnitType.Auto:

28
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs

@ -159,7 +159,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
GrayOutDesignerExceptActiveArea.Stop(ref grayOut); GrayOutDesignerExceptActiveArea.Stop(ref grayOut);
enteredIntoNewContainer=false; enteredIntoNewContainer=false;
base.EndPlacement(operation); base.EndPlacement(operation);
} }
public override void SetPosition(PlacementInformation info) public override void SetPosition(PlacementInformation info)
@ -207,14 +207,28 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
margin.Bottom = GetRowOffset(bottomRowIndex + 1) - info.Bounds.Bottom; margin.Bottom = GetRowOffset(bottomRowIndex + 1) - info.Bounds.Bottom;
info.Item.Properties[FrameworkElement.MarginProperty].SetValue(margin); info.Item.Properties[FrameworkElement.MarginProperty].SetValue(margin);
if (ha == HorizontalAlignment.Stretch) var widthIsSet = info.Item.Properties[FrameworkElement.WidthProperty].IsSet;
info.Item.Properties[FrameworkElement.WidthProperty].Reset(); var heightIsSet = info.Item.Properties[FrameworkElement.HeightProperty].IsSet;
else if (!widthIsSet)
{
if (ha == HorizontalAlignment.Stretch)
info.Item.Properties[FrameworkElement.WidthProperty].Reset();
else
info.Item.Properties[FrameworkElement.WidthProperty].SetValue(info.Bounds.Width);
}
else {
info.Item.Properties[FrameworkElement.WidthProperty].SetValue(info.Bounds.Width); info.Item.Properties[FrameworkElement.WidthProperty].SetValue(info.Bounds.Width);
if (va == VerticalAlignment.Stretch) }
info.Item.Properties[FrameworkElement.HeightProperty].Reset(); if (!heightIsSet)
else {
if (va == VerticalAlignment.Stretch)
info.Item.Properties[FrameworkElement.HeightProperty].Reset();
else
info.Item.Properties[FrameworkElement.HeightProperty].SetValue(info.Bounds.Height);
}
else {
info.Item.Properties[FrameworkElement.HeightProperty].SetValue(info.Bounds.Height); info.Item.Properties[FrameworkElement.HeightProperty].SetValue(info.Bounds.Height);
}
} }
public override void LeaveContainer(PlacementOperation operation) public override void LeaveContainer(PlacementOperation operation)

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs

@ -47,7 +47,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
private void OnMenuLoaded(object sender, EventArgs e) private void OnMenuLoaded(object sender, EventArgs e)
{ {
_menu.MainHeader.Click += MainHeaderClick; if(_menu.MainHeader!=null)
_menu.MainHeader.Click += MainHeaderClick;
int menuItemsAdded = 0; int menuItemsAdded = 0;
var view = this.ExtendedItem.View; var view = this.ExtendedItem.View;

Loading…
Cancel
Save