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(Gripper.GripperWidth / 2, Gripper.GripperWidth, Gripper.GripperWidth / 2, Gripper.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, GripperPostion.Upper);\r
94             this.SecondGripper = new Gripper(this._Controller, this.View, this.Render, GripperPostion.Bottom);\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.JumpToLineHead(this.View.CaretPostion.row,isShiftPressed);\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.JumpToLineEnd(this.View.CaretPostion.row,isShiftPressed);\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         bool HittedCaret;\r
753         Gripper hittedGripper;\r
754         void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)\r
755         {\r
756             this.HittedCaret = false;\r
757             this.hittedGripper = null;\r
758 \r
759             Point p = e.Position;\r
760             TextPoint tp = this.View.GetTextPointFromPostion(p);\r
761             if (tp == this.View.CaretPostion)\r
762             {\r
763                 HittedCaret = true;\r
764             }\r
765             \r
766             if (this.FirstGripper.IsHit(p))\r
767             {\r
768                 hittedGripper = this.FirstGripper;\r
769                 HittedCaret = true;\r
770             }\r
771             \r
772             else if (this.SecondGripper.IsHit(p))\r
773             {\r
774                 hittedGripper = this.SecondGripper;\r
775                 HittedCaret = true;\r
776             }\r
777         }\r
778 \r
779         void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)\r
780         {\r
781             if (this.Document.State == AsyncState.Loading)\r
782                 return;\r
783 \r
784             if (HittedCaret)\r
785             {\r
786                 Point p;\r
787                 if (this.hittedGripper == null)\r
788                      p = e.Position;\r
789                 else\r
790                     p = this.hittedGripper.AdjustPoint(e.Position);\r
791 \r
792                 if (hittedGripper != null)\r
793                 {\r
794                     TextPoint tp = this.View.GetTextPointFromPostion(p);\r
795                     if (this._Controller.IsReverseSelect())\r
796                     {\r
797                         if (Object.ReferenceEquals(hittedGripper,this.SecondGripper))\r
798                             this._Controller.MoveSelectBefore(tp);\r
799                         else\r
800                             this._Controller.MoveCaretAndSelect(tp);\r
801                     }\r
802                     else\r
803                     {\r
804                         if (Object.ReferenceEquals(hittedGripper,this.FirstGripper))\r
805                             this._Controller.MoveSelectBefore(tp);\r
806                         else\r
807                             this._Controller.MoveCaretAndSelect(tp);\r
808                     }\r
809                     if (this.peer != null)\r
810                         this.peer.OnNotifyCaretChanged();\r
811                     this.Refresh();\r
812                     return;\r
813                 }\r
814             }\r
815             if (e.Delta.Scale < 1)\r
816             {\r
817                 double newSize = this.Render.FontSize - 1;\r
818                 if (newSize < 1)\r
819                     newSize = 1;\r
820                 this.Render.FontSize = newSize;\r
821                 this.Refresh();\r
822                 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);\r
823                 return;\r
824             }\r
825             \r
826             if (e.Delta.Scale > 1)\r
827             {\r
828                 double newSize = this.Render.FontSize + 1;\r
829                 if (newSize > 72)\r
830                     newSize = 72;\r
831                 this.Render.FontSize = newSize;\r
832                 this.Refresh();\r
833                 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);\r
834                 return;\r
835             }\r
836 \r
837             Point translation = e.Delta.Translation;\r
838 \r
839             int scrollCount = (int)Math.Abs(translation.Y);\r
840             if (scrollCount > 0)\r
841             {\r
842                 if (scrollCount > this.View.LineCountOnScreen)  //ホイール対策\r
843                     scrollCount = this.View.LineCountOnScreen;\r
844                 if (translation.Y > 0)\r
845                     this._Controller.Scroll(ScrollDirection.Up, scrollCount, false, false);\r
846                 else\r
847                     this._Controller.Scroll(ScrollDirection.Down, scrollCount, false, false);\r
848                 this.FirstGripper.Enabled = false;\r
849                 this.SecondGripper.Enabled = false;\r
850                 this.Refresh();\r
851                 return;\r
852             }\r
853 \r
854             int deltax = (int)Math.Abs(translation.X);\r
855             if (deltax != 0)\r
856             {\r
857                 if (translation.X < 0)\r
858                     this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);\r
859                 else\r
860                     this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);\r
861                 this.FirstGripper.Enabled = false;\r
862                 this.SecondGripper.Enabled = false;\r
863                 this.Refresh();\r
864             }\r
865         }\r
866 \r
867         void gestureRecongnizer_ManipulationCompleted(GestureRecognizer sender, ManipulationCompletedEventArgs e)\r
868         {\r
869         }\r
870 \r
871         async void gestureRecongnizer_RightTapped(GestureRecognizer sender, RightTappedEventArgs e)\r
872         {\r
873             ResourceMap map = ResourceManager.Current.MainResourceMap.GetSubtree("FooEditEngine.Metro/Resources");\r
874             ResourceContext context = ResourceContext.GetForCurrentView();\r
875             if (this.View.HitTextArea(e.Position.X, e.Position.Y))\r
876             {\r
877                 FooContextMenuEventArgs args = new FooContextMenuEventArgs(e.Position);\r
878                 if (this.ContextMenuOpening != null)\r
879                     this.ContextMenuOpening(this, args);\r
880                 if (!args.Handled)\r
881                 {\r
882                     PopupMenu ContextMenu = new PopupMenu();\r
883                     ContextMenu.Commands.Add(new UICommand(map.GetValue("CopyMenuName", context).ValueAsString, (command) =>\r
884                     {\r
885                         this.CopyCommand();\r
886                     }));\r
887                     ContextMenu.Commands.Add(new UICommand(map.GetValue("CutMenuName", context).ValueAsString, (command) =>\r
888                     {\r
889                         this.CutCommand();\r
890                     }));\r
891                     ContextMenu.Commands.Add(new UICommand(map.GetValue("PasteMenuName", context).ValueAsString, async (command) =>\r
892                     {\r
893                         await this.PasteCommand();\r
894                     }));\r
895                     if (this._Controller.RectSelection)\r
896                     {\r
897                         ContextMenu.Commands.Add(new UICommand(map.GetValue("LineSelectMenuName", context).ValueAsString, (command) =>\r
898                         {\r
899                             this._Controller.RectSelection = false;\r
900                         }));\r
901                     }\r
902                     else\r
903                     {\r
904                         ContextMenu.Commands.Add(new UICommand(map.GetValue("RectSelectMenuName", context).ValueAsString, (command) =>\r
905                         {\r
906                             this._Controller.RectSelection = true;\r
907                         }));\r
908                     }\r
909                     await ContextMenu.ShowAsync(Util.GetScreentPoint(e.Position,this));\r
910                 }\r
911             }\r
912         }\r
913 \r
914         void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)\r
915         {\r
916             bool touched = e.PointerDeviceType == PointerDeviceType.Touch;\r
917             this.FirstGripper.Enabled = touched;\r
918             this.SecondGripper.Enabled = touched;\r
919             this.JumpCaret(e.Position);\r
920         }\r
921 \r
922         void JumpCaret(Point p)\r
923         {\r
924             if (this.Document.State == AsyncState.Loading)\r
925                 return;\r
926             \r
927             TextPoint tp = this.View.GetTextPointFromPostion(p);\r
928             if (tp == TextPoint.Null)\r
929                 return;\r
930 \r
931             int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);\r
932 \r
933             FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);\r
934             if (foldingData != null)\r
935             {\r
936                 if (foldingData.Expand)\r
937                     this.View.LayoutLines.FoldingCollection.Collapse(foldingData);\r
938                 else\r
939                     this.View.LayoutLines.FoldingCollection.Expand(foldingData);\r
940                 this._Controller.JumpCaret(foldingData.Start, false);\r
941             }\r
942             else\r
943             {\r
944                 this._Controller.JumpCaret(tp.row, tp.col, false);\r
945             }\r
946             if (this.peer != null)\r
947                 this.peer.OnNotifyCaretChanged();\r
948             this.Focus(FocusState.Pointer);\r
949             this.Refresh();\r
950         }\r
951 \r
952         void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)\r
953         {\r
954             if (this.Document.State == AsyncState.Loading)\r
955                 return;\r
956             Point p = e.Position;\r
957             if (this.View.HitTextArea(p.X, p.Y))\r
958             {\r
959                 TextPoint tp = this.View.GetTextPointFromPostion(p);\r
960                 this._Controller.MoveCaretAndSelect(tp);\r
961                 if (this.peer != null)\r
962                     this.peer.OnNotifyCaretChanged();\r
963                 this.Refresh();\r
964             }\r
965         }\r
966 \r
967         bool IsModiferKeyPressed(VirtualKey key)\r
968         {\r
969             CoreVirtualKeyStates state = Window.Current.CoreWindow.GetKeyState(key);\r
970             return (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;\r
971         }\r
972         void Refresh(Rectangle updateRect)\r
973         {\r
974             if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0/* || !this.Render.IsCanDraw()*/)\r
975                 return;\r
976 \r
977             this.Render.BeginDraw();\r
978             if (this.Document.State != AsyncState.Loading)\r
979                 this.View.Draw(updateRect);\r
980             else\r
981                 this.Render.FillBackground(updateRect);\r
982             this.FirstGripper.Draw();\r
983             this.SecondGripper.Draw();\r
984             this.Render.EndDraw();\r
985         }\r
986 \r
987 \r
988         bool Resize(double width, double height)\r
989         {\r
990             if (width == 0 || height == 0)\r
991                 throw new ArgumentOutOfRangeException();\r
992             if (this.Document.State != AsyncState.Loading && this.Render.Resize(this.rectangle, width, height))\r
993             {\r
994                 this.View.PageBound = new Rectangle(0, 0, width, height);\r
995 \r
996                 if (this.horizontalScrollBar != null)\r
997                 {\r
998                     this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;\r
999                     this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;\r
1000                 }\r
1001                 if (this.verticalScrollBar != null)\r
1002                 {\r
1003                     this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;\r
1004                     this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;\r
1005                 }\r
1006                 return true;\r
1007             }\r
1008             return false;\r
1009         }\r
1010 \r
1011         void View_SrcChanged(object sender, EventArgs e)\r
1012         {\r
1013             if (this.horizontalScrollBar == null || this.verticalScrollBar == null)\r
1014                 return;\r
1015             EditView view = this.View;\r
1016             if (view.Src.Row > this.verticalScrollBar.Maximum)\r
1017                 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;\r
1018             double absoulteX = Math.Abs(view.Src.X);\r
1019             if (absoulteX > this.horizontalScrollBar.Maximum)\r
1020                 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;\r
1021             if (view.Src.Row != this.verticalScrollBar.Value)\r
1022                 this.verticalScrollBar.Value = view.Src.Row;\r
1023             if (view.Src.X != this.horizontalScrollBar.Value)\r
1024                 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);\r
1025         }\r
1026 \r
1027         void FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)\r
1028         {\r
1029             if (this.Document.State == AsyncState.Loading || this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))\r
1030             {\r
1031                 this.Refresh();\r
1032                 return;\r
1033             }\r
1034         }\r
1035 \r
1036         void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)\r
1037         {\r
1038             if (this.Document.State == AsyncState.Loading)\r
1039                 return;\r
1040             if (this.horizontalScrollBar == null)\r
1041                 return;\r
1042             double toX;\r
1043             if (this.FlowDirection == FlowDirection.LeftToRight)\r
1044                 toX = this.horizontalScrollBar.Value;\r
1045             else\r
1046                 toX = -this.horizontalScrollBar.Value;\r
1047             this._Controller.Scroll(toX, this.View.Src.Row, false, false);\r
1048             this.FirstGripper.Enabled = false;\r
1049             this.SecondGripper.Enabled = false;\r
1050             this.Refresh();\r
1051         }\r
1052 \r
1053         void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)\r
1054         {\r
1055             if (this.Document.State == AsyncState.Loading)\r
1056                 return;\r
1057             if (this.verticalScrollBar == null)\r
1058                 return;\r
1059             int newRow = (int)this.verticalScrollBar.Value;\r
1060             if (newRow >= this.View.LayoutLines.Count)\r
1061                 return;\r
1062             this._Controller.Scroll(this.View.Src.X, newRow, false, false);\r
1063             this.FirstGripper.Enabled = false;\r
1064             this.SecondGripper.Enabled = false;\r
1065             this.Refresh();\r
1066         }\r
1067 \r
1068         void Document_Update(object sender, DocumentUpdateEventArgs e)\r
1069         {\r
1070             if (this.textStore.IsLocked() || this.Document.State == AsyncState.Loading || e.type == UpdateType.Clear)\r
1071                 return;\r
1072             if (e.removeLength == 0)\r
1073                 this.textStore.NotifyTextChanged(e.startIndex, e.startIndex, e.startIndex + e.insertLength);\r
1074             else\r
1075                 this.textStore.NotifyTextChanged(e.startIndex, e.startIndex + 1, e.startIndex + e.insertLength - e.removeLength);\r
1076         }\r
1077 \r
1078         void Document_Progress(object sender, ProgressEventArgs e)\r
1079         {\r
1080             if (this.Document.State == AsyncState.Loading)\r
1081                 return;\r
1082             switch (e.state)\r
1083             {\r
1084                 case ProgressState.Start:\r
1085                     this.textStore.NotifyTextChanged(0, this.Document.Length, 0);\r
1086                     break;\r
1087                 case ProgressState.Complete:\r
1088                     this.textStore.NotifyTextChanged(0, 0, this.Document.Length);\r
1089                     if (this.verticalScrollBar != null)\r
1090                         this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;\r
1091                     this.View.CalculateLineCountOnScreen();\r
1092                     break;\r
1093             }\r
1094         }\r
1095 \r
1096         void FooTextBox_Loaded(object sender, RoutedEventArgs e)\r
1097         {\r
1098             this.Focus(FocusState.Programmatic);\r
1099         }\r
1100 \r
1101         /// <inheritdoc/>\r
1102         public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)\r
1103         {\r
1104             FooTextBox source = (FooTextBox)sender;\r
1105             if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)\r
1106                 source._Controller.Select(source.Selection.Index,source.Selection.Length);\r
1107             if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)\r
1108                 source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col);\r
1109             if (e.Property.Equals(InsertModeProperty))\r
1110                 source.View.InsertMode = source.InsertMode;\r
1111             if (e.Property.Equals(TabCharsProperty))\r
1112                 source.View.TabStops = source.TabChars;\r
1113             if (e.Property.Equals(RectSelectModeProperty))\r
1114                 source._Controller.RectSelection = source.RectSelectMode;\r
1115             if (e.Property.Equals(DrawCaretProperty))\r
1116                 source.View.HideCaret = !source.DrawCaret;\r
1117             if (e.Property.Equals(DrawCaretLineProperty))\r
1118                 source.View.HideLineMarker = !source.DrawCaretLine;\r
1119             if (e.Property.Equals(DrawLineNumberProperty))\r
1120             {\r
1121                 source.View.DrawLineNumber = source.DrawLineNumber;\r
1122                 source._Controller.JumpCaret(source.View.CaretPostion.row, source.View.CaretPostion.col);\r
1123             }\r
1124             if(e.Property.Equals(MagnificationPowerPropertyKey))\r
1125                 source.Render.FontSize = source.FontSize * source.MagnificationPower;\r
1126             if (e.Property.Equals(FontFamilyProperty))\r
1127                 source.Render.FontFamily = source.FontFamily;\r
1128             if (e.Property.Equals(FontStyleProperty))\r
1129                 source.Render.FontStyle = source.FontStyle;\r
1130             if (e.Property.Equals(FontWeightProperty))\r
1131                 source.Render.FontWeigth = source.FontWeight;\r
1132             if (e.Property.Equals(FontSizeProperty))\r
1133                 source.Render.FontSize = source.FontSize;\r
1134             if (e.Property.Equals(ForegroundProperty))\r
1135                 source.Render.Foreground = source.Foreground;\r
1136             if (e.Property.Equals(BackgroundProperty))\r
1137                 source.Render.Background = source.Background;\r
1138             if (e.Property.Equals(ControlCharProperty))\r
1139                 source.Render.ControlChar = source.ControlChar;\r
1140             if (e.Property.Equals(HilightProperty))\r
1141                 source.Render.Hilight = source.Hilight;\r
1142             if (e.Property.Equals(Keyword1Property))\r
1143                 source.Render.Keyword1 = source.Keyword1;\r
1144             if (e.Property.Equals(Keyword2Property))\r
1145                 source.Render.Keyword2 = source.Keyword2;\r
1146             if (e.Property.Equals(CommentProperty))\r
1147                 source.Render.Comment = source.Comment;\r
1148             if (e.Property.Equals(LiteralProperty))\r
1149                 source.Render.Literal = source.Literal;\r
1150             if (e.Property.Equals(URLProperty))\r
1151                 source.Render.Url = source.URL;\r
1152             if (e.Property.Equals(InsertCaretProperty))\r
1153                 source.Render.InsertCaret = source.InsertCaret;\r
1154             if (e.Property.Equals(OverwriteCaretProperty))\r
1155                 source.Render.OverwriteCaret = source.OverwriteCaret;\r
1156             if (e.Property.Equals(LineMarkerProperty))\r
1157                 source.Render.LineMarker = source.LineMarker;\r
1158             if (e.Property.Equals(MarkURLProperty))\r
1159                 source.View.UrlMark = source.MarkURL;\r
1160             if (e.Property.Equals(ShowFullSpaceProperty))\r
1161                 source.Render.ShowFullSpace = source.ShowFullSpace;\r
1162             if (e.Property.Equals(ShowHalfSpaceProperty))\r
1163                 source.Render.ShowHalfSpace = source.ShowHalfSpace;\r
1164             if (e.Property.Equals(ShowTabProperty))\r
1165                 source.Render.ShowTab = source.ShowTab;\r
1166             if (e.Property.Equals(ShowLineBreakProperty))\r
1167                 source.Render.ShowLineBreak = source.ShowLineBreak;\r
1168             if (e.Property.Equals(LineBreakProperty))\r
1169                 source.View.LineBreak = source.LineBreakMethod;\r
1170             if (e.Property.Equals(LineBreakCharCountProperty))\r
1171                 source.View.LineBreakCharCount = source.LineBreakCharCount;\r
1172             if (e.Property.Equals(FlowDirectionProperty))\r
1173             {\r
1174                 source.Render.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;\r
1175                 if(source.horizontalScrollBar != null)\r
1176                     source.horizontalScrollBar.FlowDirection = source.FlowDirection;\r
1177             }\r
1178             if (e.Property.Equals(DrawRulerProperty))\r
1179             {\r
1180                 source.View.HideRuler = !source.DrawRuler;\r
1181                 source._Controller.JumpCaret(source.View.CaretPostion.row, source.View.CaretPostion.col);\r
1182             }            \r
1183         }\r
1184         #endregion\r
1185 \r
1186         #region event\r
1187         \r
1188         /// <summary>\r
1189         /// コンテキストメニューが表示されるときに呼び出されます\r
1190         /// </summary>\r
1191         public event EventHandler<FooContextMenuEventArgs> ContextMenuOpening;\r
1192 \r
1193         #endregion\r
1194 \r
1195         #region property\r
1196 \r
1197         internal Controller Controller\r
1198         {\r
1199             get\r
1200             {\r
1201                 return this._Controller;\r
1202             }\r
1203         }\r
1204 \r
1205         /// <summary>\r
1206         /// 文字列の描写に使用されるアンチエイリアシング モードを表します\r
1207         /// </summary>\r
1208         public TextAntialiasMode TextAntialiasMode\r
1209         {\r
1210             get\r
1211             {\r
1212                 return this.Render.TextAntialiasMode;\r
1213             }\r
1214             set\r
1215             {\r
1216                 this.Render.TextAntialiasMode = value;\r
1217             }\r
1218         }\r
1219 \r
1220         /// <summary>\r
1221         /// シンタックスハイライターを表す\r
1222         /// </summary>\r
1223         public IHilighter Hilighter\r
1224         {\r
1225             get\r
1226             {\r
1227                 return this.View.Hilighter;\r
1228             }\r
1229             set\r
1230             {\r
1231                 this.View.Hilighter = value;\r
1232                 this.View.LayoutLines.ClearLayoutCache();\r
1233             }\r
1234         }\r
1235 \r
1236         /// <summary>\r
1237         /// フォールティングを作成するインターフェイスを表す\r
1238         /// </summary>\r
1239         public IFoldingStrategy FoldingStrategy\r
1240         {\r
1241             get\r
1242             {\r
1243                 return this.View.LayoutLines.FoldingStrategy;\r
1244             }\r
1245             set\r
1246             {\r
1247                 this.View.LayoutLines.FoldingStrategy = value;\r
1248                 if (value == null)\r
1249                     this.View.LayoutLines.FoldingCollection.Clear();\r
1250             }\r
1251         }\r
1252 \r
1253         /// <summary>\r
1254         /// マーカーパターンセットを表す\r
1255         /// </summary>\r
1256         public MarkerPatternSet MarkerPatternSet\r
1257         {\r
1258             get\r
1259             {\r
1260                 return this.View.MarkerPatternSet;\r
1261             }\r
1262         }\r
1263 \r
1264         /// <summary>\r
1265         /// ドキュメントを表す\r
1266         /// </summary>\r
1267         public Document Document\r
1268         {\r
1269             get;\r
1270             private set;\r
1271         }\r
1272 \r
1273         /// <summary>\r
1274         /// レイアウト行を表す\r
1275         /// </summary>\r
1276         public LineToIndexTable LayoutLineCollection\r
1277         {\r
1278             get { return this.View.LayoutLines; }\r
1279         }\r
1280 \r
1281         /// <summary>\r
1282         /// 選択中の文字列を表す\r
1283         /// </summary>\r
1284         public string SelectedText\r
1285         {\r
1286             get\r
1287             {\r
1288                 return this._Controller.SelectedText;\r
1289             }\r
1290             set\r
1291             {\r
1292                 int oldLength = this.Document.Length;\r
1293                 this._Controller.SelectedText = value;\r
1294             }\r
1295         }\r
1296 \r
1297         /// <summary>\r
1298         /// 選択範囲を表す\r
1299         /// </summary>\r
1300         /// <remarks>\r
1301         /// Lengthが0の場合はキャレット位置を表します。\r
1302         /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります\r
1303         /// </remarks>\r
1304         public TextRange Selection\r
1305         {\r
1306             get { return (TextRange)GetValue(SelectionProperty); }\r
1307             set { SetValue(SelectionProperty, value); }\r
1308         }\r
1309 \r
1310         /// <summary>\r
1311         /// Selectionの依存プロパティを表す\r
1312         /// </summary>\r
1313         public static readonly DependencyProperty SelectionProperty =\r
1314             DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(0));\r
1315 \r
1316         /// <summary>\r
1317         /// 拡大率を表す\r
1318         /// </summary>\r
1319         public double MagnificationPower\r
1320         {\r
1321             get { return (double)GetValue(MagnificationPowerPropertyKey); }\r
1322             set { SetValue(MagnificationPowerPropertyKey, value); }\r
1323         }\r
1324 \r
1325         /// <summary>\r
1326         /// 拡大率を表す依存プロパティ\r
1327         /// </summary>\r
1328         public static readonly DependencyProperty MagnificationPowerPropertyKey =\r
1329             DependencyProperty.Register("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0, OnPropertyChanged));\r
1330 \r
1331         /// <summary>\r
1332         /// キャレット位置を表す\r
1333         /// </summary>\r
1334         public TextPoint CaretPostion\r
1335         {\r
1336             get { return (TextPoint)GetValue(CaretPostionPropertyKey); }\r
1337             set { SetValue(CaretPostionPropertyKey, value); }\r
1338         }\r
1339 \r
1340         static readonly DependencyProperty CaretPostionPropertyKey =\r
1341             DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(new TextPoint(), OnPropertyChanged));\r
1342 \r
1343         /// <summary>\r
1344         /// レタリング方向を表す\r
1345         /// </summary>\r
1346         public new FlowDirection FlowDirection\r
1347         {\r
1348             get { return (FlowDirection)GetValue(FlowDirectionProperty); }\r
1349             set { SetValue(FlowDirectionProperty, value); }\r
1350         }\r
1351 \r
1352         /// <summary>\r
1353         /// レタリング方向を表す。これは依存プロパティです\r
1354         /// </summary>\r
1355         public new static readonly DependencyProperty FlowDirectionProperty =\r
1356             DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight,OnPropertyChanged));\r
1357 \r
1358         /// <summary>\r
1359         /// フォントファミリーを表す\r
1360         /// </summary>\r
1361         public new FontFamily FontFamily\r
1362         {\r
1363             get { return (FontFamily)GetValue(FontFamilyProperty); }\r
1364             set { SetValue(FontFamilyProperty, value); }\r
1365         }\r
1366 \r
1367         /// <summary>\r
1368         /// FontFamilyの依存プロパティを表す\r
1369         /// </summary>\r
1370         public new static readonly DependencyProperty FontFamilyProperty =\r
1371             DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(FooTextBox), new PropertyMetadata(new FontFamily("Cambria"), OnPropertyChanged));\r
1372 \r
1373         /// <summary>\r
1374         /// フォントサイズを表す\r
1375         /// </summary>\r
1376         public new double FontSize\r
1377         {\r
1378             get { return (double)GetValue(FontSizeProperty); }\r
1379             set { SetValue(FontSizeProperty, value); }\r
1380         }\r
1381 \r
1382         /// <summary>\r
1383         /// FontSizeの依存プロパティを表す\r
1384         /// </summary>\r
1385         public new static readonly DependencyProperty FontSizeProperty =\r
1386             DependencyProperty.Register("FontSize", typeof(double), typeof(FooTextBox), new PropertyMetadata(12.0,OnPropertyChanged));\r
1387 \r
1388         /// <summary>\r
1389         /// フォントスタイルを表す\r
1390         /// </summary>\r
1391         public new FontStyle FontStyle\r
1392         {\r
1393             get { return (FontStyle)GetValue(FontStyleProperty); }\r
1394             set { SetValue(FontStyleProperty, value); }\r
1395         }\r
1396 \r
1397         /// <summary>\r
1398         /// FontStyleの依存プロパティを表す\r
1399         /// </summary>\r
1400         public new static readonly DependencyProperty FontStyleProperty =\r
1401             DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(FooTextBox), new PropertyMetadata(FontStyle.Normal,OnPropertyChanged));\r
1402 \r
1403         /// <summary>\r
1404         /// フォントの幅を表す\r
1405         /// </summary>\r
1406         public new FontWeight FontWeight\r
1407         {\r
1408             get { return (FontWeight)GetValue(FontWeightProperty); }\r
1409             set { SetValue(FontWeightProperty, value); }\r
1410         }\r
1411 \r
1412         /// <summary>\r
1413         /// FontWeigthの依存プロパティを表す\r
1414         /// </summary>\r
1415         public new static readonly DependencyProperty FontWeightProperty =\r
1416             DependencyProperty.Register("FontWeigth", typeof(FontWeight), typeof(FooTextBox), new PropertyMetadata(FontWeights.Normal,OnPropertyChanged));\r
1417 \r
1418         /// <summary>\r
1419         /// デフォルトの文字色を表す。これは依存プロパティです\r
1420         /// </summary>\r
1421         public new Windows.UI.Color Foreground\r
1422         {\r
1423             get { return (Windows.UI.Color)GetValue(ForegroundProperty); }\r
1424             set { SetValue(ForegroundProperty, value); }\r
1425         }\r
1426 \r
1427         /// <summary>\r
1428         /// Foregroundの依存プロパティを表す\r
1429         /// </summary>\r
1430         public new static readonly DependencyProperty ForegroundProperty =\r
1431             DependencyProperty.Register("Foreground", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));\r
1432 \r
1433         /// <summary>\r
1434         /// 背景色を表す。これは依存プロパティです\r
1435         /// </summary>\r
1436         public new Windows.UI.Color Background\r
1437         {\r
1438             get { return (Windows.UI.Color)GetValue(BackgroundProperty); }\r
1439             set { SetValue(BackgroundProperty, value); }\r
1440         }\r
1441 \r
1442         /// <summary>\r
1443         /// Backgroundの依存プロパティを表す\r
1444         /// </summary>\r
1445         public new static readonly DependencyProperty BackgroundProperty =\r
1446             DependencyProperty.Register("Background", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));\r
1447 \r
1448         /// <summary>\r
1449         /// コントロールコードの文字色を表す。これは依存プロパティです\r
1450         /// </summary>\r
1451         public Windows.UI.Color ControlChar\r
1452         {\r
1453             get { return (Windows.UI.Color)GetValue(ControlCharProperty); }\r
1454             set { SetValue(ControlCharProperty, value); }\r
1455         }\r
1456 \r
1457         /// <summary>\r
1458         /// ControlCharの依存プロパティを表す\r
1459         /// </summary>\r
1460         public static readonly DependencyProperty ControlCharProperty =\r
1461             DependencyProperty.Register("ControlChar", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));\r
1462 \r
1463         /// <summary>\r
1464         /// 選択時の背景色を表す。これは依存プロパティです\r
1465         /// </summary>\r
1466         public Windows.UI.Color Hilight\r
1467         {\r
1468             get { return (Windows.UI.Color)GetValue(HilightProperty); }\r
1469             set { SetValue(HilightProperty, value); }\r
1470         }\r
1471 \r
1472         /// <summary>\r
1473         /// Hilightの依存プロパティを表す\r
1474         /// </summary>\r
1475         public static readonly DependencyProperty HilightProperty =\r
1476             DependencyProperty.Register("Hilight", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DeepSkyBlue, OnPropertyChanged));\r
1477 \r
1478         /// <summary>\r
1479         /// キーワード1の文字色を表す。これは依存プロパティです\r
1480         /// </summary>\r
1481         public Windows.UI.Color Keyword1\r
1482         {\r
1483             get { return (Windows.UI.Color)GetValue(Keyword1Property); }\r
1484             set { SetValue(Keyword1Property, value); }\r
1485         }\r
1486 \r
1487         /// <summary>\r
1488         /// Keyword1の依存プロパティを表す\r
1489         /// </summary>\r
1490         public static readonly DependencyProperty Keyword1Property =\r
1491             DependencyProperty.Register("Keyword1", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));\r
1492 \r
1493         /// <summary>\r
1494         /// キーワード2の文字色を表す。これは依存プロパティです\r
1495         /// </summary>\r
1496         public Windows.UI.Color Keyword2\r
1497         {\r
1498             get { return (Windows.UI.Color)GetValue(Keyword2Property); }\r
1499             set { SetValue(Keyword2Property, value); }\r
1500         }\r
1501 \r
1502         /// <summary>\r
1503         /// Keyword2の依存プロパティを表す\r
1504         /// </summary>\r
1505         public static readonly DependencyProperty Keyword2Property =\r
1506             DependencyProperty.Register("Keyword2", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DarkCyan, OnPropertyChanged));\r
1507 \r
1508         /// <summary>\r
1509         /// コメントの文字色を表す。これは依存プロパティです\r
1510         /// </summary>\r
1511         public Windows.UI.Color Comment\r
1512         {\r
1513             get { return (Windows.UI.Color)GetValue(CommentProperty); }\r
1514             set { SetValue(CommentProperty, value); }\r
1515         }\r
1516 \r
1517         /// <summary>\r
1518         /// Commentの依存プロパティを表す\r
1519         /// </summary>\r
1520         public static readonly DependencyProperty CommentProperty =\r
1521             DependencyProperty.Register("Comment", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Green, OnPropertyChanged));\r
1522 \r
1523         /// <summary>\r
1524         /// 文字リテラルの文字色を表す。これは依存プロパティです\r
1525         /// </summary>\r
1526         public Windows.UI.Color Literal\r
1527         {\r
1528             get { return (Windows.UI.Color)GetValue(LiteralProperty); }\r
1529             set { SetValue(LiteralProperty, value); }\r
1530         }\r
1531 \r
1532         /// <summary>\r
1533         /// Literalの依存プロパティを表す\r
1534         /// </summary>\r
1535         public static readonly DependencyProperty LiteralProperty =\r
1536             DependencyProperty.Register("Literal", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Brown, OnPropertyChanged));\r
1537 \r
1538         /// <summary>\r
1539         /// URLの文字色を表す。これは依存プロパティです\r
1540         /// </summary>\r
1541         public Windows.UI.Color URL\r
1542         {\r
1543             get { return (Windows.UI.Color)GetValue(URLProperty); }\r
1544             set { SetValue(URLProperty, value); }\r
1545         }\r
1546 \r
1547         /// <summary>\r
1548         /// URLの依存プロパティを表す\r
1549         /// </summary>\r
1550         public static readonly DependencyProperty URLProperty =\r
1551             DependencyProperty.Register("URL", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));\r
1552 \r
1553 \r
1554         /// <summary>\r
1555         /// ラインマーカーの色を表す\r
1556         /// </summary>\r
1557         public Windows.UI.Color LineMarker\r
1558         {\r
1559             get { return (Windows.UI.Color)GetValue(LineMarkerProperty); }\r
1560             set { SetValue(LineMarkerProperty, value); }\r
1561         }\r
1562 \r
1563         /// <summary>\r
1564         /// LineMarkerの依存プロパティを表す\r
1565         /// </summary>\r
1566         public static readonly DependencyProperty LineMarkerProperty =\r
1567             DependencyProperty.Register("LineMarker", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));\r
1568 \r
1569         /// <summary>\r
1570         /// 挿入モード時のキャレットの色を表す\r
1571         /// </summary>\r
1572         public Windows.UI.Color InsertCaret\r
1573         {\r
1574             get { return (Windows.UI.Color)GetValue(InsertCaretProperty); }\r
1575             set { SetValue(InsertCaretProperty, value); }\r
1576         }\r
1577 \r
1578         /// <summary>\r
1579         /// InsertCaretの依存プロパティを表す\r
1580         /// </summary>\r
1581         public static readonly DependencyProperty InsertCaretProperty =\r
1582             DependencyProperty.Register("InsertCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));\r
1583 \r
1584         /// <summary>\r
1585         /// 上書きモード時のキャレット職を表す\r
1586         /// </summary>\r
1587         public Windows.UI.Color OverwriteCaret\r
1588         {\r
1589             get { return (Windows.UI.Color)GetValue(OverwriteCaretProperty); }\r
1590             set { SetValue(OverwriteCaretProperty, value); }\r
1591         }\r
1592 \r
1593         /// <summary>\r
1594         /// OverwriteCaretの依存プロパティを表す\r
1595         /// </summary>\r
1596         public static readonly DependencyProperty OverwriteCaretProperty =\r
1597             DependencyProperty.Register("OverwriteCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));\r
1598 \r
1599         /// <summary>\r
1600         /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです\r
1601         /// </summary>\r
1602         public bool InsertMode\r
1603         {\r
1604             get { return (bool)GetValue(InsertModeProperty); }\r
1605             set { SetValue(InsertModeProperty, value); }\r
1606         }\r
1607 \r
1608         /// <summary>\r
1609         /// InsertModeの依存プロパティを表す\r
1610         /// </summary>\r
1611         public static readonly DependencyProperty InsertModeProperty =\r
1612             DependencyProperty.Register("InsertMode",\r
1613             typeof(bool),\r
1614             typeof(FooTextBox),\r
1615             new PropertyMetadata(true, OnPropertyChanged));\r
1616 \r
1617         /// <summary>\r
1618         /// タブの文字数を表す。これは依存プロパティです\r
1619         /// </summary>\r
1620         public int TabChars\r
1621         {\r
1622             get { return (int)GetValue(TabCharsProperty); }\r
1623             set { SetValue(TabCharsProperty, value); }\r
1624         }\r
1625 \r
1626         /// <summary>\r
1627         /// TabCharsの依存プロパティを表す\r
1628         /// </summary>\r
1629         public static readonly DependencyProperty TabCharsProperty =\r
1630             DependencyProperty.Register("TabChars",\r
1631             typeof(int),\r
1632             typeof(FooTextBox),\r
1633             new PropertyMetadata(4, OnPropertyChanged));\r
1634 \r
1635         /// <summary>\r
1636         /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです\r
1637         /// </summary>\r
1638         public bool RectSelectMode\r
1639         {\r
1640             get { return (bool)GetValue(RectSelectModeProperty); }\r
1641             set { SetValue(RectSelectModeProperty, value); }\r
1642         }\r
1643 \r
1644         /// <summary>\r
1645         /// RectSelectModeの依存プロパティを表す\r
1646         /// </summary>\r
1647         public static readonly DependencyProperty RectSelectModeProperty =\r
1648             DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));\r
1649 \r
1650         /// <summary>\r
1651         /// 折り返しの方法を指定する\r
1652         /// </summary>\r
1653         /// <remarks>\r
1654         /// 変更した場合、レイアウトの再構築を行う必要があります\r
1655         /// </remarks>\r
1656         public LineBreakMethod LineBreakMethod\r
1657         {\r
1658             get { return (LineBreakMethod)GetValue(LineBreakProperty); }\r
1659             set { SetValue(LineBreakProperty, value); }\r
1660         }\r
1661 \r
1662         /// <summary>\r
1663         /// LineBreakMethodの依存プロパティを表す\r
1664         /// </summary>\r
1665         public static readonly DependencyProperty LineBreakProperty =\r
1666             DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None, OnPropertyChanged));\r
1667 \r
1668 \r
1669         /// <summary>\r
1670         /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます\r
1671         /// </summary>\r
1672         /// <remarks>\r
1673         /// 変更した場合、レイアウトの再構築を行う必要があります\r
1674         /// </remarks>\r
1675         public int LineBreakCharCount\r
1676         {\r
1677             get { return (int)GetValue(LineBreakCharCountProperty); }\r
1678             set { SetValue(LineBreakCharCountProperty, value); }\r
1679         }\r
1680 \r
1681         /// <summary>\r
1682         /// LineBreakCharCountの依存プロパティを表す\r
1683         /// </summary>\r
1684         public static readonly DependencyProperty LineBreakCharCountProperty =\r
1685             DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));        \r
1686 \r
1687         /// <summary>\r
1688         /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです\r
1689         /// </summary>\r
1690         public bool DrawCaret\r
1691         {\r
1692             get { return (bool)GetValue(DrawCaretProperty); }\r
1693             set { SetValue(DrawCaretProperty, value); }\r
1694         }\r
1695 \r
1696         /// <summary>\r
1697         /// DrawCaretの依存プロパティを表す\r
1698         /// </summary>\r
1699         public static readonly DependencyProperty DrawCaretProperty =\r
1700             DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new PropertyMetadata(true, OnPropertyChanged));\r
1701 \r
1702 \r
1703         /// <summary>\r
1704         /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです\r
1705         /// </summary>\r
1706         public bool DrawCaretLine\r
1707         {\r
1708             get { return (bool)GetValue(DrawCaretLineProperty); }\r
1709             set { SetValue(DrawCaretLineProperty, value); }\r
1710         }\r
1711 \r
1712         /// <summary>\r
1713         /// DrawCaretLineの依存プロパティを表す\r
1714         /// </summary>\r
1715         public static readonly DependencyProperty DrawCaretLineProperty =\r
1716             DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));\r
1717 \r
1718         /// <summary>\r
1719         /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです\r
1720         /// </summary>\r
1721         public bool DrawLineNumber\r
1722         {\r
1723             get { return (bool)GetValue(DrawLineNumberProperty); }\r
1724             set { SetValue(DrawLineNumberProperty, value); }\r
1725         }\r
1726 \r
1727         /// <summary>\r
1728         /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです\r
1729         /// </summary>\r
1730         public bool DrawRuler\r
1731         {\r
1732             get { return (bool)GetValue(DrawRulerProperty); }\r
1733             set { SetValue(DrawRulerProperty, value); }\r
1734         }\r
1735 \r
1736         /// <summary>\r
1737         /// DrawRulerの依存プロパティを表す\r
1738         /// </summary>\r
1739         public static readonly DependencyProperty DrawRulerProperty =\r
1740             DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));\r
1741 \r
1742 \r
1743         /// <summary>\r
1744         /// DrawLineNumberの依存プロパティを表す\r
1745         /// </summary>\r
1746         public static readonly DependencyProperty DrawLineNumberProperty =\r
1747             DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));\r
1748 \r
1749         /// <summary>\r
1750         /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです\r
1751         /// </summary>\r
1752         public bool MarkURL\r
1753         {\r
1754             get { return (bool)GetValue(MarkURLProperty); }\r
1755             set { SetValue(MarkURLProperty, value); }\r
1756         }\r
1757 \r
1758         /// <summary>\r
1759         /// MarkURLの依存プロパティを表す\r
1760         /// </summary>\r
1761         public static readonly DependencyProperty MarkURLProperty =\r
1762             DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));\r
1763 \r
1764         /// <summary>\r
1765         /// 全角スペースを表示するなら真。そうでないなら偽\r
1766         /// </summary>\r
1767         public bool ShowFullSpace\r
1768         {\r
1769             get { return (bool)GetValue(ShowFullSpaceProperty); }\r
1770             set { SetValue(ShowFullSpaceProperty, value); }\r
1771         }\r
1772 \r
1773         /// <summary>\r
1774         /// ShowFullSpaceの依存プロパティを表す\r
1775         /// </summary>\r
1776         public static readonly DependencyProperty ShowFullSpaceProperty =\r
1777             DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));\r
1778 \r
1779         /// <summary>\r
1780         /// 半角スペースを表示するなら真。そうでないなら偽\r
1781         /// </summary>\r
1782         public bool ShowHalfSpace\r
1783         {\r
1784             get { return (bool)GetValue(ShowHalfSpaceProperty); }\r
1785             set { SetValue(ShowHalfSpaceProperty, value); }\r
1786         }\r
1787 \r
1788         /// <summary>\r
1789         /// ShowHalfSpaceの依存プロパティを表す\r
1790         /// </summary>\r
1791         public static readonly DependencyProperty ShowHalfSpaceProperty =\r
1792             DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));\r
1793 \r
1794         /// <summary>\r
1795         /// タブを表示するなら真。そうでないなら偽\r
1796         /// </summary>\r
1797         public bool ShowTab\r
1798         {\r
1799             get { return (bool)GetValue(ShowTabProperty); }\r
1800             set { SetValue(ShowTabProperty, value); }\r
1801         }\r
1802 \r
1803         /// <summary>\r
1804         /// ShowTabの依存プロパティを表す\r
1805         /// </summary>\r
1806         public static readonly DependencyProperty ShowTabProperty =\r
1807             DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));\r
1808 \r
1809         /// <summary>\r
1810         /// 改行マークを表示するなら真。そうでないなら偽\r
1811         /// </summary>\r
1812         public bool ShowLineBreak\r
1813         {\r
1814             get { return (bool)GetValue(ShowLineBreakProperty); }\r
1815             set { SetValue(ShowLineBreakProperty, value); }\r
1816         }\r
1817 \r
1818         /// <summary>\r
1819         /// ShowLineBreakの依存プロパティを表す\r
1820         /// </summary>\r
1821         public static readonly DependencyProperty ShowLineBreakProperty =\r
1822             DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false,OnPropertyChanged));\r
1823 \r
1824         \r
1825         #endregion\r
1826 \r
1827     }\r
1828     /// <summary>\r
1829     /// コンテキストメニューのイベントデーターを表す\r
1830     /// </summary>\r
1831     public class FooContextMenuEventArgs\r
1832     {\r
1833         /// <summary>\r
1834         /// 処理済みなら真。そうでないなら偽\r
1835         /// </summary>\r
1836         public bool Handled = false;\r
1837         /// <summary>\r
1838         /// コンテキストメニューを表示すべき座標を表す\r
1839         /// </summary>\r
1840         public Windows.Foundation.Point Postion;\r
1841         /// <summary>\r
1842         /// コンストラクター\r
1843         /// </summary>\r
1844         /// <param name="pos"></param>\r
1845         public FooContextMenuEventArgs(Windows.Foundation.Point pos)\r
1846         {\r
1847             this.Postion = pos;\r
1848         }\r
1849     }\r
1850 }\r