OSDN Git Service

DPIの設定を変えると変換窓がずれる現象を修正した
[fooeditengine/FooEditEngine.git] / WPF / FooEditEngine / FooTextBox.cs
index 033b099..f25a695 100644 (file)
@@ -73,7 +73,6 @@ namespace FooEditEngine.WPF
             this.textStore = new TextStore();\r
             this.textStore.IsLoading += textStore_IsLoading;\r
             this.textStore.IsReadOnly += textStore_IsReadOnly;\r
-            this.textStore.GetDpi += textStore_GetDpi;\r
             this.textStore.GetStringLength += () => this.Document.Length;\r
             this.textStore.GetString += _textStore_GetString;\r
             this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;\r
@@ -348,6 +347,16 @@ namespace FooEditEngine.WPF
         }\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="tr">TextReader</param>\r
@@ -370,6 +379,7 @@ namespace FooEditEngine.WPF
         {\r
             WinFileReader fs = new WinFileReader(filepath, enc);\r
             await this.LoadAsyncImpl(fs, token);\r
+            fs.Close();\r
         }\r
 \r
         async Task LoadAsyncImpl(WinFileReader fs,System.Threading.CancellationTokenSource token)\r
@@ -397,6 +407,7 @@ namespace FooEditEngine.WPF
             WinFileWriter fs = new WinFileWriter(filepath, enc);\r
             fs.NewLine = newLine;\r
             await this.Document.SaveAsync(fs, token);\r
+            fs.Close();\r
         }\r
 \r
         /// <summary>\r
@@ -429,19 +440,15 @@ namespace FooEditEngine.WPF
         \r
         void Refresh(Rectangle updateRect)\r
         {\r
-            if (this.disposed)\r
+            if (this.disposed || this.Visibility == Visibility.Collapsed)\r
                 return;\r
 \r
-            this.timer.Stop();\r
-\r
             this.Render.BegineDraw();\r
             if (this.IsEnabled)\r
                 this.View.Draw(updateRect);\r
             else\r
                 this.Render.FillBackground(updateRect);\r
             this.Render.EndDraw();\r
-\r
-            this.timer.Start();\r
         }\r
 \r
         #region Commands\r
@@ -533,13 +540,6 @@ namespace FooEditEngine.WPF
             get { return this.textStore; }\r
         }\r
 \r
-        double textStore_GetDpi()\r
-        {\r
-            float dpi;\r
-            this.Render.GetDpi(out dpi, out dpi);\r
-            return dpi;\r
-        }\r
-\r
         bool textStore_IsReadOnly()\r
         {\r
             return false;\r
@@ -593,8 +593,12 @@ namespace FooEditEngine.WPF
             Point startPos, endPos;\r
             TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);\r
 \r
-            startPos = PointToScreen(this.TranslatePoint(startPos, this));\r
-            endPos = PointToScreen(this.TranslatePoint(endPos, this));\r
+            float dpi;\r
+            this.Render.GetDpi(out dpi, out dpi);\r
+            double scale = dpi / 96.0;\r
+            \r
+            startPos = PointToScreen(this.TranslatePoint(startPos.Scale(scale), this));\r
+            endPos = PointToScreen(this.TranslatePoint(endPos.Scale(scale), this));\r
             \r
             o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);\r
             o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);\r
@@ -623,7 +627,7 @@ namespace FooEditEngine.WPF
             this.Refresh();\r
         }\r
 \r
-        void _textStore_InsertAtSelection(string i_value)\r
+        void _textStore_InsertAtSelection(string i_value, ref int o_startIndex, ref int o_endIndex)\r
         {\r
             TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);\r
             this.Refresh();\r
@@ -1049,6 +1053,8 @@ namespace FooEditEngine.WPF
         void FooTextBox_Loaded(object sender, RoutedEventArgs e)\r
         {\r
             this.Resize(this.image.ActualWidth, this.image.ActualHeight);\r
+            this.Focus();\r
+            this.timer.Start();\r
         }\r
 \r
         bool Resize(double width, double height)\r
@@ -1082,6 +1088,9 @@ namespace FooEditEngine.WPF
         {\r
             switch (e.Property.Name)\r
             {\r
+                case "IndentMode":\r
+                    this._Controller.IndentMode = this.IndentMode;\r
+                    break;\r
                 case "Selection":\r
                     if(!this.nowCaretMove)\r
                         this.Select(this.Selection.Index, this.Selection.Length);\r
@@ -1192,6 +1201,9 @@ namespace FooEditEngine.WPF
                 case "UpdateArea":\r
                     this.Render.UpdateArea = D2DRender.ToColor4(this.UpdateArea);\r
                     break;\r
+                case "LineNumber":\r
+                    this.Render.LineNumber = D2DRender.ToColor4(this.LineNumber);\r
+                    break;\r
             }\r
             base.OnPropertyChanged(e);\r
         }\r
@@ -1299,6 +1311,21 @@ namespace FooEditEngine.WPF
         }\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));\r
+\r
+        /// <summary>\r
         /// 選択範囲を表す\r
         /// </summary>\r
         /// <remarks>\r
@@ -1550,13 +1577,28 @@ namespace FooEditEngine.WPF
             get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }\r
             set { SetValue(OverwriteCaretProperty, value); }\r
         }\r
-\r
+        \r
         /// <summary>\r
         /// OverwriteCaretの依存プロパティを表す\r
         /// </summary>\r
         public static readonly DependencyProperty OverwriteCaretProperty =\r
             DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));\r
-        \r
+\r
+        /// <summary>\r
+        /// 行番号の色を表す\r
+        /// </summary>\r
+        public System.Windows.Media.Color LineNumber\r
+        {\r
+            get { return (System.Windows.Media.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(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray));\r
+\r
         /// <summary>\r
         /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです\r
         /// </summary>\r