Esempio n. 1
0
        /// <summary>
        /// Set this mouse action as the active action on the
        /// diagram of the given shape, and activate its drag line
        /// centered on the shape.
        /// </summary>
        /// <param name="chainFromPoint">The point to begin the mouse action</param>
        /// <param name="clientView">The active DiagramClientView</param>
        /// <param name="emulateDrag">true if this should emulate a drag, meaning
        /// that the mouse up acts like a click.</param>
        public void ChainMouseAction(PointD chainFromPoint, DiagramClientView clientView, bool emulateDrag)
        {
            DiagramView activeView = Diagram.ActiveDiagramView;

            if (activeView != null)
            {
                // Move on to the selection action
                clientView.ActiveMouseAction = this;

                // Now emulate a mouse click in the middle of the added constraint. The click
                // actions provide a starting point for the connect action, so a mouse move
                // provides a drag line.
                Point emulateClickPoint = clientView.WorldToDevice(chainFromPoint);
                DiagramMouseEventArgs mouseEventArgs = new DiagramMouseEventArgs(new MouseEventArgs(MouseButtons.Left, 1, emulateClickPoint.X, emulateClickPoint.Y, 0), clientView);
                MouseDown(mouseEventArgs);
                Click(new DiagramPointEventArgs(emulateClickPoint.X, emulateClickPoint.Y, PointRelativeTo.Client, clientView));
                MouseUp(mouseEventArgs);

                // An extra move lets us chain when the mouse is not on the design surface,
                // such as when we are being activated via the task list.
                MouseMove(mouseEventArgs);

                myEmulateDrag = emulateDrag;
                ORMDiagram.SelectToolboxItem(activeView, ResourceStrings.ToolboxRoleConnectorItemId);
            }
        }
        /// <summary>
        /// Set this mouse action as the active action on the
        /// diagram of the given shape.
        /// </summary>
        /// <param name="attachToShape">The shape the constraint is being attached to.</param>
        /// <param name="constraint">The constraint being connected.</param>
        /// <param name="clientView">The active DiagramClientView</param>
        public void ChainMouseAction(FactTypeShape attachToShape, UniquenessConstraint constraint, DiagramClientView clientView)
        {
            DiagramView activeView = Diagram.ActiveDiagramView;

            if (activeView != null)
            {
                // Move on to the selection action
                clientView.ActiveMouseAction = this;

                // Now emulate a mouse click in the middle of the added constraint. The click
                // actions provide a starting point for the connect action, so a mouse move
                // provides a drag line.
                Point emulateClickPoint = clientView.WorldToDevice(attachToShape.GetAbsoluteConstraintAttachPoint(constraint, FactSetConstraint.GetLink(constraint, attachToShape.AssociatedFactType)));
                DiagramMouseEventArgs mouseEventArgs = new DiagramMouseEventArgs(new MouseEventArgs(MouseButtons.Left, 1, emulateClickPoint.X, emulateClickPoint.Y, 0), clientView);
                MouseDown(mouseEventArgs);
                Click(new DiagramPointEventArgs(emulateClickPoint.X, emulateClickPoint.Y, PointRelativeTo.Client, clientView));
                MouseUp(mouseEventArgs);
                attachToShape.Invalidate(true);

                // An extra move lets us chain when the mouse is not on the design surface,
                // such as when we are being activated via the task list.
                MouseMove(mouseEventArgs);

                ORMDiagram.SelectToolboxItem(activeView, ResourceStrings.ToolboxInternalUniquenessConstraintItemId);
                FactTypeShape.ActiveInternalUniquenessConstraintConnectAction = this;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// A context menu has been requested at the specified position. Translate the
        /// position to a device coordinates and show the context menu
        /// </summary>
        protected virtual void OnContextMenuRequested(DiagramMouseEventArgs mouseArgs)
        {
            DiagramClientView clientView = mouseArgs.DiagramClientView;

            if (clientView != null)
            {
                Point pt = clientView.PointToScreen(clientView.WorldToDevice(mouseArgs.MousePosition));
                this.ShowContextMenu(ContextMenuId, pt);
            }
        }
Esempio n. 4
0
 private Point DiagramToImage(PointD worldPoint)
 {
     Debug.Assert(Enabled);
     if (Enabled)
     {
         var ds = DiagramClientView.WorldToDevice(new SizeD(worldPoint.X, worldPoint.Y));
         return(new Point((int)(ds.Width * _imageScale), (int)(ds.Height * _imageScale)));
     }
     else
     {
         return(Point.Empty);
     }
 }
Esempio n. 5
0
 private Size DiagramToImage(SizeD worldSize)
 {
     Debug.Assert(Enabled);
     if (Enabled)
     {
         Debug.Assert(Enabled);
         var ds = DiagramClientView.WorldToDevice(worldSize);
         return(new Size((int)(ds.Width * _imageScale), (int)(ds.Height * _imageScale)));
     }
     else
     {
         return(Size.Empty);
     }
 }
Esempio n. 6
0
        internal void InvalidateImage(DiagramClientView diagramClientView)
        {
            _diagramClientView = diagramClientView;
            if (_diagramClientView != null)
            {
                var diagramSize       = Diagram.Size;
                var deviceDiagramSize = DiagramClientView.WorldToDevice(diagramSize);
                var maxImageSize      = MaximumImageSize;

                _imageScale = Math.Min(
                    (double)maxImageSize.Width / deviceDiagramSize.Width,
                    (double)maxImageSize.Height / deviceDiagramSize.Height);

                ImageSize = new Size(
                    (int)(deviceDiagramSize.Width * _imageScale),
                    (int)(deviceDiagramSize.Height * _imageScale));

                using (var g = Graphics.FromImage(DiagramImage))
                {
                    // Need to use background color from theme.
                    g.Clear(VSColorTheme.GetThemedColor(EnvironmentColors.DesignerBackgroundColorKey));

                    var drawMethod = typeof(Diagram).GetMethod("DrawDiagram", BindingFlags.NonPublic | BindingFlags.Instance);
                    drawMethod.Invoke(
                        Diagram, new object[]
                    {
                        g,
                        new Rectangle(0, 0, ImageSize.Width, ImageSize.Height), // fit the image
                        new PointD(0, 0),                                       // from origin
                        (float)(_imageScale * DiagramClientView.ZoomFactor),    // fit the whole diagram
                        null                                                    // don't need selection etc
                    });
                }
            }
            Invalidate();
        }
Esempio n. 7
0
		/// <summary>
		/// Set this mouse action as the active action on the
		/// diagram of the given shape, and activate its drag line
		/// centered on the shape.
		/// </summary>
		/// <param name="chainFromPoint">The point to begin the mouse action</param>
		/// <param name="clientView">The active DiagramClientView</param>
		/// <param name="emulateDrag">true if this should emulate a drag, meaning
		/// that the mouse up acts like a click.</param>
		public void ChainMouseAction(PointD chainFromPoint, DiagramClientView clientView, bool emulateDrag)
		{
			DiagramView activeView = Diagram.ActiveDiagramView;
			if (activeView != null)
			{
				// Move on to the selection action
				clientView.ActiveMouseAction = this;

				// Now emulate a mouse click in the middle of the added constraint. The click
				// actions provide a starting point for the connect action, so a mouse move
				// provides a drag line.
				Point emulateClickPoint = clientView.WorldToDevice(chainFromPoint);
				DiagramMouseEventArgs mouseEventArgs = new DiagramMouseEventArgs(new MouseEventArgs(MouseButtons.Left, 1, emulateClickPoint.X, emulateClickPoint.Y, 0), clientView);
				MouseDown(mouseEventArgs);
				Click(new DiagramPointEventArgs(emulateClickPoint.X, emulateClickPoint.Y, PointRelativeTo.Client, clientView));
				MouseUp(mouseEventArgs);

				// An extra move lets us chain when the mouse is not on the design surface,
				// such as when we are being activated via the task list.
				MouseMove(mouseEventArgs);

				myEmulateDrag = emulateDrag;
				ORMDiagram.SelectToolboxItem(activeView, ResourceStrings.ToolboxRoleConnectorItemId);
			}
		}
		/// <summary>
		/// Set this mouse action as the active action on the
		/// diagram of the given shape.
		/// </summary>
		/// <param name="attachToShape">The shape the constraint is being attached to.</param>
		/// <param name="constraint">The constraint being connected.</param>
		/// <param name="clientView">The active DiagramClientView</param>
		public void ChainMouseAction(FactTypeShape attachToShape, UniquenessConstraint constraint, DiagramClientView clientView)
		{
			DiagramView activeView = Diagram.ActiveDiagramView;
			if (activeView != null)
			{
				// Move on to the selection action
				clientView.ActiveMouseAction = this;

				// Now emulate a mouse click in the middle of the added constraint. The click
				// actions provide a starting point for the connect action, so a mouse move
				// provides a drag line.
				Point emulateClickPoint = clientView.WorldToDevice(attachToShape.GetAbsoluteConstraintAttachPoint(constraint));
				DiagramMouseEventArgs mouseEventArgs = new DiagramMouseEventArgs(new MouseEventArgs(MouseButtons.Left, 1, emulateClickPoint.X, emulateClickPoint.Y, 0), clientView);
				MouseDown(mouseEventArgs);
				Click(new DiagramPointEventArgs(emulateClickPoint.X, emulateClickPoint.Y, PointRelativeTo.Client, clientView));
				MouseUp(mouseEventArgs);
				attachToShape.Invalidate(true);

				// An extra move lets us chain when the mouse is not on the design surface,
				// such as when we are being activated via the task list.
				MouseMove(mouseEventArgs);

				ORMDiagram.SelectToolboxItem(activeView, ResourceStrings.ToolboxInternalUniquenessConstraintItemId);
				FactTypeShape.ActiveInternalUniquenessConstraintConnectAction = this;
			}
		}