OSDN Git Service

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