2 * Copyright (C) 2013 FooProject
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
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
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/>.
14 using System.ComponentModel;
15 using System.Threading.Tasks;
16 using Windows.ApplicationModel.Resources.Core;
17 using Windows.Devices.Input;
19 using Windows.ApplicationModel.DataTransfer;
20 using Windows.Foundation;
22 using Windows.UI.Input;
23 using Windows.UI.Core;
24 using Windows.UI.Popups;
25 using Windows.UI.Text;
26 using Windows.UI.Xaml.Media;
27 using Windows.UI.Xaml;
28 using Windows.UI.Xaml.Controls;
29 using Windows.UI.Xaml.Controls.Primitives;
30 using Windows.UI.Xaml.Input;
31 using Windows.UI.Text.Core;
33 // テンプレート コントロールのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234235 を参照してください
34 namespace FooEditEngine.UWP
39 public sealed class FooTextBox : Control,IDisposable
42 Controller _Controller;
48 ScrollBar horizontalScrollBar, verticalScrollBar;
49 Windows.UI.Xaml.Shapes.Rectangle rectangle;
50 GestureRecognizer gestureRecongnizer = new GestureRecognizer();
51 CoreTextEditContext textEditContext;
52 CoreTextServicesManager textServiceManager;
54 FooTextBoxAutomationPeer peer;
56 bool nowCaretMove = false;
57 bool nowCompstion = false;
58 bool requestSizeChange = false;
60 DispatcherTimer timer = new DispatcherTimer();
62 const int Interval = 32;
63 const int IntervalWhenLostFocus = 160;
70 this.DefaultStyleKey = typeof(FooTextBox);
72 this.rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
73 this.rectangle.Margin = this.Padding;
75 this.Render = new D2DRender(this,this.rectangle);
77 this.Render = new DummyRender();
80 this.Document = new Document();
82 this._View = new EditView(this.Document, this.Render, new Padding(5, 5, Gripper.HitAreaWidth / 2, Gripper.HitAreaWidth));
83 this._View.SrcChanged += View_SrcChanged;
84 this._View.InsertMode = this.InsertMode;
85 this.Document.DrawLineNumber = this.DrawLineNumber;
86 this._View.HideCaret = !this.DrawCaret;
87 this._View.HideLineMarker = !this.DrawCaretLine;
88 this.Document.HideRuler = !this.DrawRuler;
89 this.Document.UrlMark = this.MarkURL;
90 this.Document.TabStops = this.TabChars;
92 this._Controller = new Controller(this.Document, this._View);
94 this.gestureRecongnizer.GestureSettings = GestureSettings.Drag |
95 GestureSettings.RightTap |
97 GestureSettings.DoubleTap |
98 GestureSettings.ManipulationTranslateX |
99 GestureSettings.ManipulationTranslateY |
100 GestureSettings.ManipulationScale |
101 GestureSettings.ManipulationTranslateInertia |
102 GestureSettings.ManipulationScaleInertia;
103 this.gestureRecongnizer.RightTapped += gestureRecongnizer_RightTapped;
104 this.gestureRecongnizer.Tapped += gestureRecongnizer_Tapped;
105 this.gestureRecongnizer.Dragging += gestureRecongnizer_Dragging;
106 this.gestureRecongnizer.ManipulationInertiaStarting += GestureRecongnizer_ManipulationInertiaStarting; ;
107 this.gestureRecongnizer.ManipulationStarted += gestureRecongnizer_ManipulationStarted;
108 this.gestureRecongnizer.ManipulationUpdated += gestureRecongnizer_ManipulationUpdated;
109 this.gestureRecongnizer.ManipulationCompleted += gestureRecongnizer_ManipulationCompleted;
111 this.timer.Interval = new TimeSpan(0, 0, 0, 0, Interval);
112 this.timer.Tick += this.timer_Tick;
115 this.GettingFocus += FooTextBox_GettingFocus;
116 this.LosingFocus += FooTextBox_LosingFocus;
118 this.SizeChanged += FooTextBox_SizeChanged;
120 this.Loaded += FooTextBox_Loaded;
134 public void Dispose()
137 GC.SuppressFinalize(this);
140 bool Disposed = false;
141 private void Dispose(bool disposing)
147 this._View.Dispose();
148 this.Render.Dispose();
155 /// <param name="start">開始インデックス</param>
156 /// <param name="length">長さ</param>
157 public void Select(int start, int length)
159 this.Document.Select(start, length);
163 /// キャレットを指定した行に移動させます
165 /// <param name="index">インデックス</param>
166 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
167 public void JumpCaret(int index)
169 this._Controller.JumpCaret(index);
172 /// キャレットを指定した行と桁に移動させます
174 /// <param name="row">行番号</param>
175 /// <param name="col">桁</param>
176 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
177 public void JumpCaret(int row, int col)
179 this._Controller.JumpCaret(row, col);
183 /// 選択中のテキストをクリップボードにコピーします
187 string text = this._Controller.SelectedText;
188 if (text != null && text != string.Empty)
190 DataPackage dataPackage = new DataPackage();
191 dataPackage.RequestedOperation = DataPackageOperation.Copy;
192 dataPackage.SetText(text);
194 Clipboard.SetContent(dataPackage);
199 /// 選択中のテキストをクリップボードに切り取ります
203 string text = this._Controller.SelectedText;
204 if (text != null && text != string.Empty)
206 DataPackage dataPackage = new DataPackage();
207 dataPackage.RequestedOperation = DataPackageOperation.Copy;
208 dataPackage.SetText(text);
210 Clipboard.SetContent(dataPackage);
212 this._Controller.SelectedText = "";
219 public async Task PasteAsync()
221 var dataPackageView = Clipboard.GetContent();
222 if (dataPackageView.Contains(StandardDataFormats.Text))
226 this._Controller.SelectedText = await dataPackageView.GetTextAsync();
229 System.Diagnostics.Debug.WriteLine("past error:" + e.Message);
237 public void SelectAll()
239 this.Document.Select(0, this.Document.Length);
245 public void DeSelectAll()
247 this._Controller.DeSelectAll();
253 /// <param name="tp">テキストポイント</param>
254 /// <returns>座標</returns>
255 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
256 public Windows.Foundation.Point GetPostionFromTextPoint(TextPoint tp)
258 if (this.Document.FireUpdateEvent == false)
259 throw new InvalidOperationException("");
260 return this._View.GetPostionFromTextPoint(tp);
264 /// 対応するテキストポイントを返します
266 /// <param name="p">クライアント領域の原点を左上とする座標</param>
267 /// <returns>テキストポイント</returns>
268 public TextPoint GetTextPointFromPostion(Windows.Foundation.Point p)
270 if (this.Document.FireUpdateEvent == false)
271 throw new InvalidOperationException("");
272 return this._View.GetTextPointFromPostion(p);
278 /// <param name="row">レイアウト行</param>
279 /// <returns>行の高さ</returns>
280 public double GetLineHeight(int row)
282 if (this.Document.FireUpdateEvent == false)
283 throw new InvalidOperationException("");
284 return this._View.LayoutLines.GetLayout(row).Height; ;
288 /// インデックスに対応する座標を得ます
290 /// <param name="index">インデックス</param>
291 /// <returns>座標を返す</returns>
292 public Windows.Foundation.Point GetPostionFromIndex(int index)
294 if (this.Document.FireUpdateEvent == false)
295 throw new InvalidOperationException("");
296 TextPoint tp = this._View.GetLayoutLineFromIndex(index);
297 return this._View.GetPostionFromTextPoint(tp);
303 /// <param name="p">座標</param>
304 /// <returns>インデックスを返す</returns>
305 public int GetIndexFromPostion(Windows.Foundation.Point p)
307 if (this.Document.FireUpdateEvent == false)
308 throw new InvalidOperationException("");
309 TextPoint tp = this._View.GetTextPointFromPostion(p);
310 return this._View.GetIndexFromLayoutLine(tp);
317 public void Refresh(bool immidately=true)
320 this.Refresh(this._View.PageBound);
322 this.Document.RequestRedraw();
326 /// レイアウト行をすべて破棄し、再度レイアウトを行う
328 public void PerfomLayouts()
330 this.Document.PerformLayout();
336 /// <param name="row">行</param>
337 /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
338 public void ScrollIntoView(int row, bool alignTop)
340 this._View.ScrollIntoView(row, alignTop);
344 /// ファイルからドキュメントを構築する
346 /// <param name="sr">StremReader</param>
347 /// <returns>Taskオブジェクト</returns>
348 public async Task LoadFileAsync(System.IO.StreamReader sr, System.Threading.CancellationTokenSource token)
350 await this.Document.LoadAsync(sr, token);
353 private void Document_LoadProgress(object sender, ProgressEventArgs e)
355 if(e.state == ProgressState.Start)
357 this.IsEnabled = false;
359 else if(e.state == ProgressState.Complete)
361 CoreTextRange modified_range = new CoreTextRange();
362 modified_range.StartCaretPosition = 0;
363 modified_range.EndCaretPosition = 0;
364 //キャレット位置はロード前と同じにしないと違和感を感じる
365 if (this.textEditContext != null)
366 this.textEditContext.NotifyTextChanged(modified_range, this.Document.Length, modified_range);
368 if (this.verticalScrollBar != null)
369 this.verticalScrollBar.Maximum = this._View.LayoutLines.Count;
370 this.IsEnabled = true;
376 /// ドキュメントの内容をファイルに保存する
378 /// <param name="sw">StreamWriter</param>
379 /// <param name="enc">エンコード</param>
380 /// <returns>Taskオブジェクト</returns>
381 public async Task SaveFile(System.IO.StreamWriter sw, System.Threading.CancellationTokenSource token)
383 await this.Document.SaveAsync(sw, token);
398 async Task PasteCommand()
400 await this.PasteAsync();
410 protected override Windows.UI.Xaml.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
412 this.peer = new FooTextBoxAutomationPeer(this);
417 protected override void OnApplyTemplate()
419 base.OnApplyTemplate();
421 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
424 Grid.SetRow(this.rectangle, 0);
425 Grid.SetColumn(this.rectangle, 0);
426 grid.Children.Add(this.rectangle);
429 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
430 if (this.horizontalScrollBar != null)
432 this.horizontalScrollBar.SmallChange = 10;
433 this.horizontalScrollBar.LargeChange = 100;
434 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
435 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
437 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
438 if (this.verticalScrollBar != null)
440 this.verticalScrollBar.SmallChange = 1;
441 this.verticalScrollBar.LargeChange = 10;
442 this.verticalScrollBar.Maximum = this._View.LayoutLines.Count;
443 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
447 private void FooTextBox_LosingFocus(UIElement sender, LosingFocusEventArgs args)
449 this.RemoveTextContext();
451 if (this.textServiceManager != null)
453 this.textServiceManager.InputLanguageChanged -= TextServiceManager_InputLanguageChanged;
454 this.textServiceManager = null;
457 System.Diagnostics.Debug.WriteLine("losing focus");
460 private async void FooTextBox_GettingFocus(UIElement sender, GettingFocusEventArgs args)
462 System.Diagnostics.Debug.WriteLine("getting focus");
463 if (this.textServiceManager == null)
465 await Task.Delay(500);
466 this.textServiceManager = CoreTextServicesManager.GetForCurrentView();
467 this.textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;
470 this.CreateTextContext();
474 protected override void OnGotFocus(RoutedEventArgs e)
478 System.Diagnostics.Debug.WriteLine("got focus");
480 this._View.IsFocused = true;
481 this.timer.Interval = new TimeSpan(0, 0, 0, 0, Interval);
485 private void TextServiceManager_InputLanguageChanged(CoreTextServicesManager sender, object args)
487 System.Diagnostics.Debug.WriteLine("input language changed input script:"+ this.textServiceManager.InputLanguage.Script);
491 protected override void OnLostFocus(RoutedEventArgs e)
495 System.Diagnostics.Debug.WriteLine("lost focus");
497 this._View.IsFocused = false;
499 this.timer.Interval = new TimeSpan(0, 0, 0, 0, IntervalWhenLostFocus);
502 private void CreateTextContext()
504 if(this.textServiceManager != null)
506 this.textEditContext = this.textServiceManager.CreateEditContext();
507 this.textEditContext.InputScope = CoreTextInputScope.Text;
508 this.textEditContext.CompositionStarted += TextEditContext_CompositionStarted;
509 this.textEditContext.CompositionCompleted += TextEditContext_CompositionCompleted;
510 this.textEditContext.LayoutRequested += TextEditContext_LayoutRequested;
511 this.textEditContext.TextUpdating += TextEditContext_TextUpdating;
512 this.textEditContext.TextRequested += TextEditContext_TextRequested;
513 this.textEditContext.SelectionRequested += TextEditContext_SelectionRequested;
514 this.textEditContext.SelectionUpdating += TextEditContext_SelectionUpdating;
515 this.textEditContext.FormatUpdating += TextEditContext_FormatUpdating;
516 this.textEditContext.FocusRemoved += TextEditContext_FocusRemoved;
517 this.textEditContext.NotifyFocusLeaveCompleted += TextEditContext_NotifyFocusLeaveCompleted;
518 this.textEditContext.NotifyFocusEnter();
522 private void RemoveTextContext()
524 if(this.textEditContext != null)
526 this.textEditContext.NotifyFocusLeave();
527 this.textEditContext.CompositionStarted -= TextEditContext_CompositionStarted;
528 this.textEditContext.CompositionCompleted -= TextEditContext_CompositionCompleted;
529 this.textEditContext.LayoutRequested -= TextEditContext_LayoutRequested;
530 this.textEditContext.TextUpdating -= TextEditContext_TextUpdating;
531 this.textEditContext.TextRequested -= TextEditContext_TextRequested;
532 this.textEditContext.SelectionRequested -= TextEditContext_SelectionRequested;
533 this.textEditContext.SelectionUpdating -= TextEditContext_SelectionUpdating;
534 this.textEditContext.FormatUpdating -= TextEditContext_FormatUpdating;
535 this.textEditContext.FocusRemoved -= TextEditContext_FocusRemoved;
536 this.textEditContext.NotifyFocusLeaveCompleted -= TextEditContext_NotifyFocusLeaveCompleted;
537 this.textEditContext = null;
542 protected override async void OnKeyDown(KeyRoutedEventArgs e)
544 bool isControlPressed = this.IsModiferKeyPressed(VirtualKey.Control);
545 bool isShiftPressed = this.IsModiferKeyPressed(VirtualKey.Shift);
546 bool isMovedCaret = false;
548 var autocomplete = this.Document.AutoComplete as AutoCompleteBox;
549 if (autocomplete != null && autocomplete.ProcessKeyDown(this, e, isControlPressed, isShiftPressed))
555 this._Controller.MoveCaretVertical(-1, isShiftPressed);
560 case VirtualKey.Down:
561 this._Controller.MoveCaretVertical(+1, isShiftPressed);
566 case VirtualKey.Left:
567 this._Controller.MoveCaretHorizontical(-1, isShiftPressed, isControlPressed);
572 case VirtualKey.Right:
573 this._Controller.MoveCaretHorizontical(1, isShiftPressed, isControlPressed);
578 case VirtualKey.PageUp:
579 this._Controller.Scroll(ScrollDirection.Up, this._View.LineCountOnScreen, isShiftPressed, true);
583 case VirtualKey.PageDown:
584 this._Controller.Scroll(ScrollDirection.Down, this._View.LineCountOnScreen, isShiftPressed, true);
588 case VirtualKey.Home:
589 if (isControlPressed)
590 this._Controller.JumpToHead(isShiftPressed);
592 this.Controller.JumpToLineHead(this.Document.CaretPostion.row,isShiftPressed);
597 if (isControlPressed)
598 this._Controller.JumpToEnd(isShiftPressed);
600 this.Controller.JumpToLineEnd(this.Document.CaretPostion.row,isShiftPressed);
605 if (!isControlPressed)
607 if (this._Controller.SelectionLength == 0)
608 this._Controller.DoInputChar('\t');
609 else if (isShiftPressed)
610 this._Controller.DownIndent();
612 this._Controller.UpIndent();
617 case VirtualKey.Enter:
618 this._Controller.DoEnterAction();
622 case VirtualKey.Insert:
623 if(this._View.InsertMode)
624 this._View.InsertMode = false;
626 this._View.InsertMode = true;
631 if (isControlPressed)
639 if (isControlPressed)
641 if (this._Controller.RectSelection)
642 this._Controller.RectSelection = false;
644 this._Controller.RectSelection = true;
650 if (isControlPressed)
657 if (isControlPressed)
664 if (isControlPressed)
666 await this.PasteCommand();
671 if (isControlPressed)
673 this.Document.UndoManager.redo();
679 if (isControlPressed)
681 this.Document.UndoManager.undo();
686 case VirtualKey.Back:
687 this._Controller.DoBackSpaceAction();
691 case VirtualKey.Delete:
692 this._Controller.DoDeleteAction();
701 protected override void OnPointerPressed(PointerRoutedEventArgs e)
703 System.Diagnostics.Debug.WriteLine("pointer pressed");
704 this.CapturePointer(e.Pointer);
705 this.gestureRecongnizer.ProcessDownEvent(e.GetCurrentPoint(this));
710 protected override void OnPointerMoved(PointerRoutedEventArgs e)
712 System.Diagnostics.Debug.WriteLine("pointer moved");
715 this.gestureRecongnizer.ProcessMoveEvents(e.GetIntermediatePoints(this));
716 }catch(System.Runtime.InteropServices.COMException ex)
718 //ピンチズームでこの例外が発生するが、回避できない
719 System.Diagnostics.Debug.WriteLine("expection:" + ex);
723 if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
725 Point p = e.GetCurrentPoint(this).Position;
726 if (this._View.HitTextArea(p.X, p.Y))
728 TextPoint tp = this._View.GetTextPointFromPostion(p);
729 if (this._Controller.IsMarker(tp, HilightType.Url))
730 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Hand, 101);
732 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.IBeam, 101);
736 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 101);
742 protected override void OnPointerReleased(PointerRoutedEventArgs e)
744 System.Diagnostics.Debug.WriteLine("pointer released");
745 this.gestureRecongnizer.ProcessUpEvent(e.GetCurrentPoint(this));
750 protected override void OnPointerCanceled(PointerRoutedEventArgs e)
752 System.Diagnostics.Debug.WriteLine("pointer canceled");
753 this.gestureRecongnizer.CompleteGesture();
758 protected override void OnPointerWheelChanged(PointerRoutedEventArgs e)
760 System.Diagnostics.Debug.WriteLine("pointer wheelchanged");
761 bool shift = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Shift) ==
762 Windows.System.VirtualKeyModifiers.Shift;
763 bool ctrl = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Control) ==
764 Windows.System.VirtualKeyModifiers.Control;
765 this.gestureRecongnizer.ProcessMouseWheelEvent(e.GetCurrentPoint(this), shift, ctrl);
769 private void TextEditContext_FormatUpdating(CoreTextEditContext sender, CoreTextFormatUpdatingEventArgs args)
771 if (this.Document.Length == 0 || args.IsCanceled)
773 args.Result = CoreTextFormatUpdatingResult.Failed;
776 System.Diagnostics.Debug.WriteLine("core text format updating range({0}-{1}) underline type:{2} underline color:{3} reason:{4} textcolor:{5} background:{6}",
777 args.Range.StartCaretPosition,
778 args.Range.EndCaretPosition,
785 HilightType type = HilightType.None;
786 Color color = new Color(this.Foreground.A,this.Foreground.R,this.Foreground.G,this.Foreground.R);
787 bool isBoldLine = false;
788 switch (args.UnderlineType)
790 case UnderlineType.Dotted:
791 type = HilightType.Dot;
793 case UnderlineType.Single:
794 type = HilightType.Sold;
796 case UnderlineType.Dash:
797 type = HilightType.Dash;
799 case UnderlineType.Wave:
800 type = HilightType.Squiggle;
802 case UnderlineType.Thin:
803 type = HilightType.Sold;
805 case UnderlineType.Thick:
806 type = HilightType.Sold;
810 int start = args.Range.StartCaretPosition;
811 int lengt = args.Range.EndCaretPosition - args.Range.StartCaretPosition;
812 this.Document.SetMarker(MarkerIDs.IME, Marker.Create(start, lengt, type, color, isBoldLine));
814 if (args.Reason == CoreTextFormatUpdatingReason.CompositionTargetConverted)
816 this._View.AdjustSrc(args.Range.StartCaretPosition);
820 args.Result = CoreTextFormatUpdatingResult.Succeeded;
823 private void TextEditContext_TextRequested(CoreTextEditContext sender, CoreTextTextRequestedEventArgs args)
825 CoreTextTextRequest req = args.Request;
827 if (this.Document.Length == 0 || req.IsCanceled)
832 int start = req.Range.StartCaretPosition;
833 int end = req.Range.EndCaretPosition;
834 if (end > this.Document.Length)
835 end = this.Document.Length;
837 int length = end - start;
839 System.Diagnostics.Debug.WriteLine("req text start:{0} length:{1}", start, length);
841 //キャレット位置も含むので+1する必要はない
842 req.Text = this.Document.ToString(start,length);
845 private void TextEditContext_LayoutRequested(CoreTextEditContext sender, CoreTextLayoutRequestedEventArgs args)
848 Point startPos, endPos;
849 int i_startIndex = args.Request.Range.StartCaretPosition;
850 int i_endIndex = args.Request.Range.EndCaretPosition;
852 if(args.Request.IsCanceled)
857 System.Diagnostics.Debug.WriteLine("core text layoutreq range({0}-{1})",i_startIndex,i_endIndex);
859 if (i_startIndex != -1 && i_endIndex != -1)
861 TextStoreHelper.GetStringExtent(this.Document, this._View, i_startIndex, i_endIndex, out startPos, out endPos);
863 double scale = Util.GetScale();
865 //Core.Textはスクリーン座標に変換してくれないので自前で変換する(しかも、デバイス依存の座標で返さないといけない)
866 var screenStartPos = Util.GetScreentPoint(startPos, this).Scale(scale);
867 var screenEndPos = Util.GetScreentPoint(endPos, this).Scale(scale);
868 args.Request.LayoutBounds.TextBounds = new Rect(
871 Math.Max(0,screenEndPos.X - screenStartPos.X), //折り返されている場合、負になることがある
872 screenEndPos.Y - screenStartPos.Y);
876 var controlTopLeft = new Point(0, 0);
877 var controlBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
879 var gt = this.TransformToVisual(Window.Current.Content);
880 controlTopLeft = gt.TransformPoint(controlTopLeft);
881 controlBottomRight = gt.TransformPoint(controlBottomRight);
883 args.Request.LayoutBounds.ControlBounds = new Rect(
886 controlBottomRight.X - controlTopLeft.X,
887 controlBottomRight.Y - controlTopLeft.Y
891 private void TextEditContext_SelectionRequested(CoreTextEditContext sender, CoreTextSelectionRequestedEventArgs args)
893 if(args.Request.IsCanceled || this.Document.Length == 0)
897 TextRange currentSelection = new TextRange();
898 TextStoreHelper.GetSelection(this._Controller, this._View.Selections, out currentSelection);
900 CoreTextRange currentSelectionRange = new CoreTextRange();
901 currentSelectionRange.StartCaretPosition = currentSelection.Index;
902 currentSelectionRange.EndCaretPosition = currentSelection.Index + currentSelection.Length;
903 args.Request.Selection = currentSelectionRange;
904 System.Diagnostics.Debug.WriteLine("req selection start:{0} end:{1}", currentSelectionRange.StartCaretPosition, currentSelectionRange.EndCaretPosition);
907 private void TextEditContext_SelectionUpdating(CoreTextEditContext sender, CoreTextSelectionUpdatingEventArgs args)
909 if(this.Document.Length == 0 || args.IsCanceled)
911 args.Result = CoreTextSelectionUpdatingResult.Failed;
914 CoreTextRange sel = args.Selection;
915 System.Diagnostics.Debug.WriteLine("update selection start:{0} end:{1}", sel.StartCaretPosition, sel.EndCaretPosition);
916 TextStoreHelper.SetSelectionIndex(this.Controller, this._View, sel.StartCaretPosition, sel.EndCaretPosition);
917 args.Result = CoreTextSelectionUpdatingResult.Succeeded;
921 private void TextEditContext_TextUpdating(CoreTextEditContext sender, CoreTextTextUpdatingEventArgs args)
923 this.nowCompstion = true;
925 System.Diagnostics.Debug.WriteLine("update text (modify start:{0} end:{1}) text:{2} (new sel start:{0} end:{1})",
926 args.Range.StartCaretPosition,
927 args.Range.EndCaretPosition,
929 args.NewSelection.StartCaretPosition,
930 args.NewSelection.EndCaretPosition);
931 bool isTip = args.InputLanguage.Script == "Latan";
932 CoreTextRange sel = args.Range;
933 TextStoreHelper.SetSelectionIndex(this.Controller, this._View, sel.StartCaretPosition, sel.EndCaretPosition);
934 TextStoreHelper.InsertTextAtSelection(this._Controller, args.Text, isTip);
936 args.Result = CoreTextTextUpdatingResult.Succeeded;
938 this.nowCompstion = false;
941 private void TextEditContext_CompositionCompleted(CoreTextEditContext sender, CoreTextCompositionCompletedEventArgs args)
943 System.Diagnostics.Debug.WriteLine("end compostion");
944 TextStoreHelper.EndCompostion(this.Document);
945 this.Document.RemoveAllMarker(MarkerIDs.IME);
949 private void TextEditContext_CompositionStarted(CoreTextEditContext sender, CoreTextCompositionStartedEventArgs args)
951 System.Diagnostics.Debug.WriteLine("start compstion");
952 TextStoreHelper.StartCompstion(this.Document);
955 private void TextEditContext_NotifyFocusLeaveCompleted(CoreTextEditContext sender, object args)
957 System.Diagnostics.Debug.WriteLine("notify focus leaved");
960 private void TextEditContext_FocusRemoved(CoreTextEditContext sender, object args)
962 System.Diagnostics.Debug.WriteLine("focus leaved");
965 void Controller_SelectionChanged(object sender, EventArgs e)
967 if (this._Controller == null)
971 this.nowCaretMove = true;
972 SetValue(SelectedTextProperty, this._Controller.SelectedText);
973 SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
974 SetValue(CaretPostionPropertyKey, this.Document.CaretPostion);
975 this.nowCaretMove = false;
977 if(!this.nowCompstion)
979 TextRange currentSelection = new TextRange();
980 TextStoreHelper.GetSelection(this._Controller, this._View.Selections, out currentSelection);
982 CoreTextRange currentSelectionRange = new CoreTextRange();
983 currentSelectionRange.StartCaretPosition = currentSelection.Index;
984 currentSelectionRange.EndCaretPosition = currentSelection.Index + currentSelection.Length;
986 System.Diagnostics.Debug.WriteLine("notify selection start:{0} end:{1}", currentSelectionRange.StartCaretPosition, currentSelectionRange.EndCaretPosition);
988 if (this.textEditContext != null)
989 this.textEditContext.NotifySelectionChanged(currentSelectionRange);
992 if (this.peer != null)
993 this.peer.OnNotifyCaretChanged();
997 Gripper hittedGripper;
998 void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)
1000 //Updateedの段階でヒットテストしてしまうとグリッパーを触ってもヒットしないことがある
1001 this.hittedGripper = this._View.HitGripperFromPoint(e.Position);
1004 private void GestureRecongnizer_ManipulationInertiaStarting(GestureRecognizer sender, ManipulationInertiaStartingEventArgs args)
1006 //sender.InertiaTranslationDeceleration = 0.001f;
1007 //sender.InertiaExpansionDeceleration = 100.0f * 96.0f / 1000.0f;
1008 //sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
1011 void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
1013 if (e.Delta.Scale < 1)
1015 double newSize = this.Render.FontSize - 1;
1018 this.Render.FontSize = newSize;
1020 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
1024 if (e.Delta.Scale > 1)
1026 double newSize = this.Render.FontSize + 1;
1029 this.Render.FontSize = newSize;
1031 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
1035 if (this._Controller.MoveCaretAndGripper(e.Position, this.hittedGripper))
1041 Point translation = e.Delta.Translation;
1043 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
1044 if (Math.Abs(e.Cumulative.Translation.X) < Math.Abs(e.Cumulative.Translation.Y))
1046 int deltay = (int)Math.Abs(Math.Ceiling(translation.Y));
1047 if (translation.Y < 0)
1048 this._Controller.ScrollByPixel(ScrollDirection.Down, deltay, false, false);
1050 this._Controller.ScrollByPixel(ScrollDirection.Up, deltay, false, false);
1055 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
1058 if (translation.X < 0)
1059 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
1061 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
1066 void gestureRecongnizer_ManipulationCompleted(GestureRecognizer sender, ManipulationCompletedEventArgs e)
1070 async void gestureRecongnizer_RightTapped(GestureRecognizer sender, RightTappedEventArgs e)
1072 ResourceMap map = ResourceManager.Current.MainResourceMap.GetSubtree("FooEditEngine.UWP/Resources");
1073 ResourceContext context = ResourceContext.GetForCurrentView();
1074 if (this._View.HitTextArea(e.Position.X, e.Position.Y))
1076 FooContextMenuEventArgs args = new FooContextMenuEventArgs(e.Position);
1077 if (this.ContextMenuOpening != null)
1078 this.ContextMenuOpening(this, args);
1081 PopupMenu ContextMenu = new PopupMenu();
1082 ContextMenu.Commands.Add(new UICommand(map.GetValue("CopyMenuName", context).ValueAsString, (command) =>
1086 ContextMenu.Commands.Add(new UICommand(map.GetValue("CutMenuName", context).ValueAsString, (command) =>
1090 ContextMenu.Commands.Add(new UICommand(map.GetValue("PasteMenuName", context).ValueAsString, async (command) =>
1092 await this.PasteCommand();
1094 if (this._Controller.RectSelection)
1096 ContextMenu.Commands.Add(new UICommand(map.GetValue("LineSelectMenuName", context).ValueAsString, (command) =>
1098 this._Controller.RectSelection = false;
1103 ContextMenu.Commands.Add(new UICommand(map.GetValue("RectSelectMenuName", context).ValueAsString, (command) =>
1105 this._Controller.RectSelection = true;
1108 var windowStartPos = Util.GetPointInWindow(e.Position, this);
1109 await ContextMenu.ShowAsync(windowStartPos);
1114 long lastDouleTapTick;
1115 const long allowTripleTapTimeSpan = 500;
1116 void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)
1118 bool touched = e.PointerDeviceType == PointerDeviceType.Touch;
1119 this.Document.SelectGrippers.BottomLeft.Enabled = false;
1120 this.Document.SelectGrippers.BottomRight.Enabled = touched;
1121 this.JumpCaret(e.Position);
1122 if(e.TapCount == 1 && System.DateTime.Now.Ticks - lastDouleTapTick < allowTripleTapTimeSpan * 10000) //トリプルタップ
1124 //タッチスクリーンで行選択した場合、アンカーインデックスを単語の先頭にしないとバグる
1125 this.Document.SelectGrippers.BottomLeft.Enabled = touched;
1126 this.Document.SelectLine(this.Controller.SelectionStart, touched);
1129 else if(e.TapCount == 2) //ダブルタップ
1131 //タッチスクリーンで単語選択した場合、アンカーインデックスを単語の先頭にしないとバグる
1132 this.Document.SelectGrippers.BottomLeft.Enabled = touched;
1133 if (e.Position.X < this.Render.TextArea.X)
1134 this.Document.SelectLine(this.Controller.SelectionStart, touched);
1136 this.Document.SelectWord(this.Controller.SelectionStart, touched);
1137 this.lastDouleTapTick = System.DateTime.Now.Ticks;
1142 void JumpCaret(Point p)
1144 TextPoint tp = this._View.GetTextPointFromPostion(p);
1145 if (tp == TextPoint.Null)
1148 int index = this._View.LayoutLines.GetIndexFromTextPoint(tp);
1150 FoldingItem foldingData = this._View.HitFoldingData(p.X, tp.row);
1151 if (foldingData != null)
1153 if (foldingData.Expand)
1154 this._View.LayoutLines.FoldingCollection.Collapse(foldingData);
1156 this._View.LayoutLines.FoldingCollection.Expand(foldingData);
1157 this._Controller.JumpCaret(foldingData.Start, false);
1161 this._Controller.JumpCaret(tp.row, tp.col, false);
1163 this._View.IsFocused = true;
1164 this.Focus(FocusState.Programmatic);
1168 void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)
1170 Point p = e.Position;
1171 TextPointSearchRange searchRange;
1172 if (this._View.HitTextArea(p.X, p.Y))
1173 searchRange = TextPointSearchRange.TextAreaOnly;
1174 else if (this._Controller.SelectionLength > 0)
1175 searchRange = TextPointSearchRange.Full;
1178 TextPoint tp = this._View.GetTextPointFromPostion(p, searchRange);
1179 this._Controller.MoveCaretAndSelect(tp, this.IsModiferKeyPressed(VirtualKey.LeftControl));
1183 bool IsModiferKeyPressed(VirtualKey key)
1185 CoreVirtualKeyStates state = Window.Current.CoreWindow.GetKeyState(key);
1186 return (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
1188 void Refresh(Rectangle updateRect)
1190 if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0 || this.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
1193 this.Render.DrawContent(this._View, this.IsEnabled, updateRect);
1195 this.Document.IsRequestRedraw = false;
1199 bool Resize(double width, double height)
1201 if (width == 0 || height == 0)
1202 throw new ArgumentOutOfRangeException();
1203 if (this.Render.Resize(this.rectangle, width, height))
1205 this._View.PageBound = new Rectangle(0, 0, width, height);
1207 if (this.horizontalScrollBar != null)
1209 this.horizontalScrollBar.LargeChange = this._View.PageBound.Width;
1210 this.horizontalScrollBar.Maximum = this._View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1212 if (this.verticalScrollBar != null)
1214 this.verticalScrollBar.LargeChange = this._View.LineCountOnScreen;
1215 this.verticalScrollBar.Maximum = this._View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1222 void View_SrcChanged(object sender, EventArgs e)
1224 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1226 EditView view = this._View;
1227 if (view.Src.Row > this.verticalScrollBar.Maximum)
1228 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
1229 double absoulteX = Math.Abs(view.Src.X);
1230 if (absoulteX > this.horizontalScrollBar.Maximum)
1231 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1232 if (view.Src.Row != this.verticalScrollBar.Value)
1233 this.verticalScrollBar.Value = view.Src.Row;
1234 if (view.Src.X != this.horizontalScrollBar.Value)
1235 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1238 void FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)
1240 //LostFocusやGotFocusなどと競合するとDirect2Dでエラーが起きるので、timer_tickイベントでサイズ変更を行うことにした
1241 this.requestSizeChange = true;
1244 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1246 if (this.horizontalScrollBar == null)
1249 if (this.FlowDirection == FlowDirection.LeftToRight)
1250 toX = this.horizontalScrollBar.Value;
1252 toX = -this.horizontalScrollBar.Value;
1253 this._Controller.Scroll(toX, this._View.Src.Row, false, false);
1257 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1259 if (this.verticalScrollBar == null)
1261 int newRow = (int)this.verticalScrollBar.Value;
1262 if (newRow >= this._View.LayoutLines.Count)
1264 this._Controller.Scroll(this._View.Src.X, newRow, false, false);
1268 void Document_Update(object sender, DocumentUpdateEventArgs e)
1270 if (e.type == UpdateType.Replace && !this.nowCompstion)
1272 CoreTextRange oldTextRange = new CoreTextRange();
1273 oldTextRange.StartCaretPosition = e.startIndex;
1274 oldTextRange.EndCaretPosition = e.startIndex;
1275 //削除する範囲が1以上の場合、ドキュメントを飛び越えることはできない
1276 //https://msdn.microsoft.com/en-us/windows/uwp/input-and-devices/custom-text-input
1277 if (e.removeLength > 0)
1278 oldTextRange.EndCaretPosition += e.removeLength;
1280 TextRange currentSelection = new TextRange();
1281 TextStoreHelper.GetSelection(this._Controller, this._View.Selections, out currentSelection);
1283 CoreTextRange newSelection = new CoreTextRange();
1284 newSelection.StartCaretPosition = e.startIndex;
1285 newSelection.EndCaretPosition = e.startIndex;
1288 //(注意:削除された文字数のほうが多い場合は0を指定しないいけない)
1289 int newTextLength = e.insertLength;
1291 System.Diagnostics.Debug.WriteLine("notify text change (modify start:{0} end:{1}) newlength:{2} (new sel start:{3} end:{4})",
1292 oldTextRange.StartCaretPosition, oldTextRange.EndCaretPosition, newTextLength, newSelection.StartCaretPosition, newSelection.EndCaretPosition);
1294 if(this.textEditContext != null)
1295 this.textEditContext.NotifyTextChanged(oldTextRange, newTextLength, newSelection);
1297 #if ENABLE_AUTMATION
1298 if (this.peer != null)
1299 this.peer.OnNotifyTextChanged();
1303 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1305 this.Focus(FocusState.Programmatic);
1308 void timer_Tick(object sender, object e)
1311 if(this.requestSizeChange)
1313 if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))
1316 this.Refresh(this._View.PageBound);
1318 this.requestSizeChange = false;
1320 else if (this._View.LayoutLines.HilightAll() || this._View.LayoutLines.GenerateFolding() || this.Document.IsRequestRedraw)
1322 this.Refresh(this._View.PageBound);
1327 private void SetDocument(Document value)
1332 Document old_doc = this._Document;
1334 if (this._Document != null)
1336 old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
1337 this._Document.SelectionChanged -= Controller_SelectionChanged;
1338 this._Document.LoadProgress -= Document_LoadProgress;
1339 this._Document.AutoCompleteChanged -= _Document_AutoCompleteChanged;
1340 if (this._Document.AutoComplete != null)
1342 this._Document.AutoComplete.GetPostion = null;
1343 this._Document.AutoComplete = null;
1346 //NotifyTextChanged()を呼び出すと落ちるのでTextConextをごっそり作り替える
1347 this.RemoveTextContext();
1350 System.Diagnostics.Debug.WriteLine("document switched");
1352 this._Document = value;
1353 this._Document.LayoutLines.Render = this.Render;
1354 this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
1355 this._Document.LoadProgress += Document_LoadProgress;
1356 this._Document.AutoCompleteChanged += _Document_AutoCompleteChanged;
1357 if (this._Document.AutoComplete != null && this._Document.AutoComplete.GetPostion == null)
1358 this._Document_AutoCompleteChanged(this._Document, null);
1359 //初期化が終わっていればすべて存在する
1360 if (this.Controller != null && this._View != null)
1362 this.Controller.Document = value;
1363 this._View.Document = value;
1365 this.Controller.AdjustCaret();
1367 this.CreateTextContext();
1369 //依存プロパティとドキュメント内容が食い違っているので再設定する
1370 this.ShowFullSpace = value.ShowFullSpace;
1371 this.ShowHalfSpace = value.ShowHalfSpace;
1372 this.ShowLineBreak = value.ShowLineBreak;
1373 this.ShowTab = value.ShowTab;
1374 this.FlowDirection = value.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
1375 this.IndentMode = value.IndentMode;
1376 this.DrawCaretLine = !value.HideLineMarker;
1377 this.InsertMode = value.InsertMode;
1378 this.DrawRuler = !value.HideRuler;
1379 this.DrawLineNumber = value.DrawLineNumber;
1380 this.MarkURL = value.UrlMark;
1381 this.LineBreakMethod = value.LineBreak;
1382 this.LineBreakCharCount = value.LineBreakCharCount;
1383 this.TabChars = value.TabStops;
1387 //TextEditContext作成後に設定しないと落ちることがある
1388 this._Document.SelectionChanged += Controller_SelectionChanged;
1391 private void _Document_AutoCompleteChanged(object sender, EventArgs e)
1393 Document doc = (Document)sender;
1394 doc.AutoComplete.GetPostion = (tp, e_doc) =>
1396 var p = this._View.GetPostionFromTextPoint(tp);
1397 int height = (int)e_doc.LayoutLines.GetLayout(e_doc.CaretPostion.row).Height;
1399 if (p.Y + AutoCompleteBox.CompleteListBoxHeight + height > e_doc.LayoutLines.Render.TextArea.Height)
1400 p.Y -= AutoCompleteBox.CompleteListBoxHeight;
1403 //AutoCompleteBox内ではCanvasで位置を指定しているので変換する必要がある
1404 var pointInWindow = Util.GetPointInWindow(p, this);
1405 return pointInWindow;
1410 public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
1412 FooTextBox source = (FooTextBox)sender;
1413 if(e.Property.Equals(SelectedTextProperty) && !source.nowCaretMove)
1414 source._Controller.SelectedText = source.SelectedText;
1415 if (e.Property.Equals(DocumentProperty))
1416 source.SetDocument(source.Document);
1417 if(e.Property.Equals(HilighterProperty))
1418 source._View.Hilighter = source.Hilighter;
1419 if (e.Property.Equals(FoldingStrategyProperty))
1420 source._View.LayoutLines.FoldingStrategy = source.FoldingStrategy;
1421 if (e.Property.Equals(IndentModeProperty))
1422 source.Controller.IndentMode = source.IndentMode;
1423 if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)
1424 source.Document.Select(source.Selection.Index,source.Selection.Length);
1425 if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)
1426 source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col);
1427 if (e.Property.Equals(InsertModeProperty))
1428 source._View.InsertMode = source.InsertMode;
1429 if (e.Property.Equals(TabCharsProperty))
1430 source.Document.TabStops = source.TabChars;
1431 if (e.Property.Equals(RectSelectModeProperty))
1432 source._Controller.RectSelection = source.RectSelectMode;
1433 if (e.Property.Equals(DrawCaretProperty))
1434 source._View.HideCaret = !source.DrawCaret;
1435 if (e.Property.Equals(DrawCaretLineProperty))
1436 source._View.HideLineMarker = !source.DrawCaretLine;
1437 if (e.Property.Equals(DrawLineNumberProperty))
1438 source.Document.DrawLineNumber = source.DrawLineNumber;
1439 if (e.Property.Equals(MarkURLProperty))
1440 source.Document.UrlMark = source.MarkURL;
1441 if (e.Property.Equals(LineBreakProperty))
1442 source.Document.LineBreak = source.LineBreakMethod;
1443 if (e.Property.Equals(LineBreakCharCountProperty))
1444 source.Document.LineBreakCharCount = source.LineBreakCharCount;
1445 if (e.Property.Equals(FlowDirectionProperty))
1447 source.Document.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;
1448 if (source.horizontalScrollBar != null)
1449 source.horizontalScrollBar.FlowDirection = source.FlowDirection;
1451 if (e.Property.Equals(DrawRulerProperty))
1453 source.Document.HideRuler = !source.DrawRuler;
1454 source._Controller.JumpCaret(source.Document.CaretPostion.row, source.Document.CaretPostion.col);
1457 if (e.Property.Equals(TextAntialiasModeProperty))
1458 source.Render.TextAntialiasMode = source.TextAntialiasMode;
1459 if(e.Property.Equals(MagnificationPowerPropertyKey))
1460 source.Render.FontSize = source.FontSize * source.MagnificationPower;
1461 if (e.Property.Equals(FontFamilyProperty))
1462 source.Render.FontFamily = source.FontFamily;
1463 if (e.Property.Equals(FontStyleProperty))
1464 source.Render.FontStyle = source.FontStyle;
1465 if (e.Property.Equals(FontWeightProperty))
1466 source.Render.FontWeigth = source.FontWeight;
1467 if (e.Property.Equals(FontSizeProperty))
1468 source.Render.FontSize = source.FontSize;
1469 if (e.Property.Equals(ForegroundProperty))
1470 source.Render.Foreground = D2DRenderBase.ToColor4(source.Foreground);
1471 if (e.Property.Equals(HilightForegroundProperty))
1472 source.Render.HilightForeground = D2DRenderBase.ToColor4(source.HilightForeground);
1473 if (e.Property.Equals(BackgroundProperty))
1474 source.Render.Background = D2DRenderBase.ToColor4(source.Background);
1475 if (e.Property.Equals(ControlCharProperty))
1476 source.Render.ControlChar = D2DRenderBase.ToColor4(source.ControlChar);
1477 if (e.Property.Equals(HilightProperty))
1478 source.Render.Hilight = D2DRenderBase.ToColor4(source.Hilight);
1479 if (e.Property.Equals(Keyword1Property))
1480 source.Render.Keyword1 = D2DRenderBase.ToColor4(source.Keyword1);
1481 if (e.Property.Equals(Keyword2Property))
1482 source.Render.Keyword2 = D2DRenderBase.ToColor4(source.Keyword2);
1483 if (e.Property.Equals(CommentProperty))
1484 source.Render.Comment = D2DRenderBase.ToColor4(source.Comment);
1485 if (e.Property.Equals(LiteralProperty))
1486 source.Render.Literal = D2DRenderBase.ToColor4(source.Literal);
1487 if (e.Property.Equals(URLProperty))
1488 source.Render.Url = D2DRenderBase.ToColor4(source.URL);
1489 if (e.Property.Equals(InsertCaretProperty))
1490 source.Render.InsertCaret = D2DRenderBase.ToColor4(source.InsertCaret);
1491 if (e.Property.Equals(OverwriteCaretProperty))
1492 source.Render.OverwriteCaret = D2DRenderBase.ToColor4(source.OverwriteCaret);
1493 if (e.Property.Equals(PaddingProperty))
1494 source._View.Padding = new Padding((int)source.Padding.Left, (int)source.Padding.Top, (int)source.Padding.Right, (int)source.Padding.Bottom);
1495 if (e.Property.Equals(LineMarkerProperty))
1496 source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);
1497 if (e.Property.Equals(ShowFullSpaceProperty))
1498 source.Render.ShowFullSpace = source.ShowFullSpace;
1499 if (e.Property.Equals(ShowHalfSpaceProperty))
1500 source.Render.ShowHalfSpace = source.ShowHalfSpace;
1501 if (e.Property.Equals(ShowTabProperty))
1502 source.Render.ShowTab = source.ShowTab;
1503 if (e.Property.Equals(ShowLineBreakProperty))
1504 source.Render.ShowLineBreak = source.ShowLineBreak;
1505 if (e.Property.Equals(UpdateAreaProperty))
1506 source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);
1507 if (e.Property.Equals(LineNumberProperty))
1508 source.Render.LineNumber = D2DRenderBase.ToColor4(source.LineNumber);
1516 /// コンテキストメニューが表示されるときに呼び出されます
1518 public event EventHandler<FooContextMenuEventArgs> ContextMenuOpening;
1524 internal Controller Controller
1528 return this._Controller;
1532 internal EditView View
1541 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1543 public TextAntialiasMode TextAntialiasMode
1545 get { return (TextAntialiasMode)GetValue(TextAntialiasModeProperty); }
1546 set { SetValue(TextAntialiasModeProperty, value); }
1550 /// TextAntialiasModeの依存プロパティを表す
1552 public static readonly DependencyProperty TextAntialiasModeProperty =
1553 DependencyProperty.Register("TextAntialiasMode", typeof(TextAntialiasMode), typeof(FooTextBox), new PropertyMetadata(TextAntialiasMode.Default, OnPropertyChanged));
1558 public IHilighter Hilighter
1560 get { return (IHilighter)GetValue(HilighterProperty); }
1561 set { SetValue(HilighterProperty, value); }
1565 /// Hilighterの依存プロパティを表す
1567 public static readonly DependencyProperty HilighterProperty =
1568 DependencyProperty.Register("Hilighter", typeof(IHilighter), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
1571 /// フォールティングを作成するインターフェイスを表す
1573 public IFoldingStrategy FoldingStrategy
1575 get { return (IFoldingStrategy)GetValue(FoldingStrategyProperty); }
1576 set { SetValue(FoldingStrategyProperty, value); }
1580 /// FoldingStrategyの依存プロパティ
1582 public static readonly DependencyProperty FoldingStrategyProperty =
1583 DependencyProperty.Register("FoldingStrategy", typeof(IFoldingStrategy), typeof(FooTextBox), new PropertyMetadata(null,OnPropertyChanged));
1588 public MarkerPatternSet MarkerPatternSet
1592 return this.Document.MarkerPatternSet;
1599 /// <remarks>切り替え後に再描写が行われます</remarks>
1600 public Document Document
1602 get { return (Document)GetValue(DocumentProperty); }
1603 set { SetValue(DocumentProperty, value); }
1606 // Using a DependencyProperty as the backing store for Document. This enables animation, styling, binding, etc...
1607 public static readonly DependencyProperty DocumentProperty =
1608 DependencyProperty.Register("Document", typeof(Document), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
1615 public LineToIndexTable LayoutLineCollection
1617 get { return this._View.LayoutLines; }
1623 public string SelectedText
1625 get { return (string)GetValue(SelectedTextProperty); }
1626 set { SetValue(SelectedTextProperty, value); }
1630 /// SelectedTextの依存プロパティを表す
1632 public static readonly DependencyProperty SelectedTextProperty =
1633 DependencyProperty.Register("SelectedText", typeof(string), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
1638 public IndentMode IndentMode
1640 get { return (IndentMode)GetValue(IndentModeProperty); }
1641 set { SetValue(IndentModeProperty, value); }
1645 /// IndentModeの依存プロパティを表す
1647 public static readonly DependencyProperty IndentModeProperty =
1648 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab,OnPropertyChanged));
1654 /// Lengthが0の場合はキャレット位置を表します。
1655 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1657 public TextRange Selection
1659 get { return (TextRange)GetValue(SelectionProperty); }
1660 set { SetValue(SelectionProperty, value); }
1664 /// Selectionの依存プロパティを表す
1666 public static readonly DependencyProperty SelectionProperty =
1667 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null, OnPropertyChanged));
1672 public double MagnificationPower
1674 get { return (double)GetValue(MagnificationPowerPropertyKey); }
1675 set { SetValue(MagnificationPowerPropertyKey, value); }
1681 public static readonly DependencyProperty MagnificationPowerPropertyKey =
1682 DependencyProperty.Register("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0, OnPropertyChanged));
1687 public TextPoint CaretPostion
1689 get { return (TextPoint)GetValue(CaretPostionPropertyKey); }
1690 set { SetValue(CaretPostionPropertyKey, value); }
1693 static readonly DependencyProperty CaretPostionPropertyKey =
1694 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(new TextPoint(), OnPropertyChanged));
1699 public new FlowDirection FlowDirection
1701 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1702 set { SetValue(FlowDirectionProperty, value); }
1706 /// レタリング方向を表す。これは依存プロパティです
1708 public new static readonly DependencyProperty FlowDirectionProperty =
1709 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight,OnPropertyChanged));
1714 public new FontFamily FontFamily
1716 get { return (FontFamily)GetValue(FontFamilyProperty); }
1717 set { SetValue(FontFamilyProperty, value); }
1721 /// FontFamilyの依存プロパティを表す
1723 public new static readonly DependencyProperty FontFamilyProperty =
1724 DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(FooTextBox), new PropertyMetadata(new FontFamily("Cambria"), OnPropertyChanged));
1729 public new double FontSize
1731 get { return (double)GetValue(FontSizeProperty); }
1732 set { SetValue(FontSizeProperty, value); }
1736 /// FontSizeの依存プロパティを表す
1738 public new static readonly DependencyProperty FontSizeProperty =
1739 DependencyProperty.Register("FontSize", typeof(double), typeof(FooTextBox), new PropertyMetadata(12.0,OnPropertyChanged));
1744 public new FontStyle FontStyle
1746 get { return (FontStyle)GetValue(FontStyleProperty); }
1747 set { SetValue(FontStyleProperty, value); }
1751 /// FontStyleの依存プロパティを表す
1753 public new static readonly DependencyProperty FontStyleProperty =
1754 DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(FooTextBox), new PropertyMetadata(FontStyle.Normal,OnPropertyChanged));
1759 public new FontWeight FontWeight
1761 get { return (FontWeight)GetValue(FontWeightProperty); }
1762 set { SetValue(FontWeightProperty, value); }
1766 /// FontWeigthの依存プロパティを表す
1768 public new static readonly DependencyProperty FontWeightProperty =
1769 DependencyProperty.Register("FontWeigth", typeof(FontWeight), typeof(FooTextBox), new PropertyMetadata(FontWeights.Normal,OnPropertyChanged));
1772 /// デフォルトの文字色を表す。これは依存プロパティです
1774 public new Windows.UI.Color Foreground
1776 get { return (Windows.UI.Color)GetValue(ForegroundProperty); }
1777 set { SetValue(ForegroundProperty, value); }
1781 /// Foregroundの依存プロパティを表す
1783 public new static readonly DependencyProperty ForegroundProperty =
1784 DependencyProperty.Register("Foreground", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1787 /// 選択時の文字色を表す。これは依存プロパティです
1789 public Windows.UI.Color HilightForeground
1791 get { return (Windows.UI.Color)GetValue(HilightForegroundProperty); }
1792 set { SetValue(HilightForegroundProperty, value); }
1796 /// HilightForegroundForegroundの依存プロパティを表す
1798 public static readonly DependencyProperty HilightForegroundProperty =
1799 DependencyProperty.Register("HilightForeground", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));
1802 /// 背景色を表す。これは依存プロパティです
1804 public new Windows.UI.Color Background
1806 get { return (Windows.UI.Color)GetValue(BackgroundProperty); }
1807 set { SetValue(BackgroundProperty, value); }
1811 /// Backgroundの依存プロパティを表す
1813 public new static readonly DependencyProperty BackgroundProperty =
1814 DependencyProperty.Register("Background", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));
1817 /// コントロールコードの文字色を表す。これは依存プロパティです
1819 public Windows.UI.Color ControlChar
1821 get { return (Windows.UI.Color)GetValue(ControlCharProperty); }
1822 set { SetValue(ControlCharProperty, value); }
1826 /// ControlCharの依存プロパティを表す
1828 public static readonly DependencyProperty ControlCharProperty =
1829 DependencyProperty.Register("ControlChar", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1832 /// 選択時の背景色を表す。これは依存プロパティです
1834 public Windows.UI.Color Hilight
1836 get { return (Windows.UI.Color)GetValue(HilightProperty); }
1837 set { SetValue(HilightProperty, value); }
1841 /// Hilightの依存プロパティを表す
1843 public static readonly DependencyProperty HilightProperty =
1844 DependencyProperty.Register("Hilight", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DodgerBlue, OnPropertyChanged));
1847 /// キーワード1の文字色を表す。これは依存プロパティです
1849 public Windows.UI.Color Keyword1
1851 get { return (Windows.UI.Color)GetValue(Keyword1Property); }
1852 set { SetValue(Keyword1Property, value); }
1856 /// Keyword1の依存プロパティを表す
1858 public static readonly DependencyProperty Keyword1Property =
1859 DependencyProperty.Register("Keyword1", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1862 /// キーワード2の文字色を表す。これは依存プロパティです
1864 public Windows.UI.Color Keyword2
1866 get { return (Windows.UI.Color)GetValue(Keyword2Property); }
1867 set { SetValue(Keyword2Property, value); }
1871 /// Keyword2の依存プロパティを表す
1873 public static readonly DependencyProperty Keyword2Property =
1874 DependencyProperty.Register("Keyword2", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DarkCyan, OnPropertyChanged));
1877 /// コメントの文字色を表す。これは依存プロパティです
1879 public Windows.UI.Color Comment
1881 get { return (Windows.UI.Color)GetValue(CommentProperty); }
1882 set { SetValue(CommentProperty, value); }
1886 /// Commentの依存プロパティを表す
1888 public static readonly DependencyProperty CommentProperty =
1889 DependencyProperty.Register("Comment", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Green, OnPropertyChanged));
1892 /// 文字リテラルの文字色を表す。これは依存プロパティです
1894 public Windows.UI.Color Literal
1896 get { return (Windows.UI.Color)GetValue(LiteralProperty); }
1897 set { SetValue(LiteralProperty, value); }
1901 /// Literalの依存プロパティを表す
1903 public static readonly DependencyProperty LiteralProperty =
1904 DependencyProperty.Register("Literal", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Brown, OnPropertyChanged));
1907 /// URLの文字色を表す。これは依存プロパティです
1909 public Windows.UI.Color URL
1911 get { return (Windows.UI.Color)GetValue(URLProperty); }
1912 set { SetValue(URLProperty, value); }
1918 public static readonly DependencyProperty URLProperty =
1919 DependencyProperty.Register("URL", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1924 public Windows.UI.Color UpdateArea
1926 get { return (Windows.UI.Color)GetValue(UpdateAreaProperty); }
1927 set { SetValue(UpdateAreaProperty, value); }
1931 /// UpdateAreaの依存プロパティを表す
1933 public static readonly DependencyProperty UpdateAreaProperty =
1934 DependencyProperty.Register("UpdateArea", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen, OnPropertyChanged));
1939 public Windows.UI.Color LineMarker
1941 get { return (Windows.UI.Color)GetValue(LineMarkerProperty); }
1942 set { SetValue(LineMarkerProperty, value); }
1946 /// LineMarkerの依存プロパティを表す
1948 public static readonly DependencyProperty LineMarkerProperty =
1949 DependencyProperty.Register("LineMarker", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1952 /// 挿入モード時のキャレットの色を表す
1954 public Windows.UI.Color InsertCaret
1956 get { return (Windows.UI.Color)GetValue(InsertCaretProperty); }
1957 set { SetValue(InsertCaretProperty, value); }
1961 /// InsertCaretの依存プロパティを表す
1963 public static readonly DependencyProperty InsertCaretProperty =
1964 DependencyProperty.Register("InsertCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1967 /// 上書きモード時のキャレット職を表す
1969 public Windows.UI.Color OverwriteCaret
1971 get { return (Windows.UI.Color)GetValue(OverwriteCaretProperty); }
1972 set { SetValue(OverwriteCaretProperty, value); }
1976 /// OverwriteCaretの依存プロパティを表す
1978 public static readonly DependencyProperty OverwriteCaretProperty =
1979 DependencyProperty.Register("OverwriteCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1984 public Windows.UI.Color LineNumber
1986 get { return (Windows.UI.Color)GetValue(LineNumberProperty); }
1987 set { SetValue(LineNumberProperty, value); }
1991 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1993 public static readonly DependencyProperty LineNumberProperty =
1994 DependencyProperty.Register("LineNumber", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray,OnPropertyChanged));
1999 public new Thickness Padding
2001 get { return (Thickness)GetValue(PaddingProperty); }
2002 set { SetValue(PaddingProperty, value); }
2006 /// Paddingの依存プロパティを表す
2008 public new static readonly DependencyProperty PaddingProperty =
2009 DependencyProperty.Register("Padding", typeof(Thickness), typeof(FooTextBox), new PropertyMetadata(new Thickness(),OnPropertyChanged));
2012 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
2014 public bool InsertMode
2016 get { return (bool)GetValue(InsertModeProperty); }
2017 set { SetValue(InsertModeProperty, value); }
2021 /// InsertModeの依存プロパティを表す
2023 public static readonly DependencyProperty InsertModeProperty =
2024 DependencyProperty.Register("InsertMode",
2027 new PropertyMetadata(true, OnPropertyChanged));
2030 /// タブの文字数を表す。これは依存プロパティです
2034 get { return (int)GetValue(TabCharsProperty); }
2035 set { SetValue(TabCharsProperty, value); }
2039 /// TabCharsの依存プロパティを表す
2041 public static readonly DependencyProperty TabCharsProperty =
2042 DependencyProperty.Register("TabChars",
2045 new PropertyMetadata(4, OnPropertyChanged));
2048 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
2050 public bool RectSelectMode
2052 get { return (bool)GetValue(RectSelectModeProperty); }
2053 set { SetValue(RectSelectModeProperty, value); }
2057 /// RectSelectModeの依存プロパティを表す
2059 public static readonly DependencyProperty RectSelectModeProperty =
2060 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2066 /// 変更した場合、レイアウトの再構築を行う必要があります
2068 public LineBreakMethod LineBreakMethod
2070 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
2071 set { SetValue(LineBreakProperty, value); }
2075 /// LineBreakMethodの依存プロパティを表す
2077 public static readonly DependencyProperty LineBreakProperty =
2078 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None, OnPropertyChanged));
2082 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
2085 /// 変更した場合、レイアウトの再構築を行う必要があります
2087 public int LineBreakCharCount
2089 get { return (int)GetValue(LineBreakCharCountProperty); }
2090 set { SetValue(LineBreakCharCountProperty, value); }
2094 /// LineBreakCharCountの依存プロパティを表す
2096 public static readonly DependencyProperty LineBreakCharCountProperty =
2097 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80, OnPropertyChanged));
2100 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
2102 public bool DrawCaret
2104 get { return (bool)GetValue(DrawCaretProperty); }
2105 set { SetValue(DrawCaretProperty, value); }
2109 /// DrawCaretの依存プロパティを表す
2111 public static readonly DependencyProperty DrawCaretProperty =
2112 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new PropertyMetadata(true, OnPropertyChanged));
2116 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
2118 public bool DrawCaretLine
2120 get { return (bool)GetValue(DrawCaretLineProperty); }
2121 set { SetValue(DrawCaretLineProperty, value); }
2125 /// DrawCaretLineの依存プロパティを表す
2127 public static readonly DependencyProperty DrawCaretLineProperty =
2128 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2131 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
2133 public bool DrawLineNumber
2135 get { return (bool)GetValue(DrawLineNumberProperty); }
2136 set { SetValue(DrawLineNumberProperty, value); }
2140 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
2142 public bool DrawRuler
2144 get { return (bool)GetValue(DrawRulerProperty); }
2145 set { SetValue(DrawRulerProperty, value); }
2149 /// DrawRulerの依存プロパティを表す
2151 public static readonly DependencyProperty DrawRulerProperty =
2152 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2156 /// DrawLineNumberの依存プロパティを表す
2158 public static readonly DependencyProperty DrawLineNumberProperty =
2159 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2162 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
2166 get { return (bool)GetValue(MarkURLProperty); }
2167 set { SetValue(MarkURLProperty, value); }
2171 /// MarkURLの依存プロパティを表す
2173 public static readonly DependencyProperty MarkURLProperty =
2174 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2177 /// 全角スペースを表示するなら真。そうでないなら偽
2179 public bool ShowFullSpace
2181 get { return (bool)GetValue(ShowFullSpaceProperty); }
2182 set { SetValue(ShowFullSpaceProperty, value); }
2186 /// ShowFullSpaceの依存プロパティを表す
2188 public static readonly DependencyProperty ShowFullSpaceProperty =
2189 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2192 /// 半角スペースを表示するなら真。そうでないなら偽
2194 public bool ShowHalfSpace
2196 get { return (bool)GetValue(ShowHalfSpaceProperty); }
2197 set { SetValue(ShowHalfSpaceProperty, value); }
2201 /// ShowHalfSpaceの依存プロパティを表す
2203 public static readonly DependencyProperty ShowHalfSpaceProperty =
2204 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2207 /// タブを表示するなら真。そうでないなら偽
2211 get { return (bool)GetValue(ShowTabProperty); }
2212 set { SetValue(ShowTabProperty, value); }
2216 /// ShowTabの依存プロパティを表す
2218 public static readonly DependencyProperty ShowTabProperty =
2219 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2222 /// 改行マークを表示するなら真。そうでないなら偽
2224 public bool ShowLineBreak
2226 get { return (bool)GetValue(ShowLineBreakProperty); }
2227 set { SetValue(ShowLineBreakProperty, value); }
2231 /// ShowLineBreakの依存プロパティを表す
2233 public static readonly DependencyProperty ShowLineBreakProperty =
2234 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false,OnPropertyChanged));
2240 /// コンテキストメニューのイベントデーターを表す
2242 public class FooContextMenuEventArgs
2245 /// 処理済みなら真。そうでないなら偽
2247 public bool Handled = false;
2249 /// コンテキストメニューを表示すべき座標を表す
2251 public Windows.Foundation.Point Postion;
2255 /// <param name="pos"></param>
2256 public FooContextMenuEventArgs(Windows.Foundation.Point pos)