OSDN Git Service

ファイルを保存できない問題を解決した
[fooeditengine/FooEditEngine.git] / WPF / FooEditEngine / FooTextBox.cs
index af6ab2b..17084f7 100644 (file)
@@ -9,6 +9,8 @@
 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.Threading.Tasks;\r
 using System.Runtime.InteropServices;\r
 using System.Windows;\r
 using System.Windows.Input;\r
@@ -49,6 +51,7 @@ namespace FooEditEngine.WPF
         DispatcherTimer timer;\r
         bool disposed = false;\r
         FooTextBoxAutomationPeer peer;\r
+        bool nowCaretMove = false;\r
         \r
         static FooTextBox()\r
         {\r
@@ -70,6 +73,7 @@ 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
@@ -82,15 +86,15 @@ namespace FooEditEngine.WPF
             this.textStore.CompositionUpdated += textStore_CompositionUpdated;\r
             this.textStore.CompositionEnded += textStore_CompositionEnded;\r
 \r
-            this.Document = new Document();\r
-            this.Document.Progress += Document_Progress;\r
-\r
             this.Render = new D2DRender(this, 200, 200,this.image);\r
             this.Render.ShowFullSpace = this.ShowFullSpace;\r
             this.Render.ShowHalfSpace = this.ShowHalfSpace;\r
             this.Render.ShowTab = this.ShowTab;\r
 \r
-            this.View = new EditView(this.Document, this.Render,new Margin(5,5,5,5));\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, 5, 5, 5));\r
             this.View.SrcChanged += View_SrcChanged;\r
             this.View.InsertMode = this.InsertMode;\r
             this.View.DrawLineNumber = this.DrawLineNumber;\r
@@ -101,7 +105,7 @@ namespace FooEditEngine.WPF
             this.View.TabStops = this.TabChars;\r
 \r
             this._Controller = new Controller(this.Document, this.View);\r
-            this._Controller.CaretMoved += new EventHandler(Controller_CaretMoved);\r
+            this._Controller.SelectionChanged += new EventHandler(Controller_SelectionChanged);\r
 \r
             //Viewを作成した後に追加しないと例外が発生する\r
             this.Document.Update += new DocumentUpdateEventHandler(Document_Update);\r
@@ -139,6 +143,8 @@ namespace FooEditEngine.WPF
             SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);\r
 \r
             this.SystemEvents_UserPreferenceChanged(null, new UserPreferenceChangedEventArgs(UserPreferenceCategory.Keyboard));\r
+\r
+            this.CaretMoved += (s, e) => { };\r
         }\r
 \r
         /// <summary>\r
@@ -195,8 +201,6 @@ namespace FooEditEngine.WPF
         /// <param name="length">長さ</param>\r
         public void Select(int start, int length)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this._Controller.Select(start, length);\r
             this.textStore.NotifySelectionChanged();\r
         }\r
@@ -208,8 +212,6 @@ namespace FooEditEngine.WPF
         /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>\r
         public void JumpCaret(int index)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this._Controller.JumpCaret(index);\r
         }\r
         /// <summary>\r
@@ -220,8 +222,6 @@ namespace FooEditEngine.WPF
         /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>\r
         public void JumpCaret(int row, int col)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this._Controller.JumpCaret(row, col);\r
         }\r
 \r
@@ -230,8 +230,6 @@ namespace FooEditEngine.WPF
         /// </summary>\r
         public void Copy()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             string text = this._Controller.SelectedText;\r
             if (text != null && text != string.Empty)\r
                 Clipboard.SetText(text);\r
@@ -242,8 +240,6 @@ namespace FooEditEngine.WPF
         /// </summary>\r
         public void Cut()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             string text = this._Controller.SelectedText;\r
             if (text != null && text != string.Empty)\r
             {\r
@@ -257,8 +253,6 @@ namespace FooEditEngine.WPF
         /// </summary>\r
         public void Paste()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (Clipboard.ContainsText() == false)\r
                 return;\r
             string text = Clipboard.GetText();\r
@@ -270,8 +264,6 @@ namespace FooEditEngine.WPF
         /// </summary>\r
         public void DeSelectAll()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this._Controller.DeSelectAll();\r
             this.textStore.NotifySelectionChanged();\r
         }\r
