/// <summary> /// If <see cref="P:Northwoods.Go.GoButton.AutoRepeating" /> is true, have the <see cref="T:Northwoods.Go.GoToolAction" /> /// tool start calling <see cref="M:Northwoods.Go.GoButton.OnActionAdjusted(Northwoods.Go.GoView,Northwoods.Go.GoInputEventArgs)" /> repeatedly while /// the mouse is down. /// </summary> /// <param name="view"></param> /// <param name="e"></param> public virtual void OnActionActivated(GoView view, GoInputEventArgs e) { if (AutoRepeating && view != null) { (view.Tool as GoToolAction)?.StartAutoAdjusting(); } }
/// <summary> /// Implement the single-click behavior for this handle, to toggle the /// expansion state of the <see cref="T:Northwoods.Go.IGoCollapsible" /> that this handle is in. /// </summary> /// <param name="evt"></param> /// <param name="view"></param> /// <returns>true if the parent <see cref="P:Northwoods.Go.IGoCollapsible.Collapsible" /> property is true</returns> /// <remarks> /// If <see cref="P:Northwoods.Go.IGoCollapsible.IsExpanded" /> is true, this calls <see cref="M:Northwoods.Go.IGoCollapsible.Collapse" />; /// otherwise this calls <see cref="M:Northwoods.Go.IGoCollapsible.Expand" />. /// If the view is non-null, this method calls <see cref="M:Northwoods.Go.GoView.StartTransaction" /> /// and <see cref="M:Northwoods.Go.GoView.FinishTransaction(System.String)" />, with a transaction name specified by /// the value of <see cref="F:Northwoods.Go.GoUndoManager.CollapsedName" /> or <see cref="F:Northwoods.Go.GoUndoManager.ExpandedName" />. /// </remarks> public override bool OnSingleClick(GoInputEventArgs evt, GoView view) { IGoCollapsible goCollapsible = FindCollapsible(); if (goCollapsible == null) { return(false); } string tname = null; try { view?.StartTransaction(); if (goCollapsible.IsExpanded) { goCollapsible.Collapse(); tname = "Collapsed"; } else { goCollapsible.Expand(); tname = "Expanded"; } } finally { view?.FinishTransaction(tname); } return(true); }
/// <summary> /// Call all of the Action event handlers. /// </summary> /// <param name="view">the <see cref="T:Northwoods.Go.GoView" /> that is handling input events for this <see cref="T:Northwoods.Go.IGoActionObject" /></param> /// <param name="e">assumed to be the same as the <paramref name="view" />'s <see cref="P:Northwoods.Go.GoView.LastInput" /></param> /// <remarks> /// This method is called when the user does a mouse press and release /// on this button. /// If the mouse point is no longer over this object, no Action /// event handlers are called, and <see cref="M:Northwoods.Go.GoButton.OnActionCancelled(Northwoods.Go.GoView)" /> /// is called instead. /// </remarks> public virtual void OnAction(GoView view, GoInputEventArgs e) { if (view == null) { return; } GoToolAction goToolAction = view.Tool as GoToolAction; IGoActionObject goActionObject = this; if (goToolAction != null) { goActionObject = goToolAction.PickActionObject(); } if (goActionObject == this) { if (myActionEvent != null) { myActionEvent(this, e); } } else { OnActionCancelled(view); } }
/// <summary> /// Unlike a regular <see cref="T:Northwoods.Go.GoCollapsibleHandle" />, subgraph handles /// treat a Ctrl-click when expanding as a command to call <see cref="M:Northwoods.Go.GoSubGraph.ExpandAll" />. /// </summary> /// <param name="evt"></param> /// <param name="view"></param> /// <returns></returns> public override bool OnSingleClick(GoInputEventArgs evt, GoView view) { GoSubGraph goSubGraph = base.Parent as GoSubGraph; if (goSubGraph == null || !goSubGraph.Collapsible) { return(false); } view?.StartTransaction(); string text = null; if (goSubGraph.IsExpanded) { goSubGraph.Collapse(); text = "Collapsed SubGraph"; } else if (evt.Control) { goSubGraph.ExpandAll(); text = "Expanded All SubGraphs"; } else { goSubGraph.Expand(); text = "Expanded SubGraph"; } view?.FinishTransaction(text); return(true); }
/// <summary> /// Any tool can call this method in order to implement the standard click behavior. /// </summary> /// <param name="evt">a <see cref="T:Northwoods.Go.GoInputEventArgs" /> describing the input event</param> /// <returns></returns> /// <remarks> /// By default, this just calls either <see cref="M:Northwoods.Go.GoView.DoDoubleClick(Northwoods.Go.GoInputEventArgs)" /> /// or <see cref="M:Northwoods.Go.GoView.DoSingleClick(Northwoods.Go.GoInputEventArgs)" />, depending on whether /// <see cref="P:Northwoods.Go.GoInputEventArgs.DoubleClick" /> is true. /// </remarks> public virtual bool DoClick(GoInputEventArgs evt) { if (evt.DoubleClick) { return(View.DoDoubleClick(evt)); } return(View.DoSingleClick(evt)); }
/// <summary> /// Allow mouse clicks not on the OverviewRect, but elsewhere in the /// Overview, to cause the OverviewRect to be centered there, or as /// near as allowed. /// </summary> /// <param name="evt"></param> protected override void OnBackgroundSingleClicked(GoInputEventArgs evt) { base.OnBackgroundSingleClicked(evt); if (OverviewRect != null) { RectangleF bounds = OverviewRect.Bounds; PointF newLoc = new PointF(evt.DocPoint.X - bounds.Width / 2f, evt.DocPoint.Y - bounds.Height / 2f); OverviewRect.Location = OverviewRect.ComputeMove(OverviewRect.Location, newLoc); } }
/// <summary> /// Call <see cref="T:Northwoods.Go.GoView" /> method <see cref="M:Northwoods.Go.GoView.DoObjectEnterLeave(Northwoods.Go.GoObject,Northwoods.Go.GoObject,Northwoods.Go.GoInputEventArgs)" />. /// </summary> /// <param name="evt"></param> /// <remarks> /// This method keeps track of the current document object that the mouse is over. /// It ignores any objects that are part of the selection. /// When the current document object changes, this calls <see cref="M:Northwoods.Go.GoView.DoObjectEnterLeave(Northwoods.Go.GoObject,Northwoods.Go.GoObject,Northwoods.Go.GoInputEventArgs)" />. /// </remarks> public virtual void DoMouseOver(GoInputEventArgs evt) { GoObject goObject = myLastObject; GoObject goObject2 = base.View.PickObjectExcluding(doc: true, view: false, evt.DocPoint, selectableOnly: false, base.Selection); if (goObject != goObject2) { myLastObject = goObject2; base.View.DoObjectEnterLeave(goObject, goObject2, evt); } }
/// <summary> /// Call <see cref="T:Northwoods.Go.GoView" /> methods <see cref="M:Northwoods.Go.GoView.DoObjectEnterLeave(Northwoods.Go.GoObject,Northwoods.Go.GoObject,Northwoods.Go.GoInputEventArgs)" /> and <see cref="M:Northwoods.Go.GoView.DoMouseOver(Northwoods.Go.GoInputEventArgs)" />. /// </summary> /// <param name="evt"></param> /// <remarks> /// This method keeps track of the current document object that the mouse is over. /// When the current document object changes, this calls <see cref="M:Northwoods.Go.GoView.DoObjectEnterLeave(Northwoods.Go.GoObject,Northwoods.Go.GoObject,Northwoods.Go.GoInputEventArgs)" />. /// This also calls <see cref="M:Northwoods.Go.GoView.DoMouseOver(Northwoods.Go.GoInputEventArgs)" />. /// </remarks> public virtual void DoMouseOver(GoInputEventArgs evt) { GoObject currentObject = base.CurrentObject; GoObject goObject = base.View.PickObject(doc: true, view: false, evt.DocPoint, selectableOnly: false); if (currentObject != goObject) { base.CurrentObject = goObject; base.View.DoObjectEnterLeave(currentObject, goObject, evt); } base.View.DoMouseOver(evt); }
/// <summary> /// This copy constructor makes a copy of the argument object. /// </summary> /// <param name="evt"></param> public GoInputEventArgs(GoInputEventArgs evt) { ViewPoint = evt.ViewPoint; DocPoint = evt.DocPoint; Buttons = evt.Buttons; Modifiers = evt.Modifiers; Key = evt.Key; MouseEventArgs = evt.MouseEventArgs; DragEventArgs = evt.DragEventArgs; KeyEventArgs = evt.KeyEventArgs; DoubleClick = evt.DoubleClick; Delta = evt.Delta; InputState = evt.InputState; }
/// <summary> /// This is called while the user is dragging the mouse and when the user releases the mouse. /// </summary> /// <param name="evttype">A value of <c>GoInputState.Start</c> when called from <see cref="M:Northwoods.Go.GoToolResizing.Start" />, /// a value of <c>GoInputState.Continue</c> when called from <see cref="M:Northwoods.Go.GoToolResizing.DoMouseMove" />, and /// a value of <c>GoInputState.Finish</c> when called from <see cref="M:Northwoods.Go.GoToolResizing.DoMouseUp" />.</param> /// <remarks> /// Basically this just calls <see cref="M:Northwoods.Go.GoObject.DoResize(Northwoods.Go.GoView,System.Drawing.RectangleF,System.Drawing.PointF,System.Int32,Northwoods.Go.GoInputState,System.Drawing.SizeF,System.Drawing.SizeF)" /> on the /// <see cref="P:Northwoods.Go.GoTool.CurrentObject" />. Objects are responsible for their /// own resize behavior. /// However, this calls <see cref="M:Northwoods.Go.GoView.SnapPoint(System.Drawing.PointF,Northwoods.Go.GoObject)" /> to adjust the /// input event point to make sure the current resize point is a valid one /// according to whatever grids there are. /// </remarks> public virtual void DoResizing(GoInputState evttype) { if (base.CurrentObject != null) { GoInputEventArgs lastInput = base.LastInput; lastInput.DocPoint = base.View.SnapPoint(lastInput.DocPoint, base.CurrentObject); lastInput.ViewPoint = base.View.ConvertDocToView(lastInput.DocPoint); GoObject currentObject = base.CurrentObject; RectangleF bounds = currentObject.Bounds; currentObject.DoResize(base.View, OriginalBounds, lastInput.DocPoint, ResizeHandle.HandleID, evttype, MinimumSize, MaximumSize); if (!mySelectionHidden && ((bounds == currentObject.Bounds && currentObject.Document == base.View.Document) || currentObject.View == base.View)) { currentObject.AddSelectionHandles(base.Selection, mySelectedObject); } } }
/// <summary> /// When <see cref="P:Northwoods.Go.GoToolContext.SingleSelection" /> is false, the user's context-click on a selected /// object does not modify the selection, thereby allowing the context-click action to /// apply to a multiple selection. /// </summary> /// <param name="evt"></param> /// <remarks> /// If the user holds down the Control and/or Shift keys, or when <see cref="P:Northwoods.Go.GoToolContext.SingleSelection" /> /// is true, the standard <see cref="M:Northwoods.Go.GoTool.DoSelect(Northwoods.Go.GoInputEventArgs)" /> behavior occurs. /// When the user context-clicks over an object that is not selected, it becomes /// the single selection. /// When the user context-clicks over no object, the selection is cleared. /// </remarks> public override void DoSelect(GoInputEventArgs evt) { if (SingleSelection || evt.Control || evt.Shift) { base.DoSelect(evt); return; } base.CurrentObject = base.View.PickObject(doc: true, view: false, evt.DocPoint, selectableOnly: true); if (base.CurrentObject == null) { base.Selection.Clear(); } else if (!base.Selection.Contains(base.CurrentObject)) { base.Selection.Select(base.CurrentObject); } }
/// <summary> /// This tool can start when the middle mouse button is pressed, /// unless <see cref="P:Northwoods.Go.GoToolPanning.AutoPan" /> is false (for manual panning), /// in which case the left mouse button is used. /// </summary> /// <returns></returns> /// <remarks> /// However, for manual panning on WebForms, the left mouse button /// is expected only when <see cref="P:Northwoods.Go.GoToolPanning.Modal" /> is true. /// When used modelessly, the middle button must be used, since the /// whole operation will consist of a background-mouse-down and a mouse-up, /// and that gesture will not be confused with a background rubber-band /// selection. /// </remarks> public override bool CanStart() { GoInputEventArgs lastInput = base.LastInput; if (lastInput.Alt || lastInput.Control || lastInput.Shift) { return(false); } if (AutoPan) { return(lastInput.Buttons == MouseButtons.Middle); } if (lastInput.Buttons != MouseButtons.Left) { return(false); } return(base.View.PickObject(doc: true, view: true, lastInput.DocPoint, selectableOnly: true) == null); }
/// <summary> /// Limit mouse over behavior for document objects to just show tooltips. /// </summary> /// <param name="evt"></param> /// <returns></returns> /// <remarks> /// This is basically to support tooltips, which are more valuable when /// the objects are so small. Other mouse-over behavior, including /// hover and changing the cursor, is explicitly avoided, except over /// the <see cref="P:Northwoods.Go.GoOverview.OverviewRect" /> and other view objects. /// </remarks> public override bool DoMouseOver(GoInputEventArgs evt) { GoObject goObject = base.PickObject(doc: false, view: true, evt.DocPoint, selectableOnly: false); bool flag = false; while (goObject != null) { if (goObject.OnMouseOver(evt, this)) { flag = true; break; } goObject = goObject.Parent; } if (!flag) { DoBackgroundMouseOver(evt); } goObject = base.PickObject(doc: true, view: false, evt.DocPoint, selectableOnly: false); DoToolTipObject(goObject); return(true); }
/// <summary> /// Any tool can call this method in order to implement the standard selection behavior /// for a user click. /// </summary> /// <param name="evt">a <see cref="T:Northwoods.Go.GoInputEventArgs" /> describing the input event</param> /// <remarks> /// This sets the <see cref="P:Northwoods.Go.GoTool.CurrentObject" /> to be the result of a call /// to the view's <see cref="M:Northwoods.Go.GoView.PickObject(System.Boolean,System.Boolean,System.Drawing.PointF,System.Boolean)" /> to pick the selectable /// document object at the current point. /// If an object is found, what happens to the selection depends on any /// modifiers to the event: /// if <see cref="P:Northwoods.Go.GoInputEventArgs.Control" /> is true, /// we toggle the selectedness of the current object; /// if <see cref="P:Northwoods.Go.GoInputEventArgs.Shift" /> is true, /// we add the current object to the selection; /// otherwise we just make the current object the only selection. /// If no object is found and neither <see cref="P:Northwoods.Go.GoInputEventArgs.Control" /> /// nor <see cref="P:Northwoods.Go.GoInputEventArgs.Shift" /> are true, we empty the selection. /// </remarks> public virtual void DoSelect(GoInputEventArgs evt) { CurrentObject = View.PickObject(doc: true, view: false, evt.DocPoint, selectableOnly: true); CurrentObjectWasSelected = View.Selection.Contains(CurrentObject); if (CurrentObject != null) { if (evt.Control) { Selection.Toggle(CurrentObject); } else if (evt.Shift) { Selection.Add(CurrentObject); } else { Selection.Select(CurrentObject); } } else if (!evt.Control && !evt.Shift) { Selection.Clear(); } }
/// <summary> /// Provide default behavior, when not running some other tool. /// </summary> /// <remarks> /// By default this handles: /// <list type="bullet"> /// <item>Delete: the Delete key deletes the current selection</item> /// <item>Select All: Ctrl-A selects all selectable document objects</item> /// <item>Copy, Cut, Paste: The Ctrl-C, Ctrl-Insert, Ctrl-X, Shift-Delete, Ctrl-V, and Shift-Insert keys do the standard clipboard operations</item> /// <item>Edit: the F2 key starts in-place editing of the current node's text label</item> /// <item>PageDown, PageUp: The PageDown and PageUp keys scroll vertically; Shift-PageDown and Shift-PageUp /// scroll horizontally</item> /// <item>Home, End: the Home and End keys scroll to the left side and right sides of the document; /// Ctrl-Home and Ctrl-End scroll to the top-left and bottom-right corners of the document, respectively</item> /// <item>Undo, Redo: Ctrl-Z and Ctrl-Y (or Ctrl-Shift-Z) perform undo and redo</item> /// <item>Arrow keys: moves the selection in the given direction, or else scrolls the view that way; /// the Ctrl modifier causes the movement or scrolling to just be one pixel at a time. /// This uses the <see cref="P:Northwoods.Go.GoView.ArrowMoveLarge" /> and <see cref="P:Northwoods.Go.GoView.ArrowMoveSmall" /> properties /// to control how far the selection is moved.</item> /// <item>Escape: the Escape key may clear the selection and then cancels the current input operation</item> /// <item>letters and digits: selects the next node whose text starts with that character</item> /// </list> /// However, the value of <see cref="T:Northwoods.Go.GoView" />.<see cref="P:Northwoods.Go.GoView.DisableKeys" /> can disable /// each of these behaviors. /// </remarks> public override void DoKeyDown() { GoInputEventArgs lastInput = base.LastInput; bool control = lastInput.Control; bool shift = lastInput.Shift; GoViewDisableKeys disableKeys = base.View.DisableKeys; Keys key = lastInput.Key; if (key == Keys.Delete && (disableKeys & GoViewDisableKeys.Delete) == 0) { base.View.EditDelete(); return; } if (control && key == Keys.A && (disableKeys & GoViewDisableKeys.SelectAll) == 0) { base.View.SelectAll(); return; } if (((control && key == Keys.C) /*|| (control && key == Keys.Insert) bylzy*/) && (disableKeys & GoViewDisableKeys.Clipboard) == 0) { base.View.EditCopy(); return; } if (((control && key == Keys.X) || (shift && key == Keys.Delete)) && (disableKeys & GoViewDisableKeys.Clipboard) == 0) { base.View.EditCut(); return; } if (((control && key == Keys.V) || (shift && key == Keys.Insert)) && (disableKeys & GoViewDisableKeys.Clipboard) == 0) { base.View.EditPaste(); return; } if (key == Keys.F2 && (disableKeys & GoViewDisableKeys.Edit) == 0) { base.View.EditEdit(); return; } if (key == Keys.Next && (disableKeys & GoViewDisableKeys.Page) == 0) { if (shift) { base.View.ScrollPage(1f, 0f); } else { base.View.ScrollPage(0f, 1f); } return; } if (key == Keys.Prior && (disableKeys & GoViewDisableKeys.Page) == 0) { if (shift) { base.View.ScrollPage(-1f, 0f); } else { base.View.ScrollPage(0f, -1f); } return; } if (key == Keys.Home && (disableKeys & GoViewDisableKeys.Home) == 0) { RectangleF rectangleF = base.View.ComputeDocumentBounds(); if (control) { base.View.DocPosition = new PointF(rectangleF.X, rectangleF.Y); } else { base.View.DocPosition = new PointF(rectangleF.X, base.View.DocPosition.Y); } return; } if (key == Keys.End && (disableKeys & GoViewDisableKeys.End) == 0) { RectangleF rectangleF2 = base.View.ComputeDocumentBounds(); SizeF docExtentSize = base.View.DocExtentSize; PointF pointF = control ? new PointF(rectangleF2.X + rectangleF2.Width - docExtentSize.Width, rectangleF2.Y + rectangleF2.Height - docExtentSize.Height) : new PointF(rectangleF2.X + rectangleF2.Width - docExtentSize.Width, base.View.DocPosition.Y); base.View.DocPosition = new PointF(Math.Max(0f, pointF.X), Math.Max(0f, pointF.Y)); return; } if (control && !shift && key == Keys.Z && (disableKeys & GoViewDisableKeys.Undo) == 0) { base.View.Undo(); return; } if (((control && key == Keys.Y) || (control && shift && key == Keys.Z)) && (disableKeys & GoViewDisableKeys.Undo) == 0) { base.View.Redo(); return; } if (key == Keys.Escape && (disableKeys & GoViewDisableKeys.CancelDeselects) == 0) { if (base.View.CanSelectObjects()) { base.Selection.Clear(); } base.DoKeyDown(); return; } if (key == Keys.Up || key == Keys.Down || key == Keys.Left || key == Keys.Right) { float num = 0f; float num2 = 0f; switch (key) { case Keys.Left: num = 0f - base.View.WorldScale.Width; break; case Keys.Right: num = base.View.WorldScale.Width; break; case Keys.Up: num2 = 0f - base.View.WorldScale.Height; break; case Keys.Down: num2 = base.View.WorldScale.Height; break; } if (!base.View.Selection.IsEmpty && base.View.CanMoveObjects() && (disableKeys & GoViewDisableKeys.ArrowMove) == 0) { float num3 = 1f; num3 = ((!control) ? base.View.ArrowMoveLarge : base.View.ArrowMoveSmall); GoToolDragging goToolDragging = base.View.FindMouseTool(typeof(GoToolDragging), subclass: true) as GoToolDragging; if (goToolDragging != null) { GoSelection sel = goToolDragging.ComputeEffectiveSelection(base.View.Selection, move: true); base.View.MoveSelection(sel, new SizeF(num * num3, num2 * num3), grid: true); base.View.RaiseSelectionMoved(); base.View.ScrollRectangleToVisible(base.View.Selection.Primary.Bounds); } } else if ((disableKeys & GoViewDisableKeys.ArrowScroll) == 0) { if (control) { base.View.DocPosition = new PointF(base.View.DocPosition.X + num, base.View.DocPosition.Y + num2); } else { base.View.ScrollLine(num, num2); } } else { base.DoKeyDown(); } return; } bool flag = false; if (!control && !lastInput.Alt && (disableKeys & GoViewDisableKeys.SelectsByFirstChar) == 0) { string text = TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(null, CultureInfo.CurrentCulture, lastInput.Key); char c = '\0'; if (text.Length == 1) { c = text[0]; } else if (text.Length == 2 && text[0] == 'D') { c = text[1]; } if (char.IsLetterOrDigit(c)) { flag = base.View.SelectNextNode(c); } } if (!flag) { base.DoKeyDown(); } }
/// <summary> /// We don't care about any mouse movement over a button. /// </summary> /// <param name="view"></param> /// <param name="e"></param> public virtual void OnActionAdjusted(GoView view, GoInputEventArgs e) { }
// When the user double-clicks in the background, create a new node there private void goView1_BackgroundDoubleClicked(object sender, Northwoods.Go.GoInputEventArgs e) { InsertNode(e.DocPoint, (myNodeCounter % 2 == 0), "1"); }
/// <summary> /// Create a <see cref="T:Northwoods.Go.GoObjectEnterLeaveEventArgs" /> that knows about an input event /// involving a <see cref="T:Northwoods.Go.GoObject" />. /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="evt"></param> public GoObjectEnterLeaveEventArgs(GoObject from, GoObject to, GoInputEventArgs evt) : base(evt) { myFrom = from; myTo = to; }
/// <summary> /// Create a <see cref="T:Northwoods.Go.GoObjectEventArgs" /> that knows about an input event /// involving a <see cref="P:Northwoods.Go.GoObjectEventArgs.GoObject" />. /// </summary> /// <param name="obj"></param> /// <param name="evt"></param> public GoObjectEventArgs(GoObject obj, GoInputEventArgs evt) : base(evt) { myObject = obj; }