//************************************************************************* // Method: OnMouseDownLeft() // /// <summary> /// Handles the MouseDown event for the left mouse button. /// </summary> /// /// <param name="e"> /// The MouseButtonEventArgs that contains the event data. /// </param> /// /// <param name="oMouseLocation"> /// Mouse location, relative to the control. /// </param> /// /// <param name="oClickedVertex"> /// The vertex that was clicked, or null if an empty area of the graph was /// clicked. /// </param> //************************************************************************* protected void OnMouseDownLeft( MouseButtonEventArgs e, Point oMouseLocation, IVertex oClickedVertex ) { AssertValid(); if ( m_eMouseMode == MouseMode.Translate || Keyboard.IsKeyDown(Key.Space) ) { // The user might want to translate the zoomed graph by dragging // with the mouse. StartTranslationDrag(oMouseLocation); return; } if (m_eMouseMode == MouseMode.ZoomIn) { ZoomViaMouse(e, MouseLeftClickZoomFactor); return; } if (m_eMouseMode == MouseMode.ZoomOut) { ZoomViaMouse(e, 1.0 / MouseLeftClickZoomFactor); return; } if (oClickedVertex == null) { // The user clicked on part of the graph not covered by a vertex. m_oDoubleClickedVertexInfo = null; if (m_eMouseMode == MouseMode.Select) { DeselectAll(); } if (this.Graph.Vertices.Count > 0) { // The user might want to drag a marquee. Save the mouse // location for use within the MouseMove event. m_oMarqueeBeingDragged = new DraggedMarquee(oMouseLocation, this.GraphRectangle, m_oAsyncLayout.Margin); this.Cursor = GetCursorForMarqueeDrag(); Mouse.Capture(this); } return; } // If the control key is pressed, clicking a vertex should invert its // selected state. Otherwise... // // In Select mode, clicking an unselected vertex should clear the // selection and then select the vertex. Clicking a selected vertex // should leave the vertex selected. // // In AddToSelection mode, clicking a vertex should select it. // // In SubtractFromSelection mode, clicking a vertex should deselect // it. Boolean bClickedVertexIsSelected = VertexOrEdgeIsSelected( oClickedVertex); Boolean bSelectClickedVertex = true; if ( (Keyboard.Modifiers & ModifierKeys.Control) != 0 ) { bSelectClickedVertex = !bClickedVertexIsSelected; } else if (m_eMouseMode == MouseMode.Select) { if (!bClickedVertexIsSelected) { SetAllVerticesSelected(false); SetAllEdgesSelected(false); } } else if (m_eMouseMode == MouseMode.SubtractFromSelection) { bSelectClickedVertex = false; } SetVertexSelected(oClickedVertex, bSelectClickedVertex, m_bMouseAlsoSelectsIncidentEdges); // In Select and AddToSelection mode, double-clicking a vertex provides // special behavior. if ( Keyboard.Modifiers != 0 || (m_eMouseMode != MouseMode.Select && m_eMouseMode != MouseMode.AddToSelection) ) { m_oDoubleClickedVertexInfo = null; } else if (e.ClickCount == 2) { OnVertexDoubleClickLeft(oClickedVertex); } else if (m_oDoubleClickedVertexInfo != null && m_oDoubleClickedVertexInfo.Vertex != oClickedVertex) { // (The above "else if" test is required because double-clicking a // vertex results in this method being called twice: once with // e.ClickCount = 1, and again with e.ClickCount = 2. We don't // want to clear m_oDoubleClickedVertexInfo unnecessarily during // this sequence.) m_oDoubleClickedVertexInfo = null; } if ( m_bAllowVertexDrag && (m_eMouseMode == MouseMode.Select || m_eMouseMode == MouseMode.AddToSelection) && m_oSelectedVertices.Count > 0 ) { // The user might want to drag the selected vertices. Save the // mouse location for use within the MouseMove event. m_oVerticesBeingDragged = new DraggedVertices( m_oSelectedVertices.ToArray(), oMouseLocation, this.GraphRectangle, m_oAsyncLayout.Margin); this.Cursor = Cursors.ScrollAll; Mouse.Capture(this); } }
//************************************************************************* // Constructor: NodeXLControl() // /// <summary> /// Initializes a new instance of the <see cref="NodeXLControl" /> class. /// </summary> //************************************************************************* public NodeXLControl() { m_oGraph = new Graph(); m_oGraphDrawer = new GraphDrawer(this); m_oAsyncLayout = new FruchtermanReingoldLayout(); OnNewLayout(m_oAsyncLayout); m_oLastLayoutContext = new LayoutContext(System.Drawing.Rectangle.Empty); m_oLastGraphDrawingContext = null; m_eLayoutState = LayoutState.Stable; m_eMouseMode = MouseMode.Select; m_bMouseAlsoSelectsIncidentEdges = true; m_bAllowVertexDrag = true; m_oVerticesBeingDragged = null; m_oMarqueeBeingDragged = null; m_oTranslationBeingDragged = null; m_oSelectedVertices = new HashSet<IVertex>(); m_oSelectedEdges = new HashSet<IEdge>(); m_oCollapsedGroups = new Dictionary<String, IVertex>(); m_oDoubleClickedVertexInfo = null; m_bShowVertexToolTips = false; m_oLastMouseMoveLocation = new Point(-1, -1); // Create a helper object for displaying vertex tooltips. CreateVertexToolTipTracker(); m_oVertexToolTip = null; m_bGraphZoomCentered = false; this.AddLogicalChild(m_oGraphDrawer.VisualCollection); CreateTransforms(); // Prevent a focus rectangle from being drawn around the control when // it captures keyboard focus. The focus rectangle does not behave // properly when the layout and render transforms are applied -- // sometimes the rectangle disappears, and sometimes it gets magnified // by the render layout. this.FocusVisualStyle = null; // AssertValid(); }
//************************************************************************* // Method: CheckForMarqueeDragOnMouseUp() // /// <summary> /// Checks for a marquee drag operation during the MouseUp event. /// </summary> /// /// <param name="oMouseEventArgs"> /// Standard mouse event arguments. /// </param> //************************************************************************* protected void CheckForMarqueeDragOnMouseUp( MouseEventArgs oMouseEventArgs ) { Debug.Assert(oMouseEventArgs != null); AssertValid(); if ( m_oMarqueeBeingDragged != null && m_oMarqueeBeingDragged.OnMouseUp() ) { // Remove from the top of the graph any marquee drawn during the // previous MouseMove event. RemoveVisualFromTopOfGraph(m_oMarqueeBeingDragged); if ( !this.EscapeKeyIsPressed() ) { // Select or deselect the marqueed vertices. SelectMarqueedVertices(); } } m_oMarqueeBeingDragged = null; }