@@ -284,8 +276,6 @@ namespace FooEditEngine.WPF
         /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>\r
         public System.Windows.Point GetPostionFromTextPoint(TextPoint tp)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             return this.View.GetPostionFromTextPoint(tp);\r
@@ -298,8 +288,6 @@ namespace FooEditEngine.WPF
         /// <returns>テキストポイント</returns>\r
         public TextPoint GetTextPointFromPostion(System.Windows.Point p)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             return this.View.GetTextPointFromPostion(p);\r
@@ -312,11 +300,9 @@ namespace FooEditEngine.WPF
         /// <returns>行の高さ</returns>\r
         public double GetLineHeight(int row)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
-            return this.View.LayoutLines.GetData(row).Layout.Height;;\r
+            return this.View.LayoutLines.GetLayout(row).Height;;\r
         }\r
 \r
         /// <summary>\r
@@ -326,8 +312,6 @@ namespace FooEditEngine.WPF
         /// <returns>座標を返す</returns>\r
         public System.Windows.Point GetPostionFromIndex(int index)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             TextPoint tp = this.View.GetLayoutLineFromIndex(index);\r
@@ -341,8 +325,6 @@ namespace FooEditEngine.WPF
         /// <returns>インデックスを返す</returns>\r
         public int GetIndexFromPostion(System.Windows.Point p)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             TextPoint tp = this.View.GetTextPointFromPostion(p);\r
@@ -366,15 +348,69 @@ namespace FooEditEngine.WPF
         }\r
 \r
         /// <summary>\r
+        /// ストリームからドキュメントを構築する\r
+        /// </summary>\r
+        /// <param name="tr">TextReader</param>\r
+        /// <param name="token">キャンセル用トークン</param>\r
+        /// <returns>Taskオブジェクト</returns>\r
+        public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)\r
+        {\r
+            WinFileReader fs = new WinFileReader(tr);\r
+            await this.LoadAsyncImpl(fs, token);\r
+        }\r
+\r
+        /// <summary>\r
+        /// ファイルからドキュメントを構築する\r
+        /// </summary>\r
+        /// <param name="filepath">ファイルパス</param>\r
+        /// <param name="enc">エンコード</param>\r
+        /// <param name="token">キャンセル用トークン</param>\r
+        /// <returns>Taskオブジェクト</returns>\r
+        public async Task LoadFileAsync(string filepath, Encoding enc,System.Threading.CancellationTokenSource token)\r
+        {\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
+        {\r
+            this.IsEnabled = false;\r
+            this.View.LayoutLines.IsFrozneDirtyFlag = true;\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="filepath">ファイルパス</param>\r
+        /// <param name="newLine">改行コード</param>\r
+        /// <param name="enc">エンコード</param>\r
+        /// <returns>Taskオブジェクト</returns>\r
+        public async Task SaveFile(string filepath, Encoding enc,string newLine, System.Threading.CancellationTokenSource token)\r
+        {\r
+            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
         /// アンマネージドリソースを開放する\r
         /// </summary>\r
         public void Dispose()\r
         {\r
-            this.disposed = true;\r
             if (this.disposed)\r
                 return;\r
             this.Dispose(true);\r
             GC.SuppressFinalize(this);\r
+            this.disposed = true;\r
         }\r
 \r
         /// <summary>\r
@@ -401,7 +437,7 @@ namespace FooEditEngine.WPF
             this.timer.Stop();\r
 \r
             this.Render.BegineDraw();\r
-            if (this.Document.State != AsyncState.Loading)\r
+            if (this.IsEnabled)\r
                 this.View.Draw(updateRect);\r
             else\r
                 this.Render.FillBackground(updateRect);\r
@@ -413,7 +449,7 @@ namespace FooEditEngine.WPF
         #region Commands\r
         void CanExecute(object sender, CanExecuteRoutedEventArgs e)\r
         {\r
-            e.CanExecute = this.Document.State != FooEditEngine.AsyncState.Loading;\r
+            e.CanExecute = this.IsEnabled;\r
         }\r
 \r
         void ToggleCodePointCommand(object sender, RoutedEventArgs e)\r
@@ -499,6 +535,13 @@ 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
@@ -506,7 +549,7 @@ namespace FooEditEngine.WPF
 \r
         bool textStore_IsLoading()\r
         {\r
-            return this.Document.State == AsyncState.Loading;\r
+            return false;\r
         }\r
 \r
         void textStore_CompositionEnded()\r
@@ -578,8 +621,6 @@ namespace FooEditEngine.WPF
 \r
         void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);\r
             this.Refresh();\r
         }\r
@@ -598,7 +639,7 @@ namespace FooEditEngine.WPF
         {\r
             base.OnGotKeyboardFocus(e);\r
             this.textStore.SetFocus();\r
-            this.DrawCaret = true;\r
+            this.View.IsFocused = true;\r
             this.Refresh();\r
         }\r
 \r
@@ -609,11 +650,16 @@ namespace FooEditEngine.WPF
         protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)\r
         {\r
             base.OnLostKeyboardFocus(e);\r
-            this.DrawCaret = false;\r
+            this.View.IsFocused = false;\r
             this.Refresh();\r
         }\r
         #endregion\r
         #region Event\r
