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 17 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. 76
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs
  8. 91
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs
  9. 65
      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. 139
      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; @@ -7,6 +7,7 @@ using ICSharpCode.WpfDesign;
using System.Collections.ObjectModel;
using System.Collections;
using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.XamlDesigner
{
@ -104,6 +105,8 @@ namespace ICSharpCode.XamlDesigner @@ -104,6 +105,8 @@ namespace ICSharpCode.XamlDesigner
void UpdateChildren()
{
Children.Clear();
if (DesignItem.ContentPropertyName != null) {
var content = DesignItem.ContentProperty;
if (content.IsCollection) {
@ -119,8 +122,6 @@ namespace ICSharpCode.XamlDesigner @@ -119,8 +122,6 @@ namespace ICSharpCode.XamlDesigner
void UpdateChildrenCore(IEnumerable<DesignItem> items)
{
Children.Clear();
foreach (var item in items) {
if (ModelTools.CanSelectComponent(item)) {
var node = OutlineNode.Create(item);
@ -129,13 +130,14 @@ namespace ICSharpCode.XamlDesigner @@ -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)
{
if (DesignItem.ContentPropertyName == null) return false;
if (DesignItem.ContentProperty.IsCollection) {
foreach (var node in nodes) {
if (!CanCollectionAdd(DesignItem.ContentProperty.ReturnType,
if (!CollectionSupport.CanCollectionAdd(DesignItem.ContentProperty.ReturnType,
node.DesignItem.ComponentType)) {
return false;
}
@ -149,16 +151,6 @@ namespace ICSharpCode.XamlDesigner @@ -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)
{
if (copy) {

3
samples/XamlDesigner/ToolboxView.xaml

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

11
samples/XamlDesigner/ToolboxView.xaml.cs

@ -26,11 +26,13 @@ namespace ICSharpCode.XamlDesigner @@ -26,11 +26,13 @@ namespace ICSharpCode.XamlDesigner
InitializeComponent();
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)
@ -38,6 +40,11 @@ namespace ICSharpCode.XamlDesigner @@ -38,6 +40,11 @@ namespace ICSharpCode.XamlDesigner
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)
{
if (node != null) {

8
samples/XamlDesigner/XamlDesigner.csproj

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30428</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{27DA2B5C-2AAA-4478-AB00-3E184273C241}</ProjectGuid>
<OutputType>WinExe</OutputType>
@ -182,6 +182,12 @@ @@ -182,6 +182,12 @@
<Resource Include="Images\Reference.png" />
<Resource Include="Images\Tag.png" />
</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" />
<!-- 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.

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; @@ -14,7 +14,7 @@ using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Data;
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
namespace ICSharpCode.WpfDesign.Designer
{
public class BasicMetadata
{
@ -562,6 +562,8 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid @@ -562,6 +562,8 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
Metadata.AddAdvancedProperty(typeof(BindingBase), "FallbackValue");
Metadata.AddAdvancedProperty(typeof(BindingBase), "StringFormat");
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 @@ -35,6 +35,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
if (a != null && a.Key == Key.Escape) {
Mouse.Capture(null);
CurrentListener.IsDown = false;
CurrentListener.IsCanceled = true;
CurrentListener.Complete();
}
}
@ -46,6 +47,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -46,6 +47,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
CurrentPoint = StartPoint;
DeltaDelta = new Vector();
IsDown = true;
IsCanceled = false;
}
void Target_MouseMove(object sender, MouseEventArgs e)
@ -100,6 +102,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -100,6 +102,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
public Vector DeltaDelta { get; private set; }
public bool IsActive { get; private set; }
public bool IsDown { get; private set; }
public bool IsCanceled { get; private set; }
public Vector Delta {
get { return CurrentPoint - StartPoint; }

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

@ -18,30 +18,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -18,30 +18,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// <summary>
/// Provides <see cref="IPlacementBehavior"/> behavior for <see cref="Canvas"/>.
/// </summary>
[ExtensionFor(typeof(Canvas))]
public sealed class CanvasPlacementSupport : BehaviorExtension, IPlacementBehavior
[ExtensionFor(typeof(Canvas), OverrideExtension=typeof(DefaultPlacementBehavior))]
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)
{
double v = (double)element.GetValue(Canvas.LeftProperty);
@ -58,68 +37,45 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -58,68 +37,45 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
return 0;
else
return v;
}
}
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 void SetPosition(PlacementInformation info)
public override void SetPosition(PlacementInformation info)
{
base.SetPosition(info);
UIElement child = info.Item.View;
Rect newPosition = info.Bounds;
if (newPosition.Left != GetLeft(child)) {
info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(newPosition.Left);
}
if (newPosition.Top != GetTop(child)) {
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) {
this.ExtendedItem.Properties["Children"].CollectionElements.Remove(info.Item);
info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset();
info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).Reset();
}
}
public bool CanEnterContainer(PlacementOperation operation)
{
return true;
}
public void EnterContainer(PlacementOperation operation)
public override void EnterContainer(PlacementOperation operation)
{
base.EnterContainer(operation);
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.VerticalAlignmentProperty].Reset();
info.Item.Properties[FrameworkElement.MarginProperty].Reset();
}
BeginPlacement(operation);
}
}
}

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

@ -0,0 +1,91 @@ @@ -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);
}
}
}
}
}

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

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

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

