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;
52 DispatcherTimer timer;
59 this.DefaultStyleKey = typeof(FooTextBox);
61 this.textStore = new TextStore2();
62 this.textStore.IsLoading += textStore_IsLoading;
63 this.textStore.IsReadOnly += textStore_IsReadOnly;
64 this.textStore.GetStringLength += () => this.Document.Length;
65 this.textStore.GetString += _textStore_GetString;
66 this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;
67 this.textStore.SetSelectionIndex += _textStore_SetSelectionIndex;
68 this.textStore.InsertAtSelection += _textStore_InsertAtSelection;
69 this.textStore.GetScreenExtent += _textStore_GetScreenExtent;
70 this.textStore.GetStringExtent += _textStore_GetStringExtent;
71 this.textStore.CompositionStarted += textStore_CompositionStarted;
72 this.textStore.CompositionUpdated += textStore_CompositionUpdated;
73 this.textStore.CompositionEnded += textStore_CompositionEnded;
75 this.rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
76 this.rectangle.Margin = this.Padding;
77 this.Render = new D2DRender(this,this.rectangle,this.textStore);
79 this.Document = new Document();
80 this.Document.LayoutLines.Render = this.Render;
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.View.DrawLineNumber = this.DrawLineNumber;
86 this.View.HideCaret = !this.DrawCaret;
87 this.View.HideLineMarker = !this.DrawCaretLine;
88 this.View.HideRuler = !this.DrawRuler;
89 this.View.UrlMark = this.MarkURL;
90 this.View.TabStops = this.TabChars;
92 this._Controller = new Controller(this.Document, this.View);
93 this._Controller.SelectionChanged += Controller_SelectionChanged;
95 this.FirstGripper = new Gripper(this._Controller, this.View, this.Render, GripperPostion.BottomLeft);
96 this.SecondGripper = new Gripper(this._Controller, this.View, this.Render, GripperPostion.BottomRight);
98 this.gestureRecongnizer.GestureSettings = GestureSettings.Drag |
99 GestureSettings.RightTap |
100 GestureSettings.Tap |
101 GestureSettings.DoubleTap |
102 GestureSettings.ManipulationTranslateX |
103 GestureSettings.ManipulationTranslateY |
104 GestureSettings.ManipulationScale |
105 GestureSettings.ManipulationTranslateInertia |
106 GestureSettings.ManipulationScaleInertia;
107 this.gestureRecongnizer.RightTapped += gestureRecongnizer_RightTapped;
108 this.gestureRecongnizer.Tapped += gestureRecongnizer_Tapped;
109 this.gestureRecongnizer.Dragging += gestureRecongnizer_Dragging;
110 this.gestureRecongnizer.ManipulationInertiaStarting += gestureRecongnizer_ManipulationInertiaStarting;
111 this.gestureRecongnizer.ManipulationStarted += gestureRecongnizer_ManipulationStarted;
112 this.gestureRecongnizer.ManipulationUpdated += gestureRecongnizer_ManipulationUpdated;
113 this.gestureRecongnizer.ManipulationCompleted += gestureRecongnizer_ManipulationCompleted;
115 this.timer = new DispatcherTimer();
116 this.timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
117 this.timer.Tick += new EventHandler<object>(this.timer_Tick);
120 //Viewの初期化が終わった直後に置かないと例外が発生する
121 this.Document.Update += Document_Update;
123 Window.Current.CoreWindow.CharacterReceived += CoreWindow_CharacterReceived;
125 this.SizeChanged += FooTextBox_SizeChanged;
127 this.Loaded += FooTextBox_Loaded;
141 public void Dispose()
144 GC.SuppressFinalize(this);
147 bool Disposed = false;
148 private void Dispose(bool disposing)
154 this.textStore.Dispose();
156 this.Render.Dispose();
163 /// <param name="start">開始インデックス</param>
164 /// <param name="length">長さ</param>
165 public void Select(int start, int length)
167 this._Controller.Select(start, length);
171 /// キャレットを指定した行に移動させます
173 /// <param name="index">インデックス</param>
174 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
175 public void JumpCaret(int index)
177 this._Controller.JumpCaret(index);
180 /// キャレットを指定した行と桁に移動させます
182 /// <param name="row">行番号</param>
183 /// <param name="col">桁</param>
184 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
185 public void JumpCaret(int row, int col)
187 this._Controller.JumpCaret(row, col);
191 /// 選択中のテキストをクリップボードにコピーします
195 string text = this._Controller.SelectedText;
196 if (text != null && text != string.Empty)
198 DataPackage dataPackage = new DataPackage();
199 dataPackage.RequestedOperation = DataPackageOperation.Copy;
200 dataPackage.SetText(text);
202 Clipboard.SetContent(dataPackage);
207 /// 選択中のテキストをクリップボードに切り取ります
211 string text = this._Controller.SelectedText;
212 if (text != null && text != string.Empty)
214 DataPackage dataPackage = new DataPackage();
215 dataPackage.RequestedOperation = DataPackageOperation.Copy;
216 dataPackage.SetText(text);
218 Clipboard.SetContent(dataPackage);
220 this._Controller.SelectedText = "";
227 public async Task PasteAsync()
229 var dataPackageView = Clipboard.GetContent();
230 if (dataPackageView.Contains(StandardDataFormats.Text))
232 this._Controller.SelectedText = await dataPackageView.GetTextAsync();
239 public void SelectAll()
241 this._Controller.Select(0, this.Document.Length);
247 public void DeSelectAll()
249 this._Controller.DeSelectAll();
255 /// <param name="tp">テキストポイント</param>
256 /// <returns>座標</returns>
257 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
258 public Windows.Foundation.Point GetPostionFromTextPoint(TextPoint tp)
260 if (this.Document.FireUpdateEvent == false)
261 throw new InvalidOperationException("");
262 return this.View.GetPostionFromTextPoint(tp);
266 /// 対応するテキストポイントを返します
268 /// <param name="p">クライアント領域の原点を左上とする座標</param>
269 /// <returns>テキストポイント</returns>
270 public TextPoint GetTextPointFromPostion(Windows.Foundation.Point p)
272 if (this.Document.FireUpdateEvent == false)
273 throw new InvalidOperationException("");
274 return this.View.GetTextPointFromPostion(p);
280 /// <param name="row">レイアウト行</param>
281 /// <returns>行の高さ</returns>
282 public double GetLineHeight(int row)
284 if (this.Document.FireUpdateEvent == false)
285 throw new InvalidOperationException("");
286 return this.View.LayoutLines.GetLayout(row).Height; ;
290 /// インデックスに対応する座標を得ます
292 /// <param name="index">インデックス</param>
293 /// <returns>座標を返す</returns>
294 public Windows.Foundation.Point GetPostionFromIndex(int index)
296 if (this.Document.FireUpdateEvent == false)
297 throw new InvalidOperationException("");
298 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
299 return this.View.GetPostionFromTextPoint(tp);
305 /// <param name="p">座標</param>
306 /// <returns>インデックスを返す</returns>
307 public int GetIndexFromPostion(Windows.Foundation.Point p)
309 if (this.Document.FireUpdateEvent == false)
310 throw new InvalidOperationException("");
311 TextPoint tp = this.View.GetTextPointFromPostion(p);
312 return this.View.GetIndexFromLayoutLine(tp);
318 public void Refresh()
320 this.Refresh(this.View.PageBound);
324 /// レイアウト行をすべて破棄し、再度レイアウトを行う
326 public void PerfomLayouts()
328 this.View.PerfomLayouts();
334 /// <param name="row">行</param>
335 /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
336 public void ScrollIntoView(int row, bool alignTop)
338 this.View.ScrollIntoView(row, alignTop);
342 /// ファイルからドキュメントを構築する
344 /// <param name="sr">StremReader</param>
345 /// <returns>Taskオブジェクト</returns>
346 public async Task LoadFileAsync(System.IO.StreamReader sr, System.Threading.CancellationTokenSource token)
348 this.IsEnabled = false;
349 this.View.LayoutLines.IsFrozneDirtyFlag = true;
350 WinFileReader fs = new WinFileReader(sr);
351 await this.Document.LoadAsync(fs, token);
352 this.View.LayoutLines.IsFrozneDirtyFlag = false;
353 TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
354 if (this.verticalScrollBar != null)
355 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
356 this.View.CalculateLineCountOnScreen();
357 this.IsEnabled = true;
361 /// ドキュメントの内容をファイルに保存する
363 /// <param name="sw">StreamWriter</param>
364 /// <param name="enc">エンコード</param>
365 /// <returns>Taskオブジェクト</returns>
366 public async Task SaveFile(System.IO.StreamWriter sw, System.Threading.CancellationTokenSource token)
368 WinFileWriter fs = new WinFileWriter(sw);
369 await this.Document.SaveAsync(fs, token);
384 async Task PasteCommand()
386 await this.PasteAsync();
394 protected override Windows.UI.Xaml.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
396 this.peer = new FooTextBoxAutomationPeer(this);
401 protected override void OnApplyTemplate()
403 base.OnApplyTemplate();
405 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
408 Grid.SetRow(this.rectangle, 0);
409 Grid.SetColumn(this.rectangle, 0);
410 grid.Children.Add(this.rectangle);
413 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
414 if (this.horizontalScrollBar != null)
416 this.horizontalScrollBar.SmallChange = 10;
417 this.horizontalScrollBar.LargeChange = 100;
418 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
419 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
421 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
422 if (this.verticalScrollBar != null)
424 this.verticalScrollBar.SmallChange = 1;
425 this.verticalScrollBar.LargeChange = 10;
426 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
427 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
432 protected override void OnGotFocus(RoutedEventArgs e)
435 this.textStore.SetFocus();
436 this.View.IsFocused = true;
441 protected override void OnLostFocus(RoutedEventArgs e)
444 this.View.IsFocused = false;
449 protected override async void OnKeyDown(KeyRoutedEventArgs e)
451 bool isControlPressed = this.IsModiferKeyPressed(VirtualKey.Control);
452 bool isShiftPressed = this.IsModiferKeyPressed(VirtualKey.Shift);
453 bool isMovedCaret = false;
457 this._Controller.MoveCaretVertical(-1, isShiftPressed);
462 case VirtualKey.Down:
463 this._Controller.MoveCaretVertical(+1, isShiftPressed);
468 case VirtualKey.Left:
469 this._Controller.MoveCaretHorizontical(-1, isShiftPressed, isControlPressed);
474 case VirtualKey.Right:
475 this._Controller.MoveCaretHorizontical(1, isShiftPressed, isControlPressed);
480 case VirtualKey.PageUp:
481 this._Controller.Scroll(ScrollDirection.Up, this.View.LineCountOnScreen, isShiftPressed, true);
485 case VirtualKey.PageDown:
486 this._Controller.Scroll(ScrollDirection.Down, this.View.LineCountOnScreen, isShiftPressed, true);
490 case VirtualKey.Home:
491 if (isControlPressed)
492 this._Controller.JumpToHead(isShiftPressed);
494 this.Controller.JumpToLineHead(this.View.CaretPostion.row,isShiftPressed);
499 if (isControlPressed)
500 this._Controller.JumpToEnd(isShiftPressed);
502 this.Controller.JumpToLineEnd(this.View.CaretPostion.row,isShiftPressed);
507 if (!isControlPressed)
509 if (this._Controller.SelectionLength == 0)
510 this._Controller.DoInputChar('\t');
511 else if (isShiftPressed)
512 this._Controller.DownIndent();
514 this._Controller.UpIndent();
519 case VirtualKey.Enter:
520 this._Controller.DoEnterAction();
524 case VirtualKey.Insert:
525 if(this.View.InsertMode)
526 this.View.InsertMode = false;
528 this.View.InsertMode = true;
533 if (isControlPressed)
541 if (isControlPressed)
543 if (this._Controller.RectSelection)
544 this._Controller.RectSelection = false;
546 this._Controller.RectSelection = true;
552 if (isControlPressed)
559 if (isControlPressed)
566 if (isControlPressed)
568 await this.PasteCommand();
573 if (isControlPressed)
575 this.Document.UndoManager.redo();
581 if (isControlPressed)
583 this.Document.UndoManager.undo();
588 case VirtualKey.Back:
589 this._Controller.DoBackSpaceAction();
593 case VirtualKey.Delete:
594 this._Controller.DoDeleteAction();
599 if (isMovedCaret && this.peer != null)
600 this.peer.OnNotifyCaretChanged();
605 protected override void OnPointerPressed(PointerRoutedEventArgs e)
607 this.CapturePointer(e.Pointer);
608 this.gestureRecongnizer.ProcessDownEvent(e.GetCurrentPoint(this));
613 protected override void OnPointerMoved(PointerRoutedEventArgs e)
615 this.gestureRecongnizer.ProcessMoveEvents(e.GetIntermediatePoints(this));
618 if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
620 Point p = e.GetCurrentPoint(this).Position;
621 if (this.View.HitTextArea(p.X, p.Y))
623 TextPoint tp = this.View.GetTextPointFromPostion(p);
624 if (this._Controller.IsMarker(tp, HilightType.Url))
625 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Hand, 101);
627 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.IBeam, 101);
631 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 101);
637 protected override void OnPointerReleased(PointerRoutedEventArgs e)
639 this.gestureRecongnizer.ProcessUpEvent(e.GetCurrentPoint(this));
640 this.ReleasePointerCapture(e.Pointer);
645 protected override void OnPointerCanceled(PointerRoutedEventArgs e)
647 this.gestureRecongnizer.CompleteGesture();
648 this.ReleasePointerCapture(e.Pointer);
653 protected override void OnPointerCaptureLost(PointerRoutedEventArgs e)
655 this.gestureRecongnizer.CompleteGesture();
656 this.ReleasePointerCapture(e.Pointer);
661 protected override void OnPointerWheelChanged(PointerRoutedEventArgs e)
663 bool shift = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Shift) ==
664 Windows.System.VirtualKeyModifiers.Shift;
665 bool ctrl = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Control) ==
666 Windows.System.VirtualKeyModifiers.Control;
667 this.gestureRecongnizer.ProcessMouseWheelEvent(e.GetCurrentPoint(this), shift, ctrl);
671 void CoreWindow_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)
673 if (this.FocusState == FocusState.Unfocused || !this.IsEnabled)
675 if (args.KeyCode >= 00 && args.KeyCode <= 0x1f)
677 this._Controller.DoInputString(Char.ConvertFromUtf32((int)args.KeyCode));
681 bool textStore_IsReadOnly()
686 bool textStore_IsLoading()
691 void textStore_CompositionEnded()
693 TextStoreHelper.EndCompostion(this.Document);
697 void textStore_CompositionUpdated(int start, int end)
699 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
702 bool textStore_CompositionStarted()
704 return TextStoreHelper.StartCompstion(this.Document);
707 string _textStore_GetString(int start, int length)
709 return this.Document.ToString(start, length);
712 void _textStore_GetStringExtent(
716 out POINT o_bottomRight
719 Point startPos, endPos;
720 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
723 this.Render.GetDpi(out dpi, out dpi);
724 double scale = dpi / 96.0;
726 var gt = this.TransformToVisual(Window.Current.Content);
727 startPos = gt.TransformPoint(startPos.Scale(scale));
728 endPos = gt.TransformPoint(endPos.Scale(scale));
730 o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);
731 o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);
734 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
736 var pointTopLeft = new Point(0, 0);
737 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
739 var gt = this.TransformToVisual(Window.Current.Content);
740 pointTopLeft = gt.TransformPoint(pointTopLeft);
741 pointBottomRight = gt.TransformPoint(pointBottomRight);
743 o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
744 o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
747 void _textStore_GetSelectionIndex(out int o_startIndex, out int o_endIndex)
749 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out o_startIndex, out o_endIndex);
752 void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)
754 TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);
758 void _textStore_InsertAtSelection(string i_value,ref int o_stratIndex,ref int o_endIndex)
760 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
764 void Controller_SelectionChanged(object sender, EventArgs e)
767 this.nowCaretMove = true;
768 SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
769 SetValue(CaretPostionPropertyKey, this.View.CaretPostion);
770 this.nowCaretMove = false;
771 if (this.textStore.IsLocked() == false)
772 this.textStore.NotifySelectionChanged();
775 Gripper FirstGripper, SecondGripper;
777 Gripper hittedGripper;
778 private void gestureRecongnizer_ManipulationInertiaStarting(GestureRecognizer sender, ManipulationInertiaStartingEventArgs e)
780 //sender.InertiaTranslationDeceleration = 0.001f;
781 //sender.InertiaExpansionDeceleration = 100.0f * 96.0f / 1000.0f;
782 //sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
785 void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)
787 this.HittedCaret = false;
788 this.hittedGripper = null;
790 Point p = e.Position;
791 TextPoint tp = this.View.GetTextPointFromPostion(p);
792 if (tp == this.View.CaretPostion)
797 if (this.FirstGripper.IsHit(p))
799 hittedGripper = this.FirstGripper;
801 System.Diagnostics.Debug.WriteLine("first gripper hitted");
804 else if (this.SecondGripper.IsHit(p))
806 hittedGripper = this.SecondGripper;
808 System.Diagnostics.Debug.WriteLine("second gripper hitted");
812 void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
817 if (this.hittedGripper == null)
820 p = this.hittedGripper.AdjustPoint(e.Position);
822 if (hittedGripper != null)
824 TextPoint tp = this.View.GetTextPointFromPostion(p);
825 if (this._Controller.IsReverseSelect())
827 if (Object.ReferenceEquals(hittedGripper,this.SecondGripper))
828 this._Controller.MoveSelectBefore(tp);
830 this._Controller.MoveCaretAndSelect(tp);
834 if (Object.ReferenceEquals(hittedGripper,this.FirstGripper))
835 this._Controller.MoveSelectBefore(tp);
837 this._Controller.MoveCaretAndSelect(tp);
842 TextPoint tp = this.View.GetTextPointFromPostion(p);
843 this._Controller.MoveCaretAndSelect(tp);
845 if (this.peer != null)
846 this.peer.OnNotifyCaretChanged();
847 if (this._Controller.SelectionLength != 0)
848 this.FirstGripper.Enabled = true;
850 this.FirstGripper.Enabled = false;
857 if (e.Delta.Scale < 1)
859 double newSize = this.Render.FontSize - 1;
862 this.Render.FontSize = newSize;
864 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
868 if (e.Delta.Scale > 1)
870 double newSize = this.Render.FontSize + 1;
873 this.Render.FontSize = newSize;
875 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
879 Point translation = e.Delta.Translation;
881 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
882 if (Math.Abs(e.Cumulative.Translation.X) < Math.Abs(e.Cumulative.Translation.Y))
885 if (e.PointerDeviceType == PointerDeviceType.Mouse) //ホイールを使っているので、スクロール行数を計算する
886 scrollCount = (int)Math.Abs(translation.Y / sender.MouseWheelParameters.CharTranslation.Y);
888 scrollCount = (int)Math.Abs(Math.Ceiling(translation.Y));
890 if (translation.Y > 0)
891 this._Controller.Scroll(ScrollDirection.Up, scrollCount, false, false);
893 this._Controller.Scroll(ScrollDirection.Down, scrollCount, false, false);
894 this.FirstGripper.Enabled = false;
895 this.SecondGripper.Enabled = false;
900 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
903 if (translation.X < 0)
904 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
906 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
907 this.FirstGripper.Enabled = false;
908 this.SecondGripper.Enabled = false;
913 void gestureRecongnizer_ManipulationCompleted(GestureRecognizer sender, ManipulationCompletedEventArgs e)
917 async void gestureRecongnizer_RightTapped(GestureRecognizer sender, RightTappedEventArgs e)
919 ResourceMap map = ResourceManager.Current.MainResourceMap.GetSubtree("FooEditEngine.Metro/Resources");
920 ResourceContext context = ResourceContext.GetForCurrentView();
921 if (this.View.HitTextArea(e.Position.X, e.Position.Y))
923 FooContextMenuEventArgs args = new FooContextMenuEventArgs(e.Position);
924 if (this.ContextMenuOpening != null)
925 this.ContextMenuOpening(this, args);
928 PopupMenu ContextMenu = new PopupMenu();
929 ContextMenu.Commands.Add(new UICommand(map.GetValue("CopyMenuName", context).ValueAsString, (command) =>
933 ContextMenu.Commands.Add(new UICommand(map.GetValue("CutMenuName", context).ValueAsString, (command) =>
937 ContextMenu.Commands.Add(new UICommand(map.GetValue("PasteMenuName", context).ValueAsString, async (command) =>
939 await this.PasteCommand();
941 if (this._Controller.RectSelection)
943 ContextMenu.Commands.Add(new UICommand(map.GetValue("LineSelectMenuName", context).ValueAsString, (command) =>
945 this._Controller.RectSelection = false;
950 ContextMenu.Commands.Add(new UICommand(map.GetValue("RectSelectMenuName", context).ValueAsString, (command) =>
952 this._Controller.RectSelection = true;
955 await ContextMenu.ShowAsync(Util.GetScreentPoint(e.Position,this));
960 void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)
962 bool touched = e.PointerDeviceType == PointerDeviceType.Touch;
963 this.FirstGripper.Enabled = false;
964 this.SecondGripper.Enabled = touched;
965 this.JumpCaret(e.Position);
966 System.Diagnostics.Debug.WriteLine(e.TapCount);
969 this.FirstGripper.Enabled = touched;
970 //タッチスクリーンでダブルタップした場合、アンカーインデックスを単語の先頭にしないとバグる
971 this.Controller.SelectWord(this.Controller.SelectionStart, touched);
975 void JumpCaret(Point p)
977 TextPoint tp = this.View.GetTextPointFromPostion(p);
978 if (tp == TextPoint.Null)
981 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
983 FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
984 if (foldingData != null)
986 if (foldingData.Expand)
987 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
989 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
990 this._Controller.JumpCaret(foldingData.Start, false);
994 this._Controller.JumpCaret(tp.row, tp.col, false);
996 if (this.peer != null)
997 this.peer.OnNotifyCaretChanged();
998 this.View.IsFocused = true;
999 this.Focus(FocusState.Programmatic);
1003 void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)
1005 Point p = e.Position;
1006 if (this.View.HitTextArea(p.X, p.Y))
1008 TextPoint tp = this.View.GetTextPointFromPostion(p);
1009 this._Controller.MoveCaretAndSelect(tp);
1010 if (this.peer != null)
1011 this.peer.OnNotifyCaretChanged();
1016 bool IsModiferKeyPressed(VirtualKey key)
1018 CoreVirtualKeyStates state = Window.Current.CoreWindow.GetKeyState(key);
1019 return (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
1021 void Refresh(Rectangle updateRect)
1023 if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0 || this.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
1026 this.Render.BegineDraw();
1028 this.View.Draw(updateRect);
1030 this.Render.FillBackground(updateRect);
1031 this.FirstGripper.Draw();
1032 this.SecondGripper.Draw();
1033 this.Render.EndDraw();
1037 bool Resize(double width, double height)
1039 if (width == 0 || height == 0)
1040 throw new ArgumentOutOfRangeException();
1041 if (this.Render.Resize(this.rectangle, width, height))
1043 this.View.PageBound = new Rectangle(0, 0, width, height);
1045 if (this.horizontalScrollBar != null)
1047 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
1048 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1050 if (this.verticalScrollBar != null)
1052 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
1053 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1060 void View_SrcChanged(object sender, EventArgs e)
1062 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1064 EditView view = this.View;
1065 if (view.Src.Row > this.verticalScrollBar.Maximum)
1066 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
1067 double absoulteX = Math.Abs(view.Src.X);
1068 if (absoulteX > this.horizontalScrollBar.Maximum)
1069 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1070 if (view.Src.Row != this.verticalScrollBar.Value)
1071 this.verticalScrollBar.Value = view.Src.Row;
1072 if (view.Src.X != this.horizontalScrollBar.Value)
1073 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1076 void FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)
1078 if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))
1085 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1087 if (this.horizontalScrollBar == null)
1090 if (this.FlowDirection == FlowDirection.LeftToRight)
1091 toX = this.horizontalScrollBar.Value;
1093 toX = -this.horizontalScrollBar.Value;
1094 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
1095 this.FirstGripper.Enabled = false;
1096 this.SecondGripper.Enabled = false;
1100 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1102 if (this.verticalScrollBar == null)
1104 int newRow = (int)this.verticalScrollBar.Value;
1105 if (newRow >= this.View.LayoutLines.Count)
1107 this._Controller.Scroll(this.View.Src.X, newRow, false, false);
1108 this.FirstGripper.Enabled = false;
1109 this.SecondGripper.Enabled = false;
1113 void Document_Update(object sender, DocumentUpdateEventArgs e)
1115 if (this.textStore.IsLocked())
1117 if (e.type == UpdateType.Replace)
1118 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
1121 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1123 this.Focus(FocusState.Programmatic);
1126 void timer_Tick(object sender, object e)
1128 bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding();
1134 public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
1136 FooTextBox source = (FooTextBox)sender;
1137 if (e.Property.Equals(IndentModeProperty))
1138 source.Controller.IndentMode = source.IndentMode;
1139 if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)
1140 source._Controller.Select(source.Selection.Index,source.Selection.Length);
1141 if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)
1142 source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col);
1143 if (e.Property.Equals(InsertModeProperty))
1144 source.View.InsertMode = source.InsertMode;
1145 if (e.Property.Equals(TabCharsProperty))
1146 source.View.TabStops = source.TabChars;
1147 if (e.Property.Equals(RectSelectModeProperty))
1148 source._Controller.RectSelection = source.RectSelectMode;
1149 if (e.Property.Equals(DrawCaretProperty))
1150 source.View.HideCaret = !source.DrawCaret;
1151 if (e.Property.Equals(DrawCaretLineProperty))
1152 source.View.HideLineMarker = !source.DrawCaretLine;
1153 if (e.Property.Equals(DrawLineNumberProperty))
1155 source.View.DrawLineNumber = source.DrawLineNumber;
1156 source._Controller.JumpCaret(source.View.CaretPostion.row, source.View.CaretPostion.col);
1158 if(e.Property.Equals(MagnificationPowerPropertyKey))
1159 source.Render.FontSize = source.FontSize * source.MagnificationPower;
1160 if (e.Property.Equals(FontFamilyProperty))
1161 source.Render.FontFamily = source.FontFamily;
1162 if (e.Property.Equals(FontStyleProperty))
1163 source.Render.FontStyle = source.FontStyle;
1164 if (e.Property.Equals(FontWeightProperty))
1165 source.Render.FontWeigth = source.FontWeight;
1166 if (e.Property.Equals(FontSizeProperty))
1167 source.Render.FontSize = source.FontSize;
1168 if (e.Property.Equals(ForegroundProperty))
1169 source.Render.Foreground = D2DRenderBase.ToColor4(source.Foreground);
1170 if (e.Property.Equals(BackgroundProperty))
1171 source.Render.Background = D2DRenderBase.ToColor4(source.Background);
1172 if (e.Property.Equals(ControlCharProperty))
1173 source.Render.ControlChar = D2DRenderBase.ToColor4(source.ControlChar);
1174 if (e.Property.Equals(HilightProperty))
1175 source.Render.Hilight = D2DRenderBase.ToColor4(source.Hilight);
1176 if (e.Property.Equals(Keyword1Property))
1177 source.Render.Keyword1 = D2DRenderBase.ToColor4(source.Keyword1);
1178 if (e.Property.Equals(Keyword2Property))
1179 source.Render.Keyword2 = D2DRenderBase.ToColor4(source.Keyword2);
1180 if (e.Property.Equals(CommentProperty))
1181 source.Render.Comment = D2DRenderBase.ToColor4(source.Comment);
1182 if (e.Property.Equals(LiteralProperty))
1183 source.Render.Literal = D2DRenderBase.ToColor4(source.Literal);
1184 if (e.Property.Equals(URLProperty))
1185 source.Render.Url = D2DRenderBase.ToColor4(source.URL);
1186 if (e.Property.Equals(InsertCaretProperty))
1187 source.Render.InsertCaret = D2DRenderBase.ToColor4(source.InsertCaret);
1188 if (e.Property.Equals(OverwriteCaretProperty))
1189 source.Render.OverwriteCaret = D2DRenderBase.ToColor4(source.OverwriteCaret);
1190 if (e.Property.Equals(PaddingProperty))
1191 source.View.Padding = new Padding((int)source.Padding.Left, (int)source.Padding.Top, (int)source.Padding.Right, (int)source.Padding.Bottom);
1192 if (e.Property.Equals(LineMarkerProperty))
1193 source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);
1194 if (e.Property.Equals(MarkURLProperty))
1195 source.View.UrlMark = source.MarkURL;
1196 if (e.Property.Equals(ShowFullSpaceProperty))
1197 source.Render.ShowFullSpace = source.ShowFullSpace;
1198 if (e.Property.Equals(ShowHalfSpaceProperty))
1199 source.Render.ShowHalfSpace = source.ShowHalfSpace;
1200 if (e.Property.Equals(ShowTabProperty))
1201 source.Render.ShowTab = source.ShowTab;
1202 if (e.Property.Equals(ShowLineBreakProperty))
1203 source.Render.ShowLineBreak = source.ShowLineBreak;
1204 if (e.Property.Equals(LineBreakProperty))
1205 source.View.LineBreak = source.LineBreakMethod;
1206 if (e.Property.Equals(LineBreakCharCountProperty))
1207 source.View.LineBreakCharCount = source.LineBreakCharCount;
1208 if (e.Property.Equals(UpdateAreaProperty))
1209 source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);
1210 if (e.Property.Equals(LineNumberProperty))
1211 source.Render.LineNumber = D2DRenderBase.ToColor4(source.LineNumber);
1212 if (e.Property.Equals(FlowDirectionProperty))
1214 source.Render.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;
1215 if(source.horizontalScrollBar != null)
1216 source.horizontalScrollBar.FlowDirection = source.FlowDirection;
1218 if (e.Property.Equals(DrawRulerProperty))
1220 source.View.HideRuler = !source.DrawRuler;
1221 source._Controller.JumpCaret(source.View.CaretPostion.row, source.View.CaretPostion.col);
1229 /// コンテキストメニューが表示されるときに呼び出されます
1231 public event EventHandler<FooContextMenuEventArgs> ContextMenuOpening;
1237 internal Controller Controller
1241 return this._Controller;
1246 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1248 public TextAntialiasMode TextAntialiasMode
1252 return this.Render.TextAntialiasMode;
1256 this.Render.TextAntialiasMode = value;
1263 public IHilighter Hilighter
1267 return this.View.Hilighter;
1271 this.View.Hilighter = value;
1272 this.View.LayoutLines.ClearLayoutCache();
1277 /// フォールティングを作成するインターフェイスを表す
1279 public IFoldingStrategy FoldingStrategy
1283 return this.View.LayoutLines.FoldingStrategy;
1287 this.View.LayoutLines.FoldingStrategy = value;
1289 this.View.LayoutLines.FoldingCollection.Clear();
1296 public MarkerPatternSet MarkerPatternSet
1300 return this.View.MarkerPatternSet;
1307 public Document Document
1316 public LineToIndexTable LayoutLineCollection
1318 get { return this.View.LayoutLines; }
1324 public string SelectedText
1328 return this._Controller.SelectedText;
1332 int oldLength = this.Document.Length;
1333 this._Controller.SelectedText = value;
1340 public IndentMode IndentMode
1342 get { return (IndentMode)GetValue(IndentModeProperty); }
1343 set { SetValue(IndentModeProperty, value); }
1347 /// IndentModeの依存プロパティを表す
1349 public static readonly DependencyProperty IndentModeProperty =
1350 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab,OnPropertyChanged));
1356 /// Lengthが0の場合はキャレット位置を表します。
1357 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1359 public TextRange Selection
1361 get { return (TextRange)GetValue(SelectionProperty); }
1362 set { SetValue(SelectionProperty, value); }
1366 /// Selectionの依存プロパティを表す
1368 public static readonly DependencyProperty SelectionProperty =
1369 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(0));
1374 public double MagnificationPower
1376 get { return (double)GetValue(MagnificationPowerPropertyKey); }
1377 set { SetValue(MagnificationPowerPropertyKey, value); }
1383 public static readonly DependencyProperty MagnificationPowerPropertyKey =
1384 DependencyProperty.Register("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0, OnPropertyChanged));
1389 public TextPoint CaretPostion
1391 get { return (TextPoint)GetValue(CaretPostionPropertyKey); }
1392 set { SetValue(CaretPostionPropertyKey, value); }
1395 static readonly DependencyProperty CaretPostionPropertyKey =
1396 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(new TextPoint(), OnPropertyChanged));
1401 public new FlowDirection FlowDirection
1403 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1404 set { SetValue(FlowDirectionProperty, value); }
1408 /// レタリング方向を表す。これは依存プロパティです
1410 public new static readonly DependencyProperty FlowDirectionProperty =
1411 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight,OnPropertyChanged));
1416 public new FontFamily FontFamily
1418 get { return (FontFamily)GetValue(FontFamilyProperty); }
1419 set { SetValue(FontFamilyProperty, value); }
1423 /// FontFamilyの依存プロパティを表す
1425 public new static readonly DependencyProperty FontFamilyProperty =
1426 DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(FooTextBox), new PropertyMetadata(new FontFamily("Cambria"), OnPropertyChanged));
1431 public new double FontSize
1433 get { return (double)GetValue(FontSizeProperty); }
1434 set { SetValue(FontSizeProperty, value); }
1438 /// FontSizeの依存プロパティを表す
1440 public new static readonly DependencyProperty FontSizeProperty =
1441 DependencyProperty.Register("FontSize", typeof(double), typeof(FooTextBox), new PropertyMetadata(12.0,OnPropertyChanged));
1446 public new FontStyle FontStyle
1448 get { return (FontStyle)GetValue(FontStyleProperty); }
1449 set { SetValue(FontStyleProperty, value); }
1453 /// FontStyleの依存プロパティを表す
1455 public new static readonly DependencyProperty FontStyleProperty =
1456 DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(FooTextBox), new PropertyMetadata(FontStyle.Normal,OnPropertyChanged));
1461 public new FontWeight FontWeight
1463 get { return (FontWeight)GetValue(FontWeightProperty); }
1464 set { SetValue(FontWeightProperty, value); }
1468 /// FontWeigthの依存プロパティを表す
1470 public new static readonly DependencyProperty FontWeightProperty =
1471 DependencyProperty.Register("FontWeigth", typeof(FontWeight), typeof(FooTextBox), new PropertyMetadata(FontWeights.Normal,OnPropertyChanged));
1474 /// デフォルトの文字色を表す。これは依存プロパティです
1476 public new Windows.UI.Color Foreground
1478 get { return (Windows.UI.Color)GetValue(ForegroundProperty); }
1479 set { SetValue(ForegroundProperty, value); }
1483 /// Foregroundの依存プロパティを表す
1485 public new static readonly DependencyProperty ForegroundProperty =
1486 DependencyProperty.Register("Foreground", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1489 /// 背景色を表す。これは依存プロパティです
1491 public new Windows.UI.Color Background
1493 get { return (Windows.UI.Color)GetValue(BackgroundProperty); }
1494 set { SetValue(BackgroundProperty, value); }
1498 /// Backgroundの依存プロパティを表す
1500 public new static readonly DependencyProperty BackgroundProperty =
1501 DependencyProperty.Register("Background", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));
1504 /// コントロールコードの文字色を表す。これは依存プロパティです
1506 public Windows.UI.Color ControlChar
1508 get { return (Windows.UI.Color)GetValue(ControlCharProperty); }
1509 set { SetValue(ControlCharProperty, value); }
1513 /// ControlCharの依存プロパティを表す
1515 public static readonly DependencyProperty ControlCharProperty =
1516 DependencyProperty.Register("ControlChar", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1519 /// 選択時の背景色を表す。これは依存プロパティです
1521 public Windows.UI.Color Hilight
1523 get { return (Windows.UI.Color)GetValue(HilightProperty); }
1524 set { SetValue(HilightProperty, value); }
1528 /// Hilightの依存プロパティを表す
1530 public static readonly DependencyProperty HilightProperty =
1531 DependencyProperty.Register("Hilight", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DeepSkyBlue, OnPropertyChanged));
1534 /// キーワード1の文字色を表す。これは依存プロパティです
1536 public Windows.UI.Color Keyword1
1538 get { return (Windows.UI.Color)GetValue(Keyword1Property); }
1539 set { SetValue(Keyword1Property, value); }
1543 /// Keyword1の依存プロパティを表す
1545 public static readonly DependencyProperty Keyword1Property =
1546 DependencyProperty.Register("Keyword1", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1549 /// キーワード2の文字色を表す。これは依存プロパティです
1551 public Windows.UI.Color Keyword2
1553 get { return (Windows.UI.Color)GetValue(Keyword2Property); }
1554 set { SetValue(Keyword2Property, value); }
1558 /// Keyword2の依存プロパティを表す
1560 public static readonly DependencyProperty Keyword2Property =
1561 DependencyProperty.Register("Keyword2", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DarkCyan, OnPropertyChanged));
1564 /// コメントの文字色を表す。これは依存プロパティです
1566 public Windows.UI.Color Comment
1568 get { return (Windows.UI.Color)GetValue(CommentProperty); }
1569 set { SetValue(CommentProperty, value); }
1573 /// Commentの依存プロパティを表す
1575 public static readonly DependencyProperty CommentProperty =
1576 DependencyProperty.Register("Comment", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Green, OnPropertyChanged));
1579 /// 文字リテラルの文字色を表す。これは依存プロパティです
1581 public Windows.UI.Color Literal
1583 get { return (Windows.UI.Color)GetValue(LiteralProperty); }
1584 set { SetValue(LiteralProperty, value); }
1588 /// Literalの依存プロパティを表す
1590 public static readonly DependencyProperty LiteralProperty =
1591 DependencyProperty.Register("Literal", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Brown, OnPropertyChanged));
1594 /// URLの文字色を表す。これは依存プロパティです
1596 public Windows.UI.Color URL
1598 get { return (Windows.UI.Color)GetValue(URLProperty); }
1599 set { SetValue(URLProperty, value); }
1605 public static readonly DependencyProperty URLProperty =
1606 DependencyProperty.Register("URL", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1611 public Windows.UI.Color UpdateArea
1613 get { return (Windows.UI.Color)GetValue(UpdateAreaProperty); }
1614 set { SetValue(UpdateAreaProperty, value); }
1618 /// UpdateAreaの依存プロパティを表す
1620 public static readonly DependencyProperty UpdateAreaProperty =
1621 DependencyProperty.Register("UpdateArea", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));
1626 public Windows.UI.Color LineMarker
1628 get { return (Windows.UI.Color)GetValue(LineMarkerProperty); }
1629 set { SetValue(LineMarkerProperty, value); }
1633 /// LineMarkerの依存プロパティを表す
1635 public static readonly DependencyProperty LineMarkerProperty =
1636 DependencyProperty.Register("LineMarker", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1639 /// 挿入モード時のキャレットの色を表す
1641 public Windows.UI.Color InsertCaret
1643 get { return (Windows.UI.Color)GetValue(InsertCaretProperty); }
1644 set { SetValue(InsertCaretProperty, value); }
1648 /// InsertCaretの依存プロパティを表す
1650 public static readonly DependencyProperty InsertCaretProperty =
1651 DependencyProperty.Register("InsertCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1654 /// 上書きモード時のキャレット職を表す
1656 public Windows.UI.Color OverwriteCaret
1658 get { return (Windows.UI.Color)GetValue(OverwriteCaretProperty); }
1659 set { SetValue(OverwriteCaretProperty, value); }
1663 /// OverwriteCaretの依存プロパティを表す
1665 public static readonly DependencyProperty OverwriteCaretProperty =
1666 DependencyProperty.Register("OverwriteCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1671 public Windows.UI.Color LineNumber
1673 get { return (Windows.UI.Color)GetValue(LineNumberProperty); }
1674 set { SetValue(LineNumberProperty, value); }
1678 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1680 public static readonly DependencyProperty LineNumberProperty =
1681 DependencyProperty.Register("LineNumber", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray,OnPropertyChanged));
1686 public new Thickness Padding
1688 get { return (Thickness)GetValue(PaddingProperty); }
1689 set { SetValue(PaddingProperty, value); }
1693 /// Paddingの依存プロパティを表す
1695 public new static readonly DependencyProperty PaddingProperty =
1696 DependencyProperty.Register("Padding", typeof(Thickness), typeof(FooTextBox), new PropertyMetadata(new Thickness(),OnPropertyChanged));
1699 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1701 public bool InsertMode
1703 get { return (bool)GetValue(InsertModeProperty); }
1704 set { SetValue(InsertModeProperty, value); }
1708 /// InsertModeの依存プロパティを表す
1710 public static readonly DependencyProperty InsertModeProperty =
1711 DependencyProperty.Register("InsertMode",
1714 new PropertyMetadata(true, OnPropertyChanged));
1717 /// タブの文字数を表す。これは依存プロパティです
1721 get { return (int)GetValue(TabCharsProperty); }
1722 set { SetValue(TabCharsProperty, value); }
1726 /// TabCharsの依存プロパティを表す
1728 public static readonly DependencyProperty TabCharsProperty =
1729 DependencyProperty.Register("TabChars",
1732 new PropertyMetadata(4, OnPropertyChanged));
1735 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1737 public bool RectSelectMode
1739 get { return (bool)GetValue(RectSelectModeProperty); }
1740 set { SetValue(RectSelectModeProperty, value); }
1744 /// RectSelectModeの依存プロパティを表す
1746 public static readonly DependencyProperty RectSelectModeProperty =
1747 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1753 /// 変更した場合、レイアウトの再構築を行う必要があります
1755 public LineBreakMethod LineBreakMethod
1757 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1758 set { SetValue(LineBreakProperty, value); }
1762 /// LineBreakMethodの依存プロパティを表す
1764 public static readonly DependencyProperty LineBreakProperty =
1765 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None, OnPropertyChanged));
1769 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1772 /// 変更した場合、レイアウトの再構築を行う必要があります
1774 public int LineBreakCharCount
1776 get { return (int)GetValue(LineBreakCharCountProperty); }
1777 set { SetValue(LineBreakCharCountProperty, value); }
1781 /// LineBreakCharCountの依存プロパティを表す
1783 public static readonly DependencyProperty LineBreakCharCountProperty =
1784 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
1787 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1789 public bool DrawCaret
1791 get { return (bool)GetValue(DrawCaretProperty); }
1792 set { SetValue(DrawCaretProperty, value); }
1796 /// DrawCaretの依存プロパティを表す
1798 public static readonly DependencyProperty DrawCaretProperty =
1799 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new PropertyMetadata(true, OnPropertyChanged));
1803 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1805 public bool DrawCaretLine
1807 get { return (bool)GetValue(DrawCaretLineProperty); }
1808 set { SetValue(DrawCaretLineProperty, value); }
1812 /// DrawCaretLineの依存プロパティを表す
1814 public static readonly DependencyProperty DrawCaretLineProperty =
1815 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1818 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
1820 public bool DrawLineNumber
1822 get { return (bool)GetValue(DrawLineNumberProperty); }
1823 set { SetValue(DrawLineNumberProperty, value); }
1827 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
1829 public bool DrawRuler
1831 get { return (bool)GetValue(DrawRulerProperty); }
1832 set { SetValue(DrawRulerProperty, value); }
1836 /// DrawRulerの依存プロパティを表す
1838 public static readonly DependencyProperty DrawRulerProperty =
1839 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1843 /// DrawLineNumberの依存プロパティを表す
1845 public static readonly DependencyProperty DrawLineNumberProperty =
1846 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1849 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
1853 get { return (bool)GetValue(MarkURLProperty); }
1854 set { SetValue(MarkURLProperty, value); }
1858 /// MarkURLの依存プロパティを表す
1860 public static readonly DependencyProperty MarkURLProperty =
1861 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1864 /// 全角スペースを表示するなら真。そうでないなら偽
1866 public bool ShowFullSpace
1868 get { return (bool)GetValue(ShowFullSpaceProperty); }
1869 set { SetValue(ShowFullSpaceProperty, value); }
1873 /// ShowFullSpaceの依存プロパティを表す
1875 public static readonly DependencyProperty ShowFullSpaceProperty =
1876 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1879 /// 半角スペースを表示するなら真。そうでないなら偽
1881 public bool ShowHalfSpace
1883 get { return (bool)GetValue(ShowHalfSpaceProperty); }
1884 set { SetValue(ShowHalfSpaceProperty, value); }
1888 /// ShowHalfSpaceの依存プロパティを表す
1890 public static readonly DependencyProperty ShowHalfSpaceProperty =
1891 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1894 /// タブを表示するなら真。そうでないなら偽
1898 get { return (bool)GetValue(ShowTabProperty); }
1899 set { SetValue(ShowTabProperty, value); }
1903 /// ShowTabの依存プロパティを表す
1905 public static readonly DependencyProperty ShowTabProperty =
1906 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1909 /// 改行マークを表示するなら真。そうでないなら偽
1911 public bool ShowLineBreak
1913 get { return (bool)GetValue(ShowLineBreakProperty); }
1914 set { SetValue(ShowLineBreakProperty, value); }
1918 /// ShowLineBreakの依存プロパティを表す
1920 public static readonly DependencyProperty ShowLineBreakProperty =
1921 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false,OnPropertyChanged));
1928 /// コンテキストメニューのイベントデーターを表す
1930 public class FooContextMenuEventArgs
1933 /// 処理済みなら真。そうでないなら偽
1935 public bool Handled = false;
1937 /// コンテキストメニューを表示すべき座標を表す
1939 public Windows.Foundation.Point Postion;
1943 /// <param name="pos"></param>
1944 public FooContextMenuEventArgs(Windows.Foundation.Point pos)