+        /// <summary>\r
+        /// キャレットが移動したときに通知されるイベント\r
+        /// </summary>\r
+        public event EventHandler CaretMoved;\r
+\r
         /// <inheritdoc/>\r
         protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()\r
         {\r
@@ -625,8 +671,6 @@ namespace FooEditEngine.WPF
         /// <inheritdoc/>\r
         protected override void OnTextInput(TextCompositionEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             if (e.Text == "\r")\r
             {\r
                 this._Controller.DoEnterAction();\r
@@ -638,18 +682,28 @@ namespace FooEditEngine.WPF
             }\r
             else\r
             {\r
-                this._Controller.DoInputString(e.Text);\r
+                if(this.IsInputString(e.Text))\r
+                    this._Controller.DoInputString(e.Text);\r
             }\r
             this.Refresh();\r
             base.OnTextInput(e);\r
             e.Handled = true;\r
         }\r
 \r
+        bool IsInputString(string s)\r
+        {\r
+            foreach (char charCode in s)\r
+            {\r
+                if ((0x20 <= charCode && charCode <= 0x7e)\r
+                    || 0x7f < charCode)\r
+                    return true;\r
+            }\r
+            return false;\r
+        }\r
+\r
         /// <inheritdoc/>\r
         protected override void OnKeyDown(KeyEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             if (this.textStore.IsLocked())\r
                 return;\r
 \r
@@ -658,37 +712,25 @@ namespace FooEditEngine.WPF
             switch (e.Key)\r
             {\r
                 case Key.Up:\r
-                    if (!this._Controller.IsCanMoveCaret(-1,MoveFlow.Vertical))\r
-                        System.Media.SystemSounds.Beep.Play();\r
-                    else\r
-                        this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));\r
+                    this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));\r
                     this.Refresh();\r
                     e.Handled = true;\r
                     movedCaret = true;\r
                     break;\r
                 case Key.Down:\r
-                    if (!this._Controller.IsCanMoveCaret(+1, MoveFlow.Vertical))\r
-                        System.Media.SystemSounds.Beep.Play();\r
-                    else\r
-                        this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));\r
+                    this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));\r
                     this.Refresh();\r
                     e.Handled = true;\r
                     movedCaret = true;\r
                     break;\r
                 case Key.Left:\r
-                    if (!this._Controller.IsCanMoveCaret(-1, MoveFlow.Horizontical))\r
-                        System.Media.SystemSounds.Beep.Play();\r
-                    else\r
-                        this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));\r
+                    this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));\r
                     this.Refresh();\r
                     e.Handled = true;\r
                     movedCaret = true;\r
                     break;\r
                 case Key.Right:\r
-                    if (!this._Controller.IsCanMoveCaret(1, MoveFlow.Horizontical))\r
-                        System.Media.SystemSounds.Beep.Play();\r
-                    else\r
-                        this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));\r
+                    this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));\r
                     this.Refresh();\r
                     e.Handled = true;\r
                     movedCaret = true;\r
@@ -707,7 +749,7 @@ namespace FooEditEngine.WPF
                     if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))\r
                         this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));\r
                     else\r
-                        this._Controller.JumpCaret(this.View.CaretPostion.row, 0);\r
+                        this._Controller.JumpToLineHead(this.View.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));\r
                     this.Refresh();\r
                     movedCaret = true;\r
                     break;\r
