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.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.FirstGripper = new Gripper(this._Controller, this.View, this.Render, GripperPostion.BottomLeft);
96             this.SecondGripper = new Gripper(this._Controller, this.View, this.Render, GripperPostion.BottomRight);
97
98             this.gestureRecongnizer.GestureSettings = GestureSettings.Drag | 
99                 GestureSettings.RightTap | 
100                 GestureSettings.Tap | 
101                 GestureSettings.DoubleTap |
102                 GestureSettings.ManipulationTranslateX | 
103                 GestureSettings.ManipulationTranslateY |
104                 GestureSettings.ManipulationScale |
105                 GestureSettings.ManipulationTranslateInertia |
106                 GestureSettings.ManipulationScaleInertia;
107             this.gestureRecongnizer.RightTapped += gestureRecongnizer_RightTapped;
108             this.gestureRecongnizer.Tapped += gestureRecongnizer_Tapped;
109             this.gestureRecongnizer.Dragging += gestureRecongnizer_Dragging;
110             this.gestureRecongnizer.ManipulationInertiaStarting += gestureRecongnizer_ManipulationInertiaStarting;
111             this.gestureRecongnizer.ManipulationStarted += gestureRecongnizer_ManipulationStarted;
112             this.gestureRecongnizer.ManipulationUpdated += gestureRecongnizer_ManipulationUpdated;
113             this.gestureRecongnizer.ManipulationCompleted += gestureRecongnizer_ManipulationCompleted;
114
115             this.timer = new DispatcherTimer();
116             this.timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
117             this.timer.Tick += new EventHandler<object>(this.timer_Tick);
118             this.timer.Start();
119
120             //Viewの初期化が終わった直後に置かないと例外が発生する
121             this.Document.Update += Document_Update;
122
123             Window.Current.CoreWindow.CharacterReceived += CoreWindow_CharacterReceived;
124
125             this.SizeChanged += FooTextBox_SizeChanged;
126
127             this.Loaded += FooTextBox_Loaded;
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.View.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.View.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 = e.GetCurrentPoint(this).Position;
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             float dpi;
732             this.Render.GetDpi(out dpi, out dpi);
733             double scale = dpi / 96.0;
734
735             var gt = this.TransformToVisual(Window.Current.Content);
736             startPos = gt.TransformPoint(startPos.Scale(scale));
737             endPos = gt.TransformPoint(endPos.Scale(scale));
738
739             o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);
740             o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);
741         }
742
743         void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
744         {
745             var pointTopLeft = new Point(0, 0);
746             var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
747
748             var gt = this.TransformToVisual(Window.Current.Content);
749             pointTopLeft = gt.TransformPoint(pointTopLeft);
750             pointBottomRight = gt.TransformPoint(pointBottomRight);
751
752             o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
753             o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
754         }
755
756         void _textStore_GetSelectionIndex(out int o_startIndex, out int o_endIndex)
757         {
758             TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out o_startIndex, out o_endIndex);
759         }
760
761         void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)
762         {
763             TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);
764             this.Refresh();
765         }
766
767         void _textStore_InsertAtSelection(string i_value,ref int o_stratIndex,ref int o_endIndex)
768         {
769             TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
770             this.Refresh();
771         }
772
773         void Controller_SelectionChanged(object sender, EventArgs e)
774         {
775             //こうしないと選択できなくなってしまう
776             this.nowCaretMove = true;
777             SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
778             SetValue(CaretPostionPropertyKey, this.View.CaretPostion);
779             this.nowCaretMove = false;
780             if (this.textStore.IsLocked() == false)
781                 this.textStore.NotifySelectionChanged();
782         }
783
784         Gripper FirstGripper, SecondGripper;
785         bool HittedCaret;
786         Gripper hittedGripper;
787         private void gestureRecongnizer_ManipulationInertiaStarting(GestureRecognizer sender, ManipulationInertiaStartingEventArgs e)
788         {
789             //sender.InertiaTranslationDeceleration = 0.001f;
790             //sender.InertiaExpansionDeceleration = 100.0f * 96.0f / 1000.0f;
791             //sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
792         }
793
794         void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)
795         {
796             this.HittedCaret = false;
797             this.hittedGripper = null;
798
799             Point p = e.Position;
800             TextPoint tp = this.View.GetTextPointFromPostion(p);
801             if (tp == this.View.CaretPostion)
802             {
803                 HittedCaret = true;
804             }
805             
806             if (this.FirstGripper.IsHit(p))
807             {
808                 hittedGripper = this.FirstGripper;
809                 HittedCaret = true;
810                 System.Diagnostics.Debug.WriteLine("first gripper hitted");
811             }
812             
813             else if (this.SecondGripper.IsHit(p))
814             {
815                 hittedGripper = this.SecondGripper;
816                 HittedCaret = true;
817                 System.Diagnostics.Debug.WriteLine("second gripper hitted");
818             }
819         }
820
821         const int WheelNoti = 120;
822         const int WheelScrollLines = 3;
823         double TotalWheelCount = 0;
824
825         void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
826         {
827             if (HittedCaret)
828             {
829                 Point p;
830                 if (this.hittedGripper == null)
831                      p = e.Position;
832                 else
833                     p = this.hittedGripper.AdjustPoint(e.Position);
834
835                 if (hittedGripper != null)
836                 {
837                     TextPoint tp = this.View.GetTextPointFromPostion(p);
838                     if (this._Controller.IsReverseSelect())
839                     {
840                         if (Object.ReferenceEquals(hittedGripper,this.SecondGripper))
841                             this._Controller.MoveSelectBefore(tp);
842                         else
843                             this._Controller.MoveCaretAndSelect(tp);
844                     }
845                     else
846                     {
847                         if (Object.ReferenceEquals(hittedGripper,this.FirstGripper))
848                             this._Controller.MoveSelectBefore(tp);
849                         else
850                             this._Controller.MoveCaretAndSelect(tp);
851                     }
852                 }
853                 else
854                 {
855                     TextPoint tp = this.View.GetTextPointFromPostion(p);
856                     this._Controller.MoveCaretAndSelect(tp);
857                 }
858                 if (this.peer != null)
859                     this.peer.OnNotifyCaretChanged();
860                 if (this._Controller.SelectionLength != 0)
861                     this.FirstGripper.Enabled = true;
862                 else
863                     this.FirstGripper.Enabled = false;
864
865                 this.Refresh();
866                 
867                 return;
868             }
869
870             if (e.Delta.Scale < 1)
871             {
872                 double newSize = this.Render.FontSize - 1;
873                 if (newSize < 1)
874                     newSize = 1;
875                 this.Render.FontSize = newSize;
876                 this.Refresh();
877                 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
878                 return;
879             }
880             
881             if (e.Delta.Scale > 1)
882             {
883                 double newSize = this.Render.FontSize + 1;
884                 if (newSize > 72)
885                     newSize = 72;
886                 this.Render.FontSize = newSize;
887                 this.Refresh();
888                 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
889                 return;
890             }
891             
892             Point translation = e.Delta.Translation;
893
894             //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
895             if (Math.Abs(e.Cumulative.Translation.X) < Math.Abs(e.Cumulative.Translation.Y))
896             {
897                 int scrollCount = 0;
898                 if (e.PointerDeviceType == PointerDeviceType.Mouse) {
899                     //テキストボックスはWheelNotiごとにWheelScrollLinesずつスクロールするらしい
900                     scrollCount = (int)Math.Abs(this.TotalWheelCount / WheelNoti * WheelScrollLines);
901                     if (scrollCount < 1)
902                         scrollCount = 1;
903                     else if (scrollCount > WheelScrollLines)
904                         scrollCount = WheelScrollLines;
905                     if (this.TotalWheelCount >= WheelNoti)  //0にすると違和感を感じる
906                         this.TotalWheelCount = this.TotalWheelCount % WheelNoti;
907                     this.TotalWheelCount += Math.Abs(translation.Y);
908                 }
909                 else
910                 {
911                     scrollCount = (int)Math.Abs(translation.Y + 0.5);
912                 }
913
914                 if (translation.Y > 0)
915                     this._Controller.Scroll(ScrollDirection.Up, scrollCount, false, false);
916                 else
917                     this._Controller.Scroll(ScrollDirection.Down, scrollCount, false, false);
918                 this.FirstGripper.Enabled = false;
919                 this.SecondGripper.Enabled = false;
920                 this.Refresh();
921                 return;
922             }
923
924             int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
925             if (deltax != 0)
926             {
927                 if (translation.X < 0)
928                     this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
929                 else
930                     this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
931                 this.FirstGripper.Enabled = false;
932                 this.SecondGripper.Enabled = false;
933                 this.Refresh();
934             }
935         }
936
937         void gestureRecongnizer_ManipulationCompleted(GestureRecognizer sender, ManipulationCompletedEventArgs e)
938         {
939         }
940
941         async void gestureRecongnizer_RightTapped(GestureRecognizer sender, RightTappedEventArgs e)
942         {
943             ResourceMap map = ResourceManager.Current.MainResourceMap.GetSubtree("FooEditEngine.Metro/Resources");
944             ResourceContext context = ResourceContext.GetForCurrentView();
945             if (this.View.HitTextArea(e.Position.X, e.Position.Y))
946             {
947                 FooContextMenuEventArgs args = new FooContextMenuEventArgs(e.Position);
948                 if (this.ContextMenuOpening != null)
949                     this.ContextMenuOpening(this, args);
950                 if (!args.Handled)
951                 {
952                     PopupMenu ContextMenu = new PopupMenu();
953                     ContextMenu.Commands.Add(new UICommand(map.GetValue("CopyMenuName", context).ValueAsString, (command) =>
954                     {
955                         this.CopyCommand();
956                     }));
957                     ContextMenu.Commands.Add(new UICommand(map.GetValue("CutMenuName", context).ValueAsString, (command) =>
958                     {
959                         this.CutCommand();
960                     }));
961                     ContextMenu.Commands.Add(new UICommand(map.GetValue("PasteMenuName", context).ValueAsString, async (command) =>
962                     {
963                         await this.PasteCommand();
964                     }));
965                     if (this._Controller.RectSelection)
966                     {
967                         ContextMenu.Commands.Add(new UICommand(map.GetValue("LineSelectMenuName", context).ValueAsString, (command) =>
968                         {
969                             this._Controller.RectSelection = false;
970                         }));
971                     }
972                     else
973                     {
974                         ContextMenu.Commands.Add(new UICommand(map.GetValue("RectSelectMenuName", context).ValueAsString, (command) =>
975                         {
976                             this._Controller.RectSelection = true;
977                         }));
978                     }
979                     await ContextMenu.ShowAsync(Util.GetScreentPoint(e.Position,this));
980                 }
981             }
982         }
983
984         void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)
985         {
986             bool touched = e.PointerDeviceType == PointerDeviceType.Touch;
987             this.FirstGripper.Enabled = false;
988             this.SecondGripper.Enabled = touched;
989             this.JumpCaret(e.Position);
990             System.Diagnostics.Debug.WriteLine(e.TapCount);
991             if (e.TapCount == 2)
992             {
993                 this.FirstGripper.Enabled = touched;
994                 //タッチスクリーンでダブルタップした場合、アンカーインデックスを単語の先頭にしないとバグる
995                 this.Controller.SelectWord(this.Controller.SelectionStart, touched);
996             }
997         }
998
999         void JumpCaret(Point p)
1000         {
1001             TextPoint tp = this.View.GetTextPointFromPostion(p);
1002             if (tp == TextPoint.Null)
1003                 return;
1004
1005             int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
1006
1007             FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
1008             if (foldingData != null)
1009             {
1010                 if (foldingData.Expand)
1011                     this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
1012                 else
1013                     this.View.LayoutLines.FoldingCollection.Expand(foldingData);
1014                 this._Controller.JumpCaret(foldingData.Start, false);
1015             }
1016             else
1017             {
1018                 this._Controller.JumpCaret(tp.row, tp.col, false);
1019             }
1020             if (this.peer != null)
1021                 this.peer.OnNotifyCaretChanged();
1022             this.View.IsFocused = true;
1023             this.Focus(FocusState.Programmatic);
1024             this.Refresh();
1025         }
1026
1027         void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)
1028         {
1029             Point p = e.Position;
1030             if (this.View.HitTextArea(p.X, p.Y))
1031             {
1032                 TextPoint tp = this.View.GetTextPointFromPostion(p);
1033                 this._Controller.MoveCaretAndSelect(tp);
1034                 if (this.peer != null)
1035                     this.peer.OnNotifyCaretChanged();
1036                 this.Refresh();
1037             }
1038         }
1039
1040         bool IsModiferKeyPressed(VirtualKey key)
1041         {
1042             CoreVirtualKeyStates state = Window.Current.CoreWindow.GetKeyState(key);
1043             return (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
1044         }
1045         void Refresh(Rectangle updateRect)
1046         {
1047             if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0 || this.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
1048                 return;
1049
1050             this.Render.BegineDraw();
1051             if (this.IsEnabled)
1052                 this.View.Draw(updateRect);
1053             else
1054                 this.Render.FillBackground(updateRect);
1055             this.FirstGripper.Draw();
1056             this.SecondGripper.Draw();
1057             this.Render.EndDraw();
1058         }
1059
1060
1061         bool Resize(double width, double height)
1062         {
1063             if (width == 0 || height == 0)
1064                 throw new ArgumentOutOfRangeException();
1065             if (this.Render.Resize(this.rectangle, width, height))
1066             {
1067                 this.View.PageBound = new Rectangle(0, 0, width, height);
1068
1069                 if (this.horizontalScrollBar != null)
1070                 {
1071                     this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
1072                     this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1073                 }
1074                 if (this.verticalScrollBar != null)
1075                 {
1076                     this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
1077                     this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1078                 }
1079                 return true;
1080             }
1081             return false;
1082         }
1083
1084         void View_SrcChanged(object sender, EventArgs e)
1085         {
1086             if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1087                 return;
1088             EditView view = this.View;
1089             if (view.Src.Row > this.verticalScrollBar.Maximum)
1090                 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
1091             double absoulteX = Math.Abs(view.Src.X);
1092             if (absoulteX > this.horizontalScrollBar.Maximum)
1093                 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1094             if (view.Src.Row != this.verticalScrollBar.Value)
1095                 this.verticalScrollBar.Value = view.Src.Row;
1096             if (view.Src.X != this.horizontalScrollBar.Value)
1097                 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1098         }
1099
1100         void FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)
1101         {
1102             if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))
1103             {
1104                 this.Refresh();
1105                 return;
1106             }
1107         }
1108
1109         void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1110         {
1111             if (this.horizontalScrollBar == null)
1112                 return;
1113             double toX;
1114             if (this.FlowDirection == FlowDirection.LeftToRight)
1115                 toX = this.horizontalScrollBar.Value;
1116             else
1117                 toX = -this.horizontalScrollBar.Value;
1118             this._Controller.Scroll(toX, this.View.Src.Row, false, false);
1119             this.FirstGripper.Enabled = false;
1120             this.SecondGripper.Enabled = false;
1121             this.Refresh();
1122         }
1123
1124         void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1125         {
1126             if (this.verticalScrollBar == null)
1127                 return;
1128             int newRow = (int)this.verticalScrollBar.Value;
1129             if (newRow >= this.View.LayoutLines.Count)
1130                 return;
1131             this._Controller.Scroll(this.View.Src.X, newRow, false, false);
1132             this.FirstGripper.Enabled = false;
1133             this.SecondGripper.Enabled = false;
1134             this.Refresh();
1135         }
1136
1137         void Document_Update(object sender, DocumentUpdateEventArgs e)
1138         {
1139             if (this.textStore.IsLocked())
1140                 return;
1141             if (e.type == UpdateType.Replace)
1142                 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
1143         }
1144
1145         void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1146         {
1147             this.Focus(FocusState.Programmatic);
1148         }
1149
1150         void timer_Tick(object sender, object e)
1151         {
1152             bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding();
1153             if (updateAll)
1154                 this.Refresh();
1155         }
1156
1157         /// <inheritdoc/>
1158         public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
1159         {
1160             FooTextBox source = (FooTextBox)sender;
1161             if (e.Property.Equals(IndentModeProperty))
1162                 source.Controller.IndentMode = source.IndentMode;
1163             if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)
1164                 source._Controller.Select(source.Selection.Index,source.Selection.Length);
1165             if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)
1166                 source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col);
1167             if (e.Property.Equals(InsertModeProperty))
1168                 source.View.InsertMode = source.InsertMode;
1169             if (e.Property.Equals(TabCharsProperty))
1170                 source.View.TabStops = source.TabChars;
1171             if (e.Property.Equals(RectSelectModeProperty))
1172                 source._Controller.RectSelection = source.RectSelectMode;
1173             if (e.Property.Equals(DrawCaretProperty))
1174                 source.View.HideCaret = !source.DrawCaret;
1175             if (e.Property.Equals(DrawCaretLineProperty))
1176                 source.View.HideLineMarker = !source.DrawCaretLine;
1177             if (e.Property.Equals(DrawLineNumberProperty))
1178             {
1179                 source.View.DrawLineNumber = source.DrawLineNumber;
1180                 source._Controller.JumpCaret(source.View.CaretPostion.row, source.View.CaretPostion.col);
1181             }
1182             if(e.Property.Equals(MagnificationPowerPropertyKey))
1183                 source.Render.FontSize = source.FontSize * source.MagnificationPower;
1184             if (e.Property.Equals(FontFamilyProperty))
1185                 source.Render.FontFamily = source.FontFamily;
1186             if (e.Property.Equals(FontStyleProperty))
1187                 source.Render.FontStyle = source.FontStyle;
1188             if (e.Property.Equals(FontWeightProperty))
1189                 source.Render.FontWeigth = source.FontWeight;
1190             if (e.Property.Equals(FontSizeProperty))
1191                 source.Render.FontSize = source.FontSize;
1192             if (e.Property.Equals(ForegroundProperty))
1193                 source.Render.Foreground = D2DRenderBase.ToColor4(source.Foreground);
1194             if (e.Property.Equals(BackgroundProperty))
1195                 source.Render.Background = D2DRenderBase.ToColor4(source.Background);
1196             if (e.Property.Equals(ControlCharProperty))
1197                 source.Render.ControlChar = D2DRenderBase.ToColor4(source.ControlChar);
1198             if (e.Property.Equals(HilightProperty))
1199                 source.Render.Hilight = D2DRenderBase.ToColor4(source.Hilight);
1200             if (e.Property.Equals(Keyword1Property))
1201                 source.Render.Keyword1 = D2DRenderBase.ToColor4(source.Keyword1);
1202             if (e.Property.Equals(Keyword2Property))
1203                 source.Render.Keyword2 = D2DRenderBase.ToColor4(source.Keyword2);
1204             if (e.Property.Equals(CommentProperty))
1205                 source.Render.Comment = D2DRenderBase.ToColor4(source.Comment);
1206             if (e.Property.Equals(LiteralProperty))
1207                 source.Render.Literal = D2DRenderBase.ToColor4(source.Literal);
1208             if (e.Property.Equals(URLProperty))
1209                 source.Render.Url = D2DRenderBase.ToColor4(source.URL);
1210             if (e.Property.Equals(InsertCaretProperty))
1211                 source.Render.InsertCaret = D2DRenderBase.ToColor4(source.InsertCaret);
1212             if (e.Property.Equals(OverwriteCaretProperty))
1213                 source.Render.OverwriteCaret = D2DRenderBase.ToColor4(source.OverwriteCaret);
1214             if (e.Property.Equals(PaddingProperty))
1215                 source.View.Padding = new Padding((int)source.Padding.Left, (int)source.Padding.Top, (int)source.Padding.Right, (int)source.Padding.Bottom);
1216             if (e.Property.Equals(LineMarkerProperty))
1217                 source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);
1218             if (e.Property.Equals(MarkURLProperty))
1219                 source.View.UrlMark = source.MarkURL;
1220             if (e.Property.Equals(ShowFullSpaceProperty))
1221                 source.Render.ShowFullSpace = source.ShowFullSpace;
1222             if (e.Property.Equals(ShowHalfSpaceProperty))
1223                 source.Render.ShowHalfSpace = source.ShowHalfSpace;
1224             if (e.Property.Equals(ShowTabProperty))
1225                 source.Render.ShowTab = source.ShowTab;
1226             if (e.Property.Equals(ShowLineBreakProperty))
1227                 source.Render.ShowLineBreak = source.ShowLineBreak;
1228             if (e.Property.Equals(LineBreakProperty))
1229                 source.View.LineBreak = source.LineBreakMethod;
1230             if (e.Property.Equals(LineBreakCharCountProperty))
1231                 source.View.LineBreakCharCount = source.LineBreakCharCount;
1232             if (e.Property.Equals(UpdateAreaProperty))
1233                 source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);
1234             if (e.Property.Equals(LineNumberProperty))
1235                 source.Render.LineNumber = D2DRenderBase.ToColor4(source.LineNumber);
1236             if (e.Property.Equals(FlowDirectionProperty))
1237             {
1238                 source.Render.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;
1239                 if(source.horizontalScrollBar != null)
1240                     source.horizontalScrollBar.FlowDirection = source.FlowDirection;
1241             }
1242             if (e.Property.Equals(DrawRulerProperty))
1243             {
1244                 source.View.HideRuler = !source.DrawRuler;
1245                 source._Controller.JumpCaret(source.View.CaretPostion.row, source.View.CaretPostion.col);
1246             }
1247         }
1248         #endregion
1249
1250         #region event
1251         
1252         /// <summary>
1253         /// コンテキストメニューが表示されるときに呼び出されます
1254         /// </summary>
1255         public event EventHandler<FooContextMenuEventArgs> ContextMenuOpening;
1256
1257         #endregion
1258
1259         #region property
1260
1261         internal Controller Controller
1262         {
1263             get
1264             {
1265                 return this._Controller;
1266             }
1267         }
1268
1269         /// <summary>
1270         /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1271         /// </summary>
1272         public TextAntialiasMode TextAntialiasMode
1273         {
1274             get
1275             {
1276                 return this.Render.TextAntialiasMode;
1277             }
1278             set
1279             {
1280                 this.Render.TextAntialiasMode = value;
1281             }
1282         }
1283
1284         /// <summary>
1285         /// シンタックスハイライターを表す
1286         /// </summary>
1287         public IHilighter Hilighter
1288         {
1289             get
1290             {
1291                 return this.View.Hilighter;
1292             }
1293             set
1294             {
1295                 this.View.Hilighter = value;
1296                 this.View.LayoutLines.ClearLayoutCache();
1297             }
1298         }
1299
1300         /// <summary>
1301         /// フォールティングを作成するインターフェイスを表す
1302         /// </summary>
1303         public IFoldingStrategy FoldingStrategy
1304         {
1305             get
1306             {
1307                 return this.View.LayoutLines.FoldingStrategy;
1308             }
1309             set
1310             {
1311                 this.View.LayoutLines.FoldingStrategy = value;
1312                 if (value == null)
1313                     this.View.LayoutLines.FoldingCollection.Clear();
1314             }
1315         }
1316
1317         /// <summary>
1318         /// マーカーパターンセットを表す
1319         /// </summary>
1320         public MarkerPatternSet MarkerPatternSet
1321         {
1322             get
1323             {
1324                 return this.View.MarkerPatternSet;
1325             }
1326         }
1327
1328         /// <summary>
1329         /// ドキュメントを表す
1330         /// </summary>
1331         public Document Document
1332         {
1333             get;
1334             private set;
1335         }
1336
1337         /// <summary>
1338         /// レイアウト行を表す
1339         /// </summary>
1340         public LineToIndexTable LayoutLineCollection
1341         {
1342             get { return this.View.LayoutLines; }
1343         }
1344
1345         /// <summary>
1346         /// 選択中の文字列を表す
1347         /// </summary>
1348         public string SelectedText
1349         {
1350             get
1351             {
1352                 return this._Controller.SelectedText;
1353             }
1354             set
1355             {
1356                 int oldLength = this.Document.Length;
1357                 this._Controller.SelectedText = value;
1358             }
1359         }
1360
1361         /// <summary>
1362         /// インデントの方法を表す
1363         /// </summary>
1364         public IndentMode IndentMode
1365         {
1366             get { return (IndentMode)GetValue(IndentModeProperty); }
1367             set { SetValue(IndentModeProperty, value); }
1368         }
1369
1370         /// <summary>
1371         /// IndentModeの依存プロパティを表す
1372         /// </summary>
1373         public static readonly DependencyProperty IndentModeProperty =
1374             DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab,OnPropertyChanged));
1375
1376         /// <summary>
1377         /// 選択範囲を表す
1378         /// </summary>
1379         /// <remarks>
1380         /// Lengthが0の場合はキャレット位置を表します。
1381         /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1382         /// </remarks>
1383         public TextRange Selection
1384         {
1385             get { return (TextRange)GetValue(SelectionProperty); }
1386             set { SetValue(SelectionProperty, value); }
1387         }
1388
1389         /// <summary>
1390         /// Selectionの依存プロパティを表す
1391         /// </summary>
1392         public static readonly DependencyProperty SelectionProperty =
1393             DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(0));
1394
1395         /// <summary>
1396         /// 拡大率を表す
1397         /// </summary>
1398         public double MagnificationPower
1399         {
1400             get { return (double)GetValue(MagnificationPowerPropertyKey); }
1401             set { SetValue(MagnificationPowerPropertyKey, value); }
1402         }
1403
1404         /// <summary>
1405         /// 拡大率を表す依存プロパティ
1406         /// </summary>
1407         public static readonly DependencyProperty MagnificationPowerPropertyKey =
1408             DependencyProperty.Register("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0, OnPropertyChanged));
1409
1410         /// <summary>
1411         /// キャレット位置を表す
1412         /// </summary>
1413         public TextPoint CaretPostion
1414         {
1415             get { return (TextPoint)GetValue(CaretPostionPropertyKey); }
1416             set { SetValue(CaretPostionPropertyKey, value); }
1417         }
1418
1419         static readonly DependencyProperty CaretPostionPropertyKey =
1420             DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(new TextPoint(), OnPropertyChanged));
1421
1422         /// <summary>
1423         /// レタリング方向を表す
1424         /// </summary>
1425         public new FlowDirection FlowDirection
1426         {
1427             get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1428             set { SetValue(FlowDirectionProperty, value); }
1429         }
1430
1431         /// <summary>
1432         /// レタリング方向を表す。これは依存プロパティです
1433         /// </summary>
1434         public new static readonly DependencyProperty FlowDirectionProperty =
1435             DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight,OnPropertyChanged));
1436
1437         /// <summary>
1438         /// フォントファミリーを表す
1439         /// </summary>
1440         public new FontFamily FontFamily
1441         {
1442             get { return (FontFamily)GetValue(FontFamilyProperty); }
1443             set { SetValue(FontFamilyProperty, value); }
1444         }
1445
1446         /// <summary>
1447         /// FontFamilyの依存プロパティを表す
1448         /// </summary>
1449         public new static readonly DependencyProperty FontFamilyProperty =
1450             DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(FooTextBox), new PropertyMetadata(new FontFamily("Cambria"), OnPropertyChanged));
1451
1452         /// <summary>
1453         /// フォントサイズを表す
1454         /// </summary>
1455         public new double FontSize
1456         {
1457             get { return (double)GetValue(FontSizeProperty); }
1458             set { SetValue(FontSizeProperty, value); }
1459         }
1460
1461         /// <summary>
1462         /// FontSizeの依存プロパティを表す
1463         /// </summary>
1464         public new static readonly DependencyProperty FontSizeProperty =
1465             DependencyProperty.Register("FontSize", typeof(double), typeof(FooTextBox), new PropertyMetadata(12.0,OnPropertyChanged));
1466
1467         /// <summary>
1468         /// フォントスタイルを表す
1469         /// </summary>
1470         public new FontStyle FontStyle
1471         {
1472             get { return (FontStyle)GetValue(FontStyleProperty); }
1473             set { SetValue(FontStyleProperty, value); }
1474         }
1475
1476         /// <summary>
1477         /// FontStyleの依存プロパティを表す
1478         /// </summary>
1479         public new static readonly DependencyProperty FontStyleProperty =
1480             DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(FooTextBox), new PropertyMetadata(FontStyle.Normal,OnPropertyChanged));
1481
1482         /// <summary>
1483         /// フォントの幅を表す
1484         /// </summary>
1485         public new FontWeight FontWeight
1486         {
1487             get { return (FontWeight)GetValue(FontWeightProperty); }
1488             set { SetValue(FontWeightProperty, value); }
1489         }
1490
1491         /// <summary>
1492         /// FontWeigthの依存プロパティを表す
1493         /// </summary>
1494         public new static readonly DependencyProperty FontWeightProperty =
1495             DependencyProperty.Register("FontWeigth", typeof(FontWeight), typeof(FooTextBox), new PropertyMetadata(FontWeights.Normal,OnPropertyChanged));
1496
1497         /// <summary>
1498         /// デフォルトの文字色を表す。これは依存プロパティです
1499         /// </summary>
1500         public new Windows.UI.Color Foreground
1501         {
1502             get { return (Windows.UI.Color)GetValue(ForegroundProperty); }
1503             set { SetValue(ForegroundProperty, value); }
1504         }
1505
1506         /// <summary>
1507         /// Foregroundの依存プロパティを表す
1508         /// </summary>
1509         public new static readonly DependencyProperty ForegroundProperty =
1510             DependencyProperty.Register("Foreground", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1511
1512         /// <summary>
1513         /// 背景色を表す。これは依存プロパティです
1514         /// </summary>
1515         public new Windows.UI.Color Background
1516         {
1517             get { return (Windows.UI.Color)GetValue(BackgroundProperty); }
1518             set { SetValue(BackgroundProperty, value); }
1519         }
1520
1521         /// <summary>
1522         /// Backgroundの依存プロパティを表す
1523         /// </summary>
1524         public new static readonly DependencyProperty BackgroundProperty =
1525             DependencyProperty.Register("Background", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));
1526
1527         /// <summary>
1528         /// コントロールコードの文字色を表す。これは依存プロパティです
1529         /// </summary>
1530         public Windows.UI.Color ControlChar
1531         {
1532             get { return (Windows.UI.Color)GetValue(ControlCharProperty); }
1533             set { SetValue(ControlCharProperty, value); }
1534         }
1535
1536         /// <summary>
1537         /// ControlCharの依存プロパティを表す
1538         /// </summary>
1539         public static readonly DependencyProperty ControlCharProperty =
1540             DependencyProperty.Register("ControlChar", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1541
1542         /// <summary>
1543         /// 選択時の背景色を表す。これは依存プロパティです
1544         /// </summary>
1545         public Windows.UI.Color Hilight
1546         {
1547             get { return (Windows.UI.Color)GetValue(HilightProperty); }
1548             set { SetValue(HilightProperty, value); }
1549         }
1550
1551         /// <summary>
1552         /// Hilightの依存プロパティを表す
1553         /// </summary>
1554         public static readonly DependencyProperty HilightProperty =
1555             DependencyProperty.Register("Hilight", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DeepSkyBlue, OnPropertyChanged));
1556
1557         /// <summary>
1558         /// キーワード1の文字色を表す。これは依存プロパティです
1559         /// </summary>
1560         public Windows.UI.Color Keyword1
1561         {
1562             get { return (Windows.UI.Color)GetValue(Keyword1Property); }
1563             set { SetValue(Keyword1Property, value); }
1564         }
1565
1566         /// <summary>
1567         /// Keyword1の依存プロパティを表す
1568         /// </summary>
1569         public static readonly DependencyProperty Keyword1Property =
1570             DependencyProperty.Register("Keyword1", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1571
1572         /// <summary>
1573         /// キーワード2の文字色を表す。これは依存プロパティです
1574         /// </summary>
1575         public Windows.UI.Color Keyword2
1576         {
1577             get { return (Windows.UI.Color)GetValue(Keyword2Property); }
1578             set { SetValue(Keyword2Property, value); }
1579         }
1580
1581         /// <summary>
1582         /// Keyword2の依存プロパティを表す
1583         /// </summary>
1584         public static readonly DependencyProperty Keyword2Property =
1585             DependencyProperty.Register("Keyword2", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DarkCyan, OnPropertyChanged));
1586
1587         /// <summary>
1588         /// コメントの文字色を表す。これは依存プロパティです
1589         /// </summary>
1590         public Windows.UI.Color Comment
1591         {
1592             get { return (Windows.UI.Color)GetValue(CommentProperty); }
1593             set { SetValue(CommentProperty, value); }
1594         }
1595
1596         /// <summary>
1597         /// Commentの依存プロパティを表す
1598         /// </summary>
1599         public static readonly DependencyProperty CommentProperty =
1600             DependencyProperty.Register("Comment", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Green, OnPropertyChanged));
1601
1602         /// <summary>
1603         /// 文字リテラルの文字色を表す。これは依存プロパティです
1604         /// </summary>
1605         public Windows.UI.Color Literal
1606         {
1607             get { return (Windows.UI.Color)GetValue(LiteralProperty); }
1608             set { SetValue(LiteralProperty, value); }
1609         }
1610
1611         /// <summary>
1612         /// Literalの依存プロパティを表す
1613         /// </summary>
1614         public static readonly DependencyProperty LiteralProperty =
1615             DependencyProperty.Register("Literal", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Brown, OnPropertyChanged));
1616
1617         /// <summary>
1618         /// URLの文字色を表す。これは依存プロパティです
1619         /// </summary>
1620         public Windows.UI.Color URL
1621         {
1622             get { return (Windows.UI.Color)GetValue(URLProperty); }
1623             set { SetValue(URLProperty, value); }
1624         }
1625
1626         /// <summary>
1627         /// URLの依存プロパティを表す
1628         /// </summary>
1629         public static readonly DependencyProperty URLProperty =
1630             DependencyProperty.Register("URL", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1631
1632         /// <summary>
1633         /// 行更新フラグの色を表す
1634         /// </summary>
1635         public Windows.UI.Color UpdateArea
1636         {
1637             get { return (Windows.UI.Color)GetValue(UpdateAreaProperty); }
1638             set { SetValue(UpdateAreaProperty, value); }
1639         }
1640
1641         /// <summary>
1642         /// UpdateAreaの依存プロパティを表す
1643         /// </summary>
1644         public static readonly DependencyProperty UpdateAreaProperty =
1645             DependencyProperty.Register("UpdateArea", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));
1646
1647         /// <summary>
1648         /// ラインマーカーの色を表す
1649         /// </summary>
1650         public Windows.UI.Color LineMarker
1651         {
1652             get { return (Windows.UI.Color)GetValue(LineMarkerProperty); }
1653             set { SetValue(LineMarkerProperty, value); }
1654         }
1655
1656         /// <summary>
1657         /// LineMarkerの依存プロパティを表す
1658         /// </summary>
1659         public static readonly DependencyProperty LineMarkerProperty =
1660             DependencyProperty.Register("LineMarker", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1661
1662         /// <summary>
1663         /// 挿入モード時のキャレットの色を表す
1664         /// </summary>
1665         public Windows.UI.Color InsertCaret
1666         {
1667             get { return (Windows.UI.Color)GetValue(InsertCaretProperty); }
1668             set { SetValue(InsertCaretProperty, value); }
1669         }
1670
1671         /// <summary>
1672         /// InsertCaretの依存プロパティを表す
1673         /// </summary>
1674         public static readonly DependencyProperty InsertCaretProperty =
1675             DependencyProperty.Register("InsertCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1676
1677         /// <summary>
1678         /// 上書きモード時のキャレット職を表す
1679         /// </summary>
1680         public Windows.UI.Color OverwriteCaret
1681         {
1682             get { return (Windows.UI.Color)GetValue(OverwriteCaretProperty); }
1683             set { SetValue(OverwriteCaretProperty, value); }
1684         }
1685
1686         /// <summary>
1687         /// OverwriteCaretの依存プロパティを表す
1688         /// </summary>
1689         public static readonly DependencyProperty OverwriteCaretProperty =
1690             DependencyProperty.Register("OverwriteCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1691
1692         /// <summary>
1693         /// 行番号の色を表す
1694         /// </summary>
1695         public Windows.UI.Color LineNumber
1696         {
1697             get { return (Windows.UI.Color)GetValue(LineNumberProperty); }
1698             set { SetValue(LineNumberProperty, value); }
1699         }
1700
1701         /// <summary>
1702         /// Using a DependencyProperty as the backing store for LineNumber.  This enables animation, styling, binding, etc...
1703         /// </summary>
1704         public static readonly DependencyProperty LineNumberProperty =
1705             DependencyProperty.Register("LineNumber", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray,OnPropertyChanged));
1706
1707         /// <summary>
1708         /// 余白を表す
1709         /// </summary>
1710         public new Thickness Padding
1711         {
1712             get { return (Thickness)GetValue(PaddingProperty); }
1713             set { SetValue(PaddingProperty, value); }
1714         }
1715
1716         /// <summary>
1717         /// Paddingの依存プロパティを表す
1718         /// </summary>
1719         public new static readonly DependencyProperty PaddingProperty =
1720             DependencyProperty.Register("Padding", typeof(Thickness), typeof(FooTextBox), new PropertyMetadata(new Thickness(),OnPropertyChanged));        
1721
1722         /// <summary>
1723         /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1724         /// </summary>
1725         public bool InsertMode
1726         {
1727             get { return (bool)GetValue(InsertModeProperty); }
1728             set { SetValue(InsertModeProperty, value); }
1729         }
1730
1731         /// <summary>
1732         /// InsertModeの依存プロパティを表す
1733         /// </summary>
1734         public static readonly DependencyProperty InsertModeProperty =
1735             DependencyProperty.Register("InsertMode",
1736             typeof(bool),
1737             typeof(FooTextBox),
1738             new PropertyMetadata(true, OnPropertyChanged));
1739
1740         /// <summary>
1741         /// タブの文字数を表す。これは依存プロパティです
1742         /// </summary>
1743         public int TabChars
1744         {
1745             get { return (int)GetValue(TabCharsProperty); }
1746             set { SetValue(TabCharsProperty, value); }
1747         }
1748
1749         /// <summary>
1750         /// TabCharsの依存プロパティを表す
1751         /// </summary>
1752         public static readonly DependencyProperty TabCharsProperty =
1753             DependencyProperty.Register("TabChars",
1754             typeof(int),
1755             typeof(FooTextBox),
1756             new PropertyMetadata(4, OnPropertyChanged));
1757
1758         /// <summary>
1759         /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1760         /// </summary>
1761         public bool RectSelectMode
1762         {
1763             get { return (bool)GetValue(RectSelectModeProperty); }
1764             set { SetValue(RectSelectModeProperty, value); }
1765         }
1766
1767         /// <summary>
1768         /// RectSelectModeの依存プロパティを表す
1769         /// </summary>
1770         public static readonly DependencyProperty RectSelectModeProperty =
1771             DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1772
1773         /// <summary>
1774         /// 折り返しの方法を指定する
1775         /// </summary>
1776         /// <remarks>
1777         /// 変更した場合、レイアウトの再構築を行う必要があります
1778         /// </remarks>
1779         public LineBreakMethod LineBreakMethod
1780         {
1781             get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1782             set { SetValue(LineBreakProperty, value); }
1783         }
1784
1785         /// <summary>
1786         /// LineBreakMethodの依存プロパティを表す
1787         /// </summary>
1788         public static readonly DependencyProperty LineBreakProperty =
1789             DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None, OnPropertyChanged));
1790
1791
1792         /// <summary>
1793         /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1794         /// </summary>
1795         /// <remarks>
1796         /// 変更した場合、レイアウトの再構築を行う必要があります
1797         /// </remarks>
1798         public int LineBreakCharCount
1799         {
1800             get { return (int)GetValue(LineBreakCharCountProperty); }
1801             set { SetValue(LineBreakCharCountProperty, value); }
1802         }
1803
1804         /// <summary>
1805         /// LineBreakCharCountの依存プロパティを表す
1806         /// </summary>
1807         public static readonly DependencyProperty LineBreakCharCountProperty =
1808             DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));        
1809
1810         /// <summary>
1811         /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1812         /// </summary>
1813         public bool DrawCaret
1814         {
1815             get { return (bool)GetValue(DrawCaretProperty); }
1816             set { SetValue(DrawCaretProperty, value); }
1817         }
1818
1819         /// <summary>
1820         /// DrawCaretの依存プロパティを表す
1821         /// </summary>
1822         public static readonly DependencyProperty DrawCaretProperty =
1823             DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new PropertyMetadata(true, OnPropertyChanged));
1824
1825
1826         /// <summary>
1827         /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1828         /// </summary>
1829         public bool DrawCaretLine
1830         {
1831             get { return (bool)GetValue(DrawCaretLineProperty); }
1832             set { SetValue(DrawCaretLineProperty, value); }
1833         }
1834
1835         /// <summary>
1836         /// DrawCaretLineの依存プロパティを表す
1837         /// </summary>
1838         public static readonly DependencyProperty DrawCaretLineProperty =
1839             DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1840
1841         /// <summary>
1842         /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
1843         /// </summary>
1844         public bool DrawLineNumber
1845         {
1846             get { return (bool)GetValue(DrawLineNumberProperty); }
1847             set { SetValue(DrawLineNumberProperty, value); }
1848         }
1849
1850         /// <summary>
1851         /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
1852         /// </summary>
1853         public bool DrawRuler
1854         {
1855             get { return (bool)GetValue(DrawRulerProperty); }
1856             set { SetValue(DrawRulerProperty, value); }
1857         }
1858
1859         /// <summary>
1860         /// DrawRulerの依存プロパティを表す
1861         /// </summary>
1862         public static readonly DependencyProperty DrawRulerProperty =
1863             DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1864
1865
1866         /// <summary>
1867         /// DrawLineNumberの依存プロパティを表す
1868         /// </summary>
1869         public static readonly DependencyProperty DrawLineNumberProperty =
1870             DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1871
1872         /// <summary>
1873         /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
1874         /// </summary>
1875         public bool MarkURL
1876         {
1877             get { return (bool)GetValue(MarkURLProperty); }
1878             set { SetValue(MarkURLProperty, value); }
1879         }
1880
1881         /// <summary>
1882         /// MarkURLの依存プロパティを表す
1883         /// </summary>
1884         public static readonly DependencyProperty MarkURLProperty =
1885             DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1886
1887         /// <summary>
1888         /// 全角スペースを表示するなら真。そうでないなら偽
1889         /// </summary>
1890         public bool ShowFullSpace
1891         {
1892             get { return (bool)GetValue(ShowFullSpaceProperty); }
1893             set { SetValue(ShowFullSpaceProperty, value); }
1894         }
1895
1896         /// <summary>
1897         /// ShowFullSpaceの依存プロパティを表す
1898         /// </summary>
1899         public static readonly DependencyProperty ShowFullSpaceProperty =
1900             DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1901
1902         /// <summary>
1903         /// 半角スペースを表示するなら真。そうでないなら偽
1904         /// </summary>
1905         public bool ShowHalfSpace
1906         {
1907             get { return (bool)GetValue(ShowHalfSpaceProperty); }
1908             set { SetValue(ShowHalfSpaceProperty, value); }
1909         }
1910
1911         /// <summary>
1912         /// ShowHalfSpaceの依存プロパティを表す
1913         /// </summary>
1914         public static readonly DependencyProperty ShowHalfSpaceProperty =
1915             DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1916
1917         /// <summary>
1918         /// タブを表示するなら真。そうでないなら偽
1919         /// </summary>
1920         public bool ShowTab
1921         {
1922             get { return (bool)GetValue(ShowTabProperty); }
1923             set { SetValue(ShowTabProperty, value); }
1924         }
1925
1926         /// <summary>
1927         /// ShowTabの依存プロパティを表す
1928         /// </summary>
1929         public static readonly DependencyProperty ShowTabProperty =
1930             DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1931
1932         /// <summary>
1933         /// 改行マークを表示するなら真。そうでないなら偽
1934         /// </summary>
1935         public bool ShowLineBreak
1936         {
1937             get { return (bool)GetValue(ShowLineBreakProperty); }
1938             set { SetValue(ShowLineBreakProperty, value); }
1939         }
1940
1941         /// <summary>
1942         /// ShowLineBreakの依存プロパティを表す
1943         /// </summary>
1944         public static readonly DependencyProperty ShowLineBreakProperty =
1945             DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false,OnPropertyChanged));
1946
1947         
1948         #endregion
1949
1950     }
1951     /// <summary>
1952     /// コンテキストメニューのイベントデーターを表す
1953     /// </summary>
1954     public class FooContextMenuEventArgs
1955     {
1956         /// <summary>
1957         /// 処理済みなら真。そうでないなら偽
1958         /// </summary>
1959         public bool Handled = false;
1960         /// <summary>
1961         /// コンテキストメニューを表示すべき座標を表す
1962         /// </summary>
1963         public Windows.Foundation.Point Postion;
1964         /// <summary>
1965         /// コンストラクター
1966         /// </summary>
1967         /// <param name="pos"></param>
1968         public FooContextMenuEventArgs(Windows.Foundation.Point pos)
1969         {
1970             this.Postion = pos;
1971         }
1972     }
1973 }