Browse Source

Added row/column creation adorner for Grid.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2441 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
8ce6c3c1d0
  1. 13
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml
  2. 67
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml
  3. 195
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/GridAdorner.cs
  4. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/WindowClone.cs
  5. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs
  6. 130
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridAdornerProvider.cs
  7. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelSelectionHandler.cs
  8. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WindowResizeBehavior.cs
  9. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Func.cs
  10. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs
  11. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs
  12. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/SelectionService.cs
  13. 24
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/SharedInstances.cs
  14. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  15. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignItem.cs
  16. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs
  17. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelProperty.cs
  18. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionElementsCollection.cs
  19. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs
  20. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs
  21. 16
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlPropertyInfo.cs
  22. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionManager.cs
  23. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementAlignment.cs
  24. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementType.cs

13
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml

@ -30,13 +30,12 @@ @@ -30,13 +30,12 @@
<Canvas Height="50">
<Button>CB</Button>
</Canvas>
<Button>Button 1</Button>
<Canvas Height="50">
<Button>Button 2</Button>
</Canvas>
<TabControl Width="300" MinHeight="100">
<TabItem Header="Page 1"><StackPanel><Button>a</Button></StackPanel> </TabItem>
<TabItem Header="Page 2"><Button>button on page 2</Button></TabItem>
<TabControl MinHeight="150">
<TabItem Header="StackPanel"><StackPanel><Button>a</Button></StackPanel> </TabItem>
<TabItem Header="Button"><Button>button on page 2</Button></TabItem>
<TabItem Header="Canvas"><Canvas/></TabItem>
<TabItem Header="Grid"><Grid/></TabItem>
<TabItem Header="DockPanel"><DockPanel/></TabItem>
</TabControl>
</StackPanel>
</Window>

67
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml

@ -66,7 +66,7 @@ @@ -66,7 +66,7 @@
<Style TargetType="{x:Type src:WindowClone}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="src:WindowClone">
<ControlTemplate TargetType="{x:Type src:WindowClone}">
<Border Background="{DynamicResource {x:Static SystemColors.GradientActiveCaptionBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1,1,1,1" CornerRadius="5,5,5,5">
<DockPanel Margin="4,0,4,4">
<DockPanel Height="26" DockPanel.Dock="Top">
@ -106,7 +106,7 @@ @@ -106,7 +106,7 @@
<Setter Property="ShowInTaskbar" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="src:ErrorBalloon">
<ControlTemplate TargetType="{x:Type src:ErrorBalloon}">
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
@ -141,5 +141,66 @@ @@ -141,5 +141,66 @@
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type src:GridRailAdorner}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type src:GridRailAdorner}">
<Rectangle Fill="#302020ff"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type src:GridRowSplitterAdorner}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type src:GridRowSplitterAdorner}">
<Grid Height="{x:Static src:GridRailAdorner.SplitterWidth}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/> <!-- 10=RailSize -->
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Path Name="railHandle" Fill="#FFE6E6FF" Stretch="Fill" Stroke="#FF584FFF" Data="M0,0 L0,1 1,0.5 z"/>
<Path Name="line" Stretch="Fill" Stroke="#FF584FFF" Grid.Column="2" Margin="-1 0 0 0" Data="M0,0.5 L1,0.5"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="railHandle" Property="Fill" Value="#FFFFB74F"/>
</Trigger>
<Trigger Property="IsPreview" Value="True">
<Setter TargetName="railHandle" Property="Stroke" Value="#D0FFB74F"/>
<Setter TargetName="line" Property="Stroke" Value="#D0FFB74F"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type src:GridColumnSplitterAdorner}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type src:GridColumnSplitterAdorner}">
<Grid Width="{x:Static src:GridRailAdorner.SplitterWidth}">
<Grid.RowDefinitions>
<RowDefinition Height="10"/> <!-- 10=RailSize -->
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Path Name="railHandle" Fill="#FFE6E6FF" Stretch="Fill" Stroke="#FF584FFF" Data="M0,0 L1,0 0.5,1 z"/>
<Path Name="line" Stretch="Fill" Stroke="#FF584FFF" Grid.Row="2" Margin="0 -1 0 0" Data="M0.5,0 L0.5,1"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="railHandle" Property="Fill" Value="#FFFFB74F"/>
</Trigger>
<Trigger Property="IsPreview" Value="True">
<Setter TargetName="railHandle" Property="Stroke" Value="#D0FFB74F"/>
<Setter TargetName="line" Property="Stroke" Value="#D0FFB74F"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

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

