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 = 96;
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, 5, 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.GettingFocus += FooTextBox_GettingFocus;
115 this.LosingFocus += FooTextBox_LosingFocus;
117 this.SizeChanged += FooTextBox_SizeChanged;
119 this.Loaded += FooTextBox_Loaded;
133 public void Dispose()
136 GC.SuppressFinalize(this);
139 bool Disposed = false;
140 private void Dispose(bool disposing)
147 this.Render.Dispose();
154 /// <param name="start">開始インデックス</param>
155 /// <param name="length">長さ</param>
156 public void Select(int start, int length)
158 this.Document.Select(start, length);
162 /// キャレットを指定した行に移動させます
164 /// <param name="index">インデックス</param>
165 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
166 public void JumpCaret(int index)
168 this._Controller.JumpCaret(index);
171 /// キャレットを指定した行と桁に移動させます
173 /// <param name="row">行番号</param>
174 /// <param name="col">桁</param>
175 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
176 public void JumpCaret(int row, int col)
178 this._Controller.JumpCaret(row, col);
182 /// 選択中のテキストをクリップボードにコピーします
186 string text = this._Controller.SelectedText;
187 if (text != null && text != string.Empty)
189 DataPackage dataPackage = new DataPackage();
190 dataPackage.RequestedOperation = DataPackageOperation.Copy;
191 dataPackage.SetText(text);
193 Clipboard.SetContent(dataPackage);
198 /// 選択中のテキストをクリップボードに切り取ります
202 string text = this._Controller.SelectedText;
203 if (text != null && text != string.Empty)
205 DataPackage dataPackage = new DataPackage();
206 dataPackage.RequestedOperation = DataPackageOperation.Copy;
207 dataPackage.SetText(text);
209 Clipboard.SetContent(dataPackage);
211 this._Controller.SelectedText = "";
218 public async Task PasteAsync()
220 var dataPackageView = Clipboard.GetContent();
221 if (dataPackageView.Contains(StandardDataFormats.Text))
225 this._Controller.SelectedText = await dataPackageView.GetTextAsync();
228 System.Diagnostics.Debug.WriteLine("past error:" + e.Message);
236 public void SelectAll()
238 this.Document.Select(0, this.Document.Length);
244 public void DeSelectAll()
246 this._Controller.DeSelectAll();
252 /// <param name="tp">テキストポイント</param>
253 /// <returns>座標</returns>
254 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
255 public Windows.Foundation.Point GetPostionFromTextPoint(TextPoint tp)
257 if (this.Document.FireUpdateEvent == false)
258 throw new InvalidOperationException("");
259 return this.View.GetPostionFromTextPoint(tp);
263 /// 対応するテキストポイントを返します
265 /// <param name="p">クライアント領域の原点を左上とする座標</param>
266 /// <returns>テキストポイント</returns>
267 public TextPoint GetTextPointFromPostion(Windows.Foundation.Point p)
269 if (this.Document.FireUpdateEvent == false)
270 throw new InvalidOperationException("");
271 return this.View.GetTextPointFromPostion(p);
277 /// <param name="row">レイアウト行</param>
278 /// <returns>行の高さ</returns>
279 public double GetLineHeight(int row)
281 if (this.Document.FireUpdateEvent == false)
282 throw new InvalidOperationException("");
283 return this.View.LayoutLines.GetLayout(row).Height; ;
287 /// インデックスに対応する座標を得ます
289 /// <param name="index">インデックス</param>
290 /// <returns>座標を返す</returns>
291 public Windows.Foundation.Point GetPostionFromIndex(int index)
293 if (this.Document.FireUpdateEvent == false)
294 throw new InvalidOperationException("");
295 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
296 return this.View.GetPostionFromTextPoint(tp);
302 /// <param name="p">座標</param>
303 /// <returns>インデックスを返す</returns>
304 public int GetIndexFromPostion(Windows.Foundation.Point p)
306 if (this.Document.FireUpdateEvent == false)
307 throw new InvalidOperationException("");
308 TextPoint tp = this.View.GetTextPointFromPostion(p);
309 return this.View.GetIndexFromLayoutLine(tp);
316 public void Refresh()
318 this.Refresh(this.View.PageBound);
322 /// レイアウト行をすべて破棄し、再度レイアウトを行う
324 public void PerfomLayouts()
326 this.Document.PerformLayout();
332 /// <param name="row">行</param>
333 /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
334 public void ScrollIntoView(int row, bool alignTop)
336 this.View.ScrollIntoView(row, alignTop);
340 /// ファイルからドキュメントを構築する
342 /// <param name="sr">StremReader</param>
343 /// <returns>Taskオブジェクト</returns>
344 public async Task LoadFileAsync(System.IO.StreamReader sr, System.Threading.CancellationTokenSource token)
346 await this.Document.LoadAsync(sr, token);
349 private void Document_LoadProgress(object sender, ProgressEventArgs e)
351 if(e.state == ProgressState.Start)
353 this.IsEnabled = false;
355 else if(e.state == ProgressState.Complete)
357 CoreTextRange modified_range = new CoreTextRange();
358 modified_range.StartCaretPosition = 0;
359 modified_range.EndCaretPosition = 0;
360 //キャレット位置はロード前と同じにしないと違和感を感じる
361 if (this.textEditContext != null)
362 this.textEditContext.NotifyTextChanged(modified_range, this.Document.Length, modified_range);
364 if (this.verticalScrollBar != null)
365 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
366 this.IsEnabled = true;
367 this.Refresh(this.View.PageBound);
372 /// ドキュメントの内容をファイルに保存する
374 /// <param name="sw">StreamWriter</param>
375 /// <param name="enc">エンコード</param>
376 /// <returns>Taskオブジェクト</returns>
377 public async Task SaveFile(System.IO.StreamWriter sw, System.Threading.CancellationTokenSource token)
379 await this.Document.SaveAsync(sw, token);
394 async Task PasteCommand()
396 await this.PasteAsync();
406 protected override Windows.UI.Xaml.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
408 this.peer = new FooTextBoxAutomationPeer(this);
413 protected override void OnApplyTemplate()
415 base.OnApplyTemplate();
417 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
420 Grid.SetRow(this.rectangle, 0);
421 Grid.SetColumn(this.rectangle, 0);
422 grid.Children.Add(this.rectangle);
425 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
426 if (this.horizontalScrollBar != null)
428 this.horizontalScrollBar.SmallChange = 10;
429 this.horizontalScrollBar.LargeChange = 100;
430 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
431 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
433 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
434 if (this.verticalScrollBar != null)
436 this.verticalScrollBar.SmallChange = 1;
437 this.verticalScrollBar.LargeChange = 10;
438 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
439 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
443 private void FooTextBox_LosingFocus(UIElement sender, LosingFocusEventArgs args)
445 this.RemoveTextContext();
447 System.Diagnostics.Debug.WriteLine("losing focus");
450 private async void FooTextBox_GettingFocus(UIElement sender, GettingFocusEventArgs args)
452 System.Diagnostics.Debug.WriteLine("getting focus");
453 if (this.textServiceManager == null)
455 await Task.Delay(500);
456 this.textServiceManager = CoreTextServicesManager.GetForCurrentView();
457 this.textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;
460 this.CreateTextContext();
464 protected override void OnGotFocus(RoutedEventArgs e)
468 System.Diagnostics.Debug.WriteLine("got focus");
470 this.View.IsFocused = true;
471 this.timer.Interval = new TimeSpan(0, 0, 0, 0, Interval);
475 private void TextServiceManager_InputLanguageChanged(CoreTextServicesManager sender, object args)
477 System.Diagnostics.Debug.WriteLine("input language changed input script:"+ this.textServiceManager.InputLanguage.Script);
478 this.RemoveTextContext();
479 this.CreateTextContext();
483 protected override void OnLostFocus(RoutedEventArgs e)
487 System.Diagnostics.Debug.WriteLine("lost focus");
489 this.View.IsFocused = false;
490 this.Refresh(this.View.PageBound);
491 this.timer.Interval = new TimeSpan(0, 0, 0, 0, IntervalWhenLostFocus);
494 private void CreateTextContext()
496 if(this.textServiceManager != null)
498 this.textEditContext = this.textServiceManager.CreateEditContext();
499 this.textEditContext.InputScope = CoreTextInputScope.Text;
500 this.textEditContext.CompositionStarted += TextEditContext_CompositionStarted;
501 this.textEditContext.CompositionCompleted += TextEditContext_CompositionCompleted;
502 this.textEditContext.LayoutRequested += TextEditContext_LayoutRequested;
503 this.textEditContext.TextUpdating += TextEditContext_TextUpdating;
504 this.textEditContext.TextRequested += TextEditContext_TextRequested;
505 this.textEditContext.SelectionRequested += TextEditContext_SelectionRequested;
506 this.textEditContext.SelectionUpdating += TextEditContext_SelectionUpdating;
507 this.textEditContext.FormatUpdating += TextEditContext_FormatUpdating;
508 this.textEditContext.FocusRemoved += TextEditContext_FocusRemoved;
509 this.textEditContext.NotifyFocusLeaveCompleted += TextEditContext_NotifyFocusLeaveCompleted;
510 this.textEditContext.NotifyFocusEnter();
514 private void RemoveTextContext()
516 if(this.textEditContext != null)
518 this.textEditContext.CompositionStarted -= TextEditContext_CompositionStarted;
519 this.textEditContext.CompositionCompleted -= TextEditContext_CompositionCompleted;
520 this.textEditContext.LayoutRequested -= TextEditContext_LayoutRequested;
521 this.textEditContext.TextUpdating -= TextEditContext_TextUpdating;
522 this.textEditContext.TextRequested -= TextEditContext_TextRequested;
523 this.textEditContext.SelectionRequested -= TextEditContext_SelectionRequested;
524 this.textEditContext.SelectionUpdating -= TextEditContext_SelectionUpdating;
525 this.textEditContext.FormatUpdating -= TextEditContext_FormatUpdating;
526 this.textEditContext.FocusRemoved -= TextEditContext_FocusRemoved;
527 this.textEditContext.NotifyFocusLeaveCompleted -= TextEditContext_NotifyFocusLeaveCompleted;
528 this.textEditContext.NotifyFocusLeave();
529 this.textEditContext = null;
534 protected override async void OnKeyDown(KeyRoutedEventArgs e)
536 bool isControlPressed = this.IsModiferKeyPressed(VirtualKey.Control);
537 bool isShiftPressed = this.IsModiferKeyPressed(VirtualKey.Shift);
538 bool isMovedCaret = false;
540 var autocomplete = this.Document.AutoComplete as AutoCompleteBox;
541 if (autocomplete != null && autocomplete.ProcessKeyDown(this, e, isControlPressed, isShiftPressed))
547 this._Controller.MoveCaretVertical(-1, isShiftPressed);
552 case VirtualKey.Down:
553 this._Controller.MoveCaretVertical(+1, isShiftPressed);
558 case VirtualKey.Left:
559 this._Controller.MoveCaretHorizontical(-1, isShiftPressed, isControlPressed);
564 case VirtualKey.Right:
565 this._Controller.MoveCaretHorizontical(1, isShiftPressed, isControlPressed);
570 case VirtualKey.PageUp:
571 this._Controller.Scroll(ScrollDirection.Up, this.View.LineCountOnScreen, isShiftPressed, true);
575 case VirtualKey.PageDown:
576 this._Controller.Scroll(ScrollDirection.Down, this.View.LineCountOnScreen, isShiftPressed, true);
580 case VirtualKey.Home:
581 if (isControlPressed)
582 this._Controller.JumpToHead(isShiftPressed);
584 this.Controller.JumpToLineHead(this.Document.CaretPostion.row,isShiftPressed);
589 if (isControlPressed)
590 this._Controller.JumpToEnd(isShiftPressed);
592 this.Controller.JumpToLineEnd(this.Document.CaretPostion.row,isShiftPressed);
597 if (!isControlPressed)
599 if (this._Controller.SelectionLength == 0)
600 this._Controller.DoInputChar('\t');
601 else if (isShiftPressed)
602 this._Controller.DownIndent();
604 this._Controller.UpIndent();
609 case VirtualKey.Enter:
610 this._Controller.DoEnterAction();
614 case VirtualKey.Insert:
615 if(this.View.InsertMode)
616 this.View.InsertMode = false;
618 this.View.InsertMode = true;
623 if (isControlPressed)
631 if (isControlPressed)
633 if (this._Controller.RectSelection)
634 this._Controller.RectSelection = false;
636 this._Controller.RectSelection = true;
642 if (isControlPressed)
649 if (isControlPressed)
656 if (isControlPressed)
658 await this.PasteCommand();
663 if (isControlPressed)
665 this.Document.UndoManager.redo();
671 if (isControlPressed)
673 this.Document.UndoManager.undo();
678 case VirtualKey.Back:
679 this._Controller.DoBackSpaceAction();
683 case VirtualKey.Delete:
684 this._Controller.DoDeleteAction();
690 if (isMovedCaret && this.peer != null)
691 this.peer.OnNotifyCaretChanged();
697 protected override void OnPointerPressed(PointerRoutedEventArgs e)
699 System.Diagnostics.Debug.WriteLine("pointer pressed");
700 this.CapturePointer(e.Pointer);
701 this.gestureRecongnizer.ProcessDownEvent(e.GetCurrentPoint(this));
706 protected override void OnPointerMoved(PointerRoutedEventArgs e)
708 System.Diagnostics.Debug.WriteLine("pointer moved");
711 this.gestureRecongnizer.ProcessMoveEvents(e.GetIntermediatePoints(this));
712 }catch(System.Runtime.InteropServices.COMException ex)
714 //ピンチズームでこの例外が発生するが、回避できない
715 System.Diagnostics.Debug.WriteLine("expection:" + ex);
719 if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
721 Point p = e.GetCurrentPoint(this).Position;
722 if (this.View.HitTextArea(p.X, p.Y))
724 TextPoint tp = this.View.GetTextPointFromPostion(p);
725 if (this._Controller.IsMarker(tp, HilightType.Url))
726 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Hand, 101);
728 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.IBeam, 101);
732 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 101);
738 protected override void OnPointerReleased(PointerRoutedEventArgs e)
740 System.Diagnostics.Debug.WriteLine("pointer released");
741 this.gestureRecongnizer.ProcessUpEvent(e.GetCurrentPoint(this));
746 protected override void OnPointerCanceled(PointerRoutedEventArgs e)
748 System.Diagnostics.Debug.WriteLine("pointer canceled");
749 this.gestureRecongnizer.CompleteGesture();
754 protected override void OnPointerWheelChanged(PointerRoutedEventArgs e)
756 System.Diagnostics.Debug.WriteLine("pointer wheelchanged");
757 bool shift = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Shift) ==
758 Windows.System.VirtualKeyModifiers.Shift;
759 bool ctrl = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Control) ==
760 Windows.System.VirtualKeyModifiers.Control;
761 this.gestureRecongnizer.ProcessMouseWheelEvent(e.GetCurrentPoint(this), shift, ctrl);
765 private void TextEditContext_FormatUpdating(CoreTextEditContext sender, CoreTextFormatUpdatingEventArgs args)
767 if (this.Document.Length == 0 || args.IsCanceled)
769 args.Result = CoreTextFormatUpdatingResult.Failed;
772 System.Diagnostics.Debug.WriteLine("core text format updating range({0}-{1}) underline type:{2} underline color:{3} reason:{4} textcolor:{5} background:{6}",
773 args.Range.StartCaretPosition,
774 args.Range.EndCaretPosition,
781 HilightType type = HilightType.None;
782 Color color = new Color(this.Foreground.A,this.Foreground.R,this.Foreground.G,this.Foreground.R);
783 bool isBoldLine = false;
784 switch (args.UnderlineType)
786 case UnderlineType.Dotted:
787 type = HilightType.Dot;
789 case UnderlineType.Single:
790 type = HilightType.Sold;
792 case UnderlineType.Dash:
793 type = HilightType.Dash;
795 case UnderlineType.Wave:
796 type = HilightType.Squiggle;
798 case UnderlineType.Thin:
799 type = HilightType.Sold;
801 case UnderlineType.Thick:
802 type = HilightType.Sold;
806 int start = args.Range.StartCaretPosition;
807 int lengt = args.Range.EndCaretPosition - args.Range.StartCaretPosition;
808 this.Document.SetMarker(MarkerIDs.IME, Marker.Create(start, lengt, type, color, isBoldLine));
810 if (args.Reason == CoreTextFormatUpdatingReason.CompositionTargetConverted)
812 this.View.AdjustSrc(args.Range.StartCaretPosition);
816 args.Result = CoreTextFormatUpdatingResult.Succeeded;
819 private void TextEditContext_TextRequested(CoreTextEditContext sender, CoreTextTextRequestedEventArgs args)
821 CoreTextTextRequest req = args.Request;
823 if (this.Document.Length == 0 || req.IsCanceled)
828 int start = req.Range.StartCaretPosition;
829 int end = req.Range.EndCaretPosition;
830 if (end > this.Document.Length)
831 end = this.Document.Length;
833 int length = end - start;
835 System.Diagnostics.Debug.WriteLine("req text start:{0} length:{1}", start, length);
837 //キャレット位置も含むので+1する必要はない
838 req.Text = this.Document.ToString(start,length);
841 private void TextEditContext_LayoutRequested(CoreTextEditContext sender, CoreTextLayoutRequestedEventArgs args)
844 Point startPos, endPos;
845 int i_startIndex = args.Request.Range.StartCaretPosition;
846 int i_endIndex = args.Request.Range.EndCaretPosition;
848 if(args.Request.IsCanceled)
853 System.Diagnostics.Debug.WriteLine("core text layoutreq range({0}-{1})",i_startIndex,i_endIndex);
855 if (i_startIndex != -1 && i_endIndex != -1)
857 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
859 double scale = Util.GetScale();
861 //Core.Textはスクリーン座標に変換してくれないので自前で変換する(しかも、デバイス依存の座標で返さないといけない)
862 var screenStartPos = Util.GetScreentPoint(startPos, this).Scale(scale);
863 var screenEndPos = Util.GetScreentPoint(endPos, this).Scale(scale);
864 args.Request.LayoutBounds.TextBounds = new Rect(
867 Math.Max(0,screenEndPos.X - screenStartPos.X), //折り返されている場合、負になることがある
868 screenEndPos.Y - screenStartPos.Y);
872 var controlTopLeft = new Point(0, 0);
873 var controlBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
875 var gt = this.TransformToVisual(Window.Current.Content);
876 controlTopLeft = gt.TransformPoint(controlTopLeft);
877 controlBottomRight = gt.TransformPoint(controlBottomRight);
879 args.Request.LayoutBounds.ControlBounds = new Rect(
882 controlBottomRight.X - controlTopLeft.X,
883 controlBottomRight.Y - controlTopLeft.Y
887 private void TextEditContext_SelectionRequested(CoreTextEditContext sender, CoreTextSelectionRequestedEventArgs args)
889 if(args.Request.IsCanceled || this.Document.Length == 0)
893 TextRange currentSelection = new TextRange();
894 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out currentSelection);
896 CoreTextRange currentSelectionRange = new CoreTextRange();
897 currentSelectionRange.StartCaretPosition = currentSelection.Index;
898 currentSelectionRange.EndCaretPosition = currentSelection.Index + currentSelection.Length;
899 args.Request.Selection = currentSelectionRange;
900 System.Diagnostics.Debug.WriteLine("req selection start:{0} end:{1}", currentSelectionRange.StartCaretPosition, currentSelectionRange.EndCaretPosition);
903 private void TextEditContext_SelectionUpdating(CoreTextEditContext sender, CoreTextSelectionUpdatingEventArgs args)
905 if(this.Document.Length == 0 || args.IsCanceled)
907 args.Result = CoreTextSelectionUpdatingResult.Failed;
910 CoreTextRange sel = args.Selection;
911 System.Diagnostics.Debug.WriteLine("update selection start:{0} end:{1}", sel.StartCaretPosition, sel.EndCaretPosition);
912 TextStoreHelper.SetSelectionIndex(this.Controller, this.View, sel.StartCaretPosition, sel.EndCaretPosition);
913 args.Result = CoreTextSelectionUpdatingResult.Succeeded;
917 private void TextEditContext_TextUpdating(CoreTextEditContext sender, CoreTextTextUpdatingEventArgs args)
919 this.nowCompstion = true;
921 System.Diagnostics.Debug.WriteLine("update text (modify start:{0} end:{1}) text:{2} (new sel start:{0} end:{1})",
922 args.Range.StartCaretPosition,
923 args.Range.EndCaretPosition,
925 args.NewSelection.StartCaretPosition,
926 args.NewSelection.EndCaretPosition);
927 bool isTip = args.InputLanguage.Script == "Latan";
928 CoreTextRange sel = args.Range;
929 TextStoreHelper.SetSelectionIndex(this.Controller, this.View, sel.StartCaretPosition, sel.EndCaretPosition);
930 TextStoreHelper.InsertTextAtSelection(this._Controller, args.Text, isTip);
932 args.Result = CoreTextTextUpdatingResult.Succeeded;
934 this.nowCompstion = false;
937 private void TextEditContext_CompositionCompleted(CoreTextEditContext sender, CoreTextCompositionCompletedEventArgs args)
939 System.Diagnostics.Debug.WriteLine("end compostion");
940 TextStoreHelper.EndCompostion(this.Document);
941 this.Document.RemoveAllMarker(MarkerIDs.IME);
945 private void TextEditContext_CompositionStarted(CoreTextEditContext sender, CoreTextCompositionStartedEventArgs args)
947 System.Diagnostics.Debug.WriteLine("start compstion");
948 TextStoreHelper.StartCompstion(this.Document);
951 private void TextEditContext_NotifyFocusLeaveCompleted(CoreTextEditContext sender, object args)
953 System.Diagnostics.Debug.WriteLine("notify focus leaved");
956 private void TextEditContext_FocusRemoved(CoreTextEditContext sender, object args)
958 System.Diagnostics.Debug.WriteLine("focus leaved");
961 void Controller_SelectionChanged(object sender, EventArgs e)
963 if (this._Controller == null)
967 this.nowCaretMove = true;
968 SetValue(SelectedTextProperty, this._Controller.SelectedText);
969 SetValue(CaretPostionPropertyKey, this.Document.CaretPostion);
970 this.nowCaretMove = false;
972 if(!this.nowCompstion)
974 TextRange currentSelection = new TextRange();
975 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out currentSelection);
977 CoreTextRange currentSelectionRange = new CoreTextRange();
978 currentSelectionRange.StartCaretPosition = currentSelection.Index;
979 currentSelectionRange.EndCaretPosition = currentSelection.Index + currentSelection.Length;
981 System.Diagnostics.Debug.WriteLine("notify selection start:{0} end:{1}", currentSelectionRange.StartCaretPosition, currentSelectionRange.EndCaretPosition);
983 if (this.textEditContext != null)
984 this.textEditContext.NotifySelectionChanged(currentSelectionRange);
988 Gripper hittedGripper;
989 void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)
991 //Updateedの段階でヒットテストしてしまうとグリッパーを触ってもヒットしないことがある
992 this.hittedGripper = this.View.HitGripperFromPoint(e.Position);
995 private void GestureRecongnizer_ManipulationInertiaStarting(GestureRecognizer sender, ManipulationInertiaStartingEventArgs args)
997 //sender.InertiaTranslationDeceleration = 0.001f;
998 //sender.InertiaExpansionDeceleration = 100.0f * 96.0f / 1000.0f;
999 //sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
1002 void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
1004 if (e.Delta.Scale < 1)
1006 double newSize = this.Render.FontSize - 1;
1009 this.Render.FontSize = newSize;
1011 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
1015 if (e.Delta.Scale > 1)
1017 double newSize = this.Render.FontSize + 1;
1020 this.Render.FontSize = newSize;
1022 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
1026 if (this._Controller.MoveCaretAndGripper(e.Position, this.hittedGripper))
1028 #if ENABLE_AUTMATION
1029 if (this.peer != null)
1030 this.peer.OnNotifyCaretChanged();
1036 Point translation = e.Delta.Translation;
1038 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
1039 if (Math.Abs(e.Cumulative.Translation.X) < Math.Abs(e.Cumulative.Translation.Y))
1041 int deltay = (int)Math.Abs(Math.Ceiling(translation.Y));
1042 if (translation.Y < 0)
1043 this._Controller.ScrollByPixel(ScrollDirection.Down, deltay, false, false);
1045 this._Controller.ScrollByPixel(ScrollDirection.Up, deltay, false, false);
1050 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
1053 if (translation.X < 0)
1054 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
1056 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
1061 void gestureRecongnizer_ManipulationCompleted(GestureRecognizer sender, ManipulationCompletedEventArgs e)
1065 async void gestureRecongnizer_RightTapped(GestureRecognizer sender, RightTappedEventArgs e)
1067 ResourceMap map = ResourceManager.Current.MainResourceMap.GetSubtree("FooEditEngine.UWP/Resources");
1068 ResourceContext context = ResourceContext.GetForCurrentView();
1069 if (this.View.HitTextArea(e.Position.X, e.Position.Y))
1071 FooContextMenuEventArgs args = new FooContextMenuEventArgs(e.Position);
1072 if (this.ContextMenuOpening != null)
1073 this.ContextMenuOpening(this, args);
1076 PopupMenu ContextMenu = new PopupMenu();
1077 ContextMenu.Commands.Add(new UICommand(map.GetValue("CopyMenuName", context).ValueAsString, (command) =>
1081 ContextMenu.Commands.Add(new UICommand(map.GetValue("CutMenuName", context).ValueAsString, (command) =>
1085 ContextMenu.Commands.Add(new UICommand(map.GetValue("PasteMenuName", context).ValueAsString, async (command) =>
1087 await this.PasteCommand();
1089 if (this._Controller.RectSelection)
1091 ContextMenu.Commands.Add(new UICommand(map.GetValue("LineSelectMenuName", context).ValueAsString, (command) =>
1093 this._Controller.RectSelection = false;
1098 ContextMenu.Commands.Add(new UICommand(map.GetValue("RectSelectMenuName", context).ValueAsString, (command) =>
1100 this._Controller.RectSelection = true;
1103 var windowStartPos = Util.GetPointInWindow(e.Position, this);
1104 await ContextMenu.ShowAsync(windowStartPos);
1109 long lastDouleTapTick;
1110 const long allowTripleTapTimeSpan = 500;
1111 void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)
1113 bool touched = e.PointerDeviceType == PointerDeviceType.Touch;
1114 this.Document.SelectGrippers.BottomLeft.Enabled = false;
1115 this.Document.SelectGrippers.BottomRight.Enabled = touched;
1116 this.JumpCaret(e.Position);
1117 if(e.TapCount == 1 && System.DateTime.Now.Ticks - lastDouleTapTick < allowTripleTapTimeSpan * 10000) //トリプルタップ
1119 //タッチスクリーンで行選択した場合、アンカーインデックスを単語の先頭にしないとバグる
1120 this.Document.SelectGrippers.BottomLeft.Enabled = touched;
1121 this.Document.SelectLine(this.Controller.SelectionStart, touched);
1123 else if(e.TapCount == 2) //ダブルタップ
1125 //タッチスクリーンで単語選択した場合、アンカーインデックスを単語の先頭にしないとバグる
1126 this.Document.SelectGrippers.BottomLeft.Enabled = touched;
1127 if (e.Position.X < this.Render.TextArea.X)
1128 this.Document.SelectLine(this.Controller.SelectionStart, touched);
1130 this.Document.SelectWord(this.Controller.SelectionStart, touched);
1131 this.lastDouleTapTick = System.DateTime.Now.Ticks;
1136 void JumpCaret(Point p)
1138 TextPoint tp = this.View.GetTextPointFromPostion(p);
1139 if (tp == TextPoint.Null)
1142 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
1144 FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
1145 if (foldingData != null)
1147 if (foldingData.Expand)
1148 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
1150 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
1151 this._Controller.JumpCaret(foldingData.Start, false);
1155 this._Controller.JumpCaret(tp.row, tp.col, false);
1157 #if ENABLE_AUTMATION
1158 if (this.peer != null)
1159 this.peer.OnNotifyCaretChanged();
1161 this.View.IsFocused = true;
1162 this.Focus(FocusState.Programmatic);
1166 void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)
1168 Point p = e.Position;
1169 TextPointSearchRange searchRange;
1170 if (this.View.HitTextArea(p.X, p.Y))
1171 searchRange = TextPointSearchRange.TextAreaOnly;
1172 else if (this._Controller.SelectionLength > 0)
1173 searchRange = TextPointSearchRange.Full;
1176 TextPoint tp = this.View.GetTextPointFromPostion(p, searchRange);
1177 this._Controller.MoveCaretAndSelect(tp, this.IsModiferKeyPressed(VirtualKey.LeftControl));
1178 #if ENABLE_AUTMATION
1179 if (this.peer != null)
1180 this.peer.OnNotifyCaretChanged();
1185 bool IsModiferKeyPressed(VirtualKey key)
1187 CoreVirtualKeyStates state = Window.Current.CoreWindow.GetKeyState(key);
1188 return (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
1190 void Refresh(Rectangle updateRect)
1192 if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0 || this.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
1195 this.Render.DrawContent(this.View, this.IsEnabled, updateRect);
1197 this.Document.IsRequestRedraw = false;
1201 bool Resize(double width, double height)
1203 if (width == 0 || height == 0)
1204 throw new ArgumentOutOfRangeException();
1205 if (this.Render.Resize(this.rectangle, width, height))
1207 this.View.PageBound = new Rectangle(0, 0, width, height);
1209 if (this.horizontalScrollBar != null)
1211 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
1212 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1214 if (this.verticalScrollBar != null)
1216 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
1217 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1224 void View_SrcChanged(object sender, EventArgs e)
1226 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1228 EditView view = this.View;
1229 if (view.Src.Row > this.verticalScrollBar.Maximum)
1230 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
1231 double absoulteX = Math.Abs(view.Src.X);
1232 if (absoulteX > this.horizontalScrollBar.Maximum)
1233 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1234 if (view.Src.Row != this.verticalScrollBar.Value)
1235 this.verticalScrollBar.Value = view.Src.Row;
1236 if (view.Src.X != this.horizontalScrollBar.Value)
1237 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1240 void FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)
1242 if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))
1245 this.Refresh(this.View.PageBound);
1249 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1251 if (this.horizontalScrollBar == null)
1254 if (this.FlowDirection == FlowDirection.LeftToRight)
1255 toX = this.horizontalScrollBar.Value;
1257 toX = -this.horizontalScrollBar.Value;
1258 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
1262 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1264 if (this.verticalScrollBar == null)
1266 int newRow = (int)this.verticalScrollBar.Value;
1267 if (newRow >= this.View.LayoutLines.Count)
1269 this._Controller.Scroll(this.View.Src.X, newRow, false, false);
1273 void Document_Update(object sender, DocumentUpdateEventArgs e)
1275 if (e.type == UpdateType.Replace && !this.nowCompstion)
1277 CoreTextRange oldTextRange = new CoreTextRange();
1278 oldTextRange.StartCaretPosition = e.startIndex;
1279 oldTextRange.EndCaretPosition = e.startIndex;
1280 //削除する範囲が1以上の場合、ドキュメントを飛び越えることはできない
1281 //https://msdn.microsoft.com/en-us/windows/uwp/input-and-devices/custom-text-input
1282 if (e.removeLength > 0)
1283 oldTextRange.EndCaretPosition += e.removeLength;
1285 TextRange currentSelection = new TextRange();
1286 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out currentSelection);
1288 CoreTextRange newSelection = new CoreTextRange();
1289 newSelection.StartCaretPosition = e.startIndex;
1290 newSelection.EndCaretPosition = e.startIndex;
1293 //(注意:削除された文字数のほうが多い場合は0を指定しないいけない)
1294 int newTextLength = e.insertLength;
1296 System.Diagnostics.Debug.WriteLine("notify text change (modify start:{0} end:{1}) newlength:{2} (new sel start:{3} end:{4})",
1297 oldTextRange.StartCaretPosition, oldTextRange.EndCaretPosition, newTextLength, newSelection.StartCaretPosition, newSelection.EndCaretPosition);
1299 if(this.textEditContext != null)
1300 this.textEditContext.NotifyTextChanged(oldTextRange, newTextLength, newSelection);
1302 #if ENABLE_AUTMATION
1303 if (this.peer != null)
1304 this.peer.OnNotifyTextChanged();
1308 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1310 this.Focus(FocusState.Programmatic);
1313 void timer_Tick(object sender, object e)
1315 if (this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding() || this.Document.IsRequestRedraw)
1317 this.Refresh(this.View.PageBound);
1321 private void SetDocument(Document value)
1326 Document old_doc = this._Document;
1328 if (this._Document != null)
1330 old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
1331 this._Document.SelectionChanged -= Controller_SelectionChanged;
1332 this._Document.LoadProgress -= Document_LoadProgress;
1333 this._Document.AutoCompleteChanged -= _Document_AutoCompleteChanged;
1334 if (this._Document.AutoComplete != null)
1336 this._Document.AutoComplete.GetPostion = null;
1337 this._Document.AutoComplete = null;
1340 //NotifyTextChanged()を呼び出すと落ちるのでTextConextをごっそり作り替える
1341 this.RemoveTextContext();
1344 System.Diagnostics.Debug.WriteLine("document switched");
1346 this._Document = value;
1347 this._Document.LayoutLines.Render = this.Render;
1348 this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
1349 this._Document.LoadProgress += Document_LoadProgress;
1350 this._Document.AutoCompleteChanged += _Document_AutoCompleteChanged;
1351 if (this._Document.AutoComplete != null && this._Document.AutoComplete.GetPostion == null)
1352 this._Document_AutoCompleteChanged(this._Document, null);
1353 //初期化が終わっていればすべて存在する
1354 if (this.Controller != null && this.View != null)
1356 this.Controller.Document = value;
1357 this.View.Document = value;
1359 this.Controller.AdjustCaret();
1361 this.CreateTextContext();
1363 //依存プロパティとドキュメント内容が食い違っているので再設定する
1364 this.ShowFullSpace = value.ShowFullSpace;
1365 this.ShowHalfSpace = value.ShowHalfSpace;
1366 this.ShowLineBreak = value.ShowLineBreak;
1367 this.ShowTab = value.ShowTab;
1368 this.FlowDirection = value.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
1369 this.IndentMode = value.IndentMode;
1370 this.DrawCaretLine = !value.HideLineMarker;
1371 this.InsertMode = value.InsertMode;
1372 this.DrawRuler = !value.HideRuler;
1373 this.DrawLineNumber = value.DrawLineNumber;
1374 this.MarkURL = value.UrlMark;
1375 this.LineBreakMethod = value.LineBreak;
1376 this.LineBreakCharCount = value.LineBreakCharCount;
1377 this.TabChars = value.TabStops;
1381 //TextEditContext作成後に設定しないと落ちることがある
1382 this._Document.SelectionChanged += Controller_SelectionChanged;
1385 private void _Document_AutoCompleteChanged(object sender, EventArgs e)
1387 Document doc = (Document)sender;
1388 doc.AutoComplete.GetPostion = (tp, e_doc) =>
1390 var p = this.View.GetPostionFromTextPoint(tp);
1391 int height = (int)e_doc.LayoutLines.GetLayout(e_doc.CaretPostion.row).Height;
1393 if (p.Y + AutoCompleteBox.CompleteListBoxHeight + height > e_doc.LayoutLines.Render.TextArea.Height)
1394 p.Y -= AutoCompleteBox.CompleteListBoxHeight;
1397 //AutoCompleteBox内ではCanvasで位置を指定しているので変換する必要がある
1398 var pointInWindow = Util.GetPointInWindow(p, this);
1399 return pointInWindow;
1404 public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
1406 FooTextBox source = (FooTextBox)sender;
1407 if(e.Property.Equals(SelectedTextProperty) && !source.nowCaretMove)
1408 source._Controller.SelectedText = source.SelectedText;
1409 if (e.Property.Equals(DocumentProperty))
1410 source.SetDocument(source.Document);
1411 if(e.Property.Equals(HilighterProperty))
1412 source.View.Hilighter = source.Hilighter;
1413 if (e.Property.Equals(FoldingStrategyProperty))
1414 source.View.LayoutLines.FoldingStrategy = source.FoldingStrategy;
1415 if (e.Property.Equals(IndentModeProperty))
1416 source.Controller.IndentMode = source.IndentMode;
1417 if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)
1418 source.Document.Select(source.Selection.Index,source.Selection.Length);
1419 if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)
1420 source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col);
1421 if (e.Property.Equals(InsertModeProperty))
1422 source.View.InsertMode = source.InsertMode;
1423 if (e.Property.Equals(TabCharsProperty))
1424 source.Document.TabStops = source.TabChars;
1425 if (e.Property.Equals(RectSelectModeProperty))
1426 source._Controller.RectSelection = source.RectSelectMode;
1427 if (e.Property.Equals(DrawCaretProperty))
1428 source.View.HideCaret = !source.DrawCaret;
1429 if (e.Property.Equals(DrawCaretLineProperty))
1430 source.View.HideLineMarker = !source.DrawCaretLine;
1431 if (e.Property.Equals(DrawLineNumberProperty))
1432 source.Document.DrawLineNumber = source.DrawLineNumber;
1433 if (e.Property.Equals(MarkURLProperty))
1434 source.Document.UrlMark = source.MarkURL;
1435 if (e.Property.Equals(LineBreakProperty))
1436 source.Document.LineBreak = source.LineBreakMethod;
1437 if (e.Property.Equals(LineBreakCharCountProperty))
1438 source.Document.LineBreakCharCount = source.LineBreakCharCount;
1439 if (e.Property.Equals(FlowDirectionProperty))
1441 source.Document.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;
1442 if (source.horizontalScrollBar != null)
1443 source.horizontalScrollBar.FlowDirection = source.FlowDirection;
1445 if (e.Property.Equals(DrawRulerProperty))
1447 source.Document.HideRuler = !source.DrawRuler;
1448 source._Controller.JumpCaret(source.Document.CaretPostion.row, source.Document.CaretPostion.col);
1451 if (e.Property.Equals(TextAntialiasModeProperty))
1452 source.Render.TextAntialiasMode = source.TextAntialiasMode;
1453 if(e.Property.Equals(MagnificationPowerPropertyKey))
1454 source.Render.FontSize = source.FontSize * source.MagnificationPower;
1455 if (e.Property.Equals(FontFamilyProperty))
1456 source.Render.FontFamily = source.FontFamily;
1457 if (e.Property.Equals(FontStyleProperty))
1458 source.Render.FontStyle = source.FontStyle;
1459 if (e.Property.Equals(FontWeightProperty))
1460 source.Render.FontWeigth = source.FontWeight;
1461 if (e.Property.Equals(FontSizeProperty))
1462 source.Render.FontSize = source.FontSize;
1463 if (e.Property.Equals(ForegroundProperty))
1464 source.Render.Foreground = D2DRenderBase.ToColor4(source.Foreground);
1465 if (e.Property.Equals(HilightForegroundProperty))
1466 source.Render.HilightForeground = D2DRenderBase.ToColor4(source.HilightForeground);
1467 if (e.Property.Equals(BackgroundProperty))
1468 source.Render.Background = D2DRenderBase.ToColor4(source.Background);
1469 if (e.Property.Equals(ControlCharProperty))
1470 source.Render.ControlChar = D2DRenderBase.ToColor4(source.ControlChar);
1471 if (e.Property.Equals(HilightProperty))
1472 source.Render.Hilight = D2DRenderBase.ToColor4(source.Hilight);
1473 if (e.Property.Equals(Keyword1Property))
1474 source.Render.Keyword1 = D2DRenderBase.ToColor4(source.Keyword1);
1475 if (e.Property.Equals(Keyword2Property))
1476 source.Render.Keyword2 = D2DRenderBase.ToColor4(source.Keyword2);
1477 if (e.Property.Equals(CommentProperty))
1478 source.Render.Comment = D2DRenderBase.ToColor4(source.Comment);
1479 if (e.Property.Equals(LiteralProperty))
1480 source.Render.Literal = D2DRenderBase.ToColor4(source.Literal);
1481 if (e.Property.Equals(URLProperty))
1482 source.Render.Url = D2DRenderBase.ToColor4(source.URL);
1483 if (e.Property.Equals(InsertCaretProperty))
1484 source.Render.InsertCaret = D2DRenderBase.ToColor4(source.InsertCaret);
1485 if (e.Property.Equals(OverwriteCaretProperty))
1486 source.Render.OverwriteCaret = D2DRenderBase.ToColor4(source.OverwriteCaret);
1487 if (e.Property.Equals(PaddingProperty))
1488 source.View.Padding = new Padding((int)source.Padding.Left, (int)source.Padding.Top, (int)source.Padding.Right, (int)source.Padding.Bottom);
1489 if (e.Property.Equals(LineMarkerProperty))
1490 source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);
1491 if (e.Property.Equals(ShowFullSpaceProperty))
1492 source.Render.ShowFullSpace = source.ShowFullSpace;
1493 if (e.Property.Equals(ShowHalfSpaceProperty))
1494 source.Render.ShowHalfSpace = source.ShowHalfSpace;
1495 if (e.Property.Equals(ShowTabProperty))
1496 source.Render.ShowTab = source.ShowTab;
1497 if (e.Property.Equals(ShowLineBreakProperty))
1498 source.Render.ShowLineBreak = source.ShowLineBreak;
1499 if (e.Property.Equals(UpdateAreaProperty))
1500 source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);
1501 if (e.Property.Equals(LineNumberProperty))
1502 source.Render.LineNumber = D2DRenderBase.ToColor4(source.LineNumber);
1510 /// コンテキストメニューが表示されるときに呼び出されます
1512 public event EventHandler<FooContextMenuEventArgs> ContextMenuOpening;
1518 internal Controller Controller
1522 return this._Controller;
1527 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1529 public TextAntialiasMode TextAntialiasMode
1531 get { return (TextAntialiasMode)GetValue(TextAntialiasModeProperty); }
1532 set { SetValue(TextAntialiasModeProperty, value); }
1536 /// TextAntialiasModeの依存プロパティを表す
1538 public static readonly DependencyProperty TextAntialiasModeProperty =
1539 DependencyProperty.Register("TextAntialiasMode", typeof(TextAntialiasMode), typeof(FooTextBox), new PropertyMetadata(TextAntialiasMode.Default, OnPropertyChanged));
1544 public IHilighter Hilighter
1546 get { return (IHilighter)GetValue(HilighterProperty); }
1547 set { SetValue(HilighterProperty, value); }
1551 /// Hilighterの依存プロパティを表す
1553 public static readonly DependencyProperty HilighterProperty =
1554 DependencyProperty.Register("Hilighter", typeof(IHilighter), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
1557 /// フォールティングを作成するインターフェイスを表す
1559 public IFoldingStrategy FoldingStrategy
1561 get { return (IFoldingStrategy)GetValue(FoldingStrategyProperty); }
1562 set { SetValue(FoldingStrategyProperty, value); }
1566 /// FoldingStrategyの依存プロパティ
1568 public static readonly DependencyProperty FoldingStrategyProperty =
1569 DependencyProperty.Register("FoldingStrategy", typeof(IFoldingStrategy), typeof(FooTextBox), new PropertyMetadata(null,OnPropertyChanged));
1574 public MarkerPatternSet MarkerPatternSet
1578 return this.Document.MarkerPatternSet;
1585 /// <remarks>切り替え後に再描写が行われます</remarks>
1586 public Document Document
1588 get { return (Document)GetValue(DocumentProperty); }
1589 set { SetValue(DocumentProperty, value); }
1592 // Using a DependencyProperty as the backing store for Document. This enables animation, styling, binding, etc...
1593 public static readonly DependencyProperty DocumentProperty =
1594 DependencyProperty.Register("Document", typeof(Document), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
1601 public LineToIndexTable LayoutLineCollection
1603 get { return this.View.LayoutLines; }
1609 public string SelectedText
1611 get { return (string)GetValue(SelectedTextProperty); }
1612 set { SetValue(SelectedTextProperty, value); }
1616 /// SelectedTextの依存プロパティを表す
1618 public static readonly DependencyProperty SelectedTextProperty =
1619 DependencyProperty.Register("SelectedText", typeof(string), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
1624 public IndentMode IndentMode
1626 get { return (IndentMode)GetValue(IndentModeProperty); }
1627 set { SetValue(IndentModeProperty, value); }
1631 /// IndentModeの依存プロパティを表す
1633 public static readonly DependencyProperty IndentModeProperty =
1634 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab,OnPropertyChanged));
1640 /// Lengthが0の場合はキャレット位置を表します。
1641 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1643 public TextRange Selection
1645 get { return (TextRange)GetValue(SelectionProperty); }
1646 set { SetValue(SelectionProperty, value); }
1650 /// Selectionの依存プロパティを表す
1652 public static readonly DependencyProperty SelectionProperty =
1653 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null, OnPropertyChanged));
1658 public double MagnificationPower
1660 get { return (double)GetValue(MagnificationPowerPropertyKey); }
1661 set { SetValue(MagnificationPowerPropertyKey, value); }
1667 public static readonly DependencyProperty MagnificationPowerPropertyKey =
1668 DependencyProperty.Register("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0, OnPropertyChanged));
1673 public TextPoint CaretPostion
1675 get { return (TextPoint)GetValue(CaretPostionPropertyKey); }
1676 set { SetValue(CaretPostionPropertyKey, value); }
1679 static readonly DependencyProperty CaretPostionPropertyKey =
1680 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(new TextPoint(), OnPropertyChanged));
1685 public new FlowDirection FlowDirection
1687 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1688 set { SetValue(FlowDirectionProperty, value); }
1692 /// レタリング方向を表す。これは依存プロパティです
1694 public new static readonly DependencyProperty FlowDirectionProperty =
1695 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight,OnPropertyChanged));
1700 public new FontFamily FontFamily
1702 get { return (FontFamily)GetValue(FontFamilyProperty); }
1703 set { SetValue(FontFamilyProperty, value); }
1707 /// FontFamilyの依存プロパティを表す
1709 public new static readonly DependencyProperty FontFamilyProperty =
1710 DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(FooTextBox), new PropertyMetadata(new FontFamily("Cambria"), OnPropertyChanged));
1715 public new double FontSize
1717 get { return (double)GetValue(FontSizeProperty); }
1718 set { SetValue(FontSizeProperty, value); }
1722 /// FontSizeの依存プロパティを表す
1724 public new static readonly DependencyProperty FontSizeProperty =
1725 DependencyProperty.Register("FontSize", typeof(double), typeof(FooTextBox), new PropertyMetadata(12.0,OnPropertyChanged));
1730 public new FontStyle FontStyle
1732 get { return (FontStyle)GetValue(FontStyleProperty); }
1733 set { SetValue(FontStyleProperty, value); }
1737 /// FontStyleの依存プロパティを表す
1739 public new static readonly DependencyProperty FontStyleProperty =
1740 DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(FooTextBox), new PropertyMetadata(FontStyle.Normal,OnPropertyChanged));
1745 public new FontWeight FontWeight
1747 get { return (FontWeight)GetValue(FontWeightProperty); }
1748 set { SetValue(FontWeightProperty, value); }
1752 /// FontWeigthの依存プロパティを表す
1754 public new static readonly DependencyProperty FontWeightProperty =
1755 DependencyProperty.Register("FontWeigth", typeof(FontWeight), typeof(FooTextBox), new PropertyMetadata(FontWeights.Normal,OnPropertyChanged));
1758 /// デフォルトの文字色を表す。これは依存プロパティです
1760 public new Windows.UI.Color Foreground
1762 get { return (Windows.UI.Color)GetValue(ForegroundProperty); }
1763 set { SetValue(ForegroundProperty, value); }
1767 /// Foregroundの依存プロパティを表す
1769 public new static readonly DependencyProperty ForegroundProperty =
1770 DependencyProperty.Register("Foreground", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1773 /// 選択時の文字色を表す。これは依存プロパティです
1775 public Windows.UI.Color HilightForeground
1777 get { return (Windows.UI.Color)GetValue(HilightForegroundProperty); }
1778 set { SetValue(HilightForegroundProperty, value); }
1782 /// HilightForegroundForegroundの依存プロパティを表す
1784 public static readonly DependencyProperty HilightForegroundProperty =
1785 DependencyProperty.Register("HilightForeground", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));
1788 /// 背景色を表す。これは依存プロパティです
1790 public new Windows.UI.Color Background
1792 get { return (Windows.UI.Color)GetValue(BackgroundProperty); }
1793 set { SetValue(BackgroundProperty, value); }
1797 /// Backgroundの依存プロパティを表す
1799 public new static readonly DependencyProperty BackgroundProperty =
1800 DependencyProperty.Register("Background", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));
1803 /// コントロールコードの文字色を表す。これは依存プロパティです
1805 public Windows.UI.Color ControlChar
1807 get { return (Windows.UI.Color)GetValue(ControlCharProperty); }
1808 set { SetValue(ControlCharProperty, value); }
1812 /// ControlCharの依存プロパティを表す
1814 public static readonly DependencyProperty ControlCharProperty =
1815 DependencyProperty.Register("ControlChar", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1818 /// 選択時の背景色を表す。これは依存プロパティです
1820 public Windows.UI.Color Hilight
1822 get { return (Windows.UI.Color)GetValue(HilightProperty); }
1823 set { SetValue(HilightProperty, value); }
1827 /// Hilightの依存プロパティを表す
1829 public static readonly DependencyProperty HilightProperty =
1830 DependencyProperty.Register("Hilight", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DodgerBlue, OnPropertyChanged));
1833 /// キーワード1の文字色を表す。これは依存プロパティです
1835 public Windows.UI.Color Keyword1
1837 get { return (Windows.UI.Color)GetValue(Keyword1Property); }
1838 set { SetValue(Keyword1Property, value); }
1842 /// Keyword1の依存プロパティを表す
1844 public static readonly DependencyProperty Keyword1Property =
1845 DependencyProperty.Register("Keyword1", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1848 /// キーワード2の文字色を表す。これは依存プロパティです
1850 public Windows.UI.Color Keyword2
1852 get { return (Windows.UI.Color)GetValue(Keyword2Property); }
1853 set { SetValue(Keyword2Property, value); }
1857 /// Keyword2の依存プロパティを表す
1859 public static readonly DependencyProperty Keyword2Property =
1860 DependencyProperty.Register("Keyword2", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DarkCyan, OnPropertyChanged));
1863 /// コメントの文字色を表す。これは依存プロパティです
1865 public Windows.UI.Color Comment
1867 get { return (Windows.UI.Color)GetValue(CommentProperty); }
1868 set { SetValue(CommentProperty, value); }
1872 /// Commentの依存プロパティを表す
1874 public static readonly DependencyProperty CommentProperty =
1875 DependencyProperty.Register("Comment", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Green, OnPropertyChanged));
1878 /// 文字リテラルの文字色を表す。これは依存プロパティです
1880 public Windows.UI.Color Literal
1882 get { return (Windows.UI.Color)GetValue(LiteralProperty); }
1883 set { SetValue(LiteralProperty, value); }
1887 /// Literalの依存プロパティを表す
1889 public static readonly DependencyProperty LiteralProperty =
1890 DependencyProperty.Register("Literal", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Brown, OnPropertyChanged));
1893 /// URLの文字色を表す。これは依存プロパティです
1895 public Windows.UI.Color URL
1897 get { return (Windows.UI.Color)GetValue(URLProperty); }
1898 set { SetValue(URLProperty, value); }
1904 public static readonly DependencyProperty URLProperty =
1905 DependencyProperty.Register("URL", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1910 public Windows.UI.Color UpdateArea
1912 get { return (Windows.UI.Color)GetValue(UpdateAreaProperty); }
1913 set { SetValue(UpdateAreaProperty, value); }
1917 /// UpdateAreaの依存プロパティを表す
1919 public static readonly DependencyProperty UpdateAreaProperty =
1920 DependencyProperty.Register("UpdateArea", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen, OnPropertyChanged));
1925 public Windows.UI.Color LineMarker
1927 get { return (Windows.UI.Color)GetValue(LineMarkerProperty); }
1928 set { SetValue(LineMarkerProperty, value); }
1932 /// LineMarkerの依存プロパティを表す
1934 public static readonly DependencyProperty LineMarkerProperty =
1935 DependencyProperty.Register("LineMarker", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1938 /// 挿入モード時のキャレットの色を表す
1940 public Windows.UI.Color InsertCaret
1942 get { return (Windows.UI.Color)GetValue(InsertCaretProperty); }
1943 set { SetValue(InsertCaretProperty, value); }
1947 /// InsertCaretの依存プロパティを表す
1949 public static readonly DependencyProperty InsertCaretProperty =
1950 DependencyProperty.Register("InsertCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1953 /// 上書きモード時のキャレット職を表す
1955 public Windows.UI.Color OverwriteCaret
1957 get { return (Windows.UI.Color)GetValue(OverwriteCaretProperty); }
1958 set { SetValue(OverwriteCaretProperty, value); }
1962 /// OverwriteCaretの依存プロパティを表す
1964 public static readonly DependencyProperty OverwriteCaretProperty =
1965 DependencyProperty.Register("OverwriteCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1970 public Windows.UI.Color LineNumber
1972 get { return (Windows.UI.Color)GetValue(LineNumberProperty); }
1973 set { SetValue(LineNumberProperty, value); }
1977 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1979 public static readonly DependencyProperty LineNumberProperty =
1980 DependencyProperty.Register("LineNumber", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray,OnPropertyChanged));
1985 public new Thickness Padding
1987 get { return (Thickness)GetValue(PaddingProperty); }
1988 set { SetValue(PaddingProperty, value); }
1992 /// Paddingの依存プロパティを表す
1994 public new static readonly DependencyProperty PaddingProperty =
1995 DependencyProperty.Register("Padding", typeof(Thickness), typeof(FooTextBox), new PropertyMetadata(new Thickness(),OnPropertyChanged));
1998 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
2000 public bool InsertMode
2002 get { return (bool)GetValue(InsertModeProperty); }
2003 set { SetValue(InsertModeProperty, value); }
2007 /// InsertModeの依存プロパティを表す
2009 public static readonly DependencyProperty InsertModeProperty =
2010 DependencyProperty.Register("InsertMode",
2013 new PropertyMetadata(true, OnPropertyChanged));
2016 /// タブの文字数を表す。これは依存プロパティです
2020 get { return (int)GetValue(TabCharsProperty); }
2021 set { SetValue(TabCharsProperty, value); }
2025 /// TabCharsの依存プロパティを表す
2027 public static readonly DependencyProperty TabCharsProperty =
2028 DependencyProperty.Register("TabChars",
2031 new PropertyMetadata(4, OnPropertyChanged));
2034 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
2036 public bool RectSelectMode
2038 get { return (bool)GetValue(RectSelectModeProperty); }
2039 set { SetValue(RectSelectModeProperty, value); }
2043 /// RectSelectModeの依存プロパティを表す
2045 public static readonly DependencyProperty RectSelectModeProperty =
2046 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2052 /// 変更した場合、レイアウトの再構築を行う必要があります
2054 public LineBreakMethod LineBreakMethod
2056 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
2057 set { SetValue(LineBreakProperty, value); }
2061 /// LineBreakMethodの依存プロパティを表す
2063 public static readonly DependencyProperty LineBreakProperty =
2064 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None, OnPropertyChanged));
2068 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
2071 /// 変更した場合、レイアウトの再構築を行う必要があります
2073 public int LineBreakCharCount
2075 get { return (int)GetValue(LineBreakCharCountProperty); }
2076 set { SetValue(LineBreakCharCountProperty, value); }
2080 /// LineBreakCharCountの依存プロパティを表す
2082 public static readonly DependencyProperty LineBreakCharCountProperty =
2083 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80, OnPropertyChanged));
2086 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
2088 public bool DrawCaret
2090 get { return (bool)GetValue(DrawCaretProperty); }
2091 set { SetValue(DrawCaretProperty, value); }
2095 /// DrawCaretの依存プロパティを表す
2097 public static readonly DependencyProperty DrawCaretProperty =
2098 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new PropertyMetadata(true, OnPropertyChanged));
2102 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
2104 public bool DrawCaretLine
2106 get { return (bool)GetValue(DrawCaretLineProperty); }
2107 set { SetValue(DrawCaretLineProperty, value); }
2111 /// DrawCaretLineの依存プロパティを表す
2113 public static readonly DependencyProperty DrawCaretLineProperty =
2114 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2117 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
2119 public bool DrawLineNumber
2121 get { return (bool)GetValue(DrawLineNumberProperty); }
2122 set { SetValue(DrawLineNumberProperty, value); }
2126 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
2128 public bool DrawRuler
2130 get { return (bool)GetValue(DrawRulerProperty); }
2131 set { SetValue(DrawRulerProperty, value); }
2135 /// DrawRulerの依存プロパティを表す
2137 public static readonly DependencyProperty DrawRulerProperty =
2138 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2142 /// DrawLineNumberの依存プロパティを表す
2144 public static readonly DependencyProperty DrawLineNumberProperty =
2145 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2148 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
2152 get { return (bool)GetValue(MarkURLProperty); }
2153 set { SetValue(MarkURLProperty, value); }
2157 /// MarkURLの依存プロパティを表す
2159 public static readonly DependencyProperty MarkURLProperty =
2160 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2163 /// 全角スペースを表示するなら真。そうでないなら偽
2165 public bool ShowFullSpace
2167 get { return (bool)GetValue(ShowFullSpaceProperty); }
2168 set { SetValue(ShowFullSpaceProperty, value); }
2172 /// ShowFullSpaceの依存プロパティを表す
2174 public static readonly DependencyProperty ShowFullSpaceProperty =
2175 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2178 /// 半角スペースを表示するなら真。そうでないなら偽
2180 public bool ShowHalfSpace
2182 get { return (bool)GetValue(ShowHalfSpaceProperty); }
2183 set { SetValue(ShowHalfSpaceProperty, value); }
2187 /// ShowHalfSpaceの依存プロパティを表す
2189 public static readonly DependencyProperty ShowHalfSpaceProperty =
2190 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2193 /// タブを表示するなら真。そうでないなら偽
2197 get { return (bool)GetValue(ShowTabProperty); }
2198 set { SetValue(ShowTabProperty, value); }
2202 /// ShowTabの依存プロパティを表す
2204 public static readonly DependencyProperty ShowTabProperty =
2205 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2208 /// 改行マークを表示するなら真。そうでないなら偽
2210 public bool ShowLineBreak
2212 get { return (bool)GetValue(ShowLineBreakProperty); }
2213 set { SetValue(ShowLineBreakProperty, value); }
2217 /// ShowLineBreakの依存プロパティを表す
2219 public static readonly DependencyProperty ShowLineBreakProperty =
2220 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false,OnPropertyChanged));
2226 /// コンテキストメニューのイベントデーターを表す
2228 public class FooContextMenuEventArgs
2231 /// 処理済みなら真。そうでないなら偽
2233 public bool Handled = false;
2235 /// コンテキストメニューを表示すべき座標を表す
2237 public Windows.Foundation.Point Postion;
2241 /// <param name="pos"></param>
2242 public FooContextMenuEventArgs(Windows.Foundation.Point pos)