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 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 OnDragOver(DragEventArgs eventArgs) { if (this.draggedDesignerImages != null) { Point[] locations = GetDesignerLocations(base.DragInitiationPoint, this.movedDesignerImagePoint, base.DraggedActivities); this.InvalidateDraggedImages(locations); } bool flag = base.OnDragOver(eventArgs); if (this.draggedDesignerImages != null) { WorkflowView parentView = base.ParentView; Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)); Point point2 = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y)); if (parentView.IsClientPointInActiveLayout(clientPoint)) { this.movedDesignerImagePoint = point2; } else { this.movedDesignerImagePoint = base.DragInitiationPoint; } Point[] pointArray2 = GetDesignerLocations(base.DragInitiationPoint, this.movedDesignerImagePoint, base.DraggedActivities); this.InvalidateDraggedImages(pointArray2); } return(flag); }
protected override bool OnScroll(ScrollBar sender, int value) { if (this.draggedDesignerImages != null) { Point[] locations = GetDesignerLocations(base.DragInitiationPoint, this.movedDesignerImagePoint, base.DraggedActivities); this.InvalidateDraggedImages(locations); } bool flag = base.OnScroll(sender, value); if (this.draggedDesignerImages != null) { WorkflowView parentView = base.ParentView; Point clientPoint = parentView.PointToClient(Control.MousePosition); Point point2 = parentView.ScreenPointToLogical(Control.MousePosition); if (parentView.IsClientPointInActiveLayout(clientPoint)) { this.movedDesignerImagePoint = point2; } else { this.movedDesignerImagePoint = base.DragInitiationPoint; } Point[] pointArray2 = GetDesignerLocations(base.DragInitiationPoint, this.movedDesignerImagePoint, base.DraggedActivities); this.InvalidateDraggedImages(pointArray2); } return(flag); }
private void SetDraggedButton(int actionIndex, int buttonIndex) { if (this.draggedActionIndex == actionIndex && this.draggedButtonIndex == buttonIndex) { return; } WorkflowView parentView = ParentView; if (this.draggedActionIndex >= 0 && this.draggedButtonIndex >= 0) { if (this.draggedActionIndex < this.actions.Count) { this.actions[this.draggedActionIndex].Buttons[this.draggedButtonIndex].State = ActionButton.States.Highlight; } this.draggedActionIndex = -1; this.draggedButtonIndex = -1; parentView.Capture = false; UpdateTransparency(parentView.PointToClient(Control.MousePosition)); } this.draggedActionIndex = actionIndex; this.draggedButtonIndex = buttonIndex; if (this.draggedActionIndex >= 0 && this.draggedButtonIndex >= 0) { parentView.Capture = true; } }
protected override bool OnDragOver(DragEventArgs eventArgs) { WorkflowView parentView = base.ParentView; if (parentView.IsClientPointInActiveLayout(parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)))) { this.SetAutoExpandableDesigner(parentView.MessageHitTestContext.AssociatedDesigner as CompositeActivityDesigner); } else { this.SetAutoExpandableDesigner(null); } return(false); }
protected override bool OnDragEnter(DragEventArgs eventArgs) { bool flag = base.OnDragEnter(eventArgs); if (this.draggedDesignerImages == null) { WorkflowView parentView = base.ParentView; Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)); Point point2 = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y)); if (parentView.IsClientPointInActiveLayout(clientPoint)) { this.movedDesignerImagePoint = point2; return(flag); } this.movedDesignerImagePoint = base.DragInitiationPoint; } return(flag); }
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); }
/// <summary> /// The context menu is about to be shown. Build the /// available list of menu items based on the /// selected activity. /// </summary> /// <param name="menuID"></param> /// <param name="x"></param> /// <param name="y"></param> public override void ShowContextMenu( CommandID menuID, int x, int y) { base.ShowContextMenu(menuID, x, y); if (menuID == WorkflowMenuCommands.SelectionMenu) { ContextMenu contextMenu = new ContextMenu(); //add a context menu item for each designer //verb that is available foreach (DesignerVerb verb in Verbs) { MenuItem menuItem = new MenuItem(verb.Text, new EventHandler(OnMenuClicked)); menuItem.Tag = verb; contextMenu.MenuItems.Add(menuItem); } //add any context menu items based on the //selected object foreach (MenuItem menu in BuildItemsForSelection()) { contextMenu.MenuItems.Add(menu); } //show the newly constructed context menu //on the workflow view WorkflowView workflowView = GetService(typeof(WorkflowView)) as WorkflowView; if (workflowView != null) { //show the context menu contextMenu.Show(workflowView, workflowView.PointToClient(new Point(x, y))); } } }
protected override bool OnDragDrop(DragEventArgs eventArgs) { //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; DestroyDragFeedbackImages(); //Get the coordinates Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)); Point logicalPoint = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y)); //Now we check if the drag drop was in any valid area, if not then do not proceed further if (!parentView.IsClientPointInActiveLayout(clientPoint)) { if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); } this.wasCtrlKeyPressed = false; this.dropTargetDesigner = null; this.draggedActivities.Clear(); 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 we have the same designer as the old one //If not then we set the new one as drop target and pump in messages HitTestInfo hitTestInfo = MessageHitTestContext; if (this.dropTargetDesigner != hitTestInfo.AssociatedDesigner) { if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); this.dropTargetDesigner = null; } if (hitTestInfo.AssociatedDesigner != null) { this.dropTargetDesigner = hitTestInfo.AssociatedDesigner; if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragEnter(dragdropEventArgs); } } } //We now have appropriate droptarget designer try { if (this.dropTargetDesigner != null) { //We do not allow recursive drag and drop if (!this.wasCtrlKeyPressed && IsRecursiveDropOperation(this.dropTargetDesigner) || (this.dropTargetDesigner is CompositeActivityDesigner && !((CompositeActivityDesigner)this.dropTargetDesigner).IsEditable)) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); dragdropEventArgs.Effect = DragDropEffects.None; } else { // IMPORTANT: Don't use draggedActivities variable, because components which are // there may not be created using the assembly references added to ITypeResultionService // this.workflowView.time the components will be created using the assembly references got added to the project List <Activity> droppedActivities = new List <Activity>(); string transactionDescription = SR.GetString(SR.DragDropActivities); //This means that we are trying to move activities so we use the same activities for drop if (!this.wasCtrlKeyPressed && this.existingDraggedActivities.Count > 0) { droppedActivities.AddRange(this.existingDraggedActivities); if (droppedActivities.Count > 1) { transactionDescription = SR.GetString(SR.MoveMultipleActivities, droppedActivities.Count); } else if (droppedActivities.Count == 1) { transactionDescription = SR.GetString(SR.MoveSingleActivity, droppedActivities[0].GetType()); } } else { droppedActivities.AddRange(CompositeActivityDesigner.DeserializeActivitiesFromDataObject(ParentView, eventArgs.Data, true)); if (droppedActivities.Count > 0) { transactionDescription = SR.GetString(SR.CreateActivityFromToolbox, droppedActivities[0].GetType()); } } //Now that we have what needs to be dropped, we start the actual drag and drop IDesignerHost designerHost = GetService(typeof(IDesignerHost)) as IDesignerHost; DesignerTransaction transaction = null; if (droppedActivities.Count > 0) { transaction = designerHost.CreateTransaction(transactionDescription); } dragdropEventArgs = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, logicalPoint, droppedActivities); try { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragDrop(dragdropEventArgs); if (dragdropEventArgs.Effect == DragDropEffects.Move) { this.existingDraggedActivities.Clear(); } if (transaction != null) { transaction.Commit(); } } catch (Exception e) { if (transaction != null) { transaction.Cancel(); } throw e; } //We deserialize the designers and try to store the designer states if (droppedActivities.Count > 0) { Stream componentStateStream = eventArgs.Data.GetData(DragDropManager.CF_DESIGNERSTATE) as Stream; if (componentStateStream != null) { Helpers.DeserializeDesignersFromStream(droppedActivities, componentStateStream); } //Set the current selection ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService)); if (selectionService != null) { selectionService.SetSelectedComponents(droppedActivities, SelectionTypes.Replace); } } //Active the design surface if (designerHost != null) { designerHost.Activate(); } } } } catch (Exception ex) { //We purposely consume application thrown exception which are result of user cancelling the action //during dragdrop where we popup UI Wizards during drag drop. Ref: InvokeWebService ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); dragdropEventArgs.Effect = DragDropEffects.None; string dragDropException = ex.Message; if (ex.InnerException != null && !String.IsNullOrEmpty(ex.InnerException.Message)) { dragDropException = ex.InnerException.Message; } string errorMessage = DR.GetString(DR.Error_FailedToDeserializeComponents); errorMessage += "\r\n" + DR.GetString(DR.Error_Reason, dragDropException); DesignerHelpers.ShowError(ParentView, errorMessage); if (ex != CheckoutException.Canceled) { throw new Exception(errorMessage, ex); } } finally { //Make sure that mouse over designer is set to null this.wasCtrlKeyPressed = false; this.draggedActivities.Clear(); this.dropTargetDesigner = null; this.exceptionInDragDrop = false; eventArgs.Effect = dragdropEventArgs.Effect; } return(true); }
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); }
protected override bool OnDragDrop(DragEventArgs eventArgs) { WorkflowView parentView = base.ParentView; parentView.InvalidateClientRectangle(Rectangle.Empty); eventArgs.Effect = DragDropEffects.None; this.DestroyDragFeedbackImages(); Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)); Point point = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y)); if (!parentView.IsClientPointInActiveLayout(clientPoint)) { if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); } this.wasCtrlKeyPressed = false; this.dropTargetDesigner = null; this.draggedActivities.Clear(); return(false); } this.wasCtrlKeyPressed = (eventArgs.KeyState & 8) == 8; ActivityDragEventArgs e = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, point, this.draggedActivities); System.Workflow.ComponentModel.Design.HitTestInfo messageHitTestContext = base.MessageHitTestContext; if (this.dropTargetDesigner != messageHitTestContext.AssociatedDesigner) { if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); this.dropTargetDesigner = null; } if (messageHitTestContext.AssociatedDesigner != null) { this.dropTargetDesigner = messageHitTestContext.AssociatedDesigner; if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragEnter(e); } } } try { if (this.dropTargetDesigner != null) { if ((!this.wasCtrlKeyPressed && this.IsRecursiveDropOperation(this.dropTargetDesigner)) || ((this.dropTargetDesigner is CompositeActivityDesigner) && !((CompositeActivityDesigner)this.dropTargetDesigner).IsEditable)) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); e.Effect = DragDropEffects.None; } else { List <Activity> draggedActivities = new List <Activity>(); string description = SR.GetString("DragDropActivities"); if (!this.wasCtrlKeyPressed && (this.existingDraggedActivities.Count > 0)) { draggedActivities.AddRange(this.existingDraggedActivities); if (draggedActivities.Count > 1) { description = SR.GetString("MoveMultipleActivities", new object[] { draggedActivities.Count }); } else if (draggedActivities.Count == 1) { description = SR.GetString("MoveSingleActivity", new object[] { draggedActivities[0].GetType() }); } } else { draggedActivities.AddRange(CompositeActivityDesigner.DeserializeActivitiesFromDataObject(base.ParentView, eventArgs.Data, true)); if (draggedActivities.Count > 0) { description = SR.GetString("CreateActivityFromToolbox", new object[] { draggedActivities[0].GetType() }); } } IDesignerHost host = base.GetService(typeof(IDesignerHost)) as IDesignerHost; DesignerTransaction transaction = null; if (draggedActivities.Count > 0) { transaction = host.CreateTransaction(description); } e = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, point, draggedActivities); try { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragDrop(e); if (e.Effect == DragDropEffects.Move) { this.existingDraggedActivities.Clear(); } if (transaction != null) { transaction.Commit(); } } catch (Exception exception) { if (transaction != null) { transaction.Cancel(); } throw exception; } if (draggedActivities.Count > 0) { Stream data = eventArgs.Data.GetData("CF_WINOEDESIGNERCOMPONENTSSTATE") as Stream; if (data != null) { Helpers.DeserializeDesignersFromStream(draggedActivities, data); } ISelectionService service = (ISelectionService)base.GetService(typeof(ISelectionService)); if (service != null) { service.SetSelectedComponents(draggedActivities, SelectionTypes.Replace); } } if (host != null) { host.Activate(); } } } } catch (Exception exception2) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); e.Effect = DragDropEffects.None; string message = exception2.Message; if ((exception2.InnerException != null) && !string.IsNullOrEmpty(exception2.InnerException.Message)) { message = exception2.InnerException.Message; } string str3 = DR.GetString("Error_FailedToDeserializeComponents", new object[0]) + "\r\n" + DR.GetString("Error_Reason", new object[] { message }); DesignerHelpers.ShowError(base.ParentView, str3); if (exception2 != CheckoutException.Canceled) { throw new Exception(str3, exception2); } } finally { this.wasCtrlKeyPressed = false; this.draggedActivities.Clear(); this.dropTargetDesigner = null; this.exceptionInDragDrop = false; eventArgs.Effect = e.Effect; } return(true); }