OSDN Git Service

行番号が表示されないバグを修正した
[fooeditengine/FooEditEngine.git] / Metro / FooEditEngine / FooTextBox.cs
index f269cb9..79ca99b 100644 (file)
@@ -9,6 +9,7 @@
 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.\r
  */\r
 using System;\r
+using System.Text;\r
 using System.ComponentModel;\r
 using System.Threading.Tasks;\r
 using Windows.ApplicationModel.Resources.Core;\r
@@ -71,14 +72,14 @@ namespace FooEditEngine.Metro
             this.textStore.CompositionUpdated += textStore_CompositionUpdated;\r
             this.textStore.CompositionEnded += textStore_CompositionEnded;\r
 \r
-            this.Document = new Document();\r
-            DocumentExtend.Progress += Document_Progress;\r
-\r
             this.rectangle = new Windows.UI.Xaml.Shapes.Rectangle();\r
             this.rectangle.Margin = this.Padding;\r
             this.Render = new D2DRender(this,this.rectangle,this.textStore);\r
 \r
-            this.View = new EditView(this.Document, this.Render, new Padding(Gripper.GripperWidth / 2, Gripper.GripperWidth, Gripper.GripperWidth / 2, Gripper.GripperWidth));\r
+            this.Document = new Document();\r
+            this.Document.LayoutLines.Render = this.Render;\r
+\r
+            this.View = new EditView(this.Document, this.Render, new Padding(5, Gripper.HitAreaWidth, Gripper.HitAreaWidth / 2, Gripper.HitAreaWidth));\r
             this.View.SrcChanged += View_SrcChanged;\r
             this.View.InsertMode = this.InsertMode;\r
             this.View.DrawLineNumber = this.DrawLineNumber;\r
@@ -145,7 +146,6 @@ namespace FooEditEngine.Metro
                 this.View.Dispose();\r
                 this.Render.Dispose();\r
             }\r
-            DocumentExtend.Progress -= this.Document_Progress;\r
         }\r
 \r
         /// <summary>\r
@@ -319,6 +319,47 @@ namespace FooEditEngine.Metro
             this.View.PerfomLayouts();\r
         }\r
 \r
+        /// <summary>\r
+        /// 指定行までスクロールする\r
+        /// </summary>\r
+        /// <param name="row">行</param>\r
+        /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>\r
+        public void ScrollIntoView(int row, bool alignTop)\r
+        {\r
+            this.View.ScrollIntoView(row, alignTop);\r
+        }\r
+\r
+        /// <summary>\r
+        /// ファイルからドキュメントを構築する\r
+        /// </summary>\r
+        /// <param name="sr">StremReader</param>\r
+        /// <returns>Taskオブジェクト</returns>\r
+        public async Task LoadFileAsync(System.IO.StreamReader sr, System.Threading.CancellationTokenSource token)\r
+        {\r
+            this.IsEnabled = false;\r
+            this.View.LayoutLines.IsFrozneDirtyFlag = true;\r
+            WinFileReader fs = new WinFileReader(sr);\r
+            await this.Document.LoadAsync(fs, token);\r
+            this.View.LayoutLines.IsFrozneDirtyFlag = false;\r
+            TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);\r
+            if (this.verticalScrollBar != null)\r
+                this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;\r
+            this.View.CalculateLineCountOnScreen();\r
+            this.IsEnabled = true;\r
+        }\r
+\r
+        /// <summary>\r
+        /// ドキュメントの内容をファイルに保存する\r
+        /// </summary>\r
+        /// <param name="sw">StreamWriter</param>\r
+        /// <param name="enc">エンコード</param>\r
+        /// <returns>Taskオブジェクト</returns>\r
+        public async Task SaveFile(System.IO.StreamWriter sw, System.Threading.CancellationTokenSource token)\r
+        {\r
+            WinFileWriter fs = new WinFileWriter(sw);\r
+            await this.Document.SaveAsync(fs, token);\r
+        }\r
+\r
         #region command\r
         void CopyCommand()\r
         {\r
@@ -708,7 +749,7 @@ namespace FooEditEngine.Metro
             this.Refresh();\r
         }\r
 \r
-        void _textStore_InsertAtSelection(string i_value)\r
+        void _textStore_InsertAtSelection(string i_value,ref int o_stratIndex,ref int o_endIndex)\r
         {\r
             TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);\r
             this.Refresh();\r
@@ -780,11 +821,16 @@ namespace FooEditEngine.Metro
                         else\r
                             this._Controller.MoveCaretAndSelect(tp);\r
                     }\r
