Browse Source

- If element selected it can be resized (independent from IPlacementBehavior)

- DefaultPlacementBehavior through ContentProperty
- Preparation for guidelines done

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3333 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Ivan Shumilin 18 years ago
parent
commit
e5f10aa958
  1. 18
      samples/XamlDesigner/OutlineNode.cs
  2. 3
      samples/XamlDesigner/ToolboxView.xaml
  3. 11
      samples/XamlDesigner/ToolboxView.xaml.cs
  4. 8
      samples/XamlDesigner/XamlDesigner.csproj
  5. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs
  6. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs
  7. 74
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs
  8. 91
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs
  9. 63
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs
  10. 11
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GuideLineManager.cs
  11. 14
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GuideLinePlacementBehavior.cs
  12. 123
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs
  13. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
  14. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGrid.cs
  15. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs
  16. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs
  17. 25
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  18. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs
  19. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs
  20. 16
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs

18
samples/XamlDesigner/OutlineNode.cs

@ -7,6 +7,7 @@ using ICSharpCode.WpfDesign;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Collections; using System.Collections;
using ICSharpCode.WpfDesign.Designer; using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.XamlDesigner namespace ICSharpCode.XamlDesigner
{ {
@ -104,6 +105,8 @@ namespace ICSharpCode.XamlDesigner
void UpdateChildren() void UpdateChildren()
{ {
Children.Clear();
if (DesignItem.ContentPropertyName != null) { if (DesignItem.ContentPropertyName != null) {
var content = DesignItem.ContentProperty; var content = DesignItem.ContentProperty;
if (content.IsCollection) { if (content.IsCollection) {
@ -119,8 +122,6 @@ namespace ICSharpCode.XamlDesigner
void UpdateChildrenCore(IEnumerable<DesignItem> items) void UpdateChildrenCore(IEnumerable<DesignItem> items)
{ {
Children.Clear();
foreach (var item in items) { foreach (var item in items) {
if (ModelTools.CanSelectComponent(item)) { if (ModelTools.CanSelectComponent(item)) {
var node = OutlineNode.Create(item); var node = OutlineNode.Create(item);
@ -129,13 +130,14 @@ namespace ICSharpCode.XamlDesigner
} }
} }
// TODO: Outline and IPlacementBehavior must use the same logic (put it inside DesignItem)
public bool CanInsert(IEnumerable<OutlineNode> nodes, OutlineNode after, bool copy) public bool CanInsert(IEnumerable<OutlineNode> nodes, OutlineNode after, bool copy)
{ {
if (DesignItem.ContentPropertyName == null) return false; if (DesignItem.ContentPropertyName == null) return false;
if (DesignItem.ContentProperty.IsCollection) { if (DesignItem.ContentProperty.IsCollection) {
foreach (var node in nodes) { foreach (var node in nodes) {
if (!CanCollectionAdd(DesignItem.ContentProperty.ReturnType, if (!CollectionSupport.CanCollectionAdd(DesignItem.ContentProperty.ReturnType,
node.DesignItem.ComponentType)) { node.DesignItem.ComponentType)) {
return false; return false;
} }
@ -149,16 +151,6 @@ namespace ICSharpCode.XamlDesigner
} }
} }
static bool CanCollectionAdd(Type col, Type item)
{
var e = col.GetInterface("IEnumerable`1");
if (e != null && e.IsGenericType) {
var a = e.GetGenericArguments()[0];
return a.IsAssignableFrom(item);
}
return true;
}
public void Insert(IEnumerable<OutlineNode> nodes, OutlineNode after, bool copy) public void Insert(IEnumerable<OutlineNode> nodes, OutlineNode after, bool copy)
{ {
if (copy) { if (copy) {

3
samples/XamlDesigner/ToolboxView.xaml

@ -20,7 +20,6 @@
<TreeView x:Name="uxTreeView" <TreeView x:Name="uxTreeView"
ItemsSource="{Binding AssemblyNodes}" ItemsSource="{Binding AssemblyNodes}"
BorderThickness="0" BorderThickness="0"/>
SelectedItemChanged="uxTreeView_SelectedItemChanged"/>
</UserControl> </UserControl>

11
samples/XamlDesigner/ToolboxView.xaml.cs

@ -26,11 +26,13 @@ namespace ICSharpCode.XamlDesigner
InitializeComponent(); InitializeComponent();
new DragListener(this).DragStarted += Toolbox_DragStarted; new DragListener(this).DragStarted += Toolbox_DragStarted;
uxTreeView.SelectedItemChanged += uxTreeView_SelectedItemChanged;
uxTreeView.GotKeyboardFocus += uxTreeView_GotKeyboardFocus;
} }
void Toolbox_DragStarted(object sender, MouseButtonEventArgs e) void uxTreeView_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{ {
PrepareTool(e.GetDataContext() as ControlNode, true); PrepareTool(uxTreeView.SelectedItem as ControlNode, false);
} }
void uxTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) void uxTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
@ -38,6 +40,11 @@ namespace ICSharpCode.XamlDesigner
PrepareTool(uxTreeView.SelectedItem as ControlNode, false); PrepareTool(uxTreeView.SelectedItem as ControlNode, false);
} }
void Toolbox_DragStarted(object sender, MouseButtonEventArgs e)
{
PrepareTool(e.GetDataContext() as ControlNode, true);
}
void PrepareTool(ControlNode node, bool drag) void PrepareTool(ControlNode node, bool drag)
{ {
if (node != null) { if (node != null) {

8
samples/XamlDesigner/XamlDesigner.csproj

@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30428</ProductVersion> <ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{27DA2B5C-2AAA-4478-AB00-3E184273C241}</ProjectGuid> <ProjectGuid>{27DA2B5C-2AAA-4478-AB00-3E184273C241}</ProjectGuid>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
@ -182,6 +182,12 @@
<Resource Include="Images\Reference.png" /> <Resource Include="Images\Reference.png" />
<Resource Include="Images\Tag.png" /> <Resource Include="Images\Tag.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\AddIns\DisplayBindings\WpfDesign\WpfDesign.XamlDom\Project\WpfDesign.XamlDom.csproj">
<Project>{88DA149F-21B2-48AB-82C4-28FB6BDFD783}</Project>
<Name>WpfDesign.XamlDom</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/BasicMetadata.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs

@ -14,7 +14,7 @@ using System.Windows.Shapes;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
using System.Windows.Data; using System.Windows.Data;
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid namespace ICSharpCode.WpfDesign.Designer
{ {
public class BasicMetadata public class BasicMetadata
{ {
@ -562,6 +562,8 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
Metadata.AddAdvancedProperty(typeof(BindingBase), "FallbackValue"); Metadata.AddAdvancedProperty(typeof(BindingBase), "FallbackValue");
Metadata.AddAdvancedProperty(typeof(BindingBase), "StringFormat"); Metadata.AddAdvancedProperty(typeof(BindingBase), "StringFormat");
Metadata.AddAdvancedProperty(typeof(BindingBase), "TargetNullValue"); Metadata.AddAdvancedProperty(typeof(BindingBase), "TargetNullValue");
//Metadata.DisablePlacement(typeof(Button));
} }
} }
} }

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs

@ -35,6 +35,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
if (a != null && a.Key == Key.Escape) { if (a != null && a.Key == Key.Escape) {
Mouse.Capture(null); Mouse.Capture(null);
CurrentListener.IsDown = false; CurrentListener.IsDown = false;
CurrentListener.IsCanceled = true;
CurrentListener.Complete(); CurrentListener.Complete();
} }
} }
@ -46,6 +47,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
CurrentPoint = StartPoint; CurrentPoint = StartPoint;
DeltaDelta = new Vector(); DeltaDelta = new Vector();
IsDown = true; IsDown = true;
IsCanceled = false;
} }
void Target_MouseMove(object sender, MouseEventArgs e) void Target_MouseMove(object sender, MouseEventArgs e)
@ -100,6 +102,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
public Vector DeltaDelta { get; private set; } public Vector DeltaDelta { get; private set; }
public bool IsActive { get; private set; } public bool IsActive { get; private set; }
public bool IsDown { get; private set; } public bool IsDown { get; private set; }
public bool IsCanceled { get; private set; }
public Vector Delta { public Vector Delta {
get { return CurrentPoint - StartPoint; } get { return CurrentPoint - StartPoint; }

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

@ -18,30 +18,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// <summary> /// <summary>
/// Provides <see cref="IPlacementBehavior"/> behavior for <see cref="Canvas"/>. /// Provides <see cref="IPlacementBehavior"/> behavior for <see cref="Canvas"/>.
/// </summary> /// </summary>
[ExtensionFor(typeof(Canvas))] [ExtensionFor(typeof(Canvas), OverrideExtension=typeof(DefaultPlacementBehavior))]
public sealed class CanvasPlacementSupport : BehaviorExtension, IPlacementBehavior public sealed class CanvasPlacementSupport : GuideLinePlacementBehavior
{ {
protected override void OnInitialized()
{
base.OnInitialized();
this.ExtendedItem.AddBehavior(typeof(IPlacementBehavior), this);
}
GrayOutDesignerExceptActiveArea grayOut;
public bool CanPlace(ICollection<DesignItem> child, PlacementType type, PlacementAlignment position)
{
return type == PlacementType.Resize || type == PlacementType.Move
|| type == PlacementType.Delete
|| type == PlacementType.AddItem;
}
public Rect GetPosition(PlacementOperation operation, DesignItem childItem)
{
UIElement child = childItem.View;
return new Rect(GetLeft(child), GetTop(child), ModelTools.GetWidth(child), ModelTools.GetHeight(child));
}
static double GetLeft(UIElement element) static double GetLeft(UIElement element)
{ {
double v = (double)element.GetValue(Canvas.LeftProperty); double v = (double)element.GetValue(Canvas.LeftProperty);
@ -60,66 +39,43 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
return v; return v;
} }
public void SetPosition(PlacementInformation info) public override Rect GetPosition(PlacementOperation operation, DesignItem childItem)
{
UIElement child = childItem.View;
return new Rect(GetLeft(child), GetTop(child), ModelTools.GetWidth(child), ModelTools.GetHeight(child));
}
public override void SetPosition(PlacementInformation info)
{ {
base.SetPosition(info);
UIElement child = info.Item.View; UIElement child = info.Item.View;
Rect newPosition = info.Bounds; Rect newPosition = info.Bounds;
if (newPosition.Left != GetLeft(child)) { if (newPosition.Left != GetLeft(child)) {
info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(newPosition.Left); info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(newPosition.Left);
} }
if (newPosition.Top != GetTop(child)) { if (newPosition.Top != GetTop(child)) {
info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(newPosition.Top); info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(newPosition.Top);
} }
if (newPosition.Width != ModelTools.GetWidth(child)) {
info.Item.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(newPosition.Right - newPosition.Left);
}
if (newPosition.Height != ModelTools.GetHeight(child)) {
info.Item.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(newPosition.Bottom - newPosition.Top);
}
}
public void BeginPlacement(PlacementOperation op)
{
if (op.Type == PlacementType.Move || op.Type == PlacementType.Resize) {
GrayOutDesignerExceptActiveArea.Start(ref grayOut, this.Services, this.ExtendedItem.View);
}
}
public void EndPlacement(PlacementOperation op)
{
GrayOutDesignerExceptActiveArea.Stop(ref grayOut);
}
public bool CanLeaveContainer(PlacementOperation operation)
{
return true;
} }
public void LeaveContainer(PlacementOperation operation) public override void LeaveContainer(PlacementOperation operation)
{ {
EndPlacement(operation); base.LeaveContainer(operation);
foreach (PlacementInformation info in operation.PlacedItems) { foreach (PlacementInformation info in operation.PlacedItems) {
this.ExtendedItem.Properties["Children"].CollectionElements.Remove(info.Item);
info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset(); info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset();
info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).Reset(); info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).Reset();
} }
} }
public bool CanEnterContainer(PlacementOperation operation) public override void EnterContainer(PlacementOperation operation)
{
return true;
}
public void EnterContainer(PlacementOperation operation)
{ {
base.EnterContainer(operation);
foreach (PlacementInformation info in operation.PlacedItems) { foreach (PlacementInformation info in operation.PlacedItems) {
this.ExtendedItem.Properties["Children"].CollectionElements.Add(info.Item);
SetPosition(info);
info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].Reset(); info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].Reset();
info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].Reset(); info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].Reset();
info.Item.Properties[FrameworkElement.MarginProperty].Reset(); info.Item.Properties[FrameworkElement.MarginProperty].Reset();
} }
BeginPlacement(operation);
} }
} }
} }

91
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs

@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.WpfDesign.Extensions;
using System.Windows.Controls;
using System.Windows;
using ICSharpCode.WpfDesign.Designer.Controls;
using System.Diagnostics;
using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
[ExtensionFor(typeof(UIElement))]
public class DefaultPlacementBehavior : BehaviorExtension, IPlacementBehavior
{
protected override void OnInitialized()
{
base.OnInitialized();
if (ExtendedItem.ContentProperty == null ||
Metadata.IsPlacementDisabled(ExtendedItem.ComponentType))
return;
ExtendedItem.AddBehavior(typeof(IPlacementBehavior), this);
}
public virtual bool CanPlace(ICollection<DesignItem> childItems, PlacementType type, PlacementAlignment position)
{
return true;
}
public virtual void BeginPlacement(PlacementOperation operation)
{
}
public virtual void EndPlacement(PlacementOperation operation)
{
}
public virtual Rect GetPosition(PlacementOperation operation, DesignItem item)
{
var p = item.View.TranslatePoint(new Point(), operation.CurrentContainer.View);
return new Rect(p, item.View.RenderSize);
}
public virtual void SetPosition(PlacementInformation info)
{
ModelTools.Resize(info.Item, info.Bounds.Width, info.Bounds.Height);
}
public virtual bool CanLeaveContainer(PlacementOperation operation)
{
return true;
}
public virtual void LeaveContainer(PlacementOperation operation)
{
if (ExtendedItem.ContentProperty.IsCollection) {
foreach (var info in operation.PlacedItems) {
ExtendedItem.ContentProperty.CollectionElements.Remove(info.Item);
}
} else {
ExtendedItem.ContentProperty.Reset();
}
}
public virtual bool CanEnterContainer(PlacementOperation operation)
{
if (ExtendedItem.ContentProperty.IsCollection &&
CollectionSupport.CanCollectionAdd(ExtendedItem.ContentProperty.ReturnType,
operation.PlacedItems.Select(p => p.Item.Component)))
return true;
return !ExtendedItem.ContentProperty.IsSet;
}
public virtual void EnterContainer(PlacementOperation operation)
{
if (ExtendedItem.ContentProperty.IsCollection) {
foreach (var info in operation.PlacedItems) {
ExtendedItem.ContentProperty.CollectionElements.Add(info.Item);
}
} else {
ExtendedItem.ContentProperty.SetValue(operation.PlacedItems[0].Item);
}
if (operation.Type == PlacementType.AddItem) {
foreach (var info in operation.PlacedItems) {
SetPosition(info);
}
}
}
}
}

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

@ -21,8 +21,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// <summary> /// <summary>
/// Provides <see cref="IPlacementBehavior"/> behavior for <see cref="Grid"/>. /// Provides <see cref="IPlacementBehavior"/> behavior for <see cref="Grid"/>.
/// </summary> /// </summary>
[ExtensionFor(typeof(Grid))] [ExtensionFor(typeof(Grid), OverrideExtension=typeof(DefaultPlacementBehavior))]
public sealed class GridPlacementSupport : BehaviorExtension, IPlacementBehavior public sealed class GridPlacementSupport : GuideLinePlacementBehavior
{ {
Grid grid; Grid grid;
@ -30,28 +30,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
base.OnInitialized(); base.OnInitialized();
grid = (Grid)this.ExtendedItem.Component; grid = (Grid)this.ExtendedItem.Component;
this.ExtendedItem.AddBehavior(typeof(IPlacementBehavior), this);
} }
public bool CanPlace(ICollection<DesignItem> childItems, PlacementType type, PlacementAlignment position) public override Rect GetPosition(PlacementOperation operation, DesignItem child)
{
return type == PlacementType.Resize || type == PlacementType.Move
|| type == PlacementType.Delete
|| type == PlacementType.AddItem;
}
GrayOutDesignerExceptActiveArea grayOut;
public void BeginPlacement(PlacementOperation operation)
{
}
public void EndPlacement(PlacementOperation operation)
{
GrayOutDesignerExceptActiveArea.Stop(ref grayOut);
}
public Rect GetPosition(PlacementOperation operation, DesignItem child)
{ {
FrameworkElement obj = child.Component as FrameworkElement; FrameworkElement obj = child.Component as FrameworkElement;
if (obj == null) return new Rect(); if (obj == null) return new Rect();
@ -217,8 +198,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
} }
} }
public void SetPosition(PlacementInformation info) public override void SetPosition(PlacementInformation info)
{ {
base.SetPosition(info);
if (info.Operation.Type == PlacementType.AddItem) { if (info.Operation.Type == PlacementType.AddItem) {
SetColumn(info.Item, GetColumnIndex(info.Bounds.Left), 1); SetColumn(info.Item, GetColumnIndex(info.Bounds.Left), 1);
SetRow(info.Item, GetRowIndex(info.Bounds.Top), 1); SetRow(info.Item, GetRowIndex(info.Bounds.Top), 1);
@ -236,11 +218,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
new Point(GetColumnOffset(leftColumnIndex), GetRowOffset(topRowIndex)), new Point(GetColumnOffset(leftColumnIndex), GetRowOffset(topRowIndex)),
new Point(GetColumnOffset(rightColumnIndex + 1), GetRowOffset(bottomRowIndex + 1)) new Point(GetColumnOffset(rightColumnIndex + 1), GetRowOffset(bottomRowIndex + 1))
); );
if (grayOut != null) {
grayOut.AnimateActiveAreaRectTo(availableSpaceRect);
} else {
GrayOutDesignerExceptActiveArea.Start(ref grayOut, this.Services, this.ExtendedItem.View, availableSpaceRect);
}
HorizontalAlignment ha = (HorizontalAlignment)info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].ValueOnInstance; HorizontalAlignment ha = (HorizontalAlignment)info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].ValueOnInstance;
VerticalAlignment va = (VerticalAlignment)info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].ValueOnInstance; VerticalAlignment va = (VerticalAlignment)info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].ValueOnInstance;
@ -272,14 +249,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
} }
} }
public bool CanLeaveContainer(PlacementOperation operation) public override void LeaveContainer(PlacementOperation operation)
{
return true;
}
public void LeaveContainer(PlacementOperation operation)
{ {
EndPlacement(operation); base.LeaveContainer(operation);
foreach (PlacementInformation info in operation.PlacedItems) { foreach (PlacementInformation info in operation.PlacedItems) {
if (info.Item.ComponentType == typeof(ColumnDefinition)) { if (info.Item.ComponentType == typeof(ColumnDefinition)) {
// TODO: combine the width of the deleted column with the previous column // TODO: combine the width of the deleted column with the previous column
@ -287,27 +259,20 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
} else if (info.Item.ComponentType == typeof(RowDefinition)) { } else if (info.Item.ComponentType == typeof(RowDefinition)) {
this.ExtendedItem.Properties["RowDefinitions"].CollectionElements.Remove(info.Item); this.ExtendedItem.Properties["RowDefinitions"].CollectionElements.Remove(info.Item);
} else { } else {
this.ExtendedItem.Properties["Children"].CollectionElements.Remove(info.Item);
info.Item.Properties.GetAttachedProperty(Grid.RowProperty).Reset(); info.Item.Properties.GetAttachedProperty(Grid.RowProperty).Reset();
info.Item.Properties.GetAttachedProperty(Grid.ColumnProperty).Reset(); info.Item.Properties.GetAttachedProperty(Grid.ColumnProperty).Reset();
info.Item.Properties.GetAttachedProperty(Grid.RowSpanProperty).Reset(); info.Item.Properties.GetAttachedProperty(Grid.RowSpanProperty).Reset();
info.Item.Properties.GetAttachedProperty(Grid.ColumnSpanProperty).Reset(); info.Item.Properties.GetAttachedProperty(Grid.ColumnSpanProperty).Reset();
}
}
}
public bool CanEnterContainer(PlacementOperation operation) HorizontalAlignment ha = (HorizontalAlignment)info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].ValueOnInstance;
{ VerticalAlignment va = (VerticalAlignment)info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].ValueOnInstance;
return true;
}
public void EnterContainer(PlacementOperation operation) if (ha == HorizontalAlignment.Stretch)
{ info.Item.Properties[FrameworkElement.WidthProperty].SetValue(info.Bounds.Width);
foreach (PlacementInformation info in operation.PlacedItems) { if (va == VerticalAlignment.Stretch)
this.ExtendedItem.Properties["Children"].CollectionElements.Add(info.Item); info.Item.Properties[FrameworkElement.HeightProperty].SetValue(info.Bounds.Height);
SetPosition(info); }
} }
BeginPlacement(operation);
} }
} }
} }

