protected virtual void CreateDragFeedbackImages(IList <Activity> draggedActivities) { Bitmap draggedImage = null; if (draggedActivities.Count > 0) { Bitmap image = null; String description = String.Empty; if (draggedActivities.Count > 1) { image = DR.GetImage(DR.Activities) as Bitmap; description = DR.GetString(DR.ActivitiesDesc); } else { ToolboxBitmapAttribute toolboxBitmapAttribute = (ToolboxBitmapAttribute)TypeDescriptor.GetAttributes(draggedActivities[0].GetType())[typeof(ToolboxBitmapAttribute)]; image = toolboxBitmapAttribute.GetImage(draggedActivities[0].GetType()) as Bitmap; description = draggedActivities[0].GetType().Name; } if (image != null && description.Length > 0) { //Start creating a bitmap WorkflowView parentView = ParentView; Rectangle imageRectangle = (image != null) ? new Rectangle(Point.Empty, image.Size) : Rectangle.Empty; Rectangle descriptionRectangle = (description.Length > 0) ? new Rectangle(Point.Empty, new Size(AmbientTheme.DragImageTextSize.Width, parentView.Font.Height + 2)) : Rectangle.Empty; if (!imageRectangle.IsEmpty) { descriptionRectangle.Offset(imageRectangle.Width + AmbientTheme.DragImageMargins.Width, 0); } Size draggedImageSize = parentView.LogicalSizeToClient(new Size(imageRectangle.Width + descriptionRectangle.Width, Math.Max(imageRectangle.Height, descriptionRectangle.Height))); draggedImage = new Bitmap(draggedImageSize.Width, draggedImageSize.Height, PixelFormat.Format32bppArgb); using (Graphics draggedImageGraphics = Graphics.FromImage(draggedImage)) using (Brush backgroundBrush = new SolidBrush(Color.FromArgb(0, 255, 0, 255))) { draggedImageGraphics.ScaleTransform(ScaleZoomFactor, ScaleZoomFactor); draggedImageGraphics.FillRectangle(backgroundBrush, new Rectangle(0, 0, draggedImage.Width, draggedImage.Height)); if (image != null) { draggedImageGraphics.DrawImage(image, new Rectangle(Point.Empty, image.Size)); } if (description.Length > 0) { StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Near; stringFormat.Trimming = StringTrimming.EllipsisCharacter; stringFormat.LineAlignment = StringAlignment.Center; draggedImageGraphics.DrawString(description, parentView.Font, SystemBrushes.WindowText, descriptionRectangle, stringFormat); } } } } this.dragImage = draggedImage; }
protected virtual void CreateDragFeedbackImages(IList <Activity> draggedActivities) { Bitmap image = null; if (draggedActivities.Count > 0) { Bitmap bitmap2 = null; string s = string.Empty; if (draggedActivities.Count > 1) { bitmap2 = DR.GetImage("Activities") as Bitmap; s = DR.GetString("ActivitiesDesc", new object[0]); } else { ToolboxBitmapAttribute attribute = (ToolboxBitmapAttribute)TypeDescriptor.GetAttributes(draggedActivities[0].GetType())[typeof(ToolboxBitmapAttribute)]; bitmap2 = attribute.GetImage(draggedActivities[0].GetType()) as Bitmap; s = draggedActivities[0].GetType().Name; } if ((bitmap2 != null) && (s.Length > 0)) { WorkflowView parentView = base.ParentView; Rectangle rectangle = (bitmap2 != null) ? new Rectangle(Point.Empty, bitmap2.Size) : Rectangle.Empty; Rectangle layoutRectangle = (s.Length > 0) ? new Rectangle(Point.Empty, new Size(AmbientTheme.DragImageTextSize.Width, parentView.Font.Height + 2)) : Rectangle.Empty; if (!rectangle.IsEmpty) { layoutRectangle.Offset(rectangle.Width + AmbientTheme.DragImageMargins.Width, 0); } Size size = parentView.LogicalSizeToClient(new Size(rectangle.Width + layoutRectangle.Width, Math.Max(rectangle.Height, layoutRectangle.Height))); image = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(image)) { using (Brush brush = new SolidBrush(Color.FromArgb(0, 0xff, 0, 0xff))) { graphics.ScaleTransform(this.ScaleZoomFactor, this.ScaleZoomFactor); graphics.FillRectangle(brush, new Rectangle(0, 0, image.Width, image.Height)); if (bitmap2 != null) { graphics.DrawImage(bitmap2, new Rectangle(Point.Empty, bitmap2.Size)); } if (s.Length > 0) { StringFormat format = new StringFormat { Alignment = StringAlignment.Near, Trimming = StringTrimming.EllipsisCharacter, LineAlignment = StringAlignment.Center }; graphics.DrawString(s, parentView.Font, SystemBrushes.WindowText, layoutRectangle, format); } } } } } this.dragImage = image; }
protected override bool OnDragOver(DragEventArgs eventArgs) { //By default we do not allow any drag drop operation eventArgs.Effect = DragDropEffects.None; this.wasCtrlKeyPressed = false; this.dragImageSnapped = false; //Get the coordinates WorkflowView parentView = ParentView; Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)); Point logicalPoint = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y)); //Update the drag image position Point oldDragImagePoint = this.dragImagePointInClientCoOrd; this.dragImagePointInClientCoOrd = new Point(clientPoint.X + SystemInformation.CursorSize.Width / 4, clientPoint.Y + SystemInformation.CursorSize.Height / 4); //Now check if the drag point is in active layout if not then clear the designer if (!parentView.IsClientPointInActiveLayout(clientPoint)) { if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); } this.dropTargetDesigner = null; } else { //Now we have a potential for successful drag drop, so construct drag event arguments with logical coordinates this.wasCtrlKeyPressed = ((eventArgs.KeyState & 8) == 8); ActivityDragEventArgs dragdropEventArgs = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, logicalPoint, this.draggedActivities); //Now check which designer is under the cursor, if there is no designer then we return HitTestInfo hitTestInfo = MessageHitTestContext; ActivityDesigner potentialDropTargetDesigner = hitTestInfo.AssociatedDesigner; if (potentialDropTargetDesigner != null) { CompositeActivityDesigner compositeDesigner = potentialDropTargetDesigner as CompositeActivityDesigner; if ((!this.wasCtrlKeyPressed && IsRecursiveDropOperation(potentialDropTargetDesigner)) || (compositeDesigner != null && !compositeDesigner.IsEditable)) { dragdropEventArgs.Effect = DragDropEffects.None; potentialDropTargetDesigner = null; } } //If the designers differ then send appropriate messages if (this.dropTargetDesigner != potentialDropTargetDesigner) { if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); } this.dropTargetDesigner = potentialDropTargetDesigner; if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragEnter(dragdropEventArgs); } } else { //Looks like we got the same designer if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragOver(dragdropEventArgs); } //Check if there is a potential for the drag image to be snapped if (DragDropEffects.None != dragdropEventArgs.Effect && !dragdropEventArgs.DragImageSnapPoint.IsEmpty) { Point midPointInClientCoOrd = parentView.LogicalPointToClient(dragdropEventArgs.DragImageSnapPoint); Size dragImageIconSize = parentView.LogicalSizeToClient(AmbientTheme.DragImageIconSize); this.dragImagePointInClientCoOrd = new Point(midPointInClientCoOrd.X - dragImageIconSize.Width / 2, midPointInClientCoOrd.Y - dragImageIconSize.Height / 2); this.dragImageSnapped = true; } } eventArgs.Effect = dragdropEventArgs.Effect; } // if (this.dragImage != null) { parentView.InvalidateClientRectangle(new Rectangle(oldDragImagePoint, this.dragImage.Size)); parentView.InvalidateClientRectangle(new Rectangle(this.dragImagePointInClientCoOrd, this.dragImage.Size)); } if (eventArgs.Effect == DragDropEffects.None && this.exceptionInDragDrop) { eventArgs.Effect = (this.wasCtrlKeyPressed) ? DragDropEffects.Copy : DragDropEffects.Move; } return(true); }
protected override bool OnDragEnter(DragEventArgs eventArgs) { //We purposely pass the DragEnter thru to the next behavior so that the WindowingBehavior can clear the //active designer Debug.Assert(this.dropTargetDesigner == null); //Invalidate the entire rectangle so that we draw active placement glyphs on connectors WorkflowView parentView = ParentView; parentView.InvalidateClientRectangle(Rectangle.Empty); //By default we do not allow any drag drop operation eventArgs.Effect = DragDropEffects.None; this.wasCtrlKeyPressed = false; //Now cache the components which are getting dragged so that we don't need to create them again and again if (this.existingDraggedActivities.Count > 0) { this.draggedActivities.AddRange(this.existingDraggedActivities); } else { try { Activity[] activities = CompositeActivityDesigner.DeserializeActivitiesFromDataObject(ParentView, eventArgs.Data); if (activities != null) { this.draggedActivities.AddRange(activities); } } catch { this.exceptionInDragDrop = true; } } //Get the coordinates Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)); Point logicalPoint = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y)); //Now try to create the drag image and invalidate the area so that we can draw the dragged image Debug.Assert(this.dragImage == null); CreateDragFeedbackImages(this.draggedActivities); if (this.dragImage != null) { this.dragImagePointInClientCoOrd = new Point(clientPoint.X + SystemInformation.CursorSize.Width / 4, clientPoint.Y + SystemInformation.CursorSize.Height / 4); } //If the hit is not in the layouts then we need to bail out, this is very important if (!parentView.IsClientPointInActiveLayout(clientPoint)) { return(false); } //Now we have a potential for successful drag drop, so construct drag event arguments with logical coordinates this.wasCtrlKeyPressed = ((eventArgs.KeyState & 8) == 8); ActivityDragEventArgs dragdropEventArgs = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, logicalPoint, this.draggedActivities); //Now check which designer is under the cursor, if there is no designer then we return HitTestInfo hitTestInfo = MessageHitTestContext; ActivityDesigner potentialDropTargetDesigner = hitTestInfo.AssociatedDesigner; if (potentialDropTargetDesigner == null) { return(false); } //Now that we found a potential droptarget designer, make sure that we can start drag drop //If the drag drop can not be performed then return. if (!this.wasCtrlKeyPressed && IsRecursiveDropOperation(potentialDropTargetDesigner)) { return(false); } CompositeActivityDesigner compositeDesigner = potentialDropTargetDesigner as CompositeActivityDesigner; if (compositeDesigner != null && !compositeDesigner.IsEditable) { return(false); } //Now that we can truely perform drag and drop operation we can pump in the message this.dropTargetDesigner = potentialDropTargetDesigner; ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragEnter(dragdropEventArgs); //Check the return value, if this is a potential snap location then we need to snap the image if (!dragdropEventArgs.DragImageSnapPoint.IsEmpty) { Point midPointInClientCoOrd = parentView.LogicalPointToClient(dragdropEventArgs.DragImageSnapPoint); Size dragImageIconSize = parentView.LogicalSizeToClient(AmbientTheme.DragImageIconSize); this.dragImagePointInClientCoOrd = new Point(midPointInClientCoOrd.X - dragImageIconSize.Width / 2, midPointInClientCoOrd.Y - dragImageIconSize.Height / 2); this.dragImageSnapped = true; } eventArgs.Effect = dragdropEventArgs.Effect; if (eventArgs.Effect == DragDropEffects.None && this.exceptionInDragDrop) { eventArgs.Effect = (this.wasCtrlKeyPressed) ? DragDropEffects.Copy : DragDropEffects.Move; } return(true); }
protected override bool OnDragOver(DragEventArgs eventArgs) { eventArgs.Effect = DragDropEffects.None; this.wasCtrlKeyPressed = false; this.dragImageSnapped = false; WorkflowView parentView = base.ParentView; Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)); Point point = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y)); Point dragImagePointInClientCoOrd = this.dragImagePointInClientCoOrd; this.dragImagePointInClientCoOrd = new Point(clientPoint.X + (SystemInformation.CursorSize.Width / 4), clientPoint.Y + (SystemInformation.CursorSize.Height / 4)); if (!parentView.IsClientPointInActiveLayout(clientPoint)) { if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); } this.dropTargetDesigner = null; } else { this.wasCtrlKeyPressed = (eventArgs.KeyState & 8) == 8; ActivityDragEventArgs e = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, point, this.draggedActivities); ActivityDesigner associatedDesigner = base.MessageHitTestContext.AssociatedDesigner; if (associatedDesigner != null) { CompositeActivityDesigner designer2 = associatedDesigner as CompositeActivityDesigner; if ((!this.wasCtrlKeyPressed && this.IsRecursiveDropOperation(associatedDesigner)) || ((designer2 != null) && !designer2.IsEditable)) { e.Effect = DragDropEffects.None; associatedDesigner = null; } } if (this.dropTargetDesigner != associatedDesigner) { if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); } this.dropTargetDesigner = associatedDesigner; if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragEnter(e); } } else { if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragOver(e); } if ((e.Effect != DragDropEffects.None) && !e.DragImageSnapPoint.IsEmpty) { Point point4 = parentView.LogicalPointToClient(e.DragImageSnapPoint); Size size = parentView.LogicalSizeToClient(AmbientTheme.DragImageIconSize); this.dragImagePointInClientCoOrd = new Point(point4.X - (size.Width / 2), point4.Y - (size.Height / 2)); this.dragImageSnapped = true; } } eventArgs.Effect = e.Effect; } if (this.dragImage != null) { parentView.InvalidateClientRectangle(new Rectangle(dragImagePointInClientCoOrd, this.dragImage.Size)); parentView.InvalidateClientRectangle(new Rectangle(this.dragImagePointInClientCoOrd, this.dragImage.Size)); } if ((eventArgs.Effect == DragDropEffects.None) && this.exceptionInDragDrop) { eventArgs.Effect = this.wasCtrlKeyPressed ? DragDropEffects.Copy : DragDropEffects.Move; } return(true); }
protected override bool OnDragEnter(DragEventArgs eventArgs) { WorkflowView parentView = base.ParentView; parentView.InvalidateClientRectangle(Rectangle.Empty); eventArgs.Effect = DragDropEffects.None; this.wasCtrlKeyPressed = false; if (this.existingDraggedActivities.Count > 0) { this.draggedActivities.AddRange(this.existingDraggedActivities); } else { try { Activity[] collection = CompositeActivityDesigner.DeserializeActivitiesFromDataObject(base.ParentView, eventArgs.Data); if (collection != null) { this.draggedActivities.AddRange(collection); } } catch { this.exceptionInDragDrop = true; } } Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)); Point point = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y)); this.CreateDragFeedbackImages(this.draggedActivities); if (this.dragImage != null) { this.dragImagePointInClientCoOrd = new Point(clientPoint.X + (SystemInformation.CursorSize.Width / 4), clientPoint.Y + (SystemInformation.CursorSize.Height / 4)); } if (!parentView.IsClientPointInActiveLayout(clientPoint)) { return(false); } this.wasCtrlKeyPressed = (eventArgs.KeyState & 8) == 8; ActivityDragEventArgs e = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, point, this.draggedActivities); ActivityDesigner associatedDesigner = base.MessageHitTestContext.AssociatedDesigner; if (associatedDesigner == null) { return(false); } if (!this.wasCtrlKeyPressed && this.IsRecursiveDropOperation(associatedDesigner)) { return(false); } CompositeActivityDesigner designer2 = associatedDesigner as CompositeActivityDesigner; if ((designer2 != null) && !designer2.IsEditable) { return(false); } this.dropTargetDesigner = associatedDesigner; ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragEnter(e); if (!e.DragImageSnapPoint.IsEmpty) { Point point3 = parentView.LogicalPointToClient(e.DragImageSnapPoint); Size size = parentView.LogicalSizeToClient(AmbientTheme.DragImageIconSize); this.dragImagePointInClientCoOrd = new Point(point3.X - (size.Width / 2), point3.Y - (size.Height / 2)); this.dragImageSnapped = true; } eventArgs.Effect = e.Effect; if ((eventArgs.Effect == DragDropEffects.None) && this.exceptionInDragDrop) { eventArgs.Effect = this.wasCtrlKeyPressed ? DragDropEffects.Copy : DragDropEffects.Move; } return(true); }