Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TypedDatasetGenerator.cs
- RandomNumberGenerator.cs
- StorageMappingFragment.cs
- ExceptionHandlerDesigner.cs
- TrackingStringDictionary.cs
- DecoderReplacementFallback.cs
- Vector3DAnimation.cs
- CssTextWriter.cs
- ProfileEventArgs.cs
- Timer.cs
- UserPreferenceChangedEventArgs.cs
- DataGridHyperlinkColumn.cs
- WebPartConnectionsCancelVerb.cs
- AxisAngleRotation3D.cs
- CodeSnippetExpression.cs
- TripleDESCryptoServiceProvider.cs
- XmlQueryRuntime.cs
- ASCIIEncoding.cs
- unsafenativemethodstextservices.cs
- ListViewInsertedEventArgs.cs
- PropertyItemInternal.cs
- COM2TypeInfoProcessor.cs
- XmlSchemaAppInfo.cs
- RadioButtonBaseAdapter.cs
- ClrPerspective.cs
- ObjectStorage.cs
- ElementHost.cs
- ArrayEditor.cs
- StylusPointPropertyUnit.cs
- MachineKeyConverter.cs
- DTCTransactionManager.cs
- DecimalKeyFrameCollection.cs
- InvalidDataException.cs
- DbMetaDataFactory.cs
- MsmqIntegrationElement.cs
- WebPartManagerInternals.cs
- UserControl.cs
- InputGestureCollection.cs
- CodeParameterDeclarationExpression.cs
- ServerValidateEventArgs.cs
- StreamUpgradeProvider.cs
- TableItemPattern.cs
- FontFamily.cs
- ButtonRenderer.cs
- Registration.cs
- SafeProcessHandle.cs
- InstanceView.cs
- ToolBar.cs
- OrthographicCamera.cs
- NavigateUrlConverter.cs
- TextEmbeddedObject.cs
- ExceptionRoutedEventArgs.cs
- COM2ComponentEditor.cs
- SecurityTokenContainer.cs
- DbDataAdapter.cs
- LocalizabilityAttribute.cs
- TreeNodeClickEventArgs.cs
- RayMeshGeometry3DHitTestResult.cs
- InputLanguageEventArgs.cs
- SqlWebEventProvider.cs
- SafeNativeMethodsCLR.cs
- ThreadLocal.cs
- BaseServiceProvider.cs
- ExpressionHelper.cs
- TreeViewImageGenerator.cs
- AccessKeyManager.cs
- DefaultEventAttribute.cs
- ButtonFieldBase.cs
- WorkItem.cs
- ConfigXmlWhitespace.cs
- CheckBoxRenderer.cs
- COM2ICategorizePropertiesHandler.cs
- SerializationInfo.cs
- XmlSchemaSimpleTypeUnion.cs
- PopupControlService.cs
- SHA384Managed.cs
- XmlLangPropertyAttribute.cs
- UdpConstants.cs
- SID.cs
- Function.cs
- StartUpEventArgs.cs
- GridViewHeaderRowPresenterAutomationPeer.cs
- SequentialUshortCollection.cs
- IsolatedStoragePermission.cs
- HttpCachePolicyElement.cs
- Vertex.cs
- ImmComposition.cs
- IChannel.cs
- StringBlob.cs
- RequestStatusBarUpdateEventArgs.cs
- DeferredSelectedIndexReference.cs
- DataContractSerializerSection.cs
- ProviderUtil.cs
- FixUpCollection.cs
- DocumentSequence.cs
- CodeLabeledStatement.cs
- ImageCodecInfo.cs
- SqlDataSourceSelectingEventArgs.cs
- MediaPlayerState.cs
- FacetEnabledSchemaElement.cs