]> O.S.I.I.S - jp/crow.git/commitdiff
double click
authorjpbruyere <jp.bruyere@hotmail.com>
Sat, 13 Aug 2016 13:47:18 +0000 (15:47 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Sat, 13 Aug 2016 13:47:18 +0000 (15:47 +0200)
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Label.cs
src/Interface.cs

index f8d307ea29512911b2ee12f52c529d2b7a63f958..aef23cc23e5d9b72e54e203db8ec5fb752967605 100644 (file)
@@ -158,6 +158,7 @@ namespace Crow
                public event EventHandler<MouseButtonEventArgs> MouseUp;
                public event EventHandler<MouseButtonEventArgs> MouseDown;
                public event EventHandler<MouseButtonEventArgs> MouseClick;
+               public event EventHandler<MouseButtonEventArgs> MouseDoubleClick;
                public event EventHandler<MouseMoveEventArgs> MouseMove;
                public event EventHandler<MouseMoveEventArgs> MouseEnter;
                public event EventHandler<MouseMoveEventArgs> 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)
index e9568c5d6f503e5dddd55e60858d1536c87eb75c..21c6b2cdfed60868a87c92a7d7c55d44887c5f70 100644 (file)
@@ -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
+               /// <summary>
+               /// Selection begin position in char units
+               /// </summary>
                [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
+               /// <summary>
+               /// return char at CurrentLine, CurrentColumn
+               /// </summary>
+               [XmlIgnore]protected Char CurrentChar
                {
                        get {
                                return lines [CurrentLine] [CurrentColumn];
                        }
                }
-               [XmlIgnore]protected Point selectionStart   //ordered selection start and end positions
+               /// <summary>
+               /// ordered selection start and end positions in char units
+               /// </summary>
+               [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
 
                /// <summary>
index 2ffebdbda4b7d002ff359a20df4e78e60ddf15d0..bee0d8b535f8505f62629912a04665c624de0f5b 100644 (file)
@@ -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