OSDN Git Service

DrawLineNumberでしていることは同じなのでコントローラーに書くことにした
[fooeditengine/FooEditEngine.git] / Metro / FooEditEngine / FooTextBox.cs
index 9b782da..ebb25ea 100644 (file)
@@ -82,19 +82,16 @@ namespace FooEditEngine.Metro
             this.View = new EditView(this.Document, this.Render, new Padding(5, Gripper.HitAreaWidth, Gripper.HitAreaWidth / 2, Gripper.HitAreaWidth));
             this.View.SrcChanged += View_SrcChanged;
             this.View.InsertMode = this.InsertMode;
-            this.View.DrawLineNumber = this.DrawLineNumber;
+            this.Document.DrawLineNumber = this.DrawLineNumber;
             this.View.HideCaret = !this.DrawCaret;
             this.View.HideLineMarker = !this.DrawCaretLine;
-            this.View.HideRuler = !this.DrawRuler;
-            this.View.UrlMark = this.MarkURL;
-            this.View.TabStops = this.TabChars;
+            this.Document.HideRuler = !this.DrawRuler;
+            this.Document.UrlMark = this.MarkURL;
+            this.Document.TabStops = this.TabChars;
 
             this._Controller = new Controller(this.Document, this.View);
             this._Controller.SelectionChanged += Controller_SelectionChanged;
 
-            this.FirstGripper = new Gripper(this._Controller, this.View, this.Render, GripperPostion.BottomLeft);
-            this.SecondGripper = new Gripper(this._Controller, this.View, this.Render, GripperPostion.BottomRight);
-
             this.gestureRecongnizer.GestureSettings = GestureSettings.Drag | 
                 GestureSettings.RightTap | 
                 GestureSettings.Tap | 
@@ -491,7 +488,7 @@ namespace FooEditEngine.Metro
                     if (isControlPressed)
                         this._Controller.JumpToHead(isShiftPressed);
                     else
-                        this.Controller.JumpToLineHead(this.View.CaretPostion.row,isShiftPressed);
+                        this.Controller.JumpToLineHead(this.Document.CaretPostion.row,isShiftPressed);
                     this.Refresh();
                     isMovedCaret = true;
                     break;
@@ -499,7 +496,7 @@ namespace FooEditEngine.Metro
                     if (isControlPressed)
                         this._Controller.JumpToEnd(isShiftPressed);
                     else
-                        this.Controller.JumpToLineEnd(this.View.CaretPostion.row,isShiftPressed);
+                        this.Controller.JumpToLineEnd(this.Document.CaretPostion.row,isShiftPressed);
                     this.Refresh();
                     isMovedCaret = true;
                     break;
@@ -775,15 +772,14 @@ namespace FooEditEngine.Metro
             //こうしないと選択できなくなってしまう
             this.nowCaretMove = true;
             SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
-            SetValue(CaretPostionPropertyKey, this.View.CaretPostion);
+            SetValue(CaretPostionPropertyKey, this.Document.CaretPostion);
             this.nowCaretMove = false;
+            this.Document.SelectGrippers.BottomLeft.MoveByIndex(this.View, this.Controller.SelectionStart);
+            this.Document.SelectGrippers.BottomRight.MoveByIndex(this.View, this.Controller.SelectionStart + this.Controller.SelectionLength);
             if (this.textStore.IsLocked() == false)
                 this.textStore.NotifySelectionChanged();
         }
 
-        Gripper FirstGripper, SecondGripper;
-        bool HittedCaret;
-        Gripper hittedGripper;
         private void gestureRecongnizer_ManipulationInertiaStarting(GestureRecognizer sender, ManipulationInertiaStartingEventArgs e)
         {
             //sender.InertiaTranslationDeceleration = 0.001f;
@@ -791,31 +787,11 @@ namespace FooEditEngine.Metro
             //sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
         }
 
+        Gripper hittedGripper;
         void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)
         {
-            this.HittedCaret = false;
-            this.hittedGripper = null;
-
-            Point p = e.Position;
-            TextPoint tp = this.View.GetTextPointFromPostion(p);
-            if (tp == this.View.CaretPostion)
-            {
-                HittedCaret = true;
-            }
-            
-            if (this.FirstGripper.IsHit(p))
-            {
-                hittedGripper = this.FirstGripper;
-                HittedCaret = true;
-                System.Diagnostics.Debug.WriteLine("first gripper hitted");
-            }
-            
-            else if (this.SecondGripper.IsHit(p))
-            {
-                hittedGripper = this.SecondGripper;
-                HittedCaret = true;
-                System.Diagnostics.Debug.WriteLine("second gripper hitted");
-            }
+            //Updateedの段階でヒットテストしてしまうとグリッパーを触ってもヒットしないことがある
+            this.hittedGripper = this.View.HitGripperFromPoint(e.Position);
         }
 
         const int WheelNoti = 120;
