diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ArrangeDirection.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ArrangeDirection.cs new file mode 100644 index 0000000000..095d1c1f1b --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ArrangeDirection.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ICSharpCode.WpfDesign.Designer +{ + public enum ArrangeDirection + { + Top, + VerticalMiddle, + Bottom, + Left, + HorizontalMiddle, + Right, + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs index 91dbe48dd1..266bb736ae 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs @@ -145,7 +145,9 @@ namespace ICSharpCode.WpfDesign.Designer Metadata.AddPopularProperty(TreeViewItem.IsSelectedProperty); Metadata.AddPopularProperty(Border.PaddingProperty); Metadata.AddPopularProperty(Shape.StretchProperty); - + Metadata.AddPopularProperty(Control.VerticalContentAlignmentProperty); + Metadata.AddPopularProperty(Control.HorizontalContentAlignmentProperty); + Metadata.AddPopularProperty(Grid.RowProperty); Metadata.AddPopularProperty(Grid.RowSpanProperty); Metadata.AddPopularProperty(Grid.ColumnProperty); @@ -230,14 +232,14 @@ namespace ICSharpCode.WpfDesign.Designer Metadata.AddPopularControl(typeof(Border)); Metadata.AddPopularControl(typeof(Canvas)); Metadata.AddPopularControl(typeof(CheckBox)); - Metadata.AddPopularControl(typeof(ComboBox)); + Metadata.AddPopularControl(typeof(ComboBox)); Metadata.AddPopularControl(typeof(DataGrid)); Metadata.AddPopularControl(typeof(DockPanel)); Metadata.AddPopularControl(typeof(Expander)); Metadata.AddPopularControl(typeof(Grid)); Metadata.AddPopularControl(typeof(GroupBox)); - Metadata.AddPopularControl(typeof(Image)); - Metadata.AddPopularControl(typeof(InkCanvas)); + Metadata.AddPopularControl(typeof(Image)); + Metadata.AddPopularControl(typeof(InkCanvas)); Metadata.AddPopularControl(typeof(Label)); Metadata.AddPopularControl(typeof(ListBox)); Metadata.AddPopularControl(typeof(ListView)); @@ -249,7 +251,7 @@ namespace ICSharpCode.WpfDesign.Designer Metadata.AddPopularControl(typeof(RichTextBox)); Metadata.AddPopularControl(typeof(StackPanel)); Metadata.AddPopularControl(typeof(ScrollViewer)); - Metadata.AddPopularControl(typeof(Slider)); + Metadata.AddPopularControl(typeof(Slider)); Metadata.AddPopularControl(typeof(TabControl)); Metadata.AddPopularControl(typeof(TextBlock)); Metadata.AddPopularControl(typeof(TextBox)); @@ -259,28 +261,30 @@ namespace ICSharpCode.WpfDesign.Designer Metadata.AddPopularControl(typeof(Viewport3D)); Metadata.AddPopularControl(typeof(WrapPanel)); - Metadata.AddDefaultSize(typeof(UIElement), new Size(120, 100)); - Metadata.AddDefaultSize(typeof(ContentControl), new Size(120, 20)); - Metadata.AddDefaultSize(typeof(Button), new Size(75, 23)); + //Basic Metadata Size of double.NaN, means no Size should be set. + Metadata.AddDefaultSize(typeof(TextBlock), new Size(double.NaN, double.NaN)); + Metadata.AddDefaultSize(typeof(CheckBox), new Size(double.NaN, double.NaN)); + Metadata.AddDefaultSize(typeof(Image), new Size(double.NaN, double.NaN)); + + Metadata.AddDefaultSize(typeof(UIElement), new Size(120, 100)); + Metadata.AddDefaultSize(typeof(ContentControl), new Size(120, 20)); + Metadata.AddDefaultSize(typeof(Button), new Size(75, 23)); + Metadata.AddDefaultSize(typeof(ToggleButton), new Size(75, 23)); - var s1 = new Size(120, 20); - Metadata.AddDefaultSize(typeof(Slider), s1); - Metadata.AddDefaultSize(typeof(TextBox), s1); - Metadata.AddDefaultSize(typeof(PasswordBox), s1); - Metadata.AddDefaultSize(typeof(ComboBox), s1); - Metadata.AddDefaultSize(typeof(ProgressBar), s1); + Metadata.AddDefaultSize(typeof(Slider), new Size(120, 20)); + Metadata.AddDefaultSize(typeof(TextBox), new Size(120, 20)); + Metadata.AddDefaultSize(typeof(PasswordBox), new Size(120, 20)); + Metadata.AddDefaultSize(typeof(ComboBox), new Size(120, 20)); + Metadata.AddDefaultSize(typeof(ProgressBar), new Size(120, 20)); - Metadata.AddDefaultSize(typeof(ToolBar), s1); - Metadata.AddDefaultSize(typeof(Menu), s1); - - var s2=new Size(120,120); - Metadata.AddDefaultSize(typeof(InkCanvas),s2); - Metadata.AddDefaultSize(typeof(Image),s2); - Metadata.AddDefaultSize(typeof(TreeView),s2); - - var s3=new Size(130,120); - Metadata.AddDefaultSize(typeof(Label),s3); - Metadata.AddDefaultSize(typeof(Expander),s3); + Metadata.AddDefaultSize(typeof(ToolBar), new Size(120, 20)); + Metadata.AddDefaultSize(typeof(Menu), new Size(120, 20)); + + Metadata.AddDefaultSize(typeof(InkCanvas), new Size(120, 120)); + Metadata.AddDefaultSize(typeof(TreeView), new Size(120, 120)); + + Metadata.AddDefaultSize(typeof(Label), new Size(130, 120)); + Metadata.AddDefaultSize(typeof(Expander), new Size(130, 120)); } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/AdornerLayer.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/AdornerLayer.cs index caef54e20c..b4e0a025a1 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/AdornerLayer.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/AdornerLayer.cs @@ -32,7 +32,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls /// /// A control that displays adorner panels. /// - sealed class AdornerLayer : Panel + public sealed class AdornerLayer : Panel { #region AdornerPanelCollection internal sealed class AdornerPanelCollection : ICollection, IReadOnlyCollection @@ -218,13 +218,23 @@ namespace ICSharpCode.WpfDesign.Designer.Controls } return new Size(0, 0); } - + protected override Size ArrangeOverride(Size finalSize) { - foreach (AdornerPanel adorner in this.Children) { - if (adorner.AdornedElement.IsDescendantOf(_designPanel)) { - adorner.RenderTransform = (Transform)adorner.AdornedElement.TransformToAncestor(_designPanel); + foreach (AdornerPanel adorner in this.Children) { + if (adorner.AdornedElement.IsDescendantOf(_designPanel)) + { + var rt = (MatrixTransform) adorner.AdornedElement.TransformToAncestor(_designPanel); + if (adorner.AdornedDesignItem != null && adorner.AdornedDesignItem.Parent != null && adorner.AdornedDesignItem.Parent.View is Canvas && adorner.AdornedElement.RenderSize.Height == 0 && adorner.AdornedElement.RenderSize.Width == 0) + { + var xOffset = rt.Matrix.OffsetX - (((FrameworkElement)adorner.AdornedElement).Width / 2); + var yOffset = rt.Matrix.OffsetY - (((FrameworkElement)adorner.AdornedElement).Height / 2); + rt = new MatrixTransform(new Matrix(rt.Matrix.M11, rt.Matrix.M12, rt.Matrix.M21, rt.Matrix.M22, xOffset, yOffset)); + } + + adorner.RenderTransform = rt; } + adorner.Arrange(new Rect(new Point(0, 0), adorner.DesiredSize)); } return finalSize; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/CanvasPositionHandle.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/CanvasPositionHandle.cs index 17a1663c29..d1e10016cc 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/CanvasPositionHandle.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/CanvasPositionHandle.cs @@ -146,7 +146,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls if (double.IsNaN(wr)) { wr = (double) rightDescriptor.GetValue(adornedControl); - wr = canvas.ActualWidth - (adornedControl.ActualWidth + wr); + wr = canvas.ActualWidth - (PlacementOperation.GetRealElementSize(adornedControl).Width + wr); } else { @@ -167,7 +167,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls if (double.IsNaN(wr)) { wr = (double)bottomDescriptor.GetValue(adornedControl); - wr = canvas.ActualHeight - (adornedControl.ActualHeight + wr); + wr = canvas.ActualHeight - (PlacementOperation.GetRealElementSize(adornedControl).Height + wr); } else { @@ -188,7 +188,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls if (double.IsNaN(wr)) { wr = (double) leftDescriptor.GetValue(adornedControl); - wr = canvas.ActualWidth - (adornedControl.ActualWidth + wr); + wr = canvas.ActualWidth - (PlacementOperation.GetRealElementSize(adornedControl).Width + wr); } else { @@ -209,7 +209,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls if (double.IsNaN(wr)) { wr = (double)topDescriptor.GetValue(adornedControl); - wr = canvas.ActualHeight - (adornedControl.ActualHeight + wr); + wr = canvas.ActualHeight - (PlacementOperation.GetRealElementSize(adornedControl).Height + wr); } else { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml index f6deec886b..7183b558c4 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml @@ -333,7 +333,16 @@ - + + + + + + + + + + @@ -355,7 +364,17 @@ - + + + + + + + + + + + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ResizeThumb.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ResizeThumb.cs index 911f7d12bb..ec82214b0c 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ResizeThumb.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ResizeThumb.cs @@ -90,9 +90,9 @@ namespace ICSharpCode.WpfDesign.Designer.Controls AdornerPanel parent = this.Parent as AdornerPanel; if (parent != null && parent.AdornedElement != null) { if (checkWidth) - this.ResizeThumbVisible = parent.AdornedElement.RenderSize.Width > 14; + this.ResizeThumbVisible = PlacementOperation.GetRealElementSize(parent.AdornedElement).Width > 14; else if (checkHeight) - this.ResizeThumbVisible = parent.AdornedElement.RenderSize.Height > 14; + this.ResizeThumbVisible = PlacementOperation.GetRealElementSize(parent.AdornedElement).Height > 14; } return base.ArrangeOverride(arrangeBounds); } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Converters.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Converters.cs index 3c9ca0b8d1..92a11aa73e 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Converters.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Converters.cs @@ -159,8 +159,38 @@ namespace ICSharpCode.WpfDesign.Designer.Converters return value; } } - - public class FormatDoubleConverter : IValueConverter + + public class ControlToRealWidthConverter : IMultiValueConverter + { + public static readonly ControlToRealWidthConverter Instance = new ControlToRealWidthConverter(); + + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + return PlacementOperation.GetRealElementSize((UIElement)values[0]).Width; + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + + public class ControlToRealHeightConverter : IMultiValueConverter + { + public static readonly ControlToRealHeightConverter Instance = new ControlToRealHeightConverter(); + + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + return PlacementOperation.GetRealElementSize((UIElement)values[0]).Height; + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + + public class FormatDoubleConverter : IValueConverter { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")] public static readonly FormatDoubleConverter Instance=new FormatDoubleConverter(); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs index 055b4d988a..d13f23dcc8 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs @@ -17,11 +17,15 @@ // DEALINGS IN THE SOFTWARE. using System; +using System.Collections; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; +using System.Linq; using System.Windows; using System.Windows.Controls; +using System.Windows.Data; using System.Windows.Input; using System.Windows.Media; using System.Windows.Threading; @@ -58,27 +62,27 @@ namespace ICSharpCode.WpfDesign.Designer void RunHitTest(Visual reference, Point point, HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback) { VisualTreeHelper.HitTest(reference, filterCallback, resultCallback, - new PointHitTestParameters(point)); + new PointHitTestParameters(point)); } HitTestFilterBehavior FilterHitTestInvisibleElements(DependencyObject potentialHitTestTarget) { UIElement element = potentialHitTestTarget as UIElement; - + if (element != null) { if (!(element.IsHitTestVisible && element.Visibility == Visibility.Visible)) { return HitTestFilterBehavior.ContinueSkipSelfAndChildren; } var designItem = Context.Services.Component.GetDesignItem(element) as XamlDesignItem; - + if (designItem != null && designItem.IsDesignTimeLocked) { return HitTestFilterBehavior.ContinueSkipSelfAndChildren; - } + } } hitTestElements.Add(element); - + return HitTestFilterBehavior.Continue; } @@ -91,14 +95,14 @@ namespace ICSharpCode.WpfDesign.Designer DesignPanelHitTestResult result = DesignPanelHitTestResult.NoHit; HitTest(mousePosition, testAdorners, testDesignSurface, - delegate(DesignPanelHitTestResult r) { - result = r; - return false; - }, hitTestType); + delegate(DesignPanelHitTestResult r) { + result = r; + return false; + }, hitTestType); return result; } - + /// /// Performs a hit test on the design surface, raising for each match. /// Hit testing continues while the callback returns true. @@ -115,7 +119,7 @@ namespace ICSharpCode.WpfDesign.Designer HitTestFilterCallback filterBehavior = CustomHitTestFilterBehavior ?? FilterHitTestInvisibleElements; CustomHitTestFilterBehavior = null; hitTestElements.Clear(); - + if (testAdorners) { RunHitTest( @@ -152,8 +156,8 @@ namespace ICSharpCode.WpfDesign.Designer if (hitTestType == HitTestType.ElementSelection) { if (Keyboard.IsKeyDown(Key.LeftAlt)) - if (lastElement != null && lastElement != _context.RootItem.Component && - hitTestElements.Contains(lastElement)) + if (lastElement != null && lastElement != _context.RootItem.Component && + hitTestElements.Contains(lastElement)) { var idx = hitTestElements.IndexOf(lastElement) - 1; if (idx >= 0) @@ -215,6 +219,15 @@ namespace ICSharpCode.WpfDesign.Designer //Set custom HitTestFilterCallbak public HitTestFilterCallback CustomHitTestFilterBehavior { get; set; } + + public AdornerLayer AdornerLayer + { + get + { + return _adornerLayer; + } + } + /// /// Gets/Sets the design context. /// @@ -403,9 +416,9 @@ namespace ICSharpCode.WpfDesign.Designer if (!Keyboard.IsKeyDown(Key.LeftCtrl)) { info.Bounds = new Rect(bounds.Left + dx, - bounds.Top + dy, - bounds.Width, - bounds.Height); + bounds.Top + dy, + bounds.Width, + bounds.Height); } else { if (info.OriginalBounds.Width + dx >= 0 && info.OriginalBounds.Height + dy >= 0) { info.Bounds = new Rect(info.OriginalBounds.Left, @@ -421,9 +434,9 @@ namespace ICSharpCode.WpfDesign.Designer } static bool IsPropertySet(UIElement element, DependencyProperty d) - { - return element.ReadLocalValue(d) != DependencyProperty.UnsetValue; - } + { + return element.ReadLocalValue(d) != DependencyProperty.UnsetValue; + } protected override void OnQueryCursor(QueryCursorEventArgs e) { @@ -443,5 +456,54 @@ namespace ICSharpCode.WpfDesign.Designer PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); } + + #region ContextMenu + + private Dictionary>> contextMenusAndEntries = new Dictionary>>(); + + public void AddContextMenu(ContextMenu contextMenu) + { + contextMenusAndEntries.Add(contextMenu, new Tuple>(contextMenusAndEntries.Count, new List(contextMenu.Items.Cast()))); + contextMenu.Items.Clear(); + + UpdateContextMenu(); + } + + public void RemoveContextMenu(ContextMenu contextMenu) + { + contextMenusAndEntries.Remove(contextMenu); + + UpdateContextMenu(); + } + + public void ClearContextMenu() + { + contextMenusAndEntries.Clear(); + ContextMenu = null; + } + + private void UpdateContextMenu() + { + if (contextMenusAndEntries.Count == 0) + this.ContextMenu = null; + + if (this.ContextMenu == null) + this.ContextMenu = new ContextMenu(); + + this.ContextMenu.Items.Clear(); + + foreach (var entries in contextMenusAndEntries.Values.OrderBy(x => x.Item1).Select(x => x.Item2)) + { + if (this.ContextMenu.Items.Count > 0) + this.ContextMenu.Items.Add(new Separator()); + + foreach (var entry in entries) + { + ContextMenu.Items.Add(entry); + } + } + } + + #endregion } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs index 63445ab1db..b9281df50d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs @@ -155,8 +155,9 @@ namespace ICSharpCode.WpfDesign.Designer { _designContext = context; _designPanel.Context = context; + _designPanel.ClearContextMenu(); - if (context.RootItem != null) { + if (context.RootItem != null) { _sceneContainer.Child = context.RootItem.View; } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml new file mode 100644 index 0000000000..8232fecef3 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml.cs new file mode 100644 index 0000000000..aa54654c24 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml.cs @@ -0,0 +1,65 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Linq; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + public partial class ArrangeItemsContextMenu + { + private DesignItem designItem; + + public ArrangeItemsContextMenu(DesignItem designItem) + { + this.designItem = designItem; + + InitializeComponent(); + } + + void Click_ArrangeLeft(object sender, System.Windows.RoutedEventArgs e) + { + ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Left); + } + + void Click_ArrangeHorizontalCentered(object sender, System.Windows.RoutedEventArgs e) + { + ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.HorizontalMiddle); + } + + void Click_ArrangeRight(object sender, System.Windows.RoutedEventArgs e) + { + ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Right); + } + + void Click_ArrangeTop(object sender, System.Windows.RoutedEventArgs e) + { + ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Top); + } + + void Click_ArrangeVerticalCentered(object sender, System.Windows.RoutedEventArgs e) + { + ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.VerticalMiddle); + } + + void Click_ArrangeBottom(object sender, System.Windows.RoutedEventArgs e) + { + ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Bottom); + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenuExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenuExtension.cs new file mode 100644 index 0000000000..b1e8e31209 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenuExtension.cs @@ -0,0 +1,57 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Windows; +using System.Windows.Controls; +using ICSharpCode.WpfDesign.Adorners; +using ICSharpCode.WpfDesign.Extensions; +using ICSharpCode.WpfDesign.Designer; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + /// + /// + /// + [ExtensionServer(typeof(PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer))] + [ExtensionFor(typeof(UIElement))] + [Extension(Order = 30)] + public class ArrangeItemsContextMenuExtension : SelectionAdornerProvider + { + DesignPanel panel; + ContextMenu contextMenu; + + protected override void OnInitialized() + { + base.OnInitialized(); + + contextMenu = new ArrangeItemsContextMenu(ExtendedItem); + panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; + if (panel != null) + panel.AddContextMenu(contextMenu); + } + + protected override void OnRemove() + { + if (panel != null) + panel.RemoveContextMenu(contextMenu); + + base.OnRemove(); + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/BorderForImageControl.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/BorderForImageControl.cs new file mode 100644 index 0000000000..54d89a4329 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/BorderForImageControl.cs @@ -0,0 +1,106 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; + +using ICSharpCode.WpfDesign.Adorners; +using ICSharpCode.WpfDesign.Designer.Controls; +using ICSharpCode.WpfDesign.Extensions; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + [ExtensionFor(typeof(Image))] + public class BorderForImageControl : PermanentAdornerProvider + { + AdornerPanel adornerPanel; + AdornerPanel cachedAdornerPanel; + Border border; + + protected override void OnInitialized() + { + base.OnInitialized(); + + this.ExtendedItem.PropertyChanged += OnPropertyChanged; + + UpdateAdorner(); + } + + protected override void OnRemove() + { + this.ExtendedItem.PropertyChanged -= OnPropertyChanged; + base.OnRemove(); + } + + void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (sender == null || e.PropertyName == "Width" || e.PropertyName == "Height") + { + ((DesignPanel) this.ExtendedItem.Services.DesignPanel).AdornerLayer.UpdateAdornersForElement(this.ExtendedItem.View, true); + } + } + + void UpdateAdorner() + { + var element = ExtendedItem.Component as UIElement; + if (element != null) { + CreateAdorner(); + } + } + + private void CreateAdorner() + { + if (adornerPanel == null) { + + if (cachedAdornerPanel == null) { + cachedAdornerPanel = new AdornerPanel(); + cachedAdornerPanel.Order = AdornerOrder.Background; + border = new Border(); + border.BorderThickness = new Thickness(1); + border.BorderBrush = new SolidColorBrush(Color.FromRgb(0xCC, 0xCC, 0xCC)); + border.Background = Brushes.Transparent; + border.IsHitTestVisible = true; + border.MouseDown += border_MouseDown; + AdornerPanel.SetPlacement(border, AdornerPlacement.FillContent); + cachedAdornerPanel.Children.Add(border); + } + + adornerPanel = cachedAdornerPanel; + Adorners.Add(adornerPanel); + } + } + + void border_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) + { + if (!Keyboard.IsKeyDown(Key.LeftAlt) && ((Image) this.ExtendedItem.View).Source == null) + { + e.Handled = true; + this.ExtendedItem.Services.Selection.SetSelectedComponents(new DesignItem[] {this.ExtendedItem}, + SelectionTypes.Auto); + ((DesignPanel) this.ExtendedItem.Services.DesignPanel).Focus(); + } + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/BorderForInvisibleControl.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/BorderForInvisibleControl.cs index 3efe8cd541..d89ada52b4 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/BorderForInvisibleControl.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/BorderForInvisibleControl.cs @@ -39,8 +39,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions { AdornerPanel adornerPanel; AdornerPanel cachedAdornerPanel; - - protected override void OnInitialized() + + protected override void OnInitialized() { base.OnInitialized(); @@ -58,9 +58,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions element.IsVisibleChanged += (s, e) => UpdateAdorner(); } } - } + } - void UpdateAdorner() + void UpdateAdorner() { var element = ExtendedItem.Component as UIElement; if (element != null) { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs index bc776c99ca..e1e6b469ec 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs @@ -70,19 +70,21 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions if (IsPropertySet(child, Canvas.LeftProperty) || !IsPropertySet(child, Canvas.RightProperty)) { x = GetCanvasProperty(child, Canvas.LeftProperty); } else { - x = extendedComponent.ActualWidth - GetCanvasProperty(child, Canvas.RightProperty) - child.RenderSize.Width; + x = extendedComponent.ActualWidth - GetCanvasProperty(child, Canvas.RightProperty) - PlacementOperation.GetRealElementSize(child).Width; } if (IsPropertySet(child, Canvas.TopProperty) || !IsPropertySet(child, Canvas.BottomProperty)) { y = GetCanvasProperty(child, Canvas.TopProperty); } else { - y = extendedComponent.ActualHeight - GetCanvasProperty(child, Canvas.BottomProperty) - child.RenderSize.Height; + y = extendedComponent.ActualHeight - GetCanvasProperty(child, Canvas.BottomProperty) - PlacementOperation.GetRealElementSize(child).Height; } var p = new Point(x, y); - return new Rect(p, child.RenderSize); - } + //Fixes, Empty Image Resized to 0 + //return new Rect(p, child.RenderSize); + return new Rect(p, PlacementOperation.GetRealElementSize(item.View)); + } public override void SetPosition(PlacementInformation info) { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs index cb17a58b81..f894e939d2 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs @@ -79,15 +79,19 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions public virtual void EndPlacement(PlacementOperation operation) { - InfoTextEnterArea.Stop(ref infoTextEnterArea); - } + InfoTextEnterArea.Stop(ref infoTextEnterArea); + + this.ExtendedItem.Services.Selection.SetSelectedComponents(null); + this.ExtendedItem.Services.Selection.SetSelectedComponents(operation.PlacedItems.Select(x => x.Item).ToList()); + } public virtual Rect GetPosition(PlacementOperation operation, DesignItem item) { if (item.View == null) return Rect.Empty; var p = item.View.TranslatePoint(new Point(), operation.CurrentContainer.View); - return new Rect(p, item.View.RenderSize); + + return new Rect(p, PlacementOperation.GetRealElementSize(item.View)); } public virtual void BeforeSetPosition(PlacementOperation operation) @@ -96,7 +100,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions public virtual void SetPosition(PlacementInformation info) { - ModelTools.Resize(info.Item, info.Bounds.Width, info.Bounds.Height); + if (info.Operation.Type != PlacementType.Move) + ModelTools.Resize(info.Item, info.Bounds.Width, info.Bounds.Height); } public virtual bool CanLeaveContainer(PlacementOperation operation) @@ -158,7 +163,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions return false; } } - + + if (ExtendedItem.ContentProperty.ReturnType == typeof(string)) + return false; + if (!ExtendedItem.ContentProperty.IsSet) return true; @@ -180,7 +188,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions foreach (var info in operation.PlacedItems) { SetPosition(info); } - } + } } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs index 7c81c01984..cbd2ad1baa 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs @@ -220,13 +220,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions if (ha == HorizontalAlignment.Stretch) info.Item.Properties[FrameworkElement.WidthProperty].Reset(); - else - info.Item.Properties[FrameworkElement.WidthProperty].SetValue(info.Bounds.Width); + //else + // info.Item.Properties[FrameworkElement.WidthProperty].SetValue(info.Bounds.Width); if (va == VerticalAlignment.Stretch) info.Item.Properties[FrameworkElement.HeightProperty].Reset(); - else - info.Item.Properties[FrameworkElement.HeightProperty].SetValue(info.Bounds.Height); + //else + // info.Item.Properties[FrameworkElement.HeightProperty].SetValue(info.Bounds.Height); } public override void LeaveContainer(PlacementOperation operation) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/InPlaceEditorExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/InPlaceEditorExtension.cs index 81a24d77c4..1207c684ce 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/InPlaceEditorExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/InPlaceEditorExtension.cs @@ -34,7 +34,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions /// /// Extends In-Place editor to edit any text in the designer which is wrapped in the Visual tree under TexBlock /// - [ExtensionFor(typeof(FrameworkElement))] + [ExtensionFor(typeof(TextBlock))] public class InPlaceEditorExtension : PrimarySelectionAdornerProvider { AdornerPanel adornerPanel; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs index 433d48f307..05e79f50ed 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs @@ -63,7 +63,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers if (textProperty.ValueOnInstance == null || textProperty.ValueOnInstance.ToString() == "") { textProperty.SetValue(item.ComponentType.Name); - } + item.Properties[FrameworkElement.WidthProperty].Reset(); + item.Properties[FrameworkElement.HeightProperty].Reset(); + } DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"]; if (verticalAlignmentProperty.ValueOnInstance == null) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MarginHandleExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MarginHandleExtension.cs index 6d41118532..f1063f9565 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MarginHandleExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MarginHandleExtension.cs @@ -82,7 +82,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var margin = (Thickness) this.ExtendedItem.Properties[FrameworkElement.MarginProperty].ValueOnInstance; var point = this.ExtendedItem.View.TranslatePoint(new Point(), _grid); - var position = new Rect(point, this.ExtendedItem.View.RenderSize); + var position = new Rect(point, PlacementOperation.GetRealElementSize(this.ExtendedItem.View)); MarginHandle handle = null; if (sender is MarginHandle) handle = sender as MarginHandle; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PartialPanelSelectionHandler.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PartialPanelSelectionHandler.cs index 26159e559d..5c03df06a3 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PartialPanelSelectionHandler.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PartialPanelSelectionHandler.cs @@ -1,11 +1,21 @@ -/* - * Created by SharpDevelop. - * User: trubra - * Date: 2014-08-06 - * Time: 14:13 - * - * To change this template use Tools | Options | Coding | Edit Standard Headers. - */ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenu.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenu.xaml index 6d0e41b6d8..7e1eaba9fa 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenu.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenu.xaml @@ -2,9 +2,25 @@ xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer" - > - - - - +> + + + + + + + + + + + + + + + + + + + + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenu.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenu.xaml.cs index 74b169387f..932b57f4c3 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenu.xaml.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenu.xaml.cs @@ -19,17 +19,7 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using ICSharpCode.WpfDesign.PropertyGrid; namespace ICSharpCode.WpfDesign.Designer.Extensions { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenuExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenuExtension.cs index 20dd2adacd..49b65fb72b 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenuExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenuExtension.cs @@ -18,9 +18,7 @@ using System; using System.Windows; -using System.Windows.Media; -using System.Windows.Shapes; - +using System.Windows.Controls; using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Designer; @@ -35,18 +33,22 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions public sealed class RightClickContextMenuExtension : PrimarySelectionAdornerProvider { DesignPanel panel; + ContextMenu contextMenu; protected override void OnInitialized() { base.OnInitialized(); - + + contextMenu = new RightClickContextMenu(ExtendedItem); panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; - panel.ContextMenu = new RightClickContextMenu(ExtendedItem); + if (panel != null) + panel.AddContextMenu(contextMenu); } protected override void OnRemove() { - panel.ContextMenu = null; + if (panel != null) + panel.RemoveContextMenu(contextMenu); base.OnRemove(); } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs index 5f27890800..3165c03781 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs @@ -42,7 +42,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions readonly DesignItem[] extendedItemArray = new DesignItem[1]; IPlacementBehavior resizeBehavior; PlacementOperation operation; - private AdornerLayer _adornerLayer; public RotateThumbExtension() { @@ -81,8 +80,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions private void drag_Rotate_Started(DragListener drag) { - _adornerLayer = this.adornerPanel.TryFindParent(); - var designerItem = this.ExtendedItem.Component as FrameworkElement; this.parent = VisualTreeHelper.GetParent(designerItem) as UIElement; this.centerPoint = designerItem.TranslatePoint( @@ -140,7 +137,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } rtTransform.Properties["Angle"].SetValue(destAngle); - _adornerLayer.UpdateAdornersForElement(this.ExtendedItem.View, true); + ((DesignPanel) this.ExtendedItem.Services.DesignPanel).AdornerLayer.UpdateAdornersForElement(this.ExtendedItem.View, true); } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SkewThumbExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SkewThumbExtension.cs index 844b60dde0..65066ce356 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SkewThumbExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SkewThumbExtension.cs @@ -226,16 +226,20 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions { if (sender == null || e.PropertyName == "Width" || e.PropertyName == "Height") { AdornerPanel.SetPlacement(thumb1, - new RelativePlacement(HorizontalAlignment.Center, VerticalAlignment.Top) { - YOffset = 0, - XOffset = -1 * ((FrameworkElement)ExtendedItem.View).ActualWidth / 4 - }); + new RelativePlacement(HorizontalAlignment.Center, VerticalAlignment.Top) { + YOffset = 0, + XOffset = -1 * PlacementOperation.GetRealElementSize(ExtendedItem.View).Width / 4 + }); AdornerPanel.SetPlacement(thumb2, - new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Center) { - YOffset = -1 * ((FrameworkElement)ExtendedItem.View).ActualHeight / 4, - XOffset = 0 - }); + new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Center) { + YOffset = -1 * PlacementOperation.GetRealElementSize(ExtendedItem.View).Height / 4, + XOffset = 0 + }); + + var designPanel = this.ExtendedItem.Services.DesignPanel as DesignPanel; + if (designPanel != null) + designPanel.AdornerLayer.UpdateAdornersForElement(this.ExtendedItem.View, true); } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs index 90520ca808..a4ac2e5fb2 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs @@ -235,23 +235,26 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions void AddLines(Rect r, double inflate, bool requireOverlap, List h, List v, PlacementAlignment? filter) { - Rect r2 = r; - r2.Inflate(inflate, inflate); + if (r != Rect.Empty) + { + Rect r2 = r; + r2.Inflate(inflate, inflate); - if (filter == null || filter.Value.Vertical == VerticalAlignment.Top) - h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top - 1, Start = r.Left, End = r.Right }); - if (filter == null || filter.Value.Vertical == VerticalAlignment.Bottom) - h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Bottom - 1, Start = r.Left, End = r.Right }); - if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Left) - v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left - 1, Start = r.Top, End = r.Bottom }); - if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Right) - v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Right - 1, Start = r.Top, End = r.Bottom }); + if (filter == null || filter.Value.Vertical == VerticalAlignment.Top) + h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top - 1, Start = r.Left, End = r.Right }); + if (filter == null || filter.Value.Vertical == VerticalAlignment.Bottom) + h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Bottom - 1, Start = r.Left, End = r.Right }); + if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Left) + v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left - 1, Start = r.Top, End = r.Bottom }); + if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Right) + v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Right - 1, Start = r.Top, End = r.Bottom }); - if (filter == null) - { - h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top + Math.Abs((r2.Top - r2.Bottom) / 2), Start = r.Left, End = r.Right }); - v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left + Math.Abs((r2.Left - r2.Right) / 2), Start = r.Top, End = r.Bottom }); - } + if (filter == null) + { + h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top + Math.Abs((r2.Top - r2.Bottom) / 2), Start = r.Left, End = r.Right }); + v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left + Math.Abs((r2.Left - r2.Right) / 2), Start = r.Top, End = r.Bottom }); + } + } } void AddBaseline(DesignItem item, Rect bounds, List list) @@ -276,6 +279,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions void DrawLine(double x1, double y1, double x2, double y2) { + if (double.IsInfinity(x1) || double.IsNaN(x1) || double.IsInfinity(y1) || double.IsNaN(y1) || + double.IsInfinity(x2) || double.IsNaN(x2) || double.IsInfinity(y2) || double.IsNaN(y2)) + return; + var line1 = new Line() { X1 = x1, Y1 = y1, diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml similarity index 50% rename from src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml rename to src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml index d6c69df71b..7deb155b9f 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml @@ -1,8 +1,11 @@ - - - +> + + + + + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs new file mode 100644 index 0000000000..b581d15fe6 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs @@ -0,0 +1,51 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Linq; +using System.Windows; +using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + public partial class TextBlockRightClickContextMenu + { + private DesignItem designItem; + + public TextBlockRightClickContextMenu(DesignItem designItem) + { + this.designItem = designItem; + + InitializeComponent(); + } + + void Click_EditFormatedText(object sender, RoutedEventArgs e) + { + var dlg = new Window() + { + Content = new FormatedTextEditor(designItem), + Width = 440, + Height = 200, + WindowStyle = WindowStyle.ToolWindow, + Owner = ((DesignPanel) designItem.Context.Services.DesignPanel).TryFindParent(), + }; + + dlg.ShowDialog(); + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs new file mode 100644 index 0000000000..bb9fd11261 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs @@ -0,0 +1,53 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Linq; +using System.Windows.Controls; +using ICSharpCode.WpfDesign.Adorners; +using ICSharpCode.WpfDesign.Extensions; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + [ExtensionServer(typeof (OnlyOneItemSelectedExtensionServer))] + [ExtensionFor(typeof (TextBlock))] + [Extension(Order = 10)] + public class TextBlockRightClickContextMenuExtension : PrimarySelectionAdornerProvider + { + DesignPanel panel; + ContextMenu contextMenu; + + protected override void OnInitialized() + { + base.OnInitialized(); + + contextMenu = new TextBlockRightClickContextMenu(ExtendedItem); + panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; + if (panel != null) + panel.AddContextMenu(contextMenu); + } + + protected override void OnRemove() + { + if (panel != null) + panel.RemoveContextMenu(contextMenu); + + base.OnRemove(); + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandleMultipleItems.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandleMultipleItems.cs index 12a2505b3d..b5a915b2cd 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandleMultipleItems.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandleMultipleItems.cs @@ -66,8 +66,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions minX = minX < relativeLocation.X ? minX : relativeLocation.X; minY = minY < relativeLocation.Y ? minY : relativeLocation.Y; - maxX = maxX > relativeLocation.X + ((FrameworkElement)this.ExtendedItem.View).ActualWidth ? maxX : relativeLocation.X + ((FrameworkElement)this.ExtendedItem.View).ActualWidth; - maxY = maxY > relativeLocation.Y + ((FrameworkElement)this.ExtendedItem.View).ActualHeight ? maxY : relativeLocation.Y + ((FrameworkElement)this.ExtendedItem.View).ActualHeight; + maxX = maxX > relativeLocation.X + ((FrameworkElement)di.View).ActualWidth ? maxX : relativeLocation.X + ((FrameworkElement)di.View).ActualWidth; + maxY = maxY > relativeLocation.Y + ((FrameworkElement)di.View).ActualHeight ? maxY : relativeLocation.Y + ((FrameworkElement)di.View).ActualHeight; } Rectangle rect2 = new Rectangle() { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemContextMenu.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemContextMenu.xaml new file mode 100644 index 0000000000..8a4fbc3e5f --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemContextMenu.xaml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemContextMenu.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemContextMenu.xaml.cs new file mode 100644 index 0000000000..610b88f283 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemContextMenu.xaml.cs @@ -0,0 +1,41 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Linq; +using System.Windows.Controls; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + public partial class WrapItemContextMenu + { + private DesignItem designItem; + + public WrapItemContextMenu(DesignItem designItem) + { + this.designItem = designItem; + + InitializeComponent(); + } + + void Click_WrapInViewbox(object sender, System.Windows.RoutedEventArgs e) + { + ModelTools.WrapItemsNewContainer(this.designItem.Services.Selection.SelectedItems, typeof(Viewbox)); + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemContextMenuExtension.cs similarity index 80% rename from src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs rename to src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemContextMenuExtension.cs index 5f24f5caff..a3e098ac04 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemContextMenuExtension.cs @@ -18,9 +18,7 @@ using System; using System.Windows; -using System.Windows.Media; -using System.Windows.Shapes; - +using System.Windows.Controls; using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Designer; @@ -30,24 +28,29 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions /// /// /// - [ExtensionServer(typeof(MultipleSelectedExtensionServer))] + [ExtensionServer(typeof(OnlyOneItemSelectedExtensionServer))] [ExtensionFor(typeof(UIElement))] - public class RightClickMultipleItemsContextMenuExtension : SelectionAdornerProvider + [Extension(Order = 50)] + public class WrapItemContextMenuExtension : SelectionAdornerProvider { DesignPanel panel; - + ContextMenu contextMenu; + protected override void OnInitialized() { base.OnInitialized(); - + + contextMenu = new WrapItemContextMenu(ExtendedItem); panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; - panel.ContextMenu = new RightClickMultipleItemsContextMenu(ExtendedItem); + if (panel != null) + panel.AddContextMenu(contextMenu); } protected override void OnRemove() { - panel.ContextMenu = null; - + if (panel != null) + panel.RemoveContextMenu(contextMenu); + base.OnRemove(); } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml new file mode 100644 index 0000000000..d63536de8b --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml.cs similarity index 77% rename from src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml.cs rename to src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml.cs index e616350d12..4a61038d34 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml.cs @@ -17,28 +17,16 @@ // DEALINGS IN THE SOFTWARE. using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using ICSharpCode.WpfDesign.PropertyGrid; -using ICSharpCode.WpfDesign.Designer.Xaml; namespace ICSharpCode.WpfDesign.Designer.Extensions { - public partial class RightClickMultipleItemsContextMenu + public partial class WrapItemsContextMenu { private DesignItem designItem; - public RightClickMultipleItemsContextMenu(DesignItem designItem) + public WrapItemsContextMenu(DesignItem designItem) { this.designItem = designItem; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenuExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenuExtension.cs new file mode 100644 index 0000000000..9b3fdcca69 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenuExtension.cs @@ -0,0 +1,57 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Windows; +using System.Windows.Controls; +using ICSharpCode.WpfDesign.Adorners; +using ICSharpCode.WpfDesign.Extensions; +using ICSharpCode.WpfDesign.Designer; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + /// + /// + /// + [ExtensionServer(typeof(PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer))] + [ExtensionFor(typeof(UIElement))] + [Extension(Order = 50)] + public class WrapItemsContextMenuExtension : SelectionAdornerProvider + { + DesignPanel panel; + ContextMenu contextMenu; + + protected override void OnInitialized() + { + base.OnInitialized(); + + contextMenu = new WrapItemsContextMenu(ExtendedItem); + panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; + if (panel != null) + panel.AddContextMenu(contextMenu); + } + + protected override void OnRemove() + { + if (panel != null) + panel.RemoveContextMenu(contextMenu); + + base.OnRemove(); + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/canvas.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/canvas.png new file mode 100644 index 0000000000..9418691114 Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/canvas.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-bold.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-bold.png new file mode 100644 index 0000000000..200b9cfe5f Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-bold.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-color.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-color.png new file mode 100644 index 0000000000..676f1abb5e Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-color.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-italic.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-italic.png new file mode 100644 index 0000000000..18052c2e09 Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-italic.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-strike.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-strike.png new file mode 100644 index 0000000000..fa87f129ac Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-strike.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-underline.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-underline.png new file mode 100644 index 0000000000..506bb03768 Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-underline.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit.png new file mode 100644 index 0000000000..6db18b4ef1 Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/grid.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/grid.png new file mode 100644 index 0000000000..2eb69a4e43 Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/grid.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment-bottom.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment-bottom.png new file mode 100644 index 0000000000..17240991dd Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment-bottom.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment-center.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment-center.png new file mode 100644 index 0000000000..1a2ad5dec2 Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment-center.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment-left.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment-left.png new file mode 100644 index 0000000000..b96cf70205 Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment-left.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment-middle.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment-middle.png new file mode 100644 index 0000000000..a098f2e3fc Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment-middle.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment-right.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment-right.png new file mode 100644 index 0000000000..abbd5d1d9d Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment-right.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment.png new file mode 100644 index 0000000000..1b10483acf Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-alignment.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-arrange-back.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-arrange-back.png new file mode 100644 index 0000000000..0effc3bee3 Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-arrange-back.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-arrange.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-arrange.png new file mode 100644 index 0000000000..7bea99aac0 Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-arrange.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-stack-arrange-back.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-stack-arrange-back.png new file mode 100644 index 0000000000..3e56ba24ad Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-stack-arrange-back.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-stack-arrange.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-stack-arrange.png new file mode 100644 index 0000000000..db3286bb9a Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/layers-stack-arrange.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/paint-can-color.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/paint-can-color.png new file mode 100644 index 0000000000..1381f5af33 Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/paint-can-color.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/wrap-option.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/wrap-option.png new file mode 100644 index 0000000000..4ae3d5a840 Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/wrap-option.png differ diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs index f8c8d22406..d37f0845df 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs @@ -121,14 +121,15 @@ namespace ICSharpCode.WpfDesign.Designer internal static void CreateVisualTree(this UIElement element) { - try { + try + { var fixedDoc = new FixedDocument(); var pageContent = new PageContent(); var fixedPage = new FixedPage(); fixedPage.Children.Add(element); (pageContent as IAddChild).AddChild(fixedPage); fixedDoc.Pages.Add(pageContent); - + var f = new XpsSerializerFactory(); var w = f.CreateSerializerWriter(new MemoryStream()); w.Write(fixedDoc); @@ -141,31 +142,29 @@ namespace ICSharpCode.WpfDesign.Designer internal static Size GetDefaultSize(DesignItem createdItem) { - CreateVisualTree(createdItem.View); - - var s = Metadata.GetDefaultSize(createdItem.ComponentType, false); + var defS = Metadata.GetDefaultSize(createdItem.ComponentType, false); + if (defS != null) + return defS.Value; - if (double.IsNaN(s.Width) && createdItem.View.DesiredSize.Width > 0) - { - s.Width = createdItem.View.DesiredSize.Width; - } - if (double.IsNaN(s.Height) && createdItem.View.DesiredSize.Height > 0) - { - s.Height = createdItem.View.DesiredSize.Height; - } + CreateVisualTree(createdItem.View); + var s = createdItem.View.DesiredSize; + var newS = Metadata.GetDefaultSize(createdItem.ComponentType, true); - if (!(s.Width > 0)) - s.Width = newS.Width; + if (newS.HasValue) + { + if (!(s.Width > 5) && newS.Value.Width > 0) + s.Width = newS.Value.Width; - if (!(s.Height > 0)) - s.Height = newS.Height; + if (!(s.Height > 5) && newS.Value.Height > 0) + s.Height = newS.Value.Height; + } - if (double.IsNaN(s.Width)) { + if (double.IsNaN(s.Width) && GetWidth(createdItem.View) > 0) { s.Width = GetWidth(createdItem.View); } - if (double.IsNaN(s.Height)) { + if (double.IsNaN(s.Height) && GetWidth(createdItem.View) > 0) { s.Height = GetHeight(createdItem.View); } @@ -193,10 +192,16 @@ namespace ICSharpCode.WpfDesign.Designer public static void Resize(DesignItem item, double newWidth, double newHeight) { if (newWidth != GetWidth(item.View)) { - item.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(newWidth); + if(double.IsNaN(newWidth)) + item.Properties.GetProperty(FrameworkElement.WidthProperty).Reset(); + else + item.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(newWidth); } if (newHeight != GetHeight(item.View)) { - item.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(newHeight); + if (double.IsNaN(newHeight)) + item.Properties.GetProperty(FrameworkElement.HeightProperty).Reset(); + else + item.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(newHeight); } } @@ -217,87 +222,53 @@ namespace ICSharpCode.WpfDesign.Designer public DesignItem DesignItem { get; set; } } - + + private static ItemPos GetItemPos(PlacementOperation operation, DesignItem designItem) + { + var itemPos = new ItemPos() {DesignItem = designItem}; + + var pos = operation.CurrentContainerBehavior.GetPosition(operation, designItem); + itemPos.Xmin = pos.X; + itemPos.Xmax = pos.X + pos.Width; + itemPos.Ymin = pos.Y; + itemPos.Ymax = pos.Y + pos.Height; + + return itemPos; + } + public static void WrapItemsNewContainer(IEnumerable items, Type containerType) { var collection = items; var _context = collection.First().Context as XamlDesignContext; - var oldContainer = collection.First().Parent; + var container = collection.First().Parent; - if (collection.Any(x => x.Parent != oldContainer)) + if (collection.Any(x => x.Parent != container)) return; - + + //Change Code to use the Placment Operation! + var placement = container.Extensions.OfType().FirstOrDefault(); + if (placement == null) + return; + + var operation = PlacementOperation.Start(items.ToList(), PlacementType.Move); + var newInstance = Activator.CreateInstance(containerType); DesignItem newPanel = _context.Services.Component.RegisterComponentForDesigner(newInstance); - var changeGroup = newPanel.OpenGroup("Wrap in Container"); + //var changeGroup = newPanel.OpenGroup("Wrap in Container"); List itemList = new List(); foreach (var item in collection) { - - var itemPos = new ItemPos(){ DesignItem = item }; - itemList.Add(itemPos); - - if (oldContainer.Component is Canvas) { - var canvas = oldContainer.View as Canvas; - - if (item.Properties.GetAttachedProperty(Canvas.RightProperty) != null && item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) { - itemPos.HorizontalAlignment = HorizontalAlignment.Right; - itemPos.Xmax = canvas.ActualWidth - (double)item.Properties.GetAttachedProperty(Canvas.RightProperty).ValueOnInstance; - itemPos.Xmin = itemPos.Xmax - ((FrameworkElement)item.View).ActualWidth; - } - else if (item.Properties.GetAttachedProperty(Canvas.LeftProperty) != null && item.Properties.GetAttachedProperty(Canvas.LeftProperty).IsSet) { - itemPos.HorizontalAlignment = HorizontalAlignment.Left; - itemPos.Xmin = (double)item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance; - itemPos.Xmax = itemPos.Xmin + ((FrameworkElement)item.View).ActualWidth; - } else { - itemPos.HorizontalAlignment = HorizontalAlignment.Left; - itemPos.Xmax = itemPos.Xmin + ((FrameworkElement)item.View).ActualWidth; - } - - if (item.Properties.GetAttachedProperty(Canvas.BottomProperty) != null && item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) { - itemPos.VerticalAlignment = VerticalAlignment.Bottom; - itemPos.Ymax = canvas.ActualHeight - (double)item.Properties.GetAttachedProperty(Canvas.BottomProperty).ValueOnInstance; - itemPos.Ymin = itemPos.Ymax - ((FrameworkElement)item.View).ActualHeight; - } - else if (item.Properties.GetAttachedProperty(Canvas.TopProperty) != null && item.Properties.GetAttachedProperty(Canvas.TopProperty).IsSet) { - itemPos.VerticalAlignment = VerticalAlignment.Top; - itemPos.Ymin = (double)item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance; - itemPos.Ymax = itemPos.Ymin + ((FrameworkElement)item.View).ActualHeight; - } else { - itemPos.VerticalAlignment = VerticalAlignment.Top; - itemPos.Ymax = itemPos.Ymin + ((FrameworkElement)item.View).ActualHeight; - } - + itemList.Add(GetItemPos(operation, item)); + //var pos = placement.GetPosition(null, item); + if (container.Component is Canvas) { item.Properties.GetAttachedProperty(Canvas.RightProperty).Reset(); item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset(); item.Properties.GetAttachedProperty(Canvas.TopProperty).Reset(); item.Properties.GetAttachedProperty(Canvas.BottomProperty).Reset(); - } else if (oldContainer.Component is Grid) { - var grid = oldContainer.View as Grid; - - if ((HorizontalAlignment)item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance == HorizontalAlignment.Right) { - itemPos.HorizontalAlignment = HorizontalAlignment.Right; - itemPos.Xmax = grid.ActualWidth - ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Right; - itemPos.Xmin = itemPos.Xmax - ((FrameworkElement)item.View).ActualWidth; - } else { - itemPos.HorizontalAlignment = HorizontalAlignment.Left; - itemPos.Xmin = ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Left; - itemPos.Xmax = itemPos.Xmin + ((FrameworkElement)item.View).ActualWidth; - } - - if ((VerticalAlignment)item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance == VerticalAlignment.Bottom) { - itemPos.VerticalAlignment = VerticalAlignment.Bottom; - itemPos.Ymax = grid.ActualHeight - ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Bottom; - itemPos.Ymin = itemPos.Ymax - ((FrameworkElement)item.View).ActualHeight; - } else { - itemPos.VerticalAlignment = VerticalAlignment.Top; - itemPos.Ymin = ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Top; - itemPos.Ymax = itemPos.Ymin + ((FrameworkElement)item.View).ActualHeight; - } - + } else if (container.Component is Grid) { item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).Reset(); item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).Reset(); item.Properties.GetProperty(FrameworkElement.MarginProperty).Reset(); @@ -311,23 +282,8 @@ namespace ICSharpCode.WpfDesign.Designer var xmax = itemList.Max(x => x.Xmax); var ymin = itemList.Min(x => x.Ymin); var ymax = itemList.Max(x => x.Ymax); - - if (oldContainer.Component is Canvas) { - newPanel.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(xmax - xmin); - newPanel.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(ymax - ymin); - newPanel.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(xmin); - newPanel.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ymin); - } else if (oldContainer.Component is Grid) { - newPanel.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).SetValue(HorizontalAlignment.Left); - newPanel.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).SetValue(VerticalAlignment.Top); - newPanel.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(new Thickness(xmin, ymin, 0, 0)); - newPanel.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(xmax - xmin); - newPanel.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(ymax - ymin); - } - + foreach (var item in itemList) { - newPanel.ContentProperty.CollectionElements.Add(item.DesignItem); - if (newPanel.Component is Canvas) { if (item.HorizontalAlignment == HorizontalAlignment.Right) { item.DesignItem.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(xmax - item.Xmax); @@ -340,6 +296,9 @@ namespace ICSharpCode.WpfDesign.Designer } else { item.DesignItem.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(item.Ymin - ymin); } + + newPanel.ContentProperty.CollectionElements.Add(item.DesignItem); + } else if (newPanel.Component is Grid) { Thickness thickness = new Thickness(0); if (item.HorizontalAlignment == HorizontalAlignment.Right) { @@ -359,14 +318,272 @@ namespace ICSharpCode.WpfDesign.Designer } item.DesignItem.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(thickness); + + newPanel.ContentProperty.CollectionElements.Add(item.DesignItem); + + } else if (newPanel.Component is Viewbox) { + newPanel.ContentProperty.SetValue(item.DesignItem); } } - oldContainer.ContentProperty.CollectionElements.Add(newPanel); + PlacementOperation operation2 = PlacementOperation.TryStartInsertNewComponents( + container, + new[] { newPanel }, + new[] { new Rect(xmin, ymin, xmax - xmin, ymax - ymin).Round() }, + PlacementType.AddItem + ); - changeGroup.Commit(); + operation2.Commit(); + + operation.Commit(); _context.Services.Selection.SetSelectedComponents(new []{ newPanel }); } + + public static void ArrangeItems(IEnumerable items, ArrangeDirection arrangeDirection) + { + var collection = items; + + var _context = collection.First().Context as XamlDesignContext; + + var container = collection.First().Parent; + + if (collection.Any(x => x.Parent != container)) + return; + + var placement = container.Extensions.OfType().FirstOrDefault(); + if (placement == null) + return; + + var operation = PlacementOperation.Start(items.ToList(), PlacementType.Move); + + //var changeGroup = container.OpenGroup("Arrange Elements"); + + List itemList = new List(); + foreach (var item in collection) + { + itemList.Add(GetItemPos(operation, item)); + } + + var xmin = itemList.Min(x => x.Xmin); + var xmax = itemList.Max(x => x.Xmax); + var mpos = (xmax - xmin) / 2 + xmin; + var ymin = itemList.Min(x => x.Ymin); + var ymax = itemList.Max(x => x.Ymax); + var ympos = (ymax - ymin) / 2 + ymin; + + foreach (var item in collection) + { + switch (arrangeDirection) + { + case ArrangeDirection.Left: + { + if (container.Component is Canvas) + { + if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) + { + item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(xmin); + } + else + { + var pos = (double)((Panel)item.Parent.Component).ActualWidth - (xmin + (double) ((FrameworkElement) item.Component).ActualWidth); + item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos); + } + } + else if (container.Component is Grid) + { + if ((HorizontalAlignment)item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance != HorizontalAlignment.Right) + { + var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance; + margin.Left = xmin; + item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin); + } + else + { + var pos = (double)((Panel)item.Parent.Component).ActualWidth - (xmin + (double)((FrameworkElement)item.Component).ActualWidth); + var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance; + margin.Right = pos; + item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin); + } + } + } + break; + case ArrangeDirection.HorizontalMiddle: + { + if (container.Component is Canvas) + { + if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) + { + if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) + { + item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(mpos - (((FrameworkElement)item.Component).ActualWidth) / 2); + } + else + { + var pp = mpos - (((FrameworkElement)item.Component).ActualWidth) / 2; + var pos = (double)((Panel)item.Parent.Component).ActualWidth - pp - (((FrameworkElement)item.Component).ActualWidth); + item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos); + } + } + } + else if (container.Component is Grid) + { + if ((HorizontalAlignment)item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance != HorizontalAlignment.Right) + { + var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance; + margin.Left = mpos - (((FrameworkElement)item.Component).ActualWidth) / 2; + item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin); + } + else + { + var pp = mpos - (((FrameworkElement)item.Component).ActualWidth) / 2; + var pos = (double)((Panel)item.Parent.Component).ActualWidth - pp - (((FrameworkElement)item.Component).ActualWidth); + var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance; + margin.Right = pos; + item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin); + } + } + } + break; + case ArrangeDirection.Right: + { + if (container.Component is Canvas) + { + if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) + { + var pos = xmax - (double)((FrameworkElement)item.Component).ActualWidth; + item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(pos); + } + else + { + var pos = (double)((Panel)item.Parent.Component).ActualWidth - xmax; + item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos); + } + } + else if (container.Component is Grid) + { + if ((HorizontalAlignment)item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance != HorizontalAlignment.Right) + { + var pos = xmax - (double)((FrameworkElement)item.Component).ActualWidth; + var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance; + margin.Left = pos; + item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin); + } + else + { + var pos = (double)((Panel)item.Parent.Component).ActualWidth - xmax; + var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance; + margin.Right = pos; + item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin); + } + } + } + break; + case ArrangeDirection.Top: + { + if (container.Component is Canvas) + { + if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) + { + item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ymin); + } + else + { + var pos = (double)((Panel)item.Parent.Component).ActualHeight - (ymin + (double)((FrameworkElement)item.Component).ActualHeight); + item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos); + } + } + else if (container.Component is Grid) + { + if ((VerticalAlignment)item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance != VerticalAlignment.Bottom) + { + item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ymin); + var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance; + margin.Top = ymin; + item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin); + } + else + { + var pos = (double)((Panel)item.Parent.Component).ActualHeight - (ymin + (double)((FrameworkElement)item.Component).ActualHeight); + var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance; + margin.Bottom = pos; + item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin); + } + } + } + break; + case ArrangeDirection.VerticalMiddle: + { + if (container.Component is Canvas) + { + if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) + { + item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ympos - (((FrameworkElement)item.Component).ActualHeight) / 2); + } + else + { + var pp = mpos - (((FrameworkElement)item.Component).ActualHeight) / 2; + var pos = (double)((Panel)item.Parent.Component).ActualHeight - pp - (((FrameworkElement)item.Component).ActualHeight); + item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos); + } + } + else if (container.Component is Grid) + { + if ((VerticalAlignment)item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance != VerticalAlignment.Bottom) + { + var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance; + margin.Top = ympos - (((FrameworkElement)item.Component).ActualHeight) / 2; + item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin); + } + else + { + var pp = mpos - (((FrameworkElement)item.Component).ActualHeight) / 2; + var pos = (double)((Panel)item.Parent.Component).ActualHeight - pp - (((FrameworkElement)item.Component).ActualHeight); + var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance; + margin.Bottom = pos; + item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin); + } + } + } + break; + case ArrangeDirection.Bottom: + { + if (container.Component is Canvas) + { + if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) + { + var pos = ymax - (double)((FrameworkElement)item.Component).ActualHeight; + item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(pos); + } + else + { + var pos = (double)((Panel)item.Parent.Component).ActualHeight - ymax; + item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos); + } + } + else if (container.Component is Grid) + { + if ((VerticalAlignment)item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance != VerticalAlignment.Bottom) + { + var pos = ymax - (double)((FrameworkElement)item.Component).ActualHeight; + var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance; + margin.Top = pos; + item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin); + } + else + { + var pos = (double)((Panel)item.Parent.Component).ActualHeight - ymax; + var margin = (Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance; + margin.Bottom = pos; + item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin); + } + } + } + break; + } + } + + operation.Commit(); + } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml new file mode 100644 index 0000000000..27c3bf591e --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml @@ -0,0 +1,832 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"); + } + + [Test] + public void Animation2() + { + //Loaded Property has to be found, because this so also works in WPF + + TestLoading(@" + + + +"); + } + + [Test] + public void Animation3() + { + TestLoading(@" + + + +"); + } + + [Test] + public void ContentControl1() + { + TestLoading(@" + + + + + +"); + } + + [Test] + public void ContentControl2() + { + TestLoading(@" + + + + + + + +"); + } + + [Test] + public void Children1() + { + TestLoading(@" + + + + + + +"); + } + } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs index 09a3b28beb..064a4bb77c 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs @@ -23,6 +23,7 @@ using System.ComponentModel; using System.Globalization; using System.Reflection; using System.Windows; +using System.Windows.Documents; using System.Windows.Markup; namespace ICSharpCode.WpfDesign.XamlDom @@ -37,10 +38,11 @@ namespace ICSharpCode.WpfDesign.XamlDom /// public static bool IsCollectionType(Type type) { - return typeof(IList).IsAssignableFrom(type) + return type != typeof(LineBreak) && ( + typeof(IList).IsAssignableFrom(type) || type.IsArray || typeof(IAddChild).IsAssignableFrom(type) - || typeof(IDictionary).IsAssignableFrom(type); + || typeof(IDictionary).IsAssignableFrom(type)); } /// diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs index 0429d5192c..fbe1131988 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs @@ -70,7 +70,7 @@ namespace ICSharpCode.WpfDesign.XamlDom if (property.IsAttached == false) { foreach (XamlProperty p in properties) { if (p.IsAttached == false && p.PropertyName == property.PropertyName) - Debug.Fail("duplicate property"); + throw new XamlLoadException("duplicate property"); } } #endif diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs index 975d6c725e..e32e261e3e 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs @@ -21,6 +21,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Markup; +using System.Xaml; namespace ICSharpCode.WpfDesign.XamlDom { @@ -28,7 +29,7 @@ namespace ICSharpCode.WpfDesign.XamlDom /// A service provider that provides the IProvideValueTarget and IXamlTypeResolver services. /// No other services (e.g. from the document's service provider) are offered. /// - public class XamlObjectServiceProvider : IServiceProvider, IProvideValueTarget + public class XamlObjectServiceProvider : IServiceProvider, IProvideValueTarget, IXamlSchemaContextProvider, IAmbientProvider { /// /// Creates a new XamlObjectServiceProvider instance. @@ -60,6 +61,12 @@ namespace ICSharpCode.WpfDesign.XamlDom if (serviceType == typeof(IXamlTypeResolver)) { return Resolver; } + if (serviceType == typeof(IXamlSchemaContextProvider)) { + return this; + } + if (serviceType == typeof(IAmbientProvider)) { + return this; + } return null; } @@ -102,5 +109,58 @@ namespace ICSharpCode.WpfDesign.XamlDom } #endregion - } + + #region IXamlSchemaContextProvider Members + + private XamlSchemaContext iCsharpXamlSchemaContext; + + //Maybe we new our own XamlSchemaContext? + //private class ICsharpXamlSchemaContext : XamlSchemaContext + //{ + // public override XamlType GetXamlType(Type type) + // { + // return base.GetXamlType(type); + // } + //} + + public XamlSchemaContext SchemaContext + { + get + { + return iCsharpXamlSchemaContext = iCsharpXamlSchemaContext ?? new XamlSchemaContext(); + } + } + + #endregion + + #region IAmbientProvider Members + + public AmbientPropertyValue GetFirstAmbientValue(IEnumerable ceilingTypes, params XamlMember[] properties) + { + return null; + } + + public object GetFirstAmbientValue(params XamlType[] types) + { + return null; + } + + public IEnumerable GetAllAmbientValues(IEnumerable ceilingTypes, params XamlMember[] properties) + { + return new List(); + } + + public IEnumerable GetAllAmbientValues(params XamlType[] types) + { + return new List(); + } + + public IEnumerable GetAllAmbientValues(IEnumerable ceilingTypes, bool searchLiveStackOnly, IEnumerable types, + params XamlMember[] properties) + { + return new List(); + } + + #endregion + } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs index 003b9ef987..ab11c59682 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs @@ -22,6 +22,7 @@ using System.ComponentModel; using System.Globalization; using System.Diagnostics; using System.IO; +using System.Linq; using System.Reflection; using System.Windows; using System.Windows.Interop; @@ -279,7 +280,7 @@ namespace ICSharpCode.WpfDesign.XamlDom } continue; } - + ParseObjectAttribute(obj, attribute); } @@ -326,34 +327,50 @@ namespace ICSharpCode.WpfDesign.XamlDom } } } - - foreach (XmlNode childNode in elementChildNodes) { - XmlElement childElement = childNode as XmlElement; - if (childElement != null) { - if (childElement.NamespaceURI == XamlConstants.XamlNamespace) - continue; - - if (ObjectChildElementIsPropertyElement(childElement)) { - ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty); - continue; - } + + if (collectionType != null && collectionInstance == null && elementChildNodes.Count() == 1) + { + var firstChild = elementChildNodes.First() as XmlElement; + if (ObjectChildElementIsCollectionInstance(firstChild, collectionType)) + { + collectionInstance = ParseObject(firstChild); + collectionProperty.PropertyValue = (XamlPropertyValue) collectionInstance; } - if (initializeFromTextValueInsteadOfConstructor != null) - continue; - XamlPropertyValue childValue = ParseValue(childNode); - if (childValue != null) { - if (collectionProperty != null) { - collectionProperty.ParserAddCollectionElement(collectionPropertyElement, childValue); - CollectionSupport.AddToCollection(collectionType, collectionInstance, childValue); - } else { - if (defaultProperty == null) - throw new XamlLoadException("This element does not have a default value, cannot assign to it"); - - if (isDefaultValueSet) - throw new XamlLoadException("default property may have only one value assigned"); + else + { + throw new XamlLoadException("Collection Instance is null"); + } + } + else + { + foreach (XmlNode childNode in elementChildNodes) { + XmlElement childElement = childNode as XmlElement; + if (childElement != null) { + if (childElement.NamespaceURI == XamlConstants.XamlNamespace) + continue; - obj.AddProperty(new XamlProperty(obj, defaultProperty, childValue)); - isDefaultValueSet = true; + if (ObjectChildElementIsPropertyElement(childElement)) { + ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty); + continue; + } + } + if (initializeFromTextValueInsteadOfConstructor != null) + continue; + XamlPropertyValue childValue = ParseValue(childNode); + if (childValue != null) { + if (collectionProperty != null) { + collectionProperty.ParserAddCollectionElement(collectionPropertyElement, childValue); + CollectionSupport.AddToCollection(collectionType, collectionInstance, childValue); + } else { + if (defaultProperty == null) + throw new XamlLoadException("This element does not have a default value, cannot assign to it"); + + if (isDefaultValueSet) + throw new XamlLoadException("default property may have only one value assigned"); + + obj.AddProperty(new XamlProperty(obj, defaultProperty, childValue)); + isDefaultValueSet = true; + } } } } @@ -581,7 +598,12 @@ namespace ICSharpCode.WpfDesign.XamlDom { return element.LocalName.Contains("."); } - + + static bool ObjectChildElementIsCollectionInstance(XmlElement element, Type collectionType) + { + return element.Name == collectionType.Name; + } + static bool IsElementChildACollectionForProperty(XamlTypeFinder typeFinder, XmlElement element, XamlPropertyInfo propertyInfo) { return element.ChildNodes.Count == 1 && propertyInfo.ReturnType.IsAssignableFrom(FindType(typeFinder, element.FirstChild.NamespaceURI, element.FirstChild.LocalName)); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs index eee4a6848e..9e95465448 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs @@ -21,10 +21,8 @@ using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; -using System.Text; using System.Xml; using System.Windows; -using System.Windows.Markup; namespace ICSharpCode.WpfDesign.XamlDom { @@ -139,7 +137,7 @@ namespace ICSharpCode.WpfDesign.XamlDom } /// - /// Gets if the property represents the FrameworkElement.Resources property that holds a locally-defined resource dictionary. + /// Gets if the property represents the FrameworkElement.Resources property that holds a locally-defined resource dictionary. /// public bool IsResources { get { return isResources; } @@ -264,7 +262,7 @@ namespace ICSharpCode.WpfDesign.XamlDom propertyValue = null; } if (_propertyElement != null) { - Debug.Assert(!isExplicitCollection || _propertyElement.ParentNode == null); + Debug.Assert(!isExplicitCollection || _propertyElement.ParentNode == null); if (!isExplicitCollection) { _propertyElement.ParentNode.RemoveChild(_propertyElement); @@ -315,19 +313,47 @@ namespace ICSharpCode.WpfDesign.XamlDom return this.IsAttached ? this.PropertyTargetType : parentObject.ElementType; } - static XmlNode FindChildNode(XmlNode node, string localName, string namespaceURI) + static XmlNode FindChildNode(XmlNode node, Type elementType, string propertyName, XamlDocument xamlDocument) { - foreach (XmlNode childNode in node.ChildNodes) { + var localName = elementType.Name + "." + propertyName; + var namespaceURI = xamlDocument.GetNamespaceFor(elementType); + + foreach (XmlNode childNode in node.ChildNodes) + { if (childNode.LocalName == localName && childNode.NamespaceURI == namespaceURI) + { return childNode; + } } + var type = elementType.BaseType; + namespaceURI = xamlDocument.GetNamespaceFor(type); + + while (type != typeof(object)) + { + if (type.GetProperty(propertyName) == null) + break; + + localName = type.Name + "." + propertyName; + + foreach (XmlNode childNode in node.ChildNodes) + { + if (childNode.LocalName == localName && childNode.NamespaceURI == namespaceURI) + { + return childNode; + } + } + + type = type.BaseType; + } + return null; } bool IsNodeCollectionForThisProperty(XmlNode node) { - return _propertyElement == null && this.PropertyName != this.ParentObject.ContentPropertyName && this.ReturnType.IsAssignableFrom(this.ParentObject.OwnerDocument.TypeFinder.GetType(node.NamespaceURI, node.LocalName)); + //Remove the commented check! This is Possible: BeginStoryboard=>The COntent Property is Storyboard, and the Content Element is also Storyboard! + return _propertyElement == null /* && this.PropertyName != this.ParentObject.ContentPropertyName */ && this.ReturnType.IsAssignableFrom(this.ParentObject.OwnerDocument.TypeFinder.GetType(node.NamespaceURI, node.LocalName)); } internal void AddChildNodeToProperty(XmlNode newChildNode) @@ -335,7 +361,7 @@ namespace ICSharpCode.WpfDesign.XamlDom if (this.IsCollection) { if (IsNodeCollectionForThisProperty(newChildNode)) { Type propertyElementType = GetPropertyElementType(); - XmlNode parentNode = FindChildNode(parentObject.XmlElement, propertyElementType.Name + "." + this.PropertyName, parentObject.OwnerDocument.GetNamespaceFor(propertyElementType)); + XmlNode parentNode = FindChildNode(parentObject.XmlElement, propertyElementType, this.PropertyName, parentObject.OwnerDocument); if (parentNode == null) { parentNode = CreatePropertyElement(); @@ -384,7 +410,7 @@ namespace ICSharpCode.WpfDesign.XamlDom if (collection == null) { if (collectionElements.Count == 0 && this.PropertyName != this.ParentObject.ContentPropertyName) { // we have to create the collection element - _propertyElement = CreatePropertyElement(); + _propertyElement = CreatePropertyElement(); if (this.IsResources) { parentObject.XmlElement.PrependChild(_propertyElement); @@ -423,11 +449,11 @@ namespace ICSharpCode.WpfDesign.XamlDom name = PropertyTargetType.Name + "." + PropertyName; string ns = ParentObject.OwnerDocument.GetNamespaceFor(PropertyTargetType); - string prefix = element.GetPrefixOfNamespace(ns); + string prefix = element.GetPrefixOfNamespace(ns); if (String.IsNullOrEmpty(prefix)) { - prefix = ParentObject.OwnerDocument.GetPrefixForNamespace(ns); - } + prefix = ParentObject.OwnerDocument.GetPrefixForNamespace(ns); + } if (!string.IsNullOrEmpty(prefix)) { element.SetAttribute(name, ns, value); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Adorners/AdornerPanel.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Adorners/AdornerPanel.cs index f9bd39d38d..a7615de7a5 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Adorners/AdornerPanel.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Adorners/AdornerPanel.cs @@ -137,7 +137,8 @@ namespace ICSharpCode.WpfDesign.Adorners e.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); } } - return this.AdornedElement.RenderSize; + + return PlacementOperation.GetRealElementSize(this.AdornedElement); } else { return base.MeasureOverride(availableSize); } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionAttribute.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionAttribute.cs new file mode 100644 index 0000000000..2f321ae680 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionAttribute.cs @@ -0,0 +1,32 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; + +namespace ICSharpCode.WpfDesign.Extensions +{ + /// + /// Attribute to specify Properties of the Extension. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=false)] + public sealed class ExtensionAttribute : Attribute + { + //The Order in wich the Extensions are used + public int Order { get; set; } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionManager.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionManager.cs index 21046f321e..676e2400da 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionManager.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionManager.cs @@ -65,12 +65,14 @@ namespace ICSharpCode.WpfDesign.Extensions internal readonly Type ExtensionType; internal readonly ExtensionServer Server; internal readonly Type OverriddenExtensionType; - - public ExtensionEntry(Type extensionType, ExtensionServer server, Type overriddenExtensionType) + internal readonly int Order; + + public ExtensionEntry(Type extensionType, ExtensionServer server, Type overriddenExtensionType, int Order) { this.ExtensionType = extensionType; this.Server = server; this.OverriddenExtensionType = overriddenExtensionType; + this.Order = Order; } } @@ -104,7 +106,7 @@ namespace ICSharpCode.WpfDesign.Extensions result.Add(entry); } } - return result; + return result.OrderBy(x => x.Order).ToList(); } /// @@ -184,7 +186,8 @@ namespace ICSharpCode.WpfDesign.Extensions foreach (ExtensionForAttribute designerFor in extensionForAttributes) { ExtensionServer server = GetServerForExtension(type); - AddExtensionEntry(designerFor.DesignedItemType, new ExtensionEntry(type, server, designerFor.OverrideExtension)); + ExtensionAttribute extensionAttribute = type.GetCustomAttributes(typeof(ExtensionAttribute), false).FirstOrDefault() as ExtensionAttribute; + AddExtensionEntry(designerFor.DesignedItemType, new ExtensionEntry(type, server, designerFor.OverrideExtension, extensionAttribute != null ? extensionAttribute.Order : 0)); } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs index 143ff20d57..359a4823a0 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs @@ -313,7 +313,7 @@ namespace ICSharpCode.WpfDesign /// Gets the default size for new controls of the specified type, /// or new Size(double.NaN, double.NaN) if no default size was registered. /// - public static Size GetDefaultSize(Type t, bool checkBasetype = true) + public static Size? GetDefaultSize(Type t, bool checkBasetype = true) { Size s; lock (defaultSizes) { @@ -324,7 +324,7 @@ namespace ICSharpCode.WpfDesign t = checkBasetype ? t.BaseType : null; } } - return new Size(double.NaN, double.NaN); + return null; } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs index 0443f9d2fa..f217cbd41c 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs @@ -22,9 +22,6 @@ using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; using System.Windows; -using System.Windows.Input; - -using ICSharpCode.WpfDesign.Adorners; using System.Windows.Media; namespace ICSharpCode.WpfDesign @@ -204,7 +201,33 @@ namespace ICSharpCode.WpfDesign this.changeGroup = items[0].Context.OpenGroup(type.ToString(), items); } - + + /// + /// The Size wich the Element really should have (even if its smaller Rendered (like emtpy Image!)) + /// + /// + /// + public static Size GetRealElementSize(UIElement element) + { + var size = element.RenderSize; + if (element is FrameworkElement && !double.IsNaN(((FrameworkElement)element).Width)) + size.Width = ((FrameworkElement)element).Width; + if (element is FrameworkElement && !double.IsNaN(((FrameworkElement)element).Height)) + size.Height = ((FrameworkElement)element).Height; + + if (element is FrameworkElement && size.Width < ((FrameworkElement)element).MinWidth) + size.Width = ((FrameworkElement)element).MinWidth; + if (element is FrameworkElement && size.Height < ((FrameworkElement)element).MinHeight) + size.Height = ((FrameworkElement)element).Height; + + if (element is FrameworkElement && size.Width == 0) + size.Width = element.DesiredSize.Width; + if (element is FrameworkElement && size.Height == 0) + size.Height = element.DesiredSize.Height; + + return size; + } + /// /// Gets the placement behavior associated with the specified items. /// diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/TypeHelper.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/TypeHelper.cs index 252e33aba8..6af5d1e222 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/TypeHelper.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/TypeHelper.cs @@ -102,6 +102,7 @@ namespace ICSharpCode.WpfDesign.PropertyGrid } else { + var l=TypeDescriptor.GetProperties(element); foreach(PropertyDescriptor p in TypeDescriptor.GetProperties(element)){ if (!p.IsBrowsable) continue; if (p.IsReadOnly && !typeof(ICollection).IsAssignableFrom(p.PropertyType)) continue; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs index a799c1f84e..bcb7c18494 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs @@ -147,6 +147,6 @@ namespace ICSharpCode.WpfDesign /// /// Occurs when an element is dropped on the design panel. /// - event DragEventHandler Drop; + event DragEventHandler Drop; } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj index 4d2b74cf43..0159bd0b0f 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj @@ -74,6 +74,7 @@ + diff --git a/src/Libraries/WPFExtendedToolkit/Xceed.Wpf.Toolkit.dll b/src/Libraries/WPFExtendedToolkit/Xceed.Wpf.Toolkit.dll index 7af68875f9..edc55cca2f 100644 Binary files a/src/Libraries/WPFExtendedToolkit/Xceed.Wpf.Toolkit.dll and b/src/Libraries/WPFExtendedToolkit/Xceed.Wpf.Toolkit.dll differ