@ -0,0 +1,195 @@ @@ -0,0 +1,195 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Input;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
/// <summary>
/// Adorner that displays the blue bar next to grids that can be used to create new rows/column.
/// </summary>
public class GridRailAdorner : Control
{
static GridRailAdorner()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(GridRailAdorner), new FrameworkPropertyMetadata(typeof(GridRailAdorner)));
}
readonly DesignItem gridItem;
readonly Grid grid;
readonly AdornerPanel adornerPanel;
readonly GridSplitterAdorner previewAdorner;
readonly Orientation orientation;
public const double RailSize = 10;
public const double SplitterWidth = 10;
public GridRailAdorner(DesignItem gridItem, AdornerPanel adornerPanel, Orientation orientation)
{
Debug.Assert(gridItem != null);
Debug.Assert(adornerPanel != null);
this.gridItem = gridItem;
this.grid = (Grid)gridItem.Component;
this.adornerPanel = adornerPanel;
this.orientation = orientation;
if (orientation == Orientation.Horizontal) {
this.Height = RailSize;
previewAdorner = new GridColumnSplitterAdorner();
} else { // vertical
this.Width = RailSize;
previewAdorner = new GridRowSplitterAdorner();
}
previewAdorner.IsPreview = true;
previewAdorner.IsHitTestVisible = false;
}
#region Handle mouse events to add a new row/column
protected override void OnMouseEnter(MouseEventArgs e)
{
base.OnMouseEnter(e);
adornerPanel.Children.Add(previewAdorner);
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
RelativePlacement rp = new RelativePlacement();
if (orientation == Orientation.Vertical) {
rp.XOffset = -RailSize;
rp.WidthOffset = RailSize;
rp.WidthRelativeToContentWidth = 1;
rp.HeightOffset = SplitterWidth;
rp.YOffset = e.GetPosition(this).Y - SplitterWidth / 2;
} else {
rp.YOffset = -RailSize;
rp.HeightOffset = RailSize;
rp.HeightRelativeToContentHeight = 1;
rp.WidthOffset = SplitterWidth;
rp.XOffset = e.GetPosition(this).X - SplitterWidth / 2;
}
AdornerPanel.SetPlacement(previewAdorner, rp);
}
protected override void OnMouseLeave(MouseEventArgs e)
{
base.OnMouseLeave(e);
adornerPanel.Children.Remove(previewAdorner);
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
e.Handled = true;
adornerPanel.Children.Remove(previewAdorner);
if (orientation == Orientation.Vertical) {
using (ChangeGroup changeGroup = gridItem.OpenGroup("Split grid row")) {
DesignItemProperty rowCollection = gridItem.Properties["RowDefinitions"];
if (rowCollection.CollectionElements.Count == 0) {
DesignItem firstRow = gridItem.Services.Component.RegisterComponentForDesigner(new RowDefinition());
rowCollection.CollectionElements.Add(firstRow);
grid.UpdateLayout(); // let WPF assign firstRow.ActualHeight
}
double insertionPosition = e.GetPosition(this).Y;
for (int i = 0; i < grid.RowDefinitions.Count; i++) {
RowDefinition row = grid.RowDefinitions[i];
if (row.Offset > insertionPosition) continue;
if (row.Offset + row.ActualHeight < insertionPosition) continue;
// split row
GridLength oldLength = (GridLength)row.GetValue(RowDefinition.HeightProperty);
GridLength newLength1, newLength2;
SplitLength(oldLength, insertionPosition - row.Offset, row.ActualHeight, out newLength1, out newLength2);
DesignItem newRowDefinition = gridItem.Services.Component.RegisterComponentForDesigner(new RowDefinition());
rowCollection.CollectionElements.Insert(i + 1, newRowDefinition);
rowCollection.CollectionElements[i].Properties[RowDefinition.HeightProperty].SetValue(newLength1);
newRowDefinition.Properties[RowDefinition.HeightProperty].SetValue(newLength2);
changeGroup.Commit();
break;
}
}
} else {
using (ChangeGroup changeGroup = gridItem.OpenGroup("Split grid column")) {
DesignItemProperty columnCollection = gridItem.Properties["ColumnDefinitions"];
if (columnCollection.CollectionElements.Count == 0) {
DesignItem firstColumn = gridItem.Services.Component.RegisterComponentForDesigner(new ColumnDefinition());
columnCollection.CollectionElements.Add(firstColumn);
grid.UpdateLayout(); // let WPF assign firstColumn.ActualWidth
}
double insertionPosition = e.GetPosition(this).X;
for (int i = 0; i < grid.ColumnDefinitions.Count; i++) {
ColumnDefinition column = grid.ColumnDefinitions[i];
if (column.Offset > insertionPosition) continue;
if (column.Offset + column.ActualWidth < insertionPosition) continue;
// split column
GridLength oldLength = (GridLength)column.GetValue(ColumnDefinition.WidthProperty);
GridLength newLength1, newLength2;
SplitLength(oldLength, insertionPosition - column.Offset, column.ActualWidth, out newLength1, out newLength2);
columnCollection.CollectionElements[i].Properties[ColumnDefinition.WidthProperty].SetValue(newLength1);
DesignItem newColumnDefinition = gridItem.Services.Component.RegisterComponentForDesigner(new ColumnDefinition());
newColumnDefinition.Properties[ColumnDefinition.WidthProperty].SetValue(newLength2);
columnCollection.CollectionElements.Insert(i + 1, newColumnDefinition);
changeGroup.Commit();
break;
}
}
}
}
void SplitLength(GridLength oldLength, double insertionPosition, double oldActualValue,
out GridLength newLength1, out GridLength newLength2)
{
if (oldLength.IsAuto) {
oldLength = new GridLength(oldActualValue);
}
double percentage = insertionPosition / oldActualValue;
newLength1 = new GridLength(oldLength.Value * percentage, oldLength.GridUnitType);
newLength2 = new GridLength(oldLength.Value - newLength1.Value, oldLength.GridUnitType);
}
#endregion
}
public class GridSplitterAdorner : Control
{
public static readonly DependencyProperty IsPreviewProperty
= DependencyProperty.Register("IsPreview", typeof(bool), typeof(GridSplitterAdorner), new PropertyMetadata(SharedInstances.BoxedFalse));
public bool IsPreview {
get { return (bool)GetValue(IsPreviewProperty); }
set { SetValue(IsPreviewProperty, SharedInstances.Box(value)); }
}
}
public class GridRowSplitterAdorner : GridSplitterAdorner
{
static GridRowSplitterAdorner()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(GridRowSplitterAdorner), new FrameworkPropertyMetadata(typeof(GridRowSplitterAdorner)));
CursorProperty.OverrideMetadata(typeof(GridRowSplitterAdorner), new FrameworkPropertyMetadata(Cursors.SizeNS));
}
}
public class GridColumnSplitterAdorner : GridSplitterAdorner
{
static GridColumnSplitterAdorner()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(GridColumnSplitterAdorner), new FrameworkPropertyMetadata(typeof(GridColumnSplitterAdorner)));
CursorProperty.OverrideMetadata(typeof(GridColumnSplitterAdorner), new FrameworkPropertyMetadata(Cursors.SizeWE));
}
}
}

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/WindowClone.cs

