OSDN Git Service

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