-                    if (this.peer != null)\r
-                        this.peer.OnNotifyCaretChanged();\r
-                    this.Refresh();\r
-                    return;\r
                 }\r
+                else\r
+                {\r
+                    TextPoint tp = this.View.GetTextPointFromPostion(p);\r
+                    this._Controller.MoveCaretAndSelect(tp);\r
+                }\r
+                if (this.peer != null)\r
+                    this.peer.OnNotifyCaretChanged();\r
+                this.Refresh();\r
+                return;\r
             }\r
             if (e.Delta.Scale < 1)\r
             {\r
@@ -917,6 +963,7 @@ namespace FooEditEngine.Metro
             if (this.peer != null)\r
                 this.peer.OnNotifyCaretChanged();\r
             this.View.IsFocused = true;\r
+            this.Focus(FocusState.Programmatic);\r
             this.Refresh();\r
         }\r
 \r
@@ -940,10 +987,10 @@ namespace FooEditEngine.Metro
         }\r
         void Refresh(Rectangle updateRect)\r
         {\r
-            if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0/* || !this.Render.IsCanDraw()*/)\r
+            if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0 || this.Visibility == Windows.UI.Xaml.Visibility.Collapsed)\r
                 return;\r
 \r
-            this.Render.BeginDraw();\r
+            this.Render.BegineDraw();\r
             if (this.IsEnabled)\r
                 this.View.Draw(updateRect);\r
             else\r
@@ -1037,19 +1084,6 @@ namespace FooEditEngine.Metro
             TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);\r
         }\r
 \r
-        void Document_Progress(object sender, ProgressEventArgs e)\r
-        {\r
-            switch (e.state)\r
-            {\r
-                case ProgressState.Complete:\r
-                    TextStoreHelper.NotifyTextChanged(this.textStore,0,0,this.Document.Length);\r
-                    if (this.verticalScrollBar != null)\r
-                        this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;\r
-                    this.View.CalculateLineCountOnScreen();\r
-                    break;\r
-            }\r
-        }\r
-\r
         void FooTextBox_Loaded(object sender, RoutedEventArgs e)\r
         {\r
             this.Focus(FocusState.Programmatic);\r
@@ -1059,6 +1093,8 @@ namespace FooEditEngine.Metro
         public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)\r
         {\r
             FooTextBox source = (FooTextBox)sender;\r
+            if (e.Property.Equals(IndentModeProperty))\r
+                source.Controller.IndentMode = source.IndentMode;\r
             if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)\r
                 source._Controller.Select(source.Selection.Index,source.Selection.Length);\r
             if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)\r
@@ -1089,31 +1125,31 @@ namespace FooEditEngine.Metro
             if (e.Property.Equals(FontSizeProperty))\r
                 source.Render.FontSize = source.FontSize;\r
             if (e.Property.Equals(ForegroundProperty))\r
-                source.Render.Foreground = source.Foreground;\r
+                source.Render.Foreground = D2DRenderBase.ToColor4(source.Foreground);\r
             if (e.Property.Equals(BackgroundProperty))\r
-                source.Render.Background = source.Background;\r
+                source.Render.Background = D2DRenderBase.ToColor4(source.Background);\r
             if (e.Property.Equals(ControlCharProperty))\r
-                source.Render.ControlChar = source.ControlChar;\r
+                source.Render.ControlChar = D2DRenderBase.ToColor4(source.ControlChar);\r
             if (e.Property.Equals(HilightProperty))\r
-                source.Render.Hilight = source.Hilight;\r
+                source.Render.Hilight = D2DRenderBase.ToColor4(source.Hilight);\r
             if (e.Property.Equals(Keyword1Property))\r
-                source.Render.Keyword1 = source.Keyword1;\r
+                source.Render.Keyword1 = D2DRenderBase.ToColor4(source.Keyword1);\r
             if (e.Property.Equals(Keyword2Property))\r
-                source.Render.Keyword2 = source.Keyword2;\r
+                source.Render.Keyword2 = D2DRenderBase.ToColor4(source.Keyword2);\r
             if (e.Property.Equals(CommentProperty))\r
-                source.Render.Comment = source.Comment;\r
+                source.Render.Comment = D2DRenderBase.ToColor4(source.Comment);\r
             if (e.Property.Equals(LiteralProperty))\r
-                source.Render.Literal = source.Literal;\r
+                source.Render.Literal = D2DRenderBase.ToColor4(source.Literal);\r
             if (e.Property.Equals(URLProperty))\r
-                source.Render.Url = source.URL;\r
+                source.Render.Url = D2DRenderBase.ToColor4(source.URL);\r
             if (e.Property.Equals(InsertCaretProperty))\r