@@ -715,13 +757,13 @@ namespace FooEditEngine.WPF
                     if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))\r
                         this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));\r
                     else\r
-                        this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.LayoutLines[this.View.CaretPostion.row].Length - 1);\r
+                        this._Controller.JumpToLineEnd(this.View.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));\r
                     this.Refresh();\r
                     movedCaret = true;\r
                     break;\r
                 case Key.Tab:\r
                     int oldLength = this.Document.Length;\r
-                    if (this.SelectionLength == 0)\r
+                    if (this.Selection.Length == 0)\r
                         this._Controller.DoInputChar('\t');\r
                     else if(this.IsPressedModifierKey(modiferKeys,ModifierKeys.Shift))\r
                         this._Controller.DownIndent();\r
@@ -755,8 +797,6 @@ namespace FooEditEngine.WPF
         /// </remarks>\r
         protected override void OnMouseDoubleClick(MouseButtonEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             System.Windows.Point p = e.GetPosition(this);\r
             TextPoint tp = this.View.GetTextPointFromPostion(p);\r
             if (tp == TextPoint.Null)\r
@@ -795,9 +835,6 @@ namespace FooEditEngine.WPF
         /// </remarks>\r
         protected override void OnMouseDown(MouseButtonEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
-            \r
             System.Windows.Point p = e.GetPosition(this);\r
             TextPoint tp = this.View.GetTextPointFromPostion(p);\r
             if (tp == TextPoint.Null)\r
@@ -832,8 +869,9 @@ namespace FooEditEngine.WPF
                 }\r
                 if (this.peer != null)\r
                     this.peer.OnNotifyCaretChanged();\r
-                this.Refresh();\r
+                this.View.IsFocused = true;\r
                 this.Focus();\r
+                this.Refresh();\r
             }\r
         }\r
 \r
@@ -847,12 +885,6 @@ namespace FooEditEngine.WPF
         /// </remarks>\r
         protected override void  OnMouseMove(MouseEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-            {\r
-                this.Cursor = Cursors.Wait;\r
-                base.OnMouseMove(e);\r
-                return;\r
-            }\r
             System.Windows.Point p = e.GetPosition(this);\r
             TextPoint tp = this.View.GetTextPointFromPostion(p);\r
             if (tp == TextPoint.Null)\r
@@ -893,8 +925,6 @@ namespace FooEditEngine.WPF
         /// <inheritdoc/>\r
         protected override void OnMouseWheel(MouseWheelEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             if(Keyboard.Modifiers == ModifierKeys.None)\r
             {\r
                 if (e.Delta > 0)\r
@@ -936,43 +966,22 @@ namespace FooEditEngine.WPF
 \r
         void Document_Update(object sender, DocumentUpdateEventArgs e)\r
         {\r
-            if (this.textStore.IsLocked() || e.type == UpdateType.Clear)\r
-                return;\r
-            if(e.removeLength == 0)\r
-                this.textStore.NotifyTextChanged(e.startIndex,e.startIndex,e.startIndex + e.insertLength);\r
-            else\r
-                this.textStore.NotifyTextChanged(e.startIndex,e.startIndex + 1,e.startIndex + e.insertLength - e.removeLength);\r
-        }\r
-\r
-        void Document_Progress(object sender, ProgressEventArgs e)\r
-        {\r
-            if (this.Document.State == AsyncState.Loading)\r
+            if (this.textStore.IsLocked())\r
                 return;\r
-            switch (e.state)\r
-            {\r
-                case ProgressState.Start:\r
-                    this.textStore.NotifyTextChanged(0, this.Document.Length, 0);\r
-                    break;\r
-                case ProgressState.Complete:\r
-                    this.textStore.NotifyTextChanged(0, 0, this.Document.Length);\r
-                    this.OnMouseMove(new MouseEventArgs(Mouse.PrimaryDevice, new TimeSpan(DateTime.Now.Ticks).Milliseconds));\r
-                    if(this.verticalScrollBar != null)\r
-                        this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;\r
-                    break;\r
-            }\r
+            TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);\r
         }\r
 \r
         void timer_Tick(object sender, EventArgs e)\r
         {\r
             if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)\r
                 return;\r
-            if (this.Document.State == AsyncState.Loading || this.Resize(this.image.ActualWidth, this.image.ActualHeight))\r
+            if (this.Resize(this.image.ActualWidth, this.image.ActualHeight))\r
             {\r
                 this.Refresh();\r
                 return;\r
             } \r
             \r
-            ITextLayout layout = this.View.LayoutLines.GetData(this.View.CaretPostion.row).Layout;\r
+            ITextLayout layout = this.View.LayoutLines.GetLayout(this.View.CaretPostion.row);\r
             double width = layout.GetWidthFromIndex(this.View.CaretPostion.col);\r
             if (width == 0.0)\r
                 width = this.View.CaretWidthOnInsertMode;\r
@@ -988,8 +997,6 @@ namespace FooEditEngine.WPF
 \r
         void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             if (this.horizontalScrollBar == null)\r
                 return;\r
             double toX;\r
@@ -1003,8 +1010,6 @@ namespace FooEditEngine.WPF
 \r
         void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             if (this.verticalScrollBar == null)\r
                 return;\r
             int newRow = (int)this.verticalScrollBar.Value;\r
@@ -1030,10 +1035,15 @@ namespace FooEditEngine.WPF
                 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);\r
         }\r
 \r
