Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Common / AuthoringOM / Design / MessageFilters / FreeFormDragDropManager.cs / 1305376 / FreeFormDragDropManager.cs
namespace System.Workflow.ComponentModel.Design { using System; using System.Text; using System.Drawing; using System.Diagnostics; using System.Collections; using System.Windows.Forms; using System.ComponentModel; using System.Drawing.Drawing2D; using System.Collections.Generic; using System.ComponentModel.Design; #region Class FreeFormDragDropManager internal sealed class FreeFormDragDropManager : DragDropManager { #region Members and Constructor private static Cursor DragMoveCursor = new Cursor(typeof(WorkflowView), "Resources.DragMoveCursor.cur"); private static Cursor DragCopyCursor = new Cursor(typeof(WorkflowView), "Resources.DragCopyCursor.cur"); private static Cursor MoveCursor = new Cursor(typeof(WorkflowView), "Resources.MoveCursor.cur"); private ListdraggedDesignerImages = null; private Cursor previousCursor = Cursors.Default; private Point movedDesignerImagePoint = Point.Empty; public FreeFormDragDropManager() { } #endregion #region Behavior Overrides protected override bool OnDragEnter(DragEventArgs eventArgs) { bool retVal = base.OnDragEnter(eventArgs); if (this.draggedDesignerImages == null) { WorkflowView parentView = ParentView; Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)); Point logicalPoint = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y)); if (parentView.IsClientPointInActiveLayout(clientPoint)) this.movedDesignerImagePoint = logicalPoint; else this.movedDesignerImagePoint = DragInitiationPoint; } return retVal; } protected override bool OnDragOver(DragEventArgs eventArgs) { //Invalidate the dragged images if (this.draggedDesignerImages != null) { Point[] previousLocations = GetDesignerLocations(DragInitiationPoint, this.movedDesignerImagePoint, DraggedActivities); InvalidateDraggedImages(previousLocations); } bool retVal = base.OnDragOver(eventArgs); if (this.draggedDesignerImages != null) { WorkflowView parentView = ParentView; Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)); Point logicalPoint = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y)); if (parentView.IsClientPointInActiveLayout(clientPoint)) this.movedDesignerImagePoint = logicalPoint; else this.movedDesignerImagePoint = DragInitiationPoint; //Invalidate the new locations where the image is shown Point[] newLocations = GetDesignerLocations(DragInitiationPoint, this.movedDesignerImagePoint, DraggedActivities); InvalidateDraggedImages(newLocations); } return retVal; } protected override bool OnGiveFeedback(GiveFeedbackEventArgs gfbevent) { base.OnGiveFeedback(gfbevent); if (this.draggedDesignerImages != null) { gfbevent.UseDefaultCursors = false; if ((gfbevent.Effect & DragDropEffects.Move) == DragDropEffects.Move) Cursor.Current = FreeFormDragDropManager.DragMoveCursor; else if ((gfbevent.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) Cursor.Current = FreeFormDragDropManager.DragCopyCursor; else Cursor.Current = Cursors.No; return true; } return false; } protected override bool OnMouseMove(MouseEventArgs eventArgs) { bool retval = base.OnMouseMove(eventArgs); if (eventArgs.Button == MouseButtons.None) { bool showMoveCursor = false; showMoveCursor |= (MessageHitTestContext != null && MessageHitTestContext.AssociatedDesigner != null && ActivityDesigner.GetParentDesigner(MessageHitTestContext.AssociatedDesigner.Activity) is FreeformActivityDesigner && (MessageHitTestContext.HitLocation & HitTestLocations.ActionArea) == 0); UpdateCursor(showMoveCursor); } return retval; } protected override bool OnMouseLeave() { UpdateCursor(false); return false; } protected override bool OnScroll(ScrollBar sender, int value) { if (this.draggedDesignerImages != null) { Point[] previousLocations = GetDesignerLocations(DragInitiationPoint, this.movedDesignerImagePoint, DraggedActivities); InvalidateDraggedImages(previousLocations); } bool retVal = base.OnScroll(sender, value); if (this.draggedDesignerImages != null) { WorkflowView parentView = ParentView; Point clientPoint = parentView.PointToClient(Control.MousePosition); Point logicalPoint = parentView.ScreenPointToLogical(Control.MousePosition); if (parentView.IsClientPointInActiveLayout(clientPoint)) this.movedDesignerImagePoint = logicalPoint; else this.movedDesignerImagePoint = DragInitiationPoint; //Invalidate the new locations where the image is shown Point[] newLocations = GetDesignerLocations(DragInitiationPoint, this.movedDesignerImagePoint, DraggedActivities); InvalidateDraggedImages(newLocations); } return retVal; } protected override bool OnPaintWorkflowAdornments(PaintEventArgs eventArgs, Rectangle viewPort, AmbientTheme ambientTheme) { bool messageHandled = false; if (this.draggedDesignerImages == null || this.draggedDesignerImages.Count == 0 || !(DropTargetDesigner is FreeformActivityDesigner)) messageHandled = base.OnPaintWorkflowAdornments(eventArgs, viewPort, ambientTheme); return messageHandled; } protected override bool OnPaint(PaintEventArgs eventArgs, Rectangle viewPort, AmbientTheme ambientTheme) { bool messageHandled = false; if (this.draggedDesignerImages != null && DropTargetDesigner is FreeformActivityDesigner) { using (Region clipRegion = new Region(ActivityDesignerPaint.GetDesignerPath(ParentView.RootDesigner, false))) { Region oldRegion = eventArgs.Graphics.Clip; eventArgs.Graphics.Clip = clipRegion; Point[] locations = GetDesignerLocations(DragInitiationPoint, this.movedDesignerImagePoint, DraggedActivities); Debug.Assert(locations.Length == DraggedActivities.Count); Debug.Assert(this.draggedDesignerImages.Count == DraggedActivities.Count); for (int i = 0; i < this.draggedDesignerImages.Count; i++) { Size imageSize = this.draggedDesignerImages[i].Size; ActivityDesignerPaint.DrawImage(eventArgs.Graphics, this.draggedDesignerImages[i], new Rectangle(new Point(locations[i].X - 2 * ambientTheme.Margin.Width, locations[i].Y - 2 * ambientTheme.Margin.Height), imageSize), new Rectangle(Point.Empty, imageSize), DesignerContentAlignment.Fill, 0.4f, false); } eventArgs.Graphics.Clip = oldRegion; } } else { messageHandled = base.OnPaint(eventArgs, viewPort, ambientTheme); } return messageHandled; } protected override void CreateDragFeedbackImages(IList draggedActivities) { base.CreateDragFeedbackImages(draggedActivities); List imageList = new List (); using (Graphics graphics = ParentView.CreateGraphics()) { foreach (Activity activity in draggedActivities) { ActivityDesigner previewDesigner = ActivityDesigner.GetDesigner(activity); if (previewDesigner == null) previewDesigner = ActivityDesigner.CreateDesigner(ParentView, activity); imageList.Add(previewDesigner.GetPreviewImage(graphics)); } } //We create the designer images for designers associates with existing activities ParentView.InvalidateClientRectangle(Rectangle.Empty); this.draggedDesignerImages = imageList; } protected override void DestroyDragFeedbackImages() { base.DestroyDragFeedbackImages(); if (this.draggedDesignerImages != null) { foreach (Bitmap image in this.draggedDesignerImages) image.Dispose(); this.draggedDesignerImages = null; ParentView.InvalidateClientRectangle(Rectangle.Empty); } } #endregion #region Helpers private void InvalidateDraggedImages(Point[] locations) { if (this.draggedDesignerImages != null) { if (locations.Length == this.draggedDesignerImages.Count) { AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme; WorkflowView parentView = ParentView; //Invalidate the previous location where image was shown for (int i = 0; i < this.draggedDesignerImages.Count; i++) { Rectangle rectangle = new Rectangle(locations[i], this.draggedDesignerImages[i].Size); rectangle.Inflate(2 * ambientTheme.Margin.Width, 2 * ambientTheme.Margin.Height); parentView.InvalidateLogicalRectangle(rectangle); } } else { Debug.Assert(false); } } } internal static Point[] GetDesignerLocations(Point startPoint, Point endPoint, ICollection activitiesToMove) { List locations = new List (); //We move all the designers foreach (Activity activityToMove in activitiesToMove) { Point location = endPoint; ActivityDesigner designerToMove = ActivityDesigner.GetDesigner(activityToMove); if (designerToMove != null && !startPoint.IsEmpty) { Size delta = new Size(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y); location = new Point(designerToMove.Location.X + delta.Width, designerToMove.Location.Y + delta.Height); } location = DesignerHelpers.SnapToGrid(location); locations.Add(location); } return locations.ToArray(); } private void UpdateCursor(bool showMoveCursor) { if (showMoveCursor) { if (ParentView.Cursor != FreeFormDragDropManager.MoveCursor && ParentView.Cursor == Cursors.Default) { this.previousCursor = ParentView.Cursor; ParentView.Cursor = FreeFormDragDropManager.MoveCursor; } } else { ParentView.Cursor = this.previousCursor; } } #endregion } #endregion } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. namespace System.Workflow.ComponentModel.Design { using System; using System.Text; using System.Drawing; using System.Diagnostics; using System.Collections; using System.Windows.Forms; using System.ComponentModel; using System.Drawing.Drawing2D; using System.Collections.Generic; using System.ComponentModel.Design; #region Class FreeFormDragDropManager internal sealed class FreeFormDragDropManager : DragDropManager { #region Members and Constructor private static Cursor DragMoveCursor = new Cursor(typeof(WorkflowView), "Resources.DragMoveCursor.cur"); private static Cursor DragCopyCursor = new Cursor(typeof(WorkflowView), "Resources.DragCopyCursor.cur"); private static Cursor MoveCursor = new Cursor(typeof(WorkflowView), "Resources.MoveCursor.cur"); private List draggedDesignerImages = null; private Cursor previousCursor = Cursors.Default; private Point movedDesignerImagePoint = Point.Empty; public FreeFormDragDropManager() { } #endregion #region Behavior Overrides protected override bool OnDragEnter(DragEventArgs eventArgs) { bool retVal = base.OnDragEnter(eventArgs); if (this.draggedDesignerImages == null) { WorkflowView parentView = ParentView; Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)); Point logicalPoint = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y)); if (parentView.IsClientPointInActiveLayout(clientPoint)) this.movedDesignerImagePoint = logicalPoint; else this.movedDesignerImagePoint = DragInitiationPoint; } return retVal; } protected override bool OnDragOver(DragEventArgs eventArgs) { //Invalidate the dragged images if (this.draggedDesignerImages != null) { Point[] previousLocations = GetDesignerLocations(DragInitiationPoint, this.movedDesignerImagePoint, DraggedActivities); InvalidateDraggedImages(previousLocations); } bool retVal = base.OnDragOver(eventArgs); if (this.draggedDesignerImages != null) { WorkflowView parentView = ParentView; Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)); Point logicalPoint = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y)); if (parentView.IsClientPointInActiveLayout(clientPoint)) this.movedDesignerImagePoint = logicalPoint; else this.movedDesignerImagePoint = DragInitiationPoint; //Invalidate the new locations where the image is shown Point[] newLocations = GetDesignerLocations(DragInitiationPoint, this.movedDesignerImagePoint, DraggedActivities); InvalidateDraggedImages(newLocations); } return retVal; } protected override bool OnGiveFeedback(GiveFeedbackEventArgs gfbevent) { base.OnGiveFeedback(gfbevent); if (this.draggedDesignerImages != null) { gfbevent.UseDefaultCursors = false; if ((gfbevent.Effect & DragDropEffects.Move) == DragDropEffects.Move) Cursor.Current = FreeFormDragDropManager.DragMoveCursor; else if ((gfbevent.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) Cursor.Current = FreeFormDragDropManager.DragCopyCursor; else Cursor.Current = Cursors.No; return true; } return false; } protected override bool OnMouseMove(MouseEventArgs eventArgs) { bool retval = base.OnMouseMove(eventArgs); if (eventArgs.Button == MouseButtons.None) { bool showMoveCursor = false; showMoveCursor |= (MessageHitTestContext != null && MessageHitTestContext.AssociatedDesigner != null && ActivityDesigner.GetParentDesigner(MessageHitTestContext.AssociatedDesigner.Activity) is FreeformActivityDesigner && (MessageHitTestContext.HitLocation & HitTestLocations.ActionArea) == 0); UpdateCursor(showMoveCursor); } return retval; } protected override bool OnMouseLeave() { UpdateCursor(false); return false; } protected override bool OnScroll(ScrollBar sender, int value) { if (this.draggedDesignerImages != null) { Point[] previousLocations = GetDesignerLocations(DragInitiationPoint, this.movedDesignerImagePoint, DraggedActivities); InvalidateDraggedImages(previousLocations); } bool retVal = base.OnScroll(sender, value); if (this.draggedDesignerImages != null) { WorkflowView parentView = ParentView; Point clientPoint = parentView.PointToClient(Control.MousePosition); Point logicalPoint = parentView.ScreenPointToLogical(Control.MousePosition); if (parentView.IsClientPointInActiveLayout(clientPoint)) this.movedDesignerImagePoint = logicalPoint; else this.movedDesignerImagePoint = DragInitiationPoint; //Invalidate the new locations where the image is shown Point[] newLocations = GetDesignerLocations(DragInitiationPoint, this.movedDesignerImagePoint, DraggedActivities); InvalidateDraggedImages(newLocations); } return retVal; } protected override bool OnPaintWorkflowAdornments(PaintEventArgs eventArgs, Rectangle viewPort, AmbientTheme ambientTheme) { bool messageHandled = false; if (this.draggedDesignerImages == null || this.draggedDesignerImages.Count == 0 || !(DropTargetDesigner is FreeformActivityDesigner)) messageHandled = base.OnPaintWorkflowAdornments(eventArgs, viewPort, ambientTheme); return messageHandled; } protected override bool OnPaint(PaintEventArgs eventArgs, Rectangle viewPort, AmbientTheme ambientTheme) { bool messageHandled = false; if (this.draggedDesignerImages != null && DropTargetDesigner is FreeformActivityDesigner) { using (Region clipRegion = new Region(ActivityDesignerPaint.GetDesignerPath(ParentView.RootDesigner, false))) { Region oldRegion = eventArgs.Graphics.Clip; eventArgs.Graphics.Clip = clipRegion; Point[] locations = GetDesignerLocations(DragInitiationPoint, this.movedDesignerImagePoint, DraggedActivities); Debug.Assert(locations.Length == DraggedActivities.Count); Debug.Assert(this.draggedDesignerImages.Count == DraggedActivities.Count); for (int i = 0; i < this.draggedDesignerImages.Count; i++) { Size imageSize = this.draggedDesignerImages[i].Size; ActivityDesignerPaint.DrawImage(eventArgs.Graphics, this.draggedDesignerImages[i], new Rectangle(new Point(locations[i].X - 2 * ambientTheme.Margin.Width, locations[i].Y - 2 * ambientTheme.Margin.Height), imageSize), new Rectangle(Point.Empty, imageSize), DesignerContentAlignment.Fill, 0.4f, false); } eventArgs.Graphics.Clip = oldRegion; } } else { messageHandled = base.OnPaint(eventArgs, viewPort, ambientTheme); } return messageHandled; } protected override void CreateDragFeedbackImages(IList draggedActivities) { base.CreateDragFeedbackImages(draggedActivities); List imageList = new List (); using (Graphics graphics = ParentView.CreateGraphics()) { foreach (Activity activity in draggedActivities) { ActivityDesigner previewDesigner = ActivityDesigner.GetDesigner(activity); if (previewDesigner == null) previewDesigner = ActivityDesigner.CreateDesigner(ParentView, activity); imageList.Add(previewDesigner.GetPreviewImage(graphics)); } } //We create the designer images for designers associates with existing activities ParentView.InvalidateClientRectangle(Rectangle.Empty); this.draggedDesignerImages = imageList; } protected override void DestroyDragFeedbackImages() { base.DestroyDragFeedbackImages(); if (this.draggedDesignerImages != null) { foreach (Bitmap image in this.draggedDesignerImages) image.Dispose(); this.draggedDesignerImages = null; ParentView.InvalidateClientRectangle(Rectangle.Empty); } } #endregion #region Helpers private void InvalidateDraggedImages(Point[] locations) { if (this.draggedDesignerImages != null) { if (locations.Length == this.draggedDesignerImages.Count) { AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme; WorkflowView parentView = ParentView; //Invalidate the previous location where image was shown for (int i = 0; i < this.draggedDesignerImages.Count; i++) { Rectangle rectangle = new Rectangle(locations[i], this.draggedDesignerImages[i].Size); rectangle.Inflate(2 * ambientTheme.Margin.Width, 2 * ambientTheme.Margin.Height); parentView.InvalidateLogicalRectangle(rectangle); } } else { Debug.Assert(false); } } } internal static Point[] GetDesignerLocations(Point startPoint, Point endPoint, ICollection activitiesToMove) { List locations = new List (); //We move all the designers foreach (Activity activityToMove in activitiesToMove) { Point location = endPoint; ActivityDesigner designerToMove = ActivityDesigner.GetDesigner(activityToMove); if (designerToMove != null && !startPoint.IsEmpty) { Size delta = new Size(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y); location = new Point(designerToMove.Location.X + delta.Width, designerToMove.Location.Y + delta.Height); } location = DesignerHelpers.SnapToGrid(location); locations.Add(location); } return locations.ToArray(); } private void UpdateCursor(bool showMoveCursor) { if (showMoveCursor) { if (ParentView.Cursor != FreeFormDragDropManager.MoveCursor && ParentView.Cursor == Cursors.Default) { this.previousCursor = ParentView.Cursor; ParentView.Cursor = FreeFormDragDropManager.MoveCursor; } } else { ParentView.Cursor = this.previousCursor; } } #endregion } #endregion } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WindowsTreeView.cs
- ArrayElementGridEntry.cs
- HttpValueCollection.cs
- CacheSection.cs
- SQLGuidStorage.cs
- ThemeDirectoryCompiler.cs
- RawMouseInputReport.cs
- FormsAuthenticationTicket.cs
- ScriptMethodAttribute.cs
- SecuritySessionFilter.cs
- EncoderBestFitFallback.cs
- ObjectDisposedException.cs
- EventsTab.cs
- CodeAccessPermission.cs
- IndexerNameAttribute.cs
- TraceHandlerErrorFormatter.cs
- DiscoveryRequestHandler.cs
- WindowsStreamSecurityBindingElement.cs
- ToolBarTray.cs
- Overlapped.cs
- ProcessProtocolHandler.cs
- XmlSchemaAny.cs
- WorkflowTerminatedException.cs
- InvalidFilterCriteriaException.cs
- Int16AnimationBase.cs
- HostingEnvironmentException.cs
- BitmapEffectInputConnector.cs
- ReferenceConverter.cs
- AnimatedTypeHelpers.cs
- ParsedRoute.cs
- X509Utils.cs
- MimeAnyImporter.cs
- DispatcherExceptionEventArgs.cs
- SnapLine.cs
- DesignerWebPartChrome.cs
- SiteIdentityPermission.cs
- WindowsGrip.cs
- DBSchemaTable.cs
- FormViewUpdatedEventArgs.cs
- XamlStream.cs
- BrowserCapabilitiesFactoryBase.cs
- CodeSubDirectory.cs
- ByValueEqualityComparer.cs
- ScriptReferenceBase.cs
- DataGridTablesFactory.cs
- ScriptHandlerFactory.cs
- DefaultValueMapping.cs
- AutomationElement.cs
- FullTextState.cs
- StyleCollection.cs
- RelationshipManager.cs
- ProcessHostMapPath.cs
- GPRECTF.cs
- AssociationEndMember.cs
- XmlSchemaValidationException.cs
- DatatypeImplementation.cs
- PlatformNotSupportedException.cs
- KeyConverter.cs
- TraceHandler.cs
- AxDesigner.cs
- PasswordBoxAutomationPeer.cs
- GraphicsState.cs
- PrimarySelectionAdorner.cs
- RichTextBoxAutomationPeer.cs
- DesignerActionVerbItem.cs
- _LocalDataStoreMgr.cs
- WebConfigurationHostFileChange.cs
- IOThreadTimer.cs
- DataSourceXmlSerializer.cs
- XmlDeclaration.cs
- EncodingTable.cs
- TdsRecordBufferSetter.cs
- PolicyAssertionCollection.cs
- PathTooLongException.cs
- MenuItem.cs
- CompositeDispatchFormatter.cs
- JsonReader.cs
- ScopelessEnumAttribute.cs
- DataObject.cs
- Exceptions.cs
- SerTrace.cs
- ImmutableAssemblyCacheEntry.cs
- DrawingGroupDrawingContext.cs
- Region.cs
- AttributeUsageAttribute.cs
- ScrollBar.cs
- StringSorter.cs
- DllNotFoundException.cs
- StringInfo.cs
- IFormattable.cs
- XmlUtf8RawTextWriter.cs
- VisualTreeHelper.cs
- NameValueConfigurationCollection.cs
- EditorAttribute.cs
- Utils.cs
- __ConsoleStream.cs
- PrivilegeNotHeldException.cs
- QuaternionAnimationUsingKeyFrames.cs
- ApplicationFileParser.cs
- DataTable.cs