OSDN Git Service

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