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;
59 DispatcherTimer timer = new DispatcherTimer();
61 const int Interval = 16;
62 const int IntervalWhenLostFocus = 160;
69 this.DefaultStyleKey = typeof(FooTextBox);
71 this.rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
72 this.rectangle.Margin = this.Padding;
74 this.Render = new D2DRender(this,this.rectangle);
76 this.Render = new DummyRender();
79 this.Document = new Document();
81 this.View = new EditView(this.Document, this.Render, new Padding(5, Gripper.HitAreaWidth, Gripper.HitAreaWidth / 2, Gripper.HitAreaWidth));
82 this.View.SrcChanged += View_SrcChanged;
83 this.View.InsertMode = this.InsertMode;
84 this.Document.DrawLineNumber = this.DrawLineNumber;
85 this.View.HideCaret = !this.DrawCaret;
86 this.View.HideLineMarker = !this.DrawCaretLine;
87 this.Document.HideRuler = !this.DrawRuler;
88 this.Document.UrlMark = this.MarkURL;
89 this.Document.TabStops = this.TabChars;
91 this._Controller = new Controller(this.Document, this.View);
93 this.gestureRecongnizer.GestureSettings = GestureSettings.Drag |
94 GestureSettings.RightTap |
96 GestureSettings.DoubleTap |
97 GestureSettings.ManipulationTranslateX |
98 GestureSettings.ManipulationTranslateY |
99 GestureSettings.ManipulationScale |
100 GestureSettings.ManipulationTranslateInertia |
101 GestureSettings.ManipulationScaleInertia;
102 this.gestureRecongnizer.RightTapped += gestureRecongnizer_RightTapped;
103 this.gestureRecongnizer.Tapped += gestureRecongnizer_Tapped;
104 this.gestureRecongnizer.Dragging += gestureRecongnizer_Dragging;
105 this.gestureRecongnizer.ManipulationInertiaStarting += GestureRecongnizer_ManipulationInertiaStarting; ;
106 this.gestureRecongnizer.ManipulationStarted += gestureRecongnizer_ManipulationStarted;
107 this.gestureRecongnizer.ManipulationUpdated += gestureRecongnizer_ManipulationUpdated;
108 this.gestureRecongnizer.ManipulationCompleted += gestureRecongnizer_ManipulationCompleted;
110 this.timer.Interval = new TimeSpan(0, 0, 0, 0, Interval);
111 this.timer.Tick += this.timer_Tick;
114 this.SizeChanged += FooTextBox_SizeChanged;
116 this.Loaded += FooTextBox_Loaded;
130 public void Dispose()
133 GC.SuppressFinalize(this);
136 bool Disposed = false;
137 private void Dispose(bool disposing)
144 this.Render.Dispose();
151 /// <param name="start">開始インデックス</param>
152 /// <param name="length">長さ</param>
153 public void Select(int start, int length)
155 this.Document.Select(start, length);
159 /// キャレットを指定した行に移動させます
161 /// <param name="index">インデックス</param>
162 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
163 public void JumpCaret(int index)
165 this._Controller.JumpCaret(index);
168 /// キャレットを指定した行と桁に移動させます
170 /// <param name="row">行番号</param>
171 /// <param name="col">桁</param>
172 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
173 public void JumpCaret(int row, int col)
175 this._Controller.JumpCaret(row, col);
179 /// 選択中のテキストをクリップボードにコピーします
183 string text = this._Controller.SelectedText;
184 if (text != null && text != string.Empty)
186 DataPackage dataPackage = new DataPackage();
187 dataPackage.RequestedOperation = DataPackageOperation.Copy;
188 dataPackage.SetText(text);
190 Clipboard.SetContent(dataPackage);
195 /// 選択中のテキストをクリップボードに切り取ります
199 string text = this._Controller.SelectedText;
200 if (text != null && text != string.Empty)
202 DataPackage dataPackage = new DataPackage();
203 dataPackage.RequestedOperation = DataPackageOperation.Copy;
204 dataPackage.SetText(text);
206 Clipboard.SetContent(dataPackage);
208 this._Controller.SelectedText = "";
215 public async Task PasteAsync()
217 var dataPackageView = Clipboard.GetContent();
218 if (dataPackageView.Contains(StandardDataFormats.Text))
220 this._Controller.SelectedText = await dataPackageView.GetTextAsync();
227 public void SelectAll()
229 this.Document.Select(0, this.Document.Length);
235 public void DeSelectAll()
237 this._Controller.DeSelectAll();
243 /// <param name="tp">テキストポイント</param>
244 /// <returns>座標</returns>
245 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
246 public Windows.Foundation.Point GetPostionFromTextPoint(TextPoint tp)
248 if (this.Document.FireUpdateEvent == false)
249 throw new InvalidOperationException("");
250 return this.View.GetPostionFromTextPoint(tp);
254 /// 対応するテキストポイントを返します
256 /// <param name="p">クライアント領域の原点を左上とする座標</param>
257 /// <returns>テキストポイント</returns>
258 public TextPoint GetTextPointFromPostion(Windows.Foundation.Point p)
260 if (this.Document.FireUpdateEvent == false)
261 throw new InvalidOperationException("");
262 return this.View.GetTextPointFromPostion(p);
268 /// <param name="row">レイアウト行</param>
269 /// <returns>行の高さ</returns>
270 public double GetLineHeight(int row)
272 if (this.Document.FireUpdateEvent == false)
273 throw new InvalidOperationException("");
274 return this.View.LayoutLines.GetLayout(row).Height; ;
278 /// インデックスに対応する座標を得ます
280 /// <param name="index">インデックス</param>
281 /// <returns>座標を返す</returns>
282 public Windows.Foundation.Point GetPostionFromIndex(int index)
284 if (this.Document.FireUpdateEvent == false)
285 throw new InvalidOperationException("");
286 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
287 return this.View.GetPostionFromTextPoint(tp);
293 /// <param name="p">座標</param>
294 /// <returns>インデックスを返す</returns>
295 public int GetIndexFromPostion(Windows.Foundation.Point p)
297 if (this.Document.FireUpdateEvent == false)
298 throw new InvalidOperationException("");
299 TextPoint tp = this.View.GetTextPointFromPostion(p);
300 return this.View.GetIndexFromLayoutLine(tp);
307 public void Refresh()
309 this.Document.RequestRedraw();
313 /// レイアウト行をすべて破棄し、再度レイアウトを行う
315 public void PerfomLayouts()
317 this.Document.PerformLayout();
323 /// <param name="row">行</param>
324 /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
325 public void ScrollIntoView(int row, bool alignTop)
327 this.View.ScrollIntoView(row, alignTop);
331 /// ファイルからドキュメントを構築する
333 /// <param name="sr">StremReader</param>
334 /// <returns>Taskオブジェクト</returns>
335 public async Task LoadFileAsync(System.IO.StreamReader sr, System.Threading.CancellationTokenSource token)
337 await this.Document.LoadAsync(sr, token);
340 private void Document_LoadProgress(object sender, ProgressEventArgs e)
342 if(e.state == ProgressState.Start)
344 this.IsEnabled = false;
346 else if(e.state == ProgressState.Complete)
348 CoreTextRange modified_range = new CoreTextRange();
349 modified_range.StartCaretPosition = 0;
350 modified_range.EndCaretPosition = 0;
351 //キャレット位置はロード前と同じにしないと違和感を感じる
352 if (this.textEditContext != null)
353 this.textEditContext.NotifyTextChanged(modified_range, this.Document.Length, modified_range);
355 if (this.verticalScrollBar != null)
356 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
357 this.IsEnabled = true;
358 this.Refresh(this.View.PageBound);
363 /// ドキュメントの内容をファイルに保存する
365 /// <param name="sw">StreamWriter</param>
366 /// <param name="enc">エンコード</param>
367 /// <returns>Taskオブジェクト</returns>
368 public async Task SaveFile(System.IO.StreamWriter sw, System.Threading.CancellationTokenSource token)
370 await this.Document.SaveAsync(sw, token);
385 async Task PasteCommand()
387 await this.PasteAsync();
397 protected override Windows.UI.Xaml.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
399 this.peer = new FooTextBoxAutomationPeer(this);
404 protected override void OnApplyTemplate()
406 base.OnApplyTemplate();
408 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
411 Grid.SetRow(this.rectangle, 0);
412 Grid.SetColumn(this.rectangle, 0);
413 grid.Children.Add(this.rectangle);
416 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
417 if (this.horizontalScrollBar != null)
419 this.horizontalScrollBar.SmallChange = 10;
420 this.horizontalScrollBar.LargeChange = 100;
421 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
422 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
424 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
425 if (this.verticalScrollBar != null)
427 this.verticalScrollBar.SmallChange = 1;
428 this.verticalScrollBar.LargeChange = 10;
429 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
430 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
435 protected override async void OnGotFocus(RoutedEventArgs e)
439 System.Diagnostics.Debug.WriteLine("got focus");
441 if (this.textServiceManager == null)
443 await Task.Delay(500);
444 this.textServiceManager = CoreTextServicesManager.GetForCurrentView();
445 this.textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;
448 this.CreateTextContext();
450 this.View.IsFocused = true;
451 this.timer.Interval = new TimeSpan(0, 0, 0, 0, Interval);
455 private void TextServiceManager_InputLanguageChanged(CoreTextServicesManager sender, object args)
457 System.Diagnostics.Debug.WriteLine("input language changed input script:"+ this.textServiceManager.InputLanguage.Script);
458 this.RemoveTextContext();
459 this.CreateTextContext();
463 protected override void OnLostFocus(RoutedEventArgs e)
467 this.RemoveTextContext();
469 System.Diagnostics.Debug.WriteLine("lost focus");
471 this.View.IsFocused = false;
472 this.Refresh(this.View.PageBound);
473 this.timer.Interval = new TimeSpan(0, 0, 0, 0, IntervalWhenLostFocus);
476 private void CreateTextContext()
478 if(this.textServiceManager != null)
480 this.textEditContext = this.textServiceManager.CreateEditContext();
481 this.textEditContext.CompositionStarted += TextEditContext_CompositionStarted;
482 this.textEditContext.CompositionCompleted += TextEditContext_CompositionCompleted;
483 this.textEditContext.LayoutRequested += TextEditContext_LayoutRequested;
484 this.textEditContext.TextUpdating += TextEditContext_TextUpdating;
485 this.textEditContext.TextRequested += TextEditContext_TextRequested;
486 this.textEditContext.SelectionRequested += TextEditContext_SelectionRequested;
487 this.textEditContext.SelectionUpdating += TextEditContext_SelectionUpdating;
488 this.textEditContext.FormatUpdating += TextEditContext_FormatUpdating;
489 this.textEditContext.FocusRemoved += TextEditContext_FocusRemoved;
490 this.textEditContext.NotifyFocusLeaveCompleted += TextEditContext_NotifyFocusLeaveCompleted;
491 this.textEditContext.NotifyFocusEnter();
495 private void RemoveTextContext()
497 if(this.textEditContext != null)
499 this.textEditContext.CompositionStarted -= TextEditContext_CompositionStarted;
500 this.textEditContext.CompositionCompleted -= TextEditContext_CompositionCompleted;
501 this.textEditContext.LayoutRequested -= TextEditContext_LayoutRequested;
502 this.textEditContext.TextUpdating -= TextEditContext_TextUpdating;
503 this.textEditContext.TextRequested -= TextEditContext_TextRequested;
504 this.textEditContext.SelectionRequested -= TextEditContext_SelectionRequested;
505 this.textEditContext.SelectionUpdating -= TextEditContext_SelectionUpdating;
506 this.textEditContext.FormatUpdating -= TextEditContext_FormatUpdating;
507 this.textEditContext.FocusRemoved -= TextEditContext_FocusRemoved;
508 this.textEditContext.NotifyFocusLeaveCompleted -= TextEditContext_NotifyFocusLeaveCompleted;
509 this.textEditContext.NotifyFocusLeave();
510 this.textEditContext = null;
515 protected override async void OnKeyDown(KeyRoutedEventArgs e)
517 bool isControlPressed = this.IsModiferKeyPressed(VirtualKey.Control);
518 bool isShiftPressed = this.IsModiferKeyPressed(VirtualKey.Shift);
519 bool isMovedCaret = false;
521 var autocomplete = this.Document.AutoComplete as AutoCompleteBox;
522 if (autocomplete != null && autocomplete.ProcessKeyDown(this, e, isControlPressed, isShiftPressed))
528 this._Controller.MoveCaretVertical(-1, isShiftPressed);
533 case VirtualKey.Down:
534 this._Controller.MoveCaretVertical(+1, isShiftPressed);
539 case VirtualKey.Left:
540 this._Controller.MoveCaretHorizontical(-1, isShiftPressed, isControlPressed);
545 case VirtualKey.Right:
546 this._Controller.MoveCaretHorizontical(1, isShiftPressed, isControlPressed);
551 case VirtualKey.PageUp:
552 this._Controller.Scroll(ScrollDirection.Up, this.View.LineCountOnScreen, isShiftPressed, true);
556 case VirtualKey.PageDown:
557 this._Controller.Scroll(ScrollDirection.Down, this.View.LineCountOnScreen, isShiftPressed, true);
561 case VirtualKey.Home:
562 if (isControlPressed)
563 this._Controller.JumpToHead(isShiftPressed);
565 this.Controller.JumpToLineHead(this.Document.CaretPostion.row,isShiftPressed);
570 if (isControlPressed)
571 this._Controller.JumpToEnd(isShiftPressed);
573 this.Controller.JumpToLineEnd(this.Document.CaretPostion.row,isShiftPressed);
578 if (!isControlPressed)
580 if (this._Controller.SelectionLength == 0)
581 this._Controller.DoInputChar('\t');
582 else if (isShiftPressed)
583 this._Controller.DownIndent();
585 this._Controller.UpIndent();
590 case VirtualKey.Enter:
591 this._Controller.DoEnterAction();
595 case VirtualKey.Insert:
596 if(this.View.InsertMode)
597 this.View.InsertMode = false;
599 this.View.InsertMode = true;
604 if (isControlPressed)
612 if (isControlPressed)
614 if (this._Controller.RectSelection)
615 this._Controller.RectSelection = false;
617 this._Controller.RectSelection = true;
623 if (isControlPressed)
630 if (isControlPressed)
637 if (isControlPressed)
639 await this.PasteCommand();
644 if (isControlPressed)
646 this.Document.UndoManager.redo();
652 if (isControlPressed)
654 this.Document.UndoManager.undo();
659 case VirtualKey.Back:
660 this._Controller.DoBackSpaceAction();
664 case VirtualKey.Delete:
665 this._Controller.DoDeleteAction();
671 if (isMovedCaret && this.peer != null)
672 this.peer.OnNotifyCaretChanged();
678 protected override void OnPointerPressed(PointerRoutedEventArgs e)
680 this.CapturePointer(e.Pointer);
681 this.gestureRecongnizer.ProcessDownEvent(e.GetCurrentPoint(this));
686 protected override void OnPointerMoved(PointerRoutedEventArgs e)
688 this.gestureRecongnizer.ProcessMoveEvents(e.GetIntermediatePoints(this));
691 if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
693 Point p = e.GetCurrentPoint(this).Position;
694 if (this.View.HitTextArea(p.X, p.Y))
696 TextPoint tp = this.View.GetTextPointFromPostion(p);
697 if (this._Controller.IsMarker(tp, HilightType.Url))
698 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Hand, 101);
700 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.IBeam, 101);
704 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 101);
710 protected override void OnPointerReleased(PointerRoutedEventArgs e)
712 this.gestureRecongnizer.ProcessUpEvent(e.GetCurrentPoint(this));
717 protected override void OnPointerCanceled(PointerRoutedEventArgs e)
719 this.gestureRecongnizer.CompleteGesture();
724 protected override void OnPointerWheelChanged(PointerRoutedEventArgs e)
726 bool shift = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Shift) ==
727 Windows.System.VirtualKeyModifiers.Shift;
728 bool ctrl = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Control) ==
729 Windows.System.VirtualKeyModifiers.Control;
730 this.gestureRecongnizer.ProcessMouseWheelEvent(e.GetCurrentPoint(this), shift, ctrl);
734 private void TextEditContext_FormatUpdating(CoreTextEditContext sender, CoreTextFormatUpdatingEventArgs args)
736 if (this.Document.Length == 0 || args.IsCanceled)
738 args.Result = CoreTextFormatUpdatingResult.Failed;
741 System.Diagnostics.Debug.WriteLine("core text format updating range({0}-{1}) underline type:{2} underline color:{3} reason:{4} textcolor:{5} background:{6}",
742 args.Range.StartCaretPosition,
743 args.Range.EndCaretPosition,
750 HilightType type = HilightType.None;
751 Color color = new Color(this.Foreground.A,this.Foreground.R,this.Foreground.G,this.Foreground.R);
752 bool isBoldLine = false;
753 switch (args.UnderlineType)
755 case UnderlineType.Dotted:
756 type = HilightType.Dot;
758 case UnderlineType.Single:
759 type = HilightType.Sold;
761 case UnderlineType.Dash:
762 type = HilightType.Dash;
764 case UnderlineType.Wave:
765 type = HilightType.Squiggle;
767 case UnderlineType.Thin:
768 type = HilightType.Sold;
770 case UnderlineType.Thick:
771 type = HilightType.Sold;
775 int start = args.Range.StartCaretPosition;
776 int lengt = args.Range.EndCaretPosition - args.Range.StartCaretPosition;
777 this.Document.SetMarker(MarkerIDs.IME, Marker.Create(start, lengt, type, color, isBoldLine));
779 if (args.Reason == CoreTextFormatUpdatingReason.CompositionTargetConverted)
781 this.View.AdjustSrc(args.Range.StartCaretPosition);
785 args.Result = CoreTextFormatUpdatingResult.Succeeded;
788 private void TextEditContext_TextRequested(CoreTextEditContext sender, CoreTextTextRequestedEventArgs args)
790 CoreTextTextRequest req = args.Request;
792 if (this.Document.Length == 0 || req.IsCanceled)
797 int start = req.Range.StartCaretPosition;
798 int end = req.Range.EndCaretPosition;
799 if (end > this.Document.Length)
800 end = this.Document.Length;
802 int length = end - start;
804 System.Diagnostics.Debug.WriteLine("req text start:{0} length:{1}", start, length);
806 //キャレット位置も含むので+1する必要はない
807 req.Text = this.Document.ToString(start,length);
810 private void TextEditContext_LayoutRequested(CoreTextEditContext sender, CoreTextLayoutRequestedEventArgs args)
813 Point startPos, endPos;
814 int i_startIndex = args.Request.Range.StartCaretPosition;
815 int i_endIndex = args.Request.Range.EndCaretPosition;
817 if(args.Request.IsCanceled)
822 System.Diagnostics.Debug.WriteLine("core text layoutreq range({0}-{1})",i_startIndex,i_endIndex);
824 if (i_startIndex != -1 && i_endIndex != -1)
826 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
828 double scale = Util.GetScale();
830 //Core.Textはスクリーン座標に変換してくれないので自前で変換する(しかも、デバイス依存の座標で返さないといけない)
831 var screenStartPos = Util.GetScreentPoint(startPos, this).Scale(scale);
832 var screenEndPos = Util.GetScreentPoint(endPos, this).Scale(scale);
833 args.Request.LayoutBounds.TextBounds = new Rect(
836 screenEndPos.X - screenStartPos.X,
837 screenEndPos.Y - screenStartPos.Y);
841 var controlTopLeft = new Point(0, 0);
842 var controlBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
844 var gt = this.TransformToVisual(Window.Current.Content);
845 controlTopLeft = gt.TransformPoint(controlTopLeft);
846 controlBottomRight = gt.TransformPoint(controlBottomRight);
848 args.Request.LayoutBounds.ControlBounds = new Rect(
851 controlBottomRight.X - controlTopLeft.X,
852 controlBottomRight.Y - controlTopLeft.Y
856 private void TextEditContext_SelectionRequested(CoreTextEditContext sender, CoreTextSelectionRequestedEventArgs args)
858 if(args.Request.IsCanceled || this.Document.Length == 0)
862 TextRange currentSelection = new TextRange();
863 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out currentSelection);
865 CoreTextRange currentSelectionRange = new CoreTextRange();
866 currentSelectionRange.StartCaretPosition = currentSelection.Index;
867 currentSelectionRange.EndCaretPosition = currentSelection.Index + currentSelection.Length;
868 args.Request.Selection = currentSelectionRange;
869 System.Diagnostics.Debug.WriteLine("req selection start:{0} end:{1}", currentSelectionRange.StartCaretPosition, currentSelectionRange.EndCaretPosition);
872 private void TextEditContext_SelectionUpdating(CoreTextEditContext sender, CoreTextSelectionUpdatingEventArgs args)
874 if(this.Document.Length == 0 || args.IsCanceled)
876 args.Result = CoreTextSelectionUpdatingResult.Failed;
879 CoreTextRange sel = args.Selection;
880 System.Diagnostics.Debug.WriteLine("update selection start:{0} end:{1}", sel.StartCaretPosition, sel.EndCaretPosition);
881 TextStoreHelper.SetSelectionIndex(this.Controller, this.View, sel.StartCaretPosition, sel.EndCaretPosition);
882 args.Result = CoreTextSelectionUpdatingResult.Succeeded;
886 private void TextEditContext_TextUpdating(CoreTextEditContext sender, CoreTextTextUpdatingEventArgs args)
888 this.nowCompstion = true;
890 System.Diagnostics.Debug.WriteLine("update text (modify start:{0} end:{1}) text:{2} (new sel start:{0} end:{1})",
891 args.Range.StartCaretPosition,
892 args.Range.EndCaretPosition,
894 args.NewSelection.StartCaretPosition,
895 args.NewSelection.EndCaretPosition);
896 bool isTip = args.InputLanguage.Script == "Latan";
897 CoreTextRange sel = args.Range;
898 TextStoreHelper.SetSelectionIndex(this.Controller, this.View, sel.StartCaretPosition, sel.EndCaretPosition);
899 TextStoreHelper.InsertTextAtSelection(this._Controller, args.Text, isTip);
901 args.Result = CoreTextTextUpdatingResult.Succeeded;
903 this.nowCompstion = false;
906 private void TextEditContext_CompositionCompleted(CoreTextEditContext sender, CoreTextCompositionCompletedEventArgs args)
908 System.Diagnostics.Debug.WriteLine("end compostion");
909 TextStoreHelper.EndCompostion(this.Document);
910 this.Document.RemoveAllMarker(MarkerIDs.IME);
914 private void TextEditContext_CompositionStarted(CoreTextEditContext sender, CoreTextCompositionStartedEventArgs args)
916 System.Diagnostics.Debug.WriteLine("start compstion");
917 TextStoreHelper.StartCompstion(this.Document);
920 private void TextEditContext_NotifyFocusLeaveCompleted(CoreTextEditContext sender, object args)
922 System.Diagnostics.Debug.WriteLine("notify focus leaved");
925 private void TextEditContext_FocusRemoved(CoreTextEditContext sender, object args)
927 System.Diagnostics.Debug.WriteLine("focus leaved");
930 void Controller_SelectionChanged(object sender, EventArgs e)
932 if (this._Controller == null)
936 this.nowCaretMove = true;
937 SetValue(SelectedTextProperty, this._Controller.SelectedText);
938 SetValue(CaretPostionPropertyKey, this.Document.CaretPostion);
939 this.nowCaretMove = false;
941 if(!this.nowCompstion)
943 TextRange currentSelection = new TextRange();
944 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out currentSelection);
946 CoreTextRange currentSelectionRange = new CoreTextRange();
947 currentSelectionRange.StartCaretPosition = currentSelection.Index;
948 currentSelectionRange.EndCaretPosition = currentSelection.Index + currentSelection.Length;
950 System.Diagnostics.Debug.WriteLine("notify selection start:{0} end:{1}", currentSelectionRange.StartCaretPosition, currentSelectionRange.EndCaretPosition);
952 if (this.textEditContext != null)
953 this.textEditContext.NotifySelectionChanged(currentSelectionRange);
957 Gripper hittedGripper;
958 void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)
960 //Updateedの段階でヒットテストしてしまうとグリッパーを触ってもヒットしないことがある
961 this.hittedGripper = this.View.HitGripperFromPoint(e.Position);
964 private void GestureRecongnizer_ManipulationInertiaStarting(GestureRecognizer sender, ManipulationInertiaStartingEventArgs args)
966 //sender.InertiaTranslationDeceleration = 0.001f;
967 //sender.InertiaExpansionDeceleration = 100.0f * 96.0f / 1000.0f;
968 //sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
971 void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
973 if (e.Delta.Scale < 1)
975 double newSize = this.Render.FontSize - 1;
978 this.Render.FontSize = newSize;
980 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
984 if (e.Delta.Scale > 1)
986 double newSize = this.Render.FontSize + 1;
989 this.Render.FontSize = newSize;
991 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
995 if (this._Controller.MoveCaretAndGripper(e.Position, this.hittedGripper))
998 if (this.peer != null)
999 this.peer.OnNotifyCaretChanged();
1005 Point translation = e.Delta.Translation;
1007 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
1008 if (Math.Abs(e.Cumulative.Translation.X) < Math.Abs(e.Cumulative.Translation.Y))
1010 int deltay = (int)Math.Abs(Math.Ceiling(translation.Y));
1011 if (translation.Y < 0)
1012 this._Controller.ScrollByPixel(ScrollDirection.Down, deltay, false, false);
1014 this._Controller.ScrollByPixel(ScrollDirection.Up, deltay, false, false);
1019 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
1022 if (translation.X < 0)
1023 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
1025 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
1030 void gestureRecongnizer_ManipulationCompleted(GestureRecognizer sender, ManipulationCompletedEventArgs e)
1034 async void gestureRecongnizer_RightTapped(GestureRecognizer sender, RightTappedEventArgs e)
1036 ResourceMap map = ResourceManager.Current.MainResourceMap.GetSubtree("FooEditEngine.UWP/Resources");
1037 ResourceContext context = ResourceContext.GetForCurrentView();
1038 if (this.View.HitTextArea(e.Position.X, e.Position.Y))
1040 FooContextMenuEventArgs args = new FooContextMenuEventArgs(e.Position);
1041 if (this.ContextMenuOpening != null)
1042 this.ContextMenuOpening(this, args);
1045 PopupMenu ContextMenu = new PopupMenu();
1046 ContextMenu.Commands.Add(new UICommand(map.GetValue("CopyMenuName", context).ValueAsString, (command) =>
1050 ContextMenu.Commands.Add(new UICommand(map.GetValue("CutMenuName", context).ValueAsString, (command) =>
1054 ContextMenu.Commands.Add(new UICommand(map.GetValue("PasteMenuName", context).ValueAsString, async (command) =>
1056 await this.PasteCommand();
1058 if (this._Controller.RectSelection)
1060 ContextMenu.Commands.Add(new UICommand(map.GetValue("LineSelectMenuName", context).ValueAsString, (command) =>
1062 this._Controller.RectSelection = false;
1067 ContextMenu.Commands.Add(new UICommand(map.GetValue("RectSelectMenuName", context).ValueAsString, (command) =>
1069 this._Controller.RectSelection = true;
1072 await ContextMenu.ShowAsync(e.Position);
1077 void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)
1079 bool touched = e.PointerDeviceType == PointerDeviceType.Touch;
1080 this.Document.SelectGrippers.BottomLeft.Enabled = false;
1081 this.Document.SelectGrippers.BottomRight.Enabled = touched;
1082 this.JumpCaret(e.Position);
1083 if (e.TapCount == 2)
1085 this.Document.SelectGrippers.BottomLeft.Enabled = touched;
1086 //タッチスクリーンでダブルタップした場合、アンカーインデックスを単語の先頭にしないとバグる
1087 this.Document.SelectWord(this.Controller.SelectionStart, touched);
1092 void JumpCaret(Point p)
1094 TextPoint tp = this.View.GetTextPointFromPostion(p);
1095 if (tp == TextPoint.Null)
1098 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
1100 FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
1101 if (foldingData != null)
1103 if (foldingData.Expand)
1104 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
1106 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
1107 this._Controller.JumpCaret(foldingData.Start, false);
1111 this._Controller.JumpCaret(tp.row, tp.col, false);
1113 #if ENABLE_AUTMATION
1114 if (this.peer != null)
1115 this.peer.OnNotifyCaretChanged();
1117 this.View.IsFocused = true;
1118 this.Focus(FocusState.Programmatic);
1122 void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)
1124 Point p = e.Position;
1125 TextPointSearchRange searchRange;
1126 if (this.View.HitTextArea(p.X, p.Y))
1127 searchRange = TextPointSearchRange.TextAreaOnly;
1128 else if (this._Controller.SelectionLength > 0)
1129 searchRange = TextPointSearchRange.Full;
1132 TextPoint tp = this.View.GetTextPointFromPostion(p, searchRange);
1133 this._Controller.MoveCaretAndSelect(tp);
1134 #if ENABLE_AUTMATION
1135 if (this.peer != null)
1136 this.peer.OnNotifyCaretChanged();
1141 bool IsModiferKeyPressed(VirtualKey key)
1143 CoreVirtualKeyStates state = Window.Current.CoreWindow.GetKeyState(key);
1144 return (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
1146 void Refresh(Rectangle updateRect)
1148 if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0 || this.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
1151 this.Render.DrawContent(this.View, this.IsEnabled, updateRect);
1153 this.Document.IsRequestRedraw = false;
1157 bool Resize(double width, double height)
1159 if (width == 0 || height == 0)
1160 throw new ArgumentOutOfRangeException();
1161 if (this.Render.Resize(this.rectangle, width, height))
1163 this.View.PageBound = new Rectangle(0, 0, width, height);
1165 if (this.horizontalScrollBar != null)
1167 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
1168 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1170 if (this.verticalScrollBar != null)
1172 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
1173 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1180 void View_SrcChanged(object sender, EventArgs e)
1182 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1184 EditView view = this.View;
1185 if (view.Src.Row > this.verticalScrollBar.Maximum)
1186 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
1187 double absoulteX = Math.Abs(view.Src.X);
1188 if (absoulteX > this.horizontalScrollBar.Maximum)
1189 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1190 if (view.Src.Row != this.verticalScrollBar.Value)
1191 this.verticalScrollBar.Value = view.Src.Row;
1192 if (view.Src.X != this.horizontalScrollBar.Value)
1193 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1196 void FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)
1198 if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))
1205 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1207 if (this.horizontalScrollBar == null)
1210 if (this.FlowDirection == FlowDirection.LeftToRight)
1211 toX = this.horizontalScrollBar.Value;
1213 toX = -this.horizontalScrollBar.Value;
1214 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
1218 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1220 if (this.verticalScrollBar == null)
1222 int newRow = (int)this.verticalScrollBar.Value;
1223 if (newRow >= this.View.LayoutLines.Count)
1225 this._Controller.Scroll(this.View.Src.X, newRow, false, false);
1229 void Document_Update(object sender, DocumentUpdateEventArgs e)
1231 if (e.type == UpdateType.Replace && !this.nowCompstion)
1233 CoreTextRange oldTextRange = new CoreTextRange();
1234 oldTextRange.StartCaretPosition = e.startIndex;
1235 oldTextRange.EndCaretPosition = e.startIndex;
1236 //削除する範囲が1以上の場合、ドキュメントを飛び越えることはできない
1237 //https://msdn.microsoft.com/en-us/windows/uwp/input-and-devices/custom-text-input
1238 if (e.removeLength > 0)
1239 oldTextRange.EndCaretPosition += e.removeLength;
1241 TextRange currentSelection = new TextRange();
1242 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out currentSelection);
1244 CoreTextRange newSelection = new CoreTextRange();
1245 newSelection.StartCaretPosition = e.startIndex;
1246 newSelection.EndCaretPosition = e.startIndex;
1249 //(注意:削除された文字数のほうが多い場合は0を指定しないいけない)
1250 int newTextLength = e.insertLength;
1252 System.Diagnostics.Debug.WriteLine("notify text change (modify start:{0} end:{1}) newlength:{2} (new sel start:{3} end:{4})",
1253 oldTextRange.StartCaretPosition, oldTextRange.EndCaretPosition, newTextLength, newSelection.StartCaretPosition, newSelection.EndCaretPosition);
1255 if(this.textEditContext != null)
1256 this.textEditContext.NotifyTextChanged(oldTextRange, newTextLength, newSelection);
1258 #if ENABLE_AUTMATION
1259 if (this.peer != null)
1260 this.peer.OnNotifyTextChanged();
1264 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1266 this.Focus(FocusState.Programmatic);
1269 void timer_Tick(object sender, object e)
1271 System.Diagnostics.Debug.WriteLine("interval {0}", DateTime.Now.Millisecond);
1272 if (this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding() || this.Document.IsRequestRedraw)
1274 this.Refresh(this.View.PageBound);
1278 private void SetDocument(Document value)
1283 Document old_doc = this._Document;
1285 if (this._Document != null)
1287 old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
1288 this._Document.SelectionChanged -= Controller_SelectionChanged;
1289 this._Document.LoadProgress -= Document_LoadProgress;
1290 this._Document.AutoCompleteChanged -= _Document_AutoCompleteChanged;
1291 if (this._Document.AutoComplete != null)
1293 this._Document.AutoComplete.GetPostion = null;
1294 this._Document.AutoComplete = null;
1297 //NotifyTextChanged()を呼び出すと落ちるのでTextConextをごっそり作り替える
1298 this.RemoveTextContext();
1301 System.Diagnostics.Debug.WriteLine("document switched");
1303 this._Document = value;
1304 this._Document.LayoutLines.Render = this.Render;
1305 this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
1306 this._Document.LoadProgress += Document_LoadProgress;
1307 this._Document.AutoCompleteChanged += _Document_AutoCompleteChanged;
1308 if (this._Document.AutoComplete != null && this._Document.AutoComplete.GetPostion == null)
1309 this._Document_AutoCompleteChanged(this._Document, null);
1310 //初期化が終わっていればすべて存在する
1311 if (this.Controller != null && this.View != null)
1313 this.Controller.Document = value;
1314 this.View.Document = value;
1316 this.Controller.AdjustCaret();
1318 this.CreateTextContext();
1320 //依存プロパティとドキュメント内容が食い違っているので再設定する
1321 this.ShowFullSpace = value.ShowFullSpace;
1322 this.ShowHalfSpace = value.ShowHalfSpace;
1323 this.ShowLineBreak = value.ShowLineBreak;
1324 this.ShowTab = value.ShowTab;
1325 this.FlowDirection = value.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
1326 this.IndentMode = value.IndentMode;
1327 this.DrawCaretLine = !value.HideLineMarker;
1328 this.InsertMode = value.InsertMode;
1329 this.DrawRuler = !value.HideRuler;
1330 this.DrawLineNumber = value.DrawLineNumber;
1331 this.MarkURL = value.UrlMark;
1332 this.LineBreakMethod = value.LineBreak;
1333 this.LineBreakCharCount = value.LineBreakCharCount;
1334 this.TabChars = value.TabStops;
1338 //TextEditContext作成後に設定しないと落ちることがある
1339 this._Document.SelectionChanged += Controller_SelectionChanged;
1342 private void _Document_AutoCompleteChanged(object sender, EventArgs e)
1344 Document doc = (Document)sender;
1345 doc.AutoComplete.GetPostion = (tp, e_doc) =>
1347 var p = this.View.GetPostionFromTextPoint(tp);
1348 int height = (int)e_doc.LayoutLines.GetLayout(e_doc.CaretPostion.row).Height;
1350 if (p.Y + AutoCompleteBox.CompleteListBoxHeight + height > e_doc.LayoutLines.Render.TextArea.Height)
1351 p.Y -= AutoCompleteBox.CompleteListBoxHeight;
1354 //AutoCompleteBox内ではCanvasで位置を指定しているので変換する必要がある
1355 var pointInWindow = Util.GetPointInWindow(p, this);
1356 return pointInWindow;
1361 public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
1363 FooTextBox source = (FooTextBox)sender;
1364 if(e.Property.Equals(SelectedTextProperty) && !source.nowCaretMove)
1365 source._Controller.SelectedText = source.SelectedText;
1366 if (e.Property.Equals(DocumentProperty))
1367 source.SetDocument(source.Document);
1368 if(e.Property.Equals(HilighterProperty))
1369 source.View.Hilighter = source.Hilighter;
1370 if (e.Property.Equals(FoldingStrategyProperty))
1371 source.View.LayoutLines.FoldingStrategy = source.FoldingStrategy;
1372 if (e.Property.Equals(IndentModeProperty))
1373 source.Controller.IndentMode = source.IndentMode;
1374 if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)
1375 source.Document.Select(source.Selection.Index,source.Selection.Length);
1376 if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)
1377 source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col);
1378 if (e.Property.Equals(InsertModeProperty))
1379 source.View.InsertMode = source.InsertMode;
1380 if (e.Property.Equals(TabCharsProperty))
1381 source.Document.TabStops = source.TabChars;
1382 if (e.Property.Equals(RectSelectModeProperty))
1383 source._Controller.RectSelection = source.RectSelectMode;
1384 if (e.Property.Equals(DrawCaretProperty))
1385 source.View.HideCaret = !source.DrawCaret;
1386 if (e.Property.Equals(DrawCaretLineProperty))
1387 source.View.HideLineMarker = !source.DrawCaretLine;
1388 if (e.Property.Equals(DrawLineNumberProperty))
1389 source.Document.DrawLineNumber = source.DrawLineNumber;
1390 if (e.Property.Equals(MarkURLProperty))
1391 source.Document.UrlMark = source.MarkURL;
1392 if (e.Property.Equals(LineBreakProperty))
1393 source.Document.LineBreak = source.LineBreakMethod;
1394 if (e.Property.Equals(LineBreakCharCountProperty))
1395 source.Document.LineBreakCharCount = source.LineBreakCharCount;
1396 if (e.Property.Equals(FlowDirectionProperty))
1398 source.Document.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;
1399 if (source.horizontalScrollBar != null)
1400 source.horizontalScrollBar.FlowDirection = source.FlowDirection;
1402 if (e.Property.Equals(DrawRulerProperty))
1404 source.Document.HideRuler = !source.DrawRuler;
1405 source._Controller.JumpCaret(source.Document.CaretPostion.row, source.Document.CaretPostion.col);
1408 if (e.Property.Equals(TextAntialiasModeProperty))
1409 source.Render.TextAntialiasMode = source.TextAntialiasMode;
1410 if(e.Property.Equals(MagnificationPowerPropertyKey))
1411 source.Render.FontSize = source.FontSize * source.MagnificationPower;
1412 if (e.Property.Equals(FontFamilyProperty))
1413 source.Render.FontFamily = source.FontFamily;
1414 if (e.Property.Equals(FontStyleProperty))
1415 source.Render.FontStyle = source.FontStyle;
1416 if (e.Property.Equals(FontWeightProperty))
1417 source.Render.FontWeigth = source.FontWeight;
1418 if (e.Property.Equals(FontSizeProperty))
1419 source.Render.FontSize = source.FontSize;
1420 if (e.Property.Equals(ForegroundProperty))
1421 source.Render.Foreground = D2DRenderBase.ToColor4(source.Foreground);
1422 if (e.Property.Equals(BackgroundProperty))
1423 source.Render.Background = D2DRenderBase.ToColor4(source.Background);
1424 if (e.Property.Equals(ControlCharProperty))
1425 source.Render.ControlChar = D2DRenderBase.ToColor4(source.ControlChar);
1426 if (e.Property.Equals(HilightProperty))
1427 source.Render.Hilight = D2DRenderBase.ToColor4(source.Hilight);
1428 if (e.Property.Equals(Keyword1Property))
1429 source.Render.Keyword1 = D2DRenderBase.ToColor4(source.Keyword1);
1430 if (e.Property.Equals(Keyword2Property))
1431 source.Render.Keyword2 = D2DRenderBase.ToColor4(source.Keyword2);
1432 if (e.Property.Equals(CommentProperty))
1433 source.Render.Comment = D2DRenderBase.ToColor4(source.Comment);
1434 if (e.Property.Equals(LiteralProperty))
1435 source.Render.Literal = D2DRenderBase.ToColor4(source.Literal);
1436 if (e.Property.Equals(URLProperty))
1437 source.Render.Url = D2DRenderBase.ToColor4(source.URL);
1438 if (e.Property.Equals(InsertCaretProperty))
1439 source.Render.InsertCaret = D2DRenderBase.ToColor4(source.InsertCaret);
1440 if (e.Property.Equals(OverwriteCaretProperty))
1441 source.Render.OverwriteCaret = D2DRenderBase.ToColor4(source.OverwriteCaret);
1442 if (e.Property.Equals(PaddingProperty))
1443 source.View.Padding = new Padding((int)source.Padding.Left, (int)source.Padding.Top, (int)source.Padding.Right, (int)source.Padding.Bottom);
1444 if (e.Property.Equals(LineMarkerProperty))
1445 source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);
1446 if (e.Property.Equals(ShowFullSpaceProperty))
1447 source.Render.ShowFullSpace = source.ShowFullSpace;
1448 if (e.Property.Equals(ShowHalfSpaceProperty))
1449 source.Render.ShowHalfSpace = source.ShowHalfSpace;
1450 if (e.Property.Equals(ShowTabProperty))
1451 source.Render.ShowTab = source.ShowTab;
1452 if (e.Property.Equals(ShowLineBreakProperty))
1453 source.Render.ShowLineBreak = source.ShowLineBreak;
1454 if (e.Property.Equals(UpdateAreaProperty))
1455 source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);
1456 if (e.Property.Equals(LineNumberProperty))
1457 source.Render.LineNumber = D2DRenderBase.ToColor4(source.LineNumber);
1465 /// コンテキストメニューが表示されるときに呼び出されます
1467 public event EventHandler<FooContextMenuEventArgs> ContextMenuOpening;
1473 internal Controller Controller
1477 return this._Controller;
1482 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1484 public TextAntialiasMode TextAntialiasMode
1486 get { return (TextAntialiasMode)GetValue(TextAntialiasModeProperty); }
1487 set { SetValue(TextAntialiasModeProperty, value); }
1491 /// TextAntialiasModeの依存プロパティを表す
1493 public static readonly DependencyProperty TextAntialiasModeProperty =
1494 DependencyProperty.Register("TextAntialiasMode", typeof(TextAntialiasMode), typeof(FooTextBox), new PropertyMetadata(TextAntialiasMode.Default, OnPropertyChanged));
1499 public IHilighter Hilighter
1501 get { return (IHilighter)GetValue(HilighterProperty); }
1502 set { SetValue(HilighterProperty, value); }
1506 /// Hilighterの依存プロパティを表す
1508 public static readonly DependencyProperty HilighterProperty =
1509 DependencyProperty.Register("Hilighter", typeof(IHilighter), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
1512 /// フォールティングを作成するインターフェイスを表す
1514 public IFoldingStrategy FoldingStrategy
1516 get { return (IFoldingStrategy)GetValue(FoldingStrategyProperty); }
1517 set { SetValue(FoldingStrategyProperty, value); }
1521 /// FoldingStrategyの依存プロパティ
1523 public static readonly DependencyProperty FoldingStrategyProperty =
1524 DependencyProperty.Register("FoldingStrategy", typeof(IFoldingStrategy), typeof(FooTextBox), new PropertyMetadata(null,OnPropertyChanged));
1529 public MarkerPatternSet MarkerPatternSet
1533 return this.Document.MarkerPatternSet;
1540 /// <remarks>切り替え後に再描写が行われます</remarks>
1541 public Document Document
1543 get { return (Document)GetValue(DocumentProperty); }
1544 set { SetValue(DocumentProperty, value); }
1547 // Using a DependencyProperty as the backing store for Document. This enables animation, styling, binding, etc...
1548 public static readonly DependencyProperty DocumentProperty =
1549 DependencyProperty.Register("Document", typeof(Document), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
1556 public LineToIndexTable LayoutLineCollection
1558 get { return this.View.LayoutLines; }
1564 public string SelectedText
1566 get { return (string)GetValue(SelectedTextProperty); }
1567 set { SetValue(SelectedTextProperty, value); }
1571 /// SelectedTextの依存プロパティを表す
1573 public static readonly DependencyProperty SelectedTextProperty =
1574 DependencyProperty.Register("SelectedText", typeof(string), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
1579 public IndentMode IndentMode
1581 get { return (IndentMode)GetValue(IndentModeProperty); }
1582 set { SetValue(IndentModeProperty, value); }
1586 /// IndentModeの依存プロパティを表す
1588 public static readonly DependencyProperty IndentModeProperty =
1589 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab,OnPropertyChanged));
1595 /// Lengthが0の場合はキャレット位置を表します。
1596 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1598 public TextRange Selection
1600 get { return (TextRange)GetValue(SelectionProperty); }
1601 set { SetValue(SelectionProperty, value); }
1605 /// Selectionの依存プロパティを表す
1607 public static readonly DependencyProperty SelectionProperty =
1608 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null, OnPropertyChanged));
1613 public double MagnificationPower
1615 get { return (double)GetValue(MagnificationPowerPropertyKey); }
1616 set { SetValue(MagnificationPowerPropertyKey, value); }
1622 public static readonly DependencyProperty MagnificationPowerPropertyKey =
1623 DependencyProperty.Register("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0, OnPropertyChanged));
1628 public TextPoint CaretPostion
1630 get { return (TextPoint)GetValue(CaretPostionPropertyKey); }
1631 set { SetValue(CaretPostionPropertyKey, value); }
1634 static readonly DependencyProperty CaretPostionPropertyKey =
1635 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(new TextPoint(), OnPropertyChanged));
1640 public new FlowDirection FlowDirection
1642 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1643 set { SetValue(FlowDirectionProperty, value); }
1647 /// レタリング方向を表す。これは依存プロパティです
1649 public new static readonly DependencyProperty FlowDirectionProperty =
1650 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight,OnPropertyChanged));
1655 public new FontFamily FontFamily
1657 get { return (FontFamily)GetValue(FontFamilyProperty); }
1658 set { SetValue(FontFamilyProperty, value); }
1662 /// FontFamilyの依存プロパティを表す
1664 public new static readonly DependencyProperty FontFamilyProperty =
1665 DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(FooTextBox), new PropertyMetadata(new FontFamily("Cambria"), OnPropertyChanged));
1670 public new double FontSize
1672 get { return (double)GetValue(FontSizeProperty); }
1673 set { SetValue(FontSizeProperty, value); }
1677 /// FontSizeの依存プロパティを表す
1679 public new static readonly DependencyProperty FontSizeProperty =
1680 DependencyProperty.Register("FontSize", typeof(double), typeof(FooTextBox), new PropertyMetadata(12.0,OnPropertyChanged));
1685 public new FontStyle FontStyle
1687 get { return (FontStyle)GetValue(FontStyleProperty); }
1688 set { SetValue(FontStyleProperty, value); }
1692 /// FontStyleの依存プロパティを表す
1694 public new static readonly DependencyProperty FontStyleProperty =
1695 DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(FooTextBox), new PropertyMetadata(FontStyle.Normal,OnPropertyChanged));
1700 public new FontWeight FontWeight
1702 get { return (FontWeight)GetValue(FontWeightProperty); }
1703 set { SetValue(FontWeightProperty, value); }
1707 /// FontWeigthの依存プロパティを表す
1709 public new static readonly DependencyProperty FontWeightProperty =
1710 DependencyProperty.Register("FontWeigth", typeof(FontWeight), typeof(FooTextBox), new PropertyMetadata(FontWeights.Normal,OnPropertyChanged));
1713 /// デフォルトの文字色を表す。これは依存プロパティです
1715 public new Windows.UI.Color Foreground
1717 get { return (Windows.UI.Color)GetValue(ForegroundProperty); }
1718 set { SetValue(ForegroundProperty, value); }
1722 /// Foregroundの依存プロパティを表す
1724 public new static readonly DependencyProperty ForegroundProperty =
1725 DependencyProperty.Register("Foreground", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1728 /// 背景色を表す。これは依存プロパティです
1730 public new Windows.UI.Color Background
1732 get { return (Windows.UI.Color)GetValue(BackgroundProperty); }
1733 set { SetValue(BackgroundProperty, value); }
1737 /// Backgroundの依存プロパティを表す
1739 public new static readonly DependencyProperty BackgroundProperty =
1740 DependencyProperty.Register("Background", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));
1743 /// コントロールコードの文字色を表す。これは依存プロパティです
1745 public Windows.UI.Color ControlChar
1747 get { return (Windows.UI.Color)GetValue(ControlCharProperty); }
1748 set { SetValue(ControlCharProperty, value); }
1752 /// ControlCharの依存プロパティを表す
1754 public static readonly DependencyProperty ControlCharProperty =
1755 DependencyProperty.Register("ControlChar", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1758 /// 選択時の背景色を表す。これは依存プロパティです
1760 public Windows.UI.Color Hilight
1762 get { return (Windows.UI.Color)GetValue(HilightProperty); }
1763 set { SetValue(HilightProperty, value); }
1767 /// Hilightの依存プロパティを表す
1769 public static readonly DependencyProperty HilightProperty =
1770 DependencyProperty.Register("Hilight", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DeepSkyBlue, OnPropertyChanged));
1773 /// キーワード1の文字色を表す。これは依存プロパティです
1775 public Windows.UI.Color Keyword1
1777 get { return (Windows.UI.Color)GetValue(Keyword1Property); }
1778 set { SetValue(Keyword1Property, value); }
1782 /// Keyword1の依存プロパティを表す
1784 public static readonly DependencyProperty Keyword1Property =
1785 DependencyProperty.Register("Keyword1", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1788 /// キーワード2の文字色を表す。これは依存プロパティです
1790 public Windows.UI.Color Keyword2
1792 get { return (Windows.UI.Color)GetValue(Keyword2Property); }
1793 set { SetValue(Keyword2Property, value); }
1797 /// Keyword2の依存プロパティを表す
1799 public static readonly DependencyProperty Keyword2Property =
1800 DependencyProperty.Register("Keyword2", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DarkCyan, OnPropertyChanged));
1803 /// コメントの文字色を表す。これは依存プロパティです
1805 public Windows.UI.Color Comment
1807 get { return (Windows.UI.Color)GetValue(CommentProperty); }
1808 set { SetValue(CommentProperty, value); }
1812 /// Commentの依存プロパティを表す
1814 public static readonly DependencyProperty CommentProperty =
1815 DependencyProperty.Register("Comment", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Green, OnPropertyChanged));
1818 /// 文字リテラルの文字色を表す。これは依存プロパティです
1820 public Windows.UI.Color Literal
1822 get { return (Windows.UI.Color)GetValue(LiteralProperty); }
1823 set { SetValue(LiteralProperty, value); }
1827 /// Literalの依存プロパティを表す
1829 public static readonly DependencyProperty LiteralProperty =
1830 DependencyProperty.Register("Literal", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Brown, OnPropertyChanged));
1833 /// URLの文字色を表す。これは依存プロパティです
1835 public Windows.UI.Color URL
1837 get { return (Windows.UI.Color)GetValue(URLProperty); }
1838 set { SetValue(URLProperty, value); }
1844 public static readonly DependencyProperty URLProperty =
1845 DependencyProperty.Register("URL", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1850 public Windows.UI.Color UpdateArea
1852 get { return (Windows.UI.Color)GetValue(UpdateAreaProperty); }
1853 set { SetValue(UpdateAreaProperty, value); }
1857 /// UpdateAreaの依存プロパティを表す
1859 public static readonly DependencyProperty UpdateAreaProperty =
1860 DependencyProperty.Register("UpdateArea", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen, OnPropertyChanged));
1865 public Windows.UI.Color LineMarker
1867 get { return (Windows.UI.Color)GetValue(LineMarkerProperty); }
1868 set { SetValue(LineMarkerProperty, value); }
1872 /// LineMarkerの依存プロパティを表す
1874 public static readonly DependencyProperty LineMarkerProperty =
1875 DependencyProperty.Register("LineMarker", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1878 /// 挿入モード時のキャレットの色を表す
1880 public Windows.UI.Color InsertCaret
1882 get { return (Windows.UI.Color)GetValue(InsertCaretProperty); }
1883 set { SetValue(InsertCaretProperty, value); }
1887 /// InsertCaretの依存プロパティを表す
1889 public static readonly DependencyProperty InsertCaretProperty =
1890 DependencyProperty.Register("InsertCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1893 /// 上書きモード時のキャレット職を表す
1895 public Windows.UI.Color OverwriteCaret
1897 get { return (Windows.UI.Color)GetValue(OverwriteCaretProperty); }
1898 set { SetValue(OverwriteCaretProperty, value); }
1902 /// OverwriteCaretの依存プロパティを表す
1904 public static readonly DependencyProperty OverwriteCaretProperty =
1905 DependencyProperty.Register("OverwriteCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1910 public Windows.UI.Color LineNumber
1912 get { return (Windows.UI.Color)GetValue(LineNumberProperty); }
1913 set { SetValue(LineNumberProperty, value); }
1917 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1919 public static readonly DependencyProperty LineNumberProperty =
1920 DependencyProperty.Register("LineNumber", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray,OnPropertyChanged));
1925 public new Thickness Padding
1927 get { return (Thickness)GetValue(PaddingProperty); }
1928 set { SetValue(PaddingProperty, value); }
1932 /// Paddingの依存プロパティを表す
1934 public new static readonly DependencyProperty PaddingProperty =
1935 DependencyProperty.Register("Padding", typeof(Thickness), typeof(FooTextBox), new PropertyMetadata(new Thickness(),OnPropertyChanged));
1938 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1940 public bool InsertMode
1942 get { return (bool)GetValue(InsertModeProperty); }
1943 set { SetValue(InsertModeProperty, value); }
1947 /// InsertModeの依存プロパティを表す
1949 public static readonly DependencyProperty InsertModeProperty =
1950 DependencyProperty.Register("InsertMode",
1953 new PropertyMetadata(true, OnPropertyChanged));
1956 /// タブの文字数を表す。これは依存プロパティです
1960 get { return (int)GetValue(TabCharsProperty); }
1961 set { SetValue(TabCharsProperty, value); }
1965 /// TabCharsの依存プロパティを表す
1967 public static readonly DependencyProperty TabCharsProperty =
1968 DependencyProperty.Register("TabChars",
1971 new PropertyMetadata(4, OnPropertyChanged));
1974 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1976 public bool RectSelectMode
1978 get { return (bool)GetValue(RectSelectModeProperty); }
1979 set { SetValue(RectSelectModeProperty, value); }
1983 /// RectSelectModeの依存プロパティを表す
1985 public static readonly DependencyProperty RectSelectModeProperty =
1986 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1992 /// 変更した場合、レイアウトの再構築を行う必要があります
1994 public LineBreakMethod LineBreakMethod
1996 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1997 set { SetValue(LineBreakProperty, value); }
2001 /// LineBreakMethodの依存プロパティを表す
2003 public static readonly DependencyProperty LineBreakProperty =
2004 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None, OnPropertyChanged));
2008 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
2011 /// 変更した場合、レイアウトの再構築を行う必要があります
2013 public int LineBreakCharCount
2015 get { return (int)GetValue(LineBreakCharCountProperty); }
2016 set { SetValue(LineBreakCharCountProperty, value); }
2020 /// LineBreakCharCountの依存プロパティを表す
2022 public static readonly DependencyProperty LineBreakCharCountProperty =
2023 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80, OnPropertyChanged));
2026 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
2028 public bool DrawCaret
2030 get { return (bool)GetValue(DrawCaretProperty); }
2031 set { SetValue(DrawCaretProperty, value); }
2035 /// DrawCaretの依存プロパティを表す
2037 public static readonly DependencyProperty DrawCaretProperty =
2038 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new PropertyMetadata(true, OnPropertyChanged));
2042 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
2044 public bool DrawCaretLine
2046 get { return (bool)GetValue(DrawCaretLineProperty); }
2047 set { SetValue(DrawCaretLineProperty, value); }
2051 /// DrawCaretLineの依存プロパティを表す
2053 public static readonly DependencyProperty DrawCaretLineProperty =
2054 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2057 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
2059 public bool DrawLineNumber
2061 get { return (bool)GetValue(DrawLineNumberProperty); }
2062 set { SetValue(DrawLineNumberProperty, value); }
2066 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
2068 public bool DrawRuler
2070 get { return (bool)GetValue(DrawRulerProperty); }
2071 set { SetValue(DrawRulerProperty, value); }
2075 /// DrawRulerの依存プロパティを表す
2077 public static readonly DependencyProperty DrawRulerProperty =
2078 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2082 /// DrawLineNumberの依存プロパティを表す
2084 public static readonly DependencyProperty DrawLineNumberProperty =
2085 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2088 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
2092 get { return (bool)GetValue(MarkURLProperty); }
2093 set { SetValue(MarkURLProperty, value); }
2097 /// MarkURLの依存プロパティを表す
2099 public static readonly DependencyProperty MarkURLProperty =
2100 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2103 /// 全角スペースを表示するなら真。そうでないなら偽
2105 public bool ShowFullSpace
2107 get { return (bool)GetValue(ShowFullSpaceProperty); }
2108 set { SetValue(ShowFullSpaceProperty, value); }
2112 /// ShowFullSpaceの依存プロパティを表す
2114 public static readonly DependencyProperty ShowFullSpaceProperty =
2115 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2118 /// 半角スペースを表示するなら真。そうでないなら偽
2120 public bool ShowHalfSpace
2122 get { return (bool)GetValue(ShowHalfSpaceProperty); }
2123 set { SetValue(ShowHalfSpaceProperty, value); }
2127 /// ShowHalfSpaceの依存プロパティを表す
2129 public static readonly DependencyProperty ShowHalfSpaceProperty =
2130 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2133 /// タブを表示するなら真。そうでないなら偽
2137 get { return (bool)GetValue(ShowTabProperty); }
2138 set { SetValue(ShowTabProperty, value); }
2142 /// ShowTabの依存プロパティを表す
2144 public static readonly DependencyProperty ShowTabProperty =
2145 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2148 /// 改行マークを表示するなら真。そうでないなら偽
2150 public bool ShowLineBreak
2152 get { return (bool)GetValue(ShowLineBreakProperty); }
2153 set { SetValue(ShowLineBreakProperty, value); }
2157 /// ShowLineBreakの依存プロパティを表す
2159 public static readonly DependencyProperty ShowLineBreakProperty =
2160 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false,OnPropertyChanged));
2166 /// コンテキストメニューのイベントデーターを表す
2168 public class FooContextMenuEventArgs
2171 /// 処理済みなら真。そうでないなら偽
2173 public bool Handled = false;
2175 /// コンテキストメニューを表示すべき座標を表す
2177 public Windows.Foundation.Point Postion;
2181 /// <param name="pos"></param>
2182 public FooContextMenuEventArgs(Windows.Foundation.Point pos)