11
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GuideLineManager.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public class GuideLineManager
{
}
}

14
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GuideLinePlacementBehavior.cs

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using ICSharpCode.WpfDesign.Extensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public class GuideLinePlacementBehavior : DefaultPlacementBehavior
{
//TODO
}
}

123
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs

@ -14,6 +14,7 @@ using System.Windows.Input;
using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls; using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Extensions;
using System.Collections.Generic;
namespace ICSharpCode.WpfDesign.Designer.Extensions namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
@ -29,9 +30,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
readonly DesignItem[] extendedItemArray = new DesignItem[1]; readonly DesignItem[] extendedItemArray = new DesignItem[1];
IPlacementBehavior resizeBehavior; IPlacementBehavior resizeBehavior;
PlacementOperation operation; PlacementOperation operation;
ResizeThumb activeResizeThumb; ChangeGroup changeGroup;
/// <summary></summary>
public ResizeThumbExtension() public ResizeThumbExtension()
{ {
adornerPanel = new AdornerPanel(); adornerPanel = new AdornerPanel();
@ -58,99 +58,81 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
AdornerPanel.SetPlacement(resizeThumb, new RelativePlacement(alignment.Horizontal, alignment.Vertical)); AdornerPanel.SetPlacement(resizeThumb, new RelativePlacement(alignment.Horizontal, alignment.Vertical));
adornerPanel.Children.Add(resizeThumb); adornerPanel.Children.Add(resizeThumb);
resizeThumb.DragStarted += OnDragStarted; DragListener drag = new DragListener(resizeThumb);
resizeThumb.DragDelta += OnDragDelta(alignment); drag.Started += new DragHandler(drag_Started);
resizeThumb.DragCompleted += OnDragCompleted; drag.Changed += new DragHandler(drag_Changed);
drag.Completed += new DragHandler(drag_Completed);
return resizeThumb; return resizeThumb;
} }
void OnDragStarted(object sender, DragStartedEventArgs e) Size oldSize;
void drag_Started(DragListener drag)
{ {
activeResizeThumb = (ResizeThumb)sender; oldSize = new Size(ModelTools.GetWidth(ExtendedItem.View), ModelTools.GetHeight(ExtendedItem.View));
if (resizeBehavior != null)
operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize); operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize);
this.ExtendedItem.Services.GetService<IDesignPanel>().KeyDown += OnDesignPanelKeyDown; else {
changeGroup = this.ExtendedItem.Context.OpenGroup("Resize", extendedItemArray);
}
} }
DragDeltaEventHandler OnDragDelta(PlacementAlignment alignment) void drag_Changed(DragListener drag)
{ {
return delegate(object sender, DragDeltaEventArgs e) { double dx = 0;
foreach (PlacementInformation info in operation.PlacedItems) { double dy = 0;
double left = info.Bounds.Left; var alignment = (drag.Target as ResizeThumb).Alignment;
double right = info.Bounds.Right;
double bottom = info.Bounds.Bottom; if (alignment.Horizontal == HorizontalAlignment.Left) dx = -drag.Delta.X;
double top = info.Bounds.Top; if (alignment.Horizontal == HorizontalAlignment.Right) dx = drag.Delta.X;
switch (alignment.Horizontal) { if (alignment.Vertical == VerticalAlignment.Top) dy = -drag.Delta.Y;
case HorizontalAlignment.Left: if (alignment.Vertical == VerticalAlignment.Bottom) dy = drag.Delta.Y;
left += e.HorizontalChange;
if (left > right) var newWidth = Math.Max(0, oldSize.Width + dx);
left = right; var newHeight = Math.Max(0, oldSize.Height + dy);
break;
case HorizontalAlignment.Right: ModelTools.Resize(ExtendedItem, newWidth, newHeight);
right += e.HorizontalChange;
if (right < left) if (operation != null) {
right = left; var info = operation.PlacedItems[0];
break; var result = info.OriginalBounds;
}
switch (alignment.Vertical) { if (alignment.Horizontal == HorizontalAlignment.Left)
case VerticalAlignment.Top: result.X = Math.Min(result.Right, result.X - dx);
top += e.VerticalChange; if (alignment.Vertical == VerticalAlignment.Top)
if (top > bottom) result.Y = Math.Min(result.Bottom, result.Y - dy);
top = bottom; result.Width = newWidth;
break; result.Height = newHeight;
case VerticalAlignment.Bottom:
bottom += e.VerticalChange; info.Bounds = result;
if (bottom < top)
bottom = top;
break;
}
info.Bounds = new Rect(left, top, right - left, bottom - top);
operation.CurrentContainerBehavior.SetPosition(info); operation.CurrentContainerBehavior.SetPosition(info);
} }
};
} }
void OnDragCompleted(object sender, DragCompletedEventArgs e) void drag_Completed(DragListener drag)
{ {
if (operation != null) { if (operation != null) {
this.ExtendedItem.Services.GetService<IDesignPanel>().KeyDown -= OnDesignPanelKeyDown; if (drag.IsCanceled) operation.Abort();
if (e.Canceled) else operation.Commit();
operation.Abort();
else
operation.Commit();
operation = null; operation = null;
} else {
if (drag.IsCanceled) changeGroup.Abort();
else changeGroup.Commit();
changeGroup = null;
} }
} }
void OnDesignPanelKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape) {
activeResizeThumb.CancelDrag();
}
}
/// <summary/>
protected override void OnInitialized() protected override void OnInitialized()
{ {
base.OnInitialized(); base.OnInitialized();
extendedItemArray[0] = this.ExtendedItem; extendedItemArray[0] = this.ExtendedItem;
this.ExtendedItem.PropertyChanged += OnPropertyChanged;
this.Services.Selection.PrimarySelectionChanged += OnPrimarySelectionChanged; this.Services.Selection.PrimarySelectionChanged += OnPrimarySelectionChanged;
resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray); resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray);
UpdateAdornerVisibility();
OnPrimarySelectionChanged(null, null); OnPrimarySelectionChanged(null, null);
} }
void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
UpdateAdornerVisibility();
}
/// <summary/>
protected override void OnRemove() protected override void OnRemove()
{ {
this.ExtendedItem.PropertyChanged -= OnPropertyChanged;
this.Services.Selection.PrimarySelectionChanged -= OnPrimarySelectionChanged; this.Services.Selection.PrimarySelectionChanged -= OnPrimarySelectionChanged;
base.OnRemove(); base.OnRemove();
} }
@ -162,14 +144,5 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
g.IsPrimarySelection = isPrimarySelection; g.IsPrimarySelection = isPrimarySelection;
} }
} }
void UpdateAdornerVisibility()
{
FrameworkElement fe = this.ExtendedItem.View as FrameworkElement;
foreach (ResizeThumb r in resizeThumbs) {
bool isVisible = resizeBehavior != null && resizeBehavior.CanPlace(extendedItemArray, PlacementType.Resize, r.Alignment);
r.Visibility = isVisible ? Visibility.Visible : Visibility.Hidden;
}
}
} }
} }

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs

