/// <summary> /// Constructor that caches all values for perf. reasons. /// </summary> internal ResizeBehavior(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; _dragging = false; _pushedBehavior = false; _lastSnapOffset = Point.Empty; _didSnap = false; _statusCommandUI = new StatusCommandUI(serviceProvider); }
internal ResizeBehavior(IServiceProvider serviceProvider) { this.serviceProvider = serviceProvider; this.dragging = false; this.pushedBehavior = false; this.lastSnapOffset = Point.Empty; this.didSnap = false; this.statusCommandUI = new StatusCommandUI(serviceProvider); }
public ToolboxItemSnapLineBehavior(IServiceProvider serviceProvider, BehaviorService behaviorService) { this.serviceProvider = serviceProvider; this.behaviorService = behaviorService; this.designer = null; this.isPushed = false; this.lastRectangle = Rectangle.Empty; this.lastOffset = Point.Empty; this.statusCommandUI = new StatusCommandUI(serviceProvider); this.targetAllowsDragBox = true; this.targetAllowsSnapLines = true; }
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; } }