@ -28,11 +28,11 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -28,11 +28,11 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
//This style is defined in themes\generic.xaml
DefaultStyleKeyProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(typeof(WindowClone)));
Control.IsTabStopProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(false));
Control.IsTabStopProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(SharedInstances.BoxedFalse));
KeyboardNavigation.DirectionalNavigationProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(KeyboardNavigationMode.Cycle));
KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(KeyboardNavigationMode.Cycle));
KeyboardNavigation.ControlTabNavigationProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(KeyboardNavigationMode.Cycle));
FocusManager.IsFocusScopeProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(true));
FocusManager.IsFocusScopeProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(SharedInstances.BoxedTrue));
}
/// <summary>
@ -40,7 +40,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -40,7 +40,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
/// </summary>
public bool AllowsTransparency {
get { return (bool)GetValue(Window.AllowsTransparencyProperty); }
set { SetValue(Window.AllowsTransparencyProperty, value); }
set { SetValue(Window.AllowsTransparencyProperty, SharedInstances.Box(value)); }
}
/// <summary>
@ -94,7 +94,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -94,7 +94,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
/// </summary>
public bool ShowInTaskbar {
get { return (bool)GetValue(Window.ShowInTaskbarProperty); }
set { SetValue(Window.ShowInTaskbarProperty, value); }
set { SetValue(Window.ShowInTaskbarProperty, SharedInstances.Box(value)); }
}
/// <summary>
@ -127,7 +127,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -127,7 +127,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
/// </summary>
public bool Topmost {
get { return (bool)GetValue(Window.TopmostProperty); }
set { SetValue(Window.TopmostProperty, value); }
set { SetValue(Window.TopmostProperty, SharedInstances.Box(value)); }
}
WindowStartupLocation windowStartupLocation;

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs

@ -22,7 +22,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -22,7 +22,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
[ExtensionFor(typeof(Canvas))]
public sealed class CanvasPlacementSupport : BehaviorExtension, IPlacementBehavior
{
/// <inherits/>
protected override void OnInitialized()
{
base.OnInitialized();
@ -31,7 +30,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -31,7 +30,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
GrayOutDesignerExceptActiveArea grayOut;
/// <inherits/>
public bool CanPlace(ICollection<DesignItem> child, PlacementType type, PlacementAlignment position)
{
return type == PlacementType.Resize || type == PlacementType.Move
@ -39,7 +37,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -39,7 +37,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
|| type == PlacementType.AddItem;
}
/// <inherits/>
public Rect GetPosition(PlacementOperation operation, DesignItem childItem)
{
UIElement child = childItem.View;
@ -64,7 +61,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -64,7 +61,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
return v;
}
/// <inherits/>
public void SetPosition(PlacementInformation info)
{
UIElement child = info.Item.View;
@ -83,7 +79,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -83,7 +79,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
}
/// <inherits/>
public void BeginPlacement(PlacementOperation op)
{
if (op.Type == PlacementType.Move || op.Type == PlacementType.Resize) {
@ -91,19 +86,16 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -91,19 +86,16 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
}
/// <inherits/>
public void EndPlacement(PlacementOperation op)
{
GrayOutDesignerExceptActiveArea.Stop(ref grayOut);
}
/// <inherits/>
public bool CanLeaveContainer(PlacementOperation operation)
{
return true;
}
/// <inherits/>
public void LeaveContainer(PlacementOperation operation)
{
EndPlacement(operation);
@ -114,13 +106,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -114,13 +106,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
}
/// <inherits/>
public bool CanEnterContainer(PlacementOperation operation)
{
return true;
}
/// <inherits/>
public void EnterContainer(PlacementOperation operation)
{
foreach (PlacementInformation info in operation.PlacedItems) {

130
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridAdornerProvider.cs

@ -0,0 +1,130 @@ @@ -0,0 +1,130 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Threading;
using ICSharpCode.WpfDesign.Designer.Controls;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
/// <summary>
/// Allows arranging the rows/column on a grid.
/// </summary>
[ExtensionFor(typeof(Grid))]
public class GridAdornerProvider : PrimarySelectionAdornerProvider
{
sealed class RowSplitterPlacement : AdornerPlacement
{
readonly RowDefinition row;
public RowSplitterPlacement(RowDefinition row) { this.row = row; }
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{
adorner.Arrange(new Rect(-GridRailAdorner.RailSize,
row.Offset - GridRailAdorner.SplitterWidth / 2,
GridRailAdorner.RailSize + adornedElementSize.Width,
GridRailAdorner.SplitterWidth));
}
}
sealed class ColumnSplitterPlacement : AdornerPlacement
{
readonly ColumnDefinition column;
public ColumnSplitterPlacement(ColumnDefinition column) { this.column = column; }
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{
adorner.Arrange(new Rect(column.Offset - GridRailAdorner.SplitterWidth / 2,
-GridRailAdorner.RailSize,
GridRailAdorner.SplitterWidth,
GridRailAdorner.RailSize + adornedElementSize.Height));
}
}
AdornerPanel adornerPanel = new AdornerPanel();
GridRailAdorner topBar, leftBar;
protected override void OnInitialized()
{
leftBar = new GridRailAdorner(this.ExtendedItem, adornerPanel, Orientation.Vertical);
topBar = new GridRailAdorner(this.ExtendedItem, adornerPanel, Orientation.Horizontal);
AdornerPanel.SetPlacement(leftBar, new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Stretch));
AdornerPanel.SetPlacement(topBar, new RelativePlacement(HorizontalAlignment.Stretch, VerticalAlignment.Top));
adornerPanel.Children.Add(leftBar);
adornerPanel.Children.Add(topBar);
this.Adorners.Add(adornerPanel);
CreateSplitter();
this.ExtendedItem.PropertyChanged += OnPropertyChanged;
base.OnInitialized();
}
protected override void OnRemove()
{
this.ExtendedItem.PropertyChanged -= OnPropertyChanged;
base.OnRemove();
}
void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "RowDefinitions" || e.PropertyName == "ColumnDefinitions") {
CreateSplitter();
}
}
readonly List<GridSplitterAdorner> splitterList = new List<GridSplitterAdorner>();
/// <summary>
/// flag used to unsure that the asynchronus splitter creation is only enqueued once
/// </summary>
bool requireSplitterRecreation;
void CreateSplitter()
{
if (requireSplitterRecreation) return;
requireSplitterRecreation = true;
// splitter creation is asynchronous to prevent unnecessary splitter re-creation when multiple
// changes to the collection are done.
// It also ensures that the Offset property of new rows/columns is initialized when the splitter
// is added.
Dispatcher.CurrentDispatcher.BeginInvoke(
DispatcherPriority.Loaded, // Loaded = after layout, but before input
(Action)delegate {
requireSplitterRecreation = false;
foreach (GridSplitterAdorner splitter in splitterList) {
adornerPanel.Children.Remove(splitter);
}
splitterList.Clear();
Grid grid = (Grid)this.ExtendedItem.Component;
for (int i = 1; i < grid.RowDefinitions.Count; i++) {
RowDefinition row = grid.RowDefinitions[i];
GridRowSplitterAdorner splitter = new GridRowSplitterAdorner();
AdornerPanel.SetPlacement(splitter, new RowSplitterPlacement(row));
adornerPanel.Children.Add(splitter);
splitterList.Add(splitter);
}
for (int i = 1; i < grid.ColumnDefinitions.Count; i++) {
ColumnDefinition column = grid.ColumnDefinitions[i];
GridColumnSplitterAdorner splitter = new GridColumnSplitterAdorner();
AdornerPanel.SetPlacement(splitter, new ColumnSplitterPlacement(column));
adornerPanel.Children.Add(splitter);
splitterList.Add(splitter);
}
});
}
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelSelectionHandler.cs

@ -26,14 +26,12 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -26,14 +26,12 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
[ExtensionFor(typeof(Panel))]
public class PanelSelectionHandler : BehaviorExtension, IHandlePointerToolMouseDown
{
/// <inherit/>
protected override void OnInitialized()
{
base.OnInitialized();
this.ExtendedItem.AddBehavior(typeof(IHandlePointerToolMouseDown), this);
}
/// <inherit/>
public void HandleSelectionMouseDown(IDesignPanel designPanel, MouseButtonEventArgs e, DesignPanelHitTestResult result)
{
new RangeSelectionGesture(result.ModelHit).Start(designPanel, e);

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WindowResizeBehavior.cs

@ -18,14 +18,12 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -18,14 +18,12 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
[ExtensionFor(typeof(Window))]
public class WindowResizeBehavior : BehaviorExtension, IRootPlacementBehavior
{
/// <inherits/>
protected override void OnInitialized()
{
base.OnInitialized();
this.ExtendedItem.AddBehavior(typeof(IRootPlacementBehavior), this);
}
/// <inherits/>
public bool CanPlace(ICollection<DesignItem> children, PlacementType type, PlacementAlignment position)
{
return type == PlacementType.Resize &&
@ -35,24 +33,20 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -35,24 +33,20 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
/// <inherits/>
public void BeginPlacement(PlacementOperation operation)
{
}
/// <inherits/>
public void EndPlacement(PlacementOperation operation)
{
}
/// <inherits/>
public Rect GetPosition(PlacementOperation operation, DesignItem childItem)
{
UIElement child = childItem.View;
return new Rect(0, 0, ModelTools.GetWidth(child), ModelTools.GetHeight(child));
}
/// <inherits/>
public void SetPosition(PlacementInformation info)
{
UIElement element = info.Item.View;
@ -65,25 +59,21 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -65,25 +59,21 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
}
/// <inherits/>
public bool CanLeaveContainer(PlacementOperation operation)
{
return false;
}
/// <inherits/>
public void LeaveContainer(PlacementOperation operation)
{
throw new NotSupportedException();
}
/// <inherits/>
public bool CanEnterContainer(PlacementOperation operation)
{
return false;
}
/// <inherits/>
public void EnterContainer(PlacementOperation operation)
{
throw new NotSupportedException();

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Func.cs

@ -11,6 +11,8 @@ using System.Collections.Generic; @@ -11,6 +11,8 @@ using System.Collections.Generic;
namespace ICSharpCode.WpfDesign.Designer
{
delegate void Action();
// Static helpers that should become extension methods in the future
static class Func
{

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs

@ -38,12 +38,10 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -38,12 +38,10 @@ namespace ICSharpCode.WpfDesign.Designer.Services
get { return componentType; }
}
/// <inherits/>
public Cursor Cursor {
get { return null; }
}
/// <inherits/>
public void Activate(IDesignPanel designPanel)
{
designPanel.MouseDown += OnMouseDown;
@ -51,7 +49,6 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -51,7 +49,6 @@ namespace ICSharpCode.WpfDesign.Designer.Services
designPanel.Drop += OnDrop;
}
/// <inherits/>
public void Deactivate(IDesignPanel designPanel)
{
designPanel.MouseDown -= OnMouseDown;

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs

@ -36,7 +36,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -36,7 +36,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
selectedItems = clickedOn.Services.Selection.SelectedItems;
if (!selectedItems.Contains(clickedOn))
selectedItems = new DesignItem[0];
selectedItems = SharedInstances.EmptyDesignItemArray;
}
protected override void OnDragStarted(MouseEventArgs e)

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/SelectionService.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -52,7 +52,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
public void SetSelectedComponents(ICollection<DesignItem> components, SelectionTypes selectionType)
{
if (components == null)
components = new DesignItem[0];
components = SharedInstances.EmptyDesignItemArray;
if (SelectionChanging != null)
SelectionChanging(this, EventArgs.Empty);

24
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/SharedInstances.cs

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.WpfDesign.Designer
{
static class SharedInstances
{
internal static readonly object BoxedTrue = true;
internal static readonly object BoxedFalse = false;
internal static readonly object[] EmptyObjectArray = new object[0];
internal static readonly DesignItem[] EmptyDesignItemArray = new DesignItem[0];
internal static object Box(bool value)
{
return value ? BoxedTrue : BoxedFalse;
}
}
}

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<OutputPath>..\..\..\..\..\..\AddIns\AddIns\DisplayBindings\WpfDesign\</OutputPath>
<DocumentationFile>..\..\..\..\..\..\AddIns\AddIns\DisplayBindings\WpfDesign\ICSharpCode.WpfDesign.Designer.xml</DocumentationFile>
<NoWarn>1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
@ -58,6 +59,7 @@ @@ -58,6 +59,7 @@
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Controls\AdornerLayer.cs" />
<Compile Include="Controls\ContainerDragHandle.cs" />
<Compile Include="Controls\GridAdorner.cs" />
<Compile Include="Controls\SelectionFrame.cs" />
<Compile Include="Controls\ErrorBalloon.cs" />
<Compile Include="Controls\GrayOutDesignerExceptActiveArea.cs" />
@ -71,6 +73,7 @@ @@ -71,6 +73,7 @@
<Compile Include="Controls\TypeEditors\BrushEditor.cs" />
<Compile Include="Controls\WindowClone.cs" />
<Compile Include="DesignPanel.cs" />
<Compile Include="Extensions\GridAdornerProvider.cs" />
<Compile Include="ModelTools.cs" />
<Compile Include="Extensions\CanvasPlacementSupport.cs" />
<Compile Include="Extensions\PanelInstanceFactory.cs" />
@ -94,6 +97,7 @@ @@ -94,6 +97,7 @@
<Compile Include="Services\UndoService.cs" />
<Compile Include="Services\ViewService.cs" />
<Compile Include="DesignSurface.cs" />
<Compile Include="SharedInstances.cs" />
<Compile Include="Xaml\XamlModelCollectionElementsCollection.cs" />
<Compile Include="Xaml\XamlComponentService.cs" />
<Compile Include="Xaml\XamlDesignContext.cs" />

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignItem.cs

@ -122,9 +122,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -122,9 +122,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
get { return _properties; }
}
internal void NotifyPropertyChanged(string propertyName)
internal void NotifyPropertyChanged(XamlModelProperty property)
{
OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs(propertyName));
Debug.Assert(property != null);
OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs(property.Name));
}
}
}

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs

@ -190,11 +190,13 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -190,11 +190,13 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
public void Do()
{
collection.InsertInternal(index, item);
collection.modelProperty.DesignItem.NotifyPropertyChanged(collection.modelProperty);
}
public void Undo()
{
collection.RemoveInternal(index, item);
collection.modelProperty.DesignItem.NotifyPropertyChanged(collection.modelProperty);
}
}
@ -226,11 +228,13 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -226,11 +228,13 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
public void Do()
{
collection.RemoveInternal(index, item);
collection.modelProperty.DesignItem.NotifyPropertyChanged(collection.modelProperty);
}
public void Undo()
{
collection.InsertInternal(index, item);
collection.modelProperty.DesignItem.NotifyPropertyChanged(collection.modelProperty);
}
}
}

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelProperty.cs

@ -190,7 +190,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -190,7 +190,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
_property.ValueOnInstance = value;
_property.PropertyValue = newValue;
_designItem.NotifyPropertyChanged(this.Name);
_designItem.NotifyPropertyChanged(this);
}
public override void Reset()
@ -206,7 +206,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -206,7 +206,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
{
if (_property.IsSet) {
_property.Reset();
_designItem.NotifyPropertyChanged(this.Name);
_designItem.NotifyPropertyChanged(this);
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionElementsCollection.cs

@ -55,7 +55,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -55,7 +55,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
XamlPropertyInfo info = property.propertyInfo;
object collection = info.GetValue(property.ParentObject.Instance);
info.AddValue(collection, item);
CollectionSupport.Insert(info.ReturnType, collection, item, index);
item.ParentProperty = property;
property.InsertNodeInCollection(item.GetNodeForCollection(), index);

9
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs

@ -44,6 +44,15 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -44,6 +44,15 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
public static void Insert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index)
{
collectionType.InvokeMember(
"Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance,
null, collectionInstance,
new object[] { index, newElement.GetValueFor(null) },
CultureInfo.InvariantCulture);
}
static readonly Type[] RemoveAtParameters = { typeof(int) };
public static bool RemoveItemAt(Type collectionType, object collectionInstance, int index)

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs

@ -220,7 +220,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -220,7 +220,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
XamlPropertyValue childValue = ParseValue(childNode);
if (childValue != null) {
if (defaultProperty != null && defaultProperty.IsCollection) {
defaultProperty.AddValue(defaultPropertyValue, childValue);
CollectionSupport.AddToCollection(defaultProperty.ReturnType, defaultPropertyValue, childValue);
defaultCollectionProperty.ParserAddCollectionElement(null, childValue);
} else {
if (setDefaultValueTo != null)
@ -448,7 +448,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -448,7 +448,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
XamlPropertyValue childValue = ParseValue(childNode);
if (childValue != null) {
if (propertyInfo.IsCollection) {
propertyInfo.AddValue(collectionInstance, childValue);
CollectionSupport.AddToCollection(propertyInfo.ReturnType, collectionInstance, childValue);
collectionProperty.ParserAddCollectionElement(element, childValue);
} else {
if (valueWasSet)

16
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlPropertyInfo.cs

@ -34,7 +34,6 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -34,7 +34,6 @@ namespace ICSharpCode.WpfDesign.XamlDom
public abstract bool IsCollection { get; }
public virtual bool IsEvent { get { return false; } }
public abstract string Category { get; }
internal abstract void AddValue(object collectionInstance, XamlPropertyValue newElement);
}
#region XamlDependencyPropertyInfo
@ -100,11 +99,6 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -100,11 +99,6 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
((DependencyObject)instance).ClearValue(property);
}
internal override void AddValue(object collectionInstance, XamlPropertyValue newElement)
{
throw new NotSupportedException();
}
}
#endregion
@ -173,11 +167,6 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -173,11 +167,6 @@ namespace ICSharpCode.WpfDesign.XamlDom
return CollectionSupport.IsCollectionType(_propertyDescriptor.PropertyType);
}
}
internal override void AddValue(object collectionInstance, XamlPropertyValue newElement)
{
CollectionSupport.AddToCollection(_propertyDescriptor.PropertyType, collectionInstance, newElement);
}
}
#endregion
@ -243,11 +232,6 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -243,11 +232,6 @@ namespace ICSharpCode.WpfDesign.XamlDom
public override bool IsCollection {
get { return false; }
}
internal override void AddValue(object collectionInstance, XamlPropertyValue newElement)
{
throw new NotSupportedException();
}
}
#endregion
}

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionManager.cs

