public override bool CanMoveActivities(HitTestInfo moveLocation, ReadOnlyCollection<Activity> activitiesToMove) { if ((((this.ContainedDesigners.Count - activitiesToMove.Count) < 1) && (moveLocation != null)) && (moveLocation.AssociatedDesigner != this)) { return false; } return true; }
public override bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert) { if ((this == base.ActiveView.AssociatedDesigner) && (this.ContainedDesigners.Count > 0)) { return false; } return base.CanInsertActivities(insertLocation, activitiesToInsert); }
public override bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert) { foreach (Activity activity in activitiesToInsert) { if (activity.GetType() != typeof(SequenceActivity)) return false; } return base.CanInsertActivities(insertLocation, activitiesToInsert); }
public override bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert) { foreach (Activity activity in activitiesToInsert) { if (!(activity is EventDrivenActivity)) return false; } return base.CanInsertActivities(insertLocation, activitiesToInsert); }
public override bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert) { foreach (Activity activity in activitiesToInsert) { if (Helpers.IsFrameworkActivity(activity)) return false; } return base.CanInsertActivities(insertLocation, activitiesToInsert); }
/// <summary> /// We override this function re-enforce the rule that only one child activity /// can be added. /// </summary> /// <param name="insertLocation"></param> /// <param name="activitiesToInsert"></param> /// <returns></returns> public override bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert) { // We only allow one activity to be inserted. // ...If the current view is for this designer (and not the Faulting or canceling designer), // ...and there is one contained designer (i.e. child activity) then cancel this insert. if ((this == ActiveView.AssociatedDesigner) && (ContainedDesigners.Count > 0)) return false; return base.CanInsertActivities(insertLocation, activitiesToInsert); }
public override bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert) { CompositeActivity compositeActivity = Activity as CompositeActivity; if (compositeActivity != null && compositeActivity.EnabledActivities.Count > 0) return false; if (activitiesToInsert.Count > 1) return false; return base.CanInsertActivities(insertLocation, activitiesToInsert); }
internal void AddChild(Activity child) { if ((base.Activity is CompositeActivity) && (child != null)) { int count = this.ContainedDesigners.Count; System.Workflow.ComponentModel.Design.HitTestInfo insertLocation = new System.Workflow.ComponentModel.Design.HitTestInfo(this, HitTestLocations.Designer); CompositeActivityDesigner.InsertActivities(this, insertLocation, new List<Activity>(new Activity[] { child }).AsReadOnly(), string.Format(CultureInfo.InvariantCulture, System.Workflow.Activities.DR.GetString("AddingChild"), new object[] { child.GetType().Name })); if ((this.ContainedDesigners.Count > count) && (this.ContainedDesigners.Count > 0)) { this.ContainedDesigners[this.ContainedDesigners.Count - 1].EnsureVisible(); } this.SelectionService.SetSelectedComponents(new object[] { child }, SelectionTypes.Click); } }
private HitTestInfo GetUpdatedLocation(HitTestInfo location) { int lockedActivityOffset = 0; foreach (DesignerView secondaryView in Views) { if (secondaryView.AssociatedDesigner != null && this != secondaryView.AssociatedDesigner && Helpers.IsActivityLocked(secondaryView.AssociatedDesigner.Activity)) { lockedActivityOffset++; } } return(new ConnectorHitTestInfo(this, location.HitLocation, lockedActivityOffset + location.MapToIndex())); }
public override bool CanMoveActivities(HitTestInfo moveLocation, ReadOnlyCollection <Activity> activitiesToMove) { if (moveLocation == null) { throw new ArgumentNullException("moveLocation"); } if (activitiesToMove == null) { throw new ArgumentNullException("activitiesToMove"); } if ((base.ActiveDesigner == this) && ((((this.ContainedDesigners.Count - activitiesToMove.Count) < 2) && (moveLocation != null)) && (moveLocation.AssociatedDesigner != this))) { return(false); } return(base.CanMoveActivities(moveLocation, activitiesToMove)); }
public override bool CanMoveActivities(HitTestInfo moveLocation, ReadOnlyCollection<Activity> activitiesToMove) { if (moveLocation == null) { throw new ArgumentNullException("moveLocation"); } if (activitiesToMove == null) { throw new ArgumentNullException("activitiesToMove"); } if ((base.ActiveDesigner == this) && ((((this.ContainedDesigners.Count - activitiesToMove.Count) < 2) && (moveLocation != null)) && (moveLocation.AssociatedDesigner != this))) { return false; } return base.CanMoveActivities(moveLocation, activitiesToMove); }
public override bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert) { int num = 0; foreach (Activity activity in ((EventHandlingScopeActivity) base.Activity).Activities) { if (!System.Workflow.Activities.Common.Helpers.IsFrameworkActivity(activity) && !(activity is EventHandlersActivity)) { num++; } } if (num > 0) { return false; } return base.CanInsertActivities(insertLocation, activitiesToInsert); }
public override HitTestInfo HitTest(Point point) { HitTestInfo hitInfo = HitTestInfo.Nowhere; if (Expanded && ActiveDesigner == this) { if (ContainedDesigners.Count == 0 && HelpTextRectangle.Contains(point)) { hitInfo = new ConnectorHitTestInfo(this, HitTestLocations.Designer, 0); } else if (this.previewStrip.Bounds.Contains(point)) { ItemInfo itemInfo = this.previewStrip.HitTest(point); ActivityDesigner activityDesigner = (itemInfo != null) ? ActivityDesigner.GetDesigner(itemInfo.UserData[DesignerUserDataKeys.Activity] as Activity) : null; if (activityDesigner != null) { hitInfo = new HitTestInfo(activityDesigner, HitTestLocations.Designer); } else { hitInfo = new HitTestInfo(this, HitTestLocations.Designer | HitTestLocations.ActionArea); } } else if (ShowPreview && this.previewWindow.Bounds.Contains(point) && (this.previewWindow.PreviewMode || PreviewedDesigner == null || !PreviewedDesigner.Bounds.Contains(point))) { hitInfo = new HitTestInfo(this, HitTestLocations.Designer | HitTestLocations.ActionArea); } else { hitInfo = base.HitTest(point); if (ShowPreview && this.previewWindow.PreviewMode && hitInfo.AssociatedDesigner != this) { hitInfo = HitTestInfo.Nowhere; } } } else { hitInfo = base.HitTest(point); } return(hitInfo); }
protected override bool OnMouseMove(MouseEventArgs eventArgs) { Point clientPoint = new Point(eventArgs.X, eventArgs.Y); //If the mouse is not in a valid area then we return if (!ParentView.IsClientPointInActiveLayout(clientPoint)) { if (this.currentActiveDesigner != null) { ((IWorkflowDesignerMessageSink)this.currentActiveDesigner).OnMouseLeave(); } this.currentActiveDesigner = null; return(true); } //Now check which designer is hit HitTestInfo hitTestInfo = MessageHitTestContext; if (this.currentActiveDesigner != hitTestInfo.AssociatedDesigner) { if (this.currentActiveDesigner != null) { ((IWorkflowDesignerMessageSink)this.currentActiveDesigner).OnMouseLeave(); } this.currentActiveDesigner = hitTestInfo.AssociatedDesigner; if (this.currentActiveDesigner != null) { ((IWorkflowDesignerMessageSink)this.currentActiveDesigner).OnMouseEnter(eventArgs); } } else { if (this.currentActiveDesigner != null) { ((IWorkflowDesignerMessageSink)this.currentActiveDesigner).OnMouseMove(eventArgs); } } return(false); }
private void EndEditing(Nullable <Point> editPoint) { WorkflowView workflowView = ParentView; if (workflowView == null) { return; } if (EditingInProgress) { if (editPoint != null) { ConnectionPoint[] snapableConnectionPoints = null; if (this.connectorEditor.EditedConectionPoint != null) { ConnectionPoint sourceConnectionPoint = this.connectorEditor.EditedConnector.Source == this.connectorEditor.EditedConectionPoint ? this.connectorEditor.EditedConnector.Target : this.connectorEditor.EditedConnector.Source; snapableConnectionPoints = GetSnappableConnectionPoints(editPoint.Value, sourceConnectionPoint, this.connectorEditor.EditedConectionPoint, MessageHitTestContext.AssociatedDesigner, out this.snappedConnectionPoint); } if (SnappedConnectionPoint != null) { editPoint = SnappedConnectionPoint.Location; } } this.connectorEditor.OnEndEditing((editPoint != null) ? editPoint.Value : Point.Empty, (editPoint != null)); } this.initialDragPoint = null; this.dragPointHitInfo = null; this.snappedConnectionPoint = null; ConnectablePoints = null; workflowView.Capture = false; this.connectorEditor = null; }
public override HitTestInfo HitTest(Point point) { if (ActiveDesigner != this) { return(base.HitTest(point)); } HitTestInfo hitInfo = HitTestInfo.Nowhere; if (!Expanded) { hitInfo = base.HitTest(point); } else if (ContainedDesigners.Count == 0 && HelpTextRectangle.Contains(point)) { hitInfo = new ConnectorHitTestInfo(this, HitTestLocations.Designer, 0); } else { //Check if the hit is on any of the connectors Rectangle[] connectors = GetConnectors(); for (int i = 0; i < connectors.Length; i++) { if (connectors[i].Contains(point)) { hitInfo = new ConnectorHitTestInfo(this, HitTestLocations.Designer, i); break; } } if (hitInfo.HitLocation == HitTestLocations.None) { hitInfo = base.HitTest(point); } } return(hitInfo); }
public override bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection <Activity> activitiesToInsert) { if (insertLocation == null) { throw new ArgumentNullException("insertLocation"); } if (activitiesToInsert == null) { throw new ArgumentNullException("activitiesToInsert"); } ActivityDesigner hostedDesigner = (ActiveView != null) ? ActiveView.AssociatedDesigner : null; if (hostedDesigner != this) { return(false); } IList <Type> secondaryViewTypes = SecondaryViewProvider.GetActivityTypes(this); foreach (Activity activity in activitiesToInsert) { if (activity == null) { throw new ArgumentException("activitiesToInsert", SR.GetString(SR.Error_CollectionHasNullEntry)); } if (secondaryViewTypes.Contains(activity.GetType())) { return(false); } } return(base.CanInsertActivities(GetUpdatedLocation(insertLocation), activitiesToInsert)); }
internal bool IsValidDropContext(HitTestInfo dropLocation) { if (this.draggedActivities.Count == 0) return false; if (dropLocation == null || dropLocation.AssociatedDesigner == null) return false; CompositeActivityDesigner compositeDesigner = dropLocation.AssociatedDesigner as CompositeActivityDesigner; if (compositeDesigner == null) return false; if (!compositeDesigner.IsEditable || !compositeDesigner.CanInsertActivities(dropLocation, new List<Activity>(this.draggedActivities).AsReadOnly())) return false; if (!this.wasCtrlKeyPressed && this.existingDraggedActivities.Count > 0) { //We are trying to move the actvities with designer if (!DesignerHelpers.AreAssociatedDesignersMovable(this.draggedActivities)) return false; if (IsRecursiveDropOperation(dropLocation.AssociatedDesigner)) return false; IDictionary commonParentActivities = Helpers.PairUpCommonParentActivities(this.draggedActivities); foreach (DictionaryEntry entry in commonParentActivities) { CompositeActivityDesigner compositeActivityDesigner = ActivityDesigner.GetDesigner(entry.Key as Activity) as CompositeActivityDesigner; Activity[] activitiesToMove = (Activity[])((ArrayList)entry.Value).ToArray(typeof(Activity)); if (compositeActivityDesigner != null && !compositeActivityDesigner.CanMoveActivities(dropLocation, new List<Activity>(activitiesToMove).AsReadOnly())) return false; } } return true; }
/// <summary> /// Inserts activities in specified composite activity designer by creating transaction /// </summary> /// <param name="compositeActivityDesigner">Designer in which to insert the activities</param> /// <param name="insertLocation">Insertion location</param> /// <param name="activitiesToInsert">Array of activities to insert</param> /// <param name="undoTransactionDescription">Text for the designer transaction which will be created</param> public static void InsertActivities(CompositeActivityDesigner compositeActivityDesigner, HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert, string undoTransactionDescription) { if (compositeActivityDesigner == null) throw new ArgumentNullException("compositeActivityDesigner"); if (compositeActivityDesigner.Activity == null || compositeActivityDesigner.Activity.Site == null || !(compositeActivityDesigner.Activity is CompositeActivity)) throw new ArgumentException("compositeActivityDesigner"); if (insertLocation == null) throw new ArgumentNullException("insertLocation"); if (activitiesToInsert == null) throw new ArgumentNullException("activitiesToInsert"); ISite site = compositeActivityDesigner.Activity.Site; // now insert the actual activities IDesignerHost designerHost = site.GetService(typeof(IDesignerHost)) as IDesignerHost; DesignerTransaction trans = null; if (designerHost != null && !string.IsNullOrEmpty(undoTransactionDescription)) trans = designerHost.CreateTransaction(undoTransactionDescription); bool moveCase = false; try { //Detect if the activities are being moved or inserted foreach (Activity activity in activitiesToInsert) { if (activity == null) throw new ArgumentException("activitiesToInsert", SR.GetString(SR.Error_CollectionHasNullEntry)); moveCase = ((IComponent)activity).Site != null; break; } //We purposely create a new instance of activities list so that we do not modify the original one if (moveCase) compositeActivityDesigner.MoveActivities(insertLocation, activitiesToInsert); else compositeActivityDesigner.InsertActivities(insertLocation, activitiesToInsert); if (trans != null) trans.Commit(); } catch (Exception e) { if (trans != null) trans.Cancel(); throw e; } //If we are just moving the activities then we do not need to emit the class //for scopes; only when we are adding the activities the class needs to be emitted for //scope in code beside file if (!moveCase) { // if everything was successful then generate classes correposnding to new scopes // get all the activities underneath the child activities ArrayList allActivities = new ArrayList(); foreach (Activity activity in activitiesToInsert) { allActivities.Add(activity); if (activity is CompositeActivity) allActivities.AddRange(Helpers.GetNestedActivities((CompositeActivity)activity)); } } }
public override HitTestInfo HitTest(Point point) { HitTestInfo hitInfo = HitTestInfo.Nowhere; if (ExpandButtonRectangle.Contains(point)) { hitInfo = new HitTestInfo(this, HitTestLocations.Designer | HitTestLocations.ActionArea); } else if (Expanded && Bounds.Contains(point)) { //First check if any of our children are hit. ReadOnlyCollection<ActivityDesigner> containedDesigners = ContainedDesigners; for (int i = containedDesigners.Count - 1; i >= 0; i--) { ActivityDesigner activityDesigner = containedDesigners[i] as ActivityDesigner; if (activityDesigner != null && activityDesigner.IsVisible) { hitInfo = activityDesigner.HitTest(point); if (hitInfo.HitLocation != HitTestLocations.None) break; } } } //If no children are hit then call base class's hittest if (hitInfo == HitTestInfo.Nowhere) hitInfo = base.HitTest(point); //This is to create default hittest info in case the drawing state is invalid if (hitInfo.AssociatedDesigner != null && hitInfo.AssociatedDesigner.DrawingState != DrawingStates.Valid) hitInfo = new HitTestInfo(hitInfo.AssociatedDesigner, HitTestLocations.Designer | HitTestLocations.ActionArea); return hitInfo; }
/// <summary> /// Allows detection of the area hit on the designer. /// </summary> /// <param name="point">Point to test in logical coordinates.</param> /// <returns>Information indicating where the hit happened</returns> public virtual HitTestInfo HitTest(Point point) { HitTestInfo hitInfo = HitTestInfo.Nowhere; if (ParentDesigner is FreeformActivityDesigner || (ParentDesigner == null && this is FreeformActivityDesigner)) { //Check if the hit is on connection ReadOnlyCollection<ConnectionPoint> connectionPoints = GetConnectionPoints(DesignerEdges.All); for (int j = 0; j < connectionPoints.Count; j++) { if (connectionPoints[j].Bounds.Contains(point)) { hitInfo = new ConnectionPointHitTestInfo(connectionPoints[j]); break; } } } Rectangle bounds = Bounds; if (bounds.Contains(point) && hitInfo == HitTestInfo.Nowhere) { HitTestLocations flags = (bounds.Contains(point)) ? HitTestLocations.Designer : HitTestLocations.None; Rectangle hitRectangle = new Rectangle(bounds.Left, bounds.Top, bounds.Left - bounds.Left, bounds.Height); flags |= (hitRectangle.Contains(point)) ? HitTestLocations.Left : flags; hitRectangle = new Rectangle(bounds.Left, bounds.Top, bounds.Width, bounds.Height - bounds.Height); flags |= (hitRectangle.Contains(point)) ? HitTestLocations.Top : flags; hitRectangle = new Rectangle(bounds.Right, bounds.Top, bounds.Width - bounds.Width, bounds.Height); flags |= (hitRectangle.Contains(point)) ? HitTestLocations.Right : flags; hitRectangle = new Rectangle(bounds.Left, bounds.Bottom, bounds.Width, bounds.Bottom - bounds.Bottom); flags |= (hitRectangle.Contains(point)) ? HitTestLocations.Bottom : flags; hitInfo = new HitTestInfo(this, flags); } return hitInfo; }
private void EndEditing(Nullable<Point> editPoint) { WorkflowView workflowView = ParentView; if (workflowView == null) return; if (EditingInProgress) { if (editPoint != null) { ConnectionPoint[] snapableConnectionPoints = null; if (this.connectorEditor.EditedConectionPoint != null) { ConnectionPoint sourceConnectionPoint = this.connectorEditor.EditedConnector.Source == this.connectorEditor.EditedConectionPoint ? this.connectorEditor.EditedConnector.Target : this.connectorEditor.EditedConnector.Source; snapableConnectionPoints = GetSnappableConnectionPoints(editPoint.Value, sourceConnectionPoint, this.connectorEditor.EditedConectionPoint, MessageHitTestContext.AssociatedDesigner, out this.snappedConnectionPoint); } if (SnappedConnectionPoint != null) editPoint = SnappedConnectionPoint.Location; } this.connectorEditor.OnEndEditing((editPoint != null) ? editPoint.Value : Point.Empty, (editPoint != null)); } this.initialDragPoint = null; this.dragPointHitInfo = null; this.snappedConnectionPoint = null; ConnectablePoints = null; workflowView.Capture = false; this.connectorEditor = null; }
public override bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert) { if (insertLocation == null) throw new ArgumentNullException("insertLocation"); if (activitiesToInsert == null) throw new ArgumentNullException("activitiesToInsert"); ActivityDesigner hostedDesigner = (ActiveView != null) ? ActiveView.AssociatedDesigner : null; if (hostedDesigner != this) return false; IList<Type> secondaryViewTypes = SecondaryViewProvider.GetActivityTypes(this); foreach (Activity activity in activitiesToInsert) { if (activity == null) throw new ArgumentException("activitiesToInsert", SR.GetString(SR.Error_CollectionHasNullEntry)); if (secondaryViewTypes.Contains(activity.GetType())) return false; } return base.CanInsertActivities(GetUpdatedLocation(insertLocation), activitiesToInsert); }
public override HitTestInfo HitTest(Point point) { HitTestInfo hitInfo = HitTestInfo.Nowhere; if (this.Bounds.Contains(point)) { hitInfo = new HitTestInfo(this.ActivityDesigner, HitTestLocations.Designer | HitTestLocations.ActionArea); } return hitInfo; }
/// <summary> /// Checks if the activities can be moved out from the composite activity associated with designer /// </summary> /// <param name="moveLocation">Location from which to move the activities</param> /// <param name="activitiesToMove">Array of activities to move</param> /// <returns></returns> public virtual bool CanMoveActivities(HitTestInfo moveLocation, ReadOnlyCollection<Activity> activitiesToMove) { if (moveLocation == null) throw new ArgumentNullException("moveLocation"); if (activitiesToMove == null) throw new ArgumentNullException("activitiesToMove"); //If the activity has locked structure then we do not allow user to move the activity out if (!IsEditable) return false; //Now go through all the movable activities and check if their position is locked foreach (Activity activity in activitiesToMove) { ActivityDesigner designer = ActivityDesigner.GetDesigner(activity); if (designer == null || designer.IsLocked) return false; } return true; }
private void OnMenuPaste(object sender, EventArgs e) { object selectedObject = this.selectionService.PrimarySelection; CompositeActivityDesigner compositeDesigner = ActivityDesigner.GetDesigner(selectedObject as Activity) as CompositeActivityDesigner; if (compositeDesigner == null) compositeDesigner = ActivityDesigner.GetParentDesigner(selectedObject); if (compositeDesigner == null || !compositeDesigner.IsEditable) return; // deserialize activities IDataObject dataObj = Clipboard.GetDataObject(); ICollection components = null; try { components = CompositeActivityDesigner.DeserializeActivitiesFromDataObject(this.serviceProvider, dataObj, true); } catch (Exception ex) { if (ex != CheckoutException.Canceled) throw new Exception(DR.GetString(DR.ActivityInsertError) + "\n" + ex.Message, ex); } if (components == null) throw new InvalidOperationException(DR.GetString(DR.InvalidOperationBadClipboardFormat)); // get the drop target HitTestInfo hitInfo = null; if (selectedObject is HitTestInfo) { hitInfo = (HitTestInfo)selectedObject; } else if (selectedObject is CompositeActivity) { hitInfo = new HitTestInfo(compositeDesigner, HitTestLocations.Designer); } else if (selectedObject is Activity) { Activity selectedActivity = selectedObject as Activity; CompositeActivity parentActivity = selectedActivity.Parent; CompositeActivityDesigner parentDesigner = ActivityDesigner.GetDesigner(parentActivity) as CompositeActivityDesigner; if (parentDesigner != null) hitInfo = new ConnectorHitTestInfo(parentDesigner, HitTestLocations.Designer, parentActivity.Activities.IndexOf(selectedActivity) + 1); } List<Activity> topLevelActivities = new List<Activity>(Helpers.GetTopLevelActivities(components)); // check if we can insert or not // I know I should have disabled the paste menu it-self, but doing status check for paste gives a big performance hit. I am working on it. if (hitInfo == null || !compositeDesigner.CanInsertActivities(hitInfo, topLevelActivities.AsReadOnly())) throw new Exception(SR.GetString(SR.Error_NoPasteSupport)); // Make sure the project has references to all inserted activities (in the case // where an activity is copied from another project IExtendedUIService extendedUIService = this.serviceProvider.GetService(typeof(IExtendedUIService)) as IExtendedUIService; if (extendedUIService != null) { foreach (Activity pastedActivity in components) extendedUIService.AddAssemblyReference(pastedActivity.GetType().Assembly.GetName()); } CompositeActivityDesigner.InsertActivities(compositeDesigner, hitInfo, topLevelActivities.AsReadOnly(), SR.GetString(SR.PastingActivities)); Stream componentStateStream = dataObj.GetData(CF_DESIGNERSTATE) as Stream; if (componentStateStream != null) Helpers.DeserializeDesignersFromStream(components, componentStateStream); // set something on selections service this.selectionService.SetSelectedComponents(topLevelActivities.ToArray(), SelectionTypes.Replace); this.workflowView.EnsureVisible(this.selectionService.PrimarySelection); }
private void OnStatusPaste(object sender, EventArgs e) { MenuCommand cmd = (MenuCommand)sender; cmd.Enabled = false; //Check if we are in writtable context object selectedObject = this.selectionService.PrimarySelection; CompositeActivityDesigner compositeDesigner = ActivityDesigner.GetDesigner(selectedObject as Activity) as CompositeActivityDesigner; if (compositeDesigner == null) compositeDesigner = ActivityDesigner.GetParentDesigner(selectedObject); if (compositeDesigner == null || !compositeDesigner.IsEditable) return; //Check if data object format is valid IDesignerHost designerHost = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost; IToolboxService ts = (IToolboxService)this.serviceProvider.GetService(typeof(IToolboxService)); IDataObject dataObj = Clipboard.GetDataObject(); if (dataObj == null || designerHost == null || (!dataObj.GetDataPresent(CF_DESIGNER) && (ts != null && !ts.IsSupported(dataObj, designerHost)))) return; //Get the drop target and check if it is valid HitTestInfo hitInfo = null; if (selectedObject is HitTestInfo) { hitInfo = (HitTestInfo)selectedObject; } else if (selectedObject is CompositeActivity) { hitInfo = new HitTestInfo(compositeDesigner, HitTestLocations.Designer); } else if (selectedObject is Activity) { Activity selectedActivity = selectedObject as Activity; CompositeActivity parentActivity = selectedActivity.Parent; CompositeActivityDesigner parentDesigner = ActivityDesigner.GetDesigner(parentActivity) as CompositeActivityDesigner; if (parentDesigner != null) hitInfo = new ConnectorHitTestInfo(parentDesigner, HitTestLocations.Designer, parentActivity.Activities.IndexOf(selectedActivity) + 1); } //Deserialize activities ICollection components = null; try { components = CompositeActivityDesigner.DeserializeActivitiesFromDataObject(this.serviceProvider, dataObj); } catch (CheckoutException ex) { if (ex != CheckoutException.Canceled) throw ex; } cmd.Enabled = (components != null && hitInfo != null && compositeDesigner.CanInsertActivities(hitInfo, new List<Activity>(Helpers.GetTopLevelActivities(components)).AsReadOnly())); }
public override void MoveActivities(HitTestInfo moveLocation, ReadOnlyCollection<Activity> activitiesToMove) { if (moveLocation == null) throw new ArgumentNullException("moveLocation"); if (activitiesToMove == null) throw new ArgumentNullException("activitiesToMove"); base.MoveActivities(GetUpdatedLocation(moveLocation), activitiesToMove); }
protected override bool OnMouseDown(MouseEventArgs eventArgs) { Point clientPoint = new Point(eventArgs.X, eventArgs.Y); //If the point is not in clickable area then return WorkflowView parentView = ParentView; if (!parentView.IsClientPointInActiveLayout(clientPoint)) { return(true); } //Check if the mouse is hit on designer object selectedObject = null; HitTestInfo hitTestInfo = MessageHitTestContext; if (hitTestInfo == HitTestInfo.Nowhere) { selectedObject = parentView.RootDesigner.Activity; } else { selectedObject = hitTestInfo.SelectableObject; } //Selection service handles KeyModifiers, ctrl and shift will be handled as per the standard behavior if (selectedObject != null) { ISelectionService selectionService = GetService(typeof(ISelectionService)) as ISelectionService; if (selectionService != null) { selectionService.SetSelectedComponents(new object[] { selectedObject }, SelectionTypes.Primary); } } //Designer designates an area as action area if there is some special significance associated with the area ie Expand Collapse //In such cases we give activity designer an oppertunity to take action when mouse click happens on the area //if there are Ctrl or Shift keys pressed, only do the selection change, dont call the child designer //Now that the designer is selected if (this.currentActiveDesigner != hitTestInfo.AssociatedDesigner) { if (this.currentActiveDesigner != null) { ((IWorkflowDesignerMessageSink)this.currentActiveDesigner).OnMouseLeave(); } this.currentActiveDesigner = hitTestInfo.AssociatedDesigner; if (this.currentActiveDesigner != null) { ((IWorkflowDesignerMessageSink)this.currentActiveDesigner).OnMouseEnter(eventArgs); } } if (this.currentActiveDesigner != null && ((Control.ModifierKeys & (Keys.Control | Keys.Shift)) == 0)) { ((IWorkflowDesignerMessageSink)this.currentActiveDesigner).OnMouseDown(eventArgs); } return(false); }
public override bool CanMoveActivities(HitTestInfo moveLocation, ReadOnlyCollection<Activity> activitiesToMove) { return true; }
/// <summary> /// Checks if the activities can be inserted into the composite activity associated with the designer /// </summary> /// <param name="insertLocation">Location at which to insert activities</param> /// <param name="activitiesToInsert">Array of activities to be inserted</param> /// <returns>True of activities can be inserted, false otherwise</returns> public virtual bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert) { if (insertLocation == null) throw new ArgumentNullException("insertLocation"); if (activitiesToInsert == null) throw new ArgumentNullException("activitiesToInsert"); CompositeActivity compositeActivity = Activity as CompositeActivity; if (compositeActivity == null) return false; //If the activity state is locked then we can not insert activities. if (!IsEditable) return false; IExtendedUIService2 extendedUIService = this.GetService(typeof(IExtendedUIService2)) as IExtendedUIService2; foreach (Activity activity in activitiesToInsert) { if (activity == null) throw new ArgumentException("activitiesToInsert", SR.GetString(SR.Error_CollectionHasNullEntry)); if (extendedUIService != null) { if (!extendedUIService.IsSupportedType(activity.GetType())) { return false; } } if (activity is CompositeActivity && Helpers.IsAlternateFlowActivity(activity)) return false; ActivityDesigner designerToInsert = null; #pragma warning disable 56506// if (activity.Site != null) { //get an existing designer IDesignerHost designerHost = activity.Site.GetService(typeof(IDesignerHost)) as IDesignerHost; designerToInsert = (designerHost != null) ? designerHost.GetDesigner((IComponent)activity) as ActivityDesigner : null; } else { //we dont want to create a designer instance every time, so we'll cache it //this is a fix for a perf issue - this function gets called in a loop when doing drag'n'drop operation //from a toolbox if (activity.UserData.Contains(typeof(ActivityDesigner))) { designerToInsert = activity.UserData[typeof(ActivityDesigner)] as ActivityDesigner; } else { //create a new one designerToInsert = ActivityDesigner.CreateDesigner(Activity.Site, activity); activity.UserData[typeof(ActivityDesigner)] = designerToInsert; } } #pragma warning restore 56506// if (designerToInsert == null) return false; if (!designerToInsert.CanBeParentedTo(this)) return false; } 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); }
/// <summary> /// Inserts activity at specified location within designer /// </summary> /// <param name="insertLocation">Location at which to insert activities</param> /// <param name="activitiesToInsert">Array of activities to insert</param> public virtual void InsertActivities(HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert) { if (insertLocation == null) throw new ArgumentNullException("insertLocation"); if (activitiesToInsert == null) throw new ArgumentNullException("activitiesToInsert"); CompositeActivity compositeActivity = Activity as CompositeActivity; if (compositeActivity == null) throw new Exception(SR.GetString(SR.Error_DragDropInvalid)); int index = insertLocation.MapToIndex(); IIdentifierCreationService identifierCreationService = GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService; if (identifierCreationService != null) identifierCreationService.EnsureUniqueIdentifiers(compositeActivity, activitiesToInsert); else throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(IIdentifierCreationService).FullName)); foreach (Activity activity in activitiesToInsert) { if (activity == null) throw new ArgumentException("activitiesToInsert", SR.GetString(SR.Error_CollectionHasNullEntry)); if (activity.Parent == null) { compositeActivity.Activities.Insert(index++, activity); WorkflowDesignerLoader.AddActivityToDesigner(Activity.Site, activity); } } // filter out unsupported Dependency properties foreach (Activity activity in activitiesToInsert) { Walker walker = new Walker(); walker.FoundActivity += delegate(Walker w, WalkerEventArgs walkerEventArgs) { ExtenderHelpers.FilterDependencyProperties(this.Activity.Site, walkerEventArgs.CurrentActivity); }; walker.Walk(activity); } }
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); }
/// <summary> /// Moves activities from one designer to other /// </summary> /// <param name="moveLocation">Location at which to move the activities</param> /// <param name="activitiesToMove">Array of activities to move</param> public virtual void MoveActivities(HitTestInfo moveLocation, ReadOnlyCollection<Activity> activitiesToMove) { if (moveLocation == null) throw new ArgumentNullException("moveLocation"); if (activitiesToMove == null) throw new ArgumentNullException("activitiesToMove"); //Make sure that we get the composite activity CompositeActivity compositeActivity = Activity as CompositeActivity; if (compositeActivity == null) throw new Exception(SR.GetString(SR.Error_DragDropInvalid)); IIdentifierCreationService identifierCreationService = GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService; if (identifierCreationService == null) throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(IIdentifierCreationService).FullName)); IDesignerHost designerHost = GetService(typeof(IDesignerHost)) as IDesignerHost; if (designerHost == null) throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(IDesignerHost).FullName)); int index = moveLocation.MapToIndex(); foreach (Activity activity in activitiesToMove) { ActivityDesigner designer = ActivityDesigner.GetDesigner(activity); if (designer != null) { CompositeActivityDesigner parentDesigner = designer.ParentDesigner; if (parentDesigner == this) { int originalIndex = compositeActivity.Activities.IndexOf(activity); if (index > originalIndex) index--; } } //In some cases we might get activities which are added newly, in such cases we check if the activity //is existing activity or new one based on this decision we add it to the designer host. Debug.Assert(activity.Parent != null); CompositeActivity parentActivity = activity.Parent; int positionInParent = parentActivity.Activities.IndexOf(activity); activity.Parent.Activities.Remove(activity); //We need to make sure that the activity is going to have unique identifier //This might just cause problems identifierCreationService.EnsureUniqueIdentifiers(compositeActivity, new Activity[] { activity }); //We do not need to read the activity in the designer host as this is move operation //assign unique temporary name to avoid conflicts DesignerHelpers.UpdateSiteName(activity, "_activityonthemove_"); CompositeActivity compositeActivityMoved = activity as CompositeActivity; if (compositeActivityMoved != null) { int i = 1; foreach (Activity nestedActivity in Helpers.GetNestedActivities(compositeActivityMoved)) { DesignerHelpers.UpdateSiteName(nestedActivity, "_activityonthemove_" + i.ToString(CultureInfo.InvariantCulture)); i += 1; } } try { compositeActivity.Activities.Insert(index++, activity); } catch (Exception ex) { // reconnect the activity parentActivity.Activities.Insert(positionInParent, activity); // throw ex; } DesignerHelpers.UpdateSiteName(activity, activity.Name); if (compositeActivityMoved != null) { foreach (Activity nestedActivity in Helpers.GetNestedActivities(compositeActivityMoved)) DesignerHelpers.UpdateSiteName(nestedActivity, nestedActivity.Name); } } // filter out unsupported Dependency properties and refresh propertyDescriptors foreach (Activity activity in activitiesToMove) { Walker walker = new Walker(); walker.FoundActivity += delegate(Walker w, WalkerEventArgs walkerEventArgs) { ExtenderHelpers.FilterDependencyProperties(this.Activity.Site, walkerEventArgs.CurrentActivity); TypeDescriptor.Refresh(walkerEventArgs.CurrentActivity); }; walker.Walk(activity); } }
protected override bool OnMouseDown(MouseEventArgs eventArgs) { Point cursorPoint = Point.Empty; //Check if we can start editing if ((eventArgs.Button & MouseButtons.Left) == MouseButtons.Left) { WorkflowView workflowView = ParentView; Point clientPoint = new Point(eventArgs.X, eventArgs.Y); //If the point is not in clickable area then return if (workflowView != null && workflowView.IsClientPointInActiveLayout(clientPoint)) { Point logicalPoint = workflowView.ClientPointToLogical(clientPoint); if (CanBeginEditing(logicalPoint, MessageHitTestContext)) { this.initialDragPoint = new Point?(logicalPoint); this.dragPointHitInfo = MessageHitTestContext; } cursorPoint = logicalPoint; } } else { EndEditing(null); } //Update the cursor bool processedMessage = (this.initialDragPoint != null); processedMessage |= UpdateCursor(cursorPoint); return processedMessage; }
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); }
public override void InsertActivities(HitTestInfo insertLocation, ReadOnlyCollection <Activity> activitiesToInsert) { }
public override bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection <Activity> activitiesToInsert) { return(false); }
void IToolboxUser.ToolPicked(ToolboxItem toolboxItem) { ISelectionService selectionService = GetService(typeof(ISelectionService)) as ISelectionService; IToolboxService toolboxService = GetService(typeof(IToolboxService)) as IToolboxService; if (toolboxItem == null || selectionService == null) return; object selectedObject = selectionService.PrimarySelection; if (!(selectedObject is HitTestInfo) && !(selectedObject is CompositeActivity)) return; //Get the paste target HitTestInfo hitInfo = null; CompositeActivity compositeActivity = null; if (selectedObject is HitTestInfo) { hitInfo = (HitTestInfo)selectedObject; compositeActivity = hitInfo.AssociatedDesigner.Activity as CompositeActivity; } else if (selectedObject is CompositeActivity) { compositeActivity = (CompositeActivity)selectedObject; hitInfo = new HitTestInfo(ActivityDesigner.GetDesigner(compositeActivity), HitTestLocations.Designer); } //Get the parent designer for pasting CompositeActivityDesigner compositeActivityDesigner = ActivityDesigner.GetDesigner(compositeActivity) as CompositeActivityDesigner; if (compositeActivityDesigner == null) return; Activity[] activities = CompositeActivityDesigner.DeserializeActivitiesFromToolboxItem(Activity.Site, toolboxItem, false); if (activities.Length == 0) return; if (!compositeActivityDesigner.CanInsertActivities(hitInfo, new List<Activity>(activities).AsReadOnly())) return; try { activities = CompositeActivityDesigner.DeserializeActivitiesFromToolboxItem(Activity.Site, toolboxItem, true); if (activities.Length > 0) { CompositeActivityDesigner.InsertActivities(compositeActivityDesigner, hitInfo, new List<Activity>(activities).AsReadOnly(), SR.GetString(SR.PastingActivities)); selectionService.SetSelectedComponents(activities, SelectionTypes.Replace); ParentView.EnsureVisible(activities[0]); } } catch (CheckoutException ex) { if (ex != CheckoutException.Canceled) throw new Exception(DR.GetString(DR.ActivityInsertError) + "\n" + ex.Message, ex); } }
public override void InsertActivities(HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert) { if (insertLocation == null) throw new ArgumentNullException("insertLocation"); if (activitiesToInsert == null) throw new ArgumentNullException("activitiesToInsert"); base.InsertActivities(GetUpdatedLocation(insertLocation), activitiesToInsert); }
private bool CanBeginEditing(Point editPoint, HitTestInfo messageContext) { ISelectionService selectionService = GetService(typeof(ISelectionService)) as ISelectionService; if (selectionService != null) { Connector selectedConnector = Connector.GetConnectorFromSelectedObject(selectionService.PrimarySelection); if (selectedConnector != null && selectedConnector.ParentDesigner.EnableUserDrawnConnectors && new ConnectorEditor(selectedConnector).HitTest(editPoint)) return true; } ConnectionPointHitTestInfo connectionPointHitTestInfo = messageContext as ConnectionPointHitTestInfo; if (connectionPointHitTestInfo != null && connectionPointHitTestInfo.ConnectionPoint != null) { FreeformActivityDesigner connectorContainer = ConnectionManager.GetConnectorContainer(connectionPointHitTestInfo.AssociatedDesigner); if (connectorContainer != null && connectorContainer.EnableUserDrawnConnectors) return true; } return false; }
private HitTestInfo GetUpdatedLocation(HitTestInfo location) { int lockedActivityOffset = 0; foreach (DesignerView secondaryView in Views) { if (secondaryView.AssociatedDesigner != null && this != secondaryView.AssociatedDesigner && Helpers.IsActivityLocked(secondaryView.AssociatedDesigner.Activity)) { lockedActivityOffset++; } } return new ConnectorHitTestInfo(this, location.HitLocation, lockedActivityOffset + location.MapToIndex()); }
public WorkflowMessageDispatchData(WorkflowView workflowView, EventArgs e) { this.workflowView = workflowView; if (this.workflowView.RootDesigner != null && this.workflowView.stockMessageFilters.Count > 0) { Point clientPoint = Point.Empty; if (e is MouseEventArgs || e is DragEventArgs) { if (e is MouseEventArgs) { clientPoint = new Point(((MouseEventArgs)e).X, ((MouseEventArgs)e).Y); } else if (e is DragEventArgs) { clientPoint = this.workflowView.PointToClient(new Point(((DragEventArgs)e).X, ((DragEventArgs)e).Y)); this.workflowView.UpdateLayout(); } Point logicalPoint = this.workflowView.ClientPointToLogical(clientPoint); HitTestInfo hitTestInfo = this.workflowView.RootDesigner.HitTest(logicalPoint); this.messageContext = (hitTestInfo != null) ? hitTestInfo : HitTestInfo.Nowhere; this.workflowView.messageHitTestContexts.Push(this.messageContext); } } }