OSDN Git Service

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