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/>.
13 using System.ComponentModel;
14 using System.Threading.Tasks;
15 using Windows.ApplicationModel.Resources.Core;
16 using Windows.Devices.Input;
18 using Windows.ApplicationModel.DataTransfer;
19 using Windows.Foundation;
21 using Windows.UI.Input;
22 using Windows.UI.Core;
23 using Windows.UI.Popups;
24 using Windows.UI.Text;
25 using Windows.UI.Xaml.Media;
26 using Windows.UI.Xaml;
27 using Windows.UI.Xaml.Controls;
28 using Windows.UI.Xaml.Controls.Primitives;
29 using Windows.UI.Xaml.Input;
30 using Windows.UI.Text.Core;
32 // テンプレート コントロールのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234235 を参照してください
33 namespace FooEditEngine.UWP
38 public sealed class FooTextBox : Control,IDisposable
41 Controller _Controller;
43 ScrollBar horizontalScrollBar, verticalScrollBar;
44 Windows.UI.Xaml.Shapes.Rectangle rectangle;
45 GestureRecognizer gestureRecongnizer = new GestureRecognizer();
46 CoreTextEditContext textEditContext;
47 CoreTextServicesManager textServiceManager;
49 FooTextBoxAutomationPeer peer;
51 bool nowCaretMove = false;
52 bool nowCompstion = false;
54 DispatcherTimer timer = new DispatcherTimer();
61 this.DefaultStyleKey = typeof(FooTextBox);
63 this.rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
64 this.rectangle.Margin = this.Padding;
65 this.Render = new D2DRender(this,this.rectangle);
67 this.Document = new Document();
69 this.View = new EditView(this.Document, this.Render, new Padding(5, Gripper.HitAreaWidth, Gripper.HitAreaWidth / 2, Gripper.HitAreaWidth));
70 this.View.SrcChanged += View_SrcChanged;
71 this.View.InsertMode = this.InsertMode;
72 this.Document.DrawLineNumber = this.DrawLineNumber;
73 this.View.HideCaret = !this.DrawCaret;
74 this.View.HideLineMarker = !this.DrawCaretLine;
75 this.Document.HideRuler = !this.DrawRuler;
76 this.Document.UrlMark = this.MarkURL;
77 this.Document.TabStops = this.TabChars;
79 this._Controller = new Controller(this.Document, this.View);
80 this.Document.SelectionChanged += Controller_SelectionChanged;
82 this.gestureRecongnizer.GestureSettings = GestureSettings.Drag |
83 GestureSettings.RightTap |
85 GestureSettings.DoubleTap |
86 GestureSettings.ManipulationTranslateX |
87 GestureSettings.ManipulationTranslateY |
88 GestureSettings.ManipulationScale |
89 GestureSettings.ManipulationTranslateInertia |
90 GestureSettings.ManipulationScaleInertia;
91 this.gestureRecongnizer.RightTapped += gestureRecongnizer_RightTapped;
92 this.gestureRecongnizer.Tapped += gestureRecongnizer_Tapped;
93 this.gestureRecongnizer.Dragging += gestureRecongnizer_Dragging;
94 this.gestureRecongnizer.ManipulationInertiaStarting += GestureRecongnizer_ManipulationInertiaStarting; ;
95 this.gestureRecongnizer.ManipulationStarted += gestureRecongnizer_ManipulationStarted;
96 this.gestureRecongnizer.ManipulationUpdated += gestureRecongnizer_ManipulationUpdated;
97 this.gestureRecongnizer.ManipulationCompleted += gestureRecongnizer_ManipulationCompleted;
99 this.timer.Interval = new TimeSpan(0, 0, 0, 0, 500);
100 this.timer.Tick += this.timer_Tick;
103 this.SizeChanged += FooTextBox_SizeChanged;
105 this.Loaded += FooTextBox_Loaded;
119 public void Dispose()
122 GC.SuppressFinalize(this);
125 bool Disposed = false;
126 private void Dispose(bool disposing)
133 this.Render.Dispose();
140 /// <param name="start">開始インデックス</param>
141 /// <param name="length">長さ</param>
142 public void Select(int start, int length)
144 this.Document.Select(start, length);
148 /// キャレットを指定した行に移動させます
150 /// <param name="index">インデックス</param>
151 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
152 public void JumpCaret(int index)
154 this._Controller.JumpCaret(index);
157 /// キャレットを指定した行と桁に移動させます
159 /// <param name="row">行番号</param>
160 /// <param name="col">桁</param>
161 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
162 public void JumpCaret(int row, int col)
164 this._Controller.JumpCaret(row, col);
168 /// 選択中のテキストをクリップボードにコピーします
172 string text = this._Controller.SelectedText;
173 if (text != null && text != string.Empty)
175 DataPackage dataPackage = new DataPackage();
176 dataPackage.RequestedOperation = DataPackageOperation.Copy;
177 dataPackage.SetText(text);
179 Clipboard.SetContent(dataPackage);
184 /// 選択中のテキストをクリップボードに切り取ります
188 string text = this._Controller.SelectedText;
189 if (text != null && text != string.Empty)
191 DataPackage dataPackage = new DataPackage();
192 dataPackage.RequestedOperation = DataPackageOperation.Copy;
193 dataPackage.SetText(text);
195 Clipboard.SetContent(dataPackage);
197 this._Controller.SelectedText = "";
204 public async Task PasteAsync()
206 var dataPackageView = Clipboard.GetContent();
207 if (dataPackageView.Contains(StandardDataFormats.Text))
209 this._Controller.SelectedText = await dataPackageView.GetTextAsync();
216 public void SelectAll()
218 this.Document.Select(0, this.Document.Length);
224 public void DeSelectAll()
226 this._Controller.DeSelectAll();
232 /// <param name="tp">テキストポイント</param>
233 /// <returns>座標</returns>
234 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
235 public Windows.Foundation.Point GetPostionFromTextPoint(TextPoint tp)
237 if (this.Document.FireUpdateEvent == false)
238 throw new InvalidOperationException("");
239 return this.View.GetPostionFromTextPoint(tp);
243 /// 対応するテキストポイントを返します
245 /// <param name="p">クライアント領域の原点を左上とする座標</param>
246 /// <returns>テキストポイント</returns>
247 public TextPoint GetTextPointFromPostion(Windows.Foundation.Point p)
249 if (this.Document.FireUpdateEvent == false)
250 throw new InvalidOperationException("");
251 return this.View.GetTextPointFromPostion(p);
257 /// <param name="row">レイアウト行</param>
258 /// <returns>行の高さ</returns>
259 public double GetLineHeight(int row)
261 if (this.Document.FireUpdateEvent == false)
262 throw new InvalidOperationException("");
263 return this.View.LayoutLines.GetLayout(row).Height; ;
267 /// インデックスに対応する座標を得ます
269 /// <param name="index">インデックス</param>
270 /// <returns>座標を返す</returns>
271 public Windows.Foundation.Point GetPostionFromIndex(int index)
273 if (this.Document.FireUpdateEvent == false)
274 throw new InvalidOperationException("");
275 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
276 return this.View.GetPostionFromTextPoint(tp);
282 /// <param name="p">座標</param>
283 /// <returns>インデックスを返す</returns>
284 public int GetIndexFromPostion(Windows.Foundation.Point p)
286 if (this.Document.FireUpdateEvent == false)
287 throw new InvalidOperationException("");
288 TextPoint tp = this.View.GetTextPointFromPostion(p);
289 return this.View.GetIndexFromLayoutLine(tp);
296 public void Refresh()
298 this.Refresh(this.View.PageBound);
302 /// レイアウト行をすべて破棄し、再度レイアウトを行う
304 public void PerfomLayouts()
306 this.View.PerfomLayouts();
312 /// <param name="row">行</param>
313 /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
314 public void ScrollIntoView(int row, bool alignTop)
316 this.View.ScrollIntoView(row, alignTop);
320 /// ファイルからドキュメントを構築する
322 /// <param name="sr">StremReader</param>
323 /// <returns>Taskオブジェクト</returns>
324 public async Task LoadFileAsync(System.IO.StreamReader sr, System.Threading.CancellationTokenSource token)
326 this.IsEnabled = false;
327 this.View.LayoutLines.IsFrozneDirtyFlag = true;
328 WinFileReader fs = new WinFileReader(sr);
329 await this.Document.LoadAsync(fs, token);
330 this.View.LayoutLines.IsFrozneDirtyFlag = false;
332 CoreTextRange modified_range = new CoreTextRange();
333 modified_range.StartCaretPosition = 0;
334 modified_range.EndCaretPosition = 0;
335 //キャレット位置はロード前と同じにしないと違和感を感じる
336 if(this.textEditContext != null)
337 this.textEditContext.NotifyTextChanged(modified_range, this.Document.Length, modified_range);
339 if (this.verticalScrollBar != null)
340 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
341 this.View.CalculateLineCountOnScreen();
342 this.IsEnabled = true;
346 /// ドキュメントの内容をファイルに保存する
348 /// <param name="sw">StreamWriter</param>
349 /// <param name="enc">エンコード</param>
350 /// <returns>Taskオブジェクト</returns>
351 public async Task SaveFile(System.IO.StreamWriter sw, System.Threading.CancellationTokenSource token)
353 WinFileWriter fs = new WinFileWriter(sw);
354 await this.Document.SaveAsync(fs, token);
369 async Task PasteCommand()
371 await this.PasteAsync();
381 protected override Windows.UI.Xaml.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
383 this.peer = new FooTextBoxAutomationPeer(this);
388 protected override void OnApplyTemplate()
390 base.OnApplyTemplate();
392 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
395 Grid.SetRow(this.rectangle, 0);
396 Grid.SetColumn(this.rectangle, 0);
397 grid.Children.Add(this.rectangle);
400 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
401 if (this.horizontalScrollBar != null)
403 this.horizontalScrollBar.SmallChange = 10;
404 this.horizontalScrollBar.LargeChange = 100;
405 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
406 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
408 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
409 if (this.verticalScrollBar != null)
411 this.verticalScrollBar.SmallChange = 1;
412 this.verticalScrollBar.LargeChange = 10;
413 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
414 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
419 protected override async void OnGotFocus(RoutedEventArgs e)
423 if(this.textServiceManager == null)
425 await Task.Delay(500);
426 this.textServiceManager = CoreTextServicesManager.GetForCurrentView();
427 this.textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;
430 this.CreateTextContext();
432 this.View.IsFocused = true;
436 private void TextServiceManager_InputLanguageChanged(CoreTextServicesManager sender, object args)
438 this.RemoveTextContext();
439 this.CreateTextContext();
443 protected override void OnLostFocus(RoutedEventArgs e)
447 this.RemoveTextContext();
449 this.View.IsFocused = false;
453 private void CreateTextContext()
455 this.textEditContext = this.textServiceManager.CreateEditContext();
456 this.textEditContext.CompositionStarted += TextEditContext_CompositionStarted;
457 this.textEditContext.CompositionCompleted += TextEditContext_CompositionCompleted;
458 this.textEditContext.LayoutRequested += TextEditContext_LayoutRequested;
459 this.textEditContext.TextUpdating += TextEditContext_TextUpdating;
460 this.textEditContext.TextRequested += TextEditContext_TextRequested;
461 this.textEditContext.SelectionRequested += TextEditContext_SelectionRequested;
462 this.textEditContext.SelectionUpdating += TextEditContext_SelectionUpdating;
463 this.textEditContext.FormatUpdating += TextEditContext_FormatUpdating;
464 this.textEditContext.FocusRemoved += TextEditContext_FocusRemoved;
465 this.textEditContext.NotifyFocusLeaveCompleted += TextEditContext_NotifyFocusLeaveCompleted;
466 this.textEditContext.NotifyFocusEnter();
469 private void RemoveTextContext()
471 this.textEditContext.CompositionStarted -= TextEditContext_CompositionStarted;
472 this.textEditContext.CompositionCompleted -= TextEditContext_CompositionCompleted;
473 this.textEditContext.LayoutRequested -= TextEditContext_LayoutRequested;
474 this.textEditContext.TextUpdating -= TextEditContext_TextUpdating;
475 this.textEditContext.TextRequested -= TextEditContext_TextRequested;
476 this.textEditContext.SelectionRequested -= TextEditContext_SelectionRequested;
477 this.textEditContext.SelectionUpdating -= TextEditContext_SelectionUpdating;
478 this.textEditContext.FormatUpdating -= TextEditContext_FormatUpdating;
479 this.textEditContext.FocusRemoved -= TextEditContext_FocusRemoved;
480 this.textEditContext.NotifyFocusLeaveCompleted -= TextEditContext_NotifyFocusLeaveCompleted;
481 this.textEditContext.NotifyFocusLeave();
485 protected override async void OnKeyDown(KeyRoutedEventArgs e)
487 bool isControlPressed = this.IsModiferKeyPressed(VirtualKey.Control);
488 bool isShiftPressed = this.IsModiferKeyPressed(VirtualKey.Shift);
489 bool isMovedCaret = false;
493 this._Controller.MoveCaretVertical(-1, isShiftPressed);
498 case VirtualKey.Down:
499 this._Controller.MoveCaretVertical(+1, isShiftPressed);
504 case VirtualKey.Left:
505 this._Controller.MoveCaretHorizontical(-1, isShiftPressed, isControlPressed);
510 case VirtualKey.Right:
511 this._Controller.MoveCaretHorizontical(1, isShiftPressed, isControlPressed);
516 case VirtualKey.PageUp:
517 this._Controller.Scroll(ScrollDirection.Up, this.View.LineCountOnScreen, isShiftPressed, true);
521 case VirtualKey.PageDown:
522 this._Controller.Scroll(ScrollDirection.Down, this.View.LineCountOnScreen, isShiftPressed, true);
526 case VirtualKey.Home:
527 if (isControlPressed)
528 this._Controller.JumpToHead(isShiftPressed);
530 this.Controller.JumpToLineHead(this.Document.CaretPostion.row,isShiftPressed);
535 if (isControlPressed)
536 this._Controller.JumpToEnd(isShiftPressed);
538 this.Controller.JumpToLineEnd(this.Document.CaretPostion.row,isShiftPressed);
543 if (!isControlPressed)
545 if (this._Controller.SelectionLength == 0)
546 this._Controller.DoInputChar('\t');
547 else if (isShiftPressed)
548 this._Controller.DownIndent();
550 this._Controller.UpIndent();
555 case VirtualKey.Enter:
556 this._Controller.DoEnterAction();
560 case VirtualKey.Insert:
561 if(this.View.InsertMode)
562 this.View.InsertMode = false;
564 this.View.InsertMode = true;
569 if (isControlPressed)
577 if (isControlPressed)
579 if (this._Controller.RectSelection)
580 this._Controller.RectSelection = false;
582 this._Controller.RectSelection = true;
588 if (isControlPressed)
595 if (isControlPressed)
602 if (isControlPressed)
604 await this.PasteCommand();
609 if (isControlPressed)
611 this.Document.UndoManager.redo();
617 if (isControlPressed)
619 this.Document.UndoManager.undo();
624 case VirtualKey.Back:
625 this._Controller.DoBackSpaceAction();
629 case VirtualKey.Delete:
630 this._Controller.DoDeleteAction();
636 if (isMovedCaret && this.peer != null)
637 this.peer.OnNotifyCaretChanged();
643 protected override void OnPointerPressed(PointerRoutedEventArgs e)
645 this.CapturePointer(e.Pointer);
646 this.gestureRecongnizer.ProcessDownEvent(e.GetCurrentPoint(this));
651 protected override void OnPointerMoved(PointerRoutedEventArgs e)
653 this.gestureRecongnizer.ProcessMoveEvents(e.GetIntermediatePoints(this));
656 if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
658 Point p = e.GetCurrentPoint(this).Position;
659 if (this.View.HitTextArea(p.X, p.Y))
661 TextPoint tp = this.View.GetTextPointFromPostion(p);
662 if (this._Controller.IsMarker(tp, HilightType.Url))
663 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Hand, 101);
665 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.IBeam, 101);
669 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 101);
675 protected override void OnPointerReleased(PointerRoutedEventArgs e)
677 this.gestureRecongnizer.ProcessUpEvent(e.GetCurrentPoint(this));
682 protected override void OnPointerCanceled(PointerRoutedEventArgs e)
684 this.gestureRecongnizer.CompleteGesture();
689 protected override void OnPointerWheelChanged(PointerRoutedEventArgs e)
691 bool shift = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Shift) ==
692 Windows.System.VirtualKeyModifiers.Shift;
693 bool ctrl = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Control) ==
694 Windows.System.VirtualKeyModifiers.Control;
695 this.gestureRecongnizer.ProcessMouseWheelEvent(e.GetCurrentPoint(this), shift, ctrl);
699 private void TextEditContext_FormatUpdating(CoreTextEditContext sender, CoreTextFormatUpdatingEventArgs args)
701 if (this.Document.Length == 0 || args.IsCanceled)
703 args.Result = CoreTextFormatUpdatingResult.Failed;
706 this.Render.SetImeConvationInfo(args);
707 if(args.Reason == CoreTextFormatUpdatingReason.CompositionTargetConverted)
709 this.View.AdjustSrc(args.Range.StartCaretPosition);
712 args.Result = CoreTextFormatUpdatingResult.Succeeded;
715 private void TextEditContext_TextRequested(CoreTextEditContext sender, CoreTextTextRequestedEventArgs args)
717 CoreTextTextRequest req = args.Request;
719 if (this.Document.Length == 0 || req.IsCanceled)
724 int start = req.Range.StartCaretPosition;
725 int length = req.Range.EndCaretPosition - req.Range.StartCaretPosition;
726 if (length > this.Document.Length)
727 length = this.Document.Length;
729 System.Diagnostics.Debug.WriteLine("req text start:{0} length:{1}", start, length);
731 //キャレット位置も含むので+1する必要はない
732 req.Text = this.Document.ToString(start, length);
735 private void TextEditContext_LayoutRequested(CoreTextEditContext sender, CoreTextLayoutRequestedEventArgs args)
738 Point startPos, endPos;
739 int i_startIndex = args.Request.Range.StartCaretPosition;
740 int i_endIndex = args.Request.Range.EndCaretPosition;
742 if(args.Request.IsCanceled)
747 if(i_startIndex != -1 && i_endIndex != -1)
749 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
751 double scale = Util.GetScale();
753 var screenStartPos = Util.GetScreentPoint(startPos, this).Scale(scale);
754 var screenEndPos = Util.GetScreentPoint(endPos, this).Scale(scale);
755 args.Request.LayoutBounds.TextBounds = new Rect(
758 screenEndPos.X - screenStartPos.X,
759 screenEndPos.Y - screenStartPos.Y);
763 var controlTopLeft = new Point(0, 0);
764 var controlBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
766 var gt = this.TransformToVisual(Window.Current.Content);
767 controlTopLeft = gt.TransformPoint(controlTopLeft);
768 controlBottomRight = gt.TransformPoint(controlBottomRight);
770 args.Request.LayoutBounds.ControlBounds = new Rect(
773 controlBottomRight.X - controlTopLeft.X,
774 controlBottomRight.Y - controlTopLeft.Y
778 private void TextEditContext_SelectionRequested(CoreTextEditContext sender, CoreTextSelectionRequestedEventArgs args)
780 if(args.Request.IsCanceled || this.Document.Length == 0)
784 TextRange currentSelection = new TextRange();
785 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out currentSelection);
787 CoreTextRange currentSelectionRange = new CoreTextRange();
788 currentSelectionRange.StartCaretPosition = currentSelection.Index;
789 currentSelectionRange.EndCaretPosition = currentSelection.Index + currentSelection.Length;
790 args.Request.Selection = currentSelectionRange;
791 System.Diagnostics.Debug.WriteLine("req selection start:{0} end:{1}", currentSelectionRange.StartCaretPosition, currentSelectionRange.EndCaretPosition);
794 private void TextEditContext_SelectionUpdating(CoreTextEditContext sender, CoreTextSelectionUpdatingEventArgs args)
796 if(this.Document.Length == 0 || args.IsCanceled)
798 args.Result = CoreTextSelectionUpdatingResult.Failed;
801 CoreTextRange sel = args.Selection;
802 System.Diagnostics.Debug.WriteLine("update selection start:{0} end:{1}", sel.StartCaretPosition, sel.EndCaretPosition);
803 TextStoreHelper.SetSelectionIndex(this.Controller, this.View, sel.StartCaretPosition, sel.EndCaretPosition);
804 args.Result = CoreTextSelectionUpdatingResult.Succeeded;
807 private void TextEditContext_TextUpdating(CoreTextEditContext sender, CoreTextTextUpdatingEventArgs args)
809 this.nowCompstion = true;
811 System.Diagnostics.Debug.WriteLine("update text (modify start:{0} end:{1}) text:{2} (new sel start:{0} end:{1})",
812 args.Range.StartCaretPosition, args.Range.EndCaretPosition, args.Text, args.NewSelection.StartCaretPosition, args.NewSelection.EndCaretPosition);
813 CoreTextRange sel = args.Range;
814 TextStoreHelper.SetSelectionIndex(this.Controller, this.View, sel.StartCaretPosition, sel.EndCaretPosition);
815 TextStoreHelper.InsertTextAtSelection(this._Controller, args.Text);
817 args.Result = CoreTextTextUpdatingResult.Succeeded;
819 this.nowCompstion = false;
822 private void TextEditContext_CompositionCompleted(CoreTextEditContext sender, CoreTextCompositionCompletedEventArgs args)
824 System.Diagnostics.Debug.WriteLine("end compostion");
825 TextStoreHelper.EndCompostion(this.Document);
829 private void TextEditContext_CompositionStarted(CoreTextEditContext sender, CoreTextCompositionStartedEventArgs args)
831 System.Diagnostics.Debug.WriteLine("start compstion");
832 TextStoreHelper.StartCompstion(this.Document);
835 private void TextEditContext_NotifyFocusLeaveCompleted(CoreTextEditContext sender, object args)
837 System.Diagnostics.Debug.WriteLine("notify focus leaved");
840 private void TextEditContext_FocusRemoved(CoreTextEditContext sender, object args)
842 System.Diagnostics.Debug.WriteLine("focus leaved");
845 void Controller_SelectionChanged(object sender, EventArgs e)
848 this.nowCaretMove = true;
849 SetValue(SelectedTextProperty, this._Controller.SelectedText);
850 SetValue(CaretPostionPropertyKey, this.Document.CaretPostion);
851 this.nowCaretMove = false;
853 if(!this.nowCompstion)
855 TextRange currentSelection = new TextRange();
856 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out currentSelection);
858 CoreTextRange currentSelectionRange = new CoreTextRange();
859 currentSelectionRange.StartCaretPosition = currentSelection.Index;
860 currentSelectionRange.EndCaretPosition = currentSelection.Index + currentSelection.Length;
862 System.Diagnostics.Debug.WriteLine("notify selection start:{0} end:{1}", currentSelectionRange.StartCaretPosition, currentSelectionRange.EndCaretPosition);
864 if (this.textEditContext != null)
865 this.textEditContext.NotifySelectionChanged(currentSelectionRange);
869 Gripper hittedGripper;
870 void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)
872 //Updateedの段階でヒットテストしてしまうとグリッパーを触ってもヒットしないことがある
873 this.hittedGripper = this.View.HitGripperFromPoint(e.Position);
876 private void GestureRecongnizer_ManipulationInertiaStarting(GestureRecognizer sender, ManipulationInertiaStartingEventArgs args)
878 //sender.InertiaTranslationDeceleration = 0.001f;
879 //sender.InertiaExpansionDeceleration = 100.0f * 96.0f / 1000.0f;
880 //sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
883 void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
885 if (this._Controller.MoveCaretAndGripper(e.Position, this.hittedGripper))
888 if (this.peer != null)
889 this.peer.OnNotifyCaretChanged();
895 if (e.Delta.Scale < 1)
897 double newSize = this.Render.FontSize - 1;
900 this.Render.FontSize = newSize;
902 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
906 if (e.Delta.Scale > 1)
908 double newSize = this.Render.FontSize + 1;
911 this.Render.FontSize = newSize;
913 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
917 Point translation = e.Delta.Translation;
919 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
920 if (Math.Abs(e.Cumulative.Translation.X) < Math.Abs(e.Cumulative.Translation.Y))
922 int deltay = (int)Math.Abs(Math.Ceiling(translation.Y));
923 if (translation.Y < 0)
924 this._Controller.ScrollByPixel(ScrollDirection.Down, deltay, false, false);
926 this._Controller.ScrollByPixel(ScrollDirection.Up, deltay, false, false);
931 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
934 if (translation.X < 0)
935 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
937 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
942 void gestureRecongnizer_ManipulationCompleted(GestureRecognizer sender, ManipulationCompletedEventArgs e)
946 async void gestureRecongnizer_RightTapped(GestureRecognizer sender, RightTappedEventArgs e)
948 ResourceMap map = ResourceManager.Current.MainResourceMap.GetSubtree("FooEditEngine.UWP/Resources");
949 ResourceContext context = ResourceContext.GetForCurrentView();
950 if (this.View.HitTextArea(e.Position.X, e.Position.Y))
952 FooContextMenuEventArgs args = new FooContextMenuEventArgs(e.Position);
953 if (this.ContextMenuOpening != null)
954 this.ContextMenuOpening(this, args);
957 PopupMenu ContextMenu = new PopupMenu();
958 ContextMenu.Commands.Add(new UICommand(map.GetValue("CopyMenuName", context).ValueAsString, (command) =>
962 ContextMenu.Commands.Add(new UICommand(map.GetValue("CutMenuName", context).ValueAsString, (command) =>
966 ContextMenu.Commands.Add(new UICommand(map.GetValue("PasteMenuName", context).ValueAsString, async (command) =>
968 await this.PasteCommand();
970 if (this._Controller.RectSelection)
972 ContextMenu.Commands.Add(new UICommand(map.GetValue("LineSelectMenuName", context).ValueAsString, (command) =>
974 this._Controller.RectSelection = false;
979 ContextMenu.Commands.Add(new UICommand(map.GetValue("RectSelectMenuName", context).ValueAsString, (command) =>
981 this._Controller.RectSelection = true;
984 await ContextMenu.ShowAsync(Util.GetScreentPoint(e.Position,this));
989 void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)
991 bool touched = e.PointerDeviceType == PointerDeviceType.Touch;
992 this.Document.SelectGrippers.BottomLeft.Enabled = false;
993 this.Document.SelectGrippers.BottomRight.Enabled = touched;
994 this.JumpCaret(e.Position);
997 this.Document.SelectGrippers.BottomLeft.Enabled = touched;
998 //タッチスクリーンでダブルタップした場合、アンカーインデックスを単語の先頭にしないとバグる
999 this.Document.SelectWord(this.Controller.SelectionStart, touched);
1004 void JumpCaret(Point p)
1006 TextPoint tp = this.View.GetTextPointFromPostion(p);
1007 if (tp == TextPoint.Null)
1010 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
1012 FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
1013 if (foldingData != null)
1015 if (foldingData.Expand)
1016 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
1018 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
1019 this._Controller.JumpCaret(foldingData.Start, false);
1023 this._Controller.JumpCaret(tp.row, tp.col, false);
1025 #if ENABLE_AUTMATION
1026 if (this.peer != null)
1027 this.peer.OnNotifyCaretChanged();
1029 this.View.IsFocused = true;
1030 this.Focus(FocusState.Programmatic);
1034 void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)
1036 Point p = e.Position;
1037 TextPointSearchRange searchRange;
1038 if (this.View.HitTextArea(p.X, p.Y))
1039 searchRange = TextPointSearchRange.TextAreaOnly;
1040 else if (this._Controller.SelectionLength > 0)
1041 searchRange = TextPointSearchRange.Full;
1044 TextPoint tp = this.View.GetTextPointFromPostion(p, searchRange);
1045 this._Controller.MoveCaretAndSelect(tp);
1046 #if ENABLE_AUTMATION
1047 if (this.peer != null)
1048 this.peer.OnNotifyCaretChanged();
1053 bool IsModiferKeyPressed(VirtualKey key)
1055 CoreVirtualKeyStates state = Window.Current.CoreWindow.GetKeyState(key);
1056 return (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
1058 void Refresh(Rectangle updateRect)
1060 if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0 || this.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
1063 this.Render.DrawContent(this.View, this.IsEnabled, updateRect);
1067 bool Resize(double width, double height)
1069 if (width == 0 || height == 0)
1070 throw new ArgumentOutOfRangeException();
1071 if (this.Render.Resize(this.rectangle, width, height))
1073 this.View.PageBound = new Rectangle(0, 0, width, height);
1075 if (this.horizontalScrollBar != null)
1077 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
1078 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1080 if (this.verticalScrollBar != null)
1082 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
1083 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1090 void View_SrcChanged(object sender, EventArgs e)
1092 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1094 EditView view = this.View;
1095 if (view.Src.Row > this.verticalScrollBar.Maximum)
1096 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
1097 double absoulteX = Math.Abs(view.Src.X);
1098 if (absoulteX > this.horizontalScrollBar.Maximum)
1099 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1100 if (view.Src.Row != this.verticalScrollBar.Value)
1101 this.verticalScrollBar.Value = view.Src.Row;
1102 if (view.Src.X != this.horizontalScrollBar.Value)
1103 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1106 void FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)
1108 if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))
1115 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1117 if (this.horizontalScrollBar == null)
1120 if (this.FlowDirection == FlowDirection.LeftToRight)
1121 toX = this.horizontalScrollBar.Value;
1123 toX = -this.horizontalScrollBar.Value;
1124 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
1128 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1130 if (this.verticalScrollBar == null)
1132 int newRow = (int)this.verticalScrollBar.Value;
1133 if (newRow >= this.View.LayoutLines.Count)
1135 this._Controller.Scroll(this.View.Src.X, newRow, false, false);
1139 void Document_Update(object sender, DocumentUpdateEventArgs e)
1141 if (e.type == UpdateType.Replace && !this.nowCompstion)
1143 CoreTextRange oldTextRange = new CoreTextRange();
1144 oldTextRange.StartCaretPosition = e.startIndex;
1145 oldTextRange.EndCaretPosition = e.startIndex + e.removeLength;
1147 TextRange currentSelection = new TextRange();
1148 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out currentSelection);
1150 CoreTextRange newSelection = new CoreTextRange();
1151 newSelection.StartCaretPosition = e.startIndex;
1152 newSelection.EndCaretPosition = e.startIndex;
1154 int newTextLength = e.insertLength; //置き換え後の長さを指定する
1156 System.Diagnostics.Debug.WriteLine("notify text change (modify start:{0} end:{1}) newlength:{2} (new sel start:{3} end:{4})",
1157 oldTextRange.StartCaretPosition, oldTextRange.EndCaretPosition, newTextLength, newSelection.StartCaretPosition, newSelection.EndCaretPosition);
1159 if(this.textEditContext != null)
1160 this.textEditContext.NotifyTextChanged(oldTextRange, newTextLength, newSelection);
1162 #if ENABLE_AUTMATION
1163 if (this.peer != null)
1164 this.peer.OnNotifyTextChanged();
1168 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1170 this.Focus(FocusState.Programmatic);
1173 void timer_Tick(object sender, object e)
1175 if (this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding())
1176 this.Refresh(this.View.PageBound);
1180 public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
1183 FooTextBox source = (FooTextBox)sender;
1184 if(e.Property.Equals(SelectedTextProperty) && !source.nowCaretMove)
1185 source._Controller.SelectedText = source.SelectedText;
1186 if(e.Property.Equals(HilighterProperty))
1187 source.View.Hilighter = source.Hilighter;
1188 if (e.Property.Equals(TextAntialiasModeProperty))
1189 source.Render.TextAntialiasMode = source.TextAntialiasMode;
1190 if (e.Property.Equals(FoldingStrategyProperty))
1191 source.View.LayoutLines.FoldingStrategy = source.FoldingStrategy;
1192 if (e.Property.Equals(IndentModeProperty))
1193 source.Controller.IndentMode = source.IndentMode;
1194 if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)
1195 source.Document.Select(source.Selection.Index,source.Selection.Length);
1196 if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)
1197 source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col);
1198 if (e.Property.Equals(InsertModeProperty))
1199 source.View.InsertMode = source.InsertMode;
1200 if (e.Property.Equals(TabCharsProperty))
1201 source.Document.TabStops = source.TabChars;
1202 if (e.Property.Equals(RectSelectModeProperty))
1203 source._Controller.RectSelection = source.RectSelectMode;
1204 if (e.Property.Equals(DrawCaretProperty))
1205 source.View.HideCaret = !source.DrawCaret;
1206 if (e.Property.Equals(DrawCaretLineProperty))
1207 source.View.HideLineMarker = !source.DrawCaretLine;
1208 if (e.Property.Equals(DrawLineNumberProperty))
1209 source.Document.DrawLineNumber = source.DrawLineNumber;
1210 if(e.Property.Equals(MagnificationPowerPropertyKey))
1211 source.Render.FontSize = source.FontSize * source.MagnificationPower;
1212 if (e.Property.Equals(FontFamilyProperty))
1213 source.Render.FontFamily = source.FontFamily;
1214 if (e.Property.Equals(FontStyleProperty))
1215 source.Render.FontStyle = source.FontStyle;
1216 if (e.Property.Equals(FontWeightProperty))
1217 source.Render.FontWeigth = source.FontWeight;
1218 if (e.Property.Equals(FontSizeProperty))
1219 source.Render.FontSize = source.FontSize;
1220 if (e.Property.Equals(ForegroundProperty))
1221 source.Render.Foreground = D2DRenderBase.ToColor4(source.Foreground);
1222 if (e.Property.Equals(BackgroundProperty))
1223 source.Render.Background = D2DRenderBase.ToColor4(source.Background);
1224 if (e.Property.Equals(ControlCharProperty))
1225 source.Render.ControlChar = D2DRenderBase.ToColor4(source.ControlChar);
1226 if (e.Property.Equals(HilightProperty))
1227 source.Render.Hilight = D2DRenderBase.ToColor4(source.Hilight);
1228 if (e.Property.Equals(Keyword1Property))
1229 source.Render.Keyword1 = D2DRenderBase.ToColor4(source.Keyword1);
1230 if (e.Property.Equals(Keyword2Property))
1231 source.Render.Keyword2 = D2DRenderBase.ToColor4(source.Keyword2);
1232 if (e.Property.Equals(CommentProperty))
1233 source.Render.Comment = D2DRenderBase.ToColor4(source.Comment);
1234 if (e.Property.Equals(LiteralProperty))
1235 source.Render.Literal = D2DRenderBase.ToColor4(source.Literal);
1236 if (e.Property.Equals(URLProperty))
1237 source.Render.Url = D2DRenderBase.ToColor4(source.URL);
1238 if (e.Property.Equals(InsertCaretProperty))
1239 source.Render.InsertCaret = D2DRenderBase.ToColor4(source.InsertCaret);
1240 if (e.Property.Equals(OverwriteCaretProperty))
1241 source.Render.OverwriteCaret = D2DRenderBase.ToColor4(source.OverwriteCaret);
1242 if (e.Property.Equals(PaddingProperty))
1243 source.View.Padding = new Padding((int)source.Padding.Left, (int)source.Padding.Top, (int)source.Padding.Right, (int)source.Padding.Bottom);
1244 if (e.Property.Equals(LineMarkerProperty))
1245 source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);
1246 if (e.Property.Equals(MarkURLProperty))
1247 source.Document.UrlMark = source.MarkURL;
1248 if (e.Property.Equals(ShowFullSpaceProperty))
1249 source.Render.ShowFullSpace = source.ShowFullSpace;
1250 if (e.Property.Equals(ShowHalfSpaceProperty))
1251 source.Render.ShowHalfSpace = source.ShowHalfSpace;
1252 if (e.Property.Equals(ShowTabProperty))
1253 source.Render.ShowTab = source.ShowTab;
1254 if (e.Property.Equals(ShowLineBreakProperty))
1255 source.Render.ShowLineBreak = source.ShowLineBreak;
1256 if (e.Property.Equals(LineBreakProperty))
1257 source.Document.LineBreak = source.LineBreakMethod;
1258 if (e.Property.Equals(LineBreakCharCountProperty))
1259 source.Document.LineBreakCharCount = source.LineBreakCharCount;
1260 if (e.Property.Equals(UpdateAreaProperty))
1261 source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);
1262 if (e.Property.Equals(LineNumberProperty))
1263 source.Render.LineNumber = D2DRenderBase.ToColor4(source.LineNumber);
1264 if (e.Property.Equals(FlowDirectionProperty))
1266 source.Document.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;
1267 if(source.horizontalScrollBar != null)
1268 source.horizontalScrollBar.FlowDirection = source.FlowDirection;
1270 if (e.Property.Equals(DrawRulerProperty))
1272 source.Document.HideRuler = !source.DrawRuler;
1273 source._Controller.JumpCaret(source.Document.CaretPostion.row, source.Document.CaretPostion.col);
1282 /// コンテキストメニューが表示されるときに呼び出されます
1284 public event EventHandler<FooContextMenuEventArgs> ContextMenuOpening;
1290 internal Controller Controller
1294 return this._Controller;
1299 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1301 public TextAntialiasMode TextAntialiasMode
1303 get { return (TextAntialiasMode)GetValue(TextAntialiasModeProperty); }
1304 set { SetValue(TextAntialiasModeProperty, value); }
1308 /// TextAntialiasModeの依存プロパティを表す
1310 public static readonly DependencyProperty TextAntialiasModeProperty =
1311 DependencyProperty.Register("TextAntialiasMode", typeof(TextAntialiasMode), typeof(FooTextBox), new PropertyMetadata(TextAntialiasMode.Default, OnPropertyChanged));
1316 public IHilighter Hilighter
1318 get { return (IHilighter)GetValue(HilighterProperty); }
1319 set { SetValue(HilighterProperty, value); }
1323 /// Hilighterの依存プロパティを表す
1325 public static readonly DependencyProperty HilighterProperty =
1326 DependencyProperty.Register("Hilighter", typeof(IHilighter), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
1329 /// フォールティングを作成するインターフェイスを表す
1331 public IFoldingStrategy FoldingStrategy
1333 get { return (IFoldingStrategy)GetValue(FoldingStrategyProperty); }
1334 set { SetValue(FoldingStrategyProperty, value); }
1338 /// FoldingStrategyの依存プロパティ
1340 public static readonly DependencyProperty FoldingStrategyProperty =
1341 DependencyProperty.Register("FoldingStrategy", typeof(IFoldingStrategy), typeof(FooTextBox), new PropertyMetadata(null,OnPropertyChanged));
1346 public MarkerPatternSet MarkerPatternSet
1350 return this.Document.MarkerPatternSet;
1357 public Document Document
1361 return this._Document;
1365 Document old_doc = this._Document;
1366 CoreTextRange oldDocRnage = new CoreTextRange();
1367 if (this._Document != null)
1369 old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
1370 oldDocRnage.StartCaretPosition = 0;
1371 oldDocRnage.EndCaretPosition = old_doc.Length;
1374 this._Document = value;
1375 this._Document.LayoutLines.Render = this.Render;
1376 this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
1377 //初期化が終わっていればすべて存在する
1378 if (this.Controller != null && this.View != null && this.textEditContext != null)
1380 this.Controller.Document = value;
1381 this.View.Document = value;
1382 this.Controller.AdjustCaret();
1384 CoreTextRange newSelRange = new CoreTextRange();
1385 newSelRange.StartCaretPosition = this.Controller.SelectionStart;
1386 newSelRange.EndCaretPosition = this.Controller.SelectionLength > 0 ? this.Controller.SelectionStart + this.Controller.SelectionLength - 1 : this.Controller.SelectionStart;
1388 System.Diagnostics.Debug.WriteLine("notify text change (modify start:{0} end:{1}) newlength:{2} (new sel start:{0} end:{1})",
1389 oldDocRnage.StartCaretPosition, oldDocRnage.EndCaretPosition, value, newSelRange.StartCaretPosition, newSelRange.EndCaretPosition);
1390 if (this.textEditContext != null)
1391 this.textEditContext.NotifyTextChanged(oldDocRnage, value.Length, newSelRange);
1393 //依存プロパティとドキュメント内容が食い違っているので再設定する
1394 this.ShowFullSpace = value.ShowFullSpace;
1395 this.ShowHalfSpace = value.ShowHalfSpace;
1396 this.ShowLineBreak = value.ShowLineBreak;
1397 this.ShowTab = value.ShowTab;
1398 this.FlowDirection = value.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
1399 this.IndentMode = value.IndentMode;
1400 this.DrawCaretLine = !value.HideLineMarker;
1401 this.InsertMode = value.InsertMode;
1402 this.DrawRuler = !value.HideRuler;
1403 this.DrawLineNumber = value.DrawLineNumber;
1404 this.MarkURL = value.UrlMark;
1405 this.LineBreakMethod = value.LineBreak;
1406 this.LineBreakCharCount = value.LineBreakCharCount;
1407 this.TabChars = value.TabStops;
1417 public LineToIndexTable LayoutLineCollection
1419 get { return this.View.LayoutLines; }
1425 public string SelectedText
1427 get { return (string)GetValue(SelectedTextProperty); }
1428 set { SetValue(SelectedTextProperty, value); }
1432 /// SelectedTextの依存プロパティを表す
1434 public static readonly DependencyProperty SelectedTextProperty =
1435 DependencyProperty.Register("SelectedText", typeof(string), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
1440 public IndentMode IndentMode
1442 get { return (IndentMode)GetValue(IndentModeProperty); }
1443 set { SetValue(IndentModeProperty, value); }
1447 /// IndentModeの依存プロパティを表す
1449 public static readonly DependencyProperty IndentModeProperty =
1450 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab,OnPropertyChanged));
1456 /// Lengthが0の場合はキャレット位置を表します。
1457 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1459 public TextRange Selection
1461 get { return (TextRange)GetValue(SelectionProperty); }
1462 set { SetValue(SelectionProperty, value); }
1466 /// Selectionの依存プロパティを表す
1468 public static readonly DependencyProperty SelectionProperty =
1469 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null, OnPropertyChanged));
1474 public double MagnificationPower
1476 get { return (double)GetValue(MagnificationPowerPropertyKey); }
1477 set { SetValue(MagnificationPowerPropertyKey, value); }
1483 public static readonly DependencyProperty MagnificationPowerPropertyKey =
1484 DependencyProperty.Register("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0, OnPropertyChanged));
1489 public TextPoint CaretPostion
1491 get { return (TextPoint)GetValue(CaretPostionPropertyKey); }
1492 set { SetValue(CaretPostionPropertyKey, value); }
1495 static readonly DependencyProperty CaretPostionPropertyKey =
1496 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(new TextPoint(), OnPropertyChanged));
1501 public new FlowDirection FlowDirection
1503 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1504 set { SetValue(FlowDirectionProperty, value); }
1508 /// レタリング方向を表す。これは依存プロパティです
1510 public new static readonly DependencyProperty FlowDirectionProperty =
1511 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight,OnPropertyChanged));
1516 public new FontFamily FontFamily
1518 get { return (FontFamily)GetValue(FontFamilyProperty); }
1519 set { SetValue(FontFamilyProperty, value); }
1523 /// FontFamilyの依存プロパティを表す
1525 public new static readonly DependencyProperty FontFamilyProperty =
1526 DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(FooTextBox), new PropertyMetadata(new FontFamily("Cambria"), OnPropertyChanged));
1531 public new double FontSize
1533 get { return (double)GetValue(FontSizeProperty); }
1534 set { SetValue(FontSizeProperty, value); }
1538 /// FontSizeの依存プロパティを表す
1540 public new static readonly DependencyProperty FontSizeProperty =
1541 DependencyProperty.Register("FontSize", typeof(double), typeof(FooTextBox), new PropertyMetadata(12.0,OnPropertyChanged));
1546 public new FontStyle FontStyle
1548 get { return (FontStyle)GetValue(FontStyleProperty); }
1549 set { SetValue(FontStyleProperty, value); }
1553 /// FontStyleの依存プロパティを表す
1555 public new static readonly DependencyProperty FontStyleProperty =
1556 DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(FooTextBox), new PropertyMetadata(FontStyle.Normal,OnPropertyChanged));
1561 public new FontWeight FontWeight
1563 get { return (FontWeight)GetValue(FontWeightProperty); }
1564 set { SetValue(FontWeightProperty, value); }
1568 /// FontWeigthの依存プロパティを表す
1570 public new static readonly DependencyProperty FontWeightProperty =
1571 DependencyProperty.Register("FontWeigth", typeof(FontWeight), typeof(FooTextBox), new PropertyMetadata(FontWeights.Normal,OnPropertyChanged));
1574 /// デフォルトの文字色を表す。これは依存プロパティです
1576 public new Windows.UI.Color Foreground
1578 get { return (Windows.UI.Color)GetValue(ForegroundProperty); }
1579 set { SetValue(ForegroundProperty, value); }
1583 /// Foregroundの依存プロパティを表す
1585 public new static readonly DependencyProperty ForegroundProperty =
1586 DependencyProperty.Register("Foreground", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1589 /// 背景色を表す。これは依存プロパティです
1591 public new Windows.UI.Color Background
1593 get { return (Windows.UI.Color)GetValue(BackgroundProperty); }
1594 set { SetValue(BackgroundProperty, value); }
1598 /// Backgroundの依存プロパティを表す
1600 public new static readonly DependencyProperty BackgroundProperty =
1601 DependencyProperty.Register("Background", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));
1604 /// コントロールコードの文字色を表す。これは依存プロパティです
1606 public Windows.UI.Color ControlChar
1608 get { return (Windows.UI.Color)GetValue(ControlCharProperty); }
1609 set { SetValue(ControlCharProperty, value); }
1613 /// ControlCharの依存プロパティを表す
1615 public static readonly DependencyProperty ControlCharProperty =
1616 DependencyProperty.Register("ControlChar", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1619 /// 選択時の背景色を表す。これは依存プロパティです
1621 public Windows.UI.Color Hilight
1623 get { return (Windows.UI.Color)GetValue(HilightProperty); }
1624 set { SetValue(HilightProperty, value); }
1628 /// Hilightの依存プロパティを表す
1630 public static readonly DependencyProperty HilightProperty =
1631 DependencyProperty.Register("Hilight", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DeepSkyBlue, OnPropertyChanged));
1634 /// キーワード1の文字色を表す。これは依存プロパティです
1636 public Windows.UI.Color Keyword1
1638 get { return (Windows.UI.Color)GetValue(Keyword1Property); }
1639 set { SetValue(Keyword1Property, value); }
1643 /// Keyword1の依存プロパティを表す
1645 public static readonly DependencyProperty Keyword1Property =
1646 DependencyProperty.Register("Keyword1", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1649 /// キーワード2の文字色を表す。これは依存プロパティです
1651 public Windows.UI.Color Keyword2
1653 get { return (Windows.UI.Color)GetValue(Keyword2Property); }
1654 set { SetValue(Keyword2Property, value); }
1658 /// Keyword2の依存プロパティを表す
1660 public static readonly DependencyProperty Keyword2Property =
1661 DependencyProperty.Register("Keyword2", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DarkCyan, OnPropertyChanged));
1664 /// コメントの文字色を表す。これは依存プロパティです
1666 public Windows.UI.Color Comment
1668 get { return (Windows.UI.Color)GetValue(CommentProperty); }
1669 set { SetValue(CommentProperty, value); }
1673 /// Commentの依存プロパティを表す
1675 public static readonly DependencyProperty CommentProperty =
1676 DependencyProperty.Register("Comment", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Green, OnPropertyChanged));
1679 /// 文字リテラルの文字色を表す。これは依存プロパティです
1681 public Windows.UI.Color Literal
1683 get { return (Windows.UI.Color)GetValue(LiteralProperty); }
1684 set { SetValue(LiteralProperty, value); }
1688 /// Literalの依存プロパティを表す
1690 public static readonly DependencyProperty LiteralProperty =
1691 DependencyProperty.Register("Literal", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Brown, OnPropertyChanged));
1694 /// URLの文字色を表す。これは依存プロパティです
1696 public Windows.UI.Color URL
1698 get { return (Windows.UI.Color)GetValue(URLProperty); }
1699 set { SetValue(URLProperty, value); }
1705 public static readonly DependencyProperty URLProperty =
1706 DependencyProperty.Register("URL", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1711 public Windows.UI.Color UpdateArea
1713 get { return (Windows.UI.Color)GetValue(UpdateAreaProperty); }
1714 set { SetValue(UpdateAreaProperty, value); }
1718 /// UpdateAreaの依存プロパティを表す
1720 public static readonly DependencyProperty UpdateAreaProperty =
1721 DependencyProperty.Register("UpdateArea", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen, OnPropertyChanged));
1726 public Windows.UI.Color LineMarker
1728 get { return (Windows.UI.Color)GetValue(LineMarkerProperty); }
1729 set { SetValue(LineMarkerProperty, value); }
1733 /// LineMarkerの依存プロパティを表す
1735 public static readonly DependencyProperty LineMarkerProperty =
1736 DependencyProperty.Register("LineMarker", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1739 /// 挿入モード時のキャレットの色を表す
1741 public Windows.UI.Color InsertCaret
1743 get { return (Windows.UI.Color)GetValue(InsertCaretProperty); }
1744 set { SetValue(InsertCaretProperty, value); }
1748 /// InsertCaretの依存プロパティを表す
1750 public static readonly DependencyProperty InsertCaretProperty =
1751 DependencyProperty.Register("InsertCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1754 /// 上書きモード時のキャレット職を表す
1756 public Windows.UI.Color OverwriteCaret
1758 get { return (Windows.UI.Color)GetValue(OverwriteCaretProperty); }
1759 set { SetValue(OverwriteCaretProperty, value); }
1763 /// OverwriteCaretの依存プロパティを表す
1765 public static readonly DependencyProperty OverwriteCaretProperty =
1766 DependencyProperty.Register("OverwriteCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1771 public Windows.UI.Color LineNumber
1773 get { return (Windows.UI.Color)GetValue(LineNumberProperty); }
1774 set { SetValue(LineNumberProperty, value); }
1778 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1780 public static readonly DependencyProperty LineNumberProperty =
1781 DependencyProperty.Register("LineNumber", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray,OnPropertyChanged));
1786 public new Thickness Padding
1788 get { return (Thickness)GetValue(PaddingProperty); }
1789 set { SetValue(PaddingProperty, value); }
1793 /// Paddingの依存プロパティを表す
1795 public new static readonly DependencyProperty PaddingProperty =
1796 DependencyProperty.Register("Padding", typeof(Thickness), typeof(FooTextBox), new PropertyMetadata(new Thickness(),OnPropertyChanged));
1799 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1801 public bool InsertMode
1803 get { return (bool)GetValue(InsertModeProperty); }
1804 set { SetValue(InsertModeProperty, value); }
1808 /// InsertModeの依存プロパティを表す
1810 public static readonly DependencyProperty InsertModeProperty =
1811 DependencyProperty.Register("InsertMode",
1814 new PropertyMetadata(true, OnPropertyChanged));
1817 /// タブの文字数を表す。これは依存プロパティです
1821 get { return (int)GetValue(TabCharsProperty); }
1822 set { SetValue(TabCharsProperty, value); }
1826 /// TabCharsの依存プロパティを表す
1828 public static readonly DependencyProperty TabCharsProperty =
1829 DependencyProperty.Register("TabChars",
1832 new PropertyMetadata(4, OnPropertyChanged));
1835 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1837 public bool RectSelectMode
1839 get { return (bool)GetValue(RectSelectModeProperty); }
1840 set { SetValue(RectSelectModeProperty, value); }
1844 /// RectSelectModeの依存プロパティを表す
1846 public static readonly DependencyProperty RectSelectModeProperty =
1847 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1853 /// 変更した場合、レイアウトの再構築を行う必要があります
1855 public LineBreakMethod LineBreakMethod
1857 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1858 set { SetValue(LineBreakProperty, value); }
1862 /// LineBreakMethodの依存プロパティを表す
1864 public static readonly DependencyProperty LineBreakProperty =
1865 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None, OnPropertyChanged));
1869 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1872 /// 変更した場合、レイアウトの再構築を行う必要があります
1874 public int LineBreakCharCount
1876 get { return (int)GetValue(LineBreakCharCountProperty); }
1877 set { SetValue(LineBreakCharCountProperty, value); }
1881 /// LineBreakCharCountの依存プロパティを表す
1883 public static readonly DependencyProperty LineBreakCharCountProperty =
1884 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80, OnPropertyChanged));
1887 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1889 public bool DrawCaret
1891 get { return (bool)GetValue(DrawCaretProperty); }
1892 set { SetValue(DrawCaretProperty, value); }
1896 /// DrawCaretの依存プロパティを表す
1898 public static readonly DependencyProperty DrawCaretProperty =
1899 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new PropertyMetadata(true, OnPropertyChanged));
1903 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1905 public bool DrawCaretLine
1907 get { return (bool)GetValue(DrawCaretLineProperty); }
1908 set { SetValue(DrawCaretLineProperty, value); }
1912 /// DrawCaretLineの依存プロパティを表す
1914 public static readonly DependencyProperty DrawCaretLineProperty =
1915 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1918 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
1920 public bool DrawLineNumber
1922 get { return (bool)GetValue(DrawLineNumberProperty); }
1923 set { SetValue(DrawLineNumberProperty, value); }
1927 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
1929 public bool DrawRuler
1931 get { return (bool)GetValue(DrawRulerProperty); }
1932 set { SetValue(DrawRulerProperty, value); }
1936 /// DrawRulerの依存プロパティを表す
1938 public static readonly DependencyProperty DrawRulerProperty =
1939 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1943 /// DrawLineNumberの依存プロパティを表す
1945 public static readonly DependencyProperty DrawLineNumberProperty =
1946 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1949 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
1953 get { return (bool)GetValue(MarkURLProperty); }
1954 set { SetValue(MarkURLProperty, value); }
1958 /// MarkURLの依存プロパティを表す
1960 public static readonly DependencyProperty MarkURLProperty =
1961 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1964 /// 全角スペースを表示するなら真。そうでないなら偽
1966 public bool ShowFullSpace
1968 get { return (bool)GetValue(ShowFullSpaceProperty); }
1969 set { SetValue(ShowFullSpaceProperty, value); }
1973 /// ShowFullSpaceの依存プロパティを表す
1975 public static readonly DependencyProperty ShowFullSpaceProperty =
1976 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1979 /// 半角スペースを表示するなら真。そうでないなら偽
1981 public bool ShowHalfSpace
1983 get { return (bool)GetValue(ShowHalfSpaceProperty); }
1984 set { SetValue(ShowHalfSpaceProperty, value); }
1988 /// ShowHalfSpaceの依存プロパティを表す
1990 public static readonly DependencyProperty ShowHalfSpaceProperty =
1991 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1994 /// タブを表示するなら真。そうでないなら偽
1998 get { return (bool)GetValue(ShowTabProperty); }
1999 set { SetValue(ShowTabProperty, value); }
2003 /// ShowTabの依存プロパティを表す
2005 public static readonly DependencyProperty ShowTabProperty =
2006 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
2009 /// 改行マークを表示するなら真。そうでないなら偽
2011 public bool ShowLineBreak
2013 get { return (bool)GetValue(ShowLineBreakProperty); }
2014 set { SetValue(ShowLineBreakProperty, value); }
2018 /// ShowLineBreakの依存プロパティを表す
2020 public static readonly DependencyProperty ShowLineBreakProperty =
2021 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false,OnPropertyChanged));
2027 /// コンテキストメニューのイベントデーターを表す
2029 public class FooContextMenuEventArgs
2032 /// 処理済みなら真。そうでないなら偽
2034 public bool Handled = false;
2036 /// コンテキストメニューを表示すべき座標を表す
2038 public Windows.Foundation.Point Postion;
2042 /// <param name="pos"></param>
2043 public FooContextMenuEventArgs(Windows.Foundation.Point pos)