-        void Controller_CaretMoved(object sender, EventArgs e)\r
+        void Controller_SelectionChanged(object sender, EventArgs e)\r
         {\r
             this.View.CaretBlink = this.View.CaretBlink;\r
-            SetValue(CaretPostionPropertyKey, this.View.CaretPostion);\r
+            this.CaretMoved(this, null);\r
+            //こうしないと選択できなくなってしまう\r
+            this.nowCaretMove = true;\r
+            SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));\r
+            SetValue(CaretPostionProperty, this.View.CaretPostion);\r
+            this.nowCaretMove = false;            \r
             if(this.textStore.IsLocked() == false)\r
                 this.textStore.NotifySelectionChanged();\r
         }\r
@@ -1047,7 +1057,7 @@ namespace FooEditEngine.WPF
         {\r
             if (width == 0 || height == 0)\r
                 throw new ArgumentOutOfRangeException();\r
-            if (this.Render.Resize(width, height) && this.Document.State != AsyncState.Loading)\r
+            if (this.Render.Resize(width, height))\r
             {\r
                 this.View.PageBound = new Rectangle(0, 0, width, height);\r
 \r
@@ -1074,6 +1084,14 @@ namespace FooEditEngine.WPF
         {\r
             switch (e.Property.Name)\r
             {\r
+                case "Selection":\r
+                    if(!this.nowCaretMove)\r
+                        this.Select(this.Selection.Index, this.Selection.Length);\r
+                    break;\r
+                case "CaretPostion":\r
+                    if (!this.nowCaretMove)\r
+                        this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);\r
+                    break;\r
                 case "LineBreakMethod":\r
                     this.View.LineBreak = this.LineBreakMethod;\r
                     break;\r
@@ -1112,40 +1130,43 @@ namespace FooEditEngine.WPF
                     this.Render.FontWeigth = this.FontWeight;\r
                     break;\r
                 case "Foreground":\r
-                    this.Render.Foreground = this.Foreground;\r
+                    this.Render.Foreground = D2DRender.ToColor4(this.Foreground);\r
                     break;\r
                 case "Background":\r
-                    this.Render.Background = this.Background;\r
+                    this.Render.Background = D2DRender.ToColor4(this.Background);\r
                     break;\r
                 case "ControlChar":\r
-                    this.Render.ControlChar = this.ControlChar;\r
+                    this.Render.ControlChar =D2DRender.ToColor4( this.ControlChar);\r
                     break;\r
                 case "Hilight":\r
-                    this.Render.Hilight = this.Hilight;\r
+                    this.Render.Hilight = D2DRender.ToColor4(this.Hilight);\r
                     break;\r
                 case "Keyword1":\r
-                    this.Render.Keyword1 = this.Keyword1;\r
+                    this.Render.Keyword1 = D2DRender.ToColor4(this.Keyword1);\r
                     break;\r
                 case "Keyword2":\r
-                    this.Render.Keyword2 = this.Keyword2;\r
+                    this.Render.Keyword2 = D2DRender.ToColor4(this.Keyword2);\r
                     break;\r
                 case "Comment":\r
-                    this.Render.Comment = this.Comment;\r
+                    this.Render.Comment = D2DRender.ToColor4(this.Comment);\r
                     break;\r
                 case "Literal":\r
-                    this.Render.Literal = this.Literal;\r
+                    this.Render.Literal = D2DRender.ToColor4(this.Literal);\r
                     break;\r
                 case "URL":\r
-                    this.Render.Url = this.URL;\r
+                    this.Render.Url = D2DRender.ToColor4(this.URL);\r
                     break;\r
                 case "InsertCaret":\r
-                    this.Render.InsertCaret = this.InsertCaret;\r
+                    this.Render.InsertCaret = D2DRender.ToColor4(this.InsertCaret);\r
                     break;\r
                 case "OverwriteCaret":\r
-                    this.Render.OverwriteCaret = this.OverwriteCaret;\r
+                    this.Render.OverwriteCaret = D2DRender.ToColor4(this.OverwriteCaret);\r
+                    break;\r
+                case "Padding":\r
+                    this.View.Padding = new Padding((int)this.Padding.Left, (int)this.Padding.Top, (int)this.Padding.Right, (int)this.Padding.Bottom);\r
                     break;\r
                 case "LineMarker":\r
-                    this.Render.LineMarker = this.LineMarker;\r
+                    this.Render.LineMarker = D2DRender.ToColor4(this.LineMarker);\r
                     break;\r
                 case "MarkURL":\r
                     this.View.UrlMark = this.MarkURL;\r
@@ -1159,6 +1180,9 @@ namespace FooEditEngine.WPF
                 case "ShowTab":\r
                     this.Render.ShowTab = this.ShowTab;\r
                     break;\r
+                case "ShowLineBreak":\r
+                    this.Render.ShowLineBreak = this.ShowLineBreak;\r
+                    break;\r
                 case "FlowDirection":\r
                     this.Render.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;\r
                     this.horizontalScrollBar.FlowDirection = this.FlowDirection;\r
@@ -1167,6 +1191,9 @@ namespace FooEditEngine.WPF
                     this.View.HideRuler = !this.DrawRuler;\r
                     this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);\r
                     break;\r
+                case "UpdateArea":\r
+                    this.Render.UpdateArea = D2DRender.ToColor4(this.UpdateArea);\r
+                    break;\r
             }\r
             base.OnPropertyChanged(e);\r
         }\r
