From: jpbruyere Date: Sat, 13 Aug 2016 13:47:18 +0000 (+0200) Subject: double click X-Git-Tag: v0.4~7^2~5 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=7cbef57c54eede125fec5f52295b837b2c276c46;p=jp%2Fcrow.git double click --- diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index f8d307ea..aef23cc2 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -158,6 +158,7 @@ namespace Crow public event EventHandler MouseUp; public event EventHandler MouseDown; public event EventHandler MouseClick; + public event EventHandler MouseDoubleClick; public event EventHandler MouseMove; public event EventHandler MouseEnter; public event EventHandler MouseLeave; @@ -1099,11 +1100,27 @@ namespace Crow onMouseClick (this, e); } public virtual void onMouseClick(object sender, MouseButtonEventArgs e){ + + if (Interface.clickTimer.ElapsedMilliseconds > 0 && + Interface.clickTimer.ElapsedMilliseconds < Interface.DoubleClick) { + Interface.clickTimer.Reset (); + Debug.WriteLine ("double click"); + onMouseDoubleClick (this, e); + return; + } else + Interface.clickTimer.Restart (); + GraphicObject p = Parent as GraphicObject; if (p != null) p.onMouseClick(sender,e); MouseClick.Raise (this, e); } + public virtual void onMouseDoubleClick(object sender, MouseButtonEventArgs e){ + GraphicObject p = Parent as GraphicObject; + if (p != null) + p.onMouseDoubleClick(sender,e); + MouseDoubleClick.Raise (this, e); + } public virtual void onMouseWheel(object sender, MouseWheelEventArgs e){ GraphicObject p = Parent as GraphicObject; if (p != null) diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index e9568c5d..21c6b2cd 100644 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -200,8 +200,8 @@ namespace Crow set { if (value == _currentLine) return; - if (value > lines.Count) - _currentLine = lines.Count; + if (value >= lines.Count) + _currentLine = lines.Count-1; else if (value < 0) _currentLine = 0; else @@ -213,7 +213,13 @@ namespace Crow NotifyValueChanged ("CurrentLine", _currentLine); } } + [XmlIgnore]public Point CurrentPosition { + get { return new Point(_currentCol, CurrentLine); } + } //TODO:using HasFocus for drawing selection cause SelBegin and Release binding not to work + /// + /// Selection begin position in char units + /// [XmlAttributeAttribute][DefaultValue("-1")] public Point SelBegin { get { @@ -240,14 +246,19 @@ namespace Crow NotifyValueChanged ("SelectedText", SelectedText); } } - - [XmlIgnore]protected Char CurrentChar //ordered selection start and end positions + /// + /// return char at CurrentLine, CurrentColumn + /// + [XmlIgnore]protected Char CurrentChar { get { return lines [CurrentLine] [CurrentColumn]; } } - [XmlIgnore]protected Point selectionStart //ordered selection start and end positions + /// + /// ordered selection start and end positions in char units + /// + [XmlIgnore]protected Point selectionStart { get { return SelRelease < 0 || SelBegin.Y < SelRelease.Y ? SelBegin : @@ -315,10 +326,10 @@ namespace Crow { if (selectionIsEmpty) { if (CurrentColumn == 0) { - if (CurrentLine == 0) + if (CurrentLine == 0 && lines.Count == 1) return; - CurrentLine--; - CurrentColumn = lines [CurrentLine].Length; + //CurrentLine--; + CurrentColumn = 0;//lines [CurrentLine].Length; lines [CurrentLine] += lines [CurrentLine + 1]; lines.RemoveAt (CurrentLine + 1); NotifyValueChanged ("Text", Text); @@ -513,7 +524,7 @@ namespace Crow computeTextCursorPosition(gr); Foreground.SetAsSource (gr); - gr.LineWidth = 1.5; + gr.LineWidth = 1.0; gr.MoveTo(new PointD(textCursorPos + rText.X, rText.Y + CurrentLine * fe.Height)); gr.LineTo(new PointD(textCursorPos + rText.X, rText.Y + (CurrentLine + 1) * fe.Height)); gr.Stroke(); @@ -657,6 +668,17 @@ namespace Crow SelectionInProgress = false; RegisterForRedraw (); } + public override void onMouseDoubleClick (object sender, MouseButtonEventArgs e) + { + base.onMouseDoubleClick (sender, e); + + GotoWordStart (); + SelBegin = CurrentPosition; + GotoWordEnd (); + SelRelease = CurrentPosition; + SelectionInProgress = false; + RegisterForRedraw (); + } #endregion /// diff --git a/src/Interface.cs b/src/Interface.cs index 2ffebdbd..bee0d8b5 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -62,6 +62,8 @@ namespace Crow #endregion #region Static and constants + public static int DoubleClick = 200;//ms + internal static Stopwatch clickTimer = new Stopwatch(); public static int TabSize = 4; public static string LineBreak = "\r\n"; //TODO: shold be declared in graphicObject