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