From b33f8cf0daf834475f9fd9bf09a7c0881698d2dc Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 27 Oct 2014 14:53:48 +0100 Subject: [PATCH] Bugfixes for Image Placement, Formated Text, ... --- .../Project/Controls/AdornerLayer.cs | 12 +- .../Project/Controls/ResizeThumb.cs | 4 +- .../WpfDesign.Designer/Project/DesignPanel.cs | 6 +- .../Extensions/BorderForImageControl.cs | 101 +++ .../Extensions/CanvasPlacementSupport.cs | 9 +- .../Extensions/DefaultPlacementBehavior.cs | 14 +- .../Extensions/GridPlacementSupport.cs | 8 +- .../Extensions/MarginHandleExtension.cs | 2 +- .../Extensions/SnaplinePlacementBehavior.cs | 4 + .../TextBlockRightClickContextMenu.xaml.cs | 2 +- .../Project/Images/edit-underline.png | Bin 0 -> 260 bytes .../Project/Images/paint-can-color.png | Bin 0 -> 697 bytes .../WpfDesign.Designer/Project/ModelTools.cs | 6 +- .../FormatedTextEditor.xaml | 830 +++++++++++++++++- .../FormatedTextEditor.xaml.cs | 19 +- .../Project/WpfDesign.Designer.csproj | 7 + .../Project/Adorners/AdornerPanel.cs | 3 +- .../WpfDesign/Project/PlacementOperation.cs | 16 +- 18 files changed, 999 insertions(+), 44 deletions(-) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/BorderForImageControl.cs create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/edit-underline.png create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/paint-can-color.png 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 e7912acdb5..6dd91b6590 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/AdornerLayer.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/AdornerLayer.cs @@ -229,13 +229,13 @@ namespace ICSharpCode.WpfDesign.Designer.Controls //Fix Adorner Display of Image (or maybe other components...) var size = adorner.DesiredSize; - if (size.Height==0 && size.Width==0 && adorner.AdornedElement is FrameworkElement) - size = new Size(((FrameworkElement)adorner.AdornedElement).Width, ((FrameworkElement)adorner.AdornedElement).Height); + //if (size.Height==0 && size.Width==0 && adorner.AdornedElement is FrameworkElement) + // size = new Size(((FrameworkElement)adorner.AdornedElement).Width, ((FrameworkElement)adorner.AdornedElement).Height); - if (double.IsNaN(size.Width)) - size.Width = 0; - if (double.IsNaN(size.Height)) - size.Height = 0; + //if (double.IsNaN(size.Width)) + // size.Width = 0; + //if (double.IsNaN(size.Height)) + // size.Height = 0; adorner.Arrange(new Rect(new Point(0, 0), size)); } 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/DesignPanel.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs index c3c43ec9e4..47b0480465 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs @@ -102,8 +102,8 @@ namespace ICSharpCode.WpfDesign.Designer return result; } - - /// + + /// /// Performs a hit test on the design surface, raising for each match. /// Hit testing continues while the callback returns true. /// @@ -119,7 +119,7 @@ namespace ICSharpCode.WpfDesign.Designer HitTestFilterCallback filterBehavior = CustomHitTestFilterBehavior ?? FilterHitTestInvisibleElements; CustomHitTestFilterBehavior = null; hitTestElements.Clear(); - + if (testAdorners) { RunHitTest( 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..ace2505264 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/BorderForImageControl.cs @@ -0,0 +1,101 @@ +// 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; + + protected override void OnInitialized() + { + base.OnInitialized(); + + UpdateAdorner(); + } + + void UpdateAdorner() + { + var element = ExtendedItem.Component as UIElement; + if (element != null) { + //if (element.IsVisible) { + CreateAdorner(); + //} + //else { + // RemoveAdorner(); + //} + } + } + + private void CreateAdorner() + { + if (adornerPanel == null) { + + if (cachedAdornerPanel == null) { + cachedAdornerPanel = new AdornerPanel(); + cachedAdornerPanel.Order = AdornerOrder.Background; + var 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); + } + } + + private void RemoveAdorner() + { + if (adornerPanel != null) { + Adorners.Remove(adornerPanel); + adornerPanel = 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 b84847d33d..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,23 +70,20 @@ 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); //Fixes, Empty Image Resized to 0 //return new Rect(p, child.RenderSize); - var size = item.View.RenderSize; - if (item.View is FrameworkElement) - size = new Size(((FrameworkElement)item.View).Width, ((FrameworkElement)item.View).Height); - return new Rect(p, size); + 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 3e70edd0cd..934cf9d1a7 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs @@ -89,10 +89,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var p = item.View.TranslatePoint(new Point(), operation.CurrentContainer.View); //Fixes, Empty Image Resized to 0 //return new Rect(p, item.View.RenderSize); - var size = item.View.RenderSize; - if (item.View is FrameworkElement) - size = new Size(((FrameworkElement) item.View).Width, ((FrameworkElement) item.View).Height); - return new Rect(p, size); + + return new Rect(p, PlacementOperation.GetRealElementSize(item.View)); } public virtual void BeforeSetPosition(PlacementOperation operation) @@ -101,7 +99,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) @@ -163,7 +162,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions return false; } } - + + if (ExtendedItem.ContentProperty.ReturnType == typeof(string)) + return false; + if (!ExtendedItem.ContentProperty.IsSet) return true; 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/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/SnaplinePlacementBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs index 12aace83a1..a4ac2e5fb2 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs @@ -279,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/TextBlockRightClickContextMenu.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs index 679c4b3a31..1b596caa96 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs @@ -50,7 +50,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var dlg = new Window() { Content = new FormatedTextEditor(designItem), - Width = 400, + Width = 440, Height = 200, WindowStyle = WindowStyle.ToolWindow, Owner = ((DesignPanel) designItem.Context.Services.DesignPanel).TryFindParent(), 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 0000000000000000000000000000000000000000..506bb03768462f69a2090947dd732cb109cd991a GIT binary patch literal 260 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`k|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*D5XmU+53hE&{2`t$$4J+o>P$4^|t@EWqx8m!A&swhsOyBD!w7bcbCtbpT$mLJd=@j$h)S{5iMV2`IKe)ppeivVO|5}}nPG~Pb#6eQnitT;44$rjF6*2U FngGA}Tp|Df literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..1381f5af3351646667eadca45403bb6b856d56b7 GIT binary patch literal 697 zcmV;q0!ICbP)&^Ucn3AhTF3aJgLg!zNp;mZMN8q2OHfr6Up~Cn5`|O9EMb-iYealRua^%G4`qt&jf{-I<9mw>mz)@PE`sAY@WbSR zfJ_1lKA-P-DwPWK`~5ofn;)f#b`8oI#Q)d9j=}xppiqNP~hO;0NHF7UauG1+dJ6b zmyk|p5Rd0pikZ;+Mx*hx+wDGVx7*-5oemfnIT#EEsC`r_6>Z|HtE`Y7f-nlR*-Wu9 z@Qu$gR)7Zkl7t}Ar_#zxk_1_nHFC4rgvn%v$MfKrY_r)gH+T23!C;7fFP9nR3VU#@ z5;G#(3Af|%PjAZQs@C=qd3^jT=I8G(k?^K?-V@txUsng$=6F_>K~a>iH08wf^whE> z@yBGV)e5)!)?&3oin*1|@OgDUXd( zevGn52|9uZMdhF>OabK6smSCvv>!oLS*}8;F@X(oTr>onK)?SR!~RJ`*&?~{@8)6x f(f<&L{t{pSJEK#W6FAu100000NkvXXu0mjf!=OTq literal 0 HcmV?d00001 diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs index c7dad43d77..3c60527564 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs @@ -154,10 +154,10 @@ namespace ICSharpCode.WpfDesign.Designer if (newS.HasValue) { - if (!(s.Width > 0) && newS.Value.Width > 0) + if (!(s.Width > 5) && newS.Value.Width > 0) s.Width = newS.Value.Width; - if (!(s.Height > 0) && newS.Value.Height > 0) + if (!(s.Height > 5) && newS.Value.Height > 0) s.Height = newS.Value.Height; } @@ -187,7 +187,7 @@ namespace ICSharpCode.WpfDesign.Designer return element.RenderSize.Height; else return v; - } + } public static void Resize(DesignItem item, double newWidth, double newHeight) { 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 index 37cc227739..b9767044bb 100644 --- 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 @@ -4,17 +4,829 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" + xmlns:sys="clr-namespace:System;assembly=mscorlib" + xmlns:componentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase" mc:Ignorable="d" d:DesignWidth="410" d:DesignHeight="259" > - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + - -