/// <summary> /// Activate a <see cref="MouseAction"/> for a given <see cref="DiagramClientView"/> /// </summary> /// <param name="action">The <see cref="MouseAction"/> to activate.</param> /// <param name="clientView">The current <see cref="DiagramClientView"/></param> /// <param name="serviceProvider">The <see cref="IServiceProvider"/></param> public static void ActivateMouseAction(MouseAction action, DiagramClientView clientView, IServiceProvider serviceProvider) { clientView.ActiveMouseAction = action; #if !VISUALSTUDIO_10_0 IVsUIShell shell; if (null != serviceProvider && null != (shell = (IVsUIShell)serviceProvider.GetService(typeof(IVsUIShell)))) { Guid windowGuid = StandardToolWindows.Toolbox; IVsWindowFrame frame; object frameMode; if (0 == shell.FindToolWindow((uint)(__VSFINDTOOLWIN.FTW_fFrameOnly), ref windowGuid, out frame) && 0 == frame.GetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, out frameMode)) { switch ((VSFRAMEMODE)frameMode) { case VSFRAMEMODE.VSFM_FloatOnly: case VSFRAMEMODE.VSFM_Float: new ActionReactivator(action, clientView); break; } } } #endif // !VISUALSTUDIO_10_0 }
// when title is selected, select its parent shape instead. public override void CoerceSelection(DiagramItem item, DiagramClientView view, bool isAddition) { base.CoerceSelection(item, view, isAddition); if (item != null && item.Shape != null && item.Shape == this && this.ParentShape != null) { view.Selection.Clear(); view.Selection.Add(new DiagramItem(this.ParentShape)); } }
internal ThumbnailViewForm(Control baseControl, DiagramClientView diagramClientView) { if (baseControl == null) { throw new ArgumentNullException("baseControl"); } if (diagramClientView == null) { throw new ArgumentNullException("diagramClientView"); } // Initialize the form. TopMost = true; ShowInTaskbar = false; FormBorderStyle = FormBorderStyle.None; StartPosition = FormStartPosition.Manual; // Position form so that its center lines up with the center of thumbnail control // at designer's bottom-right corner. var location = baseControl.PointToScreen(new Point(baseControl.Width / 2, baseControl.Height / 2)); location.Offset(-ViewSize / 2, -ViewSize / 2); Bounds = new Rectangle(location.X, location.Y, ViewSize, ViewSize); // Make sure thumbnail form fits the screen and doesn't go below or off the right // edge of the screen. var screenBounds = Screen.FromControl(diagramClientView).WorkingArea; if (Right > screenBounds.Right) { Left = screenBounds.Right - Width; } if (Bottom > screenBounds.Bottom) { Top = screenBounds.Bottom - Height; } // Initialize a panel to host pan/zoom control. var panel1 = new Panel(); panel1.Dock = DockStyle.Fill; panel1.BorderStyle = BorderStyle.FixedSingle; Controls.Add(panel1); // Initialize and dock pan/zoom control on the panel. _panZoomPanel = new PanZoomPanel(); _panZoomPanel.Dock = DockStyle.Fill; panel1.Controls.Add(_panZoomPanel); _panZoomPanel.InvalidateImage(diagramClientView); Cursor.Hide(); }
/// <summary> /// Always return the current cursor. /// </summary> public override Cursor GetCursor(Cursor currentCursor, DiagramClientView diagramClientView, PointD mousePosition) { return(this.myCursor); }
public ActionReactivator(MouseAction action, DiagramClientView clientView) { myAction = action; myClientView = clientView; clientView.LostFocus += new EventHandler(this.OnLostFocus); }
public override void CoerceSelection(DiagramItem item, DiagramClientView view, bool isAddition) { base.CoerceSelection(item, view, isAddition); }
Color IGeometryHost.UpdateGeometryLuminosity(DiagramClientView view, Pen pen) { return myInner.UpdateGeometryLuminosity(view, pen); }
public override AccessibleStates GetAccessibleState(ShapeElement parentShape, DiagramClientView diagramClientView) { return(base.GetAccessibleState(parentShape, diagramClientView)); }
/// <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; } }
/// <summary> /// Display an appropriate cursor while the drag is in progress: /// Up-down arrow if we are inside the original compartment. /// No entry if we are elsewhere. /// </summary> /// <param name="currentCursor"></param> /// <param name="diagramClientView"></param> /// <param name="mousePosition"></param> /// <returns></returns> public override System.Windows.Forms.Cursor GetCursor(System.Windows.Forms.Cursor currentCursor, DiagramClientView diagramClientView, PointD mousePosition) { // If the cursor is inside the original compartment, show up-down cursor. return(sourceCompartmentBounds.Contains(mousePosition) ? System.Windows.Forms.Cursors.SizeNS // Up-down arrow. : System.Windows.Forms.Cursors.No); }
/// <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; } }
/// <summary> /// Replacement for <see cref="ShapeField.GetBackgroundBrush"/> that recognizes /// <see cref="IDynamicColorGeometryHost"/> /// </summary> public override Pen GetPen(DiagramClientView view, ShapeElement parentShape, ref Color oldColor) { StyleSet styleSet = (parentShape != null) ? parentShape.StyleSet : null; Color restoreColor = Color.Empty; Pen pen = null; if (styleSet != null) { StyleSetResourceId penId = GetPenId(parentShape); pen = styleSet.GetPen(penId); IDynamicColorGeometryHost dynamicColors = parentShape as IDynamicColorGeometryHost; if (dynamicColors == null || (restoreColor = dynamicColors.UpdateDynamicColor(penId, pen)).IsEmpty) { if (view != null) { restoreColor = parentShape.UpdateGeometryLuminosity(view, pen); } } else if (view != null) { parentShape.UpdateGeometryLuminosity(view, pen); } } if (pen != null && !restoreColor.IsEmpty) { restoreColor = pen.Color; } return pen; }
/// <summary> /// Replacement for <see cref="ShapeField.GetBackgroundBrush"/> that recognizes /// <see cref="IDynamicColorGeometryHost"/> /// </summary> public override Brush GetBackgroundBrush(DiagramClientView view, ShapeElement parentShape, ref Color oldColor) { StyleSet styleSet = (parentShape != null) ? parentShape.StyleSet : null; Brush brush = null; SolidBrush solidBrush = null;; Color restoreColor = Color.Empty; if (styleSet != null) { StyleSetResourceId brushId = GetBackgroundBrushId(view, parentShape); brush = styleSet.GetBrush(brushId); IDynamicColorGeometryHost dynamicColors = parentShape as IDynamicColorGeometryHost; if (dynamicColors == null || (restoreColor = dynamicColors.UpdateDynamicColor(brushId, brush)).IsEmpty) { if (view != null) { restoreColor = parentShape.UpdateGeometryLuminosity(view, brush); } } else if (view != null) { parentShape.UpdateGeometryLuminosity(view, brush); } } if (restoreColor.IsEmpty) { if ((solidBrush ?? (solidBrush = brush as SolidBrush)) != null) { restoreColor = solidBrush.Color; } } if (!restoreColor.IsEmpty) { oldColor = restoreColor; } return brush; }
/// <summary> /// In order to be able to double-click on the textfield, we need to prevent the text from /// being editable. this is what this override does /// </summary> /// <param name="parentShape"></param> /// <param name="view"></param> /// <returns></returns> public override bool CanEditValue(ShapeElement parentShape, DiagramClientView view) { return(false); }
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(); }
internal void InvalidateImage(DiagramClientView diagramClientView) { m_diagramClientView = diagramClientView; if (m_diagramClientView != null) { SizeD diagramSize = this.Diagram.Size; Size deviceDiagramSize = this.DiagramClientView.WorldToDevice(diagramSize); Size maxImageSize = this.MaximumImageSize; m_imageScale = Math.Min( (double)maxImageSize.Width / deviceDiagramSize.Width, (double)maxImageSize.Height / deviceDiagramSize.Height); this.ImageSize = new Size( (int)(deviceDiagramSize.Width * m_imageScale), (int)(deviceDiagramSize.Height * m_imageScale)); using (Graphics g = Graphics.FromImage(this.DiagramImage)) { g.Clear(Color.White); MethodInfo drawMethod = typeof(Microsoft.VisualStudio.Modeling.Diagrams.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)(m_imageScale * DiagramClientView.ZoomFactor), // fit the whole diagram null // don't need selection etc }); } } this.Invalidate(); }
protected override void OnHandleDestroyed(EventArgs e) { if (_diagramImage != null) { _diagramImage.Dispose(); _diagramImage = null; } _diagramClientView = null; base.OnHandleCreated(e); }
/// <summary> /// Gets the ID of the brush that draws the background for the shape element to which this shape field is assigned. /// </summary> /// <param name="view">The view.</param> /// <param name="parentShape">The shape element to which the shape field is assigned.</param> /// <returns> /// The ID of the brush that draws the background for the shape element to which the shape field is assigned. /// </returns> public override StyleSetResourceId GetBackgroundBrushId(DiagramClientView view, ShapeElement parentShape) { return(s_background); }
private void ActivateNewRoleSequenceAction(DiagramClientView clientView) { ORMDiagram diagram; IConstraint constraint; if (null != (diagram = this.Diagram as ORMDiagram) && diagram.StickyObject == this && null != (constraint = this.AssociatedConstraint)) { ExternalConstraintConnectAction connectAction = diagram.ExternalConstraintConnectAction; switch (constraint.ConstraintStorageStyle) { case ConstraintStorageStyle.SetConstraint: connectAction.ConstraintRoleSequenceToEdit = constraint as ConstraintRoleSequence; break; case ConstraintStorageStyle.SetComparisonConstraint: int maximum = ConstraintUtility.RoleSequenceCountMaximum(constraint); if (maximum > 0 && ((SetComparisonConstraint)constraint).RoleSequenceCollection.Count >= maximum) { return; } if (constraint.ConstraintType == ConstraintType.Exclusion) { // If this is a subtype connect action already, then give it the first sequence ExclusionConstraint exclusion = (ExclusionConstraint)constraint; foreach (FactType existingFactType in exclusion.FactTypeCollection) { if (existingFactType is SubtypeFact) { connectAction.ConstraintRoleSequenceToEdit = exclusion.RoleSequenceCollection[0]; break; } } } break; } if (!connectAction.IsActive) { if (clientView == null) { clientView = diagram.ActiveDiagramView.DiagramClientView; } connectAction.ChainMouseAction(this, clientView); } } }
/// <summary> /// Always return the current cursor. /// </summary> public override Cursor GetCursor(Cursor currentCursor, DiagramClientView diagramClientView, PointD mousePosition) { return this.myCursor; }
/// <summary> /// Redirect all luminosity modification to the ORMDiagram.ModifyLuminosity /// algorithm /// </summary> /// <param name="currentLuminosity">The luminosity to modify</param> /// <param name="view">The view containing this item</param> /// <returns>Modified luminosity value</returns> protected override int ModifyLuminosity(int currentLuminosity, DiagramClientView view) { if (view.HighlightedShapes.Contains(new DiagramItem(this))) { return ORMDiagram.ModifyLuminosity(currentLuminosity); } return currentLuminosity; }
/// <summary> /// Copy of <see cref="TextField.DoPaint"/> modified to support the /// <see cref="IDynamicColorGeometryHost"/> on the parent shape. /// </summary> public override void DoPaint(DiagramPaintEventArgs e, ShapeElement parentShape) { DiagramClientView clientView = e.View; if (!HasPendingEdit(parentShape, clientView)) { if (GetVisible(parentShape)) { string text = GetDisplayText(parentShape); StyleSet styleSet = parentShape.StyleSet; Graphics g = e.Graphics; RectangleF clip = g.ClipBounds; clip.Inflate(InflateFocus, InflateFocus); clip.Height -= InflateFocus; g.SetClip(clip); RectangleD shapeBounds = GetBounds(parentShape); RectangleF shapeRect = RectangleD.ToRectangleF(shapeBounds); Matrix startTransform = null; if (!DefaultIsHorizontal) { PointF point = PointD.ToPointF(shapeBounds.Center); startTransform = g.Transform; Matrix verticalTransform = g.Transform; verticalTransform.RotateAt(-90f, point); verticalTransform.Translate(0f, (-point.X / 2f) - shapeRect.X); g.Transform = verticalTransform; } if (parentShape.ClipWhenDrawingFields) { RectangleD parentBounds = parentShape.BoundingBox; shapeRect.Intersect(new RectangleF(0f, 0f, (float)parentBounds.Width, (float)parentBounds.Height)); } if (FillBackground) { Color startColor = Color.White; Brush brush = GetBackgroundBrush(clientView, parentShape, ref startColor); g.FillRectangle(brush, shapeRect); SolidBrush solidBrush = brush as SolidBrush; if (solidBrush != null) { solidBrush.Color = startColor; } } if (DrawBorder) { Color oldColor = Color.White; Pen pen = GetPen(clientView, parentShape, ref oldColor); GeometryUtility.SafeDrawRectangle(g, pen, shapeRect.X, shapeRect.Y, shapeRect.Width, shapeRect.Height); pen.Color = oldColor; } if (text.Length > 0x0) { using (Font font = GetFont(parentShape)) { // Note that this ignores the base GetTextBrush, which is trivial // and has no overrides. Note that we follow the convention used with // the base and do not update luminosity on the text. StyleSetResourceId textBrushId = GetTextBrushId(clientView, parentShape); Brush textBrush = styleSet.GetBrush(textBrushId); Color restoreTextColor = Color.Empty; IDynamicColorGeometryHost dynamicColors = parentShape as IDynamicColorGeometryHost; if (dynamicColors != null) { restoreTextColor = dynamicColors.UpdateDynamicColor(textBrushId, textBrush); } g.DrawString(text, font, textBrush, shapeRect, GetStringFormat(parentShape)); SolidBrush solidTextBrush; if (!restoreTextColor.IsEmpty && null != (solidTextBrush = textBrush as SolidBrush)) { solidTextBrush.Color = restoreTextColor; } } } if (HasFocusedAppearance(parentShape, clientView)) { // Note that the base makes a copy of shapeRect and // assymetrically modifies the focus rectangle. I don't // think this adds anything and gives focus floating shapes a // focus rectangle that arbitrarily overlaps nearby shapes. //RectangleF focusRect = shapeRect; //focusRect.Inflate(0f, InflateFocus); //focusRect.Height -= InflateFocus; //GeometryUtility.SafeDrawRectangle(g, styleSet.GetPen(DiagramPens.FocusIndicatorBackground), focusRect.X, focusRect.Y, focusRect.Width, focusRect.Height); //GeometryUtility.SafeDrawRectangle(g, styleSet.GetPen(DiagramPens.FocusIndicator), focusRect.X, focusRect.Y, focusRect.Width, focusRect.Height); // UNDONE: The bottom line is drawing clipped. The original code has the same problem // with both the top and bottom lines. This appears to be an issue with the Center // alignment on the default focus indicator pens. shapeRect.Inflate(0f, TextFocusTopPadding); shapeRect.Height -= TextFocusTopPadding - TextFocusBottomPadding; GeometryUtility.SafeDrawRectangle(g, styleSet.GetPen(DiagramPens.FocusIndicatorBackground), shapeRect.X, shapeRect.Y, shapeRect.Width, shapeRect.Height); GeometryUtility.SafeDrawRectangle(g, styleSet.GetPen(DiagramPens.FocusIndicator), shapeRect.X, shapeRect.Y, shapeRect.Width, shapeRect.Height); } if (startTransform != null) { g.Transform = startTransform; } } } }
/// <summary> /// Attempt to activate an activatable error. /// </summary> /// <param name="e">DiagramPointEventArgs. Indicates the element to activate.</param> /// <returns>true if an error was activated</returns> public static bool AttemptErrorActivation(DiagramPointEventArgs e) { bool retVal = false; if (!e.Handled) { DiagramClientView clientView = e.DiagramClientView; MouseAction action = clientView.ActiveMouseAction; if ((action == null || !(action is ConnectAction || action is ToolboxAction)) && clientView.Selection.Count == 1) { DiagramItem diagramItem = e.DiagramHitTestInfo.HitDiagramItem; IModelErrorActivation activator = diagramItem.Shape as IModelErrorActivation; if (activator != null) { IModelErrorOwner errorOwner = null; foreach (ModelElement mel in diagramItem.RepresentedElements) { errorOwner = EditorUtility.ResolveContextInstance(mel, false) as IModelErrorOwner; break; } if (errorOwner != null) { ModelErrorDisplayFilter displayFilter = null; ORMDiagram diagram; ORMModel model; if (null != (diagram = diagramItem.Diagram as ORMDiagram) && null != (model = diagram.ModelElement as ORMModel)) { displayFilter = model.ModelErrorDisplayFilter; } MouseAction startingMouseAction = clientView.ActiveMouseAction; foreach (ModelError error in errorOwner.GetErrorCollection(ModelErrorUses.DisplayPrimary)) { if (ModelError.IsDisplayed(error, displayFilter)) { if (activator.ActivateModelError(error)) { // UNDONE: MSBUG Report Microsoft bug DiagramClientView.OnDoubleClick is checking // for an active mouse action after the double click and clearing it if it is set. // This may be appropriate if the mouse action was set before the subfield double // click and did not change during the callback, but is definitely not appropriate // if the double click activated the mouse action. // Note that this bug makes it impossible to override OnDoubleClick and OnSubFieldDoubleClick // because e.Handled cannot be reliably checked, so there is no way to call base.OnDoubleClick // of base.OnSubFieldDoubleClick from a more derived class without attempting error activation // twice. If this is fixed, then any OnDoubleClick/OnSubFieldDoubleClick implementation // that simply defers to this method then calls the base can be eliminated in favor // of the same methods here. if (clientView.ActiveMouseAction == startingMouseAction) { e.Handled = true; } retVal = true; break; } else { if (!retVal) { IORMToolTaskItem task; IORMToolServices services; IORMToolTaskProvider provider; if (null != (task = error.TaskData as IORMToolTaskItem) && null != (services = error.Store as IORMToolServices) && null != (provider = services.TaskProvider)) { if (provider.NavigateTo(task)) { retVal = true; break; } } } } } } } } } } return(retVal); }
private ORMTestWindow(DiagramClientView clientView, ORMTestHooks ormHooks) { myClientView = clientView; myHooks = ormHooks; }
Color IGeometryHost.UpdateGeometryLuminosity(DiagramClientView view, Brush brush) { return myInner.UpdateGeometryLuminosity(view, brush); }