|
| 1 | +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a copy of this |
| 4 | +// software and associated documentation files (the "Software"), to deal in the Software |
| 5 | +// without restriction, including without limitation the rights to use, copy, modify, merge, |
| 6 | +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons |
| 7 | +// to whom the Software is furnished to do so, subject to the following conditions: |
| 8 | +// |
| 9 | +// The above copyright notice and this permission notice shall be included in all copies or |
| 10 | +// substantial portions of the Software. |
| 11 | +// |
| 12 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 13 | +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
| 14 | +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
| 15 | +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 16 | +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 17 | +// DEALINGS IN THE SOFTWARE. |
| 18 | + |
| 19 | +using System; |
| 20 | +using System.Windows.Controls; |
| 21 | +using System.Windows; |
| 22 | +using System.Windows.Input; |
| 23 | +using System.Windows.Media; |
| 24 | +using System.Windows.Shapes; |
| 25 | +using ICSharpCode.WpfDesign.Adorners; |
| 26 | +using ICSharpCode.WpfDesign.Extensions; |
| 27 | + |
| 28 | +using ICSharpCode.WpfDesign.Designer.Services; |
| 29 | +using ICSharpCode.WpfDesign.Designer.Controls; |
| 30 | + |
| 31 | +namespace ICSharpCode.WpfDesign.Designer.Extensions |
| 32 | +{ |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// The drag handle displayed for Framework Elements |
| 36 | + /// </summary> |
| 37 | + [ExtensionServer(typeof(PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer))] |
| 38 | + [ExtensionFor(typeof(FrameworkElement))] |
| 39 | + public class TopLeftContainerDragHandleMultipleItems : AdornerProvider |
| 40 | + { |
| 41 | + /// <summary/> |
| 42 | + public TopLeftContainerDragHandleMultipleItems() |
| 43 | + { } |
| 44 | + |
| 45 | + protected override void OnInitialized() |
| 46 | + { |
| 47 | + base.OnInitialized(); |
| 48 | + |
| 49 | + ContainerDragHandle rect = new ContainerDragHandle(); |
| 50 | + |
| 51 | + rect.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs e) { |
| 52 | + //Services.Selection.SetSelectedComponents(new DesignItem[] { this.ExtendedItem }, SelectionTypes.Auto); |
| 53 | + new DragMoveMouseGesture(this.ExtendedItem, false).Start(this.ExtendedItem.Services.DesignPanel,e); |
| 54 | + e.Handled=true; |
| 55 | + }; |
| 56 | + |
| 57 | + var items = this.ExtendedItem.Services.Selection.SelectedItems; |
| 58 | + |
| 59 | + double minX = 0; |
| 60 | + double minY = 0; |
| 61 | + double maxX = 0; |
| 62 | + double maxY = 0; |
| 63 | + |
| 64 | + foreach (DesignItem di in items) { |
| 65 | + Point relativeLocation = di.View.TranslatePoint(new Point(0, 0), this.ExtendedItem.View); |
| 66 | + |
| 67 | + minX = minX < relativeLocation.X ? minX : relativeLocation.X; |
| 68 | + minY = minY < relativeLocation.Y ? minY : relativeLocation.Y; |
| 69 | + maxX = maxX > relativeLocation.X + ((FrameworkElement)this.ExtendedItem.View).ActualWidth ? maxX : relativeLocation.X + ((FrameworkElement)this.ExtendedItem.View).ActualWidth; |
| 70 | + maxY = maxY > relativeLocation.Y + ((FrameworkElement)this.ExtendedItem.View).ActualHeight ? maxY : relativeLocation.Y + ((FrameworkElement)this.ExtendedItem.View).ActualHeight; |
| 71 | + } |
| 72 | + |
| 73 | + Rectangle rect2 = new Rectangle() { |
| 74 | + Width = (maxX - minX) + 4, |
| 75 | + Height = (maxY - minY) + 4, |
| 76 | + Stroke = Brushes.Black, |
| 77 | + StrokeThickness = 2, |
| 78 | + StrokeDashArray = new DoubleCollection(){ 2, 2 }, |
| 79 | + }; |
| 80 | + |
| 81 | + RelativePlacement p = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top); |
| 82 | + p.XOffset = minX - 3; |
| 83 | + p.YOffset = minY - 3; |
| 84 | + |
| 85 | + RelativePlacement p2 = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top); |
| 86 | + p2.XOffset = (minX + rect2.Width) - 2; |
| 87 | + p2.YOffset = (minY + rect2.Height) - 2; |
| 88 | + |
| 89 | + AddAdorner(p, AdornerOrder.Background, rect); |
| 90 | + AddAdorner(p2, AdornerOrder.Background, rect2); |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments