Пример #1
0
        protected override void OnDragDrop(ActivityDragEventArgs e)
        {
            base.OnDragDrop(e);

            bool ctrlKeyPressed = ((e.KeyState & 8) == 8);

            if (ctrlKeyPressed && (e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
            {
                e.Effect = DragDropEffects.Copy;
            }
            else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
            {
                e.Effect = DragDropEffects.Move;
            }

            //If the component is sited then that means that we are moving it
            try
            {
                CompositeActivityDesigner.InsertActivities(this, new ConnectorHitTestInfo(this, HitTestLocations.Designer, CurrentDropTarget), e.Activities, SR.GetString(SR.DragDropActivities));
            }
            finally
            {
                CurrentDropTarget = -1;
            }
        }
 protected override void OnDragOver(ActivityDragEventArgs e)
 {
     base.OnDragOver(e);
     this.CurrentDropTarget = this.CanDrop(e);
     e.Effect             = this.CheckDragEffect(e);
     e.DragImageSnapPoint = this.SnapInToDropTarget(e);
 }
 protected override void OnDragOver(ActivityDragEventArgs e)
 {
     if (((e.KeyState & 8) == 8) && ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy))
     {
         e.Effect = DragDropEffects.Copy;
     }
     else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
     {
         e.Effect = DragDropEffects.Move;
     }
 }
 private Point SnapInToDropTarget(ActivityDragEventArgs e)
 {
     if (this.CurrentDropTarget >= 0)
     {
         Rectangle[] dropTargets = this.GetDropTargets(new Point(e.X, e.Y));
         if (this.CurrentDropTarget < dropTargets.Length)
         {
             Rectangle rectangle = dropTargets[this.CurrentDropTarget];
             return(new Point(rectangle.Left + (rectangle.Width / 2), rectangle.Top + (rectangle.Height / 2)));
         }
     }
     return(Point.Empty);
 }
Пример #5
0
        private Point SnapInToDropTarget(ActivityDragEventArgs e)
        {
            if (CurrentDropTarget >= 0)
            {
                Rectangle[] dropTargets = GetDropTargets(new Point(e.X, e.Y));
                if (CurrentDropTarget < dropTargets.Length)
                {
                    Rectangle dropConnector = dropTargets[CurrentDropTarget];
                    return(new Point(dropConnector.Left + dropConnector.Width / 2, dropConnector.Top + dropConnector.Height / 2));
                }
            }

            return(Point.Empty);
        }
Пример #6
0
        private Point SnapInToPreviewStripDropTarget(ActivityDragEventArgs e)
        {
            int activeDropTarget = this.previewStrip.ActiveDropTarget;

            Rectangle[] dropTargets = this.previewStrip.DropTargets;
            if ((activeDropTarget < 0) || (activeDropTarget >= dropTargets.Length))
            {
                return(Point.Empty);
            }
            Rectangle rectangle = dropTargets[activeDropTarget];
            ActivityPreviewDesignerTheme designerTheme = base.DesignerTheme as ActivityPreviewDesignerTheme;

            rectangle.Width = (rectangle.Width > ((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0)) ? ((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0) : rectangle.Width;
            return(new Point(rectangle.Left + (rectangle.Width / 2), rectangle.Top + (rectangle.Height / 2)));
        }
Пример #7
0
        private Point SnapInToPreviewStripDropTarget(ActivityDragEventArgs e)
        {
            int activeDropTarget = this.previewStrip.ActiveDropTarget;

            Rectangle[] dropTargets = this.previewStrip.DropTargets;

            if (activeDropTarget < 0 || activeDropTarget >= dropTargets.Length)
            {
                return(Point.Empty);
            }

            Rectangle dropConnector = dropTargets[activeDropTarget];
            ActivityPreviewDesignerTheme designerTheme = DesignerTheme as ActivityPreviewDesignerTheme;

            dropConnector.Width = (dropConnector.Width > ((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0)) ? ((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0) : dropConnector.Width;
            return(new Point(dropConnector.Left + dropConnector.Width / 2, dropConnector.Top + dropConnector.Height / 2));
        }
Пример #8
0
        private int CanDrop(ActivityDragEventArgs e)
        {
            if (e.Activities.Count == 0)
            {
                return(-1);
            }

            Point dropPoint = new Point(e.X, e.Y);
            int   dropIndex = -1;

            Rectangle[] dropTargets = GetDropTargets(dropPoint);
            for (int i = 0; i < dropTargets.Length; i++)
            {
                if (dropTargets[i].Contains(dropPoint))
                {
                    dropIndex = i;
                    break;
                }
            }

            if (dropIndex >= 0 && !CanInsertActivities(new ConnectorHitTestInfo(this, HitTestLocations.Designer, dropIndex), e.Activities))
            {
                dropIndex = -1;
            }

            bool ctrlKeyPressed = ((e.KeyState & 8) == 8);

            if (dropIndex >= 0 && !ctrlKeyPressed && (e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
            {
                ConnectorHitTestInfo moveLocation = new ConnectorHitTestInfo(this, HitTestLocations.Designer, dropIndex);
                foreach (Activity activity in e.Activities)
                {
                    if (activity.Site != null)
                    {
                        ActivityDesigner activityDesigner = ActivityDesigner.GetDesigner(activity);
                        if (activityDesigner == null || activityDesigner.ParentDesigner == null || !activityDesigner.ParentDesigner.CanMoveActivities(moveLocation, new List <Activity>(new Activity[] { activity }).AsReadOnly()))
                        {
                            dropIndex = -1;
                            break;
                        }
                    }
                }
            }

            return(dropIndex);
        }
        protected override void OnDragDrop(ActivityDragEventArgs e)
        {
            if (((e.KeyState & 8) == 8) && ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy))
            {
                e.Effect = DragDropEffects.Copy;
            }
            else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
            {
                e.Effect = DragDropEffects.Move;
            }
            List <Activity> list  = new List <Activity>();
            List <Activity> list2 = new List <Activity>();

            foreach (Activity activity in e.Activities)
            {
                if ((activity.Site == null) || (activity.Parent != base.Activity))
                {
                    list.Add(activity);
                }
                if (activity.Site == null)
                {
                    list2.Add(activity);
                }
            }
            if (list.Count > 0)
            {
                CompositeActivityDesigner.InsertActivities(this, new ConnectorHitTestInfo(this, HitTestLocations.Designer, ((CompositeActivity)base.Activity).Activities.Count), list.AsReadOnly(), SR.GetString("DragDropActivities"));
            }
            Point endPoint = new Point(e.X, e.Y);

            Point[] pointArray = FreeFormDragDropManager.GetDesignerLocations(e.DragInitiationPoint, endPoint, e.Activities);
            if (pointArray.Length == e.Activities.Count)
            {
                for (int i = 0; i < e.Activities.Count; i++)
                {
                    ActivityDesigner containedDesigner = ActivityDesigner.GetDesigner(e.Activities[i]);
                    if (containedDesigner != null)
                    {
                        Point newLocation = list2.Contains(containedDesigner.Activity) ? endPoint : pointArray[i];
                        this.MoveContainedDesigner(containedDesigner, newLocation);
                    }
                }
            }
        }
 private DragDropEffects CheckDragEffect(ActivityDragEventArgs e)
 {
     if (e.Activities.Count == 0)
     {
         return(DragDropEffects.None);
     }
     if (this.CurrentDropTarget >= 0)
     {
         if (((e.KeyState & 8) == 8) && ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy))
         {
             return(DragDropEffects.Copy);
         }
         if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
         {
             return(DragDropEffects.Move);
         }
     }
     return(e.Effect);
 }
 protected override void OnDragDrop(ActivityDragEventArgs e)
 {
     base.OnDragDrop(e);
     if (((e.KeyState & 8) == 8) && ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy))
     {
         e.Effect = DragDropEffects.Copy;
     }
     else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
     {
         e.Effect = DragDropEffects.Move;
     }
     try
     {
         CompositeActivityDesigner.InsertActivities(this, new ConnectorHitTestInfo(this, HitTestLocations.Designer, this.CurrentDropTarget), e.Activities, SR.GetString("DragDropActivities"));
     }
     finally
     {
         this.CurrentDropTarget = -1;
     }
 }
        private int CanDrop(ActivityDragEventArgs e)
        {
            if (e.Activities.Count == 0)
            {
                return(-1);
            }
            Point dropPoint = new Point(e.X, e.Y);
            int   connector = -1;

            Rectangle[] dropTargets = this.GetDropTargets(dropPoint);
            for (int i = 0; i < dropTargets.Length; i++)
            {
                if (dropTargets[i].Contains(dropPoint))
                {
                    connector = i;
                    break;
                }
            }
            if ((connector >= 0) && !this.CanInsertActivities(new ConnectorHitTestInfo(this, HitTestLocations.Designer, connector), e.Activities))
            {
                connector = -1;
            }
            bool flag = (e.KeyState & 8) == 8;

            if (((connector >= 0) && !flag) && ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move))
            {
                ConnectorHitTestInfo moveLocation = new ConnectorHitTestInfo(this, HitTestLocations.Designer, connector);
                foreach (Activity activity in e.Activities)
                {
                    if (activity.Site != null)
                    {
                        ActivityDesigner designer = ActivityDesigner.GetDesigner(activity);
                        if (((designer == null) || (designer.ParentDesigner == null)) || !designer.ParentDesigner.CanMoveActivities(moveLocation, new List <Activity>(new Activity[] { activity }).AsReadOnly()))
                        {
                            return(-1);
                        }
                    }
                }
            }
            return(connector);
        }
Пример #13
0
        private DragDropEffects CheckDragEffect(ActivityDragEventArgs e)
        {
            if (e.Activities.Count == 0)
            {
                return(DragDropEffects.None);
            }
            else if (CurrentDropTarget >= 0)
            {
                bool ctrlKeyPressed = ((e.KeyState & 8) == 8);
                if (ctrlKeyPressed && (e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
                {
                    return(DragDropEffects.Copy);
                }
                else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
                {
                    return(DragDropEffects.Move);
                }
            }

            return(e.Effect);
        }
 private int CanDrop(ActivityDragEventArgs e)
 {
     if (e.Activities.Count == 0)
     {
         return -1;
     }
     Point dropPoint = new Point(e.X, e.Y);
     int connector = -1;
     Rectangle[] dropTargets = this.GetDropTargets(dropPoint);
     for (int i = 0; i < dropTargets.Length; i++)
     {
         if (dropTargets[i].Contains(dropPoint))
         {
             connector = i;
             break;
         }
     }
     if ((connector >= 0) && !this.CanInsertActivities(new ConnectorHitTestInfo(this, HitTestLocations.Designer, connector), e.Activities))
     {
         connector = -1;
     }
     bool flag = (e.KeyState & 8) == 8;
     if (((connector >= 0) && !flag) && ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move))
     {
         ConnectorHitTestInfo moveLocation = new ConnectorHitTestInfo(this, HitTestLocations.Designer, connector);
         foreach (Activity activity in e.Activities)
         {
             if (activity.Site != null)
             {
                 ActivityDesigner designer = ActivityDesigner.GetDesigner(activity);
                 if (((designer == null) || (designer.ParentDesigner == null)) || !designer.ParentDesigner.CanMoveActivities(moveLocation, new List<Activity>(new Activity[] { activity }).AsReadOnly()))
                 {
                     return -1;
                 }
             }
         }
     }
     return connector;
 }
Пример #15
0
        protected override void OnDragOver(ActivityDragEventArgs e)
        {
            base.OnDragOver(e);

            this.DragDropActive = CanDrop(e);
            e.Effect = CheckDragEffect(e);
            e.DragImageSnapPoint = GetDragImageSnapPoint(e);
        }
Пример #16
0
        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);
        }
 private bool CanDrop(ActivityDragEventArgs e)
 {
     if (e.Activities.Count == 0)
     {
         return false;
     }
     if (this.HasActiveDesigner)
     {
         return false;
     }
     if (!this.CanInsertActivities(new System.Workflow.ComponentModel.Design.HitTestInfo(this, HitTestLocations.Designer), e.Activities))
     {
         return false;
     }
     if (((e.KeyState & 8) != 8) && ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move))
     {
         System.Workflow.ComponentModel.Design.HitTestInfo moveLocation = new System.Workflow.ComponentModel.Design.HitTestInfo(this, HitTestLocations.Designer);
         foreach (Activity activity in e.Activities)
         {
             if (activity.Site != null)
             {
                 ActivityDesigner designer = GetDesigner(activity);
                 if (((designer == null) || (designer.ParentDesigner == null)) || !designer.ParentDesigner.CanMoveActivities(moveLocation, new List<Activity>(new Activity[] { activity }).AsReadOnly()))
                 {
                     return false;
                 }
             }
         }
     }
     return true;
 }
 protected override void OnDragOver(ActivityDragEventArgs e)
 {
     if (((e.KeyState & 8) == 8) && ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy))
     {
         e.Effect = DragDropEffects.Copy;
     }
     else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
     {
         e.Effect = DragDropEffects.Move;
     }
 }
        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);
        }