-                source.Render.InsertCaret = source.InsertCaret;\r
+                source.Render.InsertCaret = D2DRenderBase.ToColor4(source.InsertCaret);\r
             if (e.Property.Equals(OverwriteCaretProperty))\r
-                source.Render.OverwriteCaret = source.OverwriteCaret;\r
+                source.Render.OverwriteCaret = D2DRenderBase.ToColor4(source.OverwriteCaret);\r
             if (e.Property.Equals(PaddingProperty))\r
                 source.View.Padding = new Padding((int)source.Padding.Left, (int)source.Padding.Top, (int)source.Padding.Right, (int)source.Padding.Bottom);\r
             if (e.Property.Equals(LineMarkerProperty))\r
-                source.Render.LineMarker = source.LineMarker;\r
+                source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);\r
             if (e.Property.Equals(MarkURLProperty))\r
                 source.View.UrlMark = source.MarkURL;\r
             if (e.Property.Equals(ShowFullSpaceProperty))\r
@@ -1128,6 +1164,10 @@ namespace FooEditEngine.Metro
                 source.View.LineBreak = source.LineBreakMethod;\r
             if (e.Property.Equals(LineBreakCharCountProperty))\r
                 source.View.LineBreakCharCount = source.LineBreakCharCount;\r
+            if (e.Property.Equals(UpdateAreaProperty))\r
+                source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);\r
+            if (e.Property.Equals(LineNumberProperty))\r
+                source.Render.LineNumber = D2DRenderBase.ToColor4(source.LineNumber);\r
             if (e.Property.Equals(FlowDirectionProperty))\r
             {\r
                 source.Render.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;\r
@@ -1138,7 +1178,7 @@ namespace FooEditEngine.Metro
             {\r
                 source.View.HideRuler = !source.DrawRuler;\r
                 source._Controller.JumpCaret(source.View.CaretPostion.row, source.View.CaretPostion.col);\r
-            }            \r
+            }\r
         }\r
         #endregion\r
 \r
@@ -1254,6 +1294,21 @@ namespace FooEditEngine.Metro
         }\r
 \r
         /// <summary>\r
+        /// インデントの方法を表す\r
+        /// </summary>\r
+        public IndentMode IndentMode\r
+        {\r
+            get { return (IndentMode)GetValue(IndentModeProperty); }\r
+            set { SetValue(IndentModeProperty, value); }\r
+        }\r
+\r
+        /// <summary>\r
+        /// IndentModeの依存プロパティを表す\r
+        /// </summary>\r
+        public static readonly DependencyProperty IndentModeProperty =\r
+            DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab,OnPropertyChanged));\r
+\r
+        /// <summary>\r
         /// 選択範囲を表す\r
         /// </summary>\r
         /// <remarks>\r
@@ -1509,6 +1564,20 @@ namespace FooEditEngine.Metro
         public static readonly DependencyProperty URLProperty =\r
             DependencyProperty.Register("URL", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));\r
 \r
+        /// <summary>\r
+        /// 行更新フラグの色を表す\r
+        /// </summary>\r
+        public Windows.UI.Color UpdateArea\r
+        {\r
+            get { return (Windows.UI.Color)GetValue(UpdateAreaProperty); }\r
+            set { SetValue(UpdateAreaProperty, value); }\r
+        }\r
+\r
+        /// <summary>\r
+        /// UpdateAreaの依存プロパティを表す\r
+        /// </summary>\r
+        public static readonly DependencyProperty UpdateAreaProperty =\r
+            DependencyProperty.Register("UpdateArea", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));\r
 \r
         /// <summary>\r
         /// ラインマーカーの色を表す\r
@@ -1556,6 +1625,21 @@ namespace FooEditEngine.Metro
             DependencyProperty.Register("OverwriteCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));\r
 \r
         /// <summary>\r
+        /// 行番号の色を表す\r
+        /// </summary>\r
+        public Windows.UI.Color LineNumber\r
+        {\r
+            get { return (Windows.UI.Color)GetValue(LineNumberProperty); }\r
+            set { SetValue(LineNumberProperty, value); }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Using a DependencyProperty as the backing store for LineNumber.  This enables animation, styling, binding, etc...\r
+        /// </summary>\r
+        public static readonly DependencyProperty LineNumberProperty =\r
+            DependencyProperty.Register("LineNumber", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray,OnPropertyChanged));\r
+\r
+        /// <summary>\r
         /// 余白を表す\r
         /// </summary>\r
         public new Thickness Padding\r