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