OSDN Git Service

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