OSDN Git Service

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