OSDN Git Service

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