@@ -824,46 +800,11 @@ namespace FooEditEngine.Metro
 
         void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
         {
-            if (HittedCaret)
+            if (this._Controller.MoveCaretAndGripper(e.Position, this.hittedGripper))
             {
-                Point p;
-                if (this.hittedGripper == null)
-                     p = e.Position;
-                else
-                    p = this.hittedGripper.AdjustPoint(e.Position);
-
-                if (hittedGripper != null)
-                {
-                    TextPoint tp = this.View.GetTextPointFromPostion(p);
-                    if (this._Controller.IsReverseSelect())
-                    {
-                        if (Object.ReferenceEquals(hittedGripper,this.SecondGripper))
-                            this._Controller.MoveSelectBefore(tp);
-                        else
-                            this._Controller.MoveCaretAndSelect(tp);
-                    }
-                    else
-                    {
-                        if (Object.ReferenceEquals(hittedGripper,this.FirstGripper))
-                            this._Controller.MoveSelectBefore(tp);
-                        else
-                            this._Controller.MoveCaretAndSelect(tp);
-                    }
-                }
-                else
-                {
-                    TextPoint tp = this.View.GetTextPointFromPostion(p);
-                    this._Controller.MoveCaretAndSelect(tp);
-                }
                 if (this.peer != null)
                     this.peer.OnNotifyCaretChanged();
-                if (this._Controller.SelectionLength != 0)
-                    this.FirstGripper.Enabled = true;
-                else
-                    this.FirstGripper.Enabled = false;
-
-                this.Refresh();
-                
+                this.Refresh();                
                 return;
             }
 
@@ -915,8 +856,8 @@ namespace FooEditEngine.Metro
                     this._Controller.Scroll(ScrollDirection.Up, scrollCount, false, false);
                 else
                     this._Controller.Scroll(ScrollDirection.Down, scrollCount, false, false);
-                this.FirstGripper.Enabled = false;
-                this.SecondGripper.Enabled = false;
+                this.Document.SelectGrippers.BottomLeft.Enabled = false;
+                this.Document.SelectGrippers.BottomRight.Enabled = false;
                 this.Refresh();
                 return;
             }
@@ -928,8 +869,8 @@ namespace FooEditEngine.Metro
                     this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
                 else
                     this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
-                this.FirstGripper.Enabled = false;
-                this.SecondGripper.Enabled = false;
+                this.Document.SelectGrippers.BottomLeft.Enabled = false;
+                this.Document.SelectGrippers.BottomRight.Enabled = false;
                 this.Refresh();
             }
         }
@@ -984,13 +925,13 @@ namespace FooEditEngine.Metro
         void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)
         {
             bool touched = e.PointerDeviceType == PointerDeviceType.Touch;
-            this.FirstGripper.Enabled = false;
-            this.SecondGripper.Enabled = touched;
+            this.Document.SelectGrippers.BottomLeft.Enabled = false;
+            this.Document.SelectGrippers.BottomRight.Enabled = touched;
             this.JumpCaret(e.Position);
             System.Diagnostics.Debug.WriteLine(e.TapCount);
             if (e.TapCount == 2)
             {
-                this.FirstGripper.Enabled = touched;
+                this.Document.SelectGrippers.BottomLeft.Enabled = touched;
                 //タッチスクリーンでダブルタップした場合、アンカーインデックスを単語の先頭にしないとバグる
                 this.Controller.SelectWord(this.Controller.SelectionStart, touched);
             }
@@ -1052,8 +993,6 @@ namespace FooEditEngine.Metro
                 this.View.Draw(updateRect);
             else
                 this.Render.FillBackground(updateRect);
-            this.FirstGripper.Draw();
-            this.SecondGripper.Draw();
             this.Render.EndDraw();
         }
 
@@ -1116,8 +1055,8 @@ namespace FooEditEngine.Metro
             else
                 toX = -this.horizontalScrollBar.Value;
             this._Controller.Scroll(toX, this.View.Src.Row, false, false);
