OSDN Git Service

WPFでも選択時の動作をメモ帳と同じにした
authorkonekoneko <test2214@hotmail.co.jp>
Thu, 28 Jul 2016 19:33:07 +0000 (04:33 +0900)
committerkonekoneko <test2214@hotmail.co.jp>
Thu, 28 Jul 2016 19:33:07 +0000 (04:33 +0900)
WPF/FooEditEngine/FooTextBox.cs

index 4798c5a..0bcfdab 100644 (file)
@@ -827,6 +827,8 @@ namespace FooEditEngine.WPF
         /// </remarks>
         protected override void OnMouseDown(MouseButtonEventArgs e)
         {
+            this.CaptureMouse();
+
             var p = this.GetDipFromPoint(e.GetPosition(this));
             TextPoint tp = this.View.GetTextPointFromPostion(p);
             if (tp == TextPoint.Null)
@@ -870,6 +872,16 @@ namespace FooEditEngine.WPF
         }
 
         /// <summary>
+        /// マウスのボタンが離されたときに呼ばれます
+        /// </summary>
+        /// <param name="e"></param>
+        protected override void OnMouseUp(MouseButtonEventArgs e)
+        {
+            this.ReleaseMouseCapture();
+            base.OnMouseUp(e);
+        }
+
+        /// <summary>
         /// マウスが移動したときに呼ばれます
         /// </summary>
         /// <param name="e">イベントパラメーター</param>
@@ -879,13 +891,26 @@ namespace FooEditEngine.WPF
         /// </remarks>
         protected override void  OnMouseMove(MouseEventArgs e)
         {
+            bool leftPressed = e.LeftButton == MouseButtonState.Pressed;
+
             var p = this.GetDipFromPoint(e.GetPosition(this));
-            TextPoint tp = this.View.GetTextPointFromPostion(p);
+
+            TextPointSearchRange searchRange;
+            if (this.View.HitTextArea(p.X, p.Y))
+                searchRange = TextPointSearchRange.TextAreaOnly;
+            else if (leftPressed)
+                searchRange = TextPointSearchRange.Full;
+            else
+                searchRange = TextPointSearchRange.TextAreaOnly;
+
+            TextPoint tp = this.View.GetTextPointFromPostion(p, searchRange);
+
             if (tp == TextPoint.Null)
             {
                 base.OnMouseMove(e);
                 return;
             }
+
             int index = this.View.GetIndexFromLayoutLine(tp);
 
             FooMouseEventArgs newEventArgs = new FooMouseEventArgs(e.MouseDevice, e.Timestamp, e.StylusDevice, index);
@@ -895,25 +920,26 @@ namespace FooEditEngine.WPF
             if (newEventArgs.Handled)
                 return;
 
-            if (this.View.HitTextArea(p.X,p.Y))
+            //この状態のときはカーソルがテキストエリア内にある
+            if (searchRange == TextPointSearchRange.TextAreaOnly)
             {
                 if (this._Controller.IsMarker(tp, HilightType.Url))
                     this.Cursor = Cursors.Hand;
                 else
                     this.Cursor = Cursors.IBeam;
-
-                if (e.LeftButton == MouseButtonState.Pressed)
-                {
-                    this._Controller.MoveCaretAndSelect(tp);
-                    if (this.peer != null)
-                        this.peer.OnNotifyCaretChanged();
-                    this.Refresh();
-                }
             }
             else
             {
                 this.Cursor = Cursors.Arrow;
             }
+
+            if (leftPressed)
+            {
+                this._Controller.MoveCaretAndSelect(tp);
+                if (this.peer != null)
+                    this.peer.OnNotifyCaretChanged();
+                this.Refresh();
+            }
         }
 
         Gripper hittedGripper;