private void OnZoomRectComplete(object sender, EventArgs e)
 {
     if ((this.CanContinueZooming && (this.currentState == ZoomState.In)) && ((this.fastZoomingMessageFilter != null) && !this.fastZoomingMessageFilter.DragRectangle.IsEmpty))
     {
         Rectangle    dragRectangle = this.fastZoomingMessageFilter.DragRectangle;
         WorkflowView parentView    = base.ParentView;
         Point        center        = parentView.LogicalPointToClient(new Point(dragRectangle.Location.X + (dragRectangle.Width / 2), dragRectangle.Location.Y + (dragRectangle.Height / 2)));
         int          zoomLevel     = (int)(Math.Min((float)(((float)parentView.ViewPortSize.Width) / ((float)dragRectangle.Width)), (float)(((float)parentView.ViewPortSize.Height) / ((float)dragRectangle.Height))) * 100f);
         this.UpdateZoom(zoomLevel, center);
     }
 }
 private void OnZoomRectComplete(object sender, EventArgs e)
 {
     Debug.Assert(this.currentState == ZoomState.In && CanContinueZooming && this.fastZoomingMessageFilter != null);
     if (CanContinueZooming && this.currentState == ZoomState.In && this.fastZoomingMessageFilter != null && !this.fastZoomingMessageFilter.DragRectangle.IsEmpty)
     {
         Rectangle    dragRectangle = this.fastZoomingMessageFilter.DragRectangle;
         WorkflowView parentView    = ParentView;
         Point        center        = parentView.LogicalPointToClient(new Point(dragRectangle.Location.X + dragRectangle.Width / 2, dragRectangle.Location.Y + dragRectangle.Height / 2));
         int          zoom          = (int)(Math.Min((float)parentView.ViewPortSize.Width / (float)dragRectangle.Width, (float)parentView.ViewPortSize.Height / (float)dragRectangle.Height) * 100.0f);
         UpdateZoom(zoom, center);
     }
 }
        private void UpdateZoom(int zoomLevel, Point center)
        {
            PointF       empty      = PointF.Empty;
            WorkflowView parentView = base.ParentView;
            Point        point      = parentView.LogicalPointToClient(Point.Empty);

            center.X       -= point.X;
            center.Y       -= point.Y;
            empty           = new PointF(((float)center.X) / ((float)parentView.HScrollBar.Maximum), ((float)center.Y) / ((float)parentView.VScrollBar.Maximum));
            parentView.Zoom = Math.Min(Math.Max(zoomLevel, 10), 400);
            Point point2 = new Point((int)(parentView.HScrollBar.Maximum * empty.X), (int)(parentView.VScrollBar.Maximum * empty.Y));

            parentView.ScrollPosition = new Point(point2.X - (parentView.HScrollBar.LargeChange / 2), point2.Y - (parentView.VScrollBar.LargeChange / 2));
            this.currentState         = ((Control.ModifierKeys & Keys.Shift) != Keys.None) ? ((this.initialState == ZoomState.In) ? ZoomState.Out : ZoomState.In) : this.initialState;
            this.RefreshUIState();
        }
        private void UpdateZoom(int zoomLevel, Point center)
        {
            PointF       relativeCenterF = PointF.Empty;
            WorkflowView parentView      = ParentView;

            Point layoutOrigin = parentView.LogicalPointToClient(Point.Empty);

            center.X       -= layoutOrigin.X; center.Y -= layoutOrigin.Y;
            relativeCenterF = new PointF((float)center.X / (float)parentView.HScrollBar.Maximum, (float)center.Y / (float)parentView.VScrollBar.Maximum);

            parentView.Zoom = Math.Min(Math.Max(zoomLevel, AmbientTheme.MinZoom), AmbientTheme.MaxZoom);

            Point newCenter = new Point((int)((float)parentView.HScrollBar.Maximum * relativeCenterF.X), (int)((float)parentView.VScrollBar.Maximum * relativeCenterF.Y));

            parentView.ScrollPosition = new Point(newCenter.X - parentView.HScrollBar.LargeChange / 2, newCenter.Y - parentView.VScrollBar.LargeChange / 2);

            this.currentState = ((Control.ModifierKeys & Keys.Shift) != 0) ? ((this.initialState == ZoomState.In) ? ZoomState.Out : ZoomState.In) : this.initialState;
            RefreshUIState();
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
        protected override bool OnDragOver(DragEventArgs eventArgs)
        {
            eventArgs.Effect       = DragDropEffects.None;
            this.wasCtrlKeyPressed = false;
            this.dragImageSnapped  = false;
            WorkflowView parentView  = base.ParentView;
            Point        clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y));
            Point        point       = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y));
            Point        dragImagePointInClientCoOrd = this.dragImagePointInClientCoOrd;

            this.dragImagePointInClientCoOrd = new Point(clientPoint.X + (SystemInformation.CursorSize.Width / 4), clientPoint.Y + (SystemInformation.CursorSize.Height / 4));
            if (!parentView.IsClientPointInActiveLayout(clientPoint))
            {
                if (this.dropTargetDesigner != null)
                {
                    ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave();
                }
                this.dropTargetDesigner = null;
            }
            else
            {
                this.wasCtrlKeyPressed = (eventArgs.KeyState & 8) == 8;
                ActivityDragEventArgs e = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, point, this.draggedActivities);
                ActivityDesigner      associatedDesigner = base.MessageHitTestContext.AssociatedDesigner;
                if (associatedDesigner != null)
                {
                    CompositeActivityDesigner designer2 = associatedDesigner as CompositeActivityDesigner;
                    if ((!this.wasCtrlKeyPressed && this.IsRecursiveDropOperation(associatedDesigner)) || ((designer2 != null) && !designer2.IsEditable))
                    {
                        e.Effect           = DragDropEffects.None;
                        associatedDesigner = null;
                    }
                }
                if (this.dropTargetDesigner != associatedDesigner)
                {
                    if (this.dropTargetDesigner != null)
                    {
                        ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave();
                    }
                    this.dropTargetDesigner = associatedDesigner;
                    if (this.dropTargetDesigner != null)
                    {
                        ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragEnter(e);
                    }
                }
                else
                {
                    if (this.dropTargetDesigner != null)
                    {
                        ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragOver(e);
                    }
                    if ((e.Effect != DragDropEffects.None) && !e.DragImageSnapPoint.IsEmpty)
                    {
                        Point point4 = parentView.LogicalPointToClient(e.DragImageSnapPoint);
                        Size  size   = parentView.LogicalSizeToClient(AmbientTheme.DragImageIconSize);
                        this.dragImagePointInClientCoOrd = new Point(point4.X - (size.Width / 2), point4.Y - (size.Height / 2));
                        this.dragImageSnapped            = true;
                    }
                }
                eventArgs.Effect = e.Effect;
            }
            if (this.dragImage != null)
            {
                parentView.InvalidateClientRectangle(new Rectangle(dragImagePointInClientCoOrd, this.dragImage.Size));
                parentView.InvalidateClientRectangle(new Rectangle(this.dragImagePointInClientCoOrd, this.dragImage.Size));
            }
            if ((eventArgs.Effect == DragDropEffects.None) && this.exceptionInDragDrop)
            {
                eventArgs.Effect = this.wasCtrlKeyPressed ? DragDropEffects.Copy : DragDropEffects.Move;
            }
            return(true);
        }
        protected override bool OnDragEnter(DragEventArgs eventArgs)
        {
            WorkflowView parentView = base.ParentView;

            parentView.InvalidateClientRectangle(Rectangle.Empty);
            eventArgs.Effect       = DragDropEffects.None;
            this.wasCtrlKeyPressed = false;
            if (this.existingDraggedActivities.Count > 0)
            {
                this.draggedActivities.AddRange(this.existingDraggedActivities);
            }
            else
            {
                try
                {
                    Activity[] collection = CompositeActivityDesigner.DeserializeActivitiesFromDataObject(base.ParentView, eventArgs.Data);
                    if (collection != null)
                    {
                        this.draggedActivities.AddRange(collection);
                    }
                }
                catch
                {
                    this.exceptionInDragDrop = true;
                }
            }
            Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y));
            Point point       = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y));

            this.CreateDragFeedbackImages(this.draggedActivities);
            if (this.dragImage != null)
            {
                this.dragImagePointInClientCoOrd = new Point(clientPoint.X + (SystemInformation.CursorSize.Width / 4), clientPoint.Y + (SystemInformation.CursorSize.Height / 4));
            }
            if (!parentView.IsClientPointInActiveLayout(clientPoint))
            {
                return(false);
            }
            this.wasCtrlKeyPressed = (eventArgs.KeyState & 8) == 8;
            ActivityDragEventArgs e = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, point, this.draggedActivities);
            ActivityDesigner      associatedDesigner = base.MessageHitTestContext.AssociatedDesigner;

            if (associatedDesigner == null)
            {
                return(false);
            }
            if (!this.wasCtrlKeyPressed && this.IsRecursiveDropOperation(associatedDesigner))
            {
                return(false);
            }
            CompositeActivityDesigner designer2 = associatedDesigner as CompositeActivityDesigner;

            if ((designer2 != null) && !designer2.IsEditable)
            {
                return(false);
            }
            this.dropTargetDesigner = associatedDesigner;
            ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragEnter(e);
            if (!e.DragImageSnapPoint.IsEmpty)
            {
                Point point3 = parentView.LogicalPointToClient(e.DragImageSnapPoint);
                Size  size   = parentView.LogicalSizeToClient(AmbientTheme.DragImageIconSize);
                this.dragImagePointInClientCoOrd = new Point(point3.X - (size.Width / 2), point3.Y - (size.Height / 2));
                this.dragImageSnapped            = true;
            }
            eventArgs.Effect = e.Effect;
            if ((eventArgs.Effect == DragDropEffects.None) && this.exceptionInDragDrop)
            {
                eventArgs.Effect = this.wasCtrlKeyPressed ? DragDropEffects.Copy : DragDropEffects.Move;
            }
            return(true);
        }