public override bool OnMouseUp(Glyph g, MouseButtons button) { try { if (this.dragging) { if (this.dragManager != null) { this.dragManager.OnMouseUp(); this.dragManager = null; this.lastSnapOffset = Point.Empty; this.didSnap = false; } if ((this.resizeComponents != null) && (this.resizeComponents.Length > 0)) { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Width"]; PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Height"]; PropertyDescriptor descriptor3 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Top"]; PropertyDescriptor descriptor4 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Left"]; for (int i = 0; i < this.resizeComponents.Length; i++) { if ((descriptor != null) && (((Control)this.resizeComponents[i].resizeControl).Width != this.resizeComponents[i].resizeBounds.Width)) { descriptor.SetValue(this.resizeComponents[i].resizeControl, ((Control)this.resizeComponents[i].resizeControl).Width); } if ((descriptor2 != null) && (((Control)this.resizeComponents[i].resizeControl).Height != this.resizeComponents[i].resizeBounds.Height)) { descriptor2.SetValue(this.resizeComponents[i].resizeControl, ((Control)this.resizeComponents[i].resizeControl).Height); } if ((descriptor3 != null) && (((Control)this.resizeComponents[i].resizeControl).Top != this.resizeComponents[i].resizeBounds.Y)) { descriptor3.SetValue(this.resizeComponents[i].resizeControl, ((Control)this.resizeComponents[i].resizeControl).Top); } if ((descriptor4 != null) && (((Control)this.resizeComponents[i].resizeControl).Left != this.resizeComponents[i].resizeBounds.X)) { descriptor4.SetValue(this.resizeComponents[i].resizeControl, ((Control)this.resizeComponents[i].resizeControl).Left); } if ((this.resizeComponents[i].resizeControl == this.primaryControl) && (this.statusCommandUI != null)) { this.statusCommandUI.SetStatusInformation(this.primaryControl); } } } } if (this.resizeTransaction != null) { DesignerTransaction resizeTransaction = this.resizeTransaction; this.resizeTransaction = null; using (resizeTransaction) { resizeTransaction.Commit(); } } } finally { this.OnLoseCapture(g, EventArgs.Empty); } return(false); }
private void InitiateResize() { bool useSnapLines = this.BehaviorService.UseSnapLines; ArrayList dragComponents = new ArrayList(); IDesignerHost service = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost; for (int i = 0; i < this.resizeComponents.Length; i++) { this.resizeComponents[i].resizeBounds = ((Control) this.resizeComponents[i].resizeControl).Bounds; if (useSnapLines) { dragComponents.Add(this.resizeComponents[i].resizeControl); } if (service != null) { ControlDesigner designer = service.GetDesigner(this.resizeComponents[i].resizeControl as Component) as ControlDesigner; if (designer != null) { this.resizeComponents[i].resizeRules = designer.SelectionRules; } else { this.resizeComponents[i].resizeRules = SelectionRules.None; } } } this.BehaviorService.EnableAllAdorners(false); IDesignerHost host2 = (IDesignerHost) this.serviceProvider.GetService(typeof(IDesignerHost)); if (host2 != null) { string str; if (this.resizeComponents.Length == 1) { string componentName = TypeDescriptor.GetComponentName(this.resizeComponents[0].resizeControl); if ((componentName == null) || (componentName.Length == 0)) { componentName = this.resizeComponents[0].resizeControl.GetType().Name; } str = System.Design.SR.GetString("BehaviorServiceResizeControl", new object[] { componentName }); } else { str = System.Design.SR.GetString("BehaviorServiceResizeControls", new object[] { this.resizeComponents.Length }); } this.resizeTransaction = host2.CreateTransaction(str); } this.initialResize = true; if (useSnapLines) { this.dragManager = new DragAssistanceManager(this.serviceProvider, dragComponents, true); } else if (this.resizeComponents.Length > 0) { Control resizeControl = this.resizeComponents[0].resizeControl as Control; if ((resizeControl != null) && (resizeControl.Parent != null)) { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(resizeControl.Parent)["SnapToGrid"]; if ((descriptor != null) && ((bool) descriptor.GetValue(resizeControl.Parent))) { PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(resizeControl.Parent)["GridSize"]; if (descriptor2 != null) { this.parentGridSize = (Size) descriptor2.GetValue(resizeControl.Parent); this.parentLocation = this.behaviorService.ControlToAdornerWindow(resizeControl); this.parentLocation.X -= resizeControl.Location.X; this.parentLocation.Y -= resizeControl.Location.Y; } } } } this.captureLost = false; }
public override bool OnMouseUp(Glyph g, MouseButtons button) { try { if (this.dragging) { if (this.dragManager != null) { this.dragManager.OnMouseUp(); this.dragManager = null; this.lastSnapOffset = Point.Empty; this.didSnap = false; } if ((this.resizeComponents != null) && (this.resizeComponents.Length > 0)) { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Width"]; PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Height"]; PropertyDescriptor descriptor3 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Top"]; PropertyDescriptor descriptor4 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Left"]; for (int i = 0; i < this.resizeComponents.Length; i++) { if ((descriptor != null) && (((Control) this.resizeComponents[i].resizeControl).Width != this.resizeComponents[i].resizeBounds.Width)) { descriptor.SetValue(this.resizeComponents[i].resizeControl, ((Control) this.resizeComponents[i].resizeControl).Width); } if ((descriptor2 != null) && (((Control) this.resizeComponents[i].resizeControl).Height != this.resizeComponents[i].resizeBounds.Height)) { descriptor2.SetValue(this.resizeComponents[i].resizeControl, ((Control) this.resizeComponents[i].resizeControl).Height); } if ((descriptor3 != null) && (((Control) this.resizeComponents[i].resizeControl).Top != this.resizeComponents[i].resizeBounds.Y)) { descriptor3.SetValue(this.resizeComponents[i].resizeControl, ((Control) this.resizeComponents[i].resizeControl).Top); } if ((descriptor4 != null) && (((Control) this.resizeComponents[i].resizeControl).Left != this.resizeComponents[i].resizeBounds.X)) { descriptor4.SetValue(this.resizeComponents[i].resizeControl, ((Control) this.resizeComponents[i].resizeControl).Left); } if ((this.resizeComponents[i].resizeControl == this.primaryControl) && (this.statusCommandUI != null)) { this.statusCommandUI.SetStatusInformation(this.primaryControl); } } } } if (this.resizeTransaction != null) { DesignerTransaction resizeTransaction = this.resizeTransaction; this.resizeTransaction = null; using (resizeTransaction) { resizeTransaction.Commit(); } } } finally { this.OnLoseCapture(g, EventArgs.Empty); } return false; }
/// <summary> /// This ends the Behavior by popping itself from the BehaviorStack. Also, all Adorners are re-enabled at the end of a successful drag. /// </summary> public override bool OnMouseUp(Glyph g, MouseButtons button) { try { if (_dragging) { if (_dragManager != null) { _dragManager.OnMouseUp(); _dragManager = null; _lastSnapOffset = Point.Empty; _didSnap = false; } if (_resizeComponents != null && _resizeComponents.Length > 0) { // we do these separately so as not to disturb the cached sizes for values we're not actually changing. For example, if a control is docked top and we modify the height, the width shouldn't be modified. PropertyDescriptor propWidth = TypeDescriptor.GetProperties(_resizeComponents[0].resizeControl)["Width"]; PropertyDescriptor propHeight = TypeDescriptor.GetProperties(_resizeComponents[0].resizeControl)["Height"]; PropertyDescriptor propTop = TypeDescriptor.GetProperties(_resizeComponents[0].resizeControl)["Top"]; PropertyDescriptor propLeft = TypeDescriptor.GetProperties(_resizeComponents[0].resizeControl)["Left"]; for (int i = 0; i < _resizeComponents.Length; i++) { if (propWidth != null && ((Control)_resizeComponents[i].resizeControl).Width != _resizeComponents[i].resizeBounds.Width) { propWidth.SetValue(_resizeComponents[i].resizeControl, ((Control)_resizeComponents[i].resizeControl).Width); } if (propHeight != null && ((Control)_resizeComponents[i].resizeControl).Height != _resizeComponents[i].resizeBounds.Height) { propHeight.SetValue(_resizeComponents[i].resizeControl, ((Control)_resizeComponents[i].resizeControl).Height); } if (propTop != null && ((Control)_resizeComponents[i].resizeControl).Top != _resizeComponents[i].resizeBounds.Y) { propTop.SetValue(_resizeComponents[i].resizeControl, ((Control)_resizeComponents[i].resizeControl).Top); } if (propLeft != null && ((Control)_resizeComponents[i].resizeControl).Left != _resizeComponents[i].resizeBounds.X) { propLeft.SetValue(_resizeComponents[i].resizeControl, ((Control)_resizeComponents[i].resizeControl).Left); } if (_resizeComponents[i].resizeControl == _primaryControl && _statusCommandUI != null) { _statusCommandUI.SetStatusInformation(_primaryControl as Component); } } } } if (_resizeTransaction != null) { DesignerTransaction t = _resizeTransaction; _resizeTransaction = null; using (t) { t.Commit(); } } } finally { // This pops us off the stack, re-enables adorners and clears the "dragging" flag. OnLoseCapture(g, EventArgs.Empty); } return(false); }
/// <summary> /// This is called in response to the mouse moving far enough away from its initial point. Basically, we calculate the bounds for each control we're resizing and disable any adorners. /// </summary> private void InitiateResize() { bool useSnapLines = BehaviorService.UseSnapLines; ArrayList components = new ArrayList(); //check to see if the current designer participate with SnapLines cache the control bounds for (int i = 0; i < _resizeComponents.Length; i++) { _resizeComponents[i].resizeBounds = ((Control)(_resizeComponents[i].resizeControl)).Bounds; if (useSnapLines) { components.Add(_resizeComponents[i].resizeControl); } if (_serviceProvider.GetService(typeof(IDesignerHost)) is IDesignerHost designerHost) { if (designerHost.GetDesigner(_resizeComponents[i].resizeControl as Component) is ControlDesigner designer) { _resizeComponents[i].resizeRules = designer.SelectionRules; } else { Debug.Fail("Initiating resize. Could not get the designer for " + _resizeComponents[i].resizeControl.ToString()); _resizeComponents[i].resizeRules = SelectionRules.None; } } } //disable all glyphs in all adorners BehaviorService.EnableAllAdorners(false); //build up our resize transaction IDesignerHost host = (IDesignerHost)_serviceProvider.GetService(typeof(IDesignerHost)); if (host != null) { string locString; if (_resizeComponents.Length == 1) { string name = TypeDescriptor.GetComponentName(_resizeComponents[0].resizeControl); if (name == null || name.Length == 0) { name = _resizeComponents[0].resizeControl.GetType().Name; } locString = string.Format(SR.BehaviorServiceResizeControl, name); } else { locString = string.Format(SR.BehaviorServiceResizeControls, _resizeComponents.Length); } _resizeTransaction = host.CreateTransaction(locString); } _initialResize = true; if (useSnapLines) { //instantiate our class to manage snap/margin lines... _dragManager = new DragAssistanceManager(_serviceProvider, components, true); } else if (_resizeComponents.Length > 0) { //try to get the parents grid and snap settings if (_resizeComponents[0].resizeControl is Control control && control.Parent != null) { PropertyDescriptor snapProp = TypeDescriptor.GetProperties(control.Parent)["SnapToGrid"]; if (snapProp != null && (bool)snapProp.GetValue(control.Parent)) { PropertyDescriptor gridProp = TypeDescriptor.GetProperties(control.Parent)["GridSize"]; if (gridProp != null) { //cache of the gridsize and the location of the parent on the adornerwindow _parentGridSize = (Size)gridProp.GetValue(control.Parent); _parentLocation = _behaviorService.ControlToAdornerWindow(control); _parentLocation.X -= control.Location.X; _parentLocation.Y -= control.Location.Y; } } } } _captureLost = false; }
protected override void OnMouseDragEnd(bool cancel) { if (this.mouseDragBase == ControlDesigner.InvalidPoint) { base.OnMouseDragEnd(cancel); } else { Rectangle mouseDragOffset = this.mouseDragOffset; ToolboxItem mouseDragTool = this.mouseDragTool; Point mouseDragBase = this.mouseDragBase; this.mouseDragOffset = Rectangle.Empty; this.mouseDragBase = ControlDesigner.InvalidPoint; this.mouseDragTool = null; this.Control.Capture = false; Cursor.Clip = Rectangle.Empty; if (!mouseDragOffset.IsEmpty && (this.graphics != null)) { Rectangle rect = new Rectangle(mouseDragOffset.X - this.adornerWindowToScreenOffset.X, mouseDragOffset.Y - this.adornerWindowToScreenOffset.Y, mouseDragOffset.Width, mouseDragOffset.Height); int num = FrameWidth(this.mouseDragFrame); this.graphics.SetClip(rect); using (Region region = new Region(rect)) { region.Exclude(Rectangle.Inflate(rect, -num, -num)); base.BehaviorService.Invalidate(region); } this.graphics.ResetClip(); } if (this.graphics != null) { this.graphics.Dispose(); this.graphics = null; } if (this.dragManager != null) { this.dragManager.OnMouseUp(); this.dragManager = null; } IEventHandlerService service = (IEventHandlerService) this.GetService(typeof(IEventHandlerService)); if ((service != null) && (this.escapeHandler != null)) { service.PopHandler(this.escapeHandler); this.escapeHandler = null; } if ((this.statusCommandUI != null) && !mouseDragOffset.IsEmpty) { System.Design.NativeMethods.POINT pt = new System.Design.NativeMethods.POINT(mouseDragBase.X, mouseDragBase.Y); System.Design.NativeMethods.MapWindowPoints(IntPtr.Zero, this.Control.Handle, pt, 1); if (this.statusCommandUI != null) { this.statusCommandUI.SetStatusInformation(new Rectangle(pt.x, pt.y, mouseDragOffset.Width, mouseDragOffset.Height)); } } if (mouseDragOffset.IsEmpty && !cancel) { if (mouseDragTool != null) { try { this.CreateTool(mouseDragTool, mouseDragBase); if (this.toolboxService != null) { this.toolboxService.SelectedToolboxItemUsed(); } } catch (Exception exception) { if (System.Windows.Forms.ClientUtils.IsCriticalException(exception)) { throw; } base.DisplayError(exception); } } } else if (!cancel) { if (mouseDragTool != null) { try { Size size = new Size(DesignerUtils.MinDragSize.Width * 2, DesignerUtils.MinDragSize.Height * 2); if (mouseDragOffset.Width < size.Width) { mouseDragOffset.Width = size.Width; } if (mouseDragOffset.Height < size.Height) { mouseDragOffset.Height = size.Height; } this.CreateTool(mouseDragTool, mouseDragOffset); if (this.toolboxService != null) { this.toolboxService.SelectedToolboxItemUsed(); } return; } catch (Exception exception2) { if (System.Windows.Forms.ClientUtils.IsCriticalException(exception2)) { throw; } base.DisplayError(exception2); return; } } ISelectionService service2 = null; service2 = (ISelectionService) this.GetService(typeof(ISelectionService)); if (service2 != null) { object[] components = this.GetComponentsInRect(mouseDragOffset, true, false); if (components.Length > 0) { service2.SetSelectedComponents(components); } } } } }
protected override void OnMouseDragMove(int x, int y) { if ((this.toolboxItemSnapLineBehavior != null) && this.toolboxItemSnapLineBehavior.IsPushed) { base.BehaviorService.PopBehavior(this.toolboxItemSnapLineBehavior); this.toolboxItemSnapLineBehavior.IsPushed = false; } if (!this.GetOleDragHandler().Dragging && (this.mouseDragBase != ControlDesigner.InvalidPoint)) { Rectangle mouseDragOffset = this.mouseDragOffset; this.mouseDragOffset.X = this.mouseDragBase.X; this.mouseDragOffset.Y = this.mouseDragBase.Y; this.mouseDragOffset.Width = x - this.mouseDragBase.X; this.mouseDragOffset.Height = y - this.mouseDragBase.Y; if (((this.dragManager == null) && this.ParticipatesWithSnapLines) && ((this.mouseDragTool != null) && base.BehaviorService.UseSnapLines)) { this.dragManager = new DragAssistanceManager(base.Component.Site); } if (this.dragManager != null) { Rectangle dragBounds = new Rectangle(this.mouseDragBase.X - this.adornerWindowToScreenOffset.X, this.mouseDragBase.Y - this.adornerWindowToScreenOffset.Y, x - this.mouseDragBase.X, y - this.mouseDragBase.Y); Point point = this.dragManager.OnMouseMove(dragBounds, this.GenerateNewToolSnapLines(dragBounds)); this.mouseDragOffset.Width += point.X; this.mouseDragOffset.Height += point.Y; this.dragManager.RenderSnapLinesInternal(); } if (this.mouseDragOffset.Width < 0) { this.mouseDragOffset.X += this.mouseDragOffset.Width; this.mouseDragOffset.Width = -this.mouseDragOffset.Width; } if (this.mouseDragOffset.Height < 0) { this.mouseDragOffset.Y += this.mouseDragOffset.Height; this.mouseDragOffset.Height = -this.mouseDragOffset.Height; } if (this.mouseDragTool != null) { this.mouseDragOffset = this.Control.RectangleToClient(this.mouseDragOffset); this.mouseDragOffset = this.GetUpdatedRect(Rectangle.Empty, this.mouseDragOffset, true); this.mouseDragOffset = this.Control.RectangleToScreen(this.mouseDragOffset); } if (this.graphics == null) { this.graphics = base.BehaviorService.AdornerWindowGraphics; } if (!this.mouseDragOffset.IsEmpty && (this.graphics != null)) { Rectangle rect = new Rectangle(this.mouseDragOffset.X - this.adornerWindowToScreenOffset.X, this.mouseDragOffset.Y - this.adornerWindowToScreenOffset.Y, this.mouseDragOffset.Width, this.mouseDragOffset.Height); using (Region region = new Region(rect)) { int num = FrameWidth(this.mouseDragFrame); region.Exclude(Rectangle.Inflate(rect, -num, -num)); if (!mouseDragOffset.IsEmpty) { mouseDragOffset.X -= this.adornerWindowToScreenOffset.X; mouseDragOffset.Y -= this.adornerWindowToScreenOffset.Y; using (Region region2 = new Region(mouseDragOffset)) { region2.Exclude(Rectangle.Inflate(mouseDragOffset, -num, -num)); base.BehaviorService.Invalidate(region2); } } DesignerUtils.DrawFrame(this.graphics, region, this.mouseDragFrame, this.Control.BackColor); } } if (this.statusCommandUI != null) { System.Design.NativeMethods.POINT pt = new System.Design.NativeMethods.POINT(this.mouseDragOffset.X, this.mouseDragOffset.Y); System.Design.NativeMethods.MapWindowPoints(IntPtr.Zero, this.Control.Handle, pt, 1); if (this.statusCommandUI != null) { this.statusCommandUI.SetStatusInformation(new Rectangle(pt.x, pt.y, this.mouseDragOffset.Width, this.mouseDragOffset.Height)); } } } }
internal void GiveFeedback(object sender, GiveFeedbackEventArgs e) { this.lastEffect = e.Effect; if ((this.data.Target == null) || (e.Effect == DragDropEffects.None)) { if (this.clearDragImageRect != this.dragImageRect) { this.ClearAllDragImages(); this.clearDragImageRect = this.dragImageRect; } if (this.dragAssistanceManager != null) { this.dragAssistanceManager.EraseSnapLines(); } } else { bool flag = false; Point mousePosition = Control.MousePosition; bool flag2 = Control.ModifierKeys == Keys.Alt; if (flag2 && (this.dragAssistanceManager != null)) { this.dragAssistanceManager.EraseSnapLines(); } if (this.data.Target.Equals(this.data.Source) && (this.lastEffect != DragDropEffects.Copy)) { e.UseDefaultCursors = false; Cursor.Current = Cursors.Default; } else { e.UseDefaultCursors = true; } Control target = this.data.Target as Control; if ((mousePosition != this.lastFeedbackLocation) || (flag2 && (this.dragAssistanceManager != null))) { if (!this.data.Target.Equals(this.lastDropTarget)) { this.serviceProviderTarget = target.Site; if (this.serviceProviderTarget == null) { return; } IDesignerHost service = (IDesignerHost) this.serviceProviderTarget.GetService(typeof(IDesignerHost)); if (service == null) { return; } this.targetAllowsSnapLines = true; ControlDesigner designer = service.GetDesigner(target) as ControlDesigner; if ((designer != null) && !designer.ParticipatesWithSnapLines) { this.targetAllowsSnapLines = false; } this.statusCommandUITarget = new StatusCommandUI(this.serviceProviderTarget); if ((this.lastDropTarget == null) || (service != this.destHost)) { if ((this.destHost != null) && (this.destHost != this.srcHost)) { this.behaviorServiceTarget.EnableAllAdorners(true); } this.behaviorServiceTarget = (BehaviorService) this.serviceProviderTarget.GetService(typeof(BehaviorService)); if (this.behaviorServiceTarget == null) { return; } this.GetParentSnapInfo(target, this.behaviorServiceTarget); if (service != this.srcHost) { this.DisableAdorners(this.serviceProviderTarget, this.behaviorServiceTarget, true); } this.ClearAllDragImages(); if (this.lastDropTarget != null) { for (int i = 0; i < this.dragObjects.Count; i++) { Control c = (Control) this.dragObjects[i]; Rectangle rect = this.behaviorServiceSource.ControlRectInAdornerWindow(c); rect.Location = this.behaviorServiceSource.AdornerWindowPointToScreen(rect.Location); rect.Location = this.behaviorServiceTarget.MapAdornerWindowPoint(IntPtr.Zero, rect.Location); if (i == 0) { if (this.dragImageRegion != null) { this.dragImageRegion.Dispose(); } this.dragImageRegion = new Region(rect); } else { this.dragImageRegion.Union(rect); } } } if (this.graphicsTarget != null) { this.graphicsTarget.Dispose(); } this.graphicsTarget = this.behaviorServiceTarget.AdornerWindowGraphics; flag = true; this.destHost = service; } this.lastDropTarget = this.data.Target; } if (this.ShowHideDragControls(this.lastEffect == DragDropEffects.Copy) && !flag) { flag = true; } if (flag && this.behaviorServiceTarget.UseSnapLines) { if (this.dragAssistanceManager != null) { this.dragAssistanceManager.EraseSnapLines(); } this.dragAssistanceManager = new DragAssistanceManager(this.serviceProviderTarget, this.graphicsTarget, this.dragObjects, null, this.lastEffect == DragDropEffects.Copy); } Point pt = new Point((mousePosition.X - this.initialMouseLoc.X) + this.dragComponents[this.primaryComponentIndex].originalControlLocation.X, (mousePosition.Y - this.initialMouseLoc.Y) + this.dragComponents[this.primaryComponentIndex].originalControlLocation.Y); pt = this.MapPointFromSourceToTarget(pt); Rectangle dragBounds = new Rectangle(pt.X, pt.Y, this.dragComponents[this.primaryComponentIndex].dragImage.Width, this.dragComponents[this.primaryComponentIndex].dragImage.Height); if (this.dragAssistanceManager != null) { if (this.targetAllowsSnapLines && !flag2) { this.lastSnapOffset = this.dragAssistanceManager.OnMouseMove(dragBounds); } else { this.dragAssistanceManager.OnMouseMove(new Rectangle(-100, -100, 0, 0)); } } else if (!this.parentGridSize.IsEmpty) { this.lastSnapOffset = this.AdjustToGrid(pt); } pt.X += this.lastSnapOffset.X; pt.Y += this.lastSnapOffset.Y; this.dragComponents[this.primaryComponentIndex].draggedLocation = this.MapPointFromTargetToSource(pt); Rectangle dragImageRect = this.dragImageRect; pt = new Point((mousePosition.X - this.initialMouseLoc.X) + this.originalDragImageLocation.X, (mousePosition.Y - this.initialMouseLoc.Y) + this.originalDragImageLocation.Y) { X = pt.X + this.lastSnapOffset.X, Y = pt.Y + this.lastSnapOffset.Y }; this.dragImageRect.Location = pt; dragImageRect.Location = this.MapPointFromSourceToTarget(dragImageRect.Location); Rectangle a = this.dragImageRect; a.Location = this.MapPointFromSourceToTarget(a.Location); Region region = new Region(Rectangle.Union(a, dragImageRect)); region.Exclude(a); using (Region region2 = this.dragImageRegion.Clone()) { region2.Translate((int) ((mousePosition.X - this.initialMouseLoc.X) + this.lastSnapOffset.X), (int) ((mousePosition.Y - this.initialMouseLoc.Y) + this.lastSnapOffset.Y)); region2.Complement(a); region2.Union(region); this.behaviorServiceTarget.Invalidate(region2); } region.Dispose(); if (this.graphicsTarget != null) { this.graphicsTarget.SetClip(a); this.graphicsTarget.DrawImage(this.dragImage, a.X, a.Y); this.graphicsTarget.ResetClip(); } Control dragComponent = this.dragComponents[this.primaryComponentIndex].dragComponent as Control; if (dragComponent != null) { Point p = this.behaviorServiceSource.AdornerWindowPointToScreen(this.dragComponents[this.primaryComponentIndex].draggedLocation); p = target.PointToClient(p); if (target.IsMirrored && dragComponent.IsMirrored) { p.Offset(-dragComponent.Width, 0); } if (this.statusCommandUITarget != null) { this.statusCommandUITarget.SetStatusInformation(dragComponent, p); } } if (((this.dragAssistanceManager != null) && !flag2) && this.targetAllowsSnapLines) { this.dragAssistanceManager.RenderSnapLinesInternal(); } this.lastFeedbackLocation = mousePosition; } this.data.Target = null; } }
internal void GiveFeedback(object sender, GiveFeedbackEventArgs e) { this.lastEffect = e.Effect; if ((this.data.Target == null) || (e.Effect == DragDropEffects.None)) { if (this.clearDragImageRect != this.dragImageRect) { this.ClearAllDragImages(); this.clearDragImageRect = this.dragImageRect; } if (this.dragAssistanceManager != null) { this.dragAssistanceManager.EraseSnapLines(); } } else { bool flag = false; Point mousePosition = Control.MousePosition; bool flag2 = Control.ModifierKeys == Keys.Alt; if (flag2 && (this.dragAssistanceManager != null)) { this.dragAssistanceManager.EraseSnapLines(); } if (this.data.Target.Equals(this.data.Source) && (this.lastEffect != DragDropEffects.Copy)) { e.UseDefaultCursors = false; Cursor.Current = Cursors.Default; } else { e.UseDefaultCursors = true; } Control target = this.data.Target as Control; if ((mousePosition != this.lastFeedbackLocation) || (flag2 && (this.dragAssistanceManager != null))) { if (!this.data.Target.Equals(this.lastDropTarget)) { this.serviceProviderTarget = target.Site; if (this.serviceProviderTarget == null) { return; } IDesignerHost service = (IDesignerHost)this.serviceProviderTarget.GetService(typeof(IDesignerHost)); if (service == null) { return; } this.targetAllowsSnapLines = true; ControlDesigner designer = service.GetDesigner(target) as ControlDesigner; if ((designer != null) && !designer.ParticipatesWithSnapLines) { this.targetAllowsSnapLines = false; } this.statusCommandUITarget = new StatusCommandUI(this.serviceProviderTarget); if ((this.lastDropTarget == null) || (service != this.destHost)) { if ((this.destHost != null) && (this.destHost != this.srcHost)) { this.behaviorServiceTarget.EnableAllAdorners(true); } this.behaviorServiceTarget = (BehaviorService)this.serviceProviderTarget.GetService(typeof(BehaviorService)); if (this.behaviorServiceTarget == null) { return; } this.GetParentSnapInfo(target, this.behaviorServiceTarget); if (service != this.srcHost) { this.DisableAdorners(this.serviceProviderTarget, this.behaviorServiceTarget, true); } this.ClearAllDragImages(); if (this.lastDropTarget != null) { for (int i = 0; i < this.dragObjects.Count; i++) { Control c = (Control)this.dragObjects[i]; Rectangle rect = this.behaviorServiceSource.ControlRectInAdornerWindow(c); rect.Location = this.behaviorServiceSource.AdornerWindowPointToScreen(rect.Location); rect.Location = this.behaviorServiceTarget.MapAdornerWindowPoint(IntPtr.Zero, rect.Location); if (i == 0) { if (this.dragImageRegion != null) { this.dragImageRegion.Dispose(); } this.dragImageRegion = new Region(rect); } else { this.dragImageRegion.Union(rect); } } } if (this.graphicsTarget != null) { this.graphicsTarget.Dispose(); } this.graphicsTarget = this.behaviorServiceTarget.AdornerWindowGraphics; flag = true; this.destHost = service; } this.lastDropTarget = this.data.Target; } if (this.ShowHideDragControls(this.lastEffect == DragDropEffects.Copy) && !flag) { flag = true; } if (flag && this.behaviorServiceTarget.UseSnapLines) { if (this.dragAssistanceManager != null) { this.dragAssistanceManager.EraseSnapLines(); } this.dragAssistanceManager = new DragAssistanceManager(this.serviceProviderTarget, this.graphicsTarget, this.dragObjects, null, this.lastEffect == DragDropEffects.Copy); } Point pt = new Point((mousePosition.X - this.initialMouseLoc.X) + this.dragComponents[this.primaryComponentIndex].originalControlLocation.X, (mousePosition.Y - this.initialMouseLoc.Y) + this.dragComponents[this.primaryComponentIndex].originalControlLocation.Y); pt = this.MapPointFromSourceToTarget(pt); Rectangle dragBounds = new Rectangle(pt.X, pt.Y, this.dragComponents[this.primaryComponentIndex].dragImage.Width, this.dragComponents[this.primaryComponentIndex].dragImage.Height); if (this.dragAssistanceManager != null) { if (this.targetAllowsSnapLines && !flag2) { this.lastSnapOffset = this.dragAssistanceManager.OnMouseMove(dragBounds); } else { this.dragAssistanceManager.OnMouseMove(new Rectangle(-100, -100, 0, 0)); } } else if (!this.parentGridSize.IsEmpty) { this.lastSnapOffset = this.AdjustToGrid(pt); } pt.X += this.lastSnapOffset.X; pt.Y += this.lastSnapOffset.Y; this.dragComponents[this.primaryComponentIndex].draggedLocation = this.MapPointFromTargetToSource(pt); Rectangle dragImageRect = this.dragImageRect; pt = new Point((mousePosition.X - this.initialMouseLoc.X) + this.originalDragImageLocation.X, (mousePosition.Y - this.initialMouseLoc.Y) + this.originalDragImageLocation.Y) { X = pt.X + this.lastSnapOffset.X, Y = pt.Y + this.lastSnapOffset.Y }; this.dragImageRect.Location = pt; dragImageRect.Location = this.MapPointFromSourceToTarget(dragImageRect.Location); Rectangle a = this.dragImageRect; a.Location = this.MapPointFromSourceToTarget(a.Location); Region region = new Region(Rectangle.Union(a, dragImageRect)); region.Exclude(a); using (Region region2 = this.dragImageRegion.Clone()) { region2.Translate((int)((mousePosition.X - this.initialMouseLoc.X) + this.lastSnapOffset.X), (int)((mousePosition.Y - this.initialMouseLoc.Y) + this.lastSnapOffset.Y)); region2.Complement(a); region2.Union(region); this.behaviorServiceTarget.Invalidate(region2); } region.Dispose(); if (this.graphicsTarget != null) { this.graphicsTarget.SetClip(a); this.graphicsTarget.DrawImage(this.dragImage, a.X, a.Y); this.graphicsTarget.ResetClip(); } Control dragComponent = this.dragComponents[this.primaryComponentIndex].dragComponent as Control; if (dragComponent != null) { Point p = this.behaviorServiceSource.AdornerWindowPointToScreen(this.dragComponents[this.primaryComponentIndex].draggedLocation); p = target.PointToClient(p); if (target.IsMirrored && dragComponent.IsMirrored) { p.Offset(-dragComponent.Width, 0); } if (this.statusCommandUITarget != null) { this.statusCommandUITarget.SetStatusInformation(dragComponent, p); } } if (((this.dragAssistanceManager != null) && !flag2) && this.targetAllowsSnapLines) { this.dragAssistanceManager.RenderSnapLinesInternal(); } this.lastFeedbackLocation = mousePosition; } this.data.Target = null; } }
private void InitiateResize() { bool useSnapLines = this.BehaviorService.UseSnapLines; ArrayList dragComponents = new ArrayList(); IDesignerHost service = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost; for (int i = 0; i < this.resizeComponents.Length; i++) { this.resizeComponents[i].resizeBounds = ((Control)this.resizeComponents[i].resizeControl).Bounds; if (useSnapLines) { dragComponents.Add(this.resizeComponents[i].resizeControl); } if (service != null) { ControlDesigner designer = service.GetDesigner(this.resizeComponents[i].resizeControl as Component) as ControlDesigner; if (designer != null) { this.resizeComponents[i].resizeRules = designer.SelectionRules; } else { this.resizeComponents[i].resizeRules = SelectionRules.None; } } } this.BehaviorService.EnableAllAdorners(false); IDesignerHost host2 = (IDesignerHost)this.serviceProvider.GetService(typeof(IDesignerHost)); if (host2 != null) { string str; if (this.resizeComponents.Length == 1) { string componentName = TypeDescriptor.GetComponentName(this.resizeComponents[0].resizeControl); if ((componentName == null) || (componentName.Length == 0)) { componentName = this.resizeComponents[0].resizeControl.GetType().Name; } str = System.Design.SR.GetString("BehaviorServiceResizeControl", new object[] { componentName }); } else { str = System.Design.SR.GetString("BehaviorServiceResizeControls", new object[] { this.resizeComponents.Length }); } this.resizeTransaction = host2.CreateTransaction(str); } this.initialResize = true; if (useSnapLines) { this.dragManager = new DragAssistanceManager(this.serviceProvider, dragComponents, true); } else if (this.resizeComponents.Length > 0) { Control resizeControl = this.resizeComponents[0].resizeControl as Control; if ((resizeControl != null) && (resizeControl.Parent != null)) { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(resizeControl.Parent)["SnapToGrid"]; if ((descriptor != null) && ((bool)descriptor.GetValue(resizeControl.Parent))) { PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(resizeControl.Parent)["GridSize"]; if (descriptor2 != null) { this.parentGridSize = (Size)descriptor2.GetValue(resizeControl.Parent); this.parentLocation = this.behaviorService.ControlToAdornerWindow(resizeControl); this.parentLocation.X -= resizeControl.Location.X; this.parentLocation.Y -= resizeControl.Location.Y; } } } } this.captureLost = false; }
public static DragAssistanceManager.Line Overlap(DragAssistanceManager.Line l1, DragAssistanceManager.Line l2) { if (l1.LineType == l2.LineType) { if ((l1.LineType != System.Windows.Forms.Design.Behavior.DragAssistanceManager.LineType.Standard) && (l1.LineType != System.Windows.Forms.Design.Behavior.DragAssistanceManager.LineType.Baseline)) { return null; } if (((l1.x1 == l1.x2) && (l2.x1 == l2.x2)) && (l1.x1 == l2.x1)) { return new DragAssistanceManager.Line(l1.x1, Math.Min(l1.y1, l2.y1), l1.x2, Math.Max(l1.y2, l2.y2), l1.LineType); } if (((l1.y1 == l1.y2) && (l2.y1 == l2.y2)) && (l1.y1 == l2.y2)) { return new DragAssistanceManager.Line(Math.Min(l1.x1, l2.x1), l1.y1, Math.Max(l1.x2, l2.x2), l1.y2, l1.LineType); } } return null; }
public static DragAssistanceManager.Line[] GetDiffs(DragAssistanceManager.Line l1, DragAssistanceManager.Line l2) { if ((l1.x1 == l1.x2) && (l1.x1 == l2.x1)) { return new DragAssistanceManager.Line[] { new DragAssistanceManager.Line(l1.x1, Math.Min(l1.y1, l2.y1), l1.x1, Math.Max(l1.y1, l2.y1)), new DragAssistanceManager.Line(l1.x1, Math.Min(l1.y2, l2.y2), l1.x1, Math.Max(l1.y2, l2.y2)) }; } if ((l1.y1 == l1.y2) && (l1.y1 == l2.y1)) { return new DragAssistanceManager.Line[] { new DragAssistanceManager.Line(Math.Min(l1.x1, l2.x1), l1.y1, Math.Max(l1.x1, l2.x1), l1.y1), new DragAssistanceManager.Line(Math.Min(l1.x2, l2.x2), l1.y1, Math.Max(l1.x2, l2.x2), l1.y1) }; } return null; }
protected virtual void OnKeyMove(object sender, EventArgs e) { ISelectionService selectionService = this.SelectionService; if (selectionService != null) { IComponent primarySelection = selectionService.PrimarySelection as IComponent; if (primarySelection != null) { IDesignerHost service = (IDesignerHost) this.GetService(typeof(IDesignerHost)); if (service != null) { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(primarySelection)["Locked"]; if (((descriptor == null) || (descriptor.PropertyType != typeof(bool))) || !((bool) descriptor.GetValue(primarySelection))) { DesignerTransaction transaction; CommandID commandID = ((MenuCommand) sender).CommandID; bool flag = false; int x = 0; int y = 0; if (commandID.Equals(MenuCommands.KeyMoveUp)) { y = -1; } else if (commandID.Equals(MenuCommands.KeyMoveDown)) { y = 1; } else if (commandID.Equals(MenuCommands.KeyMoveLeft)) { x = -1; } else if (commandID.Equals(MenuCommands.KeyMoveRight)) { x = 1; } else if (commandID.Equals(MenuCommands.KeyNudgeUp)) { y = -1; flag = true; } else if (commandID.Equals(MenuCommands.KeyNudgeDown)) { y = 1; flag = true; } else if (commandID.Equals(MenuCommands.KeyNudgeLeft)) { x = -1; flag = true; } else if (commandID.Equals(MenuCommands.KeyNudgeRight)) { x = 1; flag = true; } if (selectionService.SelectionCount > 1) { transaction = service.CreateTransaction(System.Design.SR.GetString("DragDropMoveComponents", new object[] { selectionService.SelectionCount })); } else { transaction = service.CreateTransaction(System.Design.SR.GetString("DragDropMoveComponent", new object[] { primarySelection.Site.Name })); } try { if (this.BehaviorService != null) { Control targetControl = primarySelection as Control; bool useSnapLines = this.BehaviorService.UseSnapLines; if (this.dragManager != null) { this.EndDragManager(); } if ((flag && useSnapLines) && (targetControl != null)) { ArrayList dragComponents = new ArrayList(selectionService.GetSelectedComponents()); this.dragManager = new DragAssistanceManager(primarySelection.Site, dragComponents); Point point = this.dragManager.OffsetToNearestSnapLocation(targetControl, new Point(x, y)); x = point.X; y = point.Y; if (targetControl.Parent.IsMirrored) { x *= -1; } } else if (!flag && !useSnapLines) { bool flag3 = false; Size empty = Size.Empty; IComponent snapComponent = null; PropertyDescriptor snapProperty = null; this.GetSnapInformation(service, primarySelection, out empty, out snapComponent, out snapProperty); if (snapProperty != null) { flag3 = (bool) snapProperty.GetValue(snapComponent); } if (flag3 && !empty.IsEmpty) { x *= empty.Width; y *= empty.Height; if (targetControl != null) { ParentControlDesigner designer = service.GetDesigner(targetControl.Parent) as ParentControlDesigner; if (designer != null) { Point location = targetControl.Location; if (targetControl.Parent.IsMirrored) { x *= -1; } location.Offset(x, y); location = designer.GetSnappedPoint(location); if (x != 0) { x = location.X - targetControl.Location.X; } if (y != 0) { y = location.Y - targetControl.Location.Y; } } } } else if ((targetControl != null) && targetControl.Parent.IsMirrored) { x *= -1; } } else if ((targetControl != null) && targetControl.Parent.IsMirrored) { x *= -1; } SelectionRules rules = SelectionRules.Visible | SelectionRules.Moveable; foreach (IComponent component3 in selectionService.GetSelectedComponents()) { ControlDesigner designer2 = service.GetDesigner(component3) as ControlDesigner; if ((designer2 == null) || ((designer2.SelectionRules & rules) == rules)) { PropertyDescriptor descriptor3 = TypeDescriptor.GetProperties(component3)["Location"]; if (descriptor3 != null) { Point point3 = (Point) descriptor3.GetValue(component3); point3.Offset(x, y); descriptor3.SetValue(component3, point3); } if ((component3 == selectionService.PrimarySelection) && (this.statusCommandUI != null)) { this.statusCommandUI.SetStatusInformation(component3 as Component); } } } } } finally { if (transaction != null) { transaction.Commit(); } if (this.dragManager != null) { this.SnapLineTimer.Start(); this.dragManager.RenderSnapLinesInternal(); } } } } } } }
protected void EndDragManager() { if (this.dragManager != null) { if (this.snapLineTimer != null) { this.snapLineTimer.Stop(); } this.dragManager.EraseSnapLines(); this.dragManager.OnMouseUp(); this.dragManager = null; } }