@ -216,6 +216,8 @@ namespace ICSharpCode.WpfDesign.Extensions @@ -216,6 +216,8 @@ namespace ICSharpCode.WpfDesign.Extensions
#endregion
#region Special extensions (Instance Factory)
static readonly object[] emptyObjectArray = new object[0];
/// <summary>
/// Create an instance of the specified type using the specified arguments.
/// The instance is created using a CustomInstanceFactory registered for the type,
@ -226,7 +228,7 @@ namespace ICSharpCode.WpfDesign.Extensions @@ -226,7 +228,7 @@ namespace ICSharpCode.WpfDesign.Extensions
if (instanceType == null)
throw new ArgumentNullException("instanceType");
if (arguments == null)
arguments = new object[0];
arguments = emptyObjectArray;
foreach (Type extensionType in GetExtensionTypes(instanceType)) {
if (typeof(CustomInstanceFactory).IsAssignableFrom(extensionType)) {
CustomInstanceFactory factory = (CustomInstanceFactory)Activator.CreateInstance(extensionType);

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementAlignment.cs

@ -61,7 +61,9 @@ namespace ICSharpCode.WpfDesign @@ -61,7 +61,9 @@ namespace ICSharpCode.WpfDesign
return this.horizontal == other.horizontal && this.vertical == other.vertical;
}
/// <inherit/>
/// <summary>
/// Gets the hash code.
/// </summary>
public override int GetHashCode()
{
unchecked {

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementType.cs

@ -56,7 +56,9 @@ namespace ICSharpCode.WpfDesign @@ -56,7 +56,9 @@ namespace ICSharpCode.WpfDesign
return new PlacementType(name);
}
/// <inherit/>
/// <summary>
/// Gets the name used to register this PlacementType.
/// </summary>
public override string ToString()
{
return name;

Loading…
Cancel
Save