OSDN Git Service

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