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 DotNetTextStore;
31 using DotNetTextStore.UnmanagedAPI.TSF;
32 using DotNetTextStore.UnmanagedAPI.WinDef;
34 // テンプレート コントロールのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234235 を参照してください
36 namespace FooEditEngine.Metro
41 public sealed class FooTextBox : Control,IDisposable
44 Controller _Controller;
46 ScrollBar horizontalScrollBar, verticalScrollBar;
47 Windows.UI.Xaml.Shapes.Rectangle rectangle;
48 GestureRecognizer gestureRecongnizer = new GestureRecognizer();
50 FooTextBoxAutomationPeer peer;
51 bool nowCaretMove = false;
53 DispatcherTimer timer = new DispatcherTimer();
60 this.DefaultStyleKey = typeof(FooTextBox);
62 this.textStore = new TextStore2();
63 this.textStore.IsLoading += textStore_IsLoading;
64 this.textStore.IsReadOnly += textStore_IsReadOnly;
65 this.textStore.GetStringLength += () => this.Document.Length;
66 this.textStore.GetString += _textStore_GetString;
67 this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;
68 this.textStore.SetSelectionIndex += _textStore_SetSelectionIndex;
69 this.textStore.InsertAtSelection += _textStore_InsertAtSelection;
70 this.textStore.GetScreenExtent += _textStore_GetScreenExtent;
71 this.textStore.GetStringExtent += _textStore_GetStringExtent;
72 this.textStore.CompositionStarted += textStore_CompositionStarted;
73 this.textStore.CompositionUpdated += textStore_CompositionUpdated;
74 this.textStore.CompositionEnded += textStore_CompositionEnded;
76 this.rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
77 this.rectangle.Margin = this.Padding;
78 this.Render = new D2DRender(this,this.rectangle,this.textStore);
80 this.Document = new Document();
82 this.View = new EditView(this.Document, this.Render, new Padding(5, Gripper.HitAreaWidth, Gripper.HitAreaWidth / 2, Gripper.HitAreaWidth));
83 this.View.SrcChanged += View_SrcChanged;
84 this.View.InsertMode = this.InsertMode;
85 this.Document.DrawLineNumber = this.DrawLineNumber;
86 this.View.HideCaret = !this.DrawCaret;
87 this.View.HideLineMarker = !this.DrawCaretLine;
88 this.Document.HideRuler = !this.DrawRuler;
89 this.Document.UrlMark = this.MarkURL;
90 this.Document.TabStops = this.TabChars;
92 this._Controller = new Controller(this.Document, this.View);
93 this.Document.SelectionChanged += Controller_SelectionChanged;
95 this.gestureRecongnizer.GestureSettings = GestureSettings.Drag |
96 GestureSettings.RightTap |
98 GestureSettings.DoubleTap |
99 GestureSettings.ManipulationTranslateX |
100 GestureSettings.ManipulationTranslateY |
101 GestureSettings.ManipulationScale |
102 GestureSettings.ManipulationTranslateInertia |
103 GestureSettings.ManipulationScaleInertia;
104 this.gestureRecongnizer.RightTapped += gestureRecongnizer_RightTapped;
105 this.gestureRecongnizer.Tapped += gestureRecongnizer_Tapped;
106 this.gestureRecongnizer.Dragging += gestureRecongnizer_Dragging;
107 this.gestureRecongnizer.ManipulationInertiaStarting += GestureRecongnizer_ManipulationInertiaStarting; ;
108 this.gestureRecongnizer.ManipulationStarted += gestureRecongnizer_ManipulationStarted;
109 this.gestureRecongnizer.ManipulationUpdated += gestureRecongnizer_ManipulationUpdated;
110 this.gestureRecongnizer.ManipulationCompleted += gestureRecongnizer_ManipulationCompleted;
112 this.timer.Interval = new TimeSpan(0, 0, 0, 0, 500);
113 this.timer.Tick += this.timer_Tick;
116 //Viewの初期化が終わった直後に置かないと例外が発生する
117 this.Document.Update += Document_Update;
119 Window.Current.CoreWindow.CharacterReceived += CoreWindow_CharacterReceived;
121 this.SizeChanged += FooTextBox_SizeChanged;
123 this.Loaded += FooTextBox_Loaded;
137 public void Dispose()
140 GC.SuppressFinalize(this);
143 bool Disposed = false;
144 private void Dispose(bool disposing)
150 this.textStore.Dispose();
152 this.Render.Dispose();
159 /// <param name="start">開始インデックス</param>
160 /// <param name="length">長さ</param>
161 public void Select(int start, int length)
163 this.Document.Select(start, length);
167 /// キャレットを指定した行に移動させます
169 /// <param name="index">インデックス</param>
170 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
171 public void JumpCaret(int index)
173 this._Controller.JumpCaret(index);
176 /// キャレットを指定した行と桁に移動させます
178 /// <param name="row">行番号</param>
179 /// <param name="col">桁</param>
180 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
181 public void JumpCaret(int row, int col)
183 this._Controller.JumpCaret(row, col);
187 /// 選択中のテキストをクリップボードにコピーします
191 string text = this._Controller.SelectedText;
192 if (text != null && text != string.Empty)
194 DataPackage dataPackage = new DataPackage();
195 dataPackage.RequestedOperation = DataPackageOperation.Copy;
196 dataPackage.SetText(text);
198 Clipboard.SetContent(dataPackage);
203 /// 選択中のテキストをクリップボードに切り取ります
207 string text = this._Controller.SelectedText;
208 if (text != null && text != string.Empty)
210 DataPackage dataPackage = new DataPackage();
211 dataPackage.RequestedOperation = DataPackageOperation.Copy;
212 dataPackage.SetText(text);
214 Clipboard.SetContent(dataPackage);
216 this._Controller.SelectedText = "";
223 public async Task PasteAsync()
225 var dataPackageView = Clipboard.GetContent();
226 if (dataPackageView.Contains(StandardDataFormats.Text))
228 this._Controller.SelectedText = await dataPackageView.GetTextAsync();
235 public void SelectAll()
237 this.Document.Select(0, this.Document.Length);
243 public void DeSelectAll()
245 this._Controller.DeSelectAll();
251 /// <param name="tp">テキストポイント</param>
252 /// <returns>座標</returns>
253 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
254 public Windows.Foundation.Point GetPostionFromTextPoint(TextPoint tp)
256 if (this.Document.FireUpdateEvent == false)
257 throw new InvalidOperationException("");
258 return this.View.GetPostionFromTextPoint(tp);
262 /// 対応するテキストポイントを返します
264 /// <param name="p">クライアント領域の原点を左上とする座標</param>
265 /// <returns>テキストポイント</returns>
266 public TextPoint GetTextPointFromPostion(Windows.Foundation.Point p)
268 if (this.Document.FireUpdateEvent == false)
269 throw new InvalidOperationException("");
270 return this.View.GetTextPointFromPostion(p);
276 /// <param name="row">レイアウト行</param>
277 /// <returns>行の高さ</returns>
278 public double GetLineHeight(int row)
280 if (this.Document.FireUpdateEvent == false)
281 throw new InvalidOperationException("");
282 return this.View.LayoutLines.GetLayout(row).Height; ;
286 /// インデックスに対応する座標を得ます
288 /// <param name="index">インデックス</param>
289 /// <returns>座標を返す</returns>
290 public Windows.Foundation.Point GetPostionFromIndex(int index)
292 if (this.Document.FireUpdateEvent == false)
293 throw new InvalidOperationException("");
294 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
295 return this.View.GetPostionFromTextPoint(tp);
301 /// <param name="p">座標</param>
302 /// <returns>インデックスを返す</returns>
303 public int GetIndexFromPostion(Windows.Foundation.Point p)
305 if (this.Document.FireUpdateEvent == false)
306 throw new InvalidOperationException("");
307 TextPoint tp = this.View.GetTextPointFromPostion(p);
308 return this.View.GetIndexFromLayoutLine(tp);
314 public void Refresh()
316 this.Refresh(this.View.PageBound);
320 /// レイアウト行をすべて破棄し、再度レイアウトを行う
322 public void PerfomLayouts()
324 this.View.PerfomLayouts();
330 /// <param name="row">行</param>
331 /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
332 public void ScrollIntoView(int row, bool alignTop)
334 this.View.ScrollIntoView(row, alignTop);
338 /// ファイルからドキュメントを構築する
340 /// <param name="sr">StremReader</param>
341 /// <returns>Taskオブジェクト</returns>
342 public async Task LoadFileAsync(System.IO.StreamReader sr, System.Threading.CancellationTokenSource token)
344 this.IsEnabled = false;
345 this.View.LayoutLines.IsFrozneDirtyFlag = true;
346 WinFileReader fs = new WinFileReader(sr);
347 await this.Document.LoadAsync(fs, token);
348 this.View.LayoutLines.IsFrozneDirtyFlag = false;
349 TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
350 if (this.verticalScrollBar != null)
351 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
352 this.View.CalculateLineCountOnScreen();
353 this.IsEnabled = true;
357 /// ドキュメントの内容をファイルに保存する
359 /// <param name="sw">StreamWriter</param>
360 /// <param name="enc">エンコード</param>
361 /// <returns>Taskオブジェクト</returns>
362 public async Task SaveFile(System.IO.StreamWriter sw, System.Threading.CancellationTokenSource token)
364 WinFileWriter fs = new WinFileWriter(sw);
365 await this.Document.SaveAsync(fs, token);
380 async Task PasteCommand()
382 await this.PasteAsync();
390 protected override Windows.UI.Xaml.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
392 this.peer = new FooTextBoxAutomationPeer(this);
397 protected override void OnApplyTemplate()
399 base.OnApplyTemplate();
401 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
404 Grid.SetRow(this.rectangle, 0);
405 Grid.SetColumn(this.rectangle, 0);
406 grid.Children.Add(this.rectangle);
409 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
410 if (this.horizontalScrollBar != null)
412 this.horizontalScrollBar.SmallChange = 10;
413 this.horizontalScrollBar.LargeChange = 100;
414 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
415 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
417 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
418 if (this.verticalScrollBar != null)
420 this.verticalScrollBar.SmallChange = 1;
421 this.verticalScrollBar.LargeChange = 10;
422 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
423 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
428 protected override void OnGotFocus(RoutedEventArgs e)
431 this.textStore.SetFocus();
432 this.View.IsFocused = true;
437 protected override void OnLostFocus(RoutedEventArgs e)
440 this.View.IsFocused = false;
445 protected override async void OnKeyDown(KeyRoutedEventArgs e)
447 bool isControlPressed = this.IsModiferKeyPressed(VirtualKey.Control);
448 bool isShiftPressed = this.IsModiferKeyPressed(VirtualKey.Shift);
449 bool isMovedCaret = false;
453 this._Controller.MoveCaretVertical(-1, isShiftPressed);
458 case VirtualKey.Down:
459 this._Controller.MoveCaretVertical(+1, isShiftPressed);
464 case VirtualKey.Left:
465 this._Controller.MoveCaretHorizontical(-1, isShiftPressed, isControlPressed);
470 case VirtualKey.Right:
471 this._Controller.MoveCaretHorizontical(1, isShiftPressed, isControlPressed);
476 case VirtualKey.PageUp:
477 this._Controller.Scroll(ScrollDirection.Up, this.View.LineCountOnScreen, isShiftPressed, true);
481 case VirtualKey.PageDown:
482 this._Controller.Scroll(ScrollDirection.Down, this.View.LineCountOnScreen, isShiftPressed, true);
486 case VirtualKey.Home:
487 if (isControlPressed)
488 this._Controller.JumpToHead(isShiftPressed);
490 this.Controller.JumpToLineHead(this.Document.CaretPostion.row,isShiftPressed);
495 if (isControlPressed)
496 this._Controller.JumpToEnd(isShiftPressed);
498 this.Controller.JumpToLineEnd(this.Document.CaretPostion.row,isShiftPressed);
503 if (!isControlPressed)
505 if (this._Controller.SelectionLength == 0)
506 this._Controller.DoInputChar('\t');
507 else if (isShiftPressed)
508 this._Controller.DownIndent();
510 this._Controller.UpIndent();
515 case VirtualKey.Enter:
516 this._Controller.DoEnterAction();
520 case VirtualKey.Insert:
521 if(this.View.InsertMode)
522 this.View.InsertMode = false;
524 this.View.InsertMode = true;
529 if (isControlPressed)
537 if (isControlPressed)
539 if (this._Controller.RectSelection)
540 this._Controller.RectSelection = false;
542 this._Controller.RectSelection = true;
548 if (isControlPressed)
555 if (isControlPressed)
562 if (isControlPressed)
564 await this.PasteCommand();
569 if (isControlPressed)
571 this.Document.UndoManager.redo();
577 if (isControlPressed)
579 this.Document.UndoManager.undo();
584 case VirtualKey.Back:
585 this._Controller.DoBackSpaceAction();
589 case VirtualKey.Delete:
590 this._Controller.DoDeleteAction();
595 if (isMovedCaret && this.peer != null)
596 this.peer.OnNotifyCaretChanged();
601 protected override void OnPointerPressed(PointerRoutedEventArgs e)
603 this.CapturePointer(e.Pointer);
604 this.gestureRecongnizer.ProcessDownEvent(e.GetCurrentPoint(this));
609 protected override void OnPointerMoved(PointerRoutedEventArgs e)
611 this.gestureRecongnizer.ProcessMoveEvents(e.GetIntermediatePoints(this));
614 if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
616 Point p = e.GetCurrentPoint(this).Position;
617 if (this.View.HitTextArea(p.X, p.Y))
619 TextPoint tp = this.View.GetTextPointFromPostion(p);
620 if (this._Controller.IsMarker(tp, HilightType.Url))
621 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Hand, 101);
623 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.IBeam, 101);
627 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 101);
633 protected override void OnPointerReleased(PointerRoutedEventArgs e)
635 this.gestureRecongnizer.ProcessUpEvent(e.GetCurrentPoint(this));
640 protected override void OnPointerCanceled(PointerRoutedEventArgs e)
642 this.gestureRecongnizer.CompleteGesture();
647 protected override void OnPointerWheelChanged(PointerRoutedEventArgs e)
649 bool shift = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Shift) ==
650 Windows.System.VirtualKeyModifiers.Shift;
651 bool ctrl = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Control) ==
652 Windows.System.VirtualKeyModifiers.Control;
653 this.gestureRecongnizer.ProcessMouseWheelEvent(e.GetCurrentPoint(this), shift, ctrl);
657 void CoreWindow_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)
659 if (this.FocusState == FocusState.Unfocused || !this.IsEnabled)
661 if (args.KeyCode >= 00 && args.KeyCode <= 0x1f)
663 this._Controller.DoInputString(Char.ConvertFromUtf32((int)args.KeyCode));
667 bool textStore_IsReadOnly()
672 bool textStore_IsLoading()
677 void textStore_CompositionEnded()
679 TextStoreHelper.EndCompostion(this.Document);
683 void textStore_CompositionUpdated(int start, int end)
685 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
688 bool textStore_CompositionStarted()
690 return TextStoreHelper.StartCompstion(this.Document);
693 string _textStore_GetString(int start, int length)
695 return this.Document.ToString(start, length);
698 void _textStore_GetStringExtent(
702 out POINT o_bottomRight
705 Point startPos, endPos;
706 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
709 this.Render.GetDpi(out dpi, out dpi);
710 double scale = dpi / 96.0;
712 var gt = this.TransformToVisual(Window.Current.Content);
713 var screenStartPos = gt.TransformPoint(startPos.Scale(scale));
714 var screenEndPos = gt.TransformPoint(endPos.Scale(scale));
715 Rect win_rect = Window.Current.CoreWindow.Bounds;
716 o_topLeft = new POINT((int)(screenStartPos.X + win_rect.X), (int)(screenStartPos.Y + win_rect.Y));
717 o_bottomRight = new POINT((int)(screenEndPos.X + win_rect.X), (int)(screenEndPos.Y + win_rect.Y));
720 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
722 var pointTopLeft = new Point(0, 0);
723 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
725 var gt = this.TransformToVisual(Window.Current.Content);
726 pointTopLeft = gt.TransformPoint(pointTopLeft);
727 pointBottomRight = gt.TransformPoint(pointBottomRight);
729 o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
730 o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
733 void _textStore_GetSelectionIndex(int start_index, int max_count, out DotNetTextStore.TextSelection[] sels)
735 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out sels);
738 void _textStore_SetSelectionIndex(DotNetTextStore.TextSelection[] sels)
740 TextStoreHelper.SetSelectionIndex(this._Controller, this.View, sels);
744 void _textStore_InsertAtSelection(string i_value,ref int o_stratIndex,ref int o_endIndex)
746 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
750 void Controller_SelectionChanged(object sender, EventArgs e)
753 this.nowCaretMove = true;
754 SetValue(SelectedTextProperty, this._Controller.SelectedText);
755 SetValue(CaretPostionPropertyKey, this.Document.CaretPostion);
756 this.nowCaretMove = false;
757 if (this.textStore.IsLocked() == false)
758 this.textStore.NotifySelectionChanged();
761 Gripper hittedGripper;
762 void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)
764 //Updateedの段階でヒットテストしてしまうとグリッパーを触ってもヒットしないことがある
765 this.hittedGripper = this.View.HitGripperFromPoint(e.Position);
768 private void GestureRecongnizer_ManipulationInertiaStarting(GestureRecognizer sender, ManipulationInertiaStartingEventArgs args)
770 //sender.InertiaTranslationDeceleration = 0.001f;
771 //sender.InertiaExpansionDeceleration = 100.0f * 96.0f / 1000.0f;
772 //sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
775 void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
777 if (this._Controller.MoveCaretAndGripper(e.Position, this.hittedGripper))
779 if (this.peer != null)
780 this.peer.OnNotifyCaretChanged();
785 if (e.Delta.Scale < 1)
787 double newSize = this.Render.FontSize - 1;
790 this.Render.FontSize = newSize;
792 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
796 if (e.Delta.Scale > 1)
798 double newSize = this.Render.FontSize + 1;
801 this.Render.FontSize = newSize;
803 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
807 Point translation = e.Delta.Translation;
809 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
810 if (Math.Abs(e.Cumulative.Translation.X) < Math.Abs(e.Cumulative.Translation.Y))
812 int deltay = (int)Math.Abs(Math.Ceiling(translation.Y));
813 if (translation.Y < 0)
814 this._Controller.ScrollByPixel(ScrollDirection.Down, deltay, false, false);
816 this._Controller.ScrollByPixel(ScrollDirection.Up, deltay, false, false);
821 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
824 if (translation.X < 0)
825 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
827 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
832 void gestureRecongnizer_ManipulationCompleted(GestureRecognizer sender, ManipulationCompletedEventArgs e)
836 async void gestureRecongnizer_RightTapped(GestureRecognizer sender, RightTappedEventArgs e)
838 ResourceMap map = ResourceManager.Current.MainResourceMap.GetSubtree("FooEditEngine.Metro/Resources");
839 ResourceContext context = ResourceContext.GetForCurrentView();
840 if (this.View.HitTextArea(e.Position.X, e.Position.Y))
842 FooContextMenuEventArgs args = new FooContextMenuEventArgs(e.Position);
843 if (this.ContextMenuOpening != null)
844 this.ContextMenuOpening(this, args);
847 PopupMenu ContextMenu = new PopupMenu();
848 ContextMenu.Commands.Add(new UICommand(map.GetValue("CopyMenuName", context).ValueAsString, (command) =>
852 ContextMenu.Commands.Add(new UICommand(map.GetValue("CutMenuName", context).ValueAsString, (command) =>
856 ContextMenu.Commands.Add(new UICommand(map.GetValue("PasteMenuName", context).ValueAsString, async (command) =>
858 await this.PasteCommand();
860 if (this._Controller.RectSelection)
862 ContextMenu.Commands.Add(new UICommand(map.GetValue("LineSelectMenuName", context).ValueAsString, (command) =>
864 this._Controller.RectSelection = false;
869 ContextMenu.Commands.Add(new UICommand(map.GetValue("RectSelectMenuName", context).ValueAsString, (command) =>
871 this._Controller.RectSelection = true;
874 await ContextMenu.ShowAsync(Util.GetScreentPoint(e.Position,this));
879 void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)
881 bool touched = e.PointerDeviceType == PointerDeviceType.Touch;
882 this.Document.SelectGrippers.BottomLeft.Enabled = false;
883 this.Document.SelectGrippers.BottomRight.Enabled = touched;
884 this.JumpCaret(e.Position);
885 System.Diagnostics.Debug.WriteLine(e.TapCount);
888 this.Document.SelectGrippers.BottomLeft.Enabled = touched;
889 //タッチスクリーンでダブルタップした場合、アンカーインデックスを単語の先頭にしないとバグる
890 this.Document.SelectWord(this.Controller.SelectionStart, touched);
895 void JumpCaret(Point p)
897 TextPoint tp = this.View.GetTextPointFromPostion(p);
898 if (tp == TextPoint.Null)
901 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
903 FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
904 if (foldingData != null)
906 if (foldingData.Expand)
907 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
909 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
910 this._Controller.JumpCaret(foldingData.Start, false);
914 this._Controller.JumpCaret(tp.row, tp.col, false);
916 if (this.peer != null)
917 this.peer.OnNotifyCaretChanged();
918 this.View.IsFocused = true;
919 this.Focus(FocusState.Programmatic);
923 void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)
925 Point p = e.Position;
926 TextPointSearchRange searchRange;
927 if (this.View.HitTextArea(p.X, p.Y))
928 searchRange = TextPointSearchRange.TextAreaOnly;
929 else if (this._Controller.SelectionLength > 0)
930 searchRange = TextPointSearchRange.Full;
933 TextPoint tp = this.View.GetTextPointFromPostion(p, searchRange);
934 this._Controller.MoveCaretAndSelect(tp);
935 if (this.peer != null)
936 this.peer.OnNotifyCaretChanged();
940 bool IsModiferKeyPressed(VirtualKey key)
942 CoreVirtualKeyStates state = Window.Current.CoreWindow.GetKeyState(key);
943 return (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
945 void Refresh(Rectangle updateRect)
947 if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0 || this.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
950 this.Render.DrawContent(this.View, this.IsEnabled, updateRect);
954 bool Resize(double width, double height)
956 if (width == 0 || height == 0)
957 throw new ArgumentOutOfRangeException();
958 if (this.Render.Resize(this.rectangle, width, height))
960 this.View.PageBound = new Rectangle(0, 0, width, height);
962 if (this.horizontalScrollBar != null)
964 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
965 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
967 if (this.verticalScrollBar != null)
969 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
970 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
977 void View_SrcChanged(object sender, EventArgs e)
979 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
981 EditView view = this.View;
982 if (view.Src.Row > this.verticalScrollBar.Maximum)
983 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
984 double absoulteX = Math.Abs(view.Src.X);
985 if (absoulteX > this.horizontalScrollBar.Maximum)
986 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
987 if (view.Src.Row != this.verticalScrollBar.Value)
988 this.verticalScrollBar.Value = view.Src.Row;
989 if (view.Src.X != this.horizontalScrollBar.Value)
990 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
993 void FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)
995 if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))
1002 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1004 if (this.horizontalScrollBar == null)
1007 if (this.FlowDirection == FlowDirection.LeftToRight)
1008 toX = this.horizontalScrollBar.Value;
1010 toX = -this.horizontalScrollBar.Value;
1011 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
1015 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1017 if (this.verticalScrollBar == null)
1019 int newRow = (int)this.verticalScrollBar.Value;
1020 if (newRow >= this.View.LayoutLines.Count)
1022 this._Controller.Scroll(this.View.Src.X, newRow, false, false);
1026 void Document_Update(object sender, DocumentUpdateEventArgs e)
1028 if (this.textStore.IsLocked())
1030 if (e.type == UpdateType.Replace)
1031 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
1032 if(this.peer != null)
1033 this.peer.OnNotifyTextChanged();
1036 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1038 this.Focus(FocusState.Programmatic);
1041 void timer_Tick(object sender, object e)
1043 if (this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding())
1044 this.Refresh(this.View.PageBound);
1048 public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
1050 FooTextBox source = (FooTextBox)sender;
1051 if(e.Property.Equals(SelectedTextProperty) && !source.nowCaretMove)
1052 source._Controller.SelectedText = source.SelectedText;
1053 if(e.Property.Equals(HilighterProperty))
1054 source.View.Hilighter = source.Hilighter;
1055 if (e.Property.Equals(TextAntialiasModeProperty))
1056 source.Render.TextAntialiasMode = source.TextAntialiasMode;
1057 if (e.Property.Equals(FoldingStrategyProperty))
1058 source.View.LayoutLines.FoldingStrategy = source.FoldingStrategy;
1059 if (e.Property.Equals(IndentModeProperty))
1060 source.Controller.IndentMode = source.IndentMode;
1061 if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)
1062 source.Document.Select(source.Selection.Index,source.Selection.Length);
1063 if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)
1064 source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col);
1065 if (e.Property.Equals(InsertModeProperty))
1066 source.View.InsertMode = source.InsertMode;
1067 if (e.Property.Equals(TabCharsProperty))
1068 source.Document.TabStops = source.TabChars;
1069 if (e.Property.Equals(RectSelectModeProperty))
1070 source._Controller.RectSelection = source.RectSelectMode;
1071 if (e.Property.Equals(DrawCaretProperty))
1072 source.View.HideCaret = !source.DrawCaret;
1073 if (e.Property.Equals(DrawCaretLineProperty))
1074 source.View.HideLineMarker = !source.DrawCaretLine;
1075 if (e.Property.Equals(DrawLineNumberProperty))
1076 source.Document.DrawLineNumber = source.DrawLineNumber;
1077 if(e.Property.Equals(MagnificationPowerPropertyKey))
1078 source.Render.FontSize = source.FontSize * source.MagnificationPower;
1079 if (e.Property.Equals(FontFamilyProperty))
1080 source.Render.FontFamily = source.FontFamily;
1081 if (e.Property.Equals(FontStyleProperty))
1082 source.Render.FontStyle = source.FontStyle;
1083 if (e.Property.Equals(FontWeightProperty))
1084 source.Render.FontWeigth = source.FontWeight;
1085 if (e.Property.Equals(FontSizeProperty))
1086 source.Render.FontSize = source.FontSize;
1087 if (e.Property.Equals(ForegroundProperty))
1088 source.Render.Foreground = D2DRenderBase.ToColor4(source.Foreground);
1089 if (e.Property.Equals(BackgroundProperty))
1090 source.Render.Background = D2DRenderBase.ToColor4(source.Background);
1091 if (e.Property.Equals(ControlCharProperty))
1092 source.Render.ControlChar = D2DRenderBase.ToColor4(source.ControlChar);
1093 if (e.Property.Equals(HilightProperty))
1094 source.Render.Hilight = D2DRenderBase.ToColor4(source.Hilight);
1095 if (e.Property.Equals(Keyword1Property))
1096 source.Render.Keyword1 = D2DRenderBase.ToColor4(source.Keyword1);
1097 if (e.Property.Equals(Keyword2Property))
1098 source.Render.Keyword2 = D2DRenderBase.ToColor4(source.Keyword2);
1099 if (e.Property.Equals(CommentProperty))
1100 source.Render.Comment = D2DRenderBase.ToColor4(source.Comment);
1101 if (e.Property.Equals(LiteralProperty))
1102 source.Render.Literal = D2DRenderBase.ToColor4(source.Literal);
1103 if (e.Property.Equals(URLProperty))
1104 source.Render.Url = D2DRenderBase.ToColor4(source.URL);
1105 if (e.Property.Equals(InsertCaretProperty))
1106 source.Render.InsertCaret = D2DRenderBase.ToColor4(source.InsertCaret);
1107 if (e.Property.Equals(OverwriteCaretProperty))
1108 source.Render.OverwriteCaret = D2DRenderBase.ToColor4(source.OverwriteCaret);
1109 if (e.Property.Equals(PaddingProperty))
1110 source.View.Padding = new Padding((int)source.Padding.Left, (int)source.Padding.Top, (int)source.Padding.Right, (int)source.Padding.Bottom);
1111 if (e.Property.Equals(LineMarkerProperty))
1112 source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);
1113 if (e.Property.Equals(MarkURLProperty))
1114 source.Document.UrlMark = source.MarkURL;
1115 if (e.Property.Equals(ShowFullSpaceProperty))
1116 source.Render.ShowFullSpace = source.ShowFullSpace;
1117 if (e.Property.Equals(ShowHalfSpaceProperty))
1118 source.Render.ShowHalfSpace = source.ShowHalfSpace;
1119 if (e.Property.Equals(ShowTabProperty))
1120 source.Render.ShowTab = source.ShowTab;
1121 if (e.Property.Equals(ShowLineBreakProperty))
1122 source.Render.ShowLineBreak = source.ShowLineBreak;
1123 if (e.Property.Equals(LineBreakProperty))
1124 source.Document.LineBreak = source.LineBreakMethod;
1125 if (e.Property.Equals(LineBreakCharCountProperty))
1126 source.Document.LineBreakCharCount = source.LineBreakCharCount;
1127 if (e.Property.Equals(UpdateAreaProperty))
1128 source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);
1129 if (e.Property.Equals(LineNumberProperty))
1130 source.Render.LineNumber = D2DRenderBase.ToColor4(source.LineNumber);
1131 if (e.Property.Equals(FlowDirectionProperty))
1133 source.Document.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;
1134 if(source.horizontalScrollBar != null)
1135 source.horizontalScrollBar.FlowDirection = source.FlowDirection;
1137 if (e.Property.Equals(DrawRulerProperty))
1139 source.Document.HideRuler = !source.DrawRuler;
1140 source._Controller.JumpCaret(source.Document.CaretPostion.row, source.Document.CaretPostion.col);
1148 /// コンテキストメニューが表示されるときに呼び出されます
1150 public event EventHandler<FooContextMenuEventArgs> ContextMenuOpening;
1156 internal Controller Controller
1160 return this._Controller;
1165 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1167 public TextAntialiasMode TextAntialiasMode
1169 get { return (TextAntialiasMode)GetValue(TextAntialiasModeProperty); }
1170 set { SetValue(TextAntialiasModeProperty, value); }
1174 /// TextAntialiasModeの依存プロパティを表す
1176 public static readonly DependencyProperty TextAntialiasModeProperty =
1177 DependencyProperty.Register("TextAntialiasMode", typeof(TextAntialiasMode), typeof(FooTextBox), new PropertyMetadata(TextAntialiasMode.Default, OnPropertyChanged));
1182 public IHilighter Hilighter
1184 get { return (IHilighter)GetValue(HilighterProperty); }
1185 set { SetValue(HilighterProperty, value); }
1189 /// Hilighterの依存プロパティを表す
1191 public static readonly DependencyProperty HilighterProperty =
1192 DependencyProperty.Register("Hilighter", typeof(IHilighter), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
1195 /// フォールティングを作成するインターフェイスを表す
1197 public IFoldingStrategy FoldingStrategy
1199 get { return (IFoldingStrategy)GetValue(FoldingStrategyProperty); }
1200 set { SetValue(FoldingStrategyProperty, value); }
1204 /// FoldingStrategyの依存プロパティ
1206 public static readonly DependencyProperty FoldingStrategyProperty =
1207 DependencyProperty.Register("FoldingStrategy", typeof(IFoldingStrategy), typeof(FooTextBox), new PropertyMetadata(null,OnPropertyChanged));
1212 public MarkerPatternSet MarkerPatternSet
1216 return this.Document.MarkerPatternSet;
1223 public Document Document
1227 return this._Document;
1231 Document old_doc = this._Document;
1233 if (this._Document != null)
1235 old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
1236 oldLength = old_doc.Length;
1239 this._Document = value;
1240 this._Document.LayoutLines.Render = this.Render;
1241 this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
1242 //初期化が終わっていればすべて存在する
1243 if (this.Controller != null && this.View != null && this.textStore != null)
1245 this.Controller.Document = value;
1246 this.View.Document = value;
1247 this.Controller.AdjustCaret();
1248 this.textStore.NotifyTextChanged(oldLength, value.Length);
1250 //依存プロパティとドキュメント内容が食い違っているので再設定する
1251 this.ShowFullSpace = value.ShowFullSpace;
1252 this.ShowHalfSpace = value.ShowHalfSpace;
1253 this.ShowLineBreak = value.ShowLineBreak;
1254 this.ShowTab = value.ShowTab;
1255 this.FlowDirection = value.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
1256 this.IndentMode = value.IndentMode;
1257 this.DrawCaretLine = !value.HideLineMarker;
1258 this.InsertMode = value.InsertMode;
1259 this.DrawRuler = !value.HideRuler;
1260 this.DrawLineNumber = value.DrawLineNumber;
1261 this.MarkURL = value.UrlMark;
1262 this.LineBreakMethod = value.LineBreak;
1263 this.LineBreakCharCount = value.LineBreakCharCount;
1264 this.TabChars = value.TabStops;
1274 public LineToIndexTable LayoutLineCollection
1276 get { return this.View.LayoutLines; }
1282 public string SelectedText
1284 get { return (string)GetValue(SelectedTextProperty); }
1285 set { SetValue(SelectedTextProperty, value); }
1289 /// SelectedTextの依存プロパティを表す
1291 public static readonly DependencyProperty SelectedTextProperty =
1292 DependencyProperty.Register("SelectedText", typeof(string), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
1297 public IndentMode IndentMode
1299 get { return (IndentMode)GetValue(IndentModeProperty); }
1300 set { SetValue(IndentModeProperty, value); }
1304 /// IndentModeの依存プロパティを表す
1306 public static readonly DependencyProperty IndentModeProperty =
1307 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab,OnPropertyChanged));
1313 /// Lengthが0の場合はキャレット位置を表します。
1314 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1316 public TextRange Selection
1318 get { return (TextRange)GetValue(SelectionProperty); }
1319 set { SetValue(SelectionProperty, value); }
1323 /// Selectionの依存プロパティを表す
1325 public static readonly DependencyProperty SelectionProperty =
1326 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null, OnPropertyChanged));
1331 public double MagnificationPower
1333 get { return (double)GetValue(MagnificationPowerPropertyKey); }
1334 set { SetValue(MagnificationPowerPropertyKey, value); }
1340 public static readonly DependencyProperty MagnificationPowerPropertyKey =
1341 DependencyProperty.Register("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0, OnPropertyChanged));
1346 public TextPoint CaretPostion
1348 get { return (TextPoint)GetValue(CaretPostionPropertyKey); }
1349 set { SetValue(CaretPostionPropertyKey, value); }
1352 static readonly DependencyProperty CaretPostionPropertyKey =
1353 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(new TextPoint(), OnPropertyChanged));
1358 public new FlowDirection FlowDirection
1360 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1361 set { SetValue(FlowDirectionProperty, value); }
1365 /// レタリング方向を表す。これは依存プロパティです
1367 public new static readonly DependencyProperty FlowDirectionProperty =
1368 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight,OnPropertyChanged));
1373 public new FontFamily FontFamily
1375 get { return (FontFamily)GetValue(FontFamilyProperty); }
1376 set { SetValue(FontFamilyProperty, value); }
1380 /// FontFamilyの依存プロパティを表す
1382 public new static readonly DependencyProperty FontFamilyProperty =
1383 DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(FooTextBox), new PropertyMetadata(new FontFamily("Cambria"), OnPropertyChanged));
1388 public new double FontSize
1390 get { return (double)GetValue(FontSizeProperty); }
1391 set { SetValue(FontSizeProperty, value); }
1395 /// FontSizeの依存プロパティを表す
1397 public new static readonly DependencyProperty FontSizeProperty =
1398 DependencyProperty.Register("FontSize", typeof(double), typeof(FooTextBox), new PropertyMetadata(12.0,OnPropertyChanged));
1403 public new FontStyle FontStyle
1405 get { return (FontStyle)GetValue(FontStyleProperty); }
1406 set { SetValue(FontStyleProperty, value); }
1410 /// FontStyleの依存プロパティを表す
1412 public new static readonly DependencyProperty FontStyleProperty =
1413 DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(FooTextBox), new PropertyMetadata(FontStyle.Normal,OnPropertyChanged));
1418 public new FontWeight FontWeight
1420 get { return (FontWeight)GetValue(FontWeightProperty); }
1421 set { SetValue(FontWeightProperty, value); }
1425 /// FontWeigthの依存プロパティを表す
1427 public new static readonly DependencyProperty FontWeightProperty =
1428 DependencyProperty.Register("FontWeigth", typeof(FontWeight), typeof(FooTextBox), new PropertyMetadata(FontWeights.Normal,OnPropertyChanged));
1431 /// デフォルトの文字色を表す。これは依存プロパティです
1433 public new Windows.UI.Color Foreground
1435 get { return (Windows.UI.Color)GetValue(ForegroundProperty); }
1436 set { SetValue(ForegroundProperty, value); }
1440 /// Foregroundの依存プロパティを表す
1442 public new static readonly DependencyProperty ForegroundProperty =
1443 DependencyProperty.Register("Foreground", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1446 /// 背景色を表す。これは依存プロパティです
1448 public new Windows.UI.Color Background
1450 get { return (Windows.UI.Color)GetValue(BackgroundProperty); }
1451 set { SetValue(BackgroundProperty, value); }
1455 /// Backgroundの依存プロパティを表す
1457 public new static readonly DependencyProperty BackgroundProperty =
1458 DependencyProperty.Register("Background", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));
1461 /// コントロールコードの文字色を表す。これは依存プロパティです
1463 public Windows.UI.Color ControlChar
1465 get { return (Windows.UI.Color)GetValue(ControlCharProperty); }
1466 set { SetValue(ControlCharProperty, value); }
1470 /// ControlCharの依存プロパティを表す
1472 public static readonly DependencyProperty ControlCharProperty =
1473 DependencyProperty.Register("ControlChar", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1476 /// 選択時の背景色を表す。これは依存プロパティです
1478 public Windows.UI.Color Hilight
1480 get { return (Windows.UI.Color)GetValue(HilightProperty); }
1481 set { SetValue(HilightProperty, value); }
1485 /// Hilightの依存プロパティを表す
1487 public static readonly DependencyProperty HilightProperty =
1488 DependencyProperty.Register("Hilight", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DeepSkyBlue, OnPropertyChanged));
1491 /// キーワード1の文字色を表す。これは依存プロパティです
1493 public Windows.UI.Color Keyword1
1495 get { return (Windows.UI.Color)GetValue(Keyword1Property); }
1496 set { SetValue(Keyword1Property, value); }
1500 /// Keyword1の依存プロパティを表す
1502 public static readonly DependencyProperty Keyword1Property =
1503 DependencyProperty.Register("Keyword1", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1506 /// キーワード2の文字色を表す。これは依存プロパティです
1508 public Windows.UI.Color Keyword2
1510 get { return (Windows.UI.Color)GetValue(Keyword2Property); }
1511 set { SetValue(Keyword2Property, value); }
1515 /// Keyword2の依存プロパティを表す
1517 public static readonly DependencyProperty Keyword2Property =
1518 DependencyProperty.Register("Keyword2", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DarkCyan, OnPropertyChanged));
1521 /// コメントの文字色を表す。これは依存プロパティです
1523 public Windows.UI.Color Comment
1525 get { return (Windows.UI.Color)GetValue(CommentProperty); }
1526 set { SetValue(CommentProperty, value); }
1530 /// Commentの依存プロパティを表す
1532 public static readonly DependencyProperty CommentProperty =
1533 DependencyProperty.Register("Comment", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Green, OnPropertyChanged));
1536 /// 文字リテラルの文字色を表す。これは依存プロパティです
1538 public Windows.UI.Color Literal
1540 get { return (Windows.UI.Color)GetValue(LiteralProperty); }
1541 set { SetValue(LiteralProperty, value); }
1545 /// Literalの依存プロパティを表す
1547 public static readonly DependencyProperty LiteralProperty =
1548 DependencyProperty.Register("Literal", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Brown, OnPropertyChanged));
1551 /// URLの文字色を表す。これは依存プロパティです
1553 public Windows.UI.Color URL
1555 get { return (Windows.UI.Color)GetValue(URLProperty); }
1556 set { SetValue(URLProperty, value); }
1562 public static readonly DependencyProperty URLProperty =
1563 DependencyProperty.Register("URL", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1568 public Windows.UI.Color UpdateArea
1570 get { return (Windows.UI.Color)GetValue(UpdateAreaProperty); }
1571 set { SetValue(UpdateAreaProperty, value); }
1575 /// UpdateAreaの依存プロパティを表す
1577 public static readonly DependencyProperty UpdateAreaProperty =
1578 DependencyProperty.Register("UpdateArea", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen, OnPropertyChanged));
1583 public Windows.UI.Color LineMarker
1585 get { return (Windows.UI.Color)GetValue(LineMarkerProperty); }
1586 set { SetValue(LineMarkerProperty, value); }
1590 /// LineMarkerの依存プロパティを表す
1592 public static readonly DependencyProperty LineMarkerProperty =
1593 DependencyProperty.Register("LineMarker", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1596 /// 挿入モード時のキャレットの色を表す
1598 public Windows.UI.Color InsertCaret
1600 get { return (Windows.UI.Color)GetValue(InsertCaretProperty); }
1601 set { SetValue(InsertCaretProperty, value); }
1605 /// InsertCaretの依存プロパティを表す
1607 public static readonly DependencyProperty InsertCaretProperty =
1608 DependencyProperty.Register("InsertCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1611 /// 上書きモード時のキャレット職を表す
1613 public Windows.UI.Color OverwriteCaret
1615 get { return (Windows.UI.Color)GetValue(OverwriteCaretProperty); }
1616 set { SetValue(OverwriteCaretProperty, value); }
1620 /// OverwriteCaretの依存プロパティを表す
1622 public static readonly DependencyProperty OverwriteCaretProperty =
1623 DependencyProperty.Register("OverwriteCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1628 public Windows.UI.Color LineNumber
1630 get { return (Windows.UI.Color)GetValue(LineNumberProperty); }
1631 set { SetValue(LineNumberProperty, value); }
1635 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1637 public static readonly DependencyProperty LineNumberProperty =
1638 DependencyProperty.Register("LineNumber", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray,OnPropertyChanged));
1643 public new Thickness Padding
1645 get { return (Thickness)GetValue(PaddingProperty); }
1646 set { SetValue(PaddingProperty, value); }
1650 /// Paddingの依存プロパティを表す
1652 public new static readonly DependencyProperty PaddingProperty =
1653 DependencyProperty.Register("Padding", typeof(Thickness), typeof(FooTextBox), new PropertyMetadata(new Thickness(),OnPropertyChanged));
1656 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1658 public bool InsertMode
1660 get { return (bool)GetValue(InsertModeProperty); }
1661 set { SetValue(InsertModeProperty, value); }
1665 /// InsertModeの依存プロパティを表す
1667 public static readonly DependencyProperty InsertModeProperty =
1668 DependencyProperty.Register("InsertMode",
1671 new PropertyMetadata(true, OnPropertyChanged));
1674 /// タブの文字数を表す。これは依存プロパティです
1678 get { return (int)GetValue(TabCharsProperty); }
1679 set { SetValue(TabCharsProperty, value); }
1683 /// TabCharsの依存プロパティを表す
1685 public static readonly DependencyProperty TabCharsProperty =
1686 DependencyProperty.Register("TabChars",
1689 new PropertyMetadata(4, OnPropertyChanged));
1692 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1694 public bool RectSelectMode
1696 get { return (bool)GetValue(RectSelectModeProperty); }
1697 set { SetValue(RectSelectModeProperty, value); }
1701 /// RectSelectModeの依存プロパティを表す
1703 public static readonly DependencyProperty RectSelectModeProperty =
1704 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1710 /// 変更した場合、レイアウトの再構築を行う必要があります
1712 public LineBreakMethod LineBreakMethod
1714 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1715 set { SetValue(LineBreakProperty, value); }
1719 /// LineBreakMethodの依存プロパティを表す
1721 public static readonly DependencyProperty LineBreakProperty =
1722 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None, OnPropertyChanged));
1726 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1729 /// 変更した場合、レイアウトの再構築を行う必要があります
1731 public int LineBreakCharCount
1733 get { return (int)GetValue(LineBreakCharCountProperty); }
1734 set { SetValue(LineBreakCharCountProperty, value); }
1738 /// LineBreakCharCountの依存プロパティを表す
1740 public static readonly DependencyProperty LineBreakCharCountProperty =
1741 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80, OnPropertyChanged));
1744 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1746 public bool DrawCaret
1748 get { return (bool)GetValue(DrawCaretProperty); }
1749 set { SetValue(DrawCaretProperty, value); }
1753 /// DrawCaretの依存プロパティを表す
1755 public static readonly DependencyProperty DrawCaretProperty =
1756 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new PropertyMetadata(true, OnPropertyChanged));
1760 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1762 public bool DrawCaretLine
1764 get { return (bool)GetValue(DrawCaretLineProperty); }
1765 set { SetValue(DrawCaretLineProperty, value); }
1769 /// DrawCaretLineの依存プロパティを表す
1771 public static readonly DependencyProperty DrawCaretLineProperty =
1772 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1775 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
1777 public bool DrawLineNumber
1779 get { return (bool)GetValue(DrawLineNumberProperty); }
1780 set { SetValue(DrawLineNumberProperty, value); }
1784 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
1786 public bool DrawRuler
1788 get { return (bool)GetValue(DrawRulerProperty); }
1789 set { SetValue(DrawRulerProperty, value); }
1793 /// DrawRulerの依存プロパティを表す
1795 public static readonly DependencyProperty DrawRulerProperty =
1796 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1800 /// DrawLineNumberの依存プロパティを表す
1802 public static readonly DependencyProperty DrawLineNumberProperty =
1803 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1806 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
1810 get { return (bool)GetValue(MarkURLProperty); }
1811 set { SetValue(MarkURLProperty, value); }
1815 /// MarkURLの依存プロパティを表す
1817 public static readonly DependencyProperty MarkURLProperty =
1818 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1821 /// 全角スペースを表示するなら真。そうでないなら偽
1823 public bool ShowFullSpace
1825 get { return (bool)GetValue(ShowFullSpaceProperty); }
1826 set { SetValue(ShowFullSpaceProperty, value); }
1830 /// ShowFullSpaceの依存プロパティを表す
1832 public static readonly DependencyProperty ShowFullSpaceProperty =
1833 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1836 /// 半角スペースを表示するなら真。そうでないなら偽
1838 public bool ShowHalfSpace
1840 get { return (bool)GetValue(ShowHalfSpaceProperty); }
1841 set { SetValue(ShowHalfSpaceProperty, value); }
1845 /// ShowHalfSpaceの依存プロパティを表す
1847 public static readonly DependencyProperty ShowHalfSpaceProperty =
1848 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1851 /// タブを表示するなら真。そうでないなら偽
1855 get { return (bool)GetValue(ShowTabProperty); }
1856 set { SetValue(ShowTabProperty, value); }
1860 /// ShowTabの依存プロパティを表す
1862 public static readonly DependencyProperty ShowTabProperty =
1863 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1866 /// 改行マークを表示するなら真。そうでないなら偽
1868 public bool ShowLineBreak
1870 get { return (bool)GetValue(ShowLineBreakProperty); }
1871 set { SetValue(ShowLineBreakProperty, value); }
1875 /// ShowLineBreakの依存プロパティを表す
1877 public static readonly DependencyProperty ShowLineBreakProperty =
1878 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false,OnPropertyChanged));
1885 /// コンテキストメニューのイベントデーターを表す
1887 public class FooContextMenuEventArgs
1890 /// 処理済みなら真。そうでないなら偽
1892 public bool Handled = false;
1894 /// コンテキストメニューを表示すべき座標を表す
1896 public Windows.Foundation.Point Postion;
1900 /// <param name="pos"></param>
1901 public FooContextMenuEventArgs(Windows.Foundation.Point pos)