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