OSDN Git Service

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