public override UIHandleResult OnMouseDown(MouseEventArgs args) { if (args.Button != MouseButtons.Left || !_viewer.EnabledEx) { return(UIHandleResult.Pass); } //テキスト選択ではないのでちょっと柄悪いが。UserControl->Controlの置き換えに伴う if (!_viewer.Focused) { _viewer.Focus(); } CharacterDocument document = _viewer.CharacterDocument; lock (document) { int col, row; _viewer.MousePosToTextPos(args.X, args.Y, out col, out row); int target_id = _viewer.GetTopLine().ID + row; TextSelection sel = _viewer.TextSelection; if (sel.State == SelectionState.Fixed) { sel.Clear(); //変なところでMouseDownしたとしてもClearだけはする } if (target_id <= document.LastLineNumber) { //if(InFreeSelectionMode) ExitFreeSelectionMode(); //if(InAutoSelectionMode) ExitAutoSelectionMode(); RangeType rt; //Debug.WriteLine(String.Format("MouseDown {0} {1}", sel.State, sel.PivotType)); //同じ場所でポチポチと押すとChar->Word->Line->Charとモード変化する if (sel.StartX != args.X || sel.StartY != args.Y) { rt = RangeType.Char; } else { rt = sel.PivotType == RangeType.Char ? RangeType.Word : sel.PivotType == RangeType.Word ? RangeType.Line : RangeType.Char; } //マウスを動かしていなくても、MouseDownとともにMouseMoveが来てしまうようだ GLine tl = document.FindLine(target_id); sel.StartSelection(tl, col, rt, args.X, args.Y); } } _viewer.Invalidate(); //NOTE 選択状態に変化のあった行のみ更新すればなおよし return(UIHandleResult.Capture); }
public override UIHandleResult OnMouseUp(MouseEventArgs args) { TextSelection sel = _viewer.TextSelection; if (args.Button == MouseButtons.Left) { if (sel.State == SelectionState.Expansion || sel.State == SelectionState.Pivot) { sel.FixSelection(); } else { sel.Clear(); } } return(_viewer.MouseHandlerManager.CapturingHandler == this ? UIHandleResult.EndCapture : UIHandleResult.Pass); }