Example #1
0
        /// <summary>
        /// Performs custom actions on adaptable control MouseUp events; base method should
        /// be called first</summary>
        /// <param name="sender">Adaptable control</param>
        /// <param name="e">Mouse event args</param>
        protected override void OnMouseUp(object sender, MouseEventArgs e)
        {
            base.OnMouseUp(sender, e);

            if (e.Button == MouseButtons.Left)
            {
                if (m_draggingAnnotations != null)
                {
                    if (m_initiated)
                    {
                        ITransactionContext transactionContext = AdaptedControl.ContextAs <ITransactionContext>();
                        transactionContext.DoTransaction(
                            delegate
                        {
                            foreach (IItemDragAdapter itemDragAdapter in AdaptedControl.AsAll <IItemDragAdapter>())
                            {
                                itemDragAdapter.EndDrag();
                            }
                        }, "Drag Items".Localize());

                        m_initiated = false;
                    }
                }

                if (m_autoTranslateAdapter != null)
                {
                    m_autoTranslateAdapter.Enabled = false;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.MouseUp"></see> event. Performs custom actions on MouseUp event.</summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs"></see> that contains the event data</param>
        protected override void OnMouseUp(object sender, MouseEventArgs e)
        {
            base.OnMouseUp(sender, e);

            if (e.Button == MouseButtons.Left)
            {
                if (Dragging())
                {
                    // Reset the positions to be their original values, before doing the transaction.
                    // The transaction will then record the correct before-and-after changes for undo/redo.
                    for (int i = 0; i < m_draggingItems.Length; i++)
                    {
                        m_layoutContext.SetBounds(m_draggingItems[i], m_originalBounds[i], BoundsSpecified.All);
                    }

                    var transactionContext = AdaptedControl.ContextAs <ITransactionContext>();
                    transactionContext.DoTransaction(UpdateBounds, "Resize States".Localize());

                    AdaptedControl.Invalidate();
                }

                if (m_autoTranslateAdapter != null)
                {
                    m_autoTranslateAdapter.Enabled = false;
                }
            }

            m_draggingItems = null;
            m_direction     = Direction.None;
        }
Example #3
0
        private void control_DragDrop(object sender, DragEventArgs e)
        {
            SetMousePosition(e);

            IInstancingContext instancingContext = AdaptedControl.ContextAs <IInstancingContext>();

            if (instancingContext != null &&
                instancingContext.CanInsert(e.Data))
            {
                try
                {
                    m_isDropping = true;

                    string name = "Drag and Drop".Localize();

                    ITransactionContext transactionContext = AdaptedControl.ContextAs <ITransactionContext>();
                    transactionContext.DoTransaction(
                        delegate
                    {
                        instancingContext.Insert(e.Data);

                        if (m_statusService != null)
                        {
                            m_statusService.ShowStatus(name);
                        }
                    }, name);

                    AdaptedControl.Focus();
                }
                finally
                {
                    m_isDropping = false;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Does the work of connecting and disconnecting wires. Is called by OnMouseUp(),
        /// but clients may want to call it from OnMouseClick().</summary>
        /// <param name="e">Mouse event arguments</param>
        protected void DoMouseClick(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left &&
                ((Control.ModifierKeys & Keys.Alt) == 0))
            {
                if (!m_isConnecting)
                {
                    ConnectWires(e);
                }
                else
                {
                    // Attempt to complete the connection
                    if (m_dragEdgeReversed)
                    {
                        if (CanConnectTo())
                        {
                            m_draggingContext.DisconnectEdge = GetDisconnectEdgeTo();
                        }
                    }
                    else
                    {
                        if (CanConnectFrom())
                        {
                            m_draggingContext.DisconnectEdge = GetDisconnectEdgeFrom();
                        }
                    }

                    // make sure drag changed the edge
                    if (m_draggingContext.ExistingEdge == null || // this is a new edge
                        m_draggingContext.ExistingEdge.ToNode != m_draggingContext.DragToNode ||
                        m_draggingContext.ExistingEdge.ToRoute != m_draggingContext.DragToRoute ||
                        m_draggingContext.ExistingEdge.FromNode != m_draggingContext.DragFromNode ||
                        m_draggingContext.ExistingEdge.FromRoute != m_draggingContext.DragFromRoute)
                    {
                        ITransactionContext transactionContext = AdaptedControl.ContextAs <ITransactionContext>();
                        transactionContext.DoTransaction(MakeConnection, "Drag Edge".Localize());
                    }

                    if (m_autoTranslateAdapter != null)
                    {
                        m_autoTranslateAdapter.Enabled = false;
                    }

                    m_isConnecting = false;
                    m_draggingContext.DragFromNode   = null;
                    m_draggingContext.DragFromRoute  = null;
                    m_draggingContext.DragToNode     = null;
                    m_draggingContext.DragToRoute    = null;
                    m_draggingContext.ExistingEdge   = null;
                    m_draggingContext.DisconnectEdge = null;
                    m_graphAdapter.HideEdge(null);

                    AdaptedControl.AutoResetCursor = true;
                    AdaptedControl.Cursor          = m_oldCursor;
                    m_renderer.RouteConnecting     = null;

                    AdaptedControl.Invalidate();
                }
            }
        }
Example #5
0
        /// <summary>
        /// Ends the current label editing operation</summary>
        public void EndEdit()
        {
            m_labelEditTimer.Enabled = false;

            if (m_namingContext == null || m_item == null)
            {
                return;
            }

            if (!m_textBox.Visible)
            {
                return;
            }

            string text = m_textBox.Text;

            if (text != m_namingContext.GetName(m_item))
            {
                var transactionContext = AdaptedControl.ContextAs <ITransactionContext>();
                // check that some other transaction hasn't ended our edit
                if (transactionContext == null ||
                    !transactionContext.InTransaction)
                {
                    transactionContext.DoTransaction(delegate
                    {
                        m_namingContext.SetName(m_item, text);
                    }, "Edit Label".Localize());
                }
            }

            m_textBox.Visible = false;
            m_namingContext   = null;
            m_item            = null;
            AdaptedControl.Invalidate();
        }
Example #6
0
        private void control_ContextChanged(object sender, EventArgs e)
        {
            IGraph <TNode, TEdge, TEdgeRoute> graph = AdaptedControl.ContextAs <IGraph <TNode, TEdge, TEdgeRoute> >();

            if (graph == null)
            {
                graph = s_emptyGraph;
            }
            m_graph = graph;
        }
Example #7
0
 private void control_ContextChanged(object sender, EventArgs e)
 {
     m_graph                  = AdaptedControl.ContextAs <IGraph <TNode, TEdge, TEdgeRoute> >();
     m_layoutContext          = AdaptedControl.ContextAs <ILayoutContext>();
     m_editableGraphContainer = AdaptedControl.ContextAs <IEditableGraphContainer <TNode, TEdge, TEdgeRoute> >();
     if (m_layoutContext != null)
     {
         m_selectionContext = AdaptedControl.ContextCast <ISelectionContext>();
     }
 }
Example #8
0
        private void control_ContextChanged(object sender, EventArgs e)
        {
            IGraph <TNode, TEdge, TEdgeRoute> graph = AdaptedControl.ContextAs <IGraph <TNode, TEdge, TEdgeRoute> >();

            if (graph == null)
            {
                graph = s_emptyGraph;
            }

            if (m_graph != graph)
            {
                if (m_graph != null)
                {
                    if (m_observableContext != null)
                    {
                        m_observableContext.ItemInserted -= new EventHandler <ItemInsertedEventArgs <object> >(graph_ObjectInserted);
                        m_observableContext.ItemRemoved  -= new EventHandler <ItemRemovedEventArgs <object> >(graph_ObjectRemoved);
                        m_observableContext.ItemChanged  -= new EventHandler <ItemChangedEventArgs <object> >(graph_ObjectChanged);
                        m_observableContext.Reloaded     -= new EventHandler(graph_Reloaded);
                        m_observableContext = null;
                    }
                    if (m_selectionContext != null)
                    {
                        m_selectionContext.SelectionChanged -= new EventHandler(selection_Changed);
                        m_selectionContext = null;
                    }

                    m_visibilityContext = null;
                }

                m_graph = graph;

                if (m_graph != null)
                {
                    m_observableContext = AdaptedControl.ContextAs <IObservableContext>();
                    if (m_observableContext != null)
                    {
                        m_observableContext.ItemInserted += new EventHandler <ItemInsertedEventArgs <object> >(graph_ObjectInserted);
                        m_observableContext.ItemRemoved  += new EventHandler <ItemRemovedEventArgs <object> >(graph_ObjectRemoved);
                        m_observableContext.ItemChanged  += new EventHandler <ItemChangedEventArgs <object> >(graph_ObjectChanged);
                        m_observableContext.Reloaded     += new EventHandler(graph_Reloaded);
                    }

                    m_selectionContext = AdaptedControl.ContextAs <ISelectionContext>();
                    if (m_selectionContext != null)
                    {
                        m_selectionContext.SelectionChanged += new EventHandler(selection_Changed);
                    }

                    m_visibilityContext = AdaptedControl.ContextAs <IVisibilityContext>();
                }
            }
        }
Example #9
0
        private void control_DragOver(object sender, DragEventArgs e)
        {
            SetMousePosition(e);

            e.Effect = DragDropEffects.None;
            IInstancingContext instancingContext = AdaptedControl.ContextAs <IInstancingContext>();

            if (instancingContext != null &&
                instancingContext.CanInsert(e.Data))
            {
                OnDragOver(e);
            }
        }
Example #10
0
        private void control_ContextChanged(object sender, EventArgs e)
        {
            if (m_selectionContext != null)
            {
                m_selectionContext.SelectionChanged -= selectionContext_SelectionChanged;
            }

            m_layoutContext    = AdaptedControl.ContextAs <ILayoutContext>();
            m_selectionContext = AdaptedControl.ContextAs <ISelectionContext>();
            if (m_selectionContext != null)
            {
                m_selectionContext.SelectionChanged += selectionContext_SelectionChanged;
            }
        }
Example #11
0
        private void PrepareForEdit()
        {
            if (!AdaptedControl.Capture)
            {
                INamingContext namingContext = AdaptedControl.ContextAs <INamingContext>();
                BeginEdit(
                    namingContext,
                    m_itemHitRecord.Item,
                    m_hitLabel);
            }

            m_itemHitRecord = null;
            m_hitLabel      = null;
        }
Example #12
0
        private void control_ContextChanged(object sender, EventArgs e)
        {
            IAnnotatedDiagram annotatedContext = AdaptedControl.ContextAs <IAnnotatedDiagram>();

            if (m_annotatedDiagram != annotatedContext)
            {
                if (m_annotatedDiagram != null)
                {
                    if (m_observableContext != null)
                    {
                        m_observableContext.ItemInserted -= context_ObjectInserted;
                        m_observableContext.ItemRemoved  -= context_ObjectRemoved;
                        m_observableContext.ItemChanged  -= context_ObjectChanged;
                        m_observableContext.Reloaded     -= context_Reloaded;
                        m_observableContext = null;
                    }
                    if (m_selectionContext != null)
                    {
                        m_selectionContext.SelectionChanged -= selection_Changed;
                        m_selectionContext = null;
                    }
                }

                m_annotatedDiagram = annotatedContext;

                if (m_annotatedDiagram != null)
                {
                    m_observableContext = AdaptedControl.ContextAs <IObservableContext>();
                    if (m_observableContext != null)
                    {
                        m_observableContext.ItemInserted += context_ObjectInserted;
                        m_observableContext.ItemRemoved  += context_ObjectRemoved;
                        m_observableContext.ItemChanged  += context_ObjectChanged;
                        m_observableContext.Reloaded     += context_Reloaded;
                    }

                    m_selectionContext = AdaptedControl.ContextAs <ISelectionContext>();
                    if (m_selectionContext != null)
                    {
                        m_selectionContext.SelectionChanged += selection_Changed;
                    }

                    m_layoutContext = AdaptedControl.ContextAs <ILayoutContext>();
                }
            }
        }
Example #13
0
        private void control_ContextChanged(object sender, EventArgs e)
        {
            IGraph <Element, Wire, ICircuitPin> graph = AdaptedControl.ContextAs <IGraph <Element, Wire, ICircuitPin> >();

            if (graph == null)
            {
                graph = CircuitUtil.EmptyCircuit;
            }

            if (m_graph != graph)
            {
                m_graph = graph;
            }

            m_layoutContext = AdaptedControl.ContextAs <ILayoutContext>();

            if (m_layoutContext != null)
            {
                m_selectionContext = AdaptedControl.ContextCast <ISelectionContext>();
            }
        }
Example #14
0
        private void selectionAdapter_SelectedItemHit(object sender, DiagramHitEventArgs e)
        {
            m_itemHitRecord = e.HitRecord;
            // hit on diagram label part?
            DiagramLabel hitLabel = e.HitRecord.Part.As <DiagramLabel>();

            if (hitLabel != null)
            {
                INamingContext namingContext = AdaptedControl.ContextAs <INamingContext>();
                if (namingContext != null)
                {
                    // if label editing is enabled, mouse is over label, and item can be named, open it for edit
                    if (namingContext.CanSetName(e.HitRecord.Item))
                    {
                        m_hitLabel = hitLabel;
                        m_labelEditTimer.Interval = SystemInformation.DoubleClickTime;
                        m_labelEditTimer.Enabled  = true;
                    }
                }
            }
        }
Example #15
0
        /// <summary>
        /// Performs custom actions when ending a mouse dragging operation</summary>
        /// <param name="e">Mouse event args</param>
        protected override void OnEndDrag(MouseEventArgs e)
        {
            base.OnEndDrag(e);
            if (m_draggingNodes != null && m_draggingNodes.Length > 0)
            {
                foreach (var draggingNode in m_draggingNodes)
                {
                    ResetCustomStyle(draggingNode);
                }

                foreach (IItemDragAdapter itemDragAdapter in AdaptedControl.AsAll <IItemDragAdapter>())
                {
                    itemDragAdapter.EndingDrag(); //call ourselves, too
                }
                var transactionContext = AdaptedControl.ContextAs <ITransactionContext>();
                transactionContext.DoTransaction(delegate
                {
                    foreach (IItemDragAdapter itemDragAdapter in AdaptedControl.AsAll <IItemDragAdapter>())
                    {
                        itemDragAdapter.EndDrag();         //call ourselves, too
                    }
                }, "Drag Items".Localize());

                if (m_autoTranslateAdapter != null)
                {
                    m_autoTranslateAdapter.Enabled = false;
                }
                AdaptedControl.Invalidate();
            }
            m_draggingNodes = null;
            m_newPositions  = null;
            m_oldPositions  = null;
            ResetCustomStyle(m_targetItem);
            m_targetItem          = null;
            m_resizing            = false;
            AdaptedControl.Cursor = Cursors.Default;
        }
Example #16
0
 private void control_ContextChanged(object sender, EventArgs e)
 {
     m_graph         = AdaptedControl.ContextAs <IGraph <TNode, TEdge, TEdgeRoute> >();
     m_editableGraph = AdaptedControl.ContextAs <IEditableGraph <TNode, TEdge, TEdgeRoute> >();
 }
Example #17
0
        /// <summary>
        /// Performs custom actions on adaptable control MouseUp events; base method should
        /// be called first</summary>
        /// <param name="sender">Adaptable control</param>
        /// <param name="e">Event args</param>
        protected override void OnMouseUp(object sender, MouseEventArgs e)
        {
            base.OnMouseUp(sender, e);

            if (e.Button == MouseButtons.Left)
            {
                if (m_isDragging)
                {
                    if (m_existingEdge != null)
                    {
                        m_graphAdapter.ResetStyle(m_existingEdge);
                    }

                    if (m_disconnectEdge != null)
                    {
                        m_graphAdapter.ResetStyle(m_disconnectEdge);
                    }

                    // make sure drag changed the edge
                    if (m_existingEdge == null || // this is a new edge
                        m_existingEdge.ToNode != m_dragToNode ||
                        m_existingEdge.ToRoute != m_dragToRoute ||
                        m_existingEdge.FromNode != m_dragFromNode ||
                        m_existingEdge.FromRoute != m_dragFromRoute)
                    {
                        ITransactionContext transactionContext = AdaptedControl.ContextAs <ITransactionContext>();
                        TransactionContexts.DoTransaction(transactionContext,
                                                          delegate
                        {
                            // disconnect any existing edge on the node route
                            if (m_disconnectEdge != null)
                            {
                                m_editableGraph.Disconnect(m_disconnectEdge);
                            }

                            if (m_existingEdge != null)
                            {
                                m_editableGraph.Disconnect(m_existingEdge);
                            }

                            if (m_dragToNode != null &&
                                m_dragToRoute != null &&
                                m_dragFromNode != null &&
                                m_dragFromRoute != null)
                            {
                                m_editableGraph.Connect(
                                    m_dragFromNode,
                                    m_dragFromRoute,
                                    m_dragToNode,
                                    m_dragToRoute,
                                    m_existingEdge);
                            }
                        },
                                                          "Drag Edge".Localize());
                    }

                    AdaptedControl.Invalidate();
                }
            }

            if (m_autoTranslateAdapter != null)
            {
                m_autoTranslateAdapter.Enabled = false;
            }

            m_isDragging     = false;
            m_dragFromNode   = null;
            m_dragFromRoute  = null;
            m_dragToNode     = null;
            m_dragToRoute    = null;
            m_existingEdge   = null;
            m_disconnectEdge = null;

            AdaptedControl.Cursor = m_oldCursor;
        }
Example #18
0
 /// <summary>
 /// Context changed event handler</summary>
 /// <param name="sender">Adaptable control</param>
 /// <param name="e">Event args</param>
 protected virtual void control_ContextChanged(object sender, EventArgs e)
 {
     m_mainGraph         = AdaptedControl.ContextAs <IGraph <TNode, TEdge, TEdgeRoute> >();
     m_mainEditableGraph = AdaptedControl.ContextAs <IEditableGraph <TNode, TEdge, TEdgeRoute> >();
 }