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.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._Controller.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 = new DispatcherTimer();
113 this.timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
114 this.timer.Tick += new EventHandler<object>(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;
125 this.View.CaretBlink = true;
126 this.View.CaretBlinkTime = 1000; //TODO:ユーザーの設定を反映させる
127 this.View.CaretWidthOnInsertMode = 1; //TODO:ユーザーの設定を反映させる
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.Document.CaretPostion.row,isShiftPressed);
499 if (isControlPressed)
500 this._Controller.JumpToEnd(isShiftPressed);
502 this.Controller.JumpToLineEnd(this.Document.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)
608 this.gestureRecongnizer.AutoProcessInertia = e.Pointer.PointerDeviceType != PointerDeviceType.Mouse;
610 this.CapturePointer(e.Pointer);
611 this.gestureRecongnizer.ProcessDownEvent(e.GetCurrentPoint(this));
616 protected override void OnPointerMoved(PointerRoutedEventArgs e)
619 this.gestureRecongnizer.AutoProcessInertia = e.Pointer.PointerDeviceType != PointerDeviceType.Mouse;
621 this.gestureRecongnizer.ProcessMoveEvents(e.GetIntermediatePoints(this));
624 if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
626 Point p = ((Point)e.GetCurrentPoint(this).Position).Scale(this.Render.GetScale());
627 if (this.View.HitTextArea(p.X, p.Y))
629 TextPoint tp = this.View.GetTextPointFromPostion(p);
630 if (this._Controller.IsMarker(tp, HilightType.Url))
631 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Hand, 101);
633 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.IBeam, 101);
637 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 101);
643 protected override void OnPointerReleased(PointerRoutedEventArgs e)
645 this.gestureRecongnizer.ProcessUpEvent(e.GetCurrentPoint(this));
646 this.ReleasePointerCapture(e.Pointer);
651 protected override void OnPointerCanceled(PointerRoutedEventArgs e)
653 this.gestureRecongnizer.CompleteGesture();
654 this.ReleasePointerCapture(e.Pointer);
659 protected override void OnPointerCaptureLost(PointerRoutedEventArgs e)
661 this.gestureRecongnizer.CompleteGesture();
662 this.ReleasePointerCapture(e.Pointer);
667 protected override void OnPointerWheelChanged(PointerRoutedEventArgs e)
670 this.gestureRecongnizer.AutoProcessInertia = e.Pointer.PointerDeviceType != PointerDeviceType.Mouse;
672 bool shift = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Shift) ==
673 Windows.System.VirtualKeyModifiers.Shift;
674 bool ctrl = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Control) ==
675 Windows.System.VirtualKeyModifiers.Control;
676 this.gestureRecongnizer.ProcessMouseWheelEvent(e.GetCurrentPoint(this), shift, ctrl);
680 void CoreWindow_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)
682 if (this.FocusState == FocusState.Unfocused || !this.IsEnabled)
684 if (args.KeyCode >= 00 && args.KeyCode <= 0x1f)
686 this._Controller.DoInputString(Char.ConvertFromUtf32((int)args.KeyCode));
690 bool textStore_IsReadOnly()
695 bool textStore_IsLoading()
700 void textStore_CompositionEnded()
702 TextStoreHelper.EndCompostion(this.Document);
706 void textStore_CompositionUpdated(int start, int end)
708 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
711 bool textStore_CompositionStarted()
713 return TextStoreHelper.StartCompstion(this.Document);
716 string _textStore_GetString(int start, int length)
718 return this.Document.ToString(start, length);
721 void _textStore_GetStringExtent(
725 out POINT o_bottomRight
728 Point startPos, endPos;
729 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
731 double scale = this.Render.GetScale();
732 var screen_startPos = Util.GetScreentPoint(startPos.Scale(scale), this);
733 var screen_endPos = Util.GetScreentPoint(endPos.Scale(scale), this);
735 o_topLeft = new POINT((int)screen_startPos.X, (int)screen_startPos.Y);
736 o_bottomRight = new POINT((int)screen_endPos.X, (int)screen_endPos.Y);
739 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
741 var pointTopLeft = new Point(0, 0);
742 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
744 var gt = this.TransformToVisual(Window.Current.Content);
745 pointTopLeft = gt.TransformPoint(pointTopLeft);
746 pointBottomRight = gt.TransformPoint(pointBottomRight);
748 o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
749 o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
752 void _textStore_GetSelectionIndex(out int o_startIndex, out int o_endIndex)
754 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out o_startIndex, out o_endIndex);
757 void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)
759 TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);
763 void _textStore_InsertAtSelection(string i_value,ref int o_stratIndex,ref int o_endIndex)
765 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
769 void Controller_SelectionChanged(object sender, EventArgs e)
772 this.nowCaretMove = true;
773 SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
774 SetValue(CaretPostionPropertyKey, this.Document.CaretPostion);
775 this.nowCaretMove = false;
776 this.Document.SelectGrippers.BottomLeft.MoveByIndex(this.View, this.Controller.SelectionStart);
777 this.Document.SelectGrippers.BottomRight.MoveByIndex(this.View, this.Controller.SelectionStart + this.Controller.SelectionLength);
778 if (this.textStore.IsLocked() == false)
779 this.textStore.NotifySelectionChanged();
782 private void gestureRecongnizer_ManipulationInertiaStarting(GestureRecognizer sender, ManipulationInertiaStartingEventArgs e)
784 //sender.InertiaTranslationDeceleration = 0.001f;
785 //sender.InertiaExpansionDeceleration = 100.0f * 96.0f / 1000.0f;
786 //sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
789 private Point GetDipFromPoint(Point p)
792 this.Render.GetDpi(out dpi, out dpi);
793 double scale = dpi / 96.0;
794 return p.Scale(1 / scale);
797 Gripper hittedGripper;
798 void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)
800 //Updateedの段階でヒットテストしてしまうとグリッパーを触ってもヒットしないことがある
801 this.hittedGripper = this.View.HitGripperFromPoint(this.GetDipFromPoint(e.Position));
804 const int WheelNoti = 120;
805 const int WheelScrollLines = 3;
806 double TotalWheelCount = 0;
808 void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
810 Point p = this.GetDipFromPoint(e.Position);
811 if (this._Controller.MoveCaretAndGripper(p, this.hittedGripper))
813 if (this.peer != null)
814 this.peer.OnNotifyCaretChanged();
819 if (e.Delta.Scale < 1)
821 double newSize = this.Render.FontSize - 1;
824 this.Render.FontSize = newSize;
826 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
830 if (e.Delta.Scale > 1)
832 double newSize = this.Render.FontSize + 1;
835 this.Render.FontSize = newSize;
837 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
841 Point translation = this.GetDipFromPoint(e.Delta.Translation);
843 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
844 if (Math.Abs(e.Cumulative.Translation.X) < Math.Abs(e.Cumulative.Translation.Y))
847 if (e.PointerDeviceType == PointerDeviceType.Mouse) {
848 //テキストボックスはWheelNotiごとにWheelScrollLinesずつスクロールするらしい
849 scrollCount = (int)Math.Abs(this.TotalWheelCount / WheelNoti * WheelScrollLines);
852 else if (scrollCount > WheelScrollLines)
853 scrollCount = WheelScrollLines;
854 if (this.TotalWheelCount >= WheelNoti) //0にすると違和感を感じる
855 this.TotalWheelCount = this.TotalWheelCount % WheelNoti;
856 this.TotalWheelCount += Math.Abs(translation.Y);
860 scrollCount = (int)Math.Abs(translation.Y + 0.5);
863 if (translation.Y > 0)
864 this._Controller.Scroll(ScrollDirection.Up, scrollCount, false, false);
866 this._Controller.Scroll(ScrollDirection.Down, scrollCount, false, false);
867 this.Document.SelectGrippers.BottomLeft.Enabled = false;
868 this.Document.SelectGrippers.BottomRight.Enabled = false;
873 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
876 if (translation.X < 0)
877 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
879 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
880 this.Document.SelectGrippers.BottomLeft.Enabled = false;
881 this.Document.SelectGrippers.BottomRight.Enabled = false;
886 void gestureRecongnizer_ManipulationCompleted(GestureRecognizer sender, ManipulationCompletedEventArgs e)
890 async void gestureRecongnizer_RightTapped(GestureRecognizer sender, RightTappedEventArgs e)
892 ResourceMap map = ResourceManager.Current.MainResourceMap.GetSubtree("FooEditEngine.Metro/Resources");
893 ResourceContext context = ResourceContext.GetForCurrentView();
894 Point p = this.GetDipFromPoint(e.Position);
895 if (this.View.HitTextArea(p.X, p.Y))
897 FooContextMenuEventArgs args = new FooContextMenuEventArgs(e.Position);
898 if (this.ContextMenuOpening != null)
899 this.ContextMenuOpening(this, args);
902 PopupMenu ContextMenu = new PopupMenu();
903 ContextMenu.Commands.Add(new UICommand(map.GetValue("CopyMenuName", context).ValueAsString, (command) =>
907 ContextMenu.Commands.Add(new UICommand(map.GetValue("CutMenuName", context).ValueAsString, (command) =>
911 ContextMenu.Commands.Add(new UICommand(map.GetValue("PasteMenuName", context).ValueAsString, async (command) =>
913 await this.PasteCommand();
915 if (this._Controller.RectSelection)
917 ContextMenu.Commands.Add(new UICommand(map.GetValue("LineSelectMenuName", context).ValueAsString, (command) =>
919 this._Controller.RectSelection = false;
924 ContextMenu.Commands.Add(new UICommand(map.GetValue("RectSelectMenuName", context).ValueAsString, (command) =>
926 this._Controller.RectSelection = true;
929 await ContextMenu.ShowAsync(Util.GetScreentPoint(e.Position,this));
934 void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)
936 Point p = this.GetDipFromPoint(e.Position);
937 bool touched = e.PointerDeviceType == PointerDeviceType.Touch;
938 this.Document.SelectGrippers.BottomLeft.Enabled = false;
939 this.Document.SelectGrippers.BottomRight.Enabled = touched;
941 System.Diagnostics.Debug.WriteLine(e.TapCount);
944 this.Document.SelectGrippers.BottomLeft.Enabled = touched;
945 //タッチスクリーンでダブルタップした場合、アンカーインデックスを単語の先頭にしないとバグる
946 this.Controller.SelectWord(this.Controller.SelectionStart, touched);
950 void JumpCaret(Point p)
952 TextPoint tp = this.View.GetTextPointFromPostion(p);
953 if (tp == TextPoint.Null)
956 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
958 FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
959 if (foldingData != null)
961 if (foldingData.Expand)
962 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
964 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
965 this._Controller.JumpCaret(foldingData.Start, false);
969 this._Controller.JumpCaret(tp.row, tp.col, false);
971 if (this.peer != null)
972 this.peer.OnNotifyCaretChanged();
973 this.View.IsFocused = true;
974 this.Focus(FocusState.Programmatic);
978 void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)
980 Point p = this.GetDipFromPoint(e.Position);
981 if (this.View.HitTextArea(p.X, p.Y))
983 TextPoint tp = this.View.GetTextPointFromPostion(p);
984 this._Controller.MoveCaretAndSelect(tp);
985 if (this.peer != null)
986 this.peer.OnNotifyCaretChanged();
991 bool IsModiferKeyPressed(VirtualKey key)
993 CoreVirtualKeyStates state = Window.Current.CoreWindow.GetKeyState(key);
994 return (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
996 void Refresh(Rectangle updateRect)
998 if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0 || this.Visibility == Windows.UI.Xaml.Visibility.Collapsed || !this.Render.IsCanDraw())
1001 this.Render.BegineDraw();
1003 this.View.Draw(updateRect);
1005 this.Render.FillBackground(updateRect);
1006 this.Render.EndDraw();
1010 bool Resize(double width, double height)
1012 if (width == 0 || height == 0)
1013 throw new ArgumentOutOfRangeException();
1014 if (this.Render.Resize(this.rectangle, width, height))
1016 this.View.PageBound = new Rectangle(0, 0, width, height);
1018 if (this.horizontalScrollBar != null)
1020 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
1021 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1023 if (this.verticalScrollBar != null)
1025 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
1026 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1033 void View_SrcChanged(object sender, EventArgs e)
1035 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1037 EditView view = this.View;
1038 if (view.Src.Row > this.verticalScrollBar.Maximum)
1039 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
1040 double absoulteX = Math.Abs(view.Src.X);
1041 if (absoulteX > this.horizontalScrollBar.Maximum)
1042 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1043 if (view.Src.Row != this.verticalScrollBar.Value)
1044 this.verticalScrollBar.Value = view.Src.Row;
1045 if (view.Src.X != this.horizontalScrollBar.Value)
1046 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1049 void FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)
1053 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1055 if (this.horizontalScrollBar == null)
1058 if (this.FlowDirection == FlowDirection.LeftToRight)
1059 toX = this.horizontalScrollBar.Value;
1061 toX = -this.horizontalScrollBar.Value;
1062 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
1063 this.Document.SelectGrippers.BottomLeft.Enabled = false;
1064 this.Document.SelectGrippers.BottomRight.Enabled = false;
1068 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1070 if (this.verticalScrollBar == null)
1072 int newRow = (int)this.verticalScrollBar.Value;
1073 if (newRow >= this.View.LayoutLines.Count)
1075 this._Controller.Scroll(this.View.Src.X, newRow, false, false);
1076 this.Document.SelectGrippers.BottomLeft.Enabled = false;
1077 this.Document.SelectGrippers.BottomRight.Enabled = false;
1081 void Document_Update(object sender, DocumentUpdateEventArgs e)
1083 if (this.textStore.IsLocked())
1085 if (e.type == UpdateType.Replace)
1086 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
1089 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1091 this.Focus(FocusState.Programmatic);
1095 void timer_Tick(object sender, object e)
1097 if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))
1103 bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding();
1105 ITextLayout layout = this.View.LayoutLines.GetLayout(this.Document.CaretPostion.row);
1106 double width = layout.GetWidthFromIndex(this.Document.CaretPostion.col);
1108 width = this.View.CaretWidthOnInsertMode;
1109 double height = layout.Height;
1110 Rectangle updateRect = new Rectangle(
1111 this.View.CaretLocation.X,
1112 this.View.CaretLocation.Y,
1119 this.Refresh(updateRect);
1123 public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
1125 FooTextBox source = (FooTextBox)sender;
1126 if (e.Property.Equals(IndentModeProperty))
1127 source.Controller.IndentMode = source.IndentMode;
1128 if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)
1129 source._Controller.Select(source.Selection.Index,source.Selection.Length);
1130 if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)
1131 source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col);
1132 if (e.Property.Equals(InsertModeProperty))
1133 source.View.InsertMode = source.InsertMode;
1134 if (e.Property.Equals(TabCharsProperty))
1135 source.Document.TabStops = source.TabChars;
1136 if (e.Property.Equals(RectSelectModeProperty))
1137 source._Controller.RectSelection = source.RectSelectMode;
1138 if (e.Property.Equals(DrawCaretProperty))
1139 source.View.HideCaret = !source.DrawCaret;
1140 if (e.Property.Equals(DrawCaretLineProperty))
1141 source.View.HideLineMarker = !source.DrawCaretLine;
1142 if (e.Property.Equals(DrawLineNumberProperty))
1143 source.Document.DrawLineNumber = source.DrawLineNumber;
1144 if(e.Property.Equals(MagnificationPowerPropertyKey))
1145 source.Render.FontSize = source.FontSize * source.MagnificationPower;
1146 if (e.Property.Equals(FontFamilyProperty))
1147 source.Render.FontFamily = source.FontFamily;
1148 if (e.Property.Equals(FontStyleProperty))
1149 source.Render.FontStyle = source.FontStyle;
1150 if (e.Property.Equals(FontWeightProperty))
1151 source.Render.FontWeigth = source.FontWeight;
1152 if (e.Property.Equals(FontSizeProperty))
1153 source.Render.FontSize = source.FontSize;
1154 if (e.Property.Equals(ForegroundProperty))
1155 source.Render.Foreground = D2DRenderBase.ToColor4(source.Foreground);
1156 if (e.Property.Equals(BackgroundProperty))
1157 source.Render.Background = D2DRenderBase.ToColor4(source.Background);
1158 if (e.Property.Equals(ControlCharProperty))
1159 source.Render.ControlChar = D2DRenderBase.ToColor4(source.ControlChar);
1160 if (e.Property.Equals(HilightProperty))
1161 source.Render.Hilight = D2DRenderBase.ToColor4(source.Hilight);
1162 if (e.Property.Equals(Keyword1Property))
1163 source.Render.Keyword1 = D2DRenderBase.ToColor4(source.Keyword1);
1164 if (e.Property.Equals(Keyword2Property))
1165 source.Render.Keyword2 = D2DRenderBase.ToColor4(source.Keyword2);
1166 if (e.Property.Equals(CommentProperty))
1167 source.Render.Comment = D2DRenderBase.ToColor4(source.Comment);
1168 if (e.Property.Equals(LiteralProperty))
1169 source.Render.Literal = D2DRenderBase.ToColor4(source.Literal);
1170 if (e.Property.Equals(URLProperty))
1171 source.Render.Url = D2DRenderBase.ToColor4(source.URL);
1172 if (e.Property.Equals(InsertCaretProperty))
1173 source.Render.InsertCaret = D2DRenderBase.ToColor4(source.InsertCaret);
1174 if (e.Property.Equals(OverwriteCaretProperty))
1175 source.Render.OverwriteCaret = D2DRenderBase.ToColor4(source.OverwriteCaret);
1176 if (e.Property.Equals(PaddingProperty))
1177 source.View.Padding = new Padding((int)source.Padding.Left, (int)source.Padding.Top, (int)source.Padding.Right, (int)source.Padding.Bottom);
1178 if (e.Property.Equals(LineMarkerProperty))
1179 source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);
1180 if (e.Property.Equals(MarkURLProperty))
1181 source.Document.UrlMark = source.MarkURL;
1182 if (e.Property.Equals(ShowFullSpaceProperty))
1183 source.Render.ShowFullSpace = source.ShowFullSpace;
1184 if (e.Property.Equals(ShowHalfSpaceProperty))
1185 source.Render.ShowHalfSpace = source.ShowHalfSpace;
1186 if (e.Property.Equals(ShowTabProperty))
1187 source.Render.ShowTab = source.ShowTab;
1188 if (e.Property.Equals(ShowLineBreakProperty))
1189 source.Render.ShowLineBreak = source.ShowLineBreak;
1190 if (e.Property.Equals(LineBreakProperty))
1191 source.Document.LineBreak = source.LineBreakMethod;
1192 if (e.Property.Equals(LineBreakCharCountProperty))
1193 source.Document.LineBreakCharCount = source.LineBreakCharCount;
1194 if (e.Property.Equals(UpdateAreaProperty))
1195 source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);
1196 if (e.Property.Equals(LineNumberProperty))
1197 source.Render.LineNumber = D2DRenderBase.ToColor4(source.LineNumber);
1198 if (e.Property.Equals(FlowDirectionProperty))
1200 source.Document.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;
1201 if(source.horizontalScrollBar != null)
1202 source.horizontalScrollBar.FlowDirection = source.FlowDirection;
1204 if (e.Property.Equals(DrawRulerProperty))
1206 source.Document.HideRuler = !source.DrawRuler;
1207 source._Controller.JumpCaret(source.Document.CaretPostion.row, source.Document.CaretPostion.col);
1215 /// コンテキストメニューが表示されるときに呼び出されます
1217 public event EventHandler<FooContextMenuEventArgs> ContextMenuOpening;
1223 internal Controller Controller
1227 return this._Controller;
1232 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1234 public TextAntialiasMode TextAntialiasMode
1238 return this.Render.TextAntialiasMode;
1242 this.Render.TextAntialiasMode = value;
1249 public IHilighter Hilighter
1253 return this.View.Hilighter;
1257 this.View.Hilighter = value;
1258 this.View.LayoutLines.ClearLayoutCache();
1263 /// フォールティングを作成するインターフェイスを表す
1265 public IFoldingStrategy FoldingStrategy
1269 return this.View.LayoutLines.FoldingStrategy;
1273 this.View.LayoutLines.FoldingStrategy = value;
1275 this.View.LayoutLines.FoldingCollection.Clear();
1282 public MarkerPatternSet MarkerPatternSet
1286 return this.Document.MarkerPatternSet;
1293 public Document Document
1302 public LineToIndexTable LayoutLineCollection
1304 get { return this.View.LayoutLines; }
1310 public string SelectedText
1314 return this._Controller.SelectedText;
1318 int oldLength = this.Document.Length;
1319 this._Controller.SelectedText = value;
1326 public IndentMode IndentMode
1328 get { return (IndentMode)GetValue(IndentModeProperty); }
1329 set { SetValue(IndentModeProperty, value); }
1333 /// IndentModeの依存プロパティを表す
1335 public static readonly DependencyProperty IndentModeProperty =
1336 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab,OnPropertyChanged));
1342 /// Lengthが0の場合はキャレット位置を表します。
1343 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1345 public TextRange Selection
1347 get { return (TextRange)GetValue(SelectionProperty); }
1348 set { SetValue(SelectionProperty, value); }
1352 /// Selectionの依存プロパティを表す
1354 public static readonly DependencyProperty SelectionProperty =
1355 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(0));
1360 public double MagnificationPower
1362 get { return (double)GetValue(MagnificationPowerPropertyKey); }
1363 set { SetValue(MagnificationPowerPropertyKey, value); }
1369 public static readonly DependencyProperty MagnificationPowerPropertyKey =
1370 DependencyProperty.Register("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0, OnPropertyChanged));
1375 public TextPoint CaretPostion
1377 get { return (TextPoint)GetValue(CaretPostionPropertyKey); }
1378 set { SetValue(CaretPostionPropertyKey, value); }
1381 static readonly DependencyProperty CaretPostionPropertyKey =
1382 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(new TextPoint(), OnPropertyChanged));
1387 public new FlowDirection FlowDirection
1389 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1390 set { SetValue(FlowDirectionProperty, value); }
1394 /// レタリング方向を表す。これは依存プロパティです
1396 public new static readonly DependencyProperty FlowDirectionProperty =
1397 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight,OnPropertyChanged));
1402 public new FontFamily FontFamily
1404 get { return (FontFamily)GetValue(FontFamilyProperty); }
1405 set { SetValue(FontFamilyProperty, value); }
1409 /// FontFamilyの依存プロパティを表す
1411 public new static readonly DependencyProperty FontFamilyProperty =
1412 DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(FooTextBox), new PropertyMetadata(new FontFamily("Cambria"), OnPropertyChanged));
1417 public new double FontSize
1419 get { return (double)GetValue(FontSizeProperty); }
1420 set { SetValue(FontSizeProperty, value); }
1424 /// FontSizeの依存プロパティを表す
1426 public new static readonly DependencyProperty FontSizeProperty =
1427 DependencyProperty.Register("FontSize", typeof(double), typeof(FooTextBox), new PropertyMetadata(12.0,OnPropertyChanged));
1432 public new FontStyle FontStyle
1434 get { return (FontStyle)GetValue(FontStyleProperty); }
1435 set { SetValue(FontStyleProperty, value); }
1439 /// FontStyleの依存プロパティを表す
1441 public new static readonly DependencyProperty FontStyleProperty =
1442 DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(FooTextBox), new PropertyMetadata(FontStyle.Normal,OnPropertyChanged));
1447 public new FontWeight FontWeight
1449 get { return (FontWeight)GetValue(FontWeightProperty); }
1450 set { SetValue(FontWeightProperty, value); }
1454 /// FontWeigthの依存プロパティを表す
1456 public new static readonly DependencyProperty FontWeightProperty =
1457 DependencyProperty.Register("FontWeigth", typeof(FontWeight), typeof(FooTextBox), new PropertyMetadata(FontWeights.Normal,OnPropertyChanged));
1460 /// デフォルトの文字色を表す。これは依存プロパティです
1462 public new Windows.UI.Color Foreground
1464 get { return (Windows.UI.Color)GetValue(ForegroundProperty); }
1465 set { SetValue(ForegroundProperty, value); }
1469 /// Foregroundの依存プロパティを表す
1471 public new static readonly DependencyProperty ForegroundProperty =
1472 DependencyProperty.Register("Foreground", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1475 /// 背景色を表す。これは依存プロパティです
1477 public new Windows.UI.Color Background
1479 get { return (Windows.UI.Color)GetValue(BackgroundProperty); }
1480 set { SetValue(BackgroundProperty, value); }
1484 /// Backgroundの依存プロパティを表す
1486 public new static readonly DependencyProperty BackgroundProperty =
1487 DependencyProperty.Register("Background", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));
1490 /// コントロールコードの文字色を表す。これは依存プロパティです
1492 public Windows.UI.Color ControlChar
1494 get { return (Windows.UI.Color)GetValue(ControlCharProperty); }
1495 set { SetValue(ControlCharProperty, value); }
1499 /// ControlCharの依存プロパティを表す
1501 public static readonly DependencyProperty ControlCharProperty =
1502 DependencyProperty.Register("ControlChar", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1505 /// 選択時の背景色を表す。これは依存プロパティです
1507 public Windows.UI.Color Hilight
1509 get { return (Windows.UI.Color)GetValue(HilightProperty); }
1510 set { SetValue(HilightProperty, value); }
1514 /// Hilightの依存プロパティを表す
1516 public static readonly DependencyProperty HilightProperty =
1517 DependencyProperty.Register("Hilight", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DeepSkyBlue, OnPropertyChanged));
1520 /// キーワード1の文字色を表す。これは依存プロパティです
1522 public Windows.UI.Color Keyword1
1524 get { return (Windows.UI.Color)GetValue(Keyword1Property); }
1525 set { SetValue(Keyword1Property, value); }
1529 /// Keyword1の依存プロパティを表す
1531 public static readonly DependencyProperty Keyword1Property =
1532 DependencyProperty.Register("Keyword1", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1535 /// キーワード2の文字色を表す。これは依存プロパティです
1537 public Windows.UI.Color Keyword2
1539 get { return (Windows.UI.Color)GetValue(Keyword2Property); }
1540 set { SetValue(Keyword2Property, value); }
1544 /// Keyword2の依存プロパティを表す
1546 public static readonly DependencyProperty Keyword2Property =
1547 DependencyProperty.Register("Keyword2", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DarkCyan, OnPropertyChanged));
1550 /// コメントの文字色を表す。これは依存プロパティです
1552 public Windows.UI.Color Comment
1554 get { return (Windows.UI.Color)GetValue(CommentProperty); }
1555 set { SetValue(CommentProperty, value); }
1559 /// Commentの依存プロパティを表す
1561 public static readonly DependencyProperty CommentProperty =
1562 DependencyProperty.Register("Comment", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Green, OnPropertyChanged));
1565 /// 文字リテラルの文字色を表す。これは依存プロパティです
1567 public Windows.UI.Color Literal
1569 get { return (Windows.UI.Color)GetValue(LiteralProperty); }
1570 set { SetValue(LiteralProperty, value); }
1574 /// Literalの依存プロパティを表す
1576 public static readonly DependencyProperty LiteralProperty =
1577 DependencyProperty.Register("Literal", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Brown, OnPropertyChanged));
1580 /// URLの文字色を表す。これは依存プロパティです
1582 public Windows.UI.Color URL
1584 get { return (Windows.UI.Color)GetValue(URLProperty); }
1585 set { SetValue(URLProperty, value); }
1591 public static readonly DependencyProperty URLProperty =
1592 DependencyProperty.Register("URL", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1597 public Windows.UI.Color UpdateArea
1599 get { return (Windows.UI.Color)GetValue(UpdateAreaProperty); }
1600 set { SetValue(UpdateAreaProperty, value); }
1604 /// UpdateAreaの依存プロパティを表す
1606 public static readonly DependencyProperty UpdateAreaProperty =
1607 DependencyProperty.Register("UpdateArea", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));
1612 public Windows.UI.Color LineMarker
1614 get { return (Windows.UI.Color)GetValue(LineMarkerProperty); }
1615 set { SetValue(LineMarkerProperty, value); }
1619 /// LineMarkerの依存プロパティを表す
1621 public static readonly DependencyProperty LineMarkerProperty =
1622 DependencyProperty.Register("LineMarker", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1625 /// 挿入モード時のキャレットの色を表す
1627 public Windows.UI.Color InsertCaret
1629 get { return (Windows.UI.Color)GetValue(InsertCaretProperty); }
1630 set { SetValue(InsertCaretProperty, value); }
1634 /// InsertCaretの依存プロパティを表す
1636 public static readonly DependencyProperty InsertCaretProperty =
1637 DependencyProperty.Register("InsertCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1640 /// 上書きモード時のキャレット職を表す
1642 public Windows.UI.Color OverwriteCaret
1644 get { return (Windows.UI.Color)GetValue(OverwriteCaretProperty); }
1645 set { SetValue(OverwriteCaretProperty, value); }
1649 /// OverwriteCaretの依存プロパティを表す
1651 public static readonly DependencyProperty OverwriteCaretProperty =
1652 DependencyProperty.Register("OverwriteCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1657 public Windows.UI.Color LineNumber
1659 get { return (Windows.UI.Color)GetValue(LineNumberProperty); }
1660 set { SetValue(LineNumberProperty, value); }
1664 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1666 public static readonly DependencyProperty LineNumberProperty =
1667 DependencyProperty.Register("LineNumber", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray,OnPropertyChanged));
1672 public new Thickness Padding
1674 get { return (Thickness)GetValue(PaddingProperty); }
1675 set { SetValue(PaddingProperty, value); }
1679 /// Paddingの依存プロパティを表す
1681 public new static readonly DependencyProperty PaddingProperty =
1682 DependencyProperty.Register("Padding", typeof(Thickness), typeof(FooTextBox), new PropertyMetadata(new Thickness(),OnPropertyChanged));
1685 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1687 public bool InsertMode
1689 get { return (bool)GetValue(InsertModeProperty); }
1690 set { SetValue(InsertModeProperty, value); }
1694 /// InsertModeの依存プロパティを表す
1696 public static readonly DependencyProperty InsertModeProperty =
1697 DependencyProperty.Register("InsertMode",
1700 new PropertyMetadata(true, OnPropertyChanged));
1703 /// タブの文字数を表す。これは依存プロパティです
1707 get { return (int)GetValue(TabCharsProperty); }
1708 set { SetValue(TabCharsProperty, value); }
1712 /// TabCharsの依存プロパティを表す
1714 public static readonly DependencyProperty TabCharsProperty =
1715 DependencyProperty.Register("TabChars",
1718 new PropertyMetadata(4, OnPropertyChanged));
1721 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1723 public bool RectSelectMode
1725 get { return (bool)GetValue(RectSelectModeProperty); }
1726 set { SetValue(RectSelectModeProperty, value); }
1730 /// RectSelectModeの依存プロパティを表す
1732 public static readonly DependencyProperty RectSelectModeProperty =
1733 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1739 /// 変更した場合、レイアウトの再構築を行う必要があります
1741 public LineBreakMethod LineBreakMethod
1743 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1744 set { SetValue(LineBreakProperty, value); }
1748 /// LineBreakMethodの依存プロパティを表す
1750 public static readonly DependencyProperty LineBreakProperty =
1751 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None, OnPropertyChanged));
1755 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1758 /// 変更した場合、レイアウトの再構築を行う必要があります
1760 public int LineBreakCharCount
1762 get { return (int)GetValue(LineBreakCharCountProperty); }
1763 set { SetValue(LineBreakCharCountProperty, value); }
1767 /// LineBreakCharCountの依存プロパティを表す
1769 public static readonly DependencyProperty LineBreakCharCountProperty =
1770 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
1773 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1775 public bool DrawCaret
1777 get { return (bool)GetValue(DrawCaretProperty); }
1778 set { SetValue(DrawCaretProperty, value); }
1782 /// DrawCaretの依存プロパティを表す
1784 public static readonly DependencyProperty DrawCaretProperty =
1785 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new PropertyMetadata(true, OnPropertyChanged));
1789 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1791 public bool DrawCaretLine
1793 get { return (bool)GetValue(DrawCaretLineProperty); }
1794 set { SetValue(DrawCaretLineProperty, value); }
1798 /// DrawCaretLineの依存プロパティを表す
1800 public static readonly DependencyProperty DrawCaretLineProperty =
1801 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1804 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
1806 public bool DrawLineNumber
1808 get { return (bool)GetValue(DrawLineNumberProperty); }
1809 set { SetValue(DrawLineNumberProperty, value); }
1813 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
1815 public bool DrawRuler
1817 get { return (bool)GetValue(DrawRulerProperty); }
1818 set { SetValue(DrawRulerProperty, value); }
1822 /// DrawRulerの依存プロパティを表す
1824 public static readonly DependencyProperty DrawRulerProperty =
1825 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1829 /// DrawLineNumberの依存プロパティを表す
1831 public static readonly DependencyProperty DrawLineNumberProperty =
1832 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1835 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
1839 get { return (bool)GetValue(MarkURLProperty); }
1840 set { SetValue(MarkURLProperty, value); }
1844 /// MarkURLの依存プロパティを表す
1846 public static readonly DependencyProperty MarkURLProperty =
1847 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1850 /// 全角スペースを表示するなら真。そうでないなら偽
1852 public bool ShowFullSpace
1854 get { return (bool)GetValue(ShowFullSpaceProperty); }
1855 set { SetValue(ShowFullSpaceProperty, value); }
1859 /// ShowFullSpaceの依存プロパティを表す
1861 public static readonly DependencyProperty ShowFullSpaceProperty =
1862 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1865 /// 半角スペースを表示するなら真。そうでないなら偽
1867 public bool ShowHalfSpace
1869 get { return (bool)GetValue(ShowHalfSpaceProperty); }
1870 set { SetValue(ShowHalfSpaceProperty, value); }
1874 /// ShowHalfSpaceの依存プロパティを表す
1876 public static readonly DependencyProperty ShowHalfSpaceProperty =
1877 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1880 /// タブを表示するなら真。そうでないなら偽
1884 get { return (bool)GetValue(ShowTabProperty); }
1885 set { SetValue(ShowTabProperty, value); }
1889 /// ShowTabの依存プロパティを表す
1891 public static readonly DependencyProperty ShowTabProperty =
1892 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1895 /// 改行マークを表示するなら真。そうでないなら偽
1897 public bool ShowLineBreak
1899 get { return (bool)GetValue(ShowLineBreakProperty); }
1900 set { SetValue(ShowLineBreakProperty, value); }
1904 /// ShowLineBreakの依存プロパティを表す
1906 public static readonly DependencyProperty ShowLineBreakProperty =
1907 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false,OnPropertyChanged));
1914 /// コンテキストメニューのイベントデーターを表す
1916 public class FooContextMenuEventArgs
1919 /// 処理済みなら真。そうでないなら偽
1921 public bool Handled = false;
1923 /// コンテキストメニューを表示すべき座標を表す
1925 public Windows.Foundation.Point Postion;
1929 /// <param name="pos"></param>
1930 public FooContextMenuEventArgs(Windows.Foundation.Point pos)