OSDN Git Service

HighDPI環境下で単語選択の位置がずれることがあったので座標変換するようにした
authorgdkhd812 <test@nnn.co.jp>
Sat, 24 Oct 2015 17:18:23 +0000 (22:48 +0530)
committergdkhd812 <test@nnn.co.jp>
Sat, 24 Oct 2015 17:18:23 +0000 (22:48 +0530)
WPF/FooEditEngine/FooTextBox.cs
WPF/FooEditEngine/Properties/AssemblyInfo.cs

index bcee268..07cb538 100644 (file)
-/*\r
- * Copyright (C) 2013 FooProject\r
- * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\r
-\r
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of \r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\r
-\r
-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
-using System.Windows.Media;\r
-using System.Windows.Controls;\r
-using System.Windows.Controls.Primitives;\r
-using System.Windows.Documents;\r
-using System.Windows.Interop;\r
-using System.Windows.Threading;\r
-using DotNetTextStore;\r
-using DotNetTextStore.UnmanagedAPI.TSF;\r
-using DotNetTextStore.UnmanagedAPI.WinDef;\r
-using Microsoft.Win32;\r
-\r
-namespace FooEditEngine.WPF\r
-{\r
-    /// <summary>\r
-    /// オートインデントを行うためのデリゲートを表す\r
-    /// </summary>\r
-    /// <param name="sender">イベント発生元のオブジェクト</param>\r
-    /// <param name="e">イベントデーター</param>\r
-    public delegate void AutoIndentHookerHandler(object sender,EventArgs e);\r
-\r
-    /// <summary>\r
-    /// WPFでのFooTextBoxの実装\r
-    /// </summary>\r
-    public sealed class FooTextBox : Control, IDisposable\r
-    {\r
-        const double MaxFontSize = 72.0f;\r
-        const double MinFontSize = 1;\r
-\r
-        EditView View;\r
-        Controller _Controller;\r
-        D2DRender Render;\r
-        Image image;\r
-        ScrollBar verticalScrollBar, horizontalScrollBar;\r
-        TextStore textStore;\r
-        DispatcherTimer timer;\r
-        bool disposed = false;\r
-        FooTextBoxAutomationPeer peer;\r
-        bool nowCaretMove = false;\r
-        \r
-        static FooTextBox()\r
-        {\r
-            DefaultStyleKeyProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(typeof(FooTextBox)));\r
-            KeyboardNavigation.IsTabStopProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(true));\r
-            KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(KeyboardNavigationMode.None));\r
-        }\r
-\r
-        /// <summary>\r
-        /// コンストラクター\r
-        /// </summary>\r
-        public FooTextBox()\r
-        {\r
-            this.image = new Image();\r
-            this.image.Stretch = Stretch.Fill;\r
-            this.image.HorizontalAlignment = HorizontalAlignment.Left;\r
-            this.image.VerticalAlignment = VerticalAlignment.Top;\r
-\r
-            this.textStore = new TextStore();\r
-            this.textStore.IsLoading += textStore_IsLoading;\r
-            this.textStore.IsReadOnly += textStore_IsReadOnly;\r
-            this.textStore.GetStringLength += () => this.Document.Length;\r
-            this.textStore.GetString += _textStore_GetString;\r
-            this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;\r
-            this.textStore.SetSelectionIndex += _textStore_SetSelectionIndex;\r
-            this.textStore.InsertAtSelection += _textStore_InsertAtSelection;\r
-            this.textStore.GetHWnd += _textStore_GetHWnd;\r
-            this.textStore.GetScreenExtent += _textStore_GetScreenExtent;\r
-            this.textStore.GetStringExtent += _textStore_GetStringExtent;\r
-            this.textStore.CompositionStarted += textStore_CompositionStarted;\r
-            this.textStore.CompositionUpdated += textStore_CompositionUpdated;\r
-            this.textStore.CompositionEnded += textStore_CompositionEnded;\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.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
-            this.View.HideCaret = !this.DrawCaret;\r
-            this.View.HideLineMarker = !this.DrawCaretLine;\r
-            this.View.HideRuler = !this.DrawRuler;\r
-            this.View.UrlMark = this.MarkURL;\r
-            this.View.TabStops = this.TabChars;\r
-\r
-            this._Controller = new Controller(this.Document, this.View);\r
-            this._Controller.SelectionChanged += new EventHandler(Controller_SelectionChanged);\r
-\r
-            //Viewを作成した後に追加しないと例外が発生する\r
-            this.Document.Update += new DocumentUpdateEventHandler(Document_Update);\r
-\r
-            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, CopyCommand, CanExecute));\r
-            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, CutCommand, CanExecute));\r
-            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, PasteCommand, CanExecute));\r
-            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, DeleteCommand, CanExecute));\r
-            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, SelectAllCommand, CanExecute));\r
-            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, UndoCommand, CanExecute));\r
-            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, RedoCommand, CanExecute));\r
-            this.CommandBindings.Add(new CommandBinding(EditingCommands.ToggleInsert, ToggleInsertCommand, CanExecute));\r
-            this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleRectSelectMode, ToggleRectSelectCommand, CanExecute));\r
-            this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleFlowDirection, ToggleFlowDirectionCommand, CanExecute));\r
-            this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleCodePoint, ToggleCodePointCommand, CanExecute));\r
-\r
-            this.InputBindings.Add(new InputBinding(ApplicationCommands.Copy, new KeyGesture(Key.C, ModifierKeys.Control)));\r
-            this.InputBindings.Add(new InputBinding(ApplicationCommands.Cut, new KeyGesture(Key.X, ModifierKeys.Control)));\r
-            this.InputBindings.Add(new InputBinding(ApplicationCommands.Paste, new KeyGesture(Key.V, ModifierKeys.Control)));\r
-            this.InputBindings.Add(new InputBinding(ApplicationCommands.Delete, new KeyGesture(Key.Delete, ModifierKeys.None)));\r
-            this.InputBindings.Add(new InputBinding(ApplicationCommands.SelectAll, new KeyGesture(Key.A, ModifierKeys.Control)));\r
-            this.InputBindings.Add(new InputBinding(ApplicationCommands.Undo, new KeyGesture(Key.Z, ModifierKeys.Control)));\r
-            this.InputBindings.Add(new InputBinding(ApplicationCommands.Redo, new KeyGesture(Key.Y, ModifierKeys.Control)));\r
-            this.InputBindings.Add(new InputBinding(EditingCommands.ToggleInsert, new KeyGesture(Key.Insert, ModifierKeys.None)));\r
-            this.InputBindings.Add(new InputBinding(FooTextBoxCommands.ToggleCodePoint, new KeyGesture(Key.X, ModifierKeys.Alt)));\r
-\r
-            this.timer = new DispatcherTimer();\r
-            this.timer.Interval = new TimeSpan(0, 0, 0, 0, 100);\r
-            this.timer.Tick += new EventHandler(timer_Tick);\r
-\r
-            this.Loaded += new RoutedEventHandler(FooTextBox_Loaded);\r
-\r
-            this.AutoIndentHooker = (s,e)=>{};\r
-\r
-            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
-        /// ファイナライザー\r
-        /// </summary>\r
-        ~FooTextBox()\r
-        {\r
-            //Dispose(false)を呼び出すと落ちる\r
-            this.Dispose(false);\r
-        }\r
-\r
-        /// <summary>\r
-        /// オートインデントを行うためのイベント\r
-        /// </summary>\r
-        public AutoIndentHookerHandler AutoIndentHooker;\r
-\r
-        /// <summary>\r
-        /// テンプレートを適用します\r
-        /// </summary>\r
-        public override void OnApplyTemplate()\r
-        {\r
-            base.OnApplyTemplate();\r
-\r
-            Grid grid = this.GetTemplateChild("PART_Grid") as Grid;\r
-            if (grid != null)\r
-            {\r
-                Grid.SetRow(this.image, 0);\r
-                Grid.SetColumn(this.image, 0);\r
-                grid.Children.Add(this.image);\r
-            }\r
-\r
-            this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;\r
-            if (this.horizontalScrollBar != null)\r
-            {\r
-                this.horizontalScrollBar.SmallChange = 10;\r
-                this.horizontalScrollBar.LargeChange = 100;\r
-                this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;\r
-                this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);\r
-            }\r
-            this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;\r
-            if (this.verticalScrollBar != null)\r
-            {\r
-                this.verticalScrollBar.SmallChange = 1;\r
-                this.verticalScrollBar.LargeChange = 10;\r
-                this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;\r
-                this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// ドキュメントを選択する\r
-        /// </summary>\r
-        /// <param name="start">開始インデックス</param>\r
-        /// <param name="length">長さ</param>\r
-        public void Select(int start, int length)\r
-        {\r
-            this._Controller.Select(start, length);\r
-            this.textStore.NotifySelectionChanged();\r
-        }\r
-\r
-        /// <summary>\r
-        /// キャレットを指定した行に移動させます\r
-        /// </summary>\r
-        /// <param name="index">インデックス</param>\r
-        /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>\r
-        public void JumpCaret(int index)\r
-        {\r
-            this._Controller.JumpCaret(index);\r
-        }\r
-        /// <summary>\r
-        /// キャレットを指定した行と桁に移動させます\r
-        /// </summary>\r
-        /// <param name="row">行番号</param>\r
-        /// <param name="col">桁</param>\r
-        /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>\r
-        public void JumpCaret(int row, int col)\r
-        {\r
-            this._Controller.JumpCaret(row, col);\r
-        }\r
-\r
-        /// <summary>\r
-        /// 選択中のテキストをクリップボードにコピーします\r
-        /// </summary>\r
-        public void Copy()\r
-        {\r
-            string text = this._Controller.SelectedText;\r
-            if (text != null && text != string.Empty)\r
-                Clipboard.SetText(text);\r
-        }\r
-\r
-        /// <summary>\r
-        /// 選択中のテキストをクリップボードに切り取ります\r
-        /// </summary>\r
-        public void Cut()\r
-        {\r
-            string text = this._Controller.SelectedText;\r
-            if (text != null && text != string.Empty)\r
-            {\r
-                Clipboard.SetText(text);\r
-                this._Controller.SelectedText = "";\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// 選択中のテキストを貼り付けます\r
-        /// </summary>\r
-        public void Paste()\r
-        {\r
-            if (Clipboard.ContainsText() == false)\r
-                return;\r
-            string text = Clipboard.GetText();\r
-            this._Controller.SelectedText = text;\r
-        }\r
-\r
-        /// <summary>\r
-        /// 選択を解除する\r
-        /// </summary>\r
-        public void DeSelectAll()\r
-        {\r
-            this._Controller.DeSelectAll();\r
-            this.textStore.NotifySelectionChanged();\r
-        }\r
-\r
-        /// <summary>\r
-        /// 対応する座標を返します\r
-        /// </summary>\r
-        /// <param name="tp">テキストポイント</param>\r
-        /// <returns>座標</returns>\r
-        /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>\r
-        public System.Windows.Point GetPostionFromTextPoint(TextPoint tp)\r
-        {\r
-            if (this.Document.FireUpdateEvent == false)\r
-                throw new InvalidOperationException("");\r
-            return this.View.GetPostionFromTextPoint(tp);\r
-        }\r
-\r
-        /// <summary>\r
-        /// 対応するテキストポイントを返します\r
-        /// </summary>\r
-        /// <param name="p">クライアント領域の原点を左上とする座標</param>\r
-        /// <returns>テキストポイント</returns>\r
-        public TextPoint GetTextPointFromPostion(System.Windows.Point p)\r
-        {\r
-            if (this.Document.FireUpdateEvent == false)\r
-                throw new InvalidOperationException("");\r
-            return this.View.GetTextPointFromPostion(p);\r
-        }\r
-\r
-        /// <summary>\r
-        /// 行の高さを取得します\r
-        /// </summary>\r
-        /// <param name="row">レイアウト行</param>\r
-        /// <returns>行の高さ</returns>\r
-        public double GetLineHeight(int row)\r
-        {\r
-            if (this.Document.FireUpdateEvent == false)\r
-                throw new InvalidOperationException("");\r
-            return this.View.LayoutLines.GetLayout(row).Height;;\r
-        }\r
-\r
-        /// <summary>\r
-        /// インデックスに対応する座標を得ます\r
-        /// </summary>\r
-        /// <param name="index">インデックス</param>\r
-        /// <returns>座標を返す</returns>\r
-        public System.Windows.Point GetPostionFromIndex(int index)\r
-        {\r
-            if (this.Document.FireUpdateEvent == false)\r
-                throw new InvalidOperationException("");\r
-            TextPoint tp = this.View.GetLayoutLineFromIndex(index);\r
-            return this.View.GetPostionFromTextPoint(tp);\r
-        }\r
-\r
-        /// <summary>\r
-        /// 座標からインデックスに変換します\r
-        /// </summary>\r
-        /// <param name="p">座標</param>\r
-        /// <returns>インデックスを返す</returns>\r
-        public int GetIndexFromPostion(System.Windows.Point p)\r
-        {\r
-            if (this.Document.FireUpdateEvent == false)\r
-                throw new InvalidOperationException("");\r
-            TextPoint tp = this.View.GetTextPointFromPostion(p);\r
-            return this.View.GetIndexFromLayoutLine(tp);\r
-        }\r
-\r
-        /// <summary>\r
-        /// 再描写する\r
-        /// </summary>\r
-        public void Refresh()\r
-        {\r
-            this.Refresh(this.View.PageBound);\r
-        }\r
-\r
-        /// <summary>\r
-        /// レイアウト行をすべて破棄し、再度レイアウトを行う\r
-        /// </summary>\r
-        public void PerfomLayouts()\r
-        {\r
-            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="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
-            if (this.disposed)\r
-                return;\r
-            this.Dispose(true);\r
-            GC.SuppressFinalize(this);\r
-            this.disposed = true;\r
-        }\r
-\r
-        /// <summary>\r
-        /// リソースを開放する\r
-        /// </summary>\r
-        /// <param name="disposing">真ならマネージドリソースも開放し、そうでないならアンマネージドリソースのみを開放する</param>\r
-        void Dispose(bool disposing)\r
-        {\r
-            if (disposing)\r
-            {\r
-                this.textStore.Dispose();\r
-                this.timer.Stop();\r
-                this.View.Dispose();\r
-                this.Render.Dispose();\r
-            }\r
-            SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);\r
-        }\r
-        \r
-        void Refresh(Rectangle updateRect)\r
-        {\r
-            if (this.disposed || this.Visibility == Visibility.Collapsed)\r
-                return;\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
-\r
-        #region Commands\r
-        void CanExecute(object sender, CanExecuteRoutedEventArgs e)\r
-        {\r
-            e.CanExecute = this.IsEnabled;\r
-        }\r
-\r
-        void ToggleCodePointCommand(object sender, RoutedEventArgs e)\r
-        {\r
-            if (!this._Controller.ConvertToChar())\r
-                this._Controller.ConvertToCodePoint();\r
-            this.Refresh();\r
-        }\r
-\r
-        void CopyCommand(object sender, RoutedEventArgs e)\r
-        {\r
-            this.Copy();\r
-        }\r
-\r
-        void CutCommand(object sender, RoutedEventArgs e)\r
-        {\r
-            this.Cut();\r
-            this.Refresh();\r
-        }\r
-\r
-        void PasteCommand(object sender, RoutedEventArgs e)\r
-        {\r
-            this.Paste();\r
-            this.Refresh();\r
-        }\r
-\r
-        void DeleteCommand(object sender, RoutedEventArgs e)\r
-        {\r
-            int oldLength = this.Document.Length;\r
-            this._Controller.DoDeleteAction();\r
-            this.Refresh();\r
-        }\r
-\r
-        void SelectAllCommand(object sender, RoutedEventArgs e)\r
-        {\r
-            this.Select(0, this.Document.Length);\r
-            this.Refresh();\r
-        }\r
-\r
-        void UndoCommand(object sender, RoutedEventArgs e)\r
-        {\r
-            int oldLength = this.Document.Length;\r
-            this.Document.UndoManager.undo();\r
-            this.Refresh();\r
-        }\r
-\r
-        void RedoCommand(object sender, RoutedEventArgs e)\r
-        {\r
-            int oldLength = this.Document.Length;\r
-            this.Document.UndoManager.redo();\r
-            this.Refresh();\r
-        }\r
-\r
-        void ToggleInsertCommand(object sender, RoutedEventArgs e)\r
-        {\r
-            if (this.InsertMode)\r
-                this.InsertMode = false;\r
-            else\r
-                this.InsertMode = true;\r
-            this.Refresh();\r
-        }\r
-\r
-        void ToggleRectSelectCommand(object sender, RoutedEventArgs e)\r
-        {\r
-            if (this.RectSelectMode)\r
-                this.RectSelectMode = false;\r
-            else\r
-                this.RectSelectMode = true;\r
-            this.Refresh();\r
-        }\r
-        void ToggleFlowDirectionCommand(object sender, RoutedEventArgs e)\r
-        {\r
-            if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)\r
-                this.FlowDirection = System.Windows.FlowDirection.RightToLeft;\r
-            else\r
-                this.FlowDirection = System.Windows.FlowDirection.LeftToRight;\r
-            this.Refresh();\r
-        }\r
-        #endregion\r
-        #region TSF\r
-        internal TextStore TextStore\r
-        {\r
-            get { return this.textStore; }\r
-        }\r
-\r
-        bool textStore_IsReadOnly()\r
-        {\r
-            return false;\r
-        }\r
-\r
-        bool textStore_IsLoading()\r
-        {\r
-            return false;\r
-        }\r
-\r
-        void textStore_CompositionEnded()\r
-        {\r
-            TextStoreHelper.EndCompostion(this.Document);\r
-            this.Refresh();\r
-        }\r
-\r
-        void textStore_CompositionUpdated(int start, int end)\r
-        {\r
-            if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))\r
-                this.Refresh();\r
-        }\r
-        bool textStore_CompositionStarted()\r
-        {\r
-            bool result = TextStoreHelper.StartCompstion(this.Document);\r
-            if (!result)\r
-                System.Media.SystemSounds.Beep.Play();\r
-            return result;\r
-        }\r
-\r
-        string _textStore_GetString(int start, int length)\r
-        {\r
-            return this.Document.ToString(start, length);\r
-        }\r
-\r
-        IntPtr _textStore_GetHWnd()\r
-        {\r
-            var hwndSource = HwndSource.FromVisual(this) as HwndSource;\r
-            if (hwndSource != null)\r
-                return hwndSource.Handle;\r
-            else\r
-                return IntPtr.Zero;\r
-        }\r
-\r
-        void _textStore_GetStringExtent(\r
-            int i_startIndex,\r
-            int i_endIndex,\r
-            out POINT o_topLeft,\r
-            out POINT o_bottomRight\r
-        )\r
-        {\r
-            Point startPos, endPos;\r
-            TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);\r
-\r
-            double scale = this.Render.GetScale();\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
-        }\r
-\r
-        void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)\r
-        {\r
-            var pointTopLeft = new Point(0, 0);\r
-            var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);\r
-\r
-            pointTopLeft = PointToScreen(pointTopLeft);\r
-            pointBottomRight = PointToScreen(pointBottomRight);\r
-\r
-            o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);\r
-            o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);\r
-        }\r
-\r
-        void _textStore_GetSelectionIndex(out int o_startIndex, out int o_endIndex)\r
-        {\r
-            TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out o_startIndex, out o_endIndex);\r
-        }\r
-\r
-        void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)\r
-        {\r
-            TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);\r
-            this.Refresh();\r
-        }\r
-\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
-        }\r
-\r
-        /// <summary>\r
-        /// キーボードフォーカスが取得されたときに呼ばれます\r
-        /// </summary>\r
-        /// <param name="e">イベントデーター</param>\r
-        protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)\r
-        {\r
-            base.OnGotKeyboardFocus(e);\r
-            this.textStore.SetFocus();\r
-            this.View.IsFocused = true;\r
-            this.Refresh();\r
-        }\r
-\r
-        /// <summary>\r
-        /// キーボードフォーカスが失われたときに呼ばれます\r
-        /// </summary>\r
-        /// <param name="e">イベントデーター</param>\r
-        protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)\r
-        {\r
-            base.OnLostKeyboardFocus(e);\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
-            this.peer = new FooTextBoxAutomationPeer(this);\r
-            return this.peer;\r
-        }\r
-\r
-\r
-        /// <inheritdoc/>\r
-        protected override void OnTextInput(TextCompositionEventArgs e)\r
-        {\r
-            if (e.Text == "\r")\r
-            {\r
-                this._Controller.DoEnterAction();\r
-                this.AutoIndentHooker(this, null);\r
-            }\r
-            else if (e.Text == "\b")\r
-            {\r
-                this._Controller.DoBackSpaceAction();\r
-            }\r
-            else\r
-            {\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.textStore.IsLocked())\r
-                return;\r
-\r
-            ModifierKeys modiferKeys = e.KeyboardDevice.Modifiers;\r
-            bool movedCaret = false;\r
-            switch (e.Key)\r
-            {\r
-                case Key.Up:\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
-                    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
-                    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
-                    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.PageUp:\r
-                    this._Controller.Scroll(ScrollDirection.Up,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);\r
-                    this.Refresh();\r
-                    movedCaret = true;\r
-                    break;\r
-                case Key.PageDown:\r
-                    this._Controller.Scroll(ScrollDirection.Down,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);\r
-                    this.Refresh();\r
-                    movedCaret = true;\r
-                    break;\r
-                case Key.Home:\r
-                    if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))\r
-                        this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));\r
-                    else\r
-                        this._Controller.JumpToLineHead(this.View.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));\r
-                    this.Refresh();\r
-                    movedCaret = true;\r
-                    break;\r
-                case Key.End:\r
-                    if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))\r
-                        this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));\r
-                    else\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.Selection.Length == 0)\r
-                        this._Controller.DoInputChar('\t');\r
-                    else if(this.IsPressedModifierKey(modiferKeys,ModifierKeys.Shift))\r
-                        this._Controller.DownIndent();\r
-                    else\r
-                        this._Controller.UpIndent();\r
-                    this.Refresh();\r
-                    e.Handled = true;\r
-                    break;\r
-            }\r
-            if (movedCaret && this.peer != null)\r
-                this.peer.OnNotifyCaretChanged();\r
-            base.OnKeyDown(e);\r
-        }\r
-\r
-        bool IsPressedModifierKey(ModifierKeys keys, ModifierKeys pressed)\r
-        {\r
-            if (keys == pressed)\r
-                return true;\r
-            if ((keys & pressed) == pressed)\r
-                return true;\r
-            return false;\r
-        }\r
-\r
-        /// <summary>\r
-        /// ダブルクリックされたときに呼ばれます\r
-        /// </summary>\r
-        /// <param name="e">イベントパラメーター</param>\r
-        /// <remarks>\r
-        /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。\r
-        /// e.Handledを真にした場合、単語単位の選択が行われなくなります\r
-        /// </remarks>\r
-        protected override void OnMouseDoubleClick(MouseButtonEventArgs e)\r
-        {\r
-            System.Windows.Point p = e.GetPosition(this);\r
-            TextPoint tp = this.View.GetTextPointFromPostion(p);\r
-            if (tp == TextPoint.Null)\r
-                return;\r
-            int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);\r
-\r
-            FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,\r
-                e.Timestamp,\r
-                e.ChangedButton,\r
-                e.StylusDevice,\r
-                index);\r
-            newEventArgs.RoutedEvent = e.RoutedEvent;\r
-            base.OnMouseDoubleClick(newEventArgs);\r
-\r
-            if (newEventArgs.Handled)\r
-                return;\r
-\r
-            if (e.LeftButton == MouseButtonState.Pressed)\r
-            {\r
-\r
-                this._Controller.SelectWord(index);\r
-                this.textStore.NotifySelectionChanged();\r
-                if(this.peer != null)\r
-                    this.peer.OnNotifyCaretChanged();\r
-                this.Refresh();\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// マウスボタンが押されたときに呼ばれます\r
-        /// </summary>\r
-        /// <param name="e">イベントパラメーター</param>\r
-        /// <remarks>\r
-        /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。\r
-        /// e.Handledを真にした場合、キャレットの移動処理が行われなくなります\r
-        /// </remarks>\r
-        protected override void OnMouseDown(MouseButtonEventArgs e)\r
-        {\r
-            var p = this.GetDipFromPoint(e.GetPosition(this));\r
-            TextPoint tp = this.View.GetTextPointFromPostion(p);\r
-            if (tp == TextPoint.Null)\r
-                return;\r
-            int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);\r
-\r
-            FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,\r
-                e.Timestamp,\r
-                e.ChangedButton,\r
-                e.StylusDevice,\r
-                index);\r
-            newEventArgs.RoutedEvent = e.RoutedEvent;\r
-            base.OnMouseDown(newEventArgs);\r
-\r
-            if (newEventArgs.Handled)\r
-                return;\r
-\r
-            if (e.LeftButton == MouseButtonState.Pressed)\r
-            {\r
-                FoldingItem foldingData = this.View.HitFoldingData(p.X,tp.row);\r
-                if (foldingData != null)\r
-                {\r
-                    if (foldingData.Expand)\r
-                        this.View.LayoutLines.FoldingCollection.Collapse(foldingData);\r
-                    else\r
-                        this.View.LayoutLines.FoldingCollection.Expand(foldingData);\r
-                    this._Controller.JumpCaret(foldingData.Start,false);\r
-                }\r
-                else\r
-                {\r
-                    this._Controller.JumpCaret(tp.row, tp.col, false);\r
-                }\r
-                if (this.peer != null)\r
-                    this.peer.OnNotifyCaretChanged();\r
-                this.View.IsFocused = true;\r
-                this.Focus();\r
-                this.Refresh();\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// マウスが移動したときに呼ばれます\r
-        /// </summary>\r
-        /// <param name="e">イベントパラメーター</param>\r
-        /// <remarks>\r
-        /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。\r
-        /// e.Handledを真にした場合、選択処理と状況に応じたカーソルの変化が行われなくなります\r
-        /// </remarks>\r
-        protected override void  OnMouseMove(MouseEventArgs e)\r
-        {\r
-            var p = this.GetDipFromPoint(e.GetPosition(this));\r
-            TextPoint tp = this.View.GetTextPointFromPostion(p);\r
-            if (tp == TextPoint.Null)\r
-            {\r
-                base.OnMouseMove(e);\r
-                return;\r
-            }\r
-            int index = this.View.GetIndexFromLayoutLine(tp);\r
-\r
-            FooMouseEventArgs newEventArgs = new FooMouseEventArgs(e.MouseDevice, e.Timestamp, e.StylusDevice, index);\r
-            newEventArgs.RoutedEvent = e.RoutedEvent;\r
-            base.OnMouseMove(newEventArgs);\r
-\r
-            if (newEventArgs.Handled)\r
-                return;\r
-\r
-            if (this.View.HitTextArea(p.X,p.Y))\r
-            {\r
-                if (this._Controller.IsMarker(tp, HilightType.Url))\r
-                    this.Cursor = Cursors.Hand;\r
-                else\r
-                    this.Cursor = Cursors.IBeam;\r
-\r
-                if (e.LeftButton == MouseButtonState.Pressed)\r
-                {\r
-                    this._Controller.MoveCaretAndSelect(tp);\r
-                    if (this.peer != null)\r
-                        this.peer.OnNotifyCaretChanged();\r
-                    this.Refresh();\r
-                }\r
-            }\r
-            else\r
-            {\r
-                this.Cursor = Cursors.Arrow;\r
-            }\r
-        }\r
-\r
-        private Point GetDipFromPoint(Point p)\r
-        {\r
-            float dpi;\r
-            this.Render.GetDpi(out dpi,out dpi);\r
-            double scale = dpi / 96.0;\r
-            return p.Scale(1 / scale);\r
-        }\r
-\r
-        /// <inheritdoc/>\r
-        protected override void OnMouseWheel(MouseWheelEventArgs e)\r
-        {\r
-            if(Keyboard.Modifiers == ModifierKeys.None)\r
-            {\r
-                if (e.Delta > 0)\r
-                    this._Controller.Scroll(ScrollDirection.Up, SystemParameters.WheelScrollLines, false, false);\r
-                else\r
-                    this._Controller.Scroll(ScrollDirection.Down, SystemParameters.WheelScrollLines, false, false);\r
-            }\r
-            else if (Keyboard.Modifiers == ModifierKeys.Control)\r
-            {\r
-                double newFontSize = this.Render.FontSize;\r
-                if (e.Delta > 0)\r
-                    newFontSize++;\r
-                else\r
-                    newFontSize--;\r
-                if (newFontSize > MaxFontSize)\r
-                    newFontSize = 72;\r
-                else if (newFontSize < MinFontSize)\r
-                    newFontSize = 1;\r
-                this.Render.FontSize = newFontSize;\r
-                SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);\r
-            }\r
-            this.Refresh();\r
-            base.OnMouseWheel(e);\r
-        }\r
-\r
-        void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)\r
-        {\r
-            if (e.Category == UserPreferenceCategory.Keyboard)\r
-            {\r
-                int blinkTime = (int)NativeMethods.GetCaretBlinkTime();\r
-                this.View.CaretBlink = blinkTime >= 0;\r
-                this.View.CaretBlinkTime = blinkTime * 2;\r
-            }\r
-            if (e.Category == UserPreferenceCategory.General)\r
-            {\r
-                this.View.CaretWidthOnInsertMode = SystemParameters.CaretWidth;\r
-            }\r
-        }\r
-\r
-        void Document_Update(object sender, DocumentUpdateEventArgs e)\r
-        {\r
-            if (this.textStore.IsLocked())\r
-                return;\r
-            if(e.type == UpdateType.Replace)\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.Resize(this.image.ActualWidth, this.image.ActualHeight))\r
-            {\r
-                this.Refresh();\r
-                return;\r
-            }\r
-\r
-            bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding();\r
-\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
-            double height = layout.Height;\r
-            Rectangle updateRect = new Rectangle(\r
-                this.View.CaretLocation.X,\r
-                this.View.CaretLocation.Y,\r
-                width,\r
-                height);\r
-\r
-            if (updateAll)\r
-                this.Refresh();\r
-            else\r
-                this.Refresh(updateRect);\r
-        }\r
-\r
-        void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)\r
-        {\r
-            if (this.horizontalScrollBar == null)\r
-                return;\r
-            double toX;\r
-            if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)\r
-                toX = this.horizontalScrollBar.Value;\r
-            else\r
-                toX = -this.horizontalScrollBar.Value;\r
-            this._Controller.Scroll(toX, this.View.Src.Row, false, false);\r
-            this.Refresh();\r
-        }\r
-\r
-        void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)\r
-        {\r
-            if (this.verticalScrollBar == null)\r
-                return;\r
-            int newRow = (int)this.verticalScrollBar.Value;\r
-            if (newRow >= this.View.LayoutLines.Count)\r
-                return;\r
-            this._Controller.Scroll(this.View.Src.X,newRow, false, false);\r
-            this.Refresh();\r
-        }\r
-\r
-        void View_SrcChanged(object sender, EventArgs e)\r
-        {\r
-            if (this.horizontalScrollBar == null || this.verticalScrollBar == null)\r
-                return;\r
-            EditView view = this.View;\r
-            if (view.Src.Row > this.verticalScrollBar.Maximum)\r
-                this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;\r
-            double absoulteX = Math.Abs(view.Src.X);\r
-            if(absoulteX > this.horizontalScrollBar.Maximum)\r
-                this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;\r
-            if(view.Src.Row != this.verticalScrollBar.Value)\r
-                this.verticalScrollBar.Value = view.Src.Row;\r
-            if (view.Src.X != this.horizontalScrollBar.Value)\r
-                this.horizontalScrollBar.Value = Math.Abs(view.Src.X);\r
-        }\r
-\r
-        void Controller_SelectionChanged(object sender, EventArgs e)\r
-        {\r
-            this.View.CaretBlink = this.View.CaretBlink;\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
-\r
-        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
-        {\r
-            if (width == 0 || height == 0)\r
-                throw new ArgumentOutOfRangeException();\r
-            if (this.Render.Resize(width, height))\r
-            {\r
-                double scale = this.Render.GetScale();\r
-                // RenderはレタリングはDIPだが、widthとheightの値はDPI依存なのでDIPに変換する\r
-                this.View.PageBound = new Rectangle(0, 0, width / scale, height / scale);\r
-\r
-                if (this.horizontalScrollBar != null)\r
-                {\r
-                    this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;\r
-                    this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;\r
-                }\r
-                if (this.verticalScrollBar != null)\r
-                {\r
-                    this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;\r
-                    this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;\r
-                }\r
-                return true;\r
-            }\r
-            return false;\r
-        }\r
-\r
-        /// <summary>\r
-        /// プロパティーが変更されたときに呼ばれます\r
-        /// </summary>\r
-        /// <param name="e">イベントパラメーター</param>\r
-        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)\r
-        {\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
-                    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
-                case "LineBreakCharCount":\r
-                    this.View.LineBreakCharCount = this.LineBreakCharCount;\r
-                    break;\r
-                case "InsertMode":\r
-                    this.View.InsertMode = this.InsertMode;\r
-                    break;\r
-                case "TabChars":\r
-                    this.View.TabStops = this.TabChars;\r
-                    break;\r
-                case "RectSelectMode":\r
-                    this._Controller.RectSelection = this.RectSelectMode;\r
-                    break;\r
-                case "DrawCaret":\r
-                    this.View.HideCaret = !this.DrawCaret;\r
-                    break;\r
-                case "DrawCaretLine":\r
-                    this.View.HideLineMarker = !this.DrawCaretLine;\r
-                    break;\r
-                case "DrawLineNumber":\r
-                    this.View.DrawLineNumber = this.DrawLineNumber;\r
-                    this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);\r
-                    break;\r
-                case "FontFamily":\r
-                    this.Render.FontFamily = this.FontFamily;\r
-                    break;\r
-                case "FontSize":\r
-                    this.Render.FontSize = this.FontSize;\r
-                    break;\r
-                case "FontStyle":\r
-                    this.Render.FontStyle = this.FontStyle;\r
-                    break;\r
-                case "FontWeight":\r
-                    this.Render.FontWeigth = this.FontWeight;\r
-                    break;\r
-                case "Foreground":\r
-                    this.Render.Foreground = D2DRender.ToColor4(this.Foreground);\r
-                    break;\r
-                case "Background":\r
-                    this.Render.Background = D2DRender.ToColor4(this.Background);\r
-                    break;\r
-                case "ControlChar":\r
-                    this.Render.ControlChar =D2DRender.ToColor4( this.ControlChar);\r
-                    break;\r
-                case "Hilight":\r
-                    this.Render.Hilight = D2DRender.ToColor4(this.Hilight);\r
-                    break;\r
-                case "Keyword1":\r
-                    this.Render.Keyword1 = D2DRender.ToColor4(this.Keyword1);\r
-                    break;\r
-                case "Keyword2":\r
-                    this.Render.Keyword2 = D2DRender.ToColor4(this.Keyword2);\r
-                    break;\r
-                case "Comment":\r
-                    this.Render.Comment = D2DRender.ToColor4(this.Comment);\r
-                    break;\r
-                case "Literal":\r
-                    this.Render.Literal = D2DRender.ToColor4(this.Literal);\r
-                    break;\r
-                case "URL":\r
-                    this.Render.Url = D2DRender.ToColor4(this.URL);\r
-                    break;\r
-                case "InsertCaret":\r
-                    this.Render.InsertCaret = D2DRender.ToColor4(this.InsertCaret);\r
-                    break;\r
-                case "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 = D2DRender.ToColor4(this.LineMarker);\r
-                    break;\r
-                case "MarkURL":\r
-                    this.View.UrlMark = this.MarkURL;\r
-                    break;\r
-                case "ShowFullSpace":\r
-                    this.Render.ShowFullSpace = this.ShowFullSpace;\r
-                    break;\r
-                case "ShowHalfSpace":\r
-                    this.Render.ShowHalfSpace = this.ShowHalfSpace;\r
-                    break;\r
-                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
-                    break;\r
-                case "DrawRuler":\r
-                    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
-                case "LineNumber":\r
-                    this.Render.LineNumber = D2DRender.ToColor4(this.LineNumber);\r
-                    break;\r
-            }\r
-            base.OnPropertyChanged(e);\r
-        }\r
-        #endregion\r
-        #region property\r
-\r
-        internal Controller Controller\r
-        {\r
-            get\r
-            {\r
-                return this._Controller;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// 文字列の描写に使用されるアンチエイリアシング モードを表します\r
-        /// </summary>\r
-        public TextAntialiasMode TextAntialiasMode\r
-        {\r
-            get\r
-            {\r
-                return this.Render.TextAntialiasMode;\r
-            }\r
-            set\r
-            {\r
-                this.Render.TextAntialiasMode = value;\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// シンタックスハイライターを表す\r
-        /// </summary>\r
-        public IHilighter Hilighter\r
-        {\r
-            get\r
-            {\r
-                return this.View.Hilighter;\r
-            }\r
-            set\r
-            {\r
-                this.View.Hilighter = value;\r
-                this.View.LayoutLines.ClearLayoutCache();\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// フォールティングを作成するインターフェイスを表す\r
-        /// </summary>\r
-        public IFoldingStrategy FoldingStrategy\r
-        {\r
-            get\r
-            {\r
-                return this.View.LayoutLines.FoldingStrategy;\r
-            }\r
-            set\r
-            {\r
-                this.View.LayoutLines.FoldingStrategy = value;\r
-                if (value == null)\r
-                    this.View.LayoutLines.FoldingCollection.Clear();\r
-            }\r
-        }\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
-        {\r
-            get;\r
-            private set;\r
-        }\r
-\r
-        /// <summary>\r
-        /// レイアウト行を表す\r
-        /// </summary>\r
-        public LineToIndexTable LayoutLineCollection\r
-        {\r
-            get { return this.View.LayoutLines; }\r
-        }\r
-\r
-        /// <summary>\r
-        /// 選択中の文字列を表す\r
-        /// </summary>\r
-        public string SelectedText\r
-        {\r
-            get\r
-            {\r
-                return this._Controller.SelectedText;\r
-            }\r
-            set\r
-            {\r
-                int oldLength = this.Document.Length;\r
-                this._Controller.SelectedText = value;\r
-            }\r
-        }\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
-        /// Lengthが0の場合はキャレット位置を表します。\r
-        /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります\r
-        /// </remarks>\r
-        public TextRange Selection\r
-        {\r
-            get { return (TextRange)GetValue(SelectionProperty); }\r
-            set { SetValue(SelectionProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Selectionの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty SelectionProperty =\r
-            DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null));\r
-\r
-        /// <summary>\r
-        /// 拡大率を表す\r
-        /// </summary>\r
-        public double MagnificationPower\r
-        {\r
-            get { return (double)GetValue(MagnificationPowerPropertyKey.DependencyProperty); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// 拡大率を表す依存プロパティ\r
-        /// </summary>\r
-        public static readonly DependencyPropertyKey MagnificationPowerPropertyKey =\r
-            DependencyProperty.RegisterReadOnly("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0));\r
-\r
-        /// <summary>\r
-        /// レタリング方向を表す\r
-        /// </summary>\r
-        public new FlowDirection FlowDirection\r
-        {\r
-            get { return (FlowDirection)GetValue(FlowDirectionProperty); }\r
-            set { SetValue(FlowDirectionProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// レタリング方向を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public new static readonly DependencyProperty FlowDirectionProperty =\r
-            DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight));        \r
-\r
-        /// <summary>\r
-        /// キャレット位置を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public TextPoint CaretPostion\r
-        {\r
-            get { return (TextPoint)GetValue(CaretPostionProperty); }\r
-            set { SetValue(CaretPostionProperty, value); }\r
-        }\r
-\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
-        /// </summary>\r
-        public new System.Windows.Media.Color Foreground\r
-        {\r
-            get { return (System.Windows.Media.Color)GetValue(ForegroundProperty); }\r
-            set { SetValue(ForegroundProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Foregroundの依存プロパティを表す\r
-        /// </summary>\r
-        public new static readonly DependencyProperty ForegroundProperty =\r
-            DependencyProperty.Register("Foreground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));\r
-\r
-        /// <summary>\r
-        /// 背景色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public new System.Windows.Media.Color Background\r
-        {\r
-            get { return (System.Windows.Media.Color)GetValue(BackgroundProperty); }\r
-            set { SetValue(BackgroundProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Backgroundの依存プロパティを表す\r
-        /// </summary>\r
-        public new static readonly DependencyProperty BackgroundProperty =\r
-            DependencyProperty.Register("Background", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowColor));\r
-        \r
-        /// <summary>\r
-        /// コントロールコードの文字色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public System.Windows.Media.Color ControlChar\r
-        {\r
-            get { return (System.Windows.Media.Color)GetValue(ControlCharProperty); }\r
-            set { SetValue(ControlCharProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// ControlCharの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty ControlCharProperty =\r
-            DependencyProperty.Register("ControlChar", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Gray));\r
-        \r
-        /// <summary>\r
-        /// 選択時の背景色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public System.Windows.Media.Color Hilight\r
-        {\r
-            get { return (System.Windows.Media.Color)GetValue(HilightProperty); }\r
-            set { SetValue(HilightProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Hilightの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty HilightProperty =\r
-            DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));\r
-        \r
-        /// <summary>\r
-        /// キーワード1の文字色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public System.Windows.Media.Color Keyword1\r
-        {\r
-            get { return (System.Windows.Media.Color)GetValue(Keyword1Property); }\r
-            set { SetValue(Keyword1Property, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Keyword1の依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty Keyword1Property =\r
-            DependencyProperty.Register("Keyword1", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));\r
-\r
-        /// <summary>\r
-        /// キーワード2の文字色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public System.Windows.Media.Color Keyword2\r
-        {\r
-            get { return (System.Windows.Media.Color)GetValue(Keyword2Property); }\r
-            set { SetValue(Keyword2Property, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Keyword2の依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty Keyword2Property =\r
-            DependencyProperty.Register("Keyword2", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DarkCyan));\r
-\r
-        /// <summary>\r
-        /// コメントの文字色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public System.Windows.Media.Color Comment\r
-        {\r
-            get { return (System.Windows.Media.Color)GetValue(CommentProperty); }\r
-            set { SetValue(CommentProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Commentの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty CommentProperty =\r
-            DependencyProperty.Register("Comment", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Green));\r
-\r
-        /// <summary>\r
-        /// 文字リテラルの文字色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public System.Windows.Media.Color Literal\r
-        {\r
-            get { return (System.Windows.Media.Color)GetValue(LiteralProperty); }\r
-            set { SetValue(LiteralProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Literalの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty LiteralProperty =\r
-            DependencyProperty.Register("Literal", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Brown));\r
-\r
-        /// <summary>\r
-        /// URLの文字色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public System.Windows.Media.Color URL\r
-        {\r
-            get { return (System.Windows.Media.Color)GetValue(URLProperty); }\r
-            set { SetValue(URLProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// URLの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty URLProperty =\r
-            DependencyProperty.Register("URL", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));\r
-\r
-\r
-        /// <summary>\r
-        /// ラインマーカーの色を表す\r
-        /// </summary>\r
-        public System.Windows.Media.Color LineMarker\r
-        {\r
-            get { return (System.Windows.Media.Color)GetValue(LineMarkerProperty); }\r
-            set { SetValue(LineMarkerProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// LineMarkerの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty LineMarkerProperty =\r
-            DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));\r
-\r
-        /// <summary>\r
-        /// 挿入モード時のキャレットの色を表す\r
-        /// </summary>\r
-        public System.Windows.Media.Color InsertCaret\r
-        {\r
-            get { return (System.Windows.Media.Color)GetValue(InsertCaretProperty); }\r
-            set { SetValue(InsertCaretProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// InsertCaretの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty InsertCaretProperty =\r
-            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
-        {\r
-            get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }\r
-            set { SetValue(OverwriteCaretProperty, value); }\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
-        /// <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
-        public bool InsertMode\r
-        {\r
-            get { return (bool)GetValue(InsertModeProperty); }\r
-            set { SetValue(InsertModeProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// InsertModeの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty InsertModeProperty =\r
-            DependencyProperty.Register("InsertMode",\r
-            typeof(bool),\r
-            typeof(FooTextBox),\r
-            new FrameworkPropertyMetadata(true));\r
-\r
-        /// <summary>\r
-        /// タブの文字数を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public int TabChars\r
-        {\r
-            get { return (int)GetValue(TabCharsProperty); }\r
-            set { SetValue(TabCharsProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// TabCharsの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty TabCharsProperty =\r
-            DependencyProperty.Register("TabChars",\r
-            typeof(int),\r
-            typeof(FooTextBox),\r
-            new FrameworkPropertyMetadata(4));\r
-\r
-        /// <summary>\r
-        /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです\r
-        /// </summary>\r
-        public bool RectSelectMode\r
-        {\r
-            get { return (bool)GetValue(RectSelectModeProperty); }\r
-            set { SetValue(RectSelectModeProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// RectSelectModeの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty RectSelectModeProperty =\r
-            DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));\r
-\r
-        /// <summary>\r
-        /// 折り返しの方法を指定する\r
-        /// </summary>\r
-        /// <remarks>\r
-        /// 変更した場合、レイアウトの再構築を行う必要があります\r
-        /// </remarks>\r
-        public LineBreakMethod LineBreakMethod\r
-        {\r
-            get { return (LineBreakMethod)GetValue(LineBreakProperty); }\r
-            set { SetValue(LineBreakProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// LineBreakMethodの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty LineBreakProperty =\r
-            DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None));\r
-\r
-\r
-        /// <summary>\r
-        /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます\r
-        /// </summary>\r
-        /// <remarks>\r
-        /// 変更した場合、レイアウトの再構築を行う必要があります\r
-        /// </remarks>\r
-        public int LineBreakCharCount\r
-        {\r
-            get { return (int)GetValue(LineBreakCharCountProperty); }\r
-            set { SetValue(LineBreakCharCountProperty, value); }\r
-        }\r
-\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
-        /// <summary>\r
-        /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです\r
-        /// </summary>\r
-        public bool DrawCaret\r
-        {\r
-            get { return (bool)GetValue(DrawCaretProperty); }\r
-            set { SetValue(DrawCaretProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// DrawCaretの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty DrawCaretProperty =\r
-            DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));\r
-\r
-        \r
-        /// <summary>\r
-        /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです\r
-        /// </summary>\r
-        public bool DrawCaretLine\r
-        {\r
-            get { return (bool)GetValue(DrawCaretLineProperty); }\r
-            set { SetValue(DrawCaretLineProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// DrawCaretLineの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty DrawCaretLineProperty =\r
-            DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));\r
-\r
-        /// <summary>\r
-        /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです\r
-        /// </summary>\r
-        public bool DrawLineNumber\r
-        {\r
-            get { return (bool)GetValue(DrawLineNumberProperty); }\r
-            set { SetValue(DrawLineNumberProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです\r
-        /// </summary>\r
-        public bool DrawRuler\r
-        {\r
-            get { return (bool)GetValue(DrawRulerProperty); }\r
-            set { SetValue(DrawRulerProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// DrawRulerの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty DrawRulerProperty =\r
-            DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));\r
-\r
-        \r
-        /// <summary>\r
-        /// DrawLineNumberの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty DrawLineNumberProperty =\r
-            DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));\r
-\r
-        /// <summary>\r
-        /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public bool MarkURL\r
-        {\r
-            get { return (bool)GetValue(MarkURLProperty); }\r
-            set { SetValue(MarkURLProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// MarkURLの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty MarkURLProperty =\r
-            DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));\r
-\r
-        /// <summary>\r
-        /// 全角スペースを表示するなら真。そうでないなら偽\r
-        /// </summary>\r
-        public bool ShowFullSpace\r
-        {\r
-            get { return (bool)GetValue(ShowFullSpaceProperty); }\r
-            set { SetValue(ShowFullSpaceProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// ShowFullSpaceの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty ShowFullSpaceProperty =\r
-            DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));\r
-\r
-        /// <summary>\r
-        /// 半角スペースを表示するなら真。そうでないなら偽\r
-        /// </summary>\r
-        public bool ShowHalfSpace\r
-        {\r
-            get { return (bool)GetValue(ShowHalfSpaceProperty); }\r
-            set { SetValue(ShowHalfSpaceProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// ShowHalfSpaceの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty ShowHalfSpaceProperty =\r
-            DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));\r
-\r
-        /// <summary>\r
-        /// タブを表示するなら真。そうでないなら偽\r
-        /// </summary>\r
-        public bool ShowTab\r
-        {\r
-            get { return (bool)GetValue(ShowTabProperty); }\r
-            set { SetValue(ShowTabProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// ShowTabの依存プロパティを表す\r
-        /// </summary>\r
-        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
-    /// マウスボタン関連のイベントクラス\r
-    /// </summary>\r
-    public sealed class FooMouseButtonEventArgs : MouseButtonEventArgs\r
-    {\r
-        /// <summary>\r
-        /// イベントが発生したドキュメントのインデックス\r
-        /// </summary>\r
-        public int Index\r
-        {\r
-            get;\r
-            private set;\r
-        }\r
-\r
-        /// <summary>\r
-        /// コンストラクター\r
-        /// </summary>\r
-        /// <param name="mouse">マウスデバイス</param>\r
-        /// <param name="timestamp">タイムスタンプ</param>\r
-        /// <param name="button">ボタン</param>\r
-        /// <param name="stylusDevice">スタイラスデバイス</param>\r
-        /// <param name="index">インデックス</param>\r
-        public FooMouseButtonEventArgs(MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice, int index)\r
-            : base(mouse, timestamp, button, stylusDevice)\r
-        {\r
-            this.Index = index;\r
-        }\r
-    }\r
-    /// <summary>\r
-    /// マウス関連のイベントクラス\r
-    /// </summary>\r
-    public sealed class FooMouseEventArgs : MouseEventArgs\r
-    {\r
-        /// <summary>\r
-        /// イベントが発生したドキュメントのインデックス\r
-        /// </summary>\r
-        public int Index\r
-        {\r
-            get;\r
-            private set;\r
-        }\r
-\r
-        /// <summary>\r
-        /// コンストラクター\r
-        /// </summary>\r
-        /// <param name="mouse">マウスデバイス</param>\r
-        /// <param name="timestamp">タイムスタンプ</param>\r
-        /// <param name="stylusDevice">スタイラスデバイス</param>\r
-        /// <param name="index">インデックス</param>\r
-        public FooMouseEventArgs(MouseDevice mouse,\r
-            int timestamp,\r
-            StylusDevice stylusDevice,\r
-            int index)\r
-            : base(mouse, timestamp, stylusDevice)\r
-        {\r
-            this.Index = index;\r
-        }\r
-    }\r
-}\r
+/*
+ * Copyright (C) 2013 FooProject
+ * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+using System;
+using System.Text;
+using System.Threading.Tasks;
+using System.Runtime.InteropServices;
+using System.Windows;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
+using System.Windows.Documents;
+using System.Windows.Interop;
+using System.Windows.Threading;
+using DotNetTextStore;
+using DotNetTextStore.UnmanagedAPI.TSF;
+using DotNetTextStore.UnmanagedAPI.WinDef;
+using Microsoft.Win32;
+
+namespace FooEditEngine.WPF
+{
+    /// <summary>
+    /// オートインデントを行うためのデリゲートを表す
+    /// </summary>
+    /// <param name="sender">イベント発生元のオブジェクト</param>
+    /// <param name="e">イベントデーター</param>
+    public delegate void AutoIndentHookerHandler(object sender,EventArgs e);
+
+    /// <summary>
+    /// WPFでのFooTextBoxの実装
+    /// </summary>
+    public sealed class FooTextBox : Control, IDisposable
+    {
+        const double MaxFontSize = 72.0f;
+        const double MinFontSize = 1;
+
+        EditView View;
+        Controller _Controller;
+        D2DRender Render;
+        Image image;
+        ScrollBar verticalScrollBar, horizontalScrollBar;
+        TextStore textStore;
+        DispatcherTimer timer;
+        bool disposed = false;
+        FooTextBoxAutomationPeer peer;
+        bool nowCaretMove = false;
+        
+        static FooTextBox()
+        {
+            DefaultStyleKeyProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(typeof(FooTextBox)));
+            KeyboardNavigation.IsTabStopProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(true));
+            KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(KeyboardNavigationMode.None));
+        }
+
+        /// <summary>
+        /// コンストラクター
+        /// </summary>
+        public FooTextBox()
+        {
+            this.image = new Image();
+            this.image.Stretch = Stretch.Fill;
+            this.image.HorizontalAlignment = HorizontalAlignment.Left;
+            this.image.VerticalAlignment = VerticalAlignment.Top;
+
+            this.textStore = new TextStore();
+            this.textStore.IsLoading += textStore_IsLoading;
+            this.textStore.IsReadOnly += textStore_IsReadOnly;
+            this.textStore.GetStringLength += () => this.Document.Length;
+            this.textStore.GetString += _textStore_GetString;
+            this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;
+            this.textStore.SetSelectionIndex += _textStore_SetSelectionIndex;
+            this.textStore.InsertAtSelection += _textStore_InsertAtSelection;
+            this.textStore.GetHWnd += _textStore_GetHWnd;
+            this.textStore.GetScreenExtent += _textStore_GetScreenExtent;
+            this.textStore.GetStringExtent += _textStore_GetStringExtent;
+            this.textStore.CompositionStarted += textStore_CompositionStarted;
+            this.textStore.CompositionUpdated += textStore_CompositionUpdated;
+            this.textStore.CompositionEnded += textStore_CompositionEnded;
+
+            this.Render = new D2DRender(this, 200, 200,this.image);
+            this.Render.ShowFullSpace = this.ShowFullSpace;
+            this.Render.ShowHalfSpace = this.ShowHalfSpace;
+            this.Render.ShowTab = this.ShowTab;
+
+            this.Document = new Document();
+            this.Document.LayoutLines.Render = this.Render;
+
+            this.View = new EditView(this.Document, this.Render, new Padding(5, 5, 5, 5));
+            this.View.SrcChanged += View_SrcChanged;
+            this.View.InsertMode = this.InsertMode;
+            this.View.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._Controller = new Controller(this.Document, this.View);
+            this._Controller.SelectionChanged += new EventHandler(Controller_SelectionChanged);
+
+            //Viewを作成した後に追加しないと例外が発生する
+            this.Document.Update += new DocumentUpdateEventHandler(Document_Update);
+
+            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, CopyCommand, CanExecute));
+            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, CutCommand, CanExecute));
+            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, PasteCommand, CanExecute));
+            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, DeleteCommand, CanExecute));
+            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, SelectAllCommand, CanExecute));
+            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, UndoCommand, CanExecute));
+            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, RedoCommand, CanExecute));
+            this.CommandBindings.Add(new CommandBinding(EditingCommands.ToggleInsert, ToggleInsertCommand, CanExecute));
+            this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleRectSelectMode, ToggleRectSelectCommand, CanExecute));
+            this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleFlowDirection, ToggleFlowDirectionCommand, CanExecute));
+            this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleCodePoint, ToggleCodePointCommand, CanExecute));
+
+            this.InputBindings.Add(new InputBinding(ApplicationCommands.Copy, new KeyGesture(Key.C, ModifierKeys.Control)));
+            this.InputBindings.Add(new InputBinding(ApplicationCommands.Cut, new KeyGesture(Key.X, ModifierKeys.Control)));
+            this.InputBindings.Add(new InputBinding(ApplicationCommands.Paste, new KeyGesture(Key.V, ModifierKeys.Control)));
+            this.InputBindings.Add(new InputBinding(ApplicationCommands.Delete, new KeyGesture(Key.Delete, ModifierKeys.None)));
+            this.InputBindings.Add(new InputBinding(ApplicationCommands.SelectAll, new KeyGesture(Key.A, ModifierKeys.Control)));
+            this.InputBindings.Add(new InputBinding(ApplicationCommands.Undo, new KeyGesture(Key.Z, ModifierKeys.Control)));
+            this.InputBindings.Add(new InputBinding(ApplicationCommands.Redo, new KeyGesture(Key.Y, ModifierKeys.Control)));
+            this.InputBindings.Add(new InputBinding(EditingCommands.ToggleInsert, new KeyGesture(Key.Insert, ModifierKeys.None)));
+            this.InputBindings.Add(new InputBinding(FooTextBoxCommands.ToggleCodePoint, new KeyGesture(Key.X, ModifierKeys.Alt)));
+
+            this.timer = new DispatcherTimer();
+            this.timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
+            this.timer.Tick += new EventHandler(timer_Tick);
+
+            this.Loaded += new RoutedEventHandler(FooTextBox_Loaded);
+
+            this.AutoIndentHooker = (s,e)=>{};
+
+            SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
+
+            this.SystemEvents_UserPreferenceChanged(null, new UserPreferenceChangedEventArgs(UserPreferenceCategory.Keyboard));
+
+            this.CaretMoved += (s, e) => { };
+        }
+
+        /// <summary>
+        /// ファイナライザー
+        /// </summary>
+        ~FooTextBox()
+        {
+            //Dispose(false)を呼び出すと落ちる
+            this.Dispose(false);
+        }
+
+        /// <summary>
+        /// オートインデントを行うためのイベント
+        /// </summary>
+        public AutoIndentHookerHandler AutoIndentHooker;
+
+        /// <summary>
+        /// テンプレートを適用します
+        /// </summary>
+        public override void OnApplyTemplate()
+        {
+            base.OnApplyTemplate();
+
+            Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
+            if (grid != null)
+            {
+                Grid.SetRow(this.image, 0);
+                Grid.SetColumn(this.image, 0);
+                grid.Children.Add(this.image);
+            }
+
+            this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
+            if (this.horizontalScrollBar != null)
+            {
+                this.horizontalScrollBar.SmallChange = 10;
+                this.horizontalScrollBar.LargeChange = 100;
+                this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
+                this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
+            }
+            this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
+            if (this.verticalScrollBar != null)
+            {
+                this.verticalScrollBar.SmallChange = 1;
+                this.verticalScrollBar.LargeChange = 10;
+                this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
+                this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
+            }
+        }
+
+        /// <summary>
+        /// ドキュメントを選択する
+        /// </summary>
+        /// <param name="start">開始インデックス</param>
+        /// <param name="length">長さ</param>
+        public void Select(int start, int length)
+        {
+            this._Controller.Select(start, length);
+            this.textStore.NotifySelectionChanged();
+        }
+
+        /// <summary>
+        /// キャレットを指定した行に移動させます
+        /// </summary>
+        /// <param name="index">インデックス</param>
+        /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
+        public void JumpCaret(int index)
+        {
+            this._Controller.JumpCaret(index);
+        }
+        /// <summary>
+        /// キャレットを指定した行と桁に移動させます
+        /// </summary>
+        /// <param name="row">行番号</param>
+        /// <param name="col">桁</param>
+        /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
+        public void JumpCaret(int row, int col)
+        {
+            this._Controller.JumpCaret(row, col);
+        }
+
+        /// <summary>
+        /// 選択中のテキストをクリップボードにコピーします
+        /// </summary>
+        public void Copy()
+        {
+            string text = this._Controller.SelectedText;
+            if (text != null && text != string.Empty)
+                Clipboard.SetText(text);
+        }
+
+        /// <summary>
+        /// 選択中のテキストをクリップボードに切り取ります
+        /// </summary>
+        public void Cut()
+        {
+            string text = this._Controller.SelectedText;
+            if (text != null && text != string.Empty)
+            {
+                Clipboard.SetText(text);
+                this._Controller.SelectedText = "";
+            }
+        }
+
+        /// <summary>
+        /// 選択中のテキストを貼り付けます
+        /// </summary>
+        public void Paste()
+        {
+            if (Clipboard.ContainsText() == false)
+                return;
+            string text = Clipboard.GetText();
+            this._Controller.SelectedText = text;
+        }
+
+        /// <summary>
+        /// 選択を解除する
+        /// </summary>
+        public void DeSelectAll()
+        {
+            this._Controller.DeSelectAll();
+            this.textStore.NotifySelectionChanged();
+        }
+
+        /// <summary>
+        /// 対応する座標を返します
+        /// </summary>
+        /// <param name="tp">テキストポイント</param>
+        /// <returns>座標</returns>
+        /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
+        public System.Windows.Point GetPostionFromTextPoint(TextPoint tp)
+        {
+            if (this.Document.FireUpdateEvent == false)
+                throw new InvalidOperationException("");
+            return this.View.GetPostionFromTextPoint(tp);
+        }
+
+        /// <summary>
+        /// 対応するテキストポイントを返します
+        /// </summary>
+        /// <param name="p">クライアント領域の原点を左上とする座標</param>
+        /// <returns>テキストポイント</returns>
+        public TextPoint GetTextPointFromPostion(System.Windows.Point p)
+        {
+            if (this.Document.FireUpdateEvent == false)
+                throw new InvalidOperationException("");
+            return this.View.GetTextPointFromPostion(p);
+        }
+
+        /// <summary>
+        /// 行の高さを取得します
+        /// </summary>
+        /// <param name="row">レイアウト行</param>
+        /// <returns>行の高さ</returns>
+        public double GetLineHeight(int row)
+        {
+            if (this.Document.FireUpdateEvent == false)
+                throw new InvalidOperationException("");
+            return this.View.LayoutLines.GetLayout(row).Height;;
+        }
+
+        /// <summary>
+        /// インデックスに対応する座標を得ます
+        /// </summary>
+        /// <param name="index">インデックス</param>
+        /// <returns>座標を返す</returns>
+        public System.Windows.Point GetPostionFromIndex(int index)
+        {
+            if (this.Document.FireUpdateEvent == false)
+                throw new InvalidOperationException("");
+            TextPoint tp = this.View.GetLayoutLineFromIndex(index);
+            return this.View.GetPostionFromTextPoint(tp);
+        }
+
+        /// <summary>
+        /// 座標からインデックスに変換します
+        /// </summary>
+        /// <param name="p">座標</param>
+        /// <returns>インデックスを返す</returns>
+        public int GetIndexFromPostion(System.Windows.Point p)
+        {
+            if (this.Document.FireUpdateEvent == false)
+                throw new InvalidOperationException("");
+            TextPoint tp = this.View.GetTextPointFromPostion(p);
+            return this.View.GetIndexFromLayoutLine(tp);
+        }
+
+        /// <summary>
+        /// 再描写する
+        /// </summary>
+        public void Refresh()
+        {
+            this.Refresh(this.View.PageBound);
+        }
+
+        /// <summary>
+        /// レイアウト行をすべて破棄し、再度レイアウトを行う
+        /// </summary>
+        public void PerfomLayouts()
+        {
+            this.View.PerfomLayouts();
+        }
+
+        /// <summary>
+        /// 指定行までスクロールする
+        /// </summary>
+        /// <param name="row">行</param>
+        /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
+        public void ScrollIntoView(int row, bool alignTop)
+        {
+            this.View.ScrollIntoView(row, alignTop);
+        }
+
+        /// <summary>
+        /// ストリームからドキュメントを構築する
+        /// </summary>
+        /// <param name="tr">TextReader</param>
+        /// <param name="token">キャンセル用トークン</param>
+        /// <returns>Taskオブジェクト</returns>
+        public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)
+        {
+            WinFileReader fs = new WinFileReader(tr);
+            await this.LoadAsyncImpl(fs, token);
+        }
+
+        /// <summary>
+        /// ファイルからドキュメントを構築する
+        /// </summary>
+        /// <param name="filepath">ファイルパス</param>
+        /// <param name="enc">エンコード</param>
+        /// <param name="token">キャンセル用トークン</param>
+        /// <returns>Taskオブジェクト</returns>
+        public async Task LoadFileAsync(string filepath, Encoding enc,System.Threading.CancellationTokenSource token)
+        {
+            WinFileReader fs = new WinFileReader(filepath, enc);
+            await this.LoadAsyncImpl(fs, token);
+            fs.Close();
+        }
+
+        async Task LoadAsyncImpl(WinFileReader fs,System.Threading.CancellationTokenSource token)
+        {
+            this.IsEnabled = false;
+            this.View.LayoutLines.IsFrozneDirtyFlag = true;
+            await this.Document.LoadAsync(fs, token);
+            this.View.LayoutLines.IsFrozneDirtyFlag = false;
+            TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
+            if (this.verticalScrollBar != null)
+                this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
+            this.View.CalculateLineCountOnScreen();
+            this.IsEnabled = true;
+        }
+
+        /// <summary>
+        /// ドキュメントの内容をファイルに保存する
+        /// </summary>
+        /// <param name="filepath">ファイルパス</param>
+        /// <param name="newLine">改行コード</param>
+        /// <param name="enc">エンコード</param>
+        /// <returns>Taskオブジェクト</returns>
+        public async Task SaveFile(string filepath, Encoding enc,string newLine, System.Threading.CancellationTokenSource token)
+        {
+            WinFileWriter fs = new WinFileWriter(filepath, enc);
+            fs.NewLine = newLine;
+            await this.Document.SaveAsync(fs, token);
+            fs.Close();
+        }
+
+        /// <summary>
+        /// アンマネージドリソースを開放する
+        /// </summary>
+        public void Dispose()
+        {
+            if (this.disposed)
+                return;
+            this.Dispose(true);
+            GC.SuppressFinalize(this);
+            this.disposed = true;
+        }
+
+        /// <summary>
+        /// リソースを開放する
+        /// </summary>
+        /// <param name="disposing">真ならマネージドリソースも開放し、そうでないならアンマネージドリソースのみを開放する</param>
+        void Dispose(bool disposing)
+        {
+            if (disposing)
+            {
+                this.textStore.Dispose();
+                this.timer.Stop();
+                this.View.Dispose();
+                this.Render.Dispose();
+            }
+            SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
+        }
+        
+        void Refresh(Rectangle updateRect)
+        {
+            if (this.disposed || this.Visibility == Visibility.Collapsed)
+                return;
+
+            this.Render.BegineDraw();
+            if (this.IsEnabled)
+                this.View.Draw(updateRect);
+            else
+                this.Render.FillBackground(updateRect);
+            this.Render.EndDraw();
+        }
+
+        #region Commands
+        void CanExecute(object sender, CanExecuteRoutedEventArgs e)
+        {
+            e.CanExecute = this.IsEnabled;
+        }
+
+        void ToggleCodePointCommand(object sender, RoutedEventArgs e)
+        {
+            if (!this._Controller.ConvertToChar())
+                this._Controller.ConvertToCodePoint();
+            this.Refresh();
+        }
+
+        void CopyCommand(object sender, RoutedEventArgs e)
+        {
+            this.Copy();
+        }
+
+        void CutCommand(object sender, RoutedEventArgs e)
+        {
+            this.Cut();
+            this.Refresh();
+        }
+
+        void PasteCommand(object sender, RoutedEventArgs e)
+        {
+            this.Paste();
+            this.Refresh();
+        }
+
+        void DeleteCommand(object sender, RoutedEventArgs e)
+        {
+            int oldLength = this.Document.Length;
+            this._Controller.DoDeleteAction();
+            this.Refresh();
+        }
+
+        void SelectAllCommand(object sender, RoutedEventArgs e)
+        {
+            this.Select(0, this.Document.Length);
+            this.Refresh();
+        }
+
+        void UndoCommand(object sender, RoutedEventArgs e)
+        {
+            int oldLength = this.Document.Length;
+            this.Document.UndoManager.undo();
+            this.Refresh();
+        }
+
+        void RedoCommand(object sender, RoutedEventArgs e)
+        {
+            int oldLength = this.Document.Length;
+            this.Document.UndoManager.redo();
+            this.Refresh();
+        }
+
+        void ToggleInsertCommand(object sender, RoutedEventArgs e)
+        {
+            if (this.InsertMode)
+                this.InsertMode = false;
+            else
+                this.InsertMode = true;
+            this.Refresh();
+        }
+
+        void ToggleRectSelectCommand(object sender, RoutedEventArgs e)
+        {
+            if (this.RectSelectMode)
+                this.RectSelectMode = false;
+            else
+                this.RectSelectMode = true;
+            this.Refresh();
+        }
+        void ToggleFlowDirectionCommand(object sender, RoutedEventArgs e)
+        {
+            if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
+                this.FlowDirection = System.Windows.FlowDirection.RightToLeft;
+            else
+                this.FlowDirection = System.Windows.FlowDirection.LeftToRight;
+            this.Refresh();
+        }
+        #endregion
+        #region TSF
+        internal TextStore TextStore
+        {
+            get { return this.textStore; }
+        }
+
+        bool textStore_IsReadOnly()
+        {
+            return false;
+        }
+
+        bool textStore_IsLoading()
+        {
+            return false;
+        }
+
+        void textStore_CompositionEnded()
+        {
+            TextStoreHelper.EndCompostion(this.Document);
+            this.Refresh();
+        }
+
+        void textStore_CompositionUpdated(int start, int end)
+        {
+            if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
+                this.Refresh();
+        }
+        bool textStore_CompositionStarted()
+        {
+            bool result = TextStoreHelper.StartCompstion(this.Document);
+            if (!result)
+                System.Media.SystemSounds.Beep.Play();
+            return result;
+        }
+
+        string _textStore_GetString(int start, int length)
+        {
+            return this.Document.ToString(start, length);
+        }
+
+        IntPtr _textStore_GetHWnd()
+        {
+            var hwndSource = HwndSource.FromVisual(this) as HwndSource;
+            if (hwndSource != null)
+                return hwndSource.Handle;
+            else
+                return IntPtr.Zero;
+        }
+
+        void _textStore_GetStringExtent(
+            int i_startIndex,
+            int i_endIndex,
+            out POINT o_topLeft,
+            out POINT o_bottomRight
+        )
+        {
+            Point startPos, endPos;
+            TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
+
+            double scale = this.Render.GetScale();
+            
+            startPos = PointToScreen(this.TranslatePoint(startPos.Scale(scale), this));
+            endPos = PointToScreen(this.TranslatePoint(endPos.Scale(scale), this));
+            
+            o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);
+            o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);
+        }
+
+        void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
+        {
+            var pointTopLeft = new Point(0, 0);
+            var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
+
+            pointTopLeft = PointToScreen(pointTopLeft);
+            pointBottomRight = PointToScreen(pointBottomRight);
+
+            o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
+            o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
+        }
+
+        void _textStore_GetSelectionIndex(out int o_startIndex, out int o_endIndex)
+        {
+            TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out o_startIndex, out o_endIndex);
+        }
+
+        void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)
+        {
+            TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);
+            this.Refresh();
+        }
+
+        void _textStore_InsertAtSelection(string i_value, ref int o_startIndex, ref int o_endIndex)
+        {
+            TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
+            this.Refresh();
+        }
+
+        /// <summary>
+        /// キーボードフォーカスが取得されたときに呼ばれます
+        /// </summary>
+        /// <param name="e">イベントデーター</param>
+        protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
+        {
+            base.OnGotKeyboardFocus(e);
+            this.textStore.SetFocus();
+            this.View.IsFocused = true;
+            this.Refresh();
+        }
+
+        /// <summary>
+        /// キーボードフォーカスが失われたときに呼ばれます
+        /// </summary>
+        /// <param name="e">イベントデーター</param>
+        protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
+        {
+            base.OnLostKeyboardFocus(e);
+            this.View.IsFocused = false;
+            this.Refresh();
+        }
+        #endregion
+        #region Event
+        /// <summary>
+        /// キャレットが移動したときに通知されるイベント
+        /// </summary>
+        public event EventHandler CaretMoved;
+
+        /// <inheritdoc/>
+        protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
+        {
+            this.peer = new FooTextBoxAutomationPeer(this);
+            return this.peer;
+        }
+
+
+        /// <inheritdoc/>
+        protected override void OnTextInput(TextCompositionEventArgs e)
+        {
+            if (e.Text == "\r")
+            {
+                this._Controller.DoEnterAction();
+                this.AutoIndentHooker(this, null);
+            }
+            else if (e.Text == "\b")
+            {
+                this._Controller.DoBackSpaceAction();
+            }
+            else
+            {
+                if(this.IsInputString(e.Text))
+                    this._Controller.DoInputString(e.Text);
+            }
+            this.Refresh();
+            base.OnTextInput(e);
+            e.Handled = true;
+        }
+
+        bool IsInputString(string s)
+        {
+            foreach (char charCode in s)
+            {
+                if ((0x20 <= charCode && charCode <= 0x7e)
+                    || 0x7f < charCode)
+                    return true;
+            }
+            return false;
+        }
+
+        /// <inheritdoc/>
+        protected override void OnKeyDown(KeyEventArgs e)
+        {
+            if (this.textStore.IsLocked())
+                return;
+
+            ModifierKeys modiferKeys = e.KeyboardDevice.Modifiers;
+            bool movedCaret = false;
+            switch (e.Key)
+            {
+                case Key.Up:
+                    this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
+                    this.Refresh();
+                    e.Handled = true;
+                    movedCaret = true;
+                    break;
+                case Key.Down:
+                    this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
+                    this.Refresh();
+                    e.Handled = true;
+                    movedCaret = true;
+                    break;
+                case Key.Left:
+                    this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
+                    this.Refresh();
+                    e.Handled = true;
+                    movedCaret = true;
+                    break;
+                case Key.Right:
+                    this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
+                    this.Refresh();
+                    e.Handled = true;
+                    movedCaret = true;
+                    break;
+                case Key.PageUp:
+                    this._Controller.Scroll(ScrollDirection.Up,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
+                    this.Refresh();
+                    movedCaret = true;
+                    break;
+                case Key.PageDown:
+                    this._Controller.Scroll(ScrollDirection.Down,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
+                    this.Refresh();
+                    movedCaret = true;
+                    break;
+                case Key.Home:
+                    if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
+                        this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
+                    else
+                        this._Controller.JumpToLineHead(this.View.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
+                    this.Refresh();
+                    movedCaret = true;
+                    break;
+                case Key.End:
+                    if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
+                        this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
+                    else
+                        this._Controller.JumpToLineEnd(this.View.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
+                    this.Refresh();
+                    movedCaret = true;
+                    break;
+                case Key.Tab:
+                    int oldLength = this.Document.Length;
+                    if (this.Selection.Length == 0)
+                        this._Controller.DoInputChar('\t');
+                    else if(this.IsPressedModifierKey(modiferKeys,ModifierKeys.Shift))
+                        this._Controller.DownIndent();
+                    else
+                        this._Controller.UpIndent();
+                    this.Refresh();
+                    e.Handled = true;
+                    break;
+            }
+            if (movedCaret && this.peer != null)
+                this.peer.OnNotifyCaretChanged();
+            base.OnKeyDown(e);
+        }
+
+        bool IsPressedModifierKey(ModifierKeys keys, ModifierKeys pressed)
+        {
+            if (keys == pressed)
+                return true;
+            if ((keys & pressed) == pressed)
+                return true;
+            return false;
+        }
+
+        /// <summary>
+        /// ダブルクリックされたときに呼ばれます
+        /// </summary>
+        /// <param name="e">イベントパラメーター</param>
+        /// <remarks>
+        /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
+        /// e.Handledを真にした場合、単語単位の選択が行われなくなります
+        /// </remarks>
+        protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
+        {
+            var p = this.GetDipFromPoint(e.GetPosition(this));
+            TextPoint tp = this.View.GetTextPointFromPostion(p);
+            if (tp == TextPoint.Null)
+                return;
+            int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
+
+            FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
+                e.Timestamp,
+                e.ChangedButton,
+                e.StylusDevice,
+                index);
+            newEventArgs.RoutedEvent = e.RoutedEvent;
+            base.OnMouseDoubleClick(newEventArgs);
+
+            if (newEventArgs.Handled)
+                return;
+
+            if (e.LeftButton == MouseButtonState.Pressed)
+            {
+
+                this._Controller.SelectWord(index);
+                this.textStore.NotifySelectionChanged();
+                if(this.peer != null)
+                    this.peer.OnNotifyCaretChanged();
+                this.Refresh();
+            }
+        }
+
+        /// <summary>
+        /// マウスボタンが押されたときに呼ばれます
+        /// </summary>
+        /// <param name="e">イベントパラメーター</param>
+        /// <remarks>
+        /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
+        /// e.Handledを真にした場合、キャレットの移動処理が行われなくなります
+        /// </remarks>
+        protected override void OnMouseDown(MouseButtonEventArgs e)
+        {
+            var p = this.GetDipFromPoint(e.GetPosition(this));
+            TextPoint tp = this.View.GetTextPointFromPostion(p);
+            if (tp == TextPoint.Null)
+                return;
+            int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
+
+            FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
+                e.Timestamp,
+                e.ChangedButton,
+                e.StylusDevice,
+                index);
+            newEventArgs.RoutedEvent = e.RoutedEvent;
+            base.OnMouseDown(newEventArgs);
+
+            if (newEventArgs.Handled)
+                return;
+
+            if (e.LeftButton == MouseButtonState.Pressed)
+            {
+                FoldingItem foldingData = this.View.HitFoldingData(p.X,tp.row);
+                if (foldingData != null)
+                {
+                    if (foldingData.Expand)
+                        this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
+                    else
+                        this.View.LayoutLines.FoldingCollection.Expand(foldingData);
+                    this._Controller.JumpCaret(foldingData.Start,false);
+                }
+                else
+                {
+                    this._Controller.JumpCaret(tp.row, tp.col, false);
+                }
+                if (this.peer != null)
+                    this.peer.OnNotifyCaretChanged();
+                this.View.IsFocused = true;
+                this.Focus();
+                this.Refresh();
+            }
+        }
+
+        /// <summary>
+        /// マウスが移動したときに呼ばれます
+        /// </summary>
+        /// <param name="e">イベントパラメーター</param>
+        /// <remarks>
+        /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
+        /// e.Handledを真にした場合、選択処理と状況に応じたカーソルの変化が行われなくなります
+        /// </remarks>
+        protected override void  OnMouseMove(MouseEventArgs e)
+        {
+            var p = this.GetDipFromPoint(e.GetPosition(this));
+            TextPoint tp = this.View.GetTextPointFromPostion(p);
+            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);
+            newEventArgs.RoutedEvent = e.RoutedEvent;
+            base.OnMouseMove(newEventArgs);
+
+            if (newEventArgs.Handled)
+                return;
+
+            if (this.View.HitTextArea(p.X,p.Y))
+            {
+                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;
+            }
+        }
+
+        private Point GetDipFromPoint(Point p)
+        {
+            float dpi;
+            this.Render.GetDpi(out dpi,out dpi);
+            double scale = dpi / 96.0;
+            return p.Scale(1 / scale);
+        }
+
+        /// <inheritdoc/>
+        protected override void OnMouseWheel(MouseWheelEventArgs e)
+        {
+            if(Keyboard.Modifiers == ModifierKeys.None)
+            {
+                if (e.Delta > 0)
+                    this._Controller.Scroll(ScrollDirection.Up, SystemParameters.WheelScrollLines, false, false);
+                else
+                    this._Controller.Scroll(ScrollDirection.Down, SystemParameters.WheelScrollLines, false, false);
+            }
+            else if (Keyboard.Modifiers == ModifierKeys.Control)
+            {
+                double newFontSize = this.Render.FontSize;
+                if (e.Delta > 0)
+                    newFontSize++;
+                else
+                    newFontSize--;
+                if (newFontSize > MaxFontSize)
+                    newFontSize = 72;
+                else if (newFontSize < MinFontSize)
+                    newFontSize = 1;
+                this.Render.FontSize = newFontSize;
+                SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
+            }
+            this.Refresh();
+            base.OnMouseWheel(e);
+        }
+
+        void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
+        {
+            if (e.Category == UserPreferenceCategory.Keyboard)
+            {
+                int blinkTime = (int)NativeMethods.GetCaretBlinkTime();
+                this.View.CaretBlink = blinkTime >= 0;
+                this.View.CaretBlinkTime = blinkTime * 2;
+            }
+            if (e.Category == UserPreferenceCategory.General)
+            {
+                this.View.CaretWidthOnInsertMode = SystemParameters.CaretWidth;
+            }
+        }
+
+        void Document_Update(object sender, DocumentUpdateEventArgs e)
+        {
+            if (this.textStore.IsLocked())
+                return;
+            if(e.type == UpdateType.Replace)
+                TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
+        }
+
+        void timer_Tick(object sender, EventArgs e)
+        {
+            if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)
+                return;
+            if (this.Resize(this.image.ActualWidth, this.image.ActualHeight))
+            {
+                this.Refresh();
+                return;
+            }
+
+            bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding();
+
+            ITextLayout layout = this.View.LayoutLines.GetLayout(this.View.CaretPostion.row);
+            double width = layout.GetWidthFromIndex(this.View.CaretPostion.col);
+            if (width == 0.0)
+                width = this.View.CaretWidthOnInsertMode;
+            double height = layout.Height;
+            Rectangle updateRect = new Rectangle(
+                this.View.CaretLocation.X,
+                this.View.CaretLocation.Y,
+                width,
+                height);
+
+            if (updateAll)
+                this.Refresh();
+            else
+                this.Refresh(updateRect);
+        }
+
+        void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
+        {
+            if (this.horizontalScrollBar == null)
+                return;
+            double toX;
+            if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
+                toX = this.horizontalScrollBar.Value;
+            else
+                toX = -this.horizontalScrollBar.Value;
+            this._Controller.Scroll(toX, this.View.Src.Row, false, false);
+            this.Refresh();
+        }
+
+        void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
+        {
+            if (this.verticalScrollBar == null)
+                return;
+            int newRow = (int)this.verticalScrollBar.Value;
+            if (newRow >= this.View.LayoutLines.Count)
+                return;
+            this._Controller.Scroll(this.View.Src.X,newRow, false, false);
+            this.Refresh();
+        }
+
+        void View_SrcChanged(object sender, EventArgs e)
+        {
+            if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
+                return;
+            EditView view = this.View;
+            if (view.Src.Row > this.verticalScrollBar.Maximum)
+                this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
+            double absoulteX = Math.Abs(view.Src.X);
+            if(absoulteX > this.horizontalScrollBar.Maximum)
+                this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
+            if(view.Src.Row != this.verticalScrollBar.Value)
+                this.verticalScrollBar.Value = view.Src.Row;
+            if (view.Src.X != this.horizontalScrollBar.Value)
+                this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
+        }
+
+        void Controller_SelectionChanged(object sender, EventArgs e)
+        {
+            this.View.CaretBlink = this.View.CaretBlink;
+            this.CaretMoved(this, null);
+            //こうしないと選択できなくなってしまう
+            this.nowCaretMove = true;
+            SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
+            SetValue(CaretPostionProperty, this.View.CaretPostion);
+            this.nowCaretMove = false;            
+            if(this.textStore.IsLocked() == false)
+                this.textStore.NotifySelectionChanged();
+        }
+
+        void FooTextBox_Loaded(object sender, RoutedEventArgs e)
+        {
+            this.Resize(this.image.ActualWidth, this.image.ActualHeight);
+            this.Focus();
+            this.timer.Start();
+        }
+
+        bool Resize(double width, double height)
+        {
+            if (width == 0 || height == 0)
+                throw new ArgumentOutOfRangeException();
+            if (this.Render.Resize(width, height))
+            {
+                double scale = this.Render.GetScale();
+                // RenderはレタリングはDIPだが、widthとheightの値はDPI依存なのでDIPに変換する
+                this.View.PageBound = new Rectangle(0, 0, width / scale, height / scale);
+
+                if (this.horizontalScrollBar != null)
+                {
+                    this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
+                    this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
+                }
+                if (this.verticalScrollBar != null)
+                {
+                    this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
+                    this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
+                }
+                return true;
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// プロパティーが変更されたときに呼ばれます
+        /// </summary>
+        /// <param name="e">イベントパラメーター</param>
+        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
+        {
+            switch (e.Property.Name)
+            {
+                case "IndentMode":
+                    this._Controller.IndentMode = this.IndentMode;
+                    break;
+                case "Selection":
+                    if(!this.nowCaretMove)
+                        this.Select(this.Selection.Index, this.Selection.Length);
+                    break;
+                case "CaretPostion":
+                    if (!this.nowCaretMove)
+                        this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
+                    break;
+                case "LineBreakMethod":
+                    this.View.LineBreak = this.LineBreakMethod;
+                    break;
+                case "LineBreakCharCount":
+                    this.View.LineBreakCharCount = this.LineBreakCharCount;
+                    break;
+                case "InsertMode":
+                    this.View.InsertMode = this.InsertMode;
+                    break;
+                case "TabChars":
+                    this.View.TabStops = this.TabChars;
+                    break;
+                case "RectSelectMode":
+                    this._Controller.RectSelection = this.RectSelectMode;
+                    break;
+                case "DrawCaret":
+                    this.View.HideCaret = !this.DrawCaret;
+                    break;
+                case "DrawCaretLine":
+                    this.View.HideLineMarker = !this.DrawCaretLine;
+                    break;
+                case "DrawLineNumber":
+                    this.View.DrawLineNumber = this.DrawLineNumber;
+                    this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);
+                    break;
+                case "FontFamily":
+                    this.Render.FontFamily = this.FontFamily;
+                    break;
+                case "FontSize":
+                    this.Render.FontSize = this.FontSize;
+                    break;
+                case "FontStyle":
+                    this.Render.FontStyle = this.FontStyle;
+                    break;
+                case "FontWeight":
+                    this.Render.FontWeigth = this.FontWeight;
+                    break;
+                case "Foreground":
+                    this.Render.Foreground = D2DRender.ToColor4(this.Foreground);
+                    break;
+                case "Background":
+                    this.Render.Background = D2DRender.ToColor4(this.Background);
+                    break;
+                case "ControlChar":
+                    this.Render.ControlChar =D2DRender.ToColor4( this.ControlChar);
+                    break;
+                case "Hilight":
+                    this.Render.Hilight = D2DRender.ToColor4(this.Hilight);
+                    break;
+                case "Keyword1":
+                    this.Render.Keyword1 = D2DRender.ToColor4(this.Keyword1);
+                    break;
+                case "Keyword2":
+                    this.Render.Keyword2 = D2DRender.ToColor4(this.Keyword2);
+                    break;
+                case "Comment":
+                    this.Render.Comment = D2DRender.ToColor4(this.Comment);
+                    break;
+                case "Literal":
+                    this.Render.Literal = D2DRender.ToColor4(this.Literal);
+                    break;
+                case "URL":
+                    this.Render.Url = D2DRender.ToColor4(this.URL);
+                    break;
+                case "InsertCaret":
+                    this.Render.InsertCaret = D2DRender.ToColor4(this.InsertCaret);
+                    break;
+                case "OverwriteCaret":
+                    this.Render.OverwriteCaret = D2DRender.ToColor4(this.OverwriteCaret);
+                    break;
+                case "Padding":
+                    this.View.Padding = new Padding((int)this.Padding.Left, (int)this.Padding.Top, (int)this.Padding.Right, (int)this.Padding.Bottom);
+                    break;
+                case "LineMarker":
+                    this.Render.LineMarker = D2DRender.ToColor4(this.LineMarker);
+                    break;
+                case "MarkURL":
+                    this.View.UrlMark = this.MarkURL;
+                    break;
+                case "ShowFullSpace":
+                    this.Render.ShowFullSpace = this.ShowFullSpace;
+                    break;
+                case "ShowHalfSpace":
+                    this.Render.ShowHalfSpace = this.ShowHalfSpace;
+                    break;
+                case "ShowTab":
+                    this.Render.ShowTab = this.ShowTab;
+                    break;
+                case "ShowLineBreak":
+                    this.Render.ShowLineBreak = this.ShowLineBreak;
+                    break;
+                case "FlowDirection":
+                    this.Render.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;
+                    this.horizontalScrollBar.FlowDirection = this.FlowDirection;
+                    break;
+                case "DrawRuler":
+                    this.View.HideRuler = !this.DrawRuler;
+                    this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);
+                    break;
+                case "UpdateArea":
+                    this.Render.UpdateArea = D2DRender.ToColor4(this.UpdateArea);
+                    break;
+                case "LineNumber":
+                    this.Render.LineNumber = D2DRender.ToColor4(this.LineNumber);
+                    break;
+            }
+            base.OnPropertyChanged(e);
+        }
+        #endregion
+        #region property
+
+        internal Controller Controller
+        {
+            get
+            {
+                return this._Controller;
+            }
+        }
+
+        /// <summary>
+        /// 文字列の描写に使用されるアンチエイリアシング モードを表します
+        /// </summary>
+        public TextAntialiasMode TextAntialiasMode
+        {
+            get
+            {
+                return this.Render.TextAntialiasMode;
+            }
+            set
+            {
+                this.Render.TextAntialiasMode = value;
+            }
+        }
+
+        /// <summary>
+        /// シンタックスハイライターを表す
+        /// </summary>
+        public IHilighter Hilighter
+        {
+            get
+            {
+                return this.View.Hilighter;
+            }
+            set
+            {
+                this.View.Hilighter = value;
+                this.View.LayoutLines.ClearLayoutCache();
+            }
+        }
+
+        /// <summary>
+        /// フォールティングを作成するインターフェイスを表す
+        /// </summary>
+        public IFoldingStrategy FoldingStrategy
+        {
+            get
+            {
+                return this.View.LayoutLines.FoldingStrategy;
+            }
+            set
+            {
+                this.View.LayoutLines.FoldingStrategy = value;
+                if (value == null)
+                    this.View.LayoutLines.FoldingCollection.Clear();
+            }
+        }
+
+        /// <summary>
+        /// マーカーパターンセット
+        /// </summary>
+        public MarkerPatternSet MarkerPatternSet
+        {
+            get
+            {
+                return this.View.MarkerPatternSet;
+            }
+        }
+
+        /// <summary>
+        /// ドキュメントを表す
+        /// </summary>
+        public Document Document
+        {
+            get;
+            private set;
+        }
+
+        /// <summary>
+        /// レイアウト行を表す
+        /// </summary>
+        public LineToIndexTable LayoutLineCollection
+        {
+            get { return this.View.LayoutLines; }
+        }
+
+        /// <summary>
+        /// 選択中の文字列を表す
+        /// </summary>
+        public string SelectedText
+        {
+            get
+            {
+                return this._Controller.SelectedText;
+            }
+            set
+            {
+                int oldLength = this.Document.Length;
+                this._Controller.SelectedText = value;
+            }
+        }
+
+        /// <summary>
+        /// インデントの方法を表す
+        /// </summary>
+        public IndentMode IndentMode
+        {
+            get { return (IndentMode)GetValue(IndentModeProperty); }
+            set { SetValue(IndentModeProperty, value); }
+        }
+
+        /// <summary>
+        /// IndentModeの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty IndentModeProperty =
+            DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab));
+
+        /// <summary>
+        /// 選択範囲を表す
+        /// </summary>
+        /// <remarks>
+        /// Lengthが0の場合はキャレット位置を表します。
+        /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
+        /// </remarks>
+        public TextRange Selection
+        {
+            get { return (TextRange)GetValue(SelectionProperty); }
+            set { SetValue(SelectionProperty, value); }
+        }
+
+        /// <summary>
+        /// Selectionの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty SelectionProperty =
+            DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null));
+
+        /// <summary>
+        /// 拡大率を表す
+        /// </summary>
+        public double MagnificationPower
+        {
+            get { return (double)GetValue(MagnificationPowerPropertyKey.DependencyProperty); }
+        }
+
+        /// <summary>
+        /// 拡大率を表す依存プロパティ
+        /// </summary>
+        public static readonly DependencyPropertyKey MagnificationPowerPropertyKey =
+            DependencyProperty.RegisterReadOnly("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0));
+
+        /// <summary>
+        /// レタリング方向を表す
+        /// </summary>
+        public new FlowDirection FlowDirection
+        {
+            get { return (FlowDirection)GetValue(FlowDirectionProperty); }
+            set { SetValue(FlowDirectionProperty, value); }
+        }
+
+        /// <summary>
+        /// レタリング方向を表す。これは依存プロパティです
+        /// </summary>
+        public new static readonly DependencyProperty FlowDirectionProperty =
+            DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight));        
+
+        /// <summary>
+        /// キャレット位置を表す。これは依存プロパティです
+        /// </summary>
+        public TextPoint CaretPostion
+        {
+            get { return (TextPoint)GetValue(CaretPostionProperty); }
+            set { SetValue(CaretPostionProperty, value); }
+        }
+
+        /// <summary>
+        /// CaretPostionの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty CaretPostionProperty =
+            DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(TextPoint.Null));
+        
+        /// <summary>
+        /// デフォルトの文字色を表す。これは依存プロパティです
+        /// </summary>
+        public new System.Windows.Media.Color Foreground
+        {
+            get { return (System.Windows.Media.Color)GetValue(ForegroundProperty); }
+            set { SetValue(ForegroundProperty, value); }
+        }
+
+        /// <summary>
+        /// Foregroundの依存プロパティを表す
+        /// </summary>
+        public new static readonly DependencyProperty ForegroundProperty =
+            DependencyProperty.Register("Foreground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
+
+        /// <summary>
+        /// 背景色を表す。これは依存プロパティです
+        /// </summary>
+        public new System.Windows.Media.Color Background
+        {
+            get { return (System.Windows.Media.Color)GetValue(BackgroundProperty); }
+            set { SetValue(BackgroundProperty, value); }
+        }
+
+        /// <summary>
+        /// Backgroundの依存プロパティを表す
+        /// </summary>
+        public new static readonly DependencyProperty BackgroundProperty =
+            DependencyProperty.Register("Background", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowColor));
+        
+        /// <summary>
+        /// コントロールコードの文字色を表す。これは依存プロパティです
+        /// </summary>
+        public System.Windows.Media.Color ControlChar
+        {
+            get { return (System.Windows.Media.Color)GetValue(ControlCharProperty); }
+            set { SetValue(ControlCharProperty, value); }
+        }
+
+        /// <summary>
+        /// ControlCharの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty ControlCharProperty =
+            DependencyProperty.Register("ControlChar", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Gray));
+        
+        /// <summary>
+        /// 選択時の背景色を表す。これは依存プロパティです
+        /// </summary>
+        public System.Windows.Media.Color Hilight
+        {
+            get { return (System.Windows.Media.Color)GetValue(HilightProperty); }
+            set { SetValue(HilightProperty, value); }
+        }
+
+        /// <summary>
+        /// Hilightの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty HilightProperty =
+            DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));
+        
+        /// <summary>
+        /// キーワード1の文字色を表す。これは依存プロパティです
+        /// </summary>
+        public System.Windows.Media.Color Keyword1
+        {
+            get { return (System.Windows.Media.Color)GetValue(Keyword1Property); }
+            set { SetValue(Keyword1Property, value); }
+        }
+
+        /// <summary>
+        /// Keyword1の依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty Keyword1Property =
+            DependencyProperty.Register("Keyword1", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
+
+        /// <summary>
+        /// キーワード2の文字色を表す。これは依存プロパティです
+        /// </summary>
+        public System.Windows.Media.Color Keyword2
+        {
+            get { return (System.Windows.Media.Color)GetValue(Keyword2Property); }
+            set { SetValue(Keyword2Property, value); }
+        }
+
+        /// <summary>
+        /// Keyword2の依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty Keyword2Property =
+            DependencyProperty.Register("Keyword2", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DarkCyan));
+
+        /// <summary>
+        /// コメントの文字色を表す。これは依存プロパティです
+        /// </summary>
+        public System.Windows.Media.Color Comment
+        {
+            get { return (System.Windows.Media.Color)GetValue(CommentProperty); }
+            set { SetValue(CommentProperty, value); }
+        }
+
+        /// <summary>
+        /// Commentの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty CommentProperty =
+            DependencyProperty.Register("Comment", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Green));
+
+        /// <summary>
+        /// 文字リテラルの文字色を表す。これは依存プロパティです
+        /// </summary>
+        public System.Windows.Media.Color Literal
+        {
+            get { return (System.Windows.Media.Color)GetValue(LiteralProperty); }
+            set { SetValue(LiteralProperty, value); }
+        }
+
+        /// <summary>
+        /// Literalの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty LiteralProperty =
+            DependencyProperty.Register("Literal", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Brown));
+
+        /// <summary>
+        /// URLの文字色を表す。これは依存プロパティです
+        /// </summary>
+        public System.Windows.Media.Color URL
+        {
+            get { return (System.Windows.Media.Color)GetValue(URLProperty); }
+            set { SetValue(URLProperty, value); }
+        }
+
+        /// <summary>
+        /// URLの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty URLProperty =
+            DependencyProperty.Register("URL", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
+
+
+        /// <summary>
+        /// ラインマーカーの色を表す
+        /// </summary>
+        public System.Windows.Media.Color LineMarker
+        {
+            get { return (System.Windows.Media.Color)GetValue(LineMarkerProperty); }
+            set { SetValue(LineMarkerProperty, value); }
+        }
+
+        /// <summary>
+        /// LineMarkerの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty LineMarkerProperty =
+            DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));
+
+        /// <summary>
+        /// 挿入モード時のキャレットの色を表す
+        /// </summary>
+        public System.Windows.Media.Color InsertCaret
+        {
+            get { return (System.Windows.Media.Color)GetValue(InsertCaretProperty); }
+            set { SetValue(InsertCaretProperty, value); }
+        }
+
+        /// <summary>
+        /// InsertCaretの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty InsertCaretProperty =
+            DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
+
+        /// <summary>
+        /// 行更新フラグの色を表す
+        /// </summary>
+        public System.Windows.Media.Color UpdateArea
+        {
+            get { return (System.Windows.Media.Color)GetValue(UpdateAreaProperty); }
+            set { SetValue(UpdateAreaProperty, value); }
+        }
+
+        /// <summary>
+        /// UpdateAreaの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty UpdateAreaProperty =
+            DependencyProperty.Register("UpdateArea", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));        
+
+        /// <summary>
+        /// 上書きモード時のキャレット職を表す
+        /// </summary>
+        public System.Windows.Media.Color OverwriteCaret
+        {
+            get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }
+            set { SetValue(OverwriteCaretProperty, value); }
+        }
+        
+        /// <summary>
+        /// OverwriteCaretの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty OverwriteCaretProperty =
+            DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
+
+        /// <summary>
+        /// 行番号の色を表す
+        /// </summary>
+        public System.Windows.Media.Color LineNumber
+        {
+            get { return (System.Windows.Media.Color)GetValue(LineNumberProperty); }
+            set { SetValue(LineNumberProperty, value); }
+        }
+
+        /// <summary>
+        /// Using a DependencyProperty as the backing store for LineNumber.  This enables animation, styling, binding, etc...
+        /// </summary>
+        public static readonly DependencyProperty LineNumberProperty =
+            DependencyProperty.Register("LineNumber", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray));
+
+        /// <summary>
+        /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
+        /// </summary>
+        public bool InsertMode
+        {
+            get { return (bool)GetValue(InsertModeProperty); }
+            set { SetValue(InsertModeProperty, value); }
+        }
+
+        /// <summary>
+        /// InsertModeの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty InsertModeProperty =
+            DependencyProperty.Register("InsertMode",
+            typeof(bool),
+            typeof(FooTextBox),
+            new FrameworkPropertyMetadata(true));
+
+        /// <summary>
+        /// タブの文字数を表す。これは依存プロパティです
+        /// </summary>
+        public int TabChars
+        {
+            get { return (int)GetValue(TabCharsProperty); }
+            set { SetValue(TabCharsProperty, value); }
+        }
+
+        /// <summary>
+        /// TabCharsの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty TabCharsProperty =
+            DependencyProperty.Register("TabChars",
+            typeof(int),
+            typeof(FooTextBox),
+            new FrameworkPropertyMetadata(4));
+
+        /// <summary>
+        /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
+        /// </summary>
+        public bool RectSelectMode
+        {
+            get { return (bool)GetValue(RectSelectModeProperty); }
+            set { SetValue(RectSelectModeProperty, value); }
+        }
+
+        /// <summary>
+        /// RectSelectModeの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty RectSelectModeProperty =
+            DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
+
+        /// <summary>
+        /// 折り返しの方法を指定する
+        /// </summary>
+        /// <remarks>
+        /// 変更した場合、レイアウトの再構築を行う必要があります
+        /// </remarks>
+        public LineBreakMethod LineBreakMethod
+        {
+            get { return (LineBreakMethod)GetValue(LineBreakProperty); }
+            set { SetValue(LineBreakProperty, value); }
+        }
+
+        /// <summary>
+        /// LineBreakMethodの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty LineBreakProperty =
+            DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None));
+
+
+        /// <summary>
+        /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
+        /// </summary>
+        /// <remarks>
+        /// 変更した場合、レイアウトの再構築を行う必要があります
+        /// </remarks>
+        public int LineBreakCharCount
+        {
+            get { return (int)GetValue(LineBreakCharCountProperty); }
+            set { SetValue(LineBreakCharCountProperty, value); }
+        }
+
+        /// <summary>
+        /// LineBreakCharCountの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty LineBreakCharCountProperty =
+            DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
+
+        /// <summary>
+        /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
+        /// </summary>
+        public bool DrawCaret
+        {
+            get { return (bool)GetValue(DrawCaretProperty); }
+            set { SetValue(DrawCaretProperty, value); }
+        }
+
+        /// <summary>
+        /// DrawCaretの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty DrawCaretProperty =
+            DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
+
+        
+        /// <summary>
+        /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
+        /// </summary>
+        public bool DrawCaretLine
+        {
+            get { return (bool)GetValue(DrawCaretLineProperty); }
+            set { SetValue(DrawCaretLineProperty, value); }
+        }
+
+        /// <summary>
+        /// DrawCaretLineの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty DrawCaretLineProperty =
+            DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
+
+        /// <summary>
+        /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
+        /// </summary>
+        public bool DrawLineNumber
+        {
+            get { return (bool)GetValue(DrawLineNumberProperty); }
+            set { SetValue(DrawLineNumberProperty, value); }
+        }
+
+        /// <summary>
+        /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
+        /// </summary>
+        public bool DrawRuler
+        {
+            get { return (bool)GetValue(DrawRulerProperty); }
+            set { SetValue(DrawRulerProperty, value); }
+        }
+
+        /// <summary>
+        /// DrawRulerの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty DrawRulerProperty =
+            DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
+
+        
+        /// <summary>
+        /// DrawLineNumberの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty DrawLineNumberProperty =
+            DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
+
+        /// <summary>
+        /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
+        /// </summary>
+        public bool MarkURL
+        {
+            get { return (bool)GetValue(MarkURLProperty); }
+            set { SetValue(MarkURLProperty, value); }
+        }
+
+        /// <summary>
+        /// MarkURLの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty MarkURLProperty =
+            DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
+
+        /// <summary>
+        /// 全角スペースを表示するなら真。そうでないなら偽
+        /// </summary>
+        public bool ShowFullSpace
+        {
+            get { return (bool)GetValue(ShowFullSpaceProperty); }
+            set { SetValue(ShowFullSpaceProperty, value); }
+        }
+
+        /// <summary>
+        /// ShowFullSpaceの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty ShowFullSpaceProperty =
+            DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
+
+        /// <summary>
+        /// 半角スペースを表示するなら真。そうでないなら偽
+        /// </summary>
+        public bool ShowHalfSpace
+        {
+            get { return (bool)GetValue(ShowHalfSpaceProperty); }
+            set { SetValue(ShowHalfSpaceProperty, value); }
+        }
+
+        /// <summary>
+        /// ShowHalfSpaceの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty ShowHalfSpaceProperty =
+            DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
+
+        /// <summary>
+        /// タブを表示するなら真。そうでないなら偽
+        /// </summary>
+        public bool ShowTab
+        {
+            get { return (bool)GetValue(ShowTabProperty); }
+            set { SetValue(ShowTabProperty, value); }
+        }
+
+        /// <summary>
+        /// ShowTabの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty ShowTabProperty =
+            DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
+
+        /// <summary>
+        /// 改行マークを表示するなら真。そうでないなら偽
+        /// </summary>
+        public bool ShowLineBreak
+        {
+            get { return (bool)GetValue(ShowLineBreakProperty); }
+            set { SetValue(ShowLineBreakProperty, value); }
+        }
+
+        /// <summary>
+        /// ShowLineBreakの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty ShowLineBreakProperty =
+            DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
+        
+        #endregion
+    }
+    /// <summary>
+    /// マウスボタン関連のイベントクラス
+    /// </summary>
+    public sealed class FooMouseButtonEventArgs : MouseButtonEventArgs
+    {
+        /// <summary>
+        /// イベントが発生したドキュメントのインデックス
+        /// </summary>
+        public int Index
+        {
+            get;
+            private set;
+        }
+
+        /// <summary>
+        /// コンストラクター
+        /// </summary>
+        /// <param name="mouse">マウスデバイス</param>
+        /// <param name="timestamp">タイムスタンプ</param>
+        /// <param name="button">ボタン</param>
+        /// <param name="stylusDevice">スタイラスデバイス</param>
+        /// <param name="index">インデックス</param>
+        public FooMouseButtonEventArgs(MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice, int index)
+            : base(mouse, timestamp, button, stylusDevice)
+        {
+            this.Index = index;
+        }
+    }
+    /// <summary>
+    /// マウス関連のイベントクラス
+    /// </summary>
+    public sealed class FooMouseEventArgs : MouseEventArgs
+    {
+        /// <summary>
+        /// イベントが発生したドキュメントのインデックス
+        /// </summary>
+        public int Index
+        {
+            get;
+            private set;
+        }
+
+        /// <summary>
+        /// コンストラクター
+        /// </summary>
+        /// <param name="mouse">マウスデバイス</param>
+        /// <param name="timestamp">タイムスタンプ</param>
+        /// <param name="stylusDevice">スタイラスデバイス</param>
+        /// <param name="index">インデックス</param>
+        public FooMouseEventArgs(MouseDevice mouse,
+            int timestamp,
+            StylusDevice stylusDevice,
+            int index)
+            : base(mouse, timestamp, stylusDevice)
+        {
+            this.Index = index;
+        }
+    }
+}
index 01ee348..20ac750 100644 (file)
@@ -1,60 +1,60 @@
-using System.Reflection;\r
-using System.Resources;\r
-using System.Runtime.CompilerServices;\r
-using System.Runtime.InteropServices;\r
-using System.Windows;\r
-\r
-// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。\r
-// アセンブリに関連付けられている情報を変更するには、\r
-// これらの属性値を変更してください。\r
-[assembly: AssemblyTitle("FooEditEngine")]\r
-[assembly: AssemblyDescription("")]\r
-[assembly: AssemblyConfiguration("")]\r
-[assembly: AssemblyCompany("")]\r
-[assembly: AssemblyProduct("FooEditEngine")]\r
-[assembly: AssemblyCopyright("Copyright ©  2012")]\r
-[assembly: AssemblyTrademark("")]\r
-[assembly: AssemblyCulture("")]\r
-\r
-// ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから\r
-// 参照不可能になります。COM からこのアセンブリ内の型にアクセスする場合は、\r
-// その型の ComVisible 属性を true に設定してください。\r
-[assembly: ComVisible(false)]\r
-\r
-//ローカライズ可能なアプリケーションのビルドを開始するには、\r
-//.csproj ファイルの <UICulture>CultureYouAreCodingWith</UICulture> を\r
-//<PropertyGroup> 内部で設定します。たとえば、\r
-//ソース ファイルで英語を使用している場合、<UICulture> を en-US に設定します。次に、\r
-//下の NeutralResourceLanguage 属性のコメントを解除します。下の行の "en-US" を\r
-//プロジェクト ファイルの UICulture 設定と一致するよう更新します。\r
-\r
-//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]\r
-\r
-\r
-[assembly: ThemeInfo(\r
-    ResourceDictionaryLocation.None, //テーマ固有のリソース ディクショナリが置かれている場所\r
-    //(リソースがページ、\r
-    // またはアプリケーション リソース ディクショナリに見つからない場合に使用されます)\r
-    ResourceDictionaryLocation.SourceAssembly //汎用リソース ディクショナリが置かれている場所\r
-    //(リソースがページ、\r
-    // アプリケーション、またはいずれのテーマ固有のリソース ディクショナリにも見つからない場合に使用されます)\r
-)]\r
-\r
-\r
-// アセンブリのバージョン情報は、以下の 4 つの値で構成されています:\r
-//\r
-//      Major Version\r
-//      Minor Version \r
-//      Build Number\r
-//      Revision\r
-//\r
-// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を \r
-// 既定値にすることができます:\r
-// [assembly: AssemblyVersion("1.0.*")]\r
-[assembly: AssemblyVersion("1.200.2.0")]\r
-[assembly: AssemblyFileVersion("1.200.2.0")]\r
-\r
-#if DEBUG\r
-[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("UnitTest")]\r
-#endif\r
-\r
+using System.Reflection;
+using System.Resources;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Windows;
+
+// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
+// アセンブリに関連付けられている情報を変更するには、
+// これらの属性値を変更してください。
+[assembly: AssemblyTitle("FooEditEngine")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("FooEditEngine")]
+[assembly: AssemblyCopyright("Copyright ©  2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから
+// 参照不可能になります。COM からこのアセンブリ内の型にアクセスする場合は、
+// その型の ComVisible 属性を true に設定してください。
+[assembly: ComVisible(false)]
+
+//ローカライズ可能なアプリケーションのビルドを開始するには、
+//.csproj ファイルの <UICulture>CultureYouAreCodingWith</UICulture> を
+//<PropertyGroup> 内部で設定します。たとえば、
+//ソース ファイルで英語を使用している場合、<UICulture> を en-US に設定します。次に、
+//下の NeutralResourceLanguage 属性のコメントを解除します。下の行の "en-US" を
+//プロジェクト ファイルの UICulture 設定と一致するよう更新します。
+
+//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
+
+
+[assembly: ThemeInfo(
+    ResourceDictionaryLocation.None, //テーマ固有のリソース ディクショナリが置かれている場所
+    //(リソースがページ、
+    // またはアプリケーション リソース ディクショナリに見つからない場合に使用されます)
+    ResourceDictionaryLocation.SourceAssembly //汎用リソース ディクショナリが置かれている場所
+    //(リソースがページ、
+    // アプリケーション、またはいずれのテーマ固有のリソース ディクショナリにも見つからない場合に使用されます)
+)]
+
+
+// アセンブリのバージョン情報は、以下の 4 つの値で構成されています:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を 
+// 既定値にすることができます:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.200.3.0")]
+[assembly: AssemblyFileVersion("1.200.3.0")]
+
+#if DEBUG
+[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("UnitTest")]
+#endif
+