/// <summary> /// Eventhandler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Shape_MouseMove(object sender, DiagramMouseEventArgs e) { // this event is only fired when moving over the shape itself. // moving over compartment entries or compartment headers are handled by ElementListCompartment_MouseMove() entryNowHoveringAbove.Type = SelectedCompartmentPartType.Head; entryNowHoveringAbove.Element = null; }
/// <summary> /// Call back to the source shape to drop the dragged item. /// </summary> /// <param name="e"></param> protected override void OnMouseUp(DiagramMouseEventArgs e) { base.OnMouseUp(e); sourceShape.DoMouseUp(sourceChild, e); Cancel(e.DiagramClientView); e.Handled = true; }
/// <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); } }
public override void OnMouseDown(DiagramMouseEventArgs e) { base.OnMouseDown(e); DiagramItem diagramItem = e.HitDiagramItem; Column referenceColumn = ResolveColumn(diagramItem); if (referenceColumn != null) { // See if we're dragging other columns DiagramItemCollection selection = e.DiagramClientView.Selection.TopLevelItems; Table table = referenceColumn.Table; int count = selection.Count; Column[] selectedColumns = new Column[count]; for (int i = 0; i < count; ++i) { Column column = ResolveColumn(selection[i]); if (null == column || (column != referenceColumn && column.Table != table)) { return; } selectedColumns[i] = column; } myDragSourceColumns = selectedColumns; myDragSourceShape = (ColumnElementListCompartment)diagramItem.Shape; } else { myDragSourceColumns = null; myDragSourceShape = null; } }
/// <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> /// Test for a double click if a commit is expected to signal the /// OnClicked to forward the click to the base ConnectAction and /// complete the operation. /// </summary> /// <param name="e">DiagramMouseEventArgs</param> protected override void OnMouseDown(DiagramMouseEventArgs e) { if (myPendingOnClickedAction == OnClickedAction.CheckForCommit && e.Clicks == 2 && e.Button == MouseButtons.Left) { myPendingOnClickedAction = OnClickedAction.Commit; } base.OnMouseDown(e); }
/// <summary> /// Remember which item the mouse was dragged from. /// We don't create an Action immediately, as this would inhibit the /// inline text editing feature. Instead, we just remember the details /// and will create an Action when/if the mouse moves off this list item. /// </summary> private void Compartment_MouseDown(object sender, DiagramMouseEventArgs e) { Compartment compartment = (Compartment)sender; var compartmentElementToDrag = GetCompartmentElementToDrag(compartment, e.HitDiagramItem.RepresentedElements); dragStartElement = compartmentElementToDrag; compartmentBounds = e.HitDiagramItem.Shape.AbsoluteBoundingBox; }
/// <summary> /// When the mouse moves away from the initial list item, but still inside the compartment, /// create an Action to supervise the cursor and handle subsequent mouse events. /// Transfer the details of the initial mouse position to the Action. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Compartment_MouseMove(object sender, DiagramMouseEventArgs e) { if (dragStartElement != null && dragStartElement != e.HitDiagramItem.RepresentedElements.OfType <ModelAttribute>().FirstOrDefault()) { e.DiagramClientView.ActiveMouseAction = new CompartmentDragMouseAction <ClassShape>(dragStartElement, this, compartmentBounds); dragStartElement = null; } }
/// <summary> /// Call back to the source shape to drop the dragged item. /// </summary> /// <param name="e"></param> protected override void OnMouseUp(DiagramMouseEventArgs e) { base.OnMouseUp(e); //sourceShape.DoMouseUp(sourceChild, e); DragDropHelper.DoMouseUpForShape <TElement>(sourceChild, e); this.Cancel(e.DiagramClientView); e.Handled = true; }
/// <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); } }
/// <summary> /// Call back to the source shape to drop the dragged item. /// </summary> /// <param name="e"></param> protected override void OnMouseUp(DiagramMouseEventArgs e) { base.OnMouseUp(e); this.Cancel(e.DiagramClientView); e.Handled = true; Column column = ResolveColumn(e.HitDiagramItem); if (null != column) { Table.CustomReorderColumns(mySourceColumns, column); } }
/// <summary> /// Called by the Action when the user releases the mouse. /// If we are still on the same compartment but in a different list item, /// move the starting item to the position of the current one. /// </summary> /// <param name="dragFrom"></param> /// <param name="e"></param> internal static void DoMouseUpForShape <TElement>(ModelElement dragFrom, DiagramMouseEventArgs e) where TElement : ModelElement { // Original or "from" item: TElement dragFromElement = dragFrom as TElement; // Current or "to" item: TElement dragToElement = e.HitDiagramItem.RepresentedElements.OfType <TElement>().FirstOrDefault(); if (dragFromElement != null && dragToElement != null) { // Find the common parent model element, and the relationship links: ElementLink parentToLink = GetEmbeddingLink(dragToElement); ElementLink parentFromLink = GetEmbeddingLink(dragFromElement); if (parentToLink != parentFromLink && parentFromLink != null && parentToLink != null) { // Get the static relationship and role (= end of relationship): DomainRelationshipInfo relationshipFrom = parentFromLink.GetDomainRelationship(); DomainRoleInfo parentFromRole = relationshipFrom.DomainRoles[0]; // Get the node in which the element is embedded, usually the element displayed in the shape: ModelElement parentFrom = parentFromLink.LinkedElements[0]; // Same again for the target: DomainRelationshipInfo relationshipTo = parentToLink.GetDomainRelationship(); DomainRoleInfo parentToRole = relationshipTo.DomainRoles[0]; ModelElement parentTo = parentToLink.LinkedElements[0]; // Mouse went down and up in same parent and same compartment: if (parentTo == parentFrom && relationshipTo == relationshipFrom) { // Find index of target position: int newIndex = 0; var elementLinks = parentToRole.GetElementLinks(parentTo); foreach (ElementLink link in elementLinks) { if (link == parentToLink) { break; } newIndex++; } if (newIndex < elementLinks.Count) { using (Transaction t = parentFrom.Store.TransactionManager.BeginTransaction("Move list item")) { parentFromLink.MoveToIndex(parentFromRole, newIndex); t.Commit(); } } } } } }
/// <summary> /// If we've reached the dragging state, then /// chaing to the toolbox action. /// </summary> /// <param name="e"></param> protected override void OnMouseMove(DiagramMouseEventArgs e) { if (e.Button == MouseButtons.Left && CurrentMouseActionState == DraggingState) { DiagramClientView clientView = e.DiagramClientView; // Stop this mouse action Complete(clientView); // Chain to other action ORMDiagram diagram = (ORMDiagram)clientView.Diagram; diagram.RoleConnectAction.ChainMouseAction(this.MouseDownPoint, clientView, true); } }
/// <summary> /// Calls back to parent's implementation of <see cref="IHandleSubFieldMouseMove.OnSubFieldMouseMove"/>. /// </summary> public override void OnMouseMove(DiagramMouseEventArgs e) { base.OnMouseMove(e); DiagramItem diagramItem = e.DiagramHitTestInfo.HitDiagramItem; if (diagramItem != null && diagramItem.Field != null) { IHandleSubFieldMouseMove handlerShape = diagramItem.Shape as IHandleSubFieldMouseMove; if (handlerShape != null) { handlerShape.OnSubFieldMouseMove(diagramItem.Field, diagramItem.SubField, e); } } }
/// <summary> /// Called by the Action when the user releases the mouse. /// If we are still on the same compartment but in a different list item, /// move the starting item to the position of the current one. /// </summary> /// <param name="dragFrom"></param> /// <param name="e"></param> public void DoMouseUp(ModelElement dragFrom, DiagramMouseEventArgs e) { // Original or "from" item: #pragma warning disable IDE0019 // Use pattern matching ModelAttribute dragFromElement = dragFrom as ModelAttribute; #pragma warning restore IDE0019 // Use pattern matching // Current or "to" item: ModelAttribute dragToElement = e.HitDiagramItem.RepresentedElements.OfType <ModelAttribute>().FirstOrDefault(); if (dragFromElement != null && dragToElement != null) { // Find the common parent model element, and the relationship links: ElementLink parentToLink = GetEmbeddingLink(dragToElement); ElementLink parentFromLink = GetEmbeddingLink(dragFromElement); if (parentToLink != parentFromLink && parentFromLink != null && parentToLink != null) { // Get the static relationship and role (= end of relationship): DomainRelationshipInfo relationshipFrom = parentFromLink.GetDomainRelationship(); DomainRoleInfo parentFromRole = relationshipFrom.DomainRoles[0]; // Get the node in which the element is embedded, usually the element displayed in the shape: #pragma warning disable IDE0019 // Use pattern matching ModelClass parentFrom = parentFromLink.LinkedElements[0] as ModelClass; #pragma warning restore IDE0019 // Use pattern matching // Same again for the target: DomainRelationshipInfo relationshipTo = parentToLink.GetDomainRelationship(); DomainRoleInfo parentToRole = relationshipTo.DomainRoles[0]; // Mouse went down and up in same parent and same compartment: if (parentFrom != null && parentToLink.LinkedElements[0] is ModelClass parentTo && parentTo == parentFrom && relationshipTo == relationshipFrom) { // Find index of target position: int newIndex = parentToRole.GetElementLinks(parentTo).IndexOf(parentToLink); if (newIndex >= 0) { using (Transaction t = parentFrom.Store.TransactionManager.BeginTransaction("Move list item")) { parentFromLink.MoveToIndex(parentFromRole, newIndex); // HACK //parentTo.SetFlagValues(); t.Commit(); } } } } } }
/// <summary> /// When the mouse moves away from the initial list item, but still inside the compartment, /// create an Action to supervise the cursor and handle subsequent mouse events. /// Transfer the details of the initial mouse position to the Action. /// </summary> private void Compartment_MouseMove(object sender, DiagramMouseEventArgs e) { if (dragStartElement != null) { Compartment compartment = (Compartment)sender; var compartmentElementToDrag = GetCompartmentElementToDrag(compartment, e.HitDiagramItem.RepresentedElements); if (dragStartElement != compartmentElementToDrag) { e.DiagramClientView.ActiveMouseAction = CreateCompartmentDragMouseAction(compartment, dragStartElement); dragStartElement = null; } } }
/// <summary> /// Eventhandler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ElementListCompartment_MouseMove(object sender, DiagramMouseEventArgs e) { entryNowHoveringAbove.Type = SelectedCompartmentPartType.None; entryNowHoveringAbove.Element = null; foreach (object o in e.HitDiagramItem.RepresentedElements) { if (o is ModelElement) { entryNowHoveringAbove.Type = SelectedCompartmentPartType.Element; entryNowHoveringAbove.Element = (ModelElement)o; break; } } }
public override void OnMouseUp(DiagramMouseEventArgs e) { //base.OnMouseUp(e); if (!e.Handled) { //bool flag = DiagramClientView.IsModifierKeyDown(Keys.Control); //bool flag2 = DiagramClientView.IsModifierKeyDown(Keys.Shift); if (e.Button == MouseButtons.Left) { var shape = e.DiagramHitTestInfo.HitDiagramItem.Shape as NodeShape; Execute(shape); e.Handled = true; } } }
/// <summary> /// If we're emulating a drag (occurs when we're chained from RoleDragPendingAction), /// then complete the action on mouse up /// </summary> /// <param name="e">DiagramMouseEventArgs</param> protected override void OnMouseUp(DiagramMouseEventArgs e) { if (myEmulateDrag && (mySourceObjectType != null || mySourceRole != null)) { myEmulateDrag = false; DiagramClientView clientView = e.DiagramClientView; if (CanComplete(clientView)) { // Establish the mouse down destinations MouseDown(e); Complete(clientView); } } base.OnMouseUp(e); }
/// <summary> /// Helper function to find the role represented /// at the given diagram position. /// </summary> /// <param name="e"></param> /// <returns>Hit role, or null</returns> private static RoleBase HitRole(DiagramMouseEventArgs e) { RoleBase retVal = null; DiagramItem item = e.DiagramHitTestInfo.HitDiagramItem; if (item != null) { foreach (ModelElement element in item.RepresentedElements) { retVal = element as RoleBase; break; } } return(retVal); }
/// <summary> /// Translate mouse events into OnSubFieldMouseEnter/OnSubFieldMouseLeave events /// </summary> /// <param name="e">DiagramMouseEventArgs</param> public override void OnMouseMove(DiagramMouseEventArgs e) { base.OnMouseMove(e); if (HasSubFieldMouseEnterLeaveHover) { Debug.Assert(e.DiagramHitTestInfo.HitDiagramItem.SubField == null); // Should be in OnSubFieldMouseMove, not here ShapeSubField oldSubField = ActiveShapeSubField; if (oldSubField != null && !PendingShapeSubField.Token.SubFieldEquals(oldSubField)) { ShapeField oldShapeField = ActiveShapeField; ActiveShapeField = null; ActiveShapeSubField = PendingShapeSubField.Token; OnSubFieldMouseLeave(oldShapeField, oldSubField, e); base.OnMouseEnter(e); } } }
public override void OnMouseMove(DiagramMouseEventArgs e) { Column[] sourceColumns; if (null != (sourceColumns = myDragSourceColumns)) { DiagramItem currentItem = e.HitDiagramItem; Column targetColumn; ColumnElementListCompartment sourceShape = myDragSourceShape; if (currentItem.Shape != sourceShape) { myDragSourceColumns = null; myDragSourceShape = null; } else if (null != (targetColumn = ResolveColumn(currentItem)) && -1 == (Array.IndexOf <Column>(sourceColumns, targetColumn))) { myDragSourceColumns = null; myDragSourceShape = null; e.DiagramClientView.ActiveMouseAction = new ColumnDragMouseAction(sourceShape, sourceColumns, targetColumn); } } base.OnMouseMove(e); }
/// <summary> /// Use the auto-generated cursor that looks like the currently /// selected toolbox item. Note that for reactivation cases, /// the reactivated mouse action (without the toolbox item) is /// only active for a very short time, so it doesn't matter /// that we can't get the toolbox cursort. /// </summary> protected override void OnMouseMove(DiagramMouseEventArgs e) { Cursor cursor = Cursors.No; ElementGroupPrototype prototype; DiagramClientView clientView; Diagram diagram; DiagramView activeDiagramView; IToolboxService toolbox; ShapeElement shape; if (null != (prototype = this.myPrototype) && null != (clientView = e.DiagramClientView) && null != (diagram = clientView.Diagram) && null != (activeDiagramView = diagram.ActiveDiagramView) && null != (toolbox = activeDiagramView.Toolbox) && null != (shape = e.DiagramHitTestInfo.HitDiagramItem.Shape) && diagram.ElementOperations.CanMergeElementGroupPrototype(shape, prototype)) { toolbox.SetCursor(); cursor = Cursor.Current; } this.myCursor = cursor; }
/// <summary> /// If the current item is a role, then cache it as the /// last mouse mouse hit role /// </summary> /// <param name="e"></param> protected override void OnMouseMove(DiagramMouseEventArgs e) { myLastMouseMoveRole = HitRole(e); base.OnMouseMove(e); }
/// <summary> /// Sanity check. This action may still be active outside the /// source shape with rapid clicks. /// </summary> protected override void OnMouseDown(DiagramMouseEventArgs e) { base.OnMouseDown(e); this.Cancel(e.DiagramClientView); e.Handled = false; }
protected override void OnMouseMove(DiagramMouseEventArgs e) { base.OnMouseMove(e); myLastTargetColumn = ResolveColumn(e.HitDiagramItem); }
/// <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> /// Track information for OnDoubleClick /// </summary> protected override void OnMouseDown(DiagramMouseEventArgs e) { myAllowDoubleClick = e.Clicks == 2 && e.Button == MouseButtons.Left; base.OnMouseDown(e); }
/// <summary> /// Track the last hit diagram item /// </summary> /// <param name="e"></param> protected override void OnMouseMove(DiagramMouseEventArgs e) { myLastMouseMoveItem = (DiagramItem)e.DiagramHitTestInfo.HitDiagramItem.Clone(); base.OnMouseMove(e); }
// The context menu handlers are on the DiagramDocView, but we took // the ToolWindow derivation path from ModelingWindowPane instead of // the ModelingDocView/DiagramDocView, so we need to duplicate the // context menu support from the DiagramDocView. private void DesignerContextMenuRequested(object sender, DiagramMouseEventArgs e) { OnContextMenuRequested(e); }
/// <summary> /// Helper function to find the role represented /// at the given diagram position. /// </summary> /// <param name="e"></param> /// <returns>Hit role, or null</returns> private static RoleBase HitRole(DiagramMouseEventArgs e) { RoleBase retVal = null; DiagramItem item = e.DiagramHitTestInfo.HitDiagramItem; if (item != null) { foreach (ModelElement element in item.RepresentedElements) { retVal = element as RoleBase; break; } } return retVal; }
/// <summary> /// Remember which item the mouse was dragged from. /// We don't create an Action immediately, as this would inhibit the /// inline text editing feature. Instead, we just remember the details /// and will create an Action when/if the mouse moves off this list item. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Compartment_MouseDown(object sender, DiagramMouseEventArgs e) { dragStartElement = e.HitDiagramItem.RepresentedElements.OfType <ModelAttribute>().FirstOrDefault(); compartmentBounds = e.HitDiagramItem.Shape.AbsoluteBoundingBox; }
/// <summary> /// User has released the mouse button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Compartment_MouseUp(object sender, DiagramMouseEventArgs e) => dragStartElement = null;
/// <summary> /// Translate OnSubFieldMouseMove events into OnSubFieldMouseEnter and OnSubFieldMouseMove /// events /// </summary> public virtual void OnSubFieldMouseMove(ShapeField field, ShapeSubField subField, DiagramMouseEventArgs e) { if (HasSubFieldMouseEnterLeaveHover) { ShapeSubField oldSubField = ActiveShapeSubField; if (oldSubField != null) { if (PendingShapeSubField.Token.SubFieldEquals(oldSubField)) { ActiveShapeSubField = subField; ActiveShapeField = field; base.OnMouseLeave(e); OnSubFieldMouseEnter(field, subField, e); } else if (!oldSubField.SubFieldEquals(subField)) { OnSubFieldMouseLeave(ActiveShapeField, oldSubField, e); ActiveShapeSubField = subField; ActiveShapeField = field; OnSubFieldMouseEnter(field, subField, e); } } else { ActiveShapeSubField = subField; ActiveShapeField = field; OnSubFieldMouseEnter(field, subField, e); } e.Handled = true; // Must mark as handled, or the framework will forward this OnMouseMove } }
/// <summary> /// Forget the source item if mouse up occurs outside the compartment. /// </summary> /// <param name="e"></param> public override void OnMouseUp(DiagramMouseEventArgs e) { base.OnMouseUp(e); dragStartElement = null; }