OSDN Git Service

行を生成するメソッドをLineToIndexTableに移動した
[fooeditengine/FooEditEngine.git] / Metro / FooEditEngine / FooTextBox.cs
index c50b7f7..b15ff8e 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.ComponentModel;\r
-using System.Threading.Tasks;\r
-using Windows.ApplicationModel.Resources.Core;\r
-using Windows.Devices.Input;\r
-using Windows.System;\r
-using Windows.ApplicationModel.DataTransfer;\r
-using Windows.Foundation;\r
-using Windows.UI;\r
-using Windows.UI.Input;\r
-using Windows.UI.Core;\r
-using Windows.UI.Popups;\r
-using Windows.UI.Text;\r
-using Windows.UI.Xaml.Media;\r
-using Windows.UI.Xaml;\r
-using Windows.UI.Xaml.Controls;\r
-using Windows.UI.Xaml.Controls.Primitives;\r
-using Windows.UI.Xaml.Input;\r
-using DotNetTextStore;\r
-using DotNetTextStore.UnmanagedAPI.TSF;\r
-using DotNetTextStore.UnmanagedAPI.WinDef;\r
-\r
-// テンプレート コントロールのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234235 を参照してください\r
-\r
-namespace FooEditEngine.Metro\r
-{\r
-    /// <summary>\r
-    /// テキストボックスコントロール\r
-    /// </summary>\r
-    public sealed class FooTextBox : Control,IDisposable\r
-    {\r
-        EditView View;\r
-        Controller _Controller;\r
-        D2DRender Render;\r
-        ScrollBar horizontalScrollBar, verticalScrollBar;\r
-        Windows.UI.Xaml.Shapes.Rectangle rectangle;\r
-        GestureRecognizer gestureRecongnizer = new GestureRecognizer();\r
-        TextStore2 textStore;\r
-        FooTextBoxAutomationPeer peer;\r
-        bool nowCaretMove = false;\r
-\r
-        /// <summary>\r
-        /// コンストラクター\r
-        /// </summary>\r
-        public FooTextBox()\r
-        {\r
-            this.DefaultStyleKey = typeof(FooTextBox);\r
-\r
-            this.textStore = new TextStore2();\r
-            this.textStore.IsLoading += textStore_IsLoading;\r
-            this.textStore.IsReadOnly += textStore_IsReadOnly;\r
-            this.textStore.GetDpi += textStore_GetDpi;\r
-            this.textStore.GetStringLength += () => this.Document.Length;\r
-            this.textStore.GetString += _textStore_GetString;\r
-            this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;\r
-            this.textStore.SetSelectionIndex += _textStore_SetSelectionIndex;\r
-            this.textStore.InsertAtSelection += _textStore_InsertAtSelection;\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.Document = new Document();\r
-            DocumentExtend.Progress += Document_Progress;\r
-\r
-            this.rectangle = new Windows.UI.Xaml.Shapes.Rectangle();\r
-            this.rectangle.Margin = this.Padding;\r
-            this.Render = new D2DRender(this,this.rectangle,this.textStore);\r
-\r
-            this.View = new EditView(this.Document, this.Render, new Padding(5, Gripper.HitAreaWidth, Gripper.HitAreaWidth / 2, Gripper.HitAreaWidth));\r
-            this.View.SrcChanged += View_SrcChanged;\r
-            this.View.InsertMode = this.InsertMode;\r
-            this.View.DrawLineNumber = this.DrawLineNumber;\r
-            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 += Controller_SelectionChanged;\r
-\r
-            this.FirstGripper = new Gripper(this._Controller, this.View, this.Render, GripperPostion.Upper);\r
-            this.SecondGripper = new Gripper(this._Controller, this.View, this.Render, GripperPostion.Bottom);\r
-\r
-            this.gestureRecongnizer.GestureSettings = GestureSettings.Drag | \r
-                GestureSettings.RightTap | \r
-                GestureSettings.Tap | \r
-                GestureSettings.ManipulationTranslateX | \r
-                GestureSettings.ManipulationTranslateY |\r
-                GestureSettings.ManipulationScale;\r
-            this.gestureRecongnizer.RightTapped += gestureRecongnizer_RightTapped;\r
-            this.gestureRecongnizer.Tapped += gestureRecongnizer_Tapped;\r
-            this.gestureRecongnizer.Dragging += gestureRecongnizer_Dragging;\r
-            this.gestureRecongnizer.ManipulationStarted += gestureRecongnizer_ManipulationStarted;\r
-            this.gestureRecongnizer.ManipulationUpdated += gestureRecongnizer_ManipulationUpdated;\r
-            this.gestureRecongnizer.ManipulationCompleted += gestureRecongnizer_ManipulationCompleted;\r
-\r
-            //Viewの初期化が終わった直後に置かないと例外が発生する\r
-            this.Document.Update += Document_Update;\r
-\r
-            Window.Current.CoreWindow.CharacterReceived += CoreWindow_CharacterReceived;\r
-\r
-            this.SizeChanged += FooTextBox_SizeChanged;\r
-\r
-            this.Loaded += FooTextBox_Loaded;\r
-        }\r
-\r
-        /// <summary>\r
-        /// ファイナライザー\r
-        /// </summary>\r
-        ~FooTextBox()\r
-        {\r
-            this.Dispose(false);\r
-        }\r
-\r
-        /// <summary>\r
-        /// アンマネージドリソースを解放する\r
-        /// </summary>\r
-        public void Dispose()\r
-        {\r
-            this.Dispose(true);\r
-            GC.SuppressFinalize(this);\r
-        }\r
-\r
-        bool Disposed = false;\r
-        private void Dispose(bool disposing)\r
-        {\r
-            if (this.Disposed)\r
-                return;\r
-            if (disposing)\r
-            {\r
-                this.textStore.Dispose();\r
-                this.View.Dispose();\r
-                this.Render.Dispose();\r
-            }\r
-            DocumentExtend.Progress -= this.Document_Progress;\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
-        }\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
-            {\r
-                DataPackage dataPackage = new DataPackage();\r
-                dataPackage.RequestedOperation = DataPackageOperation.Copy;\r
-                dataPackage.SetText(text);\r
-\r
-                Clipboard.SetContent(dataPackage); \r
-            }\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
-                DataPackage dataPackage = new DataPackage();\r
-                dataPackage.RequestedOperation = DataPackageOperation.Copy;\r
-                dataPackage.SetText(text);\r
-\r
-                Clipboard.SetContent(dataPackage);\r
-                \r
-                this._Controller.SelectedText = "";\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// 選択中のテキストを貼り付けます\r
-        /// </summary>\r
-        public async Task PasteAsync()\r
-        {\r
-            var dataPackageView = Clipboard.GetContent();\r
-            if (dataPackageView.Contains(StandardDataFormats.Text))\r
-            {\r
-                this._Controller.SelectedText = await dataPackageView.GetTextAsync();\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// すべて選択する\r
-        /// </summary>\r
-        public void SelectAll()\r
-        {\r
-            this._Controller.Select(0, this.Document.Length);\r
-        }\r
-\r
-        /// <summary>\r
-        /// 選択を解除する\r
-        /// </summary>\r
-        public void DeSelectAll()\r
-        {\r
-            this._Controller.DeSelectAll();\r
-        }\r
-\r
-        /// <summary>\r
-        /// 対応する座標を返します\r
-        /// </summary>\r
-        /// <param name="tp">テキストポイント</param>\r
-        /// <returns>座標</returns>\r
-        /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>\r
-        public Windows.Foundation.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(Windows.Foundation.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 Windows.Foundation.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(Windows.Foundation.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
-        #region command\r
-        void CopyCommand()\r
-        {\r
-            this.Copy();\r
-        }\r
-\r
-        void CutCommand()\r
-        {\r
-            this.Cut();\r
-            this.Refresh();\r
-        }\r
-\r
-        async Task PasteCommand()\r
-        {\r
-            await this.PasteAsync();\r
-            this.Refresh();\r
-        }\r
-\r
-        #endregion\r
-\r
-        #region event\r
-        /// <inheritdoc/>\r
-        protected override Windows.UI.Xaml.Automation.Peers.AutomationPeer OnCreateAutomationPeer()\r
-        {\r
-            this.peer = new FooTextBoxAutomationPeer(this);\r
-            return this.peer;\r
-        }\r
-\r
-        /// <inheritdoc/>\r
-        protected 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.rectangle, 0);\r
-                Grid.SetColumn(this.rectangle, 0);\r
-                grid.Children.Add(this.rectangle);\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
-        /// <inheritdoc/>\r
-        protected override void OnGotFocus(RoutedEventArgs e)\r
-        {\r
-            base.OnGotFocus(e);\r
-            this.textStore.SetFocus();\r
-            this.View.IsFocused = true;\r
-            this.Refresh();\r
-        }\r
-\r
-        /// <inheritdoc/>\r
-        protected override void OnLostFocus(RoutedEventArgs e)\r
-        {\r
-            base.OnLostFocus(e);\r
-            this.View.IsFocused = false;\r
-            this.Refresh();\r
-        }\r
-\r
-        /// <inheritdoc/>\r
-        protected override async void OnKeyDown(KeyRoutedEventArgs e)\r
-        {\r
-            bool isControlPressed = this.IsModiferKeyPressed(VirtualKey.Control);\r
-            bool isShiftPressed = this.IsModiferKeyPressed(VirtualKey.Shift);\r
-            bool isMovedCaret = false;\r
-            switch (e.Key)\r
-            {\r
-                case VirtualKey.Up:\r
-                    this._Controller.MoveCaretVertical(-1, isShiftPressed);\r
-                    this.Refresh();\r
-                    e.Handled = true;\r
-                    isMovedCaret = true;\r
-                    break;\r
-                case VirtualKey.Down:\r
-                    this._Controller.MoveCaretVertical(+1, isShiftPressed);\r
-                    this.Refresh();\r
-                    e.Handled = true;\r
-                    isMovedCaret = true;\r
-                    break;\r
-                case VirtualKey.Left:\r
-                    this._Controller.MoveCaretHorizontical(-1, isShiftPressed, isControlPressed);\r
-                    this.Refresh();\r
-                    e.Handled = true;\r
-                    isMovedCaret = true;\r
-                    break;\r
-                case VirtualKey.Right:\r
-                    this._Controller.MoveCaretHorizontical(1, isShiftPressed, isControlPressed);\r
-                    this.Refresh();\r
-                    e.Handled = true;\r
-                    isMovedCaret = true;\r
-                    break;\r
-                case VirtualKey.PageUp:\r
-                    this._Controller.Scroll(ScrollDirection.Up, this.View.LineCountOnScreen, isShiftPressed, true);\r
-                    this.Refresh();\r
-                    isMovedCaret = true;\r
-                    break;\r
-                case VirtualKey.PageDown:\r
-                    this._Controller.Scroll(ScrollDirection.Down, this.View.LineCountOnScreen, isShiftPressed, true);\r
-                    this.Refresh();\r
-                    isMovedCaret = true;\r
-                    break;\r
-                case VirtualKey.Home:\r
-                    if (isControlPressed)\r
-                        this._Controller.JumpToHead(isShiftPressed);\r
-                    else\r
-                        this.Controller.JumpToLineHead(this.View.CaretPostion.row,isShiftPressed);\r
-                    this.Refresh();\r
-                    isMovedCaret = true;\r
-                    break;\r
-                case VirtualKey.End:\r
-                    if (isControlPressed)\r
-                        this._Controller.JumpToEnd(isShiftPressed);\r
-                    else\r
-                        this.Controller.JumpToLineEnd(this.View.CaretPostion.row,isShiftPressed);\r
-                    this.Refresh();\r
-                    isMovedCaret = true;\r
-                    break;\r
-                case VirtualKey.Tab:\r
-                    if (!isControlPressed)\r
-                    {\r
-                        if (this._Controller.SelectionLength == 0)\r
-                            this._Controller.DoInputChar('\t');\r
-                        else if (isShiftPressed)\r
-                            this._Controller.DownIndent();\r
-                        else\r
-                            this._Controller.UpIndent();\r
-                        this.Refresh();\r
-                        e.Handled = true;\r
-                    }\r
-                    break;\r
-                case VirtualKey.Enter:\r
-                    this._Controller.DoEnterAction();\r
-                    this.Refresh();\r
-                    e.Handled = true;\r
-                    break;\r
-                case VirtualKey.Insert:\r
-                    if(this.View.InsertMode)\r
-                        this.View.InsertMode = false;\r
-                    else\r
-                        this.View.InsertMode = true;\r
-                    this.Refresh();\r
-                    e.Handled = true;\r
-                    break;\r
-                case VirtualKey.A:\r
-                    if (isControlPressed)\r
-                    {\r
-                        this.SelectAll();\r
-                        this.Refresh();\r
-                        e.Handled = true;\r
-                    }\r
-                    break;\r
-                case VirtualKey.B:\r
-                    if (isControlPressed)\r
-                    {\r
-                        if (this._Controller.RectSelection)\r
-                            this._Controller.RectSelection = false;\r
-                        else\r
-                            this._Controller.RectSelection = true;\r
-                        this.Refresh();\r
-                        e.Handled = true;\r
-                    }\r
-                    break;\r
-                case VirtualKey.C:\r
-                    if (isControlPressed)\r
-                    {\r
-                        this.CopyCommand();\r
-                        e.Handled = true;\r
-                    }\r
-                    break;\r
-                case VirtualKey.X:\r
-                    if (isControlPressed)\r
-                    {\r
-                        this.CutCommand();\r
-                        e.Handled = true;\r
-                    }\r
-                    break;\r
-                case VirtualKey.V:\r
-                    if (isControlPressed)\r
-                    {\r
-                        await this.PasteCommand();\r
-                        e.Handled = true;\r
-                    }\r
-                    break;\r
-                case VirtualKey.Y:\r
-                    if (isControlPressed)\r
-                    {\r
-                        this.Document.UndoManager.redo();\r
-                        this.Refresh();\r
-                        e.Handled = true;\r
-                    }\r
-                    break;\r
-                case VirtualKey.Z:\r
-                    if (isControlPressed)\r
-                    {\r
-                        this.Document.UndoManager.undo();\r
-                        this.Refresh();\r
-                        e.Handled = true;\r
-                    }\r
-                    break;\r
-                case VirtualKey.Back:\r
-                    this._Controller.DoBackSpaceAction();\r
-                    this.Refresh();\r
-                    e.Handled = true;\r
-                    break;\r
-                case VirtualKey.Delete:\r
-                    this._Controller.DoDeleteAction();\r
-                    this.Refresh();\r
-                    e.Handled = true;\r
-                    break;\r
-            }\r
-            if (isMovedCaret && this.peer != null)\r
-                this.peer.OnNotifyCaretChanged();\r
-            base.OnKeyDown(e);\r
-        }\r
-\r
-        /// <inheritdoc/>\r
-        protected override void OnPointerPressed(PointerRoutedEventArgs e)\r
-        {\r
-            this.CapturePointer(e.Pointer);\r
-            this.gestureRecongnizer.ProcessDownEvent(e.GetCurrentPoint(this));\r
-            e.Handled = true;\r
-        }\r
-\r
-        /// <inheritdoc/>\r
-        protected override void OnPointerMoved(PointerRoutedEventArgs e)\r
-        {\r
-            this.gestureRecongnizer.ProcessMoveEvents(e.GetIntermediatePoints(this));\r
-            e.Handled = true;\r
-\r
-            if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)\r
-            {\r
-                Point p = e.GetCurrentPoint(this).Position;\r
-                if (this.View.HitTextArea(p.X, p.Y))\r
-                {\r
-                    TextPoint tp = this.View.GetTextPointFromPostion(p);\r
-                    if (this._Controller.IsMarker(tp, HilightType.Url))\r
-                        Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Hand, 101);\r
-                    else\r
-                        Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.IBeam, 101);\r
-                }\r
-                else\r
-                {\r
-                    Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 101);\r
-                }\r
-            }\r
-        }\r
-\r
-        /// <inheritdoc/>\r
-        protected override void OnPointerReleased(PointerRoutedEventArgs e)\r
-        {\r
-            this.gestureRecongnizer.ProcessUpEvent(e.GetCurrentPoint(this));\r
-            this.ReleasePointerCapture(e.Pointer);\r
-            e.Handled = true;\r
-        }\r
-\r
-        /// <inheritdoc/>\r
-        protected override void OnPointerCanceled(PointerRoutedEventArgs e)\r
-        {\r
-            this.gestureRecongnizer.CompleteGesture();\r
-            this.ReleasePointerCapture(e.Pointer);\r
-            e.Handled = true;\r
-        }\r
-\r
-        /// <inheritdoc/>\r
-        protected override void OnPointerCaptureLost(PointerRoutedEventArgs e)\r
-        {\r
-            this.gestureRecongnizer.CompleteGesture();\r
-            this.ReleasePointerCapture(e.Pointer);\r
-            e.Handled = true;\r
-        }\r
-\r
-        /// <inheritdoc/>\r
-        protected override void OnPointerWheelChanged(PointerRoutedEventArgs e)\r
-        {\r
-            bool shift = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Shift) ==\r
-                Windows.System.VirtualKeyModifiers.Shift;\r
-            bool ctrl = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Control) ==\r
-                Windows.System.VirtualKeyModifiers.Control;\r
-            this.gestureRecongnizer.ProcessMouseWheelEvent(e.GetCurrentPoint(this), shift, ctrl);\r
-            e.Handled = true;\r
-        }\r
-\r
-        void CoreWindow_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)\r
-        {\r
-            if (this.FocusState == FocusState.Unfocused || !this.IsEnabled)\r
-                return;\r
-            if (args.KeyCode >= 00 && args.KeyCode <= 0x1f)\r
-                return;\r
-            this._Controller.DoInputString(Char.ConvertFromUtf32((int)args.KeyCode));\r
-            this.Refresh();\r
-        }\r
-\r
-        double textStore_GetDpi()\r
-        {\r
-            float dpi;\r
-            this.Render.GetDpi(out dpi, out dpi);\r
-            return dpi;\r
-        }\r
-\r
-        bool textStore_IsReadOnly()\r
-        {\r
-            return false;\r
-        }\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
-            return TextStoreHelper.StartCompstion(this.Document);\r
-        }\r
-\r
-        string _textStore_GetString(int start, int length)\r
-        {\r
-            return this.Document.ToString(start, length);\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
-            var gt = this.TransformToVisual(Window.Current.Content);\r
-            startPos = gt.TransformPoint(startPos);\r
-            endPos = gt.TransformPoint(endPos);\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
-            var gt = this.TransformToVisual(Window.Current.Content);\r
-            pointTopLeft = gt.TransformPoint(pointTopLeft);\r
-            pointBottomRight = gt.TransformPoint(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)\r
-        {\r
-            TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);\r
-            this.Refresh();\r
-        }\r
-\r
-        void Controller_SelectionChanged(object sender, EventArgs e)\r
-        {\r
-            //こうしないと選択できなくなってしまう\r
-            this.nowCaretMove = true;\r
-            SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));\r
-            SetValue(CaretPostionPropertyKey, this.View.CaretPostion);\r
-            this.nowCaretMove = false;\r
-            if (this.textStore.IsLocked() == false)\r
-                this.textStore.NotifySelectionChanged();\r
-        }\r
-\r
-        Gripper FirstGripper, SecondGripper;\r
-        bool HittedCaret;\r
-        Gripper hittedGripper;\r
-        void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)\r
-        {\r
-            this.HittedCaret = false;\r
-            this.hittedGripper = null;\r
-\r
-            Point p = e.Position;\r
-            TextPoint tp = this.View.GetTextPointFromPostion(p);\r
-            if (tp == this.View.CaretPostion)\r
-            {\r
-                HittedCaret = true;\r
-            }\r
-            \r
-            if (this.FirstGripper.IsHit(p))\r
-            {\r
-                hittedGripper = this.FirstGripper;\r
-                HittedCaret = true;\r
-            }\r
-            \r
-            else if (this.SecondGripper.IsHit(p))\r
-            {\r
-                hittedGripper = this.SecondGripper;\r
-                HittedCaret = true;\r
-            }\r
-        }\r
-\r
-        void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)\r
-        {\r
-            if (HittedCaret)\r
-            {\r
-                Point p;\r
-                if (this.hittedGripper == null)\r
-                     p = e.Position;\r
-                else\r
-                    p = this.hittedGripper.AdjustPoint(e.Position);\r
-\r
-                if (hittedGripper != null)\r
-                {\r
-                    TextPoint tp = this.View.GetTextPointFromPostion(p);\r
-                    if (this._Controller.IsReverseSelect())\r
-                    {\r
-                        if (Object.ReferenceEquals(hittedGripper,this.SecondGripper))\r
-                            this._Controller.MoveSelectBefore(tp);\r
-                        else\r
-                            this._Controller.MoveCaretAndSelect(tp);\r
-                    }\r
-                    else\r
-                    {\r
-                        if (Object.ReferenceEquals(hittedGripper,this.FirstGripper))\r
-                            this._Controller.MoveSelectBefore(tp);\r
-                        else\r
-                            this._Controller.MoveCaretAndSelect(tp);\r
-                    }\r
-                    if (this.peer != null)\r
-                        this.peer.OnNotifyCaretChanged();\r
-                    this.Refresh();\r
-                    return;\r
-                }\r
-            }\r
-            if (e.Delta.Scale < 1)\r
-            {\r
-                double newSize = this.Render.FontSize - 1;\r
-                if (newSize < 1)\r
-                    newSize = 1;\r
-                this.Render.FontSize = newSize;\r
-                this.Refresh();\r
-                SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);\r
-                return;\r
-            }\r
-            \r
-            if (e.Delta.Scale > 1)\r
-            {\r
-                double newSize = this.Render.FontSize + 1;\r
-                if (newSize > 72)\r
-                    newSize = 72;\r
-                this.Render.FontSize = newSize;\r
-                this.Refresh();\r
-                SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);\r
-                return;\r
-            }\r
-\r
-            Point translation = e.Delta.Translation;\r
-\r
-            int scrollCount = (int)Math.Abs(translation.Y);\r
-            if (scrollCount > 0)\r
-            {\r
-                if (scrollCount > this.View.LineCountOnScreen)  //ホイール対策\r
-                    scrollCount = this.View.LineCountOnScreen;\r
-                if (translation.Y > 0)\r
-                    this._Controller.Scroll(ScrollDirection.Up, scrollCount, false, false);\r
-                else\r
-                    this._Controller.Scroll(ScrollDirection.Down, scrollCount, false, false);\r
-                this.FirstGripper.Enabled = false;\r
-                this.SecondGripper.Enabled = false;\r
-                this.Refresh();\r
-                return;\r
-            }\r
-\r
-            int deltax = (int)Math.Abs(translation.X);\r
-            if (deltax != 0)\r
-            {\r
-                if (translation.X < 0)\r
-                    this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);\r
-                else\r
-                    this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);\r
-                this.FirstGripper.Enabled = false;\r
-                this.SecondGripper.Enabled = false;\r
-                this.Refresh();\r
-            }\r
-        }\r
-\r
-        void gestureRecongnizer_ManipulationCompleted(GestureRecognizer sender, ManipulationCompletedEventArgs e)\r
-        {\r
-        }\r
-\r
-        async void gestureRecongnizer_RightTapped(GestureRecognizer sender, RightTappedEventArgs e)\r
-        {\r
-            ResourceMap map = ResourceManager.Current.MainResourceMap.GetSubtree("FooEditEngine.Metro/Resources");\r
-            ResourceContext context = ResourceContext.GetForCurrentView();\r
-            if (this.View.HitTextArea(e.Position.X, e.Position.Y))\r
-            {\r
-                FooContextMenuEventArgs args = new FooContextMenuEventArgs(e.Position);\r
-                if (this.ContextMenuOpening != null)\r
-                    this.ContextMenuOpening(this, args);\r
-                if (!args.Handled)\r
-                {\r
-                    PopupMenu ContextMenu = new PopupMenu();\r
-                    ContextMenu.Commands.Add(new UICommand(map.GetValue("CopyMenuName", context).ValueAsString, (command) =>\r
-                    {\r
-                        this.CopyCommand();\r
-                    }));\r
-                    ContextMenu.Commands.Add(new UICommand(map.GetValue("CutMenuName", context).ValueAsString, (command) =>\r
-                    {\r
-                        this.CutCommand();\r
-                    }));\r
-                    ContextMenu.Commands.Add(new UICommand(map.GetValue("PasteMenuName", context).ValueAsString, async (command) =>\r
-                    {\r
-                        await this.PasteCommand();\r
-                    }));\r
-                    if (this._Controller.RectSelection)\r
-                    {\r
-                        ContextMenu.Commands.Add(new UICommand(map.GetValue("LineSelectMenuName", context).ValueAsString, (command) =>\r
-                        {\r
-                            this._Controller.RectSelection = false;\r
-                        }));\r
-                    }\r
-                    else\r
-                    {\r
-                        ContextMenu.Commands.Add(new UICommand(map.GetValue("RectSelectMenuName", context).ValueAsString, (command) =>\r
-                        {\r
-                            this._Controller.RectSelection = true;\r
-                        }));\r
-                    }\r
-                    await ContextMenu.ShowAsync(Util.GetScreentPoint(e.Position,this));\r
-                }\r
-            }\r
-        }\r
-\r
-        void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)\r
-        {\r
-            bool touched = e.PointerDeviceType == PointerDeviceType.Touch;\r
-            this.FirstGripper.Enabled = touched;\r
-            this.SecondGripper.Enabled = touched;\r
-            this.JumpCaret(e.Position);\r
-        }\r
-\r
-        void JumpCaret(Point p)\r
-        {\r
-            TextPoint tp = this.View.GetTextPointFromPostion(p);\r
-            if (tp == TextPoint.Null)\r
-                return;\r
-\r
-            int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);\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.Refresh();\r
-        }\r
-\r
-        void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)\r
-        {\r
-            Point p = e.Position;\r
-            if (this.View.HitTextArea(p.X, p.Y))\r
-            {\r
-                TextPoint tp = this.View.GetTextPointFromPostion(p);\r
-                this._Controller.MoveCaretAndSelect(tp);\r
-                if (this.peer != null)\r
-                    this.peer.OnNotifyCaretChanged();\r
-                this.Refresh();\r
-            }\r
-        }\r
-\r
-        bool IsModiferKeyPressed(VirtualKey key)\r
-        {\r
-            CoreVirtualKeyStates state = Window.Current.CoreWindow.GetKeyState(key);\r
-            return (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;\r
-        }\r
-        void Refresh(Rectangle updateRect)\r
-        {\r
-            if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0/* || !this.Render.IsCanDraw()*/)\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.FirstGripper.Draw();\r
-            this.SecondGripper.Draw();\r
-            this.Render.EndDraw();\r
-        }\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(this.rectangle, width, height))\r
-            {\r
-                this.View.PageBound = new Rectangle(0, 0, width, height);\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
-        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 FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)\r
-        {\r
-            if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))\r
-            {\r
-                this.Refresh();\r
-                return;\r
-            }\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 == 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.FirstGripper.Enabled = false;\r
-            this.SecondGripper.Enabled = 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.FirstGripper.Enabled = false;\r
-            this.SecondGripper.Enabled = false;\r
-            this.Refresh();\r
-        }\r
-\r
-        void Document_Update(object sender, DocumentUpdateEventArgs e)\r
-        {\r
-            if (this.textStore.IsLocked())\r
-                return;\r
-            TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);\r
-        }\r
-\r
-        void Document_Progress(object sender, ProgressEventArgs e)\r
-        {\r
-            switch (e.state)\r
-            {\r
-                case ProgressState.Complete:\r
-                    TextStoreHelper.NotifyTextChanged(this.textStore,0,0,this.Document.Length);\r
-                    if (this.verticalScrollBar != null)\r
-                        this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;\r
-                    this.View.CalculateLineCountOnScreen();\r
-                    break;\r
-            }\r
-        }\r
-\r
-        void FooTextBox_Loaded(object sender, RoutedEventArgs e)\r
-        {\r
-            this.Focus(FocusState.Programmatic);\r
-        }\r
-\r
-        /// <inheritdoc/>\r
-        public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)\r
-        {\r
-            FooTextBox source = (FooTextBox)sender;\r
-            if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)\r
-                source._Controller.Select(source.Selection.Index,source.Selection.Length);\r
-            if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)\r
-                source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col);\r
-            if (e.Property.Equals(InsertModeProperty))\r
-                source.View.InsertMode = source.InsertMode;\r
-            if (e.Property.Equals(TabCharsProperty))\r
-                source.View.TabStops = source.TabChars;\r
-            if (e.Property.Equals(RectSelectModeProperty))\r
-                source._Controller.RectSelection = source.RectSelectMode;\r
-            if (e.Property.Equals(DrawCaretProperty))\r
-                source.View.HideCaret = !source.DrawCaret;\r
-            if (e.Property.Equals(DrawCaretLineProperty))\r
-                source.View.HideLineMarker = !source.DrawCaretLine;\r
-            if (e.Property.Equals(DrawLineNumberProperty))\r
-            {\r
-                source.View.DrawLineNumber = source.DrawLineNumber;\r
-                source._Controller.JumpCaret(source.View.CaretPostion.row, source.View.CaretPostion.col);\r
-            }\r
-            if(e.Property.Equals(MagnificationPowerPropertyKey))\r
-                source.Render.FontSize = source.FontSize * source.MagnificationPower;\r
-            if (e.Property.Equals(FontFamilyProperty))\r
-                source.Render.FontFamily = source.FontFamily;\r
-            if (e.Property.Equals(FontStyleProperty))\r
-                source.Render.FontStyle = source.FontStyle;\r
-            if (e.Property.Equals(FontWeightProperty))\r
-                source.Render.FontWeigth = source.FontWeight;\r
-            if (e.Property.Equals(FontSizeProperty))\r
-                source.Render.FontSize = source.FontSize;\r
-            if (e.Property.Equals(ForegroundProperty))\r
-                source.Render.Foreground = D2DRenderBase.ToColor4(source.Foreground);\r
-            if (e.Property.Equals(BackgroundProperty))\r
-                source.Render.Background = D2DRenderBase.ToColor4(source.Background);\r
-            if (e.Property.Equals(ControlCharProperty))\r
-                source.Render.ControlChar = D2DRenderBase.ToColor4(source.ControlChar);\r
-            if (e.Property.Equals(HilightProperty))\r
-                source.Render.Hilight = D2DRenderBase.ToColor4(source.Hilight);\r
-            if (e.Property.Equals(Keyword1Property))\r
-                source.Render.Keyword1 = D2DRenderBase.ToColor4(source.Keyword1);\r
-            if (e.Property.Equals(Keyword2Property))\r
-                source.Render.Keyword2 = D2DRenderBase.ToColor4(source.Keyword2);\r
-            if (e.Property.Equals(CommentProperty))\r
-                source.Render.Comment = D2DRenderBase.ToColor4(source.Comment);\r
-            if (e.Property.Equals(LiteralProperty))\r
-                source.Render.Literal = D2DRenderBase.ToColor4(source.Literal);\r
-            if (e.Property.Equals(URLProperty))\r
-                source.Render.Url = D2DRenderBase.ToColor4(source.URL);\r
-            if (e.Property.Equals(InsertCaretProperty))\r
-                source.Render.InsertCaret = D2DRenderBase.ToColor4(source.InsertCaret);\r
-            if (e.Property.Equals(OverwriteCaretProperty))\r
-                source.Render.OverwriteCaret = D2DRenderBase.ToColor4(source.OverwriteCaret);\r
-            if (e.Property.Equals(PaddingProperty))\r
-                source.View.Padding = new Padding((int)source.Padding.Left, (int)source.Padding.Top, (int)source.Padding.Right, (int)source.Padding.Bottom);\r
-            if (e.Property.Equals(LineMarkerProperty))\r
-                source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);\r
-            if (e.Property.Equals(MarkURLProperty))\r
-                source.View.UrlMark = source.MarkURL;\r
-            if (e.Property.Equals(ShowFullSpaceProperty))\r
-                source.Render.ShowFullSpace = source.ShowFullSpace;\r
-            if (e.Property.Equals(ShowHalfSpaceProperty))\r
-                source.Render.ShowHalfSpace = source.ShowHalfSpace;\r
-            if (e.Property.Equals(ShowTabProperty))\r
-                source.Render.ShowTab = source.ShowTab;\r
-            if (e.Property.Equals(ShowLineBreakProperty))\r
-                source.Render.ShowLineBreak = source.ShowLineBreak;\r
-            if (e.Property.Equals(LineBreakProperty))\r
-                source.View.LineBreak = source.LineBreakMethod;\r
-            if (e.Property.Equals(LineBreakCharCountProperty))\r
-                source.View.LineBreakCharCount = source.LineBreakCharCount;\r
-            if (e.Property.Equals(UpdateAreaProperty))\r
-                source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);\r
-            if (e.Property.Equals(FlowDirectionProperty))\r
-            {\r
-                source.Render.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;\r
-                if(source.horizontalScrollBar != null)\r
-                    source.horizontalScrollBar.FlowDirection = source.FlowDirection;\r
-            }\r
-            if (e.Property.Equals(DrawRulerProperty))\r
-            {\r
-                source.View.HideRuler = !source.DrawRuler;\r
-                source._Controller.JumpCaret(source.View.CaretPostion.row, source.View.CaretPostion.col);\r
-            }            \r
-        }\r
-        #endregion\r
-\r
-        #region event\r
-        \r
-        /// <summary>\r
-        /// コンテキストメニューが表示されるときに呼び出されます\r
-        /// </summary>\r
-        public event EventHandler<FooContextMenuEventArgs> ContextMenuOpening;\r
-\r
-        #endregion\r
-\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
-        /// <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(0));\r
-\r
-        /// <summary>\r
-        /// 拡大率を表す\r
-        /// </summary>\r
-        public double MagnificationPower\r
-        {\r
-            get { return (double)GetValue(MagnificationPowerPropertyKey); }\r
-            set { SetValue(MagnificationPowerPropertyKey, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// 拡大率を表す依存プロパティ\r
-        /// </summary>\r
-        public static readonly DependencyProperty MagnificationPowerPropertyKey =\r
-            DependencyProperty.Register("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0, OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// キャレット位置を表す\r
-        /// </summary>\r
-        public TextPoint CaretPostion\r
-        {\r
-            get { return (TextPoint)GetValue(CaretPostionPropertyKey); }\r
-            set { SetValue(CaretPostionPropertyKey, value); }\r
-        }\r
-\r
-        static readonly DependencyProperty CaretPostionPropertyKey =\r
-            DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(new TextPoint(), OnPropertyChanged));\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,OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// フォントファミリーを表す\r
-        /// </summary>\r
-        public new FontFamily FontFamily\r
-        {\r
-            get { return (FontFamily)GetValue(FontFamilyProperty); }\r
-            set { SetValue(FontFamilyProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// FontFamilyの依存プロパティを表す\r
-        /// </summary>\r
-        public new static readonly DependencyProperty FontFamilyProperty =\r
-            DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(FooTextBox), new PropertyMetadata(new FontFamily("Cambria"), OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// フォントサイズを表す\r
-        /// </summary>\r
-        public new double FontSize\r
-        {\r
-            get { return (double)GetValue(FontSizeProperty); }\r
-            set { SetValue(FontSizeProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// FontSizeの依存プロパティを表す\r
-        /// </summary>\r
-        public new static readonly DependencyProperty FontSizeProperty =\r
-            DependencyProperty.Register("FontSize", typeof(double), typeof(FooTextBox), new PropertyMetadata(12.0,OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// フォントスタイルを表す\r
-        /// </summary>\r
-        public new FontStyle FontStyle\r
-        {\r
-            get { return (FontStyle)GetValue(FontStyleProperty); }\r
-            set { SetValue(FontStyleProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// FontStyleの依存プロパティを表す\r
-        /// </summary>\r
-        public new static readonly DependencyProperty FontStyleProperty =\r
-            DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(FooTextBox), new PropertyMetadata(FontStyle.Normal,OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// フォントの幅を表す\r
-        /// </summary>\r
-        public new FontWeight FontWeight\r
-        {\r
-            get { return (FontWeight)GetValue(FontWeightProperty); }\r
-            set { SetValue(FontWeightProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// FontWeigthの依存プロパティを表す\r
-        /// </summary>\r
-        public new static readonly DependencyProperty FontWeightProperty =\r
-            DependencyProperty.Register("FontWeigth", typeof(FontWeight), typeof(FooTextBox), new PropertyMetadata(FontWeights.Normal,OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// デフォルトの文字色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public new Windows.UI.Color Foreground\r
-        {\r
-            get { return (Windows.UI.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(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// 背景色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public new Windows.UI.Color Background\r
-        {\r
-            get { return (Windows.UI.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(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// コントロールコードの文字色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public Windows.UI.Color ControlChar\r
-        {\r
-            get { return (Windows.UI.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(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// 選択時の背景色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public Windows.UI.Color Hilight\r
-        {\r
-            get { return (Windows.UI.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(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DeepSkyBlue, OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// キーワード1の文字色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public Windows.UI.Color Keyword1\r
-        {\r
-            get { return (Windows.UI.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(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// キーワード2の文字色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public Windows.UI.Color Keyword2\r
-        {\r
-            get { return (Windows.UI.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(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DarkCyan, OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// コメントの文字色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public Windows.UI.Color Comment\r
-        {\r
-            get { return (Windows.UI.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(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Green, OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// 文字リテラルの文字色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public Windows.UI.Color Literal\r
-        {\r
-            get { return (Windows.UI.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(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Brown, OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// URLの文字色を表す。これは依存プロパティです\r
-        /// </summary>\r
-        public Windows.UI.Color URL\r
-        {\r
-            get { return (Windows.UI.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(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// 行更新フラグの色を表す\r
-        /// </summary>\r
-        public Windows.UI.Color UpdateArea\r
-        {\r
-            get { return (Windows.UI.Color)GetValue(UpdateAreaProperty); }\r
-            set { SetValue(UpdateAreaProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// UpdateAreaの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty UpdateAreaProperty =\r
-            DependencyProperty.Register("UpdateArea", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));\r
-\r
-        /// <summary>\r
-        /// ラインマーカーの色を表す\r
-        /// </summary>\r
-        public Windows.UI.Color LineMarker\r
-        {\r
-            get { return (Windows.UI.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(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// 挿入モード時のキャレットの色を表す\r
-        /// </summary>\r
-        public Windows.UI.Color InsertCaret\r
-        {\r
-            get { return (Windows.UI.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(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// 上書きモード時のキャレット職を表す\r
-        /// </summary>\r
-        public Windows.UI.Color OverwriteCaret\r
-        {\r
-            get { return (Windows.UI.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(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));\r
-\r
-        /// <summary>\r
-        /// 余白を表す\r
-        /// </summary>\r
-        public new Thickness Padding\r
-        {\r
-            get { return (Thickness)GetValue(PaddingProperty); }\r
-            set { SetValue(PaddingProperty, value); }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Paddingの依存プロパティを表す\r
-        /// </summary>\r
-        public new static readonly DependencyProperty PaddingProperty =\r
-            DependencyProperty.Register("Padding", typeof(Thickness), typeof(FooTextBox), new PropertyMetadata(new Thickness(),OnPropertyChanged));        \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 PropertyMetadata(true, OnPropertyChanged));\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 PropertyMetadata(4, OnPropertyChanged));\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 PropertyMetadata(false, OnPropertyChanged));\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, OnPropertyChanged));\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 PropertyMetadata(true, OnPropertyChanged));\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 PropertyMetadata(false, OnPropertyChanged));\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, OnPropertyChanged));\r
-\r
-\r
-        /// <summary>\r
-        /// DrawLineNumberの依存プロパティを表す\r
-        /// </summary>\r
-        public static readonly DependencyProperty DrawLineNumberProperty =\r
-            DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));\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 PropertyMetadata(false, OnPropertyChanged));\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 PropertyMetadata(false, OnPropertyChanged));\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 PropertyMetadata(false, OnPropertyChanged));\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 PropertyMetadata(false, OnPropertyChanged));\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,OnPropertyChanged));\r
-\r
-        \r
-        #endregion\r
-\r
-    }\r
-    /// <summary>\r
-    /// コンテキストメニューのイベントデーターを表す\r
-    /// </summary>\r
-    public class FooContextMenuEventArgs\r
-    {\r
-        /// <summary>\r
-        /// 処理済みなら真。そうでないなら偽\r
-        /// </summary>\r
-        public bool Handled = false;\r
-        /// <summary>\r
-        /// コンテキストメニューを表示すべき座標を表す\r
-        /// </summary>\r
-        public Windows.Foundation.Point Postion;\r
-        /// <summary>\r
-        /// コンストラクター\r
-        /// </summary>\r
-        /// <param name="pos"></param>\r
-        public FooContextMenuEventArgs(Windows.Foundation.Point pos)\r
-        {\r
-            this.Postion = pos;\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.ComponentModel;
+using System.Threading.Tasks;
+using Windows.ApplicationModel.Resources.Core;
+using Windows.Devices.Input;
+using Windows.System;
+using Windows.ApplicationModel.DataTransfer;
+using Windows.Foundation;
+using Windows.UI;
+using Windows.UI.Input;
+using Windows.UI.Core;
+using Windows.UI.Popups;
+using Windows.UI.Text;
+using Windows.UI.Xaml.Media;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Controls.Primitives;
+using Windows.UI.Xaml.Input;
+using DotNetTextStore;
+using DotNetTextStore.UnmanagedAPI.TSF;
+using DotNetTextStore.UnmanagedAPI.WinDef;
+
+// テンプレート コントロールのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234235 を参照してください
+
+namespace FooEditEngine.Metro
+{
+    /// <summary>
+    /// テキストボックスコントロール
+    /// </summary>
+    public sealed class FooTextBox : Control,IDisposable
+    {
+        EditView View;
+        Controller _Controller;
+        D2DRender Render;
+        ScrollBar horizontalScrollBar, verticalScrollBar;
+        Windows.UI.Xaml.Shapes.Rectangle rectangle;
+        GestureRecognizer gestureRecongnizer = new GestureRecognizer();
+        TextStore2 textStore;
+        FooTextBoxAutomationPeer peer;
+        bool nowCaretMove = false;
+        Document _Document;
+        DispatcherTimer timer = new DispatcherTimer();
+
+        /// <summary>
+        /// コンストラクター
+        /// </summary>
+        public FooTextBox()
+        {
+            this.DefaultStyleKey = typeof(FooTextBox);
+
+            this.textStore = new TextStore2();
+            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.GetScreenExtent += _textStore_GetScreenExtent;
+            this.textStore.GetStringExtent += _textStore_GetStringExtent;
+            this.textStore.CompositionStarted += textStore_CompositionStarted;
+            this.textStore.CompositionUpdated += textStore_CompositionUpdated;
+            this.textStore.CompositionEnded += textStore_CompositionEnded;
+
+            this.rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
+            this.rectangle.Margin = this.Padding;
+            this.Render = new D2DRender(this,this.rectangle,this.textStore);
+
+            this.Document = new Document();
+
+            this.View = new EditView(this.Document, this.Render, new Padding(5, Gripper.HitAreaWidth, Gripper.HitAreaWidth / 2, Gripper.HitAreaWidth));
+            this.View.SrcChanged += View_SrcChanged;
+            this.View.InsertMode = this.InsertMode;
+            this.Document.DrawLineNumber = this.DrawLineNumber;
+            this.View.HideCaret = !this.DrawCaret;
+            this.View.HideLineMarker = !this.DrawCaretLine;
+            this.Document.HideRuler = !this.DrawRuler;
+            this.Document.UrlMark = this.MarkURL;
+            this.Document.TabStops = this.TabChars;
+
+            this._Controller = new Controller(this.Document, this.View);
+            this.Document.SelectionChanged += Controller_SelectionChanged;
+
+            this.gestureRecongnizer.GestureSettings = GestureSettings.Drag | 
+                GestureSettings.RightTap | 
+                GestureSettings.Tap | 
+                GestureSettings.DoubleTap |
+                GestureSettings.ManipulationTranslateX | 
+                GestureSettings.ManipulationTranslateY |
+                GestureSettings.ManipulationScale |
+                GestureSettings.ManipulationTranslateInertia |
+                GestureSettings.ManipulationScaleInertia;
+            this.gestureRecongnizer.RightTapped += gestureRecongnizer_RightTapped;
+            this.gestureRecongnizer.Tapped += gestureRecongnizer_Tapped;
+            this.gestureRecongnizer.Dragging += gestureRecongnizer_Dragging;
+            this.gestureRecongnizer.ManipulationInertiaStarting += GestureRecongnizer_ManipulationInertiaStarting; ;
+            this.gestureRecongnizer.ManipulationStarted += gestureRecongnizer_ManipulationStarted;
+            this.gestureRecongnizer.ManipulationUpdated += gestureRecongnizer_ManipulationUpdated;
+            this.gestureRecongnizer.ManipulationCompleted += gestureRecongnizer_ManipulationCompleted;
+
+            this.timer.Interval = new TimeSpan(0, 0, 0, 0, 500);
+            this.timer.Tick += this.timer_Tick;
+            this.timer.Start();
+
+            //Viewの初期化が終わった直後に置かないと例外が発生する
+            this.Document.Update += Document_Update;
+
+            Window.Current.CoreWindow.CharacterReceived += CoreWindow_CharacterReceived;
+
+            this.SizeChanged += FooTextBox_SizeChanged;
+
+            this.Loaded += FooTextBox_Loaded;
+        }
+
+        /// <summary>
+        /// ファイナライザー
+        /// </summary>
+        ~FooTextBox()
+        {
+            this.Dispose(false);
+        }
+
+        /// <summary>
+        /// アンマネージドリソースを解放する
+        /// </summary>
+        public void Dispose()
+        {
+            this.Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
+        bool Disposed = false;
+        private void Dispose(bool disposing)
+        {
+            if (this.Disposed)
+                return;
+            if (disposing)
+            {
+                this.textStore.Dispose();
+                this.View.Dispose();
+                this.Render.Dispose();
+            }
+        }
+
+        /// <summary>
+        /// ドキュメントを選択する
+        /// </summary>
+        /// <param name="start">開始インデックス</param>
+        /// <param name="length">長さ</param>
+        public void Select(int start, int length)
+        {
+            this.Document.Select(start, length);
+        }
+
+        /// <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)
+            {
+                DataPackage dataPackage = new DataPackage();
+                dataPackage.RequestedOperation = DataPackageOperation.Copy;
+                dataPackage.SetText(text);
+
+                Clipboard.SetContent(dataPackage); 
+            }
+        }
+
+        /// <summary>
+        /// 選択中のテキストをクリップボードに切り取ります
+        /// </summary>
+        public void Cut()
+        {
+            string text = this._Controller.SelectedText;
+            if (text != null && text != string.Empty)
+            {
+                DataPackage dataPackage = new DataPackage();
+                dataPackage.RequestedOperation = DataPackageOperation.Copy;
+                dataPackage.SetText(text);
+
+                Clipboard.SetContent(dataPackage);
+                
+                this._Controller.SelectedText = "";
+            }
+        }
+
+        /// <summary>
+        /// 選択中のテキストを貼り付けます
+        /// </summary>
+        public async Task PasteAsync()
+        {
+            var dataPackageView = Clipboard.GetContent();
+            if (dataPackageView.Contains(StandardDataFormats.Text))
+            {
+                this._Controller.SelectedText = await dataPackageView.GetTextAsync();
+            }
+        }
+
+        /// <summary>
+        /// すべて選択する
+        /// </summary>
+        public void SelectAll()
+        {
+            this.Document.Select(0, this.Document.Length);
+        }
+
+        /// <summary>
+        /// 選択を解除する
+        /// </summary>
+        public void DeSelectAll()
+        {
+            this._Controller.DeSelectAll();
+        }
+
+        /// <summary>
+        /// 対応する座標を返します
+        /// </summary>
+        /// <param name="tp">テキストポイント</param>
+        /// <returns>座標</returns>
+        /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
+        public Windows.Foundation.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(Windows.Foundation.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 Windows.Foundation.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(Windows.Foundation.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="sr">StremReader</param>
+        /// <returns>Taskオブジェクト</returns>
+        public async Task LoadFileAsync(System.IO.StreamReader sr, System.Threading.CancellationTokenSource token)
+        {
+            await this.Document.LoadAsync(sr, token);
+        }
+
+        /// <summary>
+        /// ドキュメントの内容をファイルに保存する
+        /// </summary>
+        /// <param name="sw">StreamWriter</param>
+        /// <param name="token">キャンセル用トークン</param>
+        /// <returns>Taskオブジェクト</returns>
+        public async Task SaveFile(System.IO.StreamWriter sw, System.Threading.CancellationTokenSource token)
+        {
+            await this.Document.SaveAsync(sw, token);
+        }
+
+        #region command
+        void CopyCommand()
+        {
+            this.Copy();
+        }
+
+        void CutCommand()
+        {
+            this.Cut();
+            this.Refresh();
+        }
+
+        async Task PasteCommand()
+        {
+            await this.PasteAsync();
+            this.Refresh();
+        }
+
+        #endregion
+
+        #region event
+        /// <inheritdoc/>
+        protected override Windows.UI.Xaml.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
+        {
+            this.peer = new FooTextBoxAutomationPeer(this);
+            return this.peer;
+        }
+
+        /// <inheritdoc/>
+        protected override void OnApplyTemplate()
+        {
+            base.OnApplyTemplate();
+
+            Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
+            if (grid != null)
+            {
+                Grid.SetRow(this.rectangle, 0);
+                Grid.SetColumn(this.rectangle, 0);
+                grid.Children.Add(this.rectangle);
+            }
+
+            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);
+            }
+        }
+
+        /// <inheritdoc/>
+        protected override void OnGotFocus(RoutedEventArgs e)
+        {
+            base.OnGotFocus(e);
+            this.textStore.SetFocus();
+            this.View.IsFocused = true;
+            this.Refresh();
+        }
+
+        /// <inheritdoc/>
+        protected override void OnLostFocus(RoutedEventArgs e)
+        {
+            base.OnLostFocus(e);
+            this.View.IsFocused = false;
+            this.Refresh();
+        }
+
+        /// <inheritdoc/>
+        protected override async void OnKeyDown(KeyRoutedEventArgs e)
+        {
+            bool isControlPressed = this.IsModiferKeyPressed(VirtualKey.Control);
+            bool isShiftPressed = this.IsModiferKeyPressed(VirtualKey.Shift);
+            bool isMovedCaret = false;
+            switch (e.Key)
+            {
+                case VirtualKey.Up:
+                    this._Controller.MoveCaretVertical(-1, isShiftPressed);
+                    this.Refresh();
+                    e.Handled = true;
+                    isMovedCaret = true;
+                    break;
+                case VirtualKey.Down:
+                    this._Controller.MoveCaretVertical(+1, isShiftPressed);
+                    this.Refresh();
+                    e.Handled = true;
+                    isMovedCaret = true;
+                    break;
+                case VirtualKey.Left:
+                    this._Controller.MoveCaretHorizontical(-1, isShiftPressed, isControlPressed);
+                    this.Refresh();
+                    e.Handled = true;
+                    isMovedCaret = true;
+                    break;
+                case VirtualKey.Right:
+                    this._Controller.MoveCaretHorizontical(1, isShiftPressed, isControlPressed);
+                    this.Refresh();
+                    e.Handled = true;
+                    isMovedCaret = true;
+                    break;
+                case VirtualKey.PageUp:
+                    this._Controller.Scroll(ScrollDirection.Up, this.View.LineCountOnScreen, isShiftPressed, true);
+                    this.Refresh();
+                    isMovedCaret = true;
+                    break;
+                case VirtualKey.PageDown:
+                    this._Controller.Scroll(ScrollDirection.Down, this.View.LineCountOnScreen, isShiftPressed, true);
+                    this.Refresh();
+                    isMovedCaret = true;
+                    break;
+                case VirtualKey.Home:
+                    if (isControlPressed)
+                        this._Controller.JumpToHead(isShiftPressed);
+                    else
+                        this.Controller.JumpToLineHead(this.Document.CaretPostion.row,isShiftPressed);
+                    this.Refresh();
+                    isMovedCaret = true;
+                    break;
+                case VirtualKey.End:
+                    if (isControlPressed)
+                        this._Controller.JumpToEnd(isShiftPressed);
+                    else
+                        this.Controller.JumpToLineEnd(this.Document.CaretPostion.row,isShiftPressed);
+                    this.Refresh();
+                    isMovedCaret = true;
+                    break;
+                case VirtualKey.Tab:
+                    if (!isControlPressed)
+                    {
+                        if (this._Controller.SelectionLength == 0)
+                            this._Controller.DoInputChar('\t');
+                        else if (isShiftPressed)
+                            this._Controller.DownIndent();
+                        else
+                            this._Controller.UpIndent();
+                        this.Refresh();
+                        e.Handled = true;
+                    }
+                    break;
+                case VirtualKey.Enter:
+                    this._Controller.DoEnterAction();
+                    this.Refresh();
+                    e.Handled = true;
+                    break;
+                case VirtualKey.Insert:
+                    if(this.View.InsertMode)
+                        this.View.InsertMode = false;
+                    else
+                        this.View.InsertMode = true;
+                    this.Refresh();
+                    e.Handled = true;
+                    break;
+                case VirtualKey.A:
+                    if (isControlPressed)
+                    {
+                        this.SelectAll();
+                        this.Refresh();
+                        e.Handled = true;
+                    }
+                    break;
+                case VirtualKey.B:
+                    if (isControlPressed)
+                    {
+                        if (this._Controller.RectSelection)
+                            this._Controller.RectSelection = false;
+                        else
+                            this._Controller.RectSelection = true;
+                        this.Refresh();
+                        e.Handled = true;
+                    }
+                    break;
+                case VirtualKey.C:
+                    if (isControlPressed)
+                    {
+                        this.CopyCommand();
+                        e.Handled = true;
+                    }
+                    break;
+                case VirtualKey.X:
+                    if (isControlPressed)
+                    {
+                        this.CutCommand();
+                        e.Handled = true;
+                    }
+                    break;
+                case VirtualKey.V:
+                    if (isControlPressed)
+                    {
+                        await this.PasteCommand();
+                        e.Handled = true;
+                    }
+                    break;
+                case VirtualKey.Y:
+                    if (isControlPressed)
+                    {
+                        this.Document.UndoManager.redo();
+                        this.Refresh();
+                        e.Handled = true;
+                    }
+                    break;
+                case VirtualKey.Z:
+                    if (isControlPressed)
+                    {
+                        this.Document.UndoManager.undo();
+                        this.Refresh();
+                        e.Handled = true;
+                    }
+                    break;
+                case VirtualKey.Back:
+                    this._Controller.DoBackSpaceAction();
+                    this.Refresh();
+                    e.Handled = true;
+                    break;
+                case VirtualKey.Delete:
+                    this._Controller.DoDeleteAction();
+                    this.Refresh();
+                    e.Handled = true;
+                    break;
+            }
+            if (isMovedCaret && this.peer != null)
+                this.peer.OnNotifyCaretChanged();
+            base.OnKeyDown(e);
+        }
+
+        /// <inheritdoc/>
+        protected override void OnPointerPressed(PointerRoutedEventArgs e)
+        {
+            this.CapturePointer(e.Pointer);
+            this.gestureRecongnizer.ProcessDownEvent(e.GetCurrentPoint(this));
+            e.Handled = true;
+        }
+
+        /// <inheritdoc/>
+        protected override void OnPointerMoved(PointerRoutedEventArgs e)
+        {
+            this.gestureRecongnizer.ProcessMoveEvents(e.GetIntermediatePoints(this));
+            e.Handled = true;
+
+            if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
+            {
+                Point p = e.GetCurrentPoint(this).Position;
+                if (this.View.HitTextArea(p.X, p.Y))
+                {
+                    TextPoint tp = this.View.GetTextPointFromPostion(p);
+                    if (this._Controller.IsMarker(tp, HilightType.Url))
+                        Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Hand, 101);
+                    else
+                        Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.IBeam, 101);
+                }
+                else
+                {
+                    Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 101);
+                }
+            }
+        }
+
+        /// <inheritdoc/>
+        protected override void OnPointerReleased(PointerRoutedEventArgs e)
+        {
+            this.gestureRecongnizer.ProcessUpEvent(e.GetCurrentPoint(this));
+            e.Handled = true;
+        }
+
+        /// <inheritdoc/>
+        protected override void OnPointerCanceled(PointerRoutedEventArgs e)
+        {
+            this.gestureRecongnizer.CompleteGesture();
+            e.Handled = true;
+        }
+
+        /// <inheritdoc/>
+        protected override void OnPointerWheelChanged(PointerRoutedEventArgs e)
+        {
+            bool shift = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Shift) ==
+                Windows.System.VirtualKeyModifiers.Shift;
+            bool ctrl = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Control) ==
+                Windows.System.VirtualKeyModifiers.Control;
+            this.gestureRecongnizer.ProcessMouseWheelEvent(e.GetCurrentPoint(this), shift, ctrl);
+            e.Handled = true;
+        }
+
+        void CoreWindow_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)
+        {
+            if (this.FocusState == FocusState.Unfocused || !this.IsEnabled)
+                return;
+            if (args.KeyCode >= 00 && args.KeyCode <= 0x1f)
+                return;
+            this._Controller.DoInputString(Char.ConvertFromUtf32((int)args.KeyCode));
+            this.Refresh();
+        }
+
+        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()
+        {
+            return TextStoreHelper.StartCompstion(this.Document);
+        }
+
+        string _textStore_GetString(int start, int length)
+        {
+            return this.Document.ToString(start, length);
+        }
+
+        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 = Util.GetScale();
+
+            //DIPを渡すと予測候補の位置がおかしくなるので、デバイス依存の座標に変換する
+            var screenStartPos = Util.GetScreentPoint(startPos, this).Scale(scale);
+            var screenEndPos = Util.GetScreentPoint(endPos, this).Scale(scale);
+            o_topLeft = new POINT((int)(screenStartPos.X), (int)(screenStartPos.Y));
+            o_bottomRight = new POINT((int)(screenEndPos.X), (int)(screenEndPos.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);
+
+            var gt = this.TransformToVisual(Window.Current.Content);
+            pointTopLeft = gt.TransformPoint(pointTopLeft);
+            pointBottomRight = gt.TransformPoint(pointBottomRight);
+
+            o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
+            o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
+        }
+
+        void _textStore_GetSelectionIndex(int start_index, int max_count, out DotNetTextStore.TextSelection[] sels)
+        {
+            TextRange selRange;
+            TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out selRange);
+
+            sels = new DotNetTextStore.TextSelection[1];
+            sels[0] = new DotNetTextStore.TextSelection();
+            sels[0].start = selRange.Index;
+            sels[0].end = selRange.Index + selRange.Length;
+        }
+
+        void _textStore_SetSelectionIndex(DotNetTextStore.TextSelection[] sels)
+        {
+            TextStoreHelper.SetSelectionIndex(this._Controller, this.View, sels[0].start, sels[0].end);
+            this.Refresh();
+        }
+
+        void _textStore_InsertAtSelection(string i_value,ref int o_stratIndex,ref int o_endIndex)
+        {
+            TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
+            this.Refresh();
+        }
+
+        void Controller_SelectionChanged(object sender, EventArgs e)
+        {
+            //こうしないと選択できなくなってしまう
+            this.nowCaretMove = true;
+            SetValue(SelectedTextProperty, this._Controller.SelectedText);
+            SetValue(CaretPostionPropertyKey, this.Document.CaretPostion);
+            this.nowCaretMove = false;
+            if (this.textStore.IsLocked() == false)
+                this.textStore.NotifySelectionChanged();
+        }
+
+        Gripper hittedGripper;
+        void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)
+        {
+            //Updateedの段階でヒットテストしてしまうとグリッパーを触ってもヒットしないことがある
+            this.hittedGripper = this.View.HitGripperFromPoint(e.Position);
+        }
+
+        private void GestureRecongnizer_ManipulationInertiaStarting(GestureRecognizer sender, ManipulationInertiaStartingEventArgs args)
+        {
+            //sender.InertiaTranslationDeceleration = 0.001f;
+            //sender.InertiaExpansionDeceleration = 100.0f * 96.0f / 1000.0f;
+            //sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
+        }
+
+        void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
+        {
+            if (this._Controller.MoveCaretAndGripper(e.Position, this.hittedGripper))
+            {
+                if (this.peer != null)
+                    this.peer.OnNotifyCaretChanged();
+                this.Refresh();                
+                return;
+            }
+
+            if (e.Delta.Scale < 1)
+            {
+                double newSize = this.Render.FontSize - 1;
+                if (newSize < 1)
+                    newSize = 1;
+                this.Render.FontSize = newSize;
+                this.Refresh();
+                SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
+                return;
+            }
+            
+            if (e.Delta.Scale > 1)
+            {
+                double newSize = this.Render.FontSize + 1;
+                if (newSize > 72)
+                    newSize = 72;
+                this.Render.FontSize = newSize;
+                this.Refresh();
+                SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
+                return;
+            }
+            
+            Point translation = e.Delta.Translation;
+
+            //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
+            if (Math.Abs(e.Cumulative.Translation.X) < Math.Abs(e.Cumulative.Translation.Y))
+            {
+                int deltay = (int)Math.Abs(Math.Ceiling(translation.Y));
+                if (translation.Y < 0)
+                    this._Controller.ScrollByPixel(ScrollDirection.Down, deltay, false, false);
+                else
+                    this._Controller.ScrollByPixel(ScrollDirection.Up, deltay, false, false);
+                this.Refresh();
+                return;
+            }
+
+            int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
+            if (deltax != 0)
+            {
+                if (translation.X < 0)
+                    this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
+                else
+                    this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
+                this.Refresh();
+            }
+        }
+
+        void gestureRecongnizer_ManipulationCompleted(GestureRecognizer sender, ManipulationCompletedEventArgs e)
+        {
+        }
+
+        async void gestureRecongnizer_RightTapped(GestureRecognizer sender, RightTappedEventArgs e)
+        {
+            ResourceMap map = ResourceManager.Current.MainResourceMap.GetSubtree("FooEditEngine.Metro/Resources");
+            ResourceContext context = ResourceContext.GetForCurrentView();
+            if (this.View.HitTextArea(e.Position.X, e.Position.Y))
+            {
+                FooContextMenuEventArgs args = new FooContextMenuEventArgs(e.Position);
+                if (this.ContextMenuOpening != null)
+                    this.ContextMenuOpening(this, args);
+                if (!args.Handled)
+                {
+                    PopupMenu ContextMenu = new PopupMenu();
+                    ContextMenu.Commands.Add(new UICommand(map.GetValue("CopyMenuName", context).ValueAsString, (command) =>
+                    {
+                        this.CopyCommand();
+                    }));
+                    ContextMenu.Commands.Add(new UICommand(map.GetValue("CutMenuName", context).ValueAsString, (command) =>
+                    {
+                        this.CutCommand();
+                    }));
+                    ContextMenu.Commands.Add(new UICommand(map.GetValue("PasteMenuName", context).ValueAsString, async (command) =>
+                    {
+                        await this.PasteCommand();
+                    }));
+                    if (this._Controller.RectSelection)
+                    {
+                        ContextMenu.Commands.Add(new UICommand(map.GetValue("LineSelectMenuName", context).ValueAsString, (command) =>
+                        {
+                            this._Controller.RectSelection = false;
+                        }));
+                    }
+                    else
+                    {
+                        ContextMenu.Commands.Add(new UICommand(map.GetValue("RectSelectMenuName", context).ValueAsString, (command) =>
+                        {
+                            this._Controller.RectSelection = true;
+                        }));
+                    }
+                    await ContextMenu.ShowAsync(Util.GetScreentPoint(e.Position,this));
+                }
+            }
+        }
+
+        void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)
+        {
+            bool touched = e.PointerDeviceType == PointerDeviceType.Touch;
+            this.Document.SelectGrippers.BottomLeft.Enabled = false;
+            this.Document.SelectGrippers.BottomRight.Enabled = touched;
+            this.JumpCaret(e.Position);
+            System.Diagnostics.Debug.WriteLine(e.TapCount);
+            if (e.TapCount == 2)
+            {
+                this.Document.SelectGrippers.BottomLeft.Enabled = touched;
+                //タッチスクリーンでダブルタップした場合、アンカーインデックスを単語の先頭にしないとバグる
+                this.Document.SelectWord(this.Controller.SelectionStart, touched);
+                this.Refresh();
+            }
+        }
+
+        void JumpCaret(Point p)
+        {
+            TextPoint tp = this.View.GetTextPointFromPostion(p);
+            if (tp == TextPoint.Null)
+                return;
+
+            int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
+
+            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(FocusState.Programmatic);
+            this.Refresh();
+        }
+
+        void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)
+        {
+            Point p = e.Position;
+            TextPointSearchRange searchRange;
+            if (this.View.HitTextArea(p.X, p.Y))
+                searchRange = TextPointSearchRange.TextAreaOnly;
+            else if (this._Controller.SelectionLength > 0)
+                searchRange = TextPointSearchRange.Full;
+            else
+                return;
+            TextPoint tp = this.View.GetTextPointFromPostion(p, searchRange);
+            this._Controller.MoveCaretAndSelect(tp);
+            if (this.peer != null)
+                this.peer.OnNotifyCaretChanged();
+            this.Refresh();
+        }
+
+        bool IsModiferKeyPressed(VirtualKey key)
+        {
+            CoreVirtualKeyStates state = Window.Current.CoreWindow.GetKeyState(key);
+            return (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
+        }
+        void Refresh(Rectangle updateRect)
+        {
+            if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0 || this.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
+                return;
+
+            this.Render.DrawContent(this.View, this.IsEnabled, updateRect);
+        }
+
+
+        bool Resize(double width, double height)
+        {
+            if (width == 0 || height == 0)
+                throw new ArgumentOutOfRangeException();
+            if (this.Render.Resize(this.rectangle, width, height))
+            {
+                this.View.PageBound = new Rectangle(0, 0, width, height);
+
+                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;
+        }
+
+        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 FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)
+        {
+            if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))
+            {
+                this.Refresh();
+                return;
+            }
+        }
+
+        void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
+        {
+            if (this.horizontalScrollBar == null)
+                return;
+            double toX;
+            if (this.FlowDirection == 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 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);
+            if(this.peer != null)
+                this.peer.OnNotifyTextChanged();
+        }
+
+        void FooTextBox_Loaded(object sender, RoutedEventArgs e)
+        {
+            this.Focus(FocusState.Programmatic);
+        }
+
+        void timer_Tick(object sender, object e)
+        {
+            if (this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding())
+                this.Refresh(this.View.PageBound);
+        }
+
+        /// <inheritdoc/>
+        public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
+        {
+            FooTextBox source = (FooTextBox)sender;
+            if(e.Property.Equals(SelectedTextProperty) && !source.nowCaretMove)
+                source._Controller.SelectedText = source.SelectedText;
+            if(e.Property.Equals(HilighterProperty))
+                source.View.Hilighter = source.Hilighter;
+            if (e.Property.Equals(TextAntialiasModeProperty))
+                source.Render.TextAntialiasMode = source.TextAntialiasMode;
+            if (e.Property.Equals(FoldingStrategyProperty))
+                source.View.LayoutLines.FoldingStrategy = source.FoldingStrategy;
+            if (e.Property.Equals(IndentModeProperty))
+                source.Controller.IndentMode = source.IndentMode;
+            if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)
+                source.Document.Select(source.Selection.Index,source.Selection.Length);
+            if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)
+                source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col);
+            if (e.Property.Equals(InsertModeProperty))
+                source.View.InsertMode = source.InsertMode;
+            if (e.Property.Equals(TabCharsProperty))
+                source.Document.TabStops = source.TabChars;
+            if (e.Property.Equals(RectSelectModeProperty))
+                source._Controller.RectSelection = source.RectSelectMode;
+            if (e.Property.Equals(DrawCaretProperty))
+                source.View.HideCaret = !source.DrawCaret;
+            if (e.Property.Equals(DrawCaretLineProperty))
+                source.View.HideLineMarker = !source.DrawCaretLine;
+            if (e.Property.Equals(DrawLineNumberProperty))
+                source.Document.DrawLineNumber = source.DrawLineNumber;
+            if(e.Property.Equals(MagnificationPowerPropertyKey))
+                source.Render.FontSize = source.FontSize * source.MagnificationPower;
+            if (e.Property.Equals(FontFamilyProperty))
+                source.Render.FontFamily = source.FontFamily;
+            if (e.Property.Equals(FontStyleProperty))
+                source.Render.FontStyle = source.FontStyle;
+            if (e.Property.Equals(FontWeightProperty))
+                source.Render.FontWeigth = source.FontWeight;
+            if (e.Property.Equals(FontSizeProperty))
+                source.Render.FontSize = source.FontSize;
+            if (e.Property.Equals(ForegroundProperty))
+                source.Render.Foreground = D2DRenderBase.ToColor4(source.Foreground);
+            if (e.Property.Equals(BackgroundProperty))
+                source.Render.Background = D2DRenderBase.ToColor4(source.Background);
+            if (e.Property.Equals(ControlCharProperty))
+                source.Render.ControlChar = D2DRenderBase.ToColor4(source.ControlChar);
+            if (e.Property.Equals(HilightProperty))
+                source.Render.Hilight = D2DRenderBase.ToColor4(source.Hilight);
+            if (e.Property.Equals(Keyword1Property))
+                source.Render.Keyword1 = D2DRenderBase.ToColor4(source.Keyword1);
+            if (e.Property.Equals(Keyword2Property))
+                source.Render.Keyword2 = D2DRenderBase.ToColor4(source.Keyword2);
+            if (e.Property.Equals(CommentProperty))
+                source.Render.Comment = D2DRenderBase.ToColor4(source.Comment);
+            if (e.Property.Equals(LiteralProperty))
+                source.Render.Literal = D2DRenderBase.ToColor4(source.Literal);
+            if (e.Property.Equals(URLProperty))
+                source.Render.Url = D2DRenderBase.ToColor4(source.URL);
+            if (e.Property.Equals(InsertCaretProperty))
+                source.Render.InsertCaret = D2DRenderBase.ToColor4(source.InsertCaret);
+            if (e.Property.Equals(OverwriteCaretProperty))
+                source.Render.OverwriteCaret = D2DRenderBase.ToColor4(source.OverwriteCaret);
+            if (e.Property.Equals(PaddingProperty))
+                source.View.Padding = new Padding((int)source.Padding.Left, (int)source.Padding.Top, (int)source.Padding.Right, (int)source.Padding.Bottom);
+            if (e.Property.Equals(LineMarkerProperty))
+                source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);
+            if (e.Property.Equals(MarkURLProperty))
+                source.Document.UrlMark = source.MarkURL;
+            if (e.Property.Equals(ShowFullSpaceProperty))
+                source.Render.ShowFullSpace = source.ShowFullSpace;
+            if (e.Property.Equals(ShowHalfSpaceProperty))
+                source.Render.ShowHalfSpace = source.ShowHalfSpace;
+            if (e.Property.Equals(ShowTabProperty))
+                source.Render.ShowTab = source.ShowTab;
+            if (e.Property.Equals(ShowLineBreakProperty))
+                source.Render.ShowLineBreak = source.ShowLineBreak;
+            if (e.Property.Equals(LineBreakProperty))
+                source.Document.LineBreak = source.LineBreakMethod;
+            if (e.Property.Equals(LineBreakCharCountProperty))
+                source.Document.LineBreakCharCount = source.LineBreakCharCount;
+            if (e.Property.Equals(UpdateAreaProperty))
+                source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);
+            if (e.Property.Equals(LineNumberProperty))
+                source.Render.LineNumber = D2DRenderBase.ToColor4(source.LineNumber);
+            if (e.Property.Equals(FlowDirectionProperty))
+            {
+                source.Document.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;
+                if(source.horizontalScrollBar != null)
+                    source.horizontalScrollBar.FlowDirection = source.FlowDirection;
+            }
+            if (e.Property.Equals(DrawRulerProperty))
+            {
+                source.Document.HideRuler = !source.DrawRuler;
+                source._Controller.JumpCaret(source.Document.CaretPostion.row, source.Document.CaretPostion.col);
+            }
+        }
+        #endregion
+
+        #region event
+        
+        /// <summary>
+        /// コンテキストメニューが表示されるときに呼び出されます
+        /// </summary>
+        public event EventHandler<FooContextMenuEventArgs> ContextMenuOpening;
+
+        #endregion
+
+        #region property
+
+        internal Controller Controller
+        {
+            get
+            {
+                return this._Controller;
+            }
+        }
+
+        /// <summary>
+        /// 文字列の描写に使用されるアンチエイリアシング モードを表します
+        /// </summary>
+        public TextAntialiasMode TextAntialiasMode
+        {
+            get { return (TextAntialiasMode)GetValue(TextAntialiasModeProperty); }
+            set { SetValue(TextAntialiasModeProperty, value); }
+        }
+
+        /// <summary>
+        /// TextAntialiasModeの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty TextAntialiasModeProperty =
+            DependencyProperty.Register("TextAntialiasMode", typeof(TextAntialiasMode), typeof(FooTextBox), new PropertyMetadata(TextAntialiasMode.Default, OnPropertyChanged));
+
+        /// <summary>
+        /// シンタックスハイライターを表す
+        /// </summary>
+        public IHilighter Hilighter
+        {
+            get { return (IHilighter)GetValue(HilighterProperty); }
+            set { SetValue(HilighterProperty, value); }
+        }
+
+        /// <summary>
+        /// Hilighterの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty HilighterProperty =
+            DependencyProperty.Register("Hilighter", typeof(IHilighter), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
+
+        /// <summary>
+        /// フォールティングを作成するインターフェイスを表す
+        /// </summary>
+        public IFoldingStrategy FoldingStrategy
+        {
+            get { return (IFoldingStrategy)GetValue(FoldingStrategyProperty); }
+            set { SetValue(FoldingStrategyProperty, value); }
+        }
+
+        /// <summary>
+        /// FoldingStrategyの依存プロパティ
+        /// </summary>
+        public static readonly DependencyProperty FoldingStrategyProperty =
+            DependencyProperty.Register("FoldingStrategy", typeof(IFoldingStrategy), typeof(FooTextBox), new PropertyMetadata(null,OnPropertyChanged));
+
+        /// <summary>
+        /// マーカーパターンセットを表す
+        /// </summary>
+        public MarkerPatternSet MarkerPatternSet
+        {
+            get
+            {
+                return this.Document.MarkerPatternSet;
+            }
+        }
+
+        /// <summary>
+        /// ドキュメントを表す
+        /// </summary>
+        public Document Document
+        {
+            get
+            {
+                return this._Document;
+            }
+            set
+            {
+                Document old_doc = this._Document;
+                int oldLength = 0;
+                if (this._Document != null)
+                {
+                    old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
+                    old_doc.LoadProgress -= _Document_LoadProgress;
+                    oldLength = old_doc.Length;
+                }
+
+                this._Document = value;
+                this._Document.LayoutLines.Render = this.Render;
+                this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
+                this._Document.LoadProgress += _Document_LoadProgress;
+                //初期化が終わっていればすべて存在する
+                if (this.Controller != null && this.View != null && this.textStore != null)
+                {
+                    this.Controller.Document = value;
+                    this.View.Document = value;
+                    this.Controller.AdjustCaret();
+                    this.textStore.NotifyTextChanged(oldLength, value.Length);
+
+                    //依存プロパティとドキュメント内容が食い違っているので再設定する
+                    this.ShowFullSpace = value.ShowFullSpace;
+                    this.ShowHalfSpace = value.ShowHalfSpace;
+                    this.ShowLineBreak = value.ShowLineBreak;
+                    this.ShowTab = value.ShowTab;
+                    this.FlowDirection = value.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
+                    this.IndentMode = value.IndentMode;
+                    this.DrawCaretLine = !value.HideLineMarker;
+                    this.InsertMode = value.InsertMode;
+                    this.DrawRuler = !value.HideRuler;
+                    this.DrawLineNumber = value.DrawLineNumber;
+                    this.MarkURL = value.UrlMark;
+                    this.LineBreakMethod = value.LineBreak;
+                    this.LineBreakCharCount = value.LineBreakCharCount;
+                    this.TabChars = value.TabStops;
+
+                    this.Refresh();
+                }
+            }
+        }
+
+        private void _Document_LoadProgress(object sender, ProgressEventArgs e)
+        {
+            if(e.state == ProgressState.Start)
+                this.IsEnabled = false;
+            else if(e.state == ProgressState.Complete)
+            {
+                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>
+        public LineToIndexTable LayoutLineCollection
+        {
+            get { return this.View.LayoutLines; }
+        }
+
+        /// <summary>
+        /// 選択中の文字列を表す
+        /// </summary>
+        public string SelectedText
+        {
+            get { return (string)GetValue(SelectedTextProperty); }
+            set { SetValue(SelectedTextProperty, value); }
+        }
+
+        /// <summary>
+        /// SelectedTextの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty SelectedTextProperty =
+            DependencyProperty.Register("SelectedText", typeof(string), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
+
+        /// <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,OnPropertyChanged));
+
+        /// <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, OnPropertyChanged));
+
+        /// <summary>
+        /// 拡大率を表す
+        /// </summary>
+        public double MagnificationPower
+        {
+            get { return (double)GetValue(MagnificationPowerPropertyKey); }
+            set { SetValue(MagnificationPowerPropertyKey, value); }
+        }
+
+        /// <summary>
+        /// 拡大率を表す依存プロパティ
+        /// </summary>
+        public static readonly DependencyProperty MagnificationPowerPropertyKey =
+            DependencyProperty.Register("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0, OnPropertyChanged));
+
+        /// <summary>
+        /// キャレット位置を表す
+        /// </summary>
+        public TextPoint CaretPostion
+        {
+            get { return (TextPoint)GetValue(CaretPostionPropertyKey); }
+            set { SetValue(CaretPostionPropertyKey, value); }
+        }
+
+        static readonly DependencyProperty CaretPostionPropertyKey =
+            DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(new TextPoint(), OnPropertyChanged));
+
+        /// <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,OnPropertyChanged));
+
+        /// <summary>
+        /// フォントファミリーを表す
+        /// </summary>
+        public new FontFamily FontFamily
+        {
+            get { return (FontFamily)GetValue(FontFamilyProperty); }
+            set { SetValue(FontFamilyProperty, value); }
+        }
+
+        /// <summary>
+        /// FontFamilyの依存プロパティを表す
+        /// </summary>
+        public new static readonly DependencyProperty FontFamilyProperty =
+            DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(FooTextBox), new PropertyMetadata(new FontFamily("Cambria"), OnPropertyChanged));
+
+        /// <summary>
+        /// フォントサイズを表す
+        /// </summary>
+        public new double FontSize
+        {
+            get { return (double)GetValue(FontSizeProperty); }
+            set { SetValue(FontSizeProperty, value); }
+        }
+
+        /// <summary>
+        /// FontSizeの依存プロパティを表す
+        /// </summary>
+        public new static readonly DependencyProperty FontSizeProperty =
+            DependencyProperty.Register("FontSize", typeof(double), typeof(FooTextBox), new PropertyMetadata(12.0,OnPropertyChanged));
+
+        /// <summary>
+        /// フォントスタイルを表す
+        /// </summary>
+        public new FontStyle FontStyle
+        {
+            get { return (FontStyle)GetValue(FontStyleProperty); }
+            set { SetValue(FontStyleProperty, value); }
+        }
+
+        /// <summary>
+        /// FontStyleの依存プロパティを表す
+        /// </summary>
+        public new static readonly DependencyProperty FontStyleProperty =
+            DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(FooTextBox), new PropertyMetadata(FontStyle.Normal,OnPropertyChanged));
+
+        /// <summary>
+        /// フォントの幅を表す
+        /// </summary>
+        public new FontWeight FontWeight
+        {
+            get { return (FontWeight)GetValue(FontWeightProperty); }
+            set { SetValue(FontWeightProperty, value); }
+        }
+
+        /// <summary>
+        /// FontWeigthの依存プロパティを表す
+        /// </summary>
+        public new static readonly DependencyProperty FontWeightProperty =
+            DependencyProperty.Register("FontWeigth", typeof(FontWeight), typeof(FooTextBox), new PropertyMetadata(FontWeights.Normal,OnPropertyChanged));
+
+        /// <summary>
+        /// デフォルトの文字色を表す。これは依存プロパティです
+        /// </summary>
+        public new Windows.UI.Color Foreground
+        {
+            get { return (Windows.UI.Color)GetValue(ForegroundProperty); }
+            set { SetValue(ForegroundProperty, value); }
+        }
+
+        /// <summary>
+        /// Foregroundの依存プロパティを表す
+        /// </summary>
+        public new static readonly DependencyProperty ForegroundProperty =
+            DependencyProperty.Register("Foreground", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
+
+        /// <summary>
+        /// 背景色を表す。これは依存プロパティです
+        /// </summary>
+        public new Windows.UI.Color Background
+        {
+            get { return (Windows.UI.Color)GetValue(BackgroundProperty); }
+            set { SetValue(BackgroundProperty, value); }
+        }
+
+        /// <summary>
+        /// Backgroundの依存プロパティを表す
+        /// </summary>
+        public new static readonly DependencyProperty BackgroundProperty =
+            DependencyProperty.Register("Background", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));
+
+        /// <summary>
+        /// コントロールコードの文字色を表す。これは依存プロパティです
+        /// </summary>
+        public Windows.UI.Color ControlChar
+        {
+            get { return (Windows.UI.Color)GetValue(ControlCharProperty); }
+            set { SetValue(ControlCharProperty, value); }
+        }
+
+        /// <summary>
+        /// ControlCharの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty ControlCharProperty =
+            DependencyProperty.Register("ControlChar", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
+
+        /// <summary>
+        /// 選択時の背景色を表す。これは依存プロパティです
+        /// </summary>
+        public Windows.UI.Color Hilight
+        {
+            get { return (Windows.UI.Color)GetValue(HilightProperty); }
+            set { SetValue(HilightProperty, value); }
+        }
+
+        /// <summary>
+        /// Hilightの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty HilightProperty =
+            DependencyProperty.Register("Hilight", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DeepSkyBlue, OnPropertyChanged));
+
+        /// <summary>
+        /// キーワード1の文字色を表す。これは依存プロパティです
+        /// </summary>
+        public Windows.UI.Color Keyword1
+        {
+            get { return (Windows.UI.Color)GetValue(Keyword1Property); }
+            set { SetValue(Keyword1Property, value); }
+        }
+
+        /// <summary>
+        /// Keyword1の依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty Keyword1Property =
+            DependencyProperty.Register("Keyword1", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
+
+        /// <summary>
+        /// キーワード2の文字色を表す。これは依存プロパティです
+        /// </summary>
+        public Windows.UI.Color Keyword2
+        {
+            get { return (Windows.UI.Color)GetValue(Keyword2Property); }
+            set { SetValue(Keyword2Property, value); }
+        }
+
+        /// <summary>
+        /// Keyword2の依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty Keyword2Property =
+            DependencyProperty.Register("Keyword2", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DarkCyan, OnPropertyChanged));
+
+        /// <summary>
+        /// コメントの文字色を表す。これは依存プロパティです
+        /// </summary>
+        public Windows.UI.Color Comment
+        {
+            get { return (Windows.UI.Color)GetValue(CommentProperty); }
+            set { SetValue(CommentProperty, value); }
+        }
+
+        /// <summary>
+        /// Commentの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty CommentProperty =
+            DependencyProperty.Register("Comment", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Green, OnPropertyChanged));
+
+        /// <summary>
+        /// 文字リテラルの文字色を表す。これは依存プロパティです
+        /// </summary>
+        public Windows.UI.Color Literal
+        {
+            get { return (Windows.UI.Color)GetValue(LiteralProperty); }
+            set { SetValue(LiteralProperty, value); }
+        }
+
+        /// <summary>
+        /// Literalの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty LiteralProperty =
+            DependencyProperty.Register("Literal", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Brown, OnPropertyChanged));
+
+        /// <summary>
+        /// URLの文字色を表す。これは依存プロパティです
+        /// </summary>
+        public Windows.UI.Color URL
+        {
+            get { return (Windows.UI.Color)GetValue(URLProperty); }
+            set { SetValue(URLProperty, value); }
+        }
+
+        /// <summary>
+        /// URLの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty URLProperty =
+            DependencyProperty.Register("URL", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
+
+        /// <summary>
+        /// 行更新フラグの色を表す
+        /// </summary>
+        public Windows.UI.Color UpdateArea
+        {
+            get { return (Windows.UI.Color)GetValue(UpdateAreaProperty); }
+            set { SetValue(UpdateAreaProperty, value); }
+        }
+
+        /// <summary>
+        /// UpdateAreaの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty UpdateAreaProperty =
+            DependencyProperty.Register("UpdateArea", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen, OnPropertyChanged));
+
+        /// <summary>
+        /// ラインマーカーの色を表す
+        /// </summary>
+        public Windows.UI.Color LineMarker
+        {
+            get { return (Windows.UI.Color)GetValue(LineMarkerProperty); }
+            set { SetValue(LineMarkerProperty, value); }
+        }
+
+        /// <summary>
+        /// LineMarkerの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty LineMarkerProperty =
+            DependencyProperty.Register("LineMarker", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
+
+        /// <summary>
+        /// 挿入モード時のキャレットの色を表す
+        /// </summary>
+        public Windows.UI.Color InsertCaret
+        {
+            get { return (Windows.UI.Color)GetValue(InsertCaretProperty); }
+            set { SetValue(InsertCaretProperty, value); }
+        }
+
+        /// <summary>
+        /// InsertCaretの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty InsertCaretProperty =
+            DependencyProperty.Register("InsertCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
+
+        /// <summary>
+        /// 上書きモード時のキャレット職を表す
+        /// </summary>
+        public Windows.UI.Color OverwriteCaret
+        {
+            get { return (Windows.UI.Color)GetValue(OverwriteCaretProperty); }
+            set { SetValue(OverwriteCaretProperty, value); }
+        }
+
+        /// <summary>
+        /// OverwriteCaretの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty OverwriteCaretProperty =
+            DependencyProperty.Register("OverwriteCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
+
+        /// <summary>
+        /// 行番号の色を表す
+        /// </summary>
+        public Windows.UI.Color LineNumber
+        {
+            get { return (Windows.UI.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(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray,OnPropertyChanged));
+
+        /// <summary>
+        /// 余白を表す
+        /// </summary>
+        public new Thickness Padding
+        {
+            get { return (Thickness)GetValue(PaddingProperty); }
+            set { SetValue(PaddingProperty, value); }
+        }
+
+        /// <summary>
+        /// Paddingの依存プロパティを表す
+        /// </summary>
+        public new static readonly DependencyProperty PaddingProperty =
+            DependencyProperty.Register("Padding", typeof(Thickness), typeof(FooTextBox), new PropertyMetadata(new Thickness(),OnPropertyChanged));        
+
+        /// <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 PropertyMetadata(true, OnPropertyChanged));
+
+        /// <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 PropertyMetadata(4, OnPropertyChanged));
+
+        /// <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 PropertyMetadata(false, OnPropertyChanged));
+
+        /// <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, OnPropertyChanged));
+
+
+        /// <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, OnPropertyChanged));        
+
+        /// <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 PropertyMetadata(true, OnPropertyChanged));
+
+
+        /// <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 PropertyMetadata(false, OnPropertyChanged));
+
+        /// <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, OnPropertyChanged));
+
+
+        /// <summary>
+        /// DrawLineNumberの依存プロパティを表す
+        /// </summary>
+        public static readonly DependencyProperty DrawLineNumberProperty =
+            DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
+
+        /// <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 PropertyMetadata(false, OnPropertyChanged));
+
+        /// <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 PropertyMetadata(false, OnPropertyChanged));
+
+        /// <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 PropertyMetadata(false, OnPropertyChanged));
+
+        /// <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 PropertyMetadata(false, OnPropertyChanged));
+
+        /// <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,OnPropertyChanged));
+
+        
+        #endregion
+
+    }
+    /// <summary>
+    /// コンテキストメニューのイベントデーターを表す
+    /// </summary>
+    public class FooContextMenuEventArgs
+    {
+        /// <summary>
+        /// 処理済みなら真。そうでないなら偽
+        /// </summary>
+        public bool Handled = false;
+        /// <summary>
+        /// コンテキストメニューを表示すべき座標を表す
+        /// </summary>
+        public Windows.Foundation.Point Postion;
+        /// <summary>
+        /// コンストラクター
+        /// </summary>
+        /// <param name="pos"></param>
+        public FooContextMenuEventArgs(Windows.Foundation.Point pos)
+        {
+            this.Postion = pos;
+        }
+    }
+}