OSDN Git Service

メトロ版でもカーソルを点滅できるようにしてみた&コードの整理
[fooeditengine/FooEditEngine.git] / Metro / FooEditEngine / FooTextBox.cs
1 /*
2  * Copyright (C) 2013 FooProject
3  * * 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
4  * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
5
6  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
7  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
10  */
11 using System;
12 using System.Text;
13 using System.ComponentModel;
14 using System.Threading.Tasks;
15 using Windows.ApplicationModel.Resources.Core;
16 using Windows.Devices.Input;
17 using Windows.System;
18 using Windows.ApplicationModel.DataTransfer;
19 using Windows.Foundation;
20 using Windows.UI;
21 using Windows.UI.Input;
22 using Windows.UI.Core;
23 using Windows.UI.Popups;
24 using Windows.UI.Text;
25 using Windows.UI.Xaml.Media;
26 using Windows.UI.Xaml;
27 using Windows.UI.Xaml.Controls;
28 using Windows.UI.Xaml.Controls.Primitives;
29 using Windows.UI.Xaml.Input;
30 using DotNetTextStore;
31 using DotNetTextStore.UnmanagedAPI.TSF;
32 using DotNetTextStore.UnmanagedAPI.WinDef;
33
34 // テンプレート コントロールのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234235 を参照してください
35
36 namespace FooEditEngine.Metro
37 {
38     /// <summary>
39     /// テキストボックスコントロール
40     /// </summary>
41     public sealed class FooTextBox : Control,IDisposable
42     {
43         EditView View;
44         Controller _Controller;
45         D2DRender Render;
46         ScrollBar horizontalScrollBar, verticalScrollBar;
47         Windows.UI.Xaml.Shapes.Rectangle rectangle;
48         GestureRecognizer gestureRecongnizer = new GestureRecognizer();
49         TextStore2 textStore;
50         FooTextBoxAutomationPeer peer;
51         bool nowCaretMove = false;
52         DispatcherTimer timer;
53
54         /// <summary>
55         /// コンストラクター
56         /// </summary>
57         public FooTextBox()
58         {
59             this.DefaultStyleKey = typeof(FooTextBox);
60
61             this.textStore = new TextStore2();
62             this.textStore.IsLoading += textStore_IsLoading;
63             this.textStore.IsReadOnly += textStore_IsReadOnly;
64             this.textStore.GetStringLength += () => this.Document.Length;
65             this.textStore.GetString += _textStore_GetString;
66             this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;
67             this.textStore.SetSelectionIndex += _textStore_SetSelectionIndex;
68             this.textStore.InsertAtSelection += _textStore_InsertAtSelection;
69             this.textStore.GetScreenExtent += _textStore_GetScreenExtent;
70             this.textStore.GetStringExtent += _textStore_GetStringExtent;
71             this.textStore.CompositionStarted += textStore_CompositionStarted;
72             this.textStore.CompositionUpdated += textStore_CompositionUpdated;
73             this.textStore.CompositionEnded += textStore_CompositionEnded;
74
75             this.rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
76             this.rectangle.Margin = this.Padding;
77             this.Render = new D2DRender(this,this.rectangle,this.textStore);
78
79             this.Document = new Document();
80             this.Document.LayoutLines.Render = this.Render;
81
82             this.View = new EditView(this.Document, this.Render, new Padding(5, Gripper.HitAreaWidth, Gripper.HitAreaWidth / 2, Gripper.HitAreaWidth));
83             this.View.SrcChanged += View_SrcChanged;
84             this.View.InsertMode = this.InsertMode;
85             this.Document.DrawLineNumber = this.DrawLineNumber;
86             this.View.HideCaret = !this.DrawCaret;
87             this.View.HideLineMarker = !this.DrawCaretLine;
88             this.Document.HideRuler = !this.DrawRuler;
89             this.Document.UrlMark = this.MarkURL;
90             this.Document.TabStops = this.TabChars;
91
92             this._Controller = new Controller(this.Document, this.View);
93             this._Controller.SelectionChanged += Controller_SelectionChanged;
94
95             this.gestureRecongnizer.GestureSettings = GestureSettings.Drag | 
96                 GestureSettings.RightTap | 
97                 GestureSettings.Tap | 
98                 GestureSettings.DoubleTap |
99                 GestureSettings.ManipulationTranslateX | 
100                 GestureSettings.ManipulationTranslateY |
101                 GestureSettings.ManipulationScale |
102                 GestureSettings.ManipulationTranslateInertia |
103                 GestureSettings.ManipulationScaleInertia;
104             this.gestureRecongnizer.RightTapped += gestureRecongnizer_RightTapped;
105             this.gestureRecongnizer.Tapped += gestureRecongnizer_Tapped;
106             this.gestureRecongnizer.Dragging += gestureRecongnizer_Dragging;
107             this.gestureRecongnizer.ManipulationInertiaStarting += gestureRecongnizer_ManipulationInertiaStarting;
108             this.gestureRecongnizer.ManipulationStarted += gestureRecongnizer_ManipulationStarted;
109             this.gestureRecongnizer.ManipulationUpdated += gestureRecongnizer_ManipulationUpdated;
110             this.gestureRecongnizer.ManipulationCompleted += gestureRecongnizer_ManipulationCompleted;
111
112             this.timer = new DispatcherTimer();
113             this.timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
114             this.timer.Tick += new EventHandler<object>(this.timer_Tick);
115
116             //Viewの初期化が終わった直後に置かないと例外が発生する
117             this.Document.Update += Document_Update;
118
119             Window.Current.CoreWindow.CharacterReceived += CoreWindow_CharacterReceived;
120
121             this.SizeChanged += FooTextBox_SizeChanged;
122
123             this.Loaded += FooTextBox_Loaded;
124
125             this.View.CaretBlink = true;
126             this.View.CaretBlinkTime = 1000;    //TODO:ユーザーの設定を反映させる
127             this.View.CaretWidthOnInsertMode = 1;    //TODO:ユーザーの設定を反映させる
128         }
129
130         /// <summary>
131         /// ファイナライザー
132         /// </summary>
133         ~FooTextBox()
134         {
135             this.Dispose(false);
136         }
137
138         /// <summary>
139         /// アンマネージドリソースを解放する
140         /// </summary>
141         public void Dispose()
142         {
143             this.Dispose(true);
144             GC.SuppressFinalize(this);
145         }
146
147         bool Disposed = false;
148         private void Dispose(bool disposing)
149         {
150             if (this.Disposed)
151                 return;
152             if (disposing)
153             {
154                 this.textStore.Dispose();
155                 this.View.Dispose();
156                 this.Render.Dispose();
157             }
158         }
159
160         /// <summary>
161         /// ドキュメントを選択する
162         /// </summary>
163         /// <param name="start">開始インデックス</param>
164         /// <param name="length">長さ</param>
165         public void Select(int start, int length)
166         {
167             this._Controller.Select(start, length);
168         }
169
170         /// <summary>
171         /// キャレットを指定した行に移動させます
172         /// </summary>
173         /// <param name="index">インデックス</param>
174         /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
175         public void JumpCaret(int index)
176         {
177             this._Controller.JumpCaret(index);
178         }
179         /// <summary>
180         /// キャレットを指定した行と桁に移動させます
181         /// </summary>
182         /// <param name="row">行番号</param>
183         /// <param name="col">桁</param>
184         /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
185         public void JumpCaret(int row, int col)
186         {
187             this._Controller.JumpCaret(row, col);
188         }
189
190         /// <summary>
191         /// 選択中のテキストをクリップボードにコピーします
192         /// </summary>
193         public void Copy()
194         {
195             string text = this._Controller.SelectedText;
196             if (text != null && text != string.Empty)
197             {
198                 DataPackage dataPackage = new DataPackage();
199                 dataPackage.RequestedOperation = DataPackageOperation.Copy;
200                 dataPackage.SetText(text);
201
202                 Clipboard.SetContent(dataPackage); 
203             }
204         }
205
206         /// <summary>
207         /// 選択中のテキストをクリップボードに切り取ります
208         /// </summary>
209         public void Cut()
210         {
211             string text = this._Controller.SelectedText;
212             if (text != null && text != string.Empty)
213             {
214                 DataPackage dataPackage = new DataPackage();
215                 dataPackage.RequestedOperation = DataPackageOperation.Copy;
216                 dataPackage.SetText(text);
217
218                 Clipboard.SetContent(dataPackage);
219                 
220                 this._Controller.SelectedText = "";
221             }
222         }
223
224         /// <summary>
225         /// 選択中のテキストを貼り付けます
226         /// </summary>
227         public async Task PasteAsync()
228         {
229             var dataPackageView = Clipboard.GetContent();
230             if (dataPackageView.Contains(StandardDataFormats.Text))
231             {
232                 this._Controller.SelectedText = await dataPackageView.GetTextAsync();
233             }
234         }
235
236         /// <summary>
237         /// すべて選択する
238         /// </summary>
239         public void SelectAll()
240         {
241             this._Controller.Select(0, this.Document.Length);
242         }
243
244         /// <summary>
245         /// 選択を解除する
246         /// </summary>
247         public void DeSelectAll()
248         {
249             this._Controller.DeSelectAll();
250         }
251
252         /// <summary>
253         /// 対応する座標を返します
254         /// </summary>
255         /// <param name="tp">テキストポイント</param>
256         /// <returns>座標</returns>
257         /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
258         public Windows.Foundation.Point GetPostionFromTextPoint(TextPoint tp)
259         {
260             if (this.Document.FireUpdateEvent == false)
261                 throw new InvalidOperationException("");
262             return this.View.GetPostionFromTextPoint(tp);
263         }
264
265         /// <summary>
266         /// 対応するテキストポイントを返します
267         /// </summary>
268         /// <param name="p">クライアント領域の原点を左上とする座標</param>
269         /// <returns>テキストポイント</returns>
270         public TextPoint GetTextPointFromPostion(Windows.Foundation.Point p)
271         {
272             if (this.Document.FireUpdateEvent == false)
273                 throw new InvalidOperationException("");
274             return this.View.GetTextPointFromPostion(p);
275         }
276
277         /// <summary>
278         /// 行の高さを取得します
279         /// </summary>
280         /// <param name="row">レイアウト行</param>
281         /// <returns>行の高さ</returns>
282         public double GetLineHeight(int row)
283         {
284             if (this.Document.FireUpdateEvent == false)
285                 throw new InvalidOperationException("");
286             return this.View.LayoutLines.GetLayout(row).Height; ;
287         }
288
289         /// <summary>
290         /// インデックスに対応する座標を得ます
291         /// </summary>
292         /// <param name="index">インデックス</param>
293         /// <returns>座標を返す</returns>
294         public Windows.Foundation.Point GetPostionFromIndex(int index)
295         {
296             if (this.Document.FireUpdateEvent == false)
297                 throw new InvalidOperationException("");
298             TextPoint tp = this.View.GetLayoutLineFromIndex(index);
299             return this.View.GetPostionFromTextPoint(tp);
300         }
301
302         /// <summary>
303         /// 座標からインデックスに変換します
304         /// </summary>
305         /// <param name="p">座標</param>
306         /// <returns>インデックスを返す</returns>
307         public int GetIndexFromPostion(Windows.Foundation.Point p)
308         {
309             if (this.Document.FireUpdateEvent == false)
310                 throw new InvalidOperationException("");
311             TextPoint tp = this.View.GetTextPointFromPostion(p);
312             return this.View.GetIndexFromLayoutLine(tp);
313         }
314
315         /// <summary>
316         /// 再描写する
317         /// </summary>
318         public void Refresh()
319         {
320             this.Refresh(this.View.PageBound);
321         }
322
323         /// <summary>
324         /// レイアウト行をすべて破棄し、再度レイアウトを行う
325         /// </summary>
326         public void PerfomLayouts()
327         {
328             this.View.PerfomLayouts();
329         }
330
331         /// <summary>
332         /// 指定行までスクロールする
333         /// </summary>
334         /// <param name="row">行</param>
335         /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
336         public void ScrollIntoView(int row, bool alignTop)
337         {
338             this.View.ScrollIntoView(row, alignTop);
339         }
340
341         /// <summary>
342         /// ファイルからドキュメントを構築する
343         /// </summary>
344         /// <param name="sr">StremReader</param>
345         /// <returns>Taskオブジェクト</returns>
346         public async Task LoadFileAsync(System.IO.StreamReader sr, System.Threading.CancellationTokenSource token)
347         {
348             this.IsEnabled = false;
349             this.View.LayoutLines.IsFrozneDirtyFlag = true;
350             WinFileReader fs = new WinFileReader(sr);
351             await this.Document.LoadAsync(fs, token);
352             this.View.LayoutLines.IsFrozneDirtyFlag = false;
353             TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
354             if (this.verticalScrollBar != null)
355                 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
356             this.View.CalculateLineCountOnScreen();
357             this.IsEnabled = true;
358         }
359
360         /// <summary>
361         /// ドキュメントの内容をファイルに保存する
362         /// </summary>
363         /// <param name="sw">StreamWriter</param>
364         /// <param name="enc">エンコード</param>
365         /// <returns>Taskオブジェクト</returns>
366         public async Task SaveFile(System.IO.StreamWriter sw, System.Threading.CancellationTokenSource token)
367         {
368             WinFileWriter fs = new WinFileWriter(sw);
369             await this.Document.SaveAsync(fs, token);
370         }
371
372         #region command
373         void CopyCommand()
374         {
375             this.Copy();
376         }
377
378         void CutCommand()
379         {
380             this.Cut();
381             this.Refresh();
382         }
383
384         async Task PasteCommand()
385         {
386             await this.PasteAsync();
387             this.Refresh();
388         }
389
390         #endregion
391
392         #region event
393         /// <inheritdoc/>
394         protected override Windows.UI.Xaml.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
395         {
396             this.peer = new FooTextBoxAutomationPeer(this);
397             return this.peer;
398         }
399
400         /// <inheritdoc/>
401         protected override void OnApplyTemplate()
402         {
403             base.OnApplyTemplate();
404
405             Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
406             if (grid != null)
407             {
408                 Grid.SetRow(this.rectangle, 0);
409                 Grid.SetColumn(this.rectangle, 0);
410                 grid.Children.Add(this.rectangle);
411             }
412
413             this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
414             if (this.horizontalScrollBar != null)
415             {
416                 this.horizontalScrollBar.SmallChange = 10;
417                 this.horizontalScrollBar.LargeChange = 100;
418                 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
419                 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
420             }
421             this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
422             if (this.verticalScrollBar != null)
423             {
424                 this.verticalScrollBar.SmallChange = 1;
425                 this.verticalScrollBar.LargeChange = 10;
426                 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
427                 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
428             }
429         }
430
431         /// <inheritdoc/>
432         protected override void OnGotFocus(RoutedEventArgs e)
433         {
434             base.OnGotFocus(e);
435             this.textStore.SetFocus();
436             this.View.IsFocused = true;
437             this.Refresh();
438         }
439
440         /// <inheritdoc/>
441         protected override void OnLostFocus(RoutedEventArgs e)
442         {
443             base.OnLostFocus(e);
444             this.View.IsFocused = false;
445             this.Refresh();
446         }
447
448         /// <inheritdoc/>
449         protected override async void OnKeyDown(KeyRoutedEventArgs e)
450         {
451             bool isControlPressed = this.IsModiferKeyPressed(VirtualKey.Control);
452             bool isShiftPressed = this.IsModiferKeyPressed(VirtualKey.Shift);
453             bool isMovedCaret = false;
454             switch (e.Key)
455             {
456                 case VirtualKey.Up:
457                     this._Controller.MoveCaretVertical(-1, isShiftPressed);
458                     this.Refresh();
459                     e.Handled = true;
460                     isMovedCaret = true;
461                     break;
462                 case VirtualKey.Down:
463                     this._Controller.MoveCaretVertical(+1, isShiftPressed);
464                     this.Refresh();
465                     e.Handled = true;
466                     isMovedCaret = true;
467                     break;
468                 case VirtualKey.Left:
469                     this._Controller.MoveCaretHorizontical(-1, isShiftPressed, isControlPressed);
470                     this.Refresh();
471                     e.Handled = true;
472                     isMovedCaret = true;
473                     break;
474                 case VirtualKey.Right:
475                     this._Controller.MoveCaretHorizontical(1, isShiftPressed, isControlPressed);
476                     this.Refresh();
477                     e.Handled = true;
478                     isMovedCaret = true;
479                     break;
480                 case VirtualKey.PageUp:
481                     this._Controller.Scroll(ScrollDirection.Up, this.View.LineCountOnScreen, isShiftPressed, true);
482                     this.Refresh();
483                     isMovedCaret = true;
484                     break;
485                 case VirtualKey.PageDown:
486                     this._Controller.Scroll(ScrollDirection.Down, this.View.LineCountOnScreen, isShiftPressed, true);
487                     this.Refresh();
488                     isMovedCaret = true;
489                     break;
490                 case VirtualKey.Home:
491                     if (isControlPressed)
492                         this._Controller.JumpToHead(isShiftPressed);
493                     else
494                         this.Controller.JumpToLineHead(this.Document.CaretPostion.row,isShiftPressed);
495                     this.Refresh();
496                     isMovedCaret = true;
497                     break;
498                 case VirtualKey.End:
499                     if (isControlPressed)
500                         this._Controller.JumpToEnd(isShiftPressed);
501                     else
502                         this.Controller.JumpToLineEnd(this.Document.CaretPostion.row,isShiftPressed);
503                     this.Refresh();
504                     isMovedCaret = true;
505                     break;
506                 case VirtualKey.Tab:
507                     if (!isControlPressed)
508                     {
509                         if (this._Controller.SelectionLength == 0)
510                             this._Controller.DoInputChar('\t');
511                         else if (isShiftPressed)
512                             this._Controller.DownIndent();
513                         else
514                             this._Controller.UpIndent();
515                         this.Refresh();
516                         e.Handled = true;
517                     }
518                     break;
519                 case VirtualKey.Enter:
520                     this._Controller.DoEnterAction();
521                     this.Refresh();
522                     e.Handled = true;
523                     break;
524                 case VirtualKey.Insert:
525                     if(this.View.InsertMode)
526                         this.View.InsertMode = false;
527                     else
528                         this.View.InsertMode = true;
529                     this.Refresh();
530                     e.Handled = true;
531                     break;
532                 case VirtualKey.A:
533                     if (isControlPressed)
534                     {
535                         this.SelectAll();
536                         this.Refresh();
537                         e.Handled = true;
538                     }
539                     break;
540                 case VirtualKey.B:
541                     if (isControlPressed)
542                     {
543                         if (this._Controller.RectSelection)
544                             this._Controller.RectSelection = false;
545                         else
546                             this._Controller.RectSelection = true;
547                         this.Refresh();
548                         e.Handled = true;
549                     }
550                     break;
551                 case VirtualKey.C:
552                     if (isControlPressed)
553                     {
554                         this.CopyCommand();
555                         e.Handled = true;
556                     }
557                     break;
558                 case VirtualKey.X:
559                     if (isControlPressed)
560                     {
561                         this.CutCommand();
562                         e.Handled = true;
563                     }
564                     break;
565                 case VirtualKey.V:
566                     if (isControlPressed)
567                     {
568                         await this.PasteCommand();
569                         e.Handled = true;
570                     }
571                     break;
572                 case VirtualKey.Y:
573                     if (isControlPressed)
574                     {
575                         this.Document.UndoManager.redo();
576                         this.Refresh();
577                         e.Handled = true;
578                     }
579                     break;
580                 case VirtualKey.Z:
581                     if (isControlPressed)
582                     {
583                         this.Document.UndoManager.undo();
584                         this.Refresh();
585                         e.Handled = true;
586                     }
587                     break;
588                 case VirtualKey.Back:
589                     this._Controller.DoBackSpaceAction();
590                     this.Refresh();
591                     e.Handled = true;
592                     break;
593                 case VirtualKey.Delete:
594                     this._Controller.DoDeleteAction();
595                     this.Refresh();
596                     e.Handled = true;
597                     break;
598             }
599             if (isMovedCaret && this.peer != null)
600                 this.peer.OnNotifyCaretChanged();
601             base.OnKeyDown(e);
602         }
603
604         /// <inheritdoc/>
605         protected override void OnPointerPressed(PointerRoutedEventArgs e)
606         {
607             //マウスでは慣性移動自体必要じゃない
608             this.gestureRecongnizer.AutoProcessInertia = e.Pointer.PointerDeviceType != PointerDeviceType.Mouse;
609
610             this.CapturePointer(e.Pointer);
611             this.gestureRecongnizer.ProcessDownEvent(e.GetCurrentPoint(this));
612             e.Handled = true;
613         }
614
615         /// <inheritdoc/>
616         protected override void OnPointerMoved(PointerRoutedEventArgs e)
617         {
618             //マウスでは慣性移動自体必要じゃない
619             this.gestureRecongnizer.AutoProcessInertia = e.Pointer.PointerDeviceType != PointerDeviceType.Mouse;
620
621             this.gestureRecongnizer.ProcessMoveEvents(e.GetIntermediatePoints(this));
622             e.Handled = true;
623
624             if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
625             {
626                 Point p = ((Point)e.GetCurrentPoint(this).Position).Scale(this.Render.GetScale());
627                 if (this.View.HitTextArea(p.X, p.Y))
628                 {
629                     TextPoint tp = this.View.GetTextPointFromPostion(p);
630                     if (this._Controller.IsMarker(tp, HilightType.Url))
631                         Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Hand, 101);
632                     else
633                         Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.IBeam, 101);
634                 }
635                 else
636                 {
637                     Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 101);
638                 }
639             }
640         }
641
642         /// <inheritdoc/>
643         protected override void OnPointerReleased(PointerRoutedEventArgs e)
644         {
645             this.gestureRecongnizer.ProcessUpEvent(e.GetCurrentPoint(this));
646             this.ReleasePointerCapture(e.Pointer);
647             e.Handled = true;
648         }
649
650         /// <inheritdoc/>
651         protected override void OnPointerCanceled(PointerRoutedEventArgs e)
652         {
653             this.gestureRecongnizer.CompleteGesture();
654             this.ReleasePointerCapture(e.Pointer);
655             e.Handled = true;
656         }
657
658         /// <inheritdoc/>
659         protected override void OnPointerCaptureLost(PointerRoutedEventArgs e)
660         {
661             this.gestureRecongnizer.CompleteGesture();
662             this.ReleasePointerCapture(e.Pointer);
663             e.Handled = true;
664         }
665
666         /// <inheritdoc/>
667         protected override void OnPointerWheelChanged(PointerRoutedEventArgs e)
668         {
669             //マウスでは慣性移動自体必要じゃない
670             this.gestureRecongnizer.AutoProcessInertia = e.Pointer.PointerDeviceType != PointerDeviceType.Mouse;
671
672             bool shift = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Shift) ==
673                 Windows.System.VirtualKeyModifiers.Shift;
674             bool ctrl = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Control) ==
675                 Windows.System.VirtualKeyModifiers.Control;
676             this.gestureRecongnizer.ProcessMouseWheelEvent(e.GetCurrentPoint(this), shift, ctrl);
677             e.Handled = true;
678         }
679
680         void CoreWindow_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)
681         {
682             if (this.FocusState == FocusState.Unfocused || !this.IsEnabled)
683                 return;
684             if (args.KeyCode >= 00 && args.KeyCode <= 0x1f)
685                 return;
686             this._Controller.DoInputString(Char.ConvertFromUtf32((int)args.KeyCode));
687             this.Refresh();
688         }
689
690         bool textStore_IsReadOnly()
691         {
692             return false;
693         }
694
695         bool textStore_IsLoading()
696         {
697             return false;
698         }
699
700         void textStore_CompositionEnded()
701         {
702             TextStoreHelper.EndCompostion(this.Document);
703             this.Refresh();
704         }
705
706         void textStore_CompositionUpdated(int start, int end)
707         {
708             if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
709                 this.Refresh();
710         }
711         bool textStore_CompositionStarted()
712         {
713             return TextStoreHelper.StartCompstion(this.Document);
714         }
715
716         string _textStore_GetString(int start, int length)
717         {
718             return this.Document.ToString(start, length);
719         }
720
721         void _textStore_GetStringExtent(
722             int i_startIndex,
723             int i_endIndex,
724             out POINT o_topLeft,
725             out POINT o_bottomRight
726         )
727         {
728             Point startPos, endPos;
729             TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
730
731             double scale = this.Render.GetScale();
732             var screen_startPos = Util.GetScreentPoint(startPos.Scale(scale), this);
733             var screen_endPos = Util.GetScreentPoint(endPos.Scale(scale), this);
734
735             o_topLeft = new POINT((int)screen_startPos.X, (int)screen_startPos.Y);
736             o_bottomRight = new POINT((int)screen_endPos.X, (int)screen_endPos.Y);
737         }
738
739         void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
740         {
741             var pointTopLeft = new Point(0, 0);
742             var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
743
744             var gt = this.TransformToVisual(Window.Current.Content);
745             pointTopLeft = gt.TransformPoint(pointTopLeft);
746             pointBottomRight = gt.TransformPoint(pointBottomRight);
747
748             o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
749             o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
750         }
751
752         void _textStore_GetSelectionIndex(out int o_startIndex, out int o_endIndex)
753         {
754             TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out o_startIndex, out o_endIndex);
755         }
756
757         void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)
758         {
759             TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);
760             this.Refresh();
761         }
762
763         void _textStore_InsertAtSelection(string i_value,ref int o_stratIndex,ref int o_endIndex)
764         {
765             TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
766             this.Refresh();
767         }
768
769         void Controller_SelectionChanged(object sender, EventArgs e)
770         {
771             //こうしないと選択できなくなってしまう
772             this.nowCaretMove = true;
773             SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
774             SetValue(CaretPostionPropertyKey, this.Document.CaretPostion);
775             this.nowCaretMove = false;
776             this.Document.SelectGrippers.BottomLeft.MoveByIndex(this.View, this.Controller.SelectionStart);
777             this.Document.SelectGrippers.BottomRight.MoveByIndex(this.View, this.Controller.SelectionStart + this.Controller.SelectionLength);
778             if (this.textStore.IsLocked() == false)
779                 this.textStore.NotifySelectionChanged();
780         }
781
782         private void gestureRecongnizer_ManipulationInertiaStarting(GestureRecognizer sender, ManipulationInertiaStartingEventArgs e)
783         {
784             //sender.InertiaTranslationDeceleration = 0.001f;
785             //sender.InertiaExpansionDeceleration = 100.0f * 96.0f / 1000.0f;
786             //sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
787         }
788
789         private Point GetDipFromPoint(Point p)
790         {
791             float dpi;
792             this.Render.GetDpi(out dpi, out dpi);
793             double scale = dpi / 96.0;
794             return p.Scale(1 / scale);
795         }
796
797         Gripper hittedGripper;
798         void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)
799         {
800             //Updateedの段階でヒットテストしてしまうとグリッパーを触ってもヒットしないことがある
801             this.hittedGripper = this.View.HitGripperFromPoint(this.GetDipFromPoint(e.Position));
802         }
803
804         const int WheelNoti = 120;
805         const int WheelScrollLines = 3;
806         double TotalWheelCount = 0;
807
808         void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
809         {
810             Point p = this.GetDipFromPoint(e.Position);
811             if (this._Controller.MoveCaretAndGripper(p, this.hittedGripper))
812             {
813                 if (this.peer != null)
814                     this.peer.OnNotifyCaretChanged();
815                 this.Refresh();                
816                 return;
817             }
818
819             if (e.Delta.Scale < 1)
820             {
821                 double newSize = this.Render.FontSize - 1;
822                 if (newSize < 1)
823                     newSize = 1;
824                 this.Render.FontSize = newSize;
825                 this.Refresh();
826                 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
827                 return;
828             }
829             
830             if (e.Delta.Scale > 1)
831             {
832                 double newSize = this.Render.FontSize + 1;
833                 if (newSize > 72)
834                     newSize = 72;
835                 this.Render.FontSize = newSize;
836                 this.Refresh();
837                 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
838                 return;
839             }
840             
841             Point translation = this.GetDipFromPoint(e.Delta.Translation);
842
843             //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
844             if (Math.Abs(e.Cumulative.Translation.X) < Math.Abs(e.Cumulative.Translation.Y))
845             {
846                 int scrollCount = 0;
847                 if (e.PointerDeviceType == PointerDeviceType.Mouse) {
848                     //テキストボックスはWheelNotiごとにWheelScrollLinesずつスクロールするらしい
849                     scrollCount = (int)Math.Abs(this.TotalWheelCount / WheelNoti * WheelScrollLines);
850                     if (scrollCount < 1)
851                         scrollCount = 1;
852                     else if (scrollCount > WheelScrollLines)
853                         scrollCount = WheelScrollLines;
854                     if (this.TotalWheelCount >= WheelNoti)  //0にすると違和感を感じる
855                         this.TotalWheelCount = this.TotalWheelCount % WheelNoti;
856                     this.TotalWheelCount += Math.Abs(translation.Y);
857                 }
858                 else
859                 {
860                     scrollCount = (int)Math.Abs(translation.Y + 0.5);
861                 }
862
863                 if (translation.Y > 0)
864                     this._Controller.Scroll(ScrollDirection.Up, scrollCount, false, false);
865                 else
866                     this._Controller.Scroll(ScrollDirection.Down, scrollCount, false, false);
867                 this.Document.SelectGrippers.BottomLeft.Enabled = false;
868                 this.Document.SelectGrippers.BottomRight.Enabled = false;
869                 this.Refresh();
870                 return;
871             }
872
873             int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
874             if (deltax != 0)
875             {
876                 if (translation.X < 0)
877                     this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
878                 else
879                     this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
880                 this.Document.SelectGrippers.BottomLeft.Enabled = false;
881                 this.Document.SelectGrippers.BottomRight.Enabled = false;
882                 this.Refresh();
883             }
884         }
885
886         void gestureRecongnizer_ManipulationCompleted(GestureRecognizer sender, ManipulationCompletedEventArgs e)
887         {
888         }
889
890         async void gestureRecongnizer_RightTapped(GestureRecognizer sender, RightTappedEventArgs e)
891         {
892             ResourceMap map = ResourceManager.Current.MainResourceMap.GetSubtree("FooEditEngine.Metro/Resources");
893             ResourceContext context = ResourceContext.GetForCurrentView();
894             Point p = this.GetDipFromPoint(e.Position);
895             if (this.View.HitTextArea(p.X, p.Y))
896             {
897                 FooContextMenuEventArgs args = new FooContextMenuEventArgs(e.Position);
898                 if (this.ContextMenuOpening != null)
899                     this.ContextMenuOpening(this, args);
900                 if (!args.Handled)
901                 {
902                     PopupMenu ContextMenu = new PopupMenu();
903                     ContextMenu.Commands.Add(new UICommand(map.GetValue("CopyMenuName", context).ValueAsString, (command) =>
904                     {
905                         this.CopyCommand();
906                     }));
907                     ContextMenu.Commands.Add(new UICommand(map.GetValue("CutMenuName", context).ValueAsString, (command) =>
908                     {
909                         this.CutCommand();
910                     }));
911                     ContextMenu.Commands.Add(new UICommand(map.GetValue("PasteMenuName", context).ValueAsString, async (command) =>
912                     {
913                         await this.PasteCommand();
914                     }));
915                     if (this._Controller.RectSelection)
916                     {
917                         ContextMenu.Commands.Add(new UICommand(map.GetValue("LineSelectMenuName", context).ValueAsString, (command) =>
918                         {
919                             this._Controller.RectSelection = false;
920                         }));
921                     }
922                     else
923                     {
924                         ContextMenu.Commands.Add(new UICommand(map.GetValue("RectSelectMenuName", context).ValueAsString, (command) =>
925                         {
926                             this._Controller.RectSelection = true;
927                         }));
928                     }
929                     await ContextMenu.ShowAsync(Util.GetScreentPoint(e.Position,this));
930                 }
931             }
932         }
933
934         void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)
935         {
936             Point p = this.GetDipFromPoint(e.Position);
937             bool touched = e.PointerDeviceType == PointerDeviceType.Touch;
938             this.Document.SelectGrippers.BottomLeft.Enabled = false;
939             this.Document.SelectGrippers.BottomRight.Enabled = touched;
940             this.JumpCaret(p);
941             System.Diagnostics.Debug.WriteLine(e.TapCount);
942             if (e.TapCount == 2)
943             {
944                 this.Document.SelectGrippers.BottomLeft.Enabled = touched;
945                 //タッチスクリーンでダブルタップした場合、アンカーインデックスを単語の先頭にしないとバグる
946                 this.Controller.SelectWord(this.Controller.SelectionStart, touched);
947             }
948         }
949
950         void JumpCaret(Point p)
951         {
952             TextPoint tp = this.View.GetTextPointFromPostion(p);
953             if (tp == TextPoint.Null)
954                 return;
955
956             int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
957
958             FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
959             if (foldingData != null)
960             {
961                 if (foldingData.Expand)
962                     this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
963                 else
964                     this.View.LayoutLines.FoldingCollection.Expand(foldingData);
965                 this._Controller.JumpCaret(foldingData.Start, false);
966             }
967             else
968             {
969                 this._Controller.JumpCaret(tp.row, tp.col, false);
970             }
971             if (this.peer != null)
972                 this.peer.OnNotifyCaretChanged();
973             this.View.IsFocused = true;
974             this.Focus(FocusState.Programmatic);
975             this.Refresh();
976         }
977
978         void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)
979         {
980             Point p = this.GetDipFromPoint(e.Position);
981             if (this.View.HitTextArea(p.X, p.Y))
982             {
983                 TextPoint tp = this.View.GetTextPointFromPostion(p);
984                 this._Controller.MoveCaretAndSelect(tp);
985                 if (this.peer != null)
986                     this.peer.OnNotifyCaretChanged();
987                 this.Refresh();
988             }
989         }
990
991         bool IsModiferKeyPressed(VirtualKey key)
992         {
993             CoreVirtualKeyStates state = Window.Current.CoreWindow.GetKeyState(key);
994             return (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
995         }
996         void Refresh(Rectangle updateRect)
997         {
998             if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0 || this.Visibility == Windows.UI.Xaml.Visibility.Collapsed || !this.Render.IsCanDraw())
999                 return;
1000
1001             this.Render.BegineDraw();
1002             if (this.IsEnabled)
1003                 this.View.Draw(updateRect);
1004             else
1005                 this.Render.FillBackground(updateRect);
1006             this.Render.EndDraw();
1007         }
1008
1009
1010         bool Resize(double width, double height)
1011         {
1012             if (width == 0 || height == 0)
1013                 throw new ArgumentOutOfRangeException();
1014             if (this.Render.Resize(this.rectangle, width, height))
1015             {
1016                 this.View.PageBound = new Rectangle(0, 0, width, height);
1017
1018                 if (this.horizontalScrollBar != null)
1019                 {
1020                     this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
1021                     this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1022                 }
1023                 if (this.verticalScrollBar != null)
1024                 {
1025                     this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
1026                     this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1027                 }
1028                 return true;
1029             }
1030             return false;
1031         }
1032
1033         void View_SrcChanged(object sender, EventArgs e)
1034         {
1035             if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1036                 return;
1037             EditView view = this.View;
1038             if (view.Src.Row > this.verticalScrollBar.Maximum)
1039                 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
1040             double absoulteX = Math.Abs(view.Src.X);
1041             if (absoulteX > this.horizontalScrollBar.Maximum)
1042                 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1043             if (view.Src.Row != this.verticalScrollBar.Value)
1044                 this.verticalScrollBar.Value = view.Src.Row;
1045             if (view.Src.X != this.horizontalScrollBar.Value)
1046                 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1047         }
1048
1049         void FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)
1050         {
1051         }
1052
1053         void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1054         {
1055             if (this.horizontalScrollBar == null)
1056                 return;
1057             double toX;
1058             if (this.FlowDirection == FlowDirection.LeftToRight)
1059                 toX = this.horizontalScrollBar.Value;
1060             else
1061                 toX = -this.horizontalScrollBar.Value;
1062             this._Controller.Scroll(toX, this.View.Src.Row, false, false);
1063             this.Document.SelectGrippers.BottomLeft.Enabled = false;
1064             this.Document.SelectGrippers.BottomRight.Enabled = false;
1065             this.Refresh();
1066         }
1067
1068         void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1069         {
1070             if (this.verticalScrollBar == null)
1071                 return;
1072             int newRow = (int)this.verticalScrollBar.Value;
1073             if (newRow >= this.View.LayoutLines.Count)
1074                 return;
1075             this._Controller.Scroll(this.View.Src.X, newRow, false, false);
1076             this.Document.SelectGrippers.BottomLeft.Enabled = false;
1077             this.Document.SelectGrippers.BottomRight.Enabled = false;
1078             this.Refresh();
1079         }
1080
1081         void Document_Update(object sender, DocumentUpdateEventArgs e)
1082         {
1083             if (this.textStore.IsLocked())
1084                 return;
1085             if (e.type == UpdateType.Replace)
1086                 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
1087         }
1088
1089         void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1090         {
1091             this.Focus(FocusState.Programmatic);
1092             this.timer.Start();
1093         }
1094
1095         void timer_Tick(object sender, object e)
1096         {
1097             if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))
1098             {
1099                 this.Refresh();
1100                 return;
1101             }
1102
1103             bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding();
1104
1105             ITextLayout layout = this.View.LayoutLines.GetLayout(this.Document.CaretPostion.row);
1106             double width = layout.GetWidthFromIndex(this.Document.CaretPostion.col);
1107             if (width == 0.0)
1108                 width = this.View.CaretWidthOnInsertMode;
1109             double height = layout.Height;
1110             Rectangle updateRect = new Rectangle(
1111                 this.View.CaretLocation.X,
1112                 this.View.CaretLocation.Y,
1113                 width,
1114                 height);
1115
1116             if (updateAll)
1117                 this.Refresh();
1118             else
1119                 this.Refresh(updateRect);
1120         }
1121
1122         /// <inheritdoc/>
1123         public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
1124         {
1125             FooTextBox source = (FooTextBox)sender;
1126             if (e.Property.Equals(IndentModeProperty))
1127                 source.Controller.IndentMode = source.IndentMode;
1128             if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)
1129                 source._Controller.Select(source.Selection.Index,source.Selection.Length);
1130             if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)
1131                 source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col);
1132             if (e.Property.Equals(InsertModeProperty))
1133                 source.View.InsertMode = source.InsertMode;
1134             if (e.Property.Equals(TabCharsProperty))
1135                 source.Document.TabStops = source.TabChars;
1136             if (e.Property.Equals(RectSelectModeProperty))
1137                 source._Controller.RectSelection = source.RectSelectMode;
1138             if (e.Property.Equals(DrawCaretProperty))
1139                 source.View.HideCaret = !source.DrawCaret;
1140             if (e.Property.Equals(DrawCaretLineProperty))
1141                 source.View.HideLineMarker = !source.DrawCaretLine;
1142             if (e.Property.Equals(DrawLineNumberProperty))
1143                 source.Document.DrawLineNumber = source.DrawLineNumber;
1144             if(e.Property.Equals(MagnificationPowerPropertyKey))
1145                 source.Render.FontSize = source.FontSize * source.MagnificationPower;
1146             if (e.Property.Equals(FontFamilyProperty))
1147                 source.Render.FontFamily = source.FontFamily;
1148             if (e.Property.Equals(FontStyleProperty))
1149                 source.Render.FontStyle = source.FontStyle;
1150             if (e.Property.Equals(FontWeightProperty))
1151                 source.Render.FontWeigth = source.FontWeight;
1152             if (e.Property.Equals(FontSizeProperty))
1153                 source.Render.FontSize = source.FontSize;
1154             if (e.Property.Equals(ForegroundProperty))
1155                 source.Render.Foreground = D2DRenderBase.ToColor4(source.Foreground);
1156             if (e.Property.Equals(BackgroundProperty))
1157                 source.Render.Background = D2DRenderBase.ToColor4(source.Background);
1158             if (e.Property.Equals(ControlCharProperty))
1159                 source.Render.ControlChar = D2DRenderBase.ToColor4(source.ControlChar);
1160             if (e.Property.Equals(HilightProperty))
1161                 source.Render.Hilight = D2DRenderBase.ToColor4(source.Hilight);
1162             if (e.Property.Equals(Keyword1Property))
1163                 source.Render.Keyword1 = D2DRenderBase.ToColor4(source.Keyword1);
1164             if (e.Property.Equals(Keyword2Property))
1165                 source.Render.Keyword2 = D2DRenderBase.ToColor4(source.Keyword2);
1166             if (e.Property.Equals(CommentProperty))
1167                 source.Render.Comment = D2DRenderBase.ToColor4(source.Comment);
1168             if (e.Property.Equals(LiteralProperty))
1169                 source.Render.Literal = D2DRenderBase.ToColor4(source.Literal);
1170             if (e.Property.Equals(URLProperty))
1171                 source.Render.Url = D2DRenderBase.ToColor4(source.URL);
1172             if (e.Property.Equals(InsertCaretProperty))
1173                 source.Render.InsertCaret = D2DRenderBase.ToColor4(source.InsertCaret);
1174             if (e.Property.Equals(OverwriteCaretProperty))
1175                 source.Render.OverwriteCaret = D2DRenderBase.ToColor4(source.OverwriteCaret);
1176             if (e.Property.Equals(PaddingProperty))
1177                 source.View.Padding = new Padding((int)source.Padding.Left, (int)source.Padding.Top, (int)source.Padding.Right, (int)source.Padding.Bottom);
1178             if (e.Property.Equals(LineMarkerProperty))
1179                 source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);
1180             if (e.Property.Equals(MarkURLProperty))
1181                 source.Document.UrlMark = source.MarkURL;
1182             if (e.Property.Equals(ShowFullSpaceProperty))
1183                 source.Render.ShowFullSpace = source.ShowFullSpace;
1184             if (e.Property.Equals(ShowHalfSpaceProperty))
1185                 source.Render.ShowHalfSpace = source.ShowHalfSpace;
1186             if (e.Property.Equals(ShowTabProperty))
1187                 source.Render.ShowTab = source.ShowTab;
1188             if (e.Property.Equals(ShowLineBreakProperty))
1189                 source.Render.ShowLineBreak = source.ShowLineBreak;
1190             if (e.Property.Equals(LineBreakProperty))
1191                 source.Document.LineBreak = source.LineBreakMethod;
1192             if (e.Property.Equals(LineBreakCharCountProperty))
1193                 source.Document.LineBreakCharCount = source.LineBreakCharCount;
1194             if (e.Property.Equals(UpdateAreaProperty))
1195                 source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);
1196             if (e.Property.Equals(LineNumberProperty))
1197                 source.Render.LineNumber = D2DRenderBase.ToColor4(source.LineNumber);
1198             if (e.Property.Equals(FlowDirectionProperty))
1199             {
1200                 source.Document.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;
1201                 if(source.horizontalScrollBar != null)
1202                     source.horizontalScrollBar.FlowDirection = source.FlowDirection;
1203             }
1204             if (e.Property.Equals(DrawRulerProperty))
1205             {
1206                 source.Document.HideRuler = !source.DrawRuler;
1207                 source._Controller.JumpCaret(source.Document.CaretPostion.row, source.Document.CaretPostion.col);
1208             }
1209         }
1210         #endregion
1211
1212         #region event
1213         
1214         /// <summary>
1215         /// コンテキストメニューが表示されるときに呼び出されます
1216         /// </summary>
1217         public event EventHandler<FooContextMenuEventArgs> ContextMenuOpening;
1218
1219         #endregion
1220
1221         #region property
1222
1223         internal Controller Controller
1224         {
1225             get
1226             {
1227                 return this._Controller;
1228             }
1229         }
1230
1231         /// <summary>
1232         /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1233         /// </summary>
1234         public TextAntialiasMode TextAntialiasMode
1235         {
1236             get
1237             {
1238                 return this.Render.TextAntialiasMode;
1239             }
1240             set
1241             {
1242                 this.Render.TextAntialiasMode = value;
1243             }
1244         }
1245
1246         /// <summary>
1247         /// シンタックスハイライターを表す
1248         /// </summary>
1249         public IHilighter Hilighter
1250         {
1251             get
1252             {
1253                 return this.View.Hilighter;
1254             }
1255             set
1256             {
1257                 this.View.Hilighter = value;
1258                 this.View.LayoutLines.ClearLayoutCache();
1259             }
1260         }
1261
1262         /// <summary>
1263         /// フォールティングを作成するインターフェイスを表す
1264         /// </summary>
1265         public IFoldingStrategy FoldingStrategy
1266         {
1267             get
1268             {
1269                 return this.View.LayoutLines.FoldingStrategy;
1270             }
1271             set
1272             {
1273                 this.View.LayoutLines.FoldingStrategy = value;
1274                 if (value == null)
1275                     this.View.LayoutLines.FoldingCollection.Clear();
1276             }
1277         }
1278
1279         /// <summary>
1280         /// マーカーパターンセットを表す
1281         /// </summary>
1282         public MarkerPatternSet MarkerPatternSet
1283         {
1284             get
1285             {
1286                 return this.Document.MarkerPatternSet;
1287             }
1288         }
1289
1290         /// <summary>
1291         /// ドキュメントを表す
1292         /// </summary>
1293         public Document Document
1294         {
1295             get;
1296             private set;
1297         }
1298
1299         /// <summary>
1300         /// レイアウト行を表す
1301         /// </summary>
1302         public LineToIndexTable LayoutLineCollection
1303         {
1304             get { return this.View.LayoutLines; }
1305         }
1306
1307         /// <summary>
1308         /// 選択中の文字列を表す
1309         /// </summary>
1310         public string SelectedText
1311         {
1312             get
1313             {
1314                 return this._Controller.SelectedText;
1315             }
1316             set
1317             {
1318                 int oldLength = this.Document.Length;
1319                 this._Controller.SelectedText = value;
1320             }
1321         }
1322
1323         /// <summary>
1324         /// インデントの方法を表す
1325         /// </summary>
1326         public IndentMode IndentMode
1327         {
1328             get { return (IndentMode)GetValue(IndentModeProperty); }
1329             set { SetValue(IndentModeProperty, value); }
1330         }
1331
1332         /// <summary>
1333         /// IndentModeの依存プロパティを表す
1334         /// </summary>
1335         public static readonly DependencyProperty IndentModeProperty =
1336             DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab,OnPropertyChanged));
1337
1338         /// <summary>
1339         /// 選択範囲を表す
1340         /// </summary>
1341         /// <remarks>
1342         /// Lengthが0の場合はキャレット位置を表します。
1343         /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1344         /// </remarks>
1345         public TextRange Selection
1346         {
1347             get { return (TextRange)GetValue(SelectionProperty); }
1348             set { SetValue(SelectionProperty, value); }
1349         }
1350
1351         /// <summary>
1352         /// Selectionの依存プロパティを表す
1353         /// </summary>
1354         public static readonly DependencyProperty SelectionProperty =
1355             DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(0));
1356
1357         /// <summary>
1358         /// 拡大率を表す
1359         /// </summary>
1360         public double MagnificationPower
1361         {
1362             get { return (double)GetValue(MagnificationPowerPropertyKey); }
1363             set { SetValue(MagnificationPowerPropertyKey, value); }
1364         }
1365
1366         /// <summary>
1367         /// 拡大率を表す依存プロパティ
1368         /// </summary>
1369         public static readonly DependencyProperty MagnificationPowerPropertyKey =
1370             DependencyProperty.Register("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0, OnPropertyChanged));
1371
1372         /// <summary>
1373         /// キャレット位置を表す
1374         /// </summary>
1375         public TextPoint CaretPostion
1376         {
1377             get { return (TextPoint)GetValue(CaretPostionPropertyKey); }
1378             set { SetValue(CaretPostionPropertyKey, value); }
1379         }
1380
1381         static readonly DependencyProperty CaretPostionPropertyKey =
1382             DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(new TextPoint(), OnPropertyChanged));
1383
1384         /// <summary>
1385         /// レタリング方向を表す
1386         /// </summary>
1387         public new FlowDirection FlowDirection
1388         {
1389             get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1390             set { SetValue(FlowDirectionProperty, value); }
1391         }
1392
1393         /// <summary>
1394         /// レタリング方向を表す。これは依存プロパティです
1395         /// </summary>
1396         public new static readonly DependencyProperty FlowDirectionProperty =
1397             DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight,OnPropertyChanged));
1398
1399         /// <summary>
1400         /// フォントファミリーを表す
1401         /// </summary>
1402         public new FontFamily FontFamily
1403         {
1404             get { return (FontFamily)GetValue(FontFamilyProperty); }
1405             set { SetValue(FontFamilyProperty, value); }
1406         }
1407
1408         /// <summary>
1409         /// FontFamilyの依存プロパティを表す
1410         /// </summary>
1411         public new static readonly DependencyProperty FontFamilyProperty =
1412             DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(FooTextBox), new PropertyMetadata(new FontFamily("Cambria"), OnPropertyChanged));
1413
1414         /// <summary>
1415         /// フォントサイズを表す
1416         /// </summary>
1417         public new double FontSize
1418         {
1419             get { return (double)GetValue(FontSizeProperty); }
1420             set { SetValue(FontSizeProperty, value); }
1421         }
1422
1423         /// <summary>
1424         /// FontSizeの依存プロパティを表す
1425         /// </summary>
1426         public new static readonly DependencyProperty FontSizeProperty =
1427             DependencyProperty.Register("FontSize", typeof(double), typeof(FooTextBox), new PropertyMetadata(12.0,OnPropertyChanged));
1428
1429         /// <summary>
1430         /// フォントスタイルを表す
1431         /// </summary>
1432         public new FontStyle FontStyle
1433         {
1434             get { return (FontStyle)GetValue(FontStyleProperty); }
1435             set { SetValue(FontStyleProperty, value); }
1436         }
1437
1438         /// <summary>
1439         /// FontStyleの依存プロパティを表す
1440         /// </summary>
1441         public new static readonly DependencyProperty FontStyleProperty =
1442             DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(FooTextBox), new PropertyMetadata(FontStyle.Normal,OnPropertyChanged));
1443
1444         /// <summary>
1445         /// フォントの幅を表す
1446         /// </summary>
1447         public new FontWeight FontWeight
1448         {
1449             get { return (FontWeight)GetValue(FontWeightProperty); }
1450             set { SetValue(FontWeightProperty, value); }
1451         }
1452
1453         /// <summary>
1454         /// FontWeigthの依存プロパティを表す
1455         /// </summary>
1456         public new static readonly DependencyProperty FontWeightProperty =
1457             DependencyProperty.Register("FontWeigth", typeof(FontWeight), typeof(FooTextBox), new PropertyMetadata(FontWeights.Normal,OnPropertyChanged));
1458
1459         /// <summary>
1460         /// デフォルトの文字色を表す。これは依存プロパティです
1461         /// </summary>
1462         public new Windows.UI.Color Foreground
1463         {
1464             get { return (Windows.UI.Color)GetValue(ForegroundProperty); }
1465             set { SetValue(ForegroundProperty, value); }
1466         }
1467
1468         /// <summary>
1469         /// Foregroundの依存プロパティを表す
1470         /// </summary>
1471         public new static readonly DependencyProperty ForegroundProperty =
1472             DependencyProperty.Register("Foreground", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1473
1474         /// <summary>
1475         /// 背景色を表す。これは依存プロパティです
1476         /// </summary>
1477         public new Windows.UI.Color Background
1478         {
1479             get { return (Windows.UI.Color)GetValue(BackgroundProperty); }
1480             set { SetValue(BackgroundProperty, value); }
1481         }
1482
1483         /// <summary>
1484         /// Backgroundの依存プロパティを表す
1485         /// </summary>
1486         public new static readonly DependencyProperty BackgroundProperty =
1487             DependencyProperty.Register("Background", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));
1488
1489         /// <summary>
1490         /// コントロールコードの文字色を表す。これは依存プロパティです
1491         /// </summary>
1492         public Windows.UI.Color ControlChar
1493         {
1494             get { return (Windows.UI.Color)GetValue(ControlCharProperty); }
1495             set { SetValue(ControlCharProperty, value); }
1496         }
1497
1498         /// <summary>
1499         /// ControlCharの依存プロパティを表す
1500         /// </summary>
1501         public static readonly DependencyProperty ControlCharProperty =
1502             DependencyProperty.Register("ControlChar", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1503
1504         /// <summary>
1505         /// 選択時の背景色を表す。これは依存プロパティです
1506         /// </summary>
1507         public Windows.UI.Color Hilight
1508         {
1509             get { return (Windows.UI.Color)GetValue(HilightProperty); }
1510             set { SetValue(HilightProperty, value); }
1511         }
1512
1513         /// <summary>
1514         /// Hilightの依存プロパティを表す
1515         /// </summary>
1516         public static readonly DependencyProperty HilightProperty =
1517             DependencyProperty.Register("Hilight", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DeepSkyBlue, OnPropertyChanged));
1518
1519         /// <summary>
1520         /// キーワード1の文字色を表す。これは依存プロパティです
1521         /// </summary>
1522         public Windows.UI.Color Keyword1
1523         {
1524             get { return (Windows.UI.Color)GetValue(Keyword1Property); }
1525             set { SetValue(Keyword1Property, value); }
1526         }
1527
1528         /// <summary>
1529         /// Keyword1の依存プロパティを表す
1530         /// </summary>
1531         public static readonly DependencyProperty Keyword1Property =
1532             DependencyProperty.Register("Keyword1", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1533
1534         /// <summary>
1535         /// キーワード2の文字色を表す。これは依存プロパティです
1536         /// </summary>
1537         public Windows.UI.Color Keyword2
1538         {
1539             get { return (Windows.UI.Color)GetValue(Keyword2Property); }
1540             set { SetValue(Keyword2Property, value); }
1541         }
1542
1543         /// <summary>
1544         /// Keyword2の依存プロパティを表す
1545         /// </summary>
1546         public static readonly DependencyProperty Keyword2Property =
1547             DependencyProperty.Register("Keyword2", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DarkCyan, OnPropertyChanged));
1548
1549         /// <summary>
1550         /// コメントの文字色を表す。これは依存プロパティです
1551         /// </summary>
1552         public Windows.UI.Color Comment
1553         {
1554             get { return (Windows.UI.Color)GetValue(CommentProperty); }
1555             set { SetValue(CommentProperty, value); }
1556         }
1557
1558         /// <summary>
1559         /// Commentの依存プロパティを表す
1560         /// </summary>
1561         public static readonly DependencyProperty CommentProperty =
1562             DependencyProperty.Register("Comment", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Green, OnPropertyChanged));
1563
1564         /// <summary>
1565         /// 文字リテラルの文字色を表す。これは依存プロパティです
1566         /// </summary>
1567         public Windows.UI.Color Literal
1568         {
1569             get { return (Windows.UI.Color)GetValue(LiteralProperty); }
1570             set { SetValue(LiteralProperty, value); }
1571         }
1572
1573         /// <summary>
1574         /// Literalの依存プロパティを表す
1575         /// </summary>
1576         public static readonly DependencyProperty LiteralProperty =
1577             DependencyProperty.Register("Literal", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Brown, OnPropertyChanged));
1578
1579         /// <summary>
1580         /// URLの文字色を表す。これは依存プロパティです
1581         /// </summary>
1582         public Windows.UI.Color URL
1583         {
1584             get { return (Windows.UI.Color)GetValue(URLProperty); }
1585             set { SetValue(URLProperty, value); }
1586         }
1587
1588         /// <summary>
1589         /// URLの依存プロパティを表す
1590         /// </summary>
1591         public static readonly DependencyProperty URLProperty =
1592             DependencyProperty.Register("URL", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1593
1594         /// <summary>
1595         /// 行更新フラグの色を表す
1596         /// </summary>
1597         public Windows.UI.Color UpdateArea
1598         {
1599             get { return (Windows.UI.Color)GetValue(UpdateAreaProperty); }
1600             set { SetValue(UpdateAreaProperty, value); }
1601         }
1602
1603         /// <summary>
1604         /// UpdateAreaの依存プロパティを表す
1605         /// </summary>
1606         public static readonly DependencyProperty UpdateAreaProperty =
1607             DependencyProperty.Register("UpdateArea", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));
1608
1609         /// <summary>
1610         /// ラインマーカーの色を表す
1611         /// </summary>
1612         public Windows.UI.Color LineMarker
1613         {
1614             get { return (Windows.UI.Color)GetValue(LineMarkerProperty); }
1615             set { SetValue(LineMarkerProperty, value); }
1616         }
1617
1618         /// <summary>
1619         /// LineMarkerの依存プロパティを表す
1620         /// </summary>
1621         public static readonly DependencyProperty LineMarkerProperty =
1622             DependencyProperty.Register("LineMarker", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1623
1624         /// <summary>
1625         /// 挿入モード時のキャレットの色を表す
1626         /// </summary>
1627         public Windows.UI.Color InsertCaret
1628         {
1629             get { return (Windows.UI.Color)GetValue(InsertCaretProperty); }
1630             set { SetValue(InsertCaretProperty, value); }
1631         }
1632
1633         /// <summary>
1634         /// InsertCaretの依存プロパティを表す
1635         /// </summary>
1636         public static readonly DependencyProperty InsertCaretProperty =
1637             DependencyProperty.Register("InsertCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1638
1639         /// <summary>
1640         /// 上書きモード時のキャレット職を表す
1641         /// </summary>
1642         public Windows.UI.Color OverwriteCaret
1643         {
1644             get { return (Windows.UI.Color)GetValue(OverwriteCaretProperty); }
1645             set { SetValue(OverwriteCaretProperty, value); }
1646         }
1647
1648         /// <summary>
1649         /// OverwriteCaretの依存プロパティを表す
1650         /// </summary>
1651         public static readonly DependencyProperty OverwriteCaretProperty =
1652             DependencyProperty.Register("OverwriteCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1653
1654         /// <summary>
1655         /// 行番号の色を表す
1656         /// </summary>
1657         public Windows.UI.Color LineNumber
1658         {
1659             get { return (Windows.UI.Color)GetValue(LineNumberProperty); }
1660             set { SetValue(LineNumberProperty, value); }
1661         }
1662
1663         /// <summary>
1664         /// Using a DependencyProperty as the backing store for LineNumber.  This enables animation, styling, binding, etc...
1665         /// </summary>
1666         public static readonly DependencyProperty LineNumberProperty =
1667             DependencyProperty.Register("LineNumber", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray,OnPropertyChanged));
1668
1669         /// <summary>
1670         /// 余白を表す
1671         /// </summary>
1672         public new Thickness Padding
1673         {
1674             get { return (Thickness)GetValue(PaddingProperty); }
1675             set { SetValue(PaddingProperty, value); }
1676         }
1677
1678         /// <summary>
1679         /// Paddingの依存プロパティを表す
1680         /// </summary>
1681         public new static readonly DependencyProperty PaddingProperty =
1682             DependencyProperty.Register("Padding", typeof(Thickness), typeof(FooTextBox), new PropertyMetadata(new Thickness(),OnPropertyChanged));        
1683
1684         /// <summary>
1685         /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1686         /// </summary>
1687         public bool InsertMode
1688         {
1689             get { return (bool)GetValue(InsertModeProperty); }
1690             set { SetValue(InsertModeProperty, value); }
1691         }
1692
1693         /// <summary>
1694         /// InsertModeの依存プロパティを表す
1695         /// </summary>
1696         public static readonly DependencyProperty InsertModeProperty =
1697             DependencyProperty.Register("InsertMode",
1698             typeof(bool),
1699             typeof(FooTextBox),
1700             new PropertyMetadata(true, OnPropertyChanged));
1701
1702         /// <summary>
1703         /// タブの文字数を表す。これは依存プロパティです
1704         /// </summary>
1705         public int TabChars
1706         {
1707             get { return (int)GetValue(TabCharsProperty); }
1708             set { SetValue(TabCharsProperty, value); }
1709         }
1710
1711         /// <summary>
1712         /// TabCharsの依存プロパティを表す
1713         /// </summary>
1714         public static readonly DependencyProperty TabCharsProperty =
1715             DependencyProperty.Register("TabChars",
1716             typeof(int),
1717             typeof(FooTextBox),
1718             new PropertyMetadata(4, OnPropertyChanged));
1719
1720         /// <summary>
1721         /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1722         /// </summary>
1723         public bool RectSelectMode
1724         {
1725             get { return (bool)GetValue(RectSelectModeProperty); }
1726             set { SetValue(RectSelectModeProperty, value); }
1727         }
1728
1729         /// <summary>
1730         /// RectSelectModeの依存プロパティを表す
1731         /// </summary>
1732         public static readonly DependencyProperty RectSelectModeProperty =
1733             DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1734
1735         /// <summary>
1736         /// 折り返しの方法を指定する
1737         /// </summary>
1738         /// <remarks>
1739         /// 変更した場合、レイアウトの再構築を行う必要があります
1740         /// </remarks>
1741         public LineBreakMethod LineBreakMethod
1742         {
1743             get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1744             set { SetValue(LineBreakProperty, value); }
1745         }
1746
1747         /// <summary>
1748         /// LineBreakMethodの依存プロパティを表す
1749         /// </summary>
1750         public static readonly DependencyProperty LineBreakProperty =
1751             DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None, OnPropertyChanged));
1752
1753
1754         /// <summary>
1755         /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1756         /// </summary>
1757         /// <remarks>
1758         /// 変更した場合、レイアウトの再構築を行う必要があります
1759         /// </remarks>
1760         public int LineBreakCharCount
1761         {
1762             get { return (int)GetValue(LineBreakCharCountProperty); }
1763             set { SetValue(LineBreakCharCountProperty, value); }
1764         }
1765
1766         /// <summary>
1767         /// LineBreakCharCountの依存プロパティを表す
1768         /// </summary>
1769         public static readonly DependencyProperty LineBreakCharCountProperty =
1770             DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));        
1771
1772         /// <summary>
1773         /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1774         /// </summary>
1775         public bool DrawCaret
1776         {
1777             get { return (bool)GetValue(DrawCaretProperty); }
1778             set { SetValue(DrawCaretProperty, value); }
1779         }
1780
1781         /// <summary>
1782         /// DrawCaretの依存プロパティを表す
1783         /// </summary>
1784         public static readonly DependencyProperty DrawCaretProperty =
1785             DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new PropertyMetadata(true, OnPropertyChanged));
1786
1787
1788         /// <summary>
1789         /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1790         /// </summary>
1791         public bool DrawCaretLine
1792         {
1793             get { return (bool)GetValue(DrawCaretLineProperty); }
1794             set { SetValue(DrawCaretLineProperty, value); }
1795         }
1796
1797         /// <summary>
1798         /// DrawCaretLineの依存プロパティを表す
1799         /// </summary>
1800         public static readonly DependencyProperty DrawCaretLineProperty =
1801             DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1802
1803         /// <summary>
1804         /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
1805         /// </summary>
1806         public bool DrawLineNumber
1807         {
1808             get { return (bool)GetValue(DrawLineNumberProperty); }
1809             set { SetValue(DrawLineNumberProperty, value); }
1810         }
1811
1812         /// <summary>
1813         /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
1814         /// </summary>
1815         public bool DrawRuler
1816         {
1817             get { return (bool)GetValue(DrawRulerProperty); }
1818             set { SetValue(DrawRulerProperty, value); }
1819         }
1820
1821         /// <summary>
1822         /// DrawRulerの依存プロパティを表す
1823         /// </summary>
1824         public static readonly DependencyProperty DrawRulerProperty =
1825             DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1826
1827
1828         /// <summary>
1829         /// DrawLineNumberの依存プロパティを表す
1830         /// </summary>
1831         public static readonly DependencyProperty DrawLineNumberProperty =
1832             DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1833
1834         /// <summary>
1835         /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
1836         /// </summary>
1837         public bool MarkURL
1838         {
1839             get { return (bool)GetValue(MarkURLProperty); }
1840             set { SetValue(MarkURLProperty, value); }
1841         }
1842
1843         /// <summary>
1844         /// MarkURLの依存プロパティを表す
1845         /// </summary>
1846         public static readonly DependencyProperty MarkURLProperty =
1847             DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1848
1849         /// <summary>
1850         /// 全角スペースを表示するなら真。そうでないなら偽
1851         /// </summary>
1852         public bool ShowFullSpace
1853         {
1854             get { return (bool)GetValue(ShowFullSpaceProperty); }
1855             set { SetValue(ShowFullSpaceProperty, value); }
1856         }
1857
1858         /// <summary>
1859         /// ShowFullSpaceの依存プロパティを表す
1860         /// </summary>
1861         public static readonly DependencyProperty ShowFullSpaceProperty =
1862             DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1863
1864         /// <summary>
1865         /// 半角スペースを表示するなら真。そうでないなら偽
1866         /// </summary>
1867         public bool ShowHalfSpace
1868         {
1869             get { return (bool)GetValue(ShowHalfSpaceProperty); }
1870             set { SetValue(ShowHalfSpaceProperty, value); }
1871         }
1872
1873         /// <summary>
1874         /// ShowHalfSpaceの依存プロパティを表す
1875         /// </summary>
1876         public static readonly DependencyProperty ShowHalfSpaceProperty =
1877             DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1878
1879         /// <summary>
1880         /// タブを表示するなら真。そうでないなら偽
1881         /// </summary>
1882         public bool ShowTab
1883         {
1884             get { return (bool)GetValue(ShowTabProperty); }
1885             set { SetValue(ShowTabProperty, value); }
1886         }
1887
1888         /// <summary>
1889         /// ShowTabの依存プロパティを表す
1890         /// </summary>
1891         public static readonly DependencyProperty ShowTabProperty =
1892             DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1893
1894         /// <summary>
1895         /// 改行マークを表示するなら真。そうでないなら偽
1896         /// </summary>
1897         public bool ShowLineBreak
1898         {
1899             get { return (bool)GetValue(ShowLineBreakProperty); }
1900             set { SetValue(ShowLineBreakProperty, value); }
1901         }
1902
1903         /// <summary>
1904         /// ShowLineBreakの依存プロパティを表す
1905         /// </summary>
1906         public static readonly DependencyProperty ShowLineBreakProperty =
1907             DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false,OnPropertyChanged));
1908
1909         
1910         #endregion
1911
1912     }
1913     /// <summary>
1914     /// コンテキストメニューのイベントデーターを表す
1915     /// </summary>
1916     public class FooContextMenuEventArgs
1917     {
1918         /// <summary>
1919         /// 処理済みなら真。そうでないなら偽
1920         /// </summary>
1921         public bool Handled = false;
1922         /// <summary>
1923         /// コンテキストメニューを表示すべき座標を表す
1924         /// </summary>
1925         public Windows.Foundation.Point Postion;
1926         /// <summary>
1927         /// コンストラクター
1928         /// </summary>
1929         /// <param name="pos"></param>
1930         public FooContextMenuEventArgs(Windows.Foundation.Point pos)
1931         {
1932             this.Postion = pos;
1933         }
1934     }
1935 }