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