@@ -1230,6 +1257,17 @@ namespace FooEditEngine.WPF
         }\r
 \r
         /// <summary>\r
+        /// マーカーパターンセット\r
+        /// </summary>\r
+        public MarkerPatternSet MarkerPatternSet\r
+        {\r
+            get\r
+            {\r
+                return this.View.MarkerPatternSet;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
         /// ドキュメントを表す\r
         /// </summary>\r
         public Document Document\r
@@ -1263,22 +1301,23 @@ namespace FooEditEngine.WPF
         }\r
 \r
         /// <summary>\r
-        /// é\81¸æ\8a\9eç¯\84å\9b²ã\81®é\96\8bå§\8bã\82¤ã\83³ã\83\87ã\83\83ã\82¯ã\82¹\r
+        /// é\81¸æ\8a\9eç¯\84å\9b²ã\82\92表ã\81\99\r
         /// </summary>\r
-        /// <remarks>SelectionLengthが0の場合はキャレット位置を表します</remarks>\r
-        public int SelectionStart\r
+        /// <remarks>\r
+        /// Lengthが0の場合はキャレット位置を表します。\r
+        /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります\r
+        /// </remarks>\r
+        public TextRange Selection\r
         {\r
-            get { return this._Controller.SelectionStart; }\r
+            get { return (TextRange)GetValue(SelectionProperty); }\r
+            set { SetValue(SelectionProperty, value); }\r
         }\r
 \r
         /// <summary>\r
-        /// 選択範囲の長さ\r
+        /// Selectionの依存プロパティを表す\r
         /// </summary>\r
-        /// <remarks>矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります</remarks>\r
-        public int SelectionLength\r
-        {\r
-            get { return this._Controller.SelectionLength; }\r
-        }\r
+        public static readonly DependencyProperty SelectionProperty =\r
+            DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null));\r
 \r
         /// <summary>\r
         /// 拡大率を表す\r
