예제 #1
0
        private bool CanBeginEditing(Point editPoint, HitTestInfo messageContext)
        {
            ISelectionService selectionService = GetService(typeof(ISelectionService)) as ISelectionService;

            if (selectionService != null)
            {
                Connector selectedConnector = Connector.GetConnectorFromSelectedObject(selectionService.PrimarySelection);
                if (selectedConnector != null && selectedConnector.ParentDesigner.EnableUserDrawnConnectors && new ConnectorEditor(selectedConnector).HitTest(editPoint))
                {
                    return(true);
                }
            }

            ConnectionPointHitTestInfo connectionPointHitTestInfo = messageContext as ConnectionPointHitTestInfo;

            if (connectionPointHitTestInfo != null && connectionPointHitTestInfo.ConnectionPoint != null)
            {
                FreeformActivityDesigner connectorContainer = ConnectionManager.GetConnectorContainer(connectionPointHitTestInfo.AssociatedDesigner);
                if (connectorContainer != null && connectorContainer.EnableUserDrawnConnectors)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
        private ConnectorEditor GetConnectorEditor(Point editPoint, System.Workflow.ComponentModel.Design.HitTestInfo messageContext)
        {
            Connector         connectorEdited = null;
            ISelectionService service         = base.GetService(typeof(ISelectionService)) as ISelectionService;

            if (service != null)
            {
                Connector connectorFromSelectedObject = Connector.GetConnectorFromSelectedObject(service.PrimarySelection);
                if (((connectorFromSelectedObject != null) && connectorFromSelectedObject.ParentDesigner.EnableUserDrawnConnectors) && new ConnectorEditor(connectorFromSelectedObject).HitTest(editPoint))
                {
                    connectorEdited = connectorFromSelectedObject;
                }
            }
            if (connectorEdited == null)
            {
                ConnectionPointHitTestInfo info = messageContext as ConnectionPointHitTestInfo;
                if ((info != null) && (info.ConnectionPoint != null))
                {
                    FreeformActivityDesigner connectorContainer = GetConnectorContainer(info.AssociatedDesigner);
                    if ((connectorContainer != null) && connectorContainer.EnableUserDrawnConnectors)
                    {
                        connectorEdited = connectorContainer.CreateConnector(info.ConnectionPoint, info.ConnectionPoint);
                    }
                }
            }
            if (connectorEdited == null)
            {
                return(null);
            }
            return(new ConnectorEditor(connectorEdited));
        }
예제 #3
0
        private ConnectorEditor GetConnectorEditor(Point editPoint, HitTestInfo messageContext)
        {
            Connector connector = null;

            //First check if we are editing a existing selected connector
            ISelectionService selectionService = GetService(typeof(ISelectionService)) as ISelectionService;

            if (selectionService != null)
            {
                Connector selectedConnector = Connector.GetConnectorFromSelectedObject(selectionService.PrimarySelection);
                if (selectedConnector != null && selectedConnector.ParentDesigner.EnableUserDrawnConnectors && new ConnectorEditor(selectedConnector).HitTest(editPoint))
                {
                    connector = selectedConnector;
                }
            }

            //Then check if the hit is on a ConnectionPoint for drawing new connectors
            if (connector == null)
            {
                ConnectionPointHitTestInfo connectionPointHitTestInfo = messageContext as ConnectionPointHitTestInfo;
                if (connectionPointHitTestInfo != null && connectionPointHitTestInfo.ConnectionPoint != null)
                {
                    FreeformActivityDesigner connectorContainer = ConnectionManager.GetConnectorContainer(connectionPointHitTestInfo.AssociatedDesigner);
                    if (connectorContainer != null && connectorContainer.EnableUserDrawnConnectors)
                    {
                        connector = connectorContainer.CreateConnector(connectionPointHitTestInfo.ConnectionPoint, connectionPointHitTestInfo.ConnectionPoint);
                    }
                }
            }

            return((connector != null) ? new ConnectorEditor(connector) : null);
        }
        /// <summary>
        /// Allows detection of the area hit on the designer.
        /// </summary>
        /// <param name="point">Point to test in logical coordinates.</param>
        /// <returns>Information indicating where the hit happened</returns>
        public virtual HitTestInfo HitTest(Point point)
        {
            HitTestInfo hitInfo = HitTestInfo.Nowhere;
            if (ParentDesigner is FreeformActivityDesigner ||
                (ParentDesigner == null && this is FreeformActivityDesigner))
            {
                //Check if the hit is on connection
                ReadOnlyCollection<ConnectionPoint> connectionPoints = GetConnectionPoints(DesignerEdges.All);
                for (int j = 0; j < connectionPoints.Count; j++)
                {
                    if (connectionPoints[j].Bounds.Contains(point))
                    {
                        hitInfo = new ConnectionPointHitTestInfo(connectionPoints[j]);
                        break;
                    }
                }
            }

            Rectangle bounds = Bounds;
            if (bounds.Contains(point) && hitInfo == HitTestInfo.Nowhere)
            {
                HitTestLocations flags = (bounds.Contains(point)) ? HitTestLocations.Designer : HitTestLocations.None;

                Rectangle hitRectangle = new Rectangle(bounds.Left, bounds.Top, bounds.Left - bounds.Left, bounds.Height);
                flags |= (hitRectangle.Contains(point)) ? HitTestLocations.Left : flags;

                hitRectangle = new Rectangle(bounds.Left, bounds.Top, bounds.Width, bounds.Height - bounds.Height);
                flags |= (hitRectangle.Contains(point)) ? HitTestLocations.Top : flags;

                hitRectangle = new Rectangle(bounds.Right, bounds.Top, bounds.Width - bounds.Width, bounds.Height);
                flags |= (hitRectangle.Contains(point)) ? HitTestLocations.Right : flags;

                hitRectangle = new Rectangle(bounds.Left, bounds.Bottom, bounds.Width, bounds.Bottom - bounds.Bottom);
                flags |= (hitRectangle.Contains(point)) ? HitTestLocations.Bottom : flags;

                hitInfo = new HitTestInfo(this, flags);
            }

            return hitInfo;
        }