@ -118,5 +118,15 @@ namespace ICSharpCode.WpfDesign.Designer
else else
return v; return v;
} }
public static void Resize(DesignItem item, double newWidth, double newHeight)
{
if (newWidth != GetWidth(item.View)) {
item.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(newWidth);
}
if (newHeight != GetHeight(item.View)) {
item.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(newHeight);
}
}
} }
} }

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGrid.cs

@ -18,12 +18,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
public class PropertyGrid : INotifyPropertyChanged public class PropertyGrid : INotifyPropertyChanged
{ {
static PropertyGrid()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
new BasicMetadata();
}
public PropertyGrid() public PropertyGrid()
{ {
Categories = new ObservableCollection<Category>(); Categories = new ObservableCollection<Category>();

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

@ -39,7 +39,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
} }
public Cursor Cursor { public Cursor Cursor {
get { return null; } get { return Cursors.Cross; }
} }
public void Activate(IDesignPanel designPanel) public void Activate(IDesignPanel designPanel)

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

@ -61,9 +61,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
// try to switch the container // try to switch the container
if (operation.CurrentContainerBehavior.CanLeaveContainer(operation)) { if (operation.CurrentContainerBehavior.CanLeaveContainer(operation)) {
if (ChangeContainerIfPossible(e)) { ChangeContainerIfPossible(e);
return;
}
} }
Vector v = e.GetPosition(positionRelativeTo) - startPoint; Vector v = e.GetPosition(positionRelativeTo) - startPoint;

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

@ -74,11 +74,13 @@
<DependentUpon>EnumBar.xaml</DependentUpon> <DependentUpon>EnumBar.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Controls\EnumButton.cs" /> <Compile Include="Controls\EnumButton.cs" />
<Compile Include="Controls\GrayOutDesignerExceptActiveArea.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Controls\GridAdorner.cs" /> <Compile Include="Controls\GridAdorner.cs" />
<Compile Include="Controls\NumericUpDown.cs" /> <Compile Include="Controls\NumericUpDown.cs" />
<Compile Include="Controls\SelectionFrame.cs" /> <Compile Include="Controls\SelectionFrame.cs" />
<Compile Include="Controls\ErrorBalloon.cs" /> <Compile Include="Controls\ErrorBalloon.cs" />
<Compile Include="Controls\GrayOutDesignerExceptActiveArea.cs" />
<Compile Include="Controls\ResizeThumb.cs" /> <Compile Include="Controls\ResizeThumb.cs" />
<Compile Include="Controls\SingleVisualChildElement.cs" /> <Compile Include="Controls\SingleVisualChildElement.cs" />
<Compile Include="CallExtension.cs" /> <Compile Include="CallExtension.cs" />
@ -88,11 +90,20 @@
<Compile Include="DesignPanel.cs" /> <Compile Include="DesignPanel.cs" />
<Compile Include="DragDropExceptionHandler.cs" /> <Compile Include="DragDropExceptionHandler.cs" />
<Compile Include="ExtensionMethods.cs" /> <Compile Include="ExtensionMethods.cs" />
<Compile Include="Extensions\CanvasPlacementSupport.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Extensions\ContentControlDefaultInitializer.cs" /> <Compile Include="Extensions\ContentControlDefaultInitializer.cs" />
<Compile Include="Extensions\DefaultPlacementBehavior.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Extensions\GridAdornerProvider.cs" /> <Compile Include="Extensions\GridAdornerProvider.cs" />
<Compile Include="Extensions\GridPlacementSupport.cs" /> <Compile Include="Extensions\GridPlacementSupport.cs" />
<Compile Include="Extensions\GuideLineManager.cs" />
<Compile Include="Extensions\GuideLinePlacementBehavior.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="ModelTools.cs" /> <Compile Include="ModelTools.cs" />
<Compile Include="Extensions\CanvasPlacementSupport.cs" />
<Compile Include="Extensions\PanelInstanceFactory.cs" /> <Compile Include="Extensions\PanelInstanceFactory.cs" />
<Compile Include="Extensions\PanelSelectionHandler.cs" /> <Compile Include="Extensions\PanelSelectionHandler.cs" />
<Compile Include="Extensions\SelectedElementRectangleExtension.cs" /> <Compile Include="Extensions\SelectedElementRectangleExtension.cs" />
@ -100,7 +111,7 @@
<Compile Include="Extensions\TopLeftContainerDragHandle.cs" /> <Compile Include="Extensions\TopLeftContainerDragHandle.cs" />
<Compile Include="Extensions\ResizeThumbExtension.cs" /> <Compile Include="Extensions\ResizeThumbExtension.cs" />
<Compile Include="Extensions\WindowResizeBehavior.cs" /> <Compile Include="Extensions\WindowResizeBehavior.cs" />
<Compile Include="PropertyGrid\BasicMetadata.cs" /> <Compile Include="BasicMetadata.cs" />
<Compile Include="PropertyGrid\Category.cs" /> <Compile Include="PropertyGrid\Category.cs" />
<Compile Include="PropertyGrid\Editors\BoolEditor.xaml.cs"> <Compile Include="PropertyGrid\Editors\BoolEditor.xaml.cs">
<DependentUpon>BoolEditor.xaml</DependentUpon> <DependentUpon>BoolEditor.xaml</DependentUpon>
@ -154,7 +165,9 @@
<Compile Include="Services\DragMoveMouseGesture.cs" /> <Compile Include="Services\DragMoveMouseGesture.cs" />
<Compile Include="Services\ErrorService.cs" /> <Compile Include="Services\ErrorService.cs" />
<Compile Include="Services\MouseGestureBase.cs" /> <Compile Include="Services\MouseGestureBase.cs" />
<Compile Include="Services\OptionService.cs" /> <Compile Include="Services\OptionService.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Services\PointerTool.cs" /> <Compile Include="Services\PointerTool.cs" />
<Compile Include="Services\SelectionService.cs" /> <Compile Include="Services\SelectionService.cs" />
<Compile Include="Services\ToolService.cs" /> <Compile Include="Services\ToolService.cs" />
@ -244,7 +257,9 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
<Page Include="themes\generic.xaml" /> <Page Include="Themes\Generic.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Resource Include="Images\Class.png" /> <Resource Include="Images\Class.png" />

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs

@ -14,6 +14,8 @@ using ICSharpCode.WpfDesign.Designer.Services;
using ICSharpCode.WpfDesign.Designer.Extensions; using ICSharpCode.WpfDesign.Designer.Extensions;
using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.PropertyGrid; using ICSharpCode.WpfDesign.PropertyGrid;
using System.Threading;
using System.Globalization;
namespace ICSharpCode.WpfDesign.Designer.Xaml namespace ICSharpCode.WpfDesign.Designer.Xaml
{ {
@ -22,6 +24,12 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
/// </summary> /// </summary>
public sealed class XamlDesignContext : DesignContext public sealed class XamlDesignContext : DesignContext
{ {
static XamlDesignContext()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
new BasicMetadata();
}
readonly XamlDocument _doc; readonly XamlDocument _doc;
readonly XamlDesignItem _rootItem; readonly XamlDesignItem _rootItem;
internal readonly XamlComponentService _componentService; internal readonly XamlComponentService _componentService;

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

@ -16,7 +16,7 @@ using System.Windows.Markup;
namespace ICSharpCode.WpfDesign.XamlDom namespace ICSharpCode.WpfDesign.XamlDom
{ {
static class CollectionSupport public static class CollectionSupport
{ {
public static bool IsCollectionType(Type type) public static bool IsCollectionType(Type type)
{ {
@ -26,6 +26,24 @@ namespace ICSharpCode.WpfDesign.XamlDom
|| typeof(ResourceDictionary).IsAssignableFrom(type); || typeof(ResourceDictionary).IsAssignableFrom(type);
} }
public static bool CanCollectionAdd(Type col, Type item)
{
var e = col.GetInterface("IEnumerable`1");
if (e != null && e.IsGenericType) {
var a = e.GetGenericArguments()[0];
return a.IsAssignableFrom(item);
}
return true;
}
public static bool CanCollectionAdd(Type col, IEnumerable items)
{
foreach (var item in items) {
if (!CanCollectionAdd(col, item.GetType())) return false;
}
return true;
}
public static void AddToCollection(Type collectionType, object collectionInstance, XamlPropertyValue newElement) public static void AddToCollection(Type collectionType, object collectionInstance, XamlPropertyValue newElement)
{ {
IAddChild addChild = collectionInstance as IAddChild; IAddChild addChild = collectionInstance as IAddChild;

16
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs

@ -127,6 +127,22 @@ namespace ICSharpCode.WpfDesign
} }
return null; return null;
} }
static HashSet<Type> placementDisabled = new HashSet<Type>();
public static void DisablePlacement(Type type)
{
lock (placementDisabled) {
placementDisabled.Add(type);
}
}
public static bool IsPlacementDisabled(Type type)
{
lock (placementDisabled) {
return placementDisabled.Contains(type);
}
}
} }
public class NumberRange public class NumberRange

Loading…
Cancel
Save