@@ -1314,11 +1353,15 @@ namespace FooEditEngine.WPF
         /// </summary>\r
         public TextPoint CaretPostion\r
         {\r
-            get { return (TextPoint)GetValue(CaretPostionPropertyKey.DependencyProperty); }\r
+            get { return (TextPoint)GetValue(CaretPostionProperty); }\r
+            set { SetValue(CaretPostionProperty, value); }\r
         }\r
 \r
-        static readonly DependencyPropertyKey CaretPostionPropertyKey =\r
-            DependencyProperty.RegisterReadOnly("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new FrameworkPropertyMetadata(new TextPoint()));\r
+        /// <summary>\r
+        /// CaretPostionの依存プロパティを表す\r
+        /// </summary>\r
+        public static readonly DependencyProperty CaretPostionProperty =\r
+            DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(TextPoint.Null));\r
         \r
         /// <summary>\r
         /// デフォルトの文字色を表す。これは依存プロパティです\r
@@ -1378,7 +1421,7 @@ namespace FooEditEngine.WPF
         /// Hilightの依存プロパティを表す\r
         /// </summary>\r
         public static readonly DependencyProperty HilightProperty =\r
-            DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.HighlightColor));\r
+            DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));\r
         \r
         /// <summary>\r
         /// キーワード1の文字色を表す。これは依存プロパティです\r
@@ -1469,7 +1512,7 @@ namespace FooEditEngine.WPF
         /// LineMarkerの依存プロパティを表す\r
         /// </summary>\r
         public static readonly DependencyProperty LineMarkerProperty =\r
-            DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.WhiteSmoke));\r
+            DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));\r
 \r
         /// <summary>\r
         /// 挿入モード時のキャレットの色を表す\r
@@ -1487,6 +1530,21 @@ namespace FooEditEngine.WPF
             DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));\r
 \r
         /// <summary>\r
+        /// 行更新フラグの色を表す\r
+        /// </summary>\r
+        public System.Windows.Media.Color UpdateArea\r
+        {\r
+            get { return (System.Windows.Media.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(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));        \r
+\r
+        /// <summary>\r
         /// 上書きモード時のキャレット職を表す\r
         /// </summary>\r
         public System.Windows.Media.Color OverwriteCaret\r
@@ -1583,7 +1641,9 @@ namespace FooEditEngine.WPF
             set { SetValue(LineBreakCharCountProperty, value); }\r
         }\r
 \r
-        // Using a DependencyProperty as the backing store for LineBreakCharCount.  This enables animation, styling, binding, etc...\r
+        /// <summary>\r
+        /// LineBreakCharCountの依存プロパティを表す\r
+        /// </summary>\r
         public static readonly DependencyProperty LineBreakCharCountProperty =\r
             DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));\r
 \r
@@ -1616,7 +1676,7 @@ namespace FooEditEngine.WPF
         /// DrawCaretLineの依存プロパティを表す\r
         /// </summary>\r
         public static readonly DependencyProperty DrawCaretLineProperty =\r
-            DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));\r
+            DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));\r
 \r
         /// <summary>\r
         /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです\r
@@ -1662,7 +1722,7 @@ namespace FooEditEngine.WPF
         /// MarkURLの依存プロパティを表す\r
         /// </summary>\r
         public static readonly DependencyProperty MarkURLProperty =\r
-            DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));\r
+            DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));\r
 \r
         /// <summary>\r
         /// 全角スペースを表示するなら真。そうでないなら偽\r
@@ -1709,6 +1769,21 @@ namespace FooEditEngine.WPF
         public static readonly DependencyProperty ShowTabProperty =\r
             DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));\r
 \r
+        /// <summary>\r
+        /// 改行マークを表示するなら真。そうでないなら偽\r
+        /// </summary>\r
+        public bool ShowLineBreak\r
+        {\r
+            get { return (bool)GetValue(ShowLineBreakProperty); }\r
+            set { SetValue(ShowLineBreakProperty, value); }\r
+        }\r
+\r
+        /// <summary>\r
+        /// ShowLineBreakの依存プロパティを表す\r
+        /// </summary>\r
+        public static readonly DependencyProperty ShowLineBreakProperty =\r
+            DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));\r
+        \r
         #endregion\r
     }\r
     /// <summary>\r