Пример #20
0
        private Point GetDragImageSnapPoint(ActivityDragEventArgs e)
        {
            Point snapPoint = new Point(e.Y, e.Y);
            if (!this.HasActiveDesigner)
            {
                int eventHandlersLayoutBottom = this._statesLayout.EventHandlersLayout.Bounds.Bottom;
                if (snapPoint.Y <= eventHandlersLayoutBottom)
                    snapPoint.Y = eventHandlersLayoutBottom + 1;
            }

            return snapPoint;
        }
 private Point SnapInToPreviewStripDropTarget(ActivityDragEventArgs e)
 {
     int activeDropTarget = this.previewStrip.ActiveDropTarget;
     Rectangle[] dropTargets = this.previewStrip.DropTargets;
     if ((activeDropTarget < 0) || (activeDropTarget >= dropTargets.Length))
     {
         return Point.Empty;
     }
     Rectangle rectangle = dropTargets[activeDropTarget];
     ActivityPreviewDesignerTheme designerTheme = base.DesignerTheme as ActivityPreviewDesignerTheme;
     rectangle.Width = (rectangle.Width > ((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0)) ? ((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0) : rectangle.Width;
     return new Point(rectangle.Left + (rectangle.Width / 2), rectangle.Top + (rectangle.Height / 2));
 }
        private Point SnapInToPreviewStripDropTarget(ActivityDragEventArgs e)
        {
            int activeDropTarget = this.previewStrip.ActiveDropTarget;
            Rectangle[] dropTargets = this.previewStrip.DropTargets;

            if (activeDropTarget < 0 || activeDropTarget >= dropTargets.Length)
                return Point.Empty;

            Rectangle dropConnector = dropTargets[activeDropTarget];
            ActivityPreviewDesignerTheme designerTheme = DesignerTheme as ActivityPreviewDesignerTheme;
            dropConnector.Width = (dropConnector.Width > ((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0)) ? ((designerTheme != null) ? designerTheme.ConnectorSize.Width : 0) : dropConnector.Width;
            return new Point(dropConnector.Left + dropConnector.Width / 2, dropConnector.Top + dropConnector.Height / 2);
        }
 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;
 }
        protected override void OnDragDrop(ActivityDragEventArgs e)
        {
            //Set the correct drag drop effect
            bool ctrlKeyPressed = ((e.KeyState & 8) == 8);
            if (ctrlKeyPressed && (e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
                e.Effect = DragDropEffects.Copy;
            else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
                e.Effect = DragDropEffects.Move;

            //Now there can be set of activities which are inserted and set of activities which are moved
            //So first lets get the list of activities which need to be inserted
            List<Activity> activitiesToInsert = new List<Activity>();
            List<Activity> newActivities = new List<Activity>();
            foreach (Activity activity in e.Activities)
            {
                if (activity.Site == null || activity.Parent != Activity)
                    activitiesToInsert.Add(activity);

                if (activity.Site == null)
                    newActivities.Add(activity);
            }

            //If the component are sited then that means that we are inserting it 
            if (activitiesToInsert.Count > 0)
                CompositeActivityDesigner.InsertActivities(this, new ConnectorHitTestInfo(this, HitTestLocations.Designer, ((CompositeActivity)Activity).Activities.Count), activitiesToInsert.AsReadOnly(), SR.GetString(SR.DragDropActivities));

            Point dropPoint = new Point(e.X, e.Y);
            Point[] movedLocations = FreeFormDragDropManager.GetDesignerLocations(e.DragInitiationPoint, dropPoint, e.Activities);
            if (movedLocations.Length == e.Activities.Count)
            {
                for (int i = 0; i < e.Activities.Count; i++)
                {
                    ActivityDesigner designerToMove = ActivityDesigner.GetDesigner(e.Activities[i]);
                    if (designerToMove != null)
                    {
                        Point location = (newActivities.Contains(designerToMove.Activity)) ? dropPoint : movedLocations[i];
                        MoveContainedDesigner(designerToMove, location);
                    }
                }
            }
            else
            {
                Debug.Assert(false);
            }
        }
        protected override void OnDragOver(ActivityDragEventArgs e)
        {
            base.OnDragOver(e);

            e.DragImageSnapPoint = SnapInToPreviewStripDropTarget(e);
        }
 protected override void OnDragOver(ActivityDragEventArgs e)
 {
     bool ctrlKeyPressed = ((e.KeyState & 8) == 8);
     if (ctrlKeyPressed && (e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
         e.Effect = DragDropEffects.Copy;
     else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
         e.Effect = DragDropEffects.Move;
 }
 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 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;
 }
Пример #29
0
 protected override void OnDragDrop(ActivityDragEventArgs e)
 {
     if (this.DragDropActive)
     {
         base.OnDragDrop(e);
         this.DragDropActive = false;
     }
 }
        private int CanDrop(ActivityDragEventArgs e)
        {
            if (e.Activities.Count == 0)
                return -1;

            Point dropPoint = new Point(e.X, e.Y);
            int dropIndex = -1;
            Rectangle[] dropTargets = GetDropTargets(dropPoint);
            for (int i = 0; i < dropTargets.Length; i++)
            {
                if (dropTargets[i].Contains(dropPoint))
                {
                    dropIndex = i;
                    break;
                }
            }

            if (dropIndex >= 0 && !CanInsertActivities(new ConnectorHitTestInfo(this, HitTestLocations.Designer, dropIndex), e.Activities))
                dropIndex = -1;

            bool ctrlKeyPressed = ((e.KeyState & 8) == 8);
            if (dropIndex >= 0 && !ctrlKeyPressed && (e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
            {
                ConnectorHitTestInfo moveLocation = new ConnectorHitTestInfo(this, HitTestLocations.Designer, dropIndex);
                foreach (Activity activity in e.Activities)
                {
                    if (activity.Site != null)
                    {
                        ActivityDesigner activityDesigner = ActivityDesigner.GetDesigner(activity);
                        if (activityDesigner == null || activityDesigner.ParentDesigner == null || !activityDesigner.ParentDesigner.CanMoveActivities(moveLocation, new List<Activity>(new Activity[] { activity }).AsReadOnly()))
                        {
                            dropIndex = -1;
                            break;
                        }
                    }
                }
            }

            return dropIndex;
        }
Пример #31
0
        private bool CanDrop(ActivityDragEventArgs e)
        {
            if (e.Activities.Count == 0)
                return false;

            if (this.HasActiveDesigner)
                return false;

            if (!CanInsertActivities(new HitTestInfo(this, HitTestLocations.Designer), e.Activities))
                return false;

            bool ctrlKeyPressed = ((e.KeyState & 8) == 8);
            if (!ctrlKeyPressed && (e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
            {
                HitTestInfo moveLocation = new HitTestInfo(this, HitTestLocations.Designer);
                foreach (Activity activity in e.Activities)
                {
                    if (activity.Site != null)
                    {
                        ActivityDesigner activityDesigner = StateDesigner.GetDesigner(activity);
                        if (activityDesigner == null || activityDesigner.ParentDesigner == null || !activityDesigner.ParentDesigner.CanMoveActivities(moveLocation, new List<Activity>(new Activity[] { activity }).AsReadOnly()))
                        {
                            return false;
                        }
                    }
                }
            }

            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);
        }
 private Point SnapInToDropTarget(ActivityDragEventArgs e)
 {
     if (this.CurrentDropTarget >= 0)
     {
         Rectangle[] dropTargets = this.GetDropTargets(new Point(e.X, e.Y));
         if (this.CurrentDropTarget < dropTargets.Length)
         {
             Rectangle rectangle = dropTargets[this.CurrentDropTarget];
             return new Point(rectangle.Left + (rectangle.Width / 2), rectangle.Top + (rectangle.Height / 2));
         }
     }
     return Point.Empty;
 }
Пример #34
0
        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 void OnDragDrop(ActivityDragEventArgs e)
 {
     if (((e.KeyState & 8) == 8) && ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy))
     {
         e.Effect = DragDropEffects.Copy;
     }
     else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
     {
         e.Effect = DragDropEffects.Move;
     }
     List<Activity> list = new List<Activity>();
     List<Activity> list2 = new List<Activity>();
     foreach (Activity activity in e.Activities)
     {
         if ((activity.Site == null) || (activity.Parent != base.Activity))
         {
             list.Add(activity);
         }
         if (activity.Site == null)
         {
             list2.Add(activity);
         }
     }
     if (list.Count > 0)
     {
         CompositeActivityDesigner.InsertActivities(this, new ConnectorHitTestInfo(this, HitTestLocations.Designer, ((CompositeActivity) base.Activity).Activities.Count), list.AsReadOnly(), SR.GetString("DragDropActivities"));
     }
     Point endPoint = new Point(e.X, e.Y);
     Point[] pointArray = FreeFormDragDropManager.GetDesignerLocations(e.DragInitiationPoint, endPoint, e.Activities);
     if (pointArray.Length == e.Activities.Count)
     {
         for (int i = 0; i < e.Activities.Count; i++)
         {
             ActivityDesigner containedDesigner = ActivityDesigner.GetDesigner(e.Activities[i]);
             if (containedDesigner != null)
             {
                 Point newLocation = list2.Contains(containedDesigner.Activity) ? endPoint : pointArray[i];
                 this.MoveContainedDesigner(containedDesigner, newLocation);
             }
         }
     }
 }
        protected override void OnDragDrop(ActivityDragEventArgs e)
        {
            base.OnDragDrop(e);

            bool ctrlKeyPressed = ((e.KeyState & 8) == 8);
            if (ctrlKeyPressed && (e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
                e.Effect = DragDropEffects.Copy;
            else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
                e.Effect = DragDropEffects.Move;

            //If the component is sited then that means that we are moving it 
            try
            {
                CompositeActivityDesigner.InsertActivities(this, new ConnectorHitTestInfo(this, HitTestLocations.Designer, CurrentDropTarget), e.Activities, SR.GetString(SR.DragDropActivities));
            }
            finally
            {
                CurrentDropTarget = -1;
            }
        }
Пример #37
0
 protected override void OnDragOver(ActivityDragEventArgs e)
 {
     base.OnDragOver(e);
     e.DragImageSnapPoint = this.SnapInToPreviewStripDropTarget(e);
 }
 protected override void OnDragDrop(ActivityDragEventArgs e)
 {
     base.OnDragDrop(e);
     if (((e.KeyState & 8) == 8) && ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy))
     {
         e.Effect = DragDropEffects.Copy;
     }
     else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
     {
         e.Effect = DragDropEffects.Move;
     }
     try
     {
         CompositeActivityDesigner.InsertActivities(this, new ConnectorHitTestInfo(this, HitTestLocations.Designer, this.CurrentDropTarget), e.Activities, SR.GetString("DragDropActivities"));
     }
     finally
     {
         this.CurrentDropTarget = -1;
     }
 }
 /// <summary>
 /// Called when the drag drop operation is completed inside designer bounds.
 /// </summary>
 /// <param name="e">Drag drop event arguments.</param>
 protected virtual void OnDragDrop(ActivityDragEventArgs e)
 {
     if (e == null)
         throw new ArgumentNullException("e");
 }
        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;
        }
Пример #41
0
        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);
        }
 private DragDropEffects CheckDragEffect(ActivityDragEventArgs e)
 {
     if ((e.Activities.Count == 0) || !this.DragDropActive)
     {
         return DragDropEffects.None;
     }
     if (((e.KeyState & 8) == 8) && ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy))
     {
         return DragDropEffects.Copy;
     }
     if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
     {
         return DragDropEffects.Move;
     }
     return e.Effect;
 }
        protected override void OnDragOver(ActivityDragEventArgs e)
        {
            base.OnDragOver(e);

            CurrentDropTarget = CanDrop(e);
            e.Effect = CheckDragEffect(e);
            e.DragImageSnapPoint = SnapInToDropTarget(e);
        }
        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;
        }
        private Point SnapInToDropTarget(ActivityDragEventArgs e)
        {
            if (CurrentDropTarget >= 0)
            {
                Rectangle[] dropTargets = GetDropTargets(new Point(e.X, e.Y));
                if (CurrentDropTarget < dropTargets.Length)
                {
                    Rectangle dropConnector = dropTargets[CurrentDropTarget];
                    return new Point(dropConnector.Left + dropConnector.Width / 2, dropConnector.Top + dropConnector.Height / 2);
                }
            }

            return Point.Empty;
        }
        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;
        }
        private DragDropEffects CheckDragEffect(ActivityDragEventArgs e)
        {
            if (e.Activities.Count == 0)
            {
                return DragDropEffects.None;
            }
            else if (CurrentDropTarget >= 0)
            {
                bool ctrlKeyPressed = ((e.KeyState & 8) == 8);
                if (ctrlKeyPressed && (e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
                    return DragDropEffects.Copy;
                else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
                    return DragDropEffects.Move;
            }

            return e.Effect;
        }
        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);
        }