@ -0,0 +1,11 @@ @@ -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 @@ @@ -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
}
}

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

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

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

@ -39,7 +39,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -39,7 +39,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
}
public Cursor Cursor {
get { return null; }
get { return Cursors.Cross; }
}
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 @@ -61,9 +61,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
// try to switch the container
if (operation.CurrentContainerBehavior.CanLeaveContainer(operation)) {
if (ChangeContainerIfPossible(e)) {
return;
}
ChangeContainerIfPossible(e);
}
Vector v = e.GetPosition(positionRelativeTo) - startPoint;

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

@ -74,11 +74,13 @@ @@ -74,11 +74,13 @@
<DependentUpon>EnumBar.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\EnumButton.cs" />
<Compile Include="Controls\GrayOutDesignerExceptActiveArea.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Controls\GridAdorner.cs" />
<Compile Include="Controls\NumericUpDown.cs" />
<Compile Include="Controls\SelectionFrame.cs" />
<Compile Include="Controls\ErrorBalloon.cs" />
<Compile Include="Controls\GrayOutDesignerExceptActiveArea.cs" />
<Compile Include="Controls\ResizeThumb.cs" />
<Compile Include="Controls\SingleVisualChildElement.cs" />
<Compile Include="CallExtension.cs" />
@ -88,11 +90,20 @@ @@ -88,11 +90,20 @@
<Compile Include="DesignPanel.cs" />
<Compile Include="DragDropExceptionHandler.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="Extensions\CanvasPlacementSupport.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Extensions\ContentControlDefaultInitializer.cs" />
<Compile Include="Extensions\DefaultPlacementBehavior.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Extensions\GridAdornerProvider.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="Extensions\CanvasPlacementSupport.cs" />
<Compile Include="Extensions\PanelInstanceFactory.cs" />
<Compile Include="Extensions\PanelSelectionHandler.cs" />
<Compile Include="Extensions\SelectedElementRectangleExtension.cs" />
@ -100,7 +111,7 @@ @@ -100,7 +111,7 @@
<Compile Include="Extensions\TopLeftContainerDragHandle.cs" />
<Compile Include="Extensions\ResizeThumbExtension.cs" />
<Compile Include="Extensions\WindowResizeBehavior.cs" />
<Compile Include="PropertyGrid\BasicMetadata.cs" />
<Compile Include="BasicMetadata.cs" />
<Compile Include="PropertyGrid\Category.cs" />
<Compile Include="PropertyGrid\Editors\BoolEditor.xaml.cs">
<DependentUpon>BoolEditor.xaml</DependentUpon>
@ -154,7 +165,9 @@ @@ -154,7 +165,9 @@
<Compile Include="Services\DragMoveMouseGesture.cs" />
<Compile Include="Services\ErrorService.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\SelectionService.cs" />
<Compile Include="Services\ToolService.cs" />
@ -244,7 +257,9 @@ @@ -244,7 +257,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="themes\generic.xaml" />
<Page Include="Themes\Generic.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<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; @@ -14,6 +14,8 @@ using ICSharpCode.WpfDesign.Designer.Services;
using ICSharpCode.WpfDesign.Designer.Extensions;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.PropertyGrid;
using System.Threading;
using System.Globalization;
namespace ICSharpCode.WpfDesign.Designer.Xaml
{
@ -22,6 +24,12 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -22,6 +24,12 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
/// </summary>
public sealed class XamlDesignContext : DesignContext
{
static XamlDesignContext()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
new BasicMetadata();
}
readonly XamlDocument _doc;
readonly XamlDesignItem _rootItem;
internal readonly XamlComponentService _componentService;

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

@ -16,7 +16,7 @@ using System.Windows.Markup; @@ -16,7 +16,7 @@ using System.Windows.Markup;
namespace ICSharpCode.WpfDesign.XamlDom
{
static class CollectionSupport
public static class CollectionSupport
{
public static bool IsCollectionType(Type type)
{
@ -24,6 +24,24 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -24,6 +24,24 @@ namespace ICSharpCode.WpfDesign.XamlDom
|| type.IsArray
|| typeof(IAddChild).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)

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

@ -127,6 +127,22 @@ namespace ICSharpCode.WpfDesign @@ -127,6 +127,22 @@ namespace ICSharpCode.WpfDesign
}
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

Loading…
Cancel
Save