-            this.FirstGripper.Enabled = false;
-            this.SecondGripper.Enabled = false;
+            this.Document.SelectGrippers.BottomLeft.Enabled = false;
+            this.Document.SelectGrippers.BottomRight.Enabled = false;
             this.Refresh();
         }
 
@@ -1129,8 +1068,8 @@ namespace FooEditEngine.Metro
             if (newRow >= this.View.LayoutLines.Count)
                 return;
             this._Controller.Scroll(this.View.Src.X, newRow, false, false);
-            this.FirstGripper.Enabled = false;
-            this.SecondGripper.Enabled = false;
+            this.Document.SelectGrippers.BottomLeft.Enabled = false;
+            this.Document.SelectGrippers.BottomRight.Enabled = false;
             this.Refresh();
         }
 
@@ -1167,7 +1106,7 @@ namespace FooEditEngine.Metro
             if (e.Property.Equals(InsertModeProperty))
                 source.View.InsertMode = source.InsertMode;
             if (e.Property.Equals(TabCharsProperty))
-                source.View.TabStops = source.TabChars;
+                source.Document.TabStops = source.TabChars;
             if (e.Property.Equals(RectSelectModeProperty))
                 source._Controller.RectSelection = source.RectSelectMode;
             if (e.Property.Equals(DrawCaretProperty))
@@ -1175,10 +1114,7 @@ namespace FooEditEngine.Metro
             if (e.Property.Equals(DrawCaretLineProperty))
                 source.View.HideLineMarker = !source.DrawCaretLine;
             if (e.Property.Equals(DrawLineNumberProperty))
-            {
-                source.View.DrawLineNumber = source.DrawLineNumber;
-                source._Controller.JumpCaret(source.View.CaretPostion.row, source.View.CaretPostion.col);
-            }
+                source.Document.DrawLineNumber = source.DrawLineNumber;
             if(e.Property.Equals(MagnificationPowerPropertyKey))
                 source.Render.FontSize = source.FontSize * source.MagnificationPower;
             if (e.Property.Equals(FontFamilyProperty))
@@ -1216,7 +1152,7 @@ namespace FooEditEngine.Metro
             if (e.Property.Equals(LineMarkerProperty))
                 source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);
             if (e.Property.Equals(MarkURLProperty))
-                source.View.UrlMark = source.MarkURL;
+                source.Document.UrlMark = source.MarkURL;
             if (e.Property.Equals(ShowFullSpaceProperty))
                 source.Render.ShowFullSpace = source.ShowFullSpace;
             if (e.Property.Equals(ShowHalfSpaceProperty))
@@ -1226,23 +1162,23 @@ namespace FooEditEngine.Metro
             if (e.Property.Equals(ShowLineBreakProperty))
                 source.Render.ShowLineBreak = source.ShowLineBreak;
             if (e.Property.Equals(LineBreakProperty))
-                source.View.LineBreak = source.LineBreakMethod;
+                source.Document.LineBreak = source.LineBreakMethod;
             if (e.Property.Equals(LineBreakCharCountProperty))
-                source.View.LineBreakCharCount = source.LineBreakCharCount;
+                source.Document.LineBreakCharCount = source.LineBreakCharCount;
             if (e.Property.Equals(UpdateAreaProperty))
                 source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);
             if (e.Property.Equals(LineNumberProperty))
                 source.Render.LineNumber = D2DRenderBase.ToColor4(source.LineNumber);
             if (e.Property.Equals(FlowDirectionProperty))
             {
-                source.Render.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;
+                source.Document.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;
                 if(source.horizontalScrollBar != null)
                     source.horizontalScrollBar.FlowDirection = source.FlowDirection;
             }
             if (e.Property.Equals(DrawRulerProperty))
             {
-                source.View.HideRuler = !source.DrawRuler;
-                source._Controller.JumpCaret(source.View.CaretPostion.row, source.View.CaretPostion.col);
+                source.Document.HideRuler = !source.DrawRuler;
+                source._Controller.JumpCaret(source.Document.CaretPostion.row, source.Document.CaretPostion.col);
             }
         }
         #endregion
@@ -1321,7 +1257,7 @@ namespace FooEditEngine.Metro
         {
             get
             {
-                return this.View.MarkerPatternSet;
+                return this.Document.MarkerPatternSet;
             }
         }