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.
OnMouseDownLeftVertexNotClicked(oMouseLocation);
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 ( ControlKeyIsPressed() )
{
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_oLayout.Margin);
this.Cursor = Cursors.ScrollAll;
Mouse.Capture(this);
}
}