OSDN Git Service

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