2 * Copyright (C) 2013 FooProject
3 * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
13 using System.ComponentModel;
14 using System.Threading.Tasks;
15 using Windows.ApplicationModel.Resources.Core;
16 using Windows.Devices.Input;
18 using Windows.ApplicationModel.DataTransfer;
19 using Windows.Foundation;
21 using Windows.UI.Input;
22 using Windows.UI.Core;
23 using Windows.UI.Popups;
24 using Windows.UI.Text;
25 using Windows.UI.Xaml.Media;
26 using Windows.UI.Xaml;
27 using Windows.UI.Xaml.Controls;
28 using Windows.UI.Xaml.Controls.Primitives;
29 using Windows.UI.Xaml.Input;
30 using DotNetTextStore;
31 using DotNetTextStore.UnmanagedAPI.TSF;
32 using DotNetTextStore.UnmanagedAPI.WinDef;
34 // テンプレート コントロールのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234235 を参照してください
36 namespace FooEditEngine.Metro
41 public sealed class FooTextBox : Control,IDisposable
44 Controller _Controller;
46 ScrollBar horizontalScrollBar, verticalScrollBar;
47 Windows.UI.Xaml.Shapes.Rectangle rectangle;
48 GestureRecognizer gestureRecongnizer = new GestureRecognizer();
50 FooTextBoxAutomationPeer peer;
51 bool nowCaretMove = false;
53 DispatcherTimer timer = new DispatcherTimer();
60 this.DefaultStyleKey = typeof(FooTextBox);
62 this.textStore = new TextStore2();
63 this.textStore.IsLoading += textStore_IsLoading;
64 this.textStore.IsReadOnly += textStore_IsReadOnly;
65 this.textStore.GetStringLength += () => this.Document.Length;
66 this.textStore.GetString += _textStore_GetString;
67 this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;
68 this.textStore.SetSelectionIndex += _textStore_SetSelectionIndex;
69 this.textStore.InsertAtSelection += _textStore_InsertAtSelection;
70 this.textStore.GetScreenExtent += _textStore_GetScreenExtent;
71 this.textStore.GetStringExtent += _textStore_GetStringExtent;
72 this.textStore.CompositionStarted += textStore_CompositionStarted;
73 this.textStore.CompositionUpdated += textStore_CompositionUpdated;
74 this.textStore.CompositionEnded += textStore_CompositionEnded;
76 this.rectangle = new Windows.UI.Xaml.Shapes.Rectangle();
77 this.rectangle.Margin = this.Padding;
78 this.Render = new D2DRender(this,this.rectangle,this.textStore);
80 this.Document = new Document();
82 this.View = new EditView(this.Document, this.Render, new Padding(5, Gripper.HitAreaWidth, Gripper.HitAreaWidth / 2, Gripper.HitAreaWidth));
83 this.View.SrcChanged += View_SrcChanged;
84 this.View.InsertMode = this.InsertMode;
85 this.Document.DrawLineNumber = this.DrawLineNumber;
86 this.View.HideCaret = !this.DrawCaret;
87 this.View.HideLineMarker = !this.DrawCaretLine;
88 this.Document.HideRuler = !this.DrawRuler;
89 this.Document.UrlMark = this.MarkURL;
90 this.Document.TabStops = this.TabChars;
92 this._Controller = new Controller(this.Document, this.View);
93 this.Document.SelectionChanged += Controller_SelectionChanged;
95 this.gestureRecongnizer.GestureSettings = GestureSettings.Drag |
96 GestureSettings.RightTap |
98 GestureSettings.DoubleTap |
99 GestureSettings.ManipulationTranslateX |
100 GestureSettings.ManipulationTranslateY |
101 GestureSettings.ManipulationScale |
102 GestureSettings.ManipulationTranslateInertia |
103 GestureSettings.ManipulationScaleInertia;
104 this.gestureRecongnizer.RightTapped += gestureRecongnizer_RightTapped;
105 this.gestureRecongnizer.Tapped += gestureRecongnizer_Tapped;
106 this.gestureRecongnizer.Dragging += gestureRecongnizer_Dragging;
107 this.gestureRecongnizer.ManipulationInertiaStarting += GestureRecongnizer_ManipulationInertiaStarting; ;
108 this.gestureRecongnizer.ManipulationStarted += gestureRecongnizer_ManipulationStarted;
109 this.gestureRecongnizer.ManipulationUpdated += gestureRecongnizer_ManipulationUpdated;
110 this.gestureRecongnizer.ManipulationCompleted += gestureRecongnizer_ManipulationCompleted;
112 this.timer.Interval = new TimeSpan(0, 0, 0, 0, 500);
113 this.timer.Tick += this.timer_Tick;
116 //Viewの初期化が終わった直後に置かないと例外が発生する
117 this.Document.Update += Document_Update;
119 Window.Current.CoreWindow.CharacterReceived += CoreWindow_CharacterReceived;
121 this.SizeChanged += FooTextBox_SizeChanged;
123 this.Loaded += FooTextBox_Loaded;
137 public void Dispose()
140 GC.SuppressFinalize(this);
143 bool Disposed = false;
144 private void Dispose(bool disposing)
150 this.textStore.Dispose();
152 this.Render.Dispose();
159 /// <param name="start">開始インデックス</param>
160 /// <param name="length">長さ</param>
161 public void Select(int start, int length)
163 this.Document.Select(start, length);
167 /// キャレットを指定した行に移動させます
169 /// <param name="index">インデックス</param>
170 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
171 public void JumpCaret(int index)
173 this._Controller.JumpCaret(index);
176 /// キャレットを指定した行と桁に移動させます
178 /// <param name="row">行番号</param>
179 /// <param name="col">桁</param>
180 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
181 public void JumpCaret(int row, int col)
183 this._Controller.JumpCaret(row, col);
187 /// 選択中のテキストをクリップボードにコピーします
191 string text = this._Controller.SelectedText;
192 if (text != null && text != string.Empty)
194 DataPackage dataPackage = new DataPackage();
195 dataPackage.RequestedOperation = DataPackageOperation.Copy;
196 dataPackage.SetText(text);
198 Clipboard.SetContent(dataPackage);
203 /// 選択中のテキストをクリップボードに切り取ります
207 string text = this._Controller.SelectedText;
208 if (text != null && text != string.Empty)
210 DataPackage dataPackage = new DataPackage();
211 dataPackage.RequestedOperation = DataPackageOperation.Copy;
212 dataPackage.SetText(text);
214 Clipboard.SetContent(dataPackage);
216 this._Controller.SelectedText = "";
223 public async Task PasteAsync()
225 var dataPackageView = Clipboard.GetContent();
226 if (dataPackageView.Contains(StandardDataFormats.Text))
228 this._Controller.SelectedText = await dataPackageView.GetTextAsync();
235 public void SelectAll()
237 this.Document.Select(0, this.Document.Length);
243 public void DeSelectAll()
245 this._Controller.DeSelectAll();
251 /// <param name="tp">テキストポイント</param>
252 /// <returns>座標</returns>
253 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
254 public Windows.Foundation.Point GetPostionFromTextPoint(TextPoint tp)
256 if (this.Document.FireUpdateEvent == false)
257 throw new InvalidOperationException("");
258 return this.View.GetPostionFromTextPoint(tp);
262 /// 対応するテキストポイントを返します
264 /// <param name="p">クライアント領域の原点を左上とする座標</param>
265 /// <returns>テキストポイント</returns>
266 public TextPoint GetTextPointFromPostion(Windows.Foundation.Point p)
268 if (this.Document.FireUpdateEvent == false)
269 throw new InvalidOperationException("");
270 return this.View.GetTextPointFromPostion(p);
276 /// <param name="row">レイアウト行</param>
277 /// <returns>行の高さ</returns>
278 public double GetLineHeight(int row)
280 if (this.Document.FireUpdateEvent == false)
281 throw new InvalidOperationException("");
282 return this.View.LayoutLines.GetLayout(row).Height; ;
286 /// インデックスに対応する座標を得ます
288 /// <param name="index">インデックス</param>
289 /// <returns>座標を返す</returns>
290 public Windows.Foundation.Point GetPostionFromIndex(int index)
292 if (this.Document.FireUpdateEvent == false)
293 throw new InvalidOperationException("");
294 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
295 return this.View.GetPostionFromTextPoint(tp);
301 /// <param name="p">座標</param>
302 /// <returns>インデックスを返す</returns>
303 public int GetIndexFromPostion(Windows.Foundation.Point p)
305 if (this.Document.FireUpdateEvent == false)
306 throw new InvalidOperationException("");
307 TextPoint tp = this.View.GetTextPointFromPostion(p);
308 return this.View.GetIndexFromLayoutLine(tp);
314 public void Refresh()
316 this.Refresh(this.View.PageBound);
320 /// レイアウト行をすべて破棄し、再度レイアウトを行う
322 public void PerfomLayouts()
324 this.View.PerfomLayouts();
330 /// <param name="row">行</param>
331 /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
332 public void ScrollIntoView(int row, bool alignTop)
334 this.View.ScrollIntoView(row, alignTop);
338 /// ファイルからドキュメントを構築する
340 /// <param name="sr">StremReader</param>
341 /// <returns>Taskオブジェクト</returns>
342 public async Task LoadFileAsync(System.IO.StreamReader sr, System.Threading.CancellationTokenSource token)
344 await this.Document.LoadAsync(sr, token);
348 /// ドキュメントの内容をファイルに保存する
350 /// <param name="sw">StreamWriter</param>
351 /// <param name="token">キャンセル用トークン</param>
352 /// <returns>Taskオブジェクト</returns>
353 public async Task SaveFile(System.IO.StreamWriter sw, System.Threading.CancellationTokenSource token)
355 await this.Document.SaveAsync(sw, token);
370 async Task PasteCommand()
372 await this.PasteAsync();
380 protected override Windows.UI.Xaml.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
382 this.peer = new FooTextBoxAutomationPeer(this);
387 protected override void OnApplyTemplate()
389 base.OnApplyTemplate();
391 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
394 Grid.SetRow(this.rectangle, 0);
395 Grid.SetColumn(this.rectangle, 0);
396 grid.Children.Add(this.rectangle);
399 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
400 if (this.horizontalScrollBar != null)
402 this.horizontalScrollBar.SmallChange = 10;
403 this.horizontalScrollBar.LargeChange = 100;
404 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
405 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
407 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
408 if (this.verticalScrollBar != null)
410 this.verticalScrollBar.SmallChange = 1;
411 this.verticalScrollBar.LargeChange = 10;
412 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
413 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
418 protected override void OnGotFocus(RoutedEventArgs e)
421 this.textStore.SetFocus();
422 this.View.IsFocused = true;
427 protected override void OnLostFocus(RoutedEventArgs e)
430 this.View.IsFocused = false;
435 protected override async void OnKeyDown(KeyRoutedEventArgs e)
437 bool isControlPressed = this.IsModiferKeyPressed(VirtualKey.Control);
438 bool isShiftPressed = this.IsModiferKeyPressed(VirtualKey.Shift);
439 bool isMovedCaret = false;
443 this._Controller.MoveCaretVertical(-1, isShiftPressed);
448 case VirtualKey.Down:
449 this._Controller.MoveCaretVertical(+1, isShiftPressed);
454 case VirtualKey.Left:
455 this._Controller.MoveCaretHorizontical(-1, isShiftPressed, isControlPressed);
460 case VirtualKey.Right:
461 this._Controller.MoveCaretHorizontical(1, isShiftPressed, isControlPressed);
466 case VirtualKey.PageUp:
467 this._Controller.Scroll(ScrollDirection.Up, this.View.LineCountOnScreen, isShiftPressed, true);
471 case VirtualKey.PageDown:
472 this._Controller.Scroll(ScrollDirection.Down, this.View.LineCountOnScreen, isShiftPressed, true);
476 case VirtualKey.Home:
477 if (isControlPressed)
478 this._Controller.JumpToHead(isShiftPressed);
480 this.Controller.JumpToLineHead(this.Document.CaretPostion.row,isShiftPressed);
485 if (isControlPressed)
486 this._Controller.JumpToEnd(isShiftPressed);
488 this.Controller.JumpToLineEnd(this.Document.CaretPostion.row,isShiftPressed);
493 if (!isControlPressed)
495 if (this._Controller.SelectionLength == 0)
496 this._Controller.DoInputChar('\t');
497 else if (isShiftPressed)
498 this._Controller.DownIndent();
500 this._Controller.UpIndent();
505 case VirtualKey.Enter:
506 this._Controller.DoEnterAction();
510 case VirtualKey.Insert:
511 if(this.View.InsertMode)
512 this.View.InsertMode = false;
514 this.View.InsertMode = true;
519 if (isControlPressed)
527 if (isControlPressed)
529 if (this._Controller.RectSelection)
530 this._Controller.RectSelection = false;
532 this._Controller.RectSelection = true;
538 if (isControlPressed)
545 if (isControlPressed)
552 if (isControlPressed)
554 await this.PasteCommand();
559 if (isControlPressed)
561 this.Document.UndoManager.redo();
567 if (isControlPressed)
569 this.Document.UndoManager.undo();
574 case VirtualKey.Back:
575 this._Controller.DoBackSpaceAction();
579 case VirtualKey.Delete:
580 this._Controller.DoDeleteAction();
585 if (isMovedCaret && this.peer != null)
586 this.peer.OnNotifyCaretChanged();
591 protected override void OnPointerPressed(PointerRoutedEventArgs e)
593 this.CapturePointer(e.Pointer);
594 this.gestureRecongnizer.ProcessDownEvent(e.GetCurrentPoint(this));
599 protected override void OnPointerMoved(PointerRoutedEventArgs e)
601 this.gestureRecongnizer.ProcessMoveEvents(e.GetIntermediatePoints(this));
604 if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
606 Point p = e.GetCurrentPoint(this).Position;
607 if (this.View.HitTextArea(p.X, p.Y))
609 TextPoint tp = this.View.GetTextPointFromPostion(p);
610 if (this._Controller.IsMarker(tp, HilightType.Url))
611 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Hand, 101);
613 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.IBeam, 101);
617 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 101);
623 protected override void OnPointerReleased(PointerRoutedEventArgs e)
625 this.gestureRecongnizer.ProcessUpEvent(e.GetCurrentPoint(this));
630 protected override void OnPointerCanceled(PointerRoutedEventArgs e)
632 this.gestureRecongnizer.CompleteGesture();
637 protected override void OnPointerWheelChanged(PointerRoutedEventArgs e)
639 bool shift = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Shift) ==
640 Windows.System.VirtualKeyModifiers.Shift;
641 bool ctrl = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Control) ==
642 Windows.System.VirtualKeyModifiers.Control;
643 this.gestureRecongnizer.ProcessMouseWheelEvent(e.GetCurrentPoint(this), shift, ctrl);
647 void CoreWindow_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)
649 if (this.FocusState == FocusState.Unfocused || !this.IsEnabled)
651 if (args.KeyCode >= 00 && args.KeyCode <= 0x1f)
653 this._Controller.DoInputString(Char.ConvertFromUtf32((int)args.KeyCode));
657 bool textStore_IsReadOnly()
662 bool textStore_IsLoading()
667 void textStore_CompositionEnded()
669 TextStoreHelper.EndCompostion(this.Document);
673 void textStore_CompositionUpdated(int start, int end)
675 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
678 bool textStore_CompositionStarted()
680 return TextStoreHelper.StartCompstion(this.Document);
683 string _textStore_GetString(int start, int length)
685 return this.Document.ToString(start, length);
688 void _textStore_GetStringExtent(
692 out POINT o_bottomRight
695 Point startPos, endPos;
696 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
698 double scale = Util.GetScale();
700 //DIPを渡すと予測候補の位置がおかしくなるので、デバイス依存の座標に変換する
701 var screenStartPos = Util.GetScreentPoint(startPos, this).Scale(scale);
702 var screenEndPos = Util.GetScreentPoint(endPos, this).Scale(scale);
703 o_topLeft = new POINT((int)(screenStartPos.X), (int)(screenStartPos.Y));
704 o_bottomRight = new POINT((int)(screenEndPos.X), (int)(screenEndPos.Y));
707 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
709 var pointTopLeft = new Point(0, 0);
710 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
712 var gt = this.TransformToVisual(Window.Current.Content);
713 pointTopLeft = gt.TransformPoint(pointTopLeft);
714 pointBottomRight = gt.TransformPoint(pointBottomRight);
716 o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
717 o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
720 void _textStore_GetSelectionIndex(int start_index, int max_count, out DotNetTextStore.TextSelection[] sels)
723 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out selRange);
725 sels = new DotNetTextStore.TextSelection[1];
726 sels[0] = new DotNetTextStore.TextSelection();
727 sels[0].start = selRange.Index;
728 sels[0].end = selRange.Index + selRange.Length;
731 void _textStore_SetSelectionIndex(DotNetTextStore.TextSelection[] sels)
733 TextStoreHelper.SetSelectionIndex(this._Controller, this.View, sels[0].start, sels[0].end);
737 void _textStore_InsertAtSelection(string i_value,ref int o_stratIndex,ref int o_endIndex)
739 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
743 void Controller_SelectionChanged(object sender, EventArgs e)
746 this.nowCaretMove = true;
747 SetValue(SelectedTextProperty, this._Controller.SelectedText);
748 SetValue(CaretPostionPropertyKey, this.Document.CaretPostion);
749 this.nowCaretMove = false;
750 if (this.textStore.IsLocked() == false)
751 this.textStore.NotifySelectionChanged();
754 Gripper hittedGripper;
755 void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)
757 //Updateedの段階でヒットテストしてしまうとグリッパーを触ってもヒットしないことがある
758 this.hittedGripper = this.View.HitGripperFromPoint(e.Position);
761 private void GestureRecongnizer_ManipulationInertiaStarting(GestureRecognizer sender, ManipulationInertiaStartingEventArgs args)
763 //sender.InertiaTranslationDeceleration = 0.001f;
764 //sender.InertiaExpansionDeceleration = 100.0f * 96.0f / 1000.0f;
765 //sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
768 void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
770 if (this._Controller.MoveCaretAndGripper(e.Position, this.hittedGripper))
772 if (this.peer != null)
773 this.peer.OnNotifyCaretChanged();
778 if (e.Delta.Scale < 1)
780 double newSize = this.Render.FontSize - 1;
783 this.Render.FontSize = newSize;
785 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
789 if (e.Delta.Scale > 1)
791 double newSize = this.Render.FontSize + 1;
794 this.Render.FontSize = newSize;
796 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
800 Point translation = e.Delta.Translation;
802 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
803 if (Math.Abs(e.Cumulative.Translation.X) < Math.Abs(e.Cumulative.Translation.Y))
805 int deltay = (int)Math.Abs(Math.Ceiling(translation.Y));
806 if (translation.Y < 0)
807 this._Controller.ScrollByPixel(ScrollDirection.Down, deltay, false, false);
809 this._Controller.ScrollByPixel(ScrollDirection.Up, deltay, false, false);
814 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
817 if (translation.X < 0)
818 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
820 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
825 void gestureRecongnizer_ManipulationCompleted(GestureRecognizer sender, ManipulationCompletedEventArgs e)
829 async void gestureRecongnizer_RightTapped(GestureRecognizer sender, RightTappedEventArgs e)
831 ResourceMap map = ResourceManager.Current.MainResourceMap.GetSubtree("FooEditEngine.Metro/Resources");
832 ResourceContext context = ResourceContext.GetForCurrentView();
833 if (this.View.HitTextArea(e.Position.X, e.Position.Y))
835 FooContextMenuEventArgs args = new FooContextMenuEventArgs(e.Position);
836 if (this.ContextMenuOpening != null)
837 this.ContextMenuOpening(this, args);
840 PopupMenu ContextMenu = new PopupMenu();
841 ContextMenu.Commands.Add(new UICommand(map.GetValue("CopyMenuName", context).ValueAsString, (command) =>
845 ContextMenu.Commands.Add(new UICommand(map.GetValue("CutMenuName", context).ValueAsString, (command) =>
849 ContextMenu.Commands.Add(new UICommand(map.GetValue("PasteMenuName", context).ValueAsString, async (command) =>
851 await this.PasteCommand();
853 if (this._Controller.RectSelection)
855 ContextMenu.Commands.Add(new UICommand(map.GetValue("LineSelectMenuName", context).ValueAsString, (command) =>
857 this._Controller.RectSelection = false;
862 ContextMenu.Commands.Add(new UICommand(map.GetValue("RectSelectMenuName", context).ValueAsString, (command) =>
864 this._Controller.RectSelection = true;
867 await ContextMenu.ShowAsync(Util.GetScreentPoint(e.Position,this));
872 void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)
874 bool touched = e.PointerDeviceType == PointerDeviceType.Touch;
875 this.Document.SelectGrippers.BottomLeft.Enabled = false;
876 this.Document.SelectGrippers.BottomRight.Enabled = touched;
877 this.JumpCaret(e.Position);
878 System.Diagnostics.Debug.WriteLine(e.TapCount);
881 this.Document.SelectGrippers.BottomLeft.Enabled = touched;
882 //タッチスクリーンでダブルタップした場合、アンカーインデックスを単語の先頭にしないとバグる
883 this.Document.SelectWord(this.Controller.SelectionStart, touched);
888 void JumpCaret(Point p)
890 TextPoint tp = this.View.GetTextPointFromPostion(p);
891 if (tp == TextPoint.Null)
894 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
896 FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
897 if (foldingData != null)
899 if (foldingData.Expand)
900 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
902 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
903 this._Controller.JumpCaret(foldingData.Start, false);
907 this._Controller.JumpCaret(tp.row, tp.col, false);
909 if (this.peer != null)
910 this.peer.OnNotifyCaretChanged();
911 this.View.IsFocused = true;
912 this.Focus(FocusState.Programmatic);
916 void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)
918 Point p = e.Position;
919 TextPointSearchRange searchRange;
920 if (this.View.HitTextArea(p.X, p.Y))
921 searchRange = TextPointSearchRange.TextAreaOnly;
922 else if (this._Controller.SelectionLength > 0)
923 searchRange = TextPointSearchRange.Full;
926 TextPoint tp = this.View.GetTextPointFromPostion(p, searchRange);
927 this._Controller.MoveCaretAndSelect(tp);
928 if (this.peer != null)
929 this.peer.OnNotifyCaretChanged();
933 bool IsModiferKeyPressed(VirtualKey key)
935 CoreVirtualKeyStates state = Window.Current.CoreWindow.GetKeyState(key);
936 return (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
938 void Refresh(Rectangle updateRect)
940 if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0 || this.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
943 this.Render.DrawContent(this.View, this.IsEnabled, updateRect);
947 bool Resize(double width, double height)
949 if (width == 0 || height == 0)
950 throw new ArgumentOutOfRangeException();
951 if (this.Render.Resize(this.rectangle, width, height))
953 this.View.PageBound = new Rectangle(0, 0, width, height);
955 if (this.horizontalScrollBar != null)
957 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
958 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
960 if (this.verticalScrollBar != null)
962 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
963 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
970 void View_SrcChanged(object sender, EventArgs e)
972 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
974 EditView view = this.View;
975 if (view.Src.Row > this.verticalScrollBar.Maximum)
976 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
977 double absoulteX = Math.Abs(view.Src.X);
978 if (absoulteX > this.horizontalScrollBar.Maximum)
979 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
980 if (view.Src.Row != this.verticalScrollBar.Value)
981 this.verticalScrollBar.Value = view.Src.Row;
982 if (view.Src.X != this.horizontalScrollBar.Value)
983 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
986 void FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)
988 if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))
995 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
997 if (this.horizontalScrollBar == null)
1000 if (this.FlowDirection == FlowDirection.LeftToRight)
1001 toX = this.horizontalScrollBar.Value;
1003 toX = -this.horizontalScrollBar.Value;
1004 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
1008 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1010 if (this.verticalScrollBar == null)
1012 int newRow = (int)this.verticalScrollBar.Value;
1013 if (newRow >= this.View.LayoutLines.Count)
1015 this._Controller.Scroll(this.View.Src.X, newRow, false, false);
1019 void Document_Update(object sender, DocumentUpdateEventArgs e)
1021 if (this.textStore.IsLocked())
1023 if (e.type == UpdateType.Replace)
1024 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
1025 if(this.peer != null)
1026 this.peer.OnNotifyTextChanged();
1029 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1031 this.Focus(FocusState.Programmatic);
1034 void timer_Tick(object sender, object e)
1036 if (this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding())
1037 this.Refresh(this.View.PageBound);
1041 public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
1043 FooTextBox source = (FooTextBox)sender;
1044 if(e.Property.Equals(SelectedTextProperty) && !source.nowCaretMove)
1045 source._Controller.SelectedText = source.SelectedText;
1046 if(e.Property.Equals(HilighterProperty))
1047 source.View.Hilighter = source.Hilighter;
1048 if (e.Property.Equals(TextAntialiasModeProperty))
1049 source.Render.TextAntialiasMode = source.TextAntialiasMode;
1050 if (e.Property.Equals(FoldingStrategyProperty))
1051 source.View.LayoutLines.FoldingStrategy = source.FoldingStrategy;
1052 if (e.Property.Equals(IndentModeProperty))
1053 source.Controller.IndentMode = source.IndentMode;
1054 if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)
1055 source.Document.Select(source.Selection.Index,source.Selection.Length);
1056 if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)
1057 source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col);
1058 if (e.Property.Equals(InsertModeProperty))
1059 source.View.InsertMode = source.InsertMode;
1060 if (e.Property.Equals(TabCharsProperty))
1061 source.Document.TabStops = source.TabChars;
1062 if (e.Property.Equals(RectSelectModeProperty))
1063 source._Controller.RectSelection = source.RectSelectMode;
1064 if (e.Property.Equals(DrawCaretProperty))
1065 source.View.HideCaret = !source.DrawCaret;
1066 if (e.Property.Equals(DrawCaretLineProperty))
1067 source.View.HideLineMarker = !source.DrawCaretLine;
1068 if (e.Property.Equals(DrawLineNumberProperty))
1069 source.Document.DrawLineNumber = source.DrawLineNumber;
1070 if(e.Property.Equals(MagnificationPowerPropertyKey))
1071 source.Render.FontSize = source.FontSize * source.MagnificationPower;
1072 if (e.Property.Equals(FontFamilyProperty))
1073 source.Render.FontFamily = source.FontFamily;
1074 if (e.Property.Equals(FontStyleProperty))
1075 source.Render.FontStyle = source.FontStyle;
1076 if (e.Property.Equals(FontWeightProperty))
1077 source.Render.FontWeigth = source.FontWeight;
1078 if (e.Property.Equals(FontSizeProperty))
1079 source.Render.FontSize = source.FontSize;
1080 if (e.Property.Equals(ForegroundProperty))
1081 source.Render.Foreground = D2DRenderBase.ToColor4(source.Foreground);
1082 if (e.Property.Equals(BackgroundProperty))
1083 source.Render.Background = D2DRenderBase.ToColor4(source.Background);
1084 if (e.Property.Equals(ControlCharProperty))
1085 source.Render.ControlChar = D2DRenderBase.ToColor4(source.ControlChar);
1086 if (e.Property.Equals(HilightProperty))
1087 source.Render.Hilight = D2DRenderBase.ToColor4(source.Hilight);
1088 if (e.Property.Equals(Keyword1Property))
1089 source.Render.Keyword1 = D2DRenderBase.ToColor4(source.Keyword1);
1090 if (e.Property.Equals(Keyword2Property))
1091 source.Render.Keyword2 = D2DRenderBase.ToColor4(source.Keyword2);
1092 if (e.Property.Equals(CommentProperty))
1093 source.Render.Comment = D2DRenderBase.ToColor4(source.Comment);
1094 if (e.Property.Equals(LiteralProperty))
1095 source.Render.Literal = D2DRenderBase.ToColor4(source.Literal);
1096 if (e.Property.Equals(URLProperty))
1097 source.Render.Url = D2DRenderBase.ToColor4(source.URL);
1098 if (e.Property.Equals(InsertCaretProperty))
1099 source.Render.InsertCaret = D2DRenderBase.ToColor4(source.InsertCaret);
1100 if (e.Property.Equals(OverwriteCaretProperty))
1101 source.Render.OverwriteCaret = D2DRenderBase.ToColor4(source.OverwriteCaret);
1102 if (e.Property.Equals(PaddingProperty))
1103 source.View.Padding = new Padding((int)source.Padding.Left, (int)source.Padding.Top, (int)source.Padding.Right, (int)source.Padding.Bottom);
1104 if (e.Property.Equals(LineMarkerProperty))
1105 source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);
1106 if (e.Property.Equals(MarkURLProperty))
1107 source.Document.UrlMark = source.MarkURL;
1108 if (e.Property.Equals(ShowFullSpaceProperty))
1109 source.Render.ShowFullSpace = source.ShowFullSpace;
1110 if (e.Property.Equals(ShowHalfSpaceProperty))
1111 source.Render.ShowHalfSpace = source.ShowHalfSpace;
1112 if (e.Property.Equals(ShowTabProperty))
1113 source.Render.ShowTab = source.ShowTab;
1114 if (e.Property.Equals(ShowLineBreakProperty))
1115 source.Render.ShowLineBreak = source.ShowLineBreak;
1116 if (e.Property.Equals(LineBreakProperty))
1117 source.Document.LineBreak = source.LineBreakMethod;
1118 if (e.Property.Equals(LineBreakCharCountProperty))
1119 source.Document.LineBreakCharCount = source.LineBreakCharCount;
1120 if (e.Property.Equals(UpdateAreaProperty))
1121 source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);
1122 if (e.Property.Equals(LineNumberProperty))
1123 source.Render.LineNumber = D2DRenderBase.ToColor4(source.LineNumber);
1124 if (e.Property.Equals(FlowDirectionProperty))
1126 source.Document.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;
1127 if(source.horizontalScrollBar != null)
1128 source.horizontalScrollBar.FlowDirection = source.FlowDirection;
1130 if (e.Property.Equals(DrawRulerProperty))
1132 source.Document.HideRuler = !source.DrawRuler;
1133 source._Controller.JumpCaret(source.Document.CaretPostion.row, source.Document.CaretPostion.col);
1141 /// コンテキストメニューが表示されるときに呼び出されます
1143 public event EventHandler<FooContextMenuEventArgs> ContextMenuOpening;
1149 internal Controller Controller
1153 return this._Controller;
1158 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1160 public TextAntialiasMode TextAntialiasMode
1162 get { return (TextAntialiasMode)GetValue(TextAntialiasModeProperty); }
1163 set { SetValue(TextAntialiasModeProperty, value); }
1167 /// TextAntialiasModeの依存プロパティを表す
1169 public static readonly DependencyProperty TextAntialiasModeProperty =
1170 DependencyProperty.Register("TextAntialiasMode", typeof(TextAntialiasMode), typeof(FooTextBox), new PropertyMetadata(TextAntialiasMode.Default, OnPropertyChanged));
1175 public IHilighter Hilighter
1177 get { return (IHilighter)GetValue(HilighterProperty); }
1178 set { SetValue(HilighterProperty, value); }
1182 /// Hilighterの依存プロパティを表す
1184 public static readonly DependencyProperty HilighterProperty =
1185 DependencyProperty.Register("Hilighter", typeof(IHilighter), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
1188 /// フォールティングを作成するインターフェイスを表す
1190 public IFoldingStrategy FoldingStrategy
1192 get { return (IFoldingStrategy)GetValue(FoldingStrategyProperty); }
1193 set { SetValue(FoldingStrategyProperty, value); }
1197 /// FoldingStrategyの依存プロパティ
1199 public static readonly DependencyProperty FoldingStrategyProperty =
1200 DependencyProperty.Register("FoldingStrategy", typeof(IFoldingStrategy), typeof(FooTextBox), new PropertyMetadata(null,OnPropertyChanged));
1205 public MarkerPatternSet MarkerPatternSet
1209 return this.Document.MarkerPatternSet;
1216 public Document Document
1220 return this._Document;
1224 Document old_doc = this._Document;
1226 if (this._Document != null)
1228 old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
1229 old_doc.LoadProgress -= _Document_LoadProgress;
1230 oldLength = old_doc.Length;
1233 this._Document = value;
1234 this._Document.LayoutLines.Render = this.Render;
1235 this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
1236 this._Document.LoadProgress += _Document_LoadProgress;
1237 //初期化が終わっていればすべて存在する
1238 if (this.Controller != null && this.View != null && this.textStore != null)
1240 this.Controller.Document = value;
1241 this.View.Document = value;
1242 this.Controller.AdjustCaret();
1243 this.textStore.NotifyTextChanged(oldLength, value.Length);
1245 //依存プロパティとドキュメント内容が食い違っているので再設定する
1246 this.ShowFullSpace = value.ShowFullSpace;
1247 this.ShowHalfSpace = value.ShowHalfSpace;
1248 this.ShowLineBreak = value.ShowLineBreak;
1249 this.ShowTab = value.ShowTab;
1250 this.FlowDirection = value.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
1251 this.IndentMode = value.IndentMode;
1252 this.DrawCaretLine = !value.HideLineMarker;
1253 this.InsertMode = value.InsertMode;
1254 this.DrawRuler = !value.HideRuler;
1255 this.DrawLineNumber = value.DrawLineNumber;
1256 this.MarkURL = value.UrlMark;
1257 this.LineBreakMethod = value.LineBreak;
1258 this.LineBreakCharCount = value.LineBreakCharCount;
1259 this.TabChars = value.TabStops;
1266 private void _Document_LoadProgress(object sender, ProgressEventArgs e)
1268 if(e.state == ProgressState.Start)
1269 this.IsEnabled = false;
1270 else if(e.state == ProgressState.Complete)
1272 TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
1273 if (this.verticalScrollBar != null)
1274 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
1275 this.View.CalculateLineCountOnScreen();
1276 this.IsEnabled = true;
1283 public LineToIndexTable LayoutLineCollection
1285 get { return this.View.LayoutLines; }
1291 public string SelectedText
1293 get { return (string)GetValue(SelectedTextProperty); }
1294 set { SetValue(SelectedTextProperty, value); }
1298 /// SelectedTextの依存プロパティを表す
1300 public static readonly DependencyProperty SelectedTextProperty =
1301 DependencyProperty.Register("SelectedText", typeof(string), typeof(FooTextBox), new PropertyMetadata(null, OnPropertyChanged));
1306 public IndentMode IndentMode
1308 get { return (IndentMode)GetValue(IndentModeProperty); }
1309 set { SetValue(IndentModeProperty, value); }
1313 /// IndentModeの依存プロパティを表す
1315 public static readonly DependencyProperty IndentModeProperty =
1316 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab,OnPropertyChanged));
1322 /// Lengthが0の場合はキャレット位置を表します。
1323 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1325 public TextRange Selection
1327 get { return (TextRange)GetValue(SelectionProperty); }
1328 set { SetValue(SelectionProperty, value); }
1332 /// Selectionの依存プロパティを表す
1334 public static readonly DependencyProperty SelectionProperty =
1335 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null, OnPropertyChanged));
1340 public double MagnificationPower
1342 get { return (double)GetValue(MagnificationPowerPropertyKey); }
1343 set { SetValue(MagnificationPowerPropertyKey, value); }
1349 public static readonly DependencyProperty MagnificationPowerPropertyKey =
1350 DependencyProperty.Register("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0, OnPropertyChanged));
1355 public TextPoint CaretPostion
1357 get { return (TextPoint)GetValue(CaretPostionPropertyKey); }
1358 set { SetValue(CaretPostionPropertyKey, value); }
1361 static readonly DependencyProperty CaretPostionPropertyKey =
1362 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(new TextPoint(), OnPropertyChanged));
1367 public new FlowDirection FlowDirection
1369 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1370 set { SetValue(FlowDirectionProperty, value); }
1374 /// レタリング方向を表す。これは依存プロパティです
1376 public new static readonly DependencyProperty FlowDirectionProperty =
1377 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight,OnPropertyChanged));
1382 public new FontFamily FontFamily
1384 get { return (FontFamily)GetValue(FontFamilyProperty); }
1385 set { SetValue(FontFamilyProperty, value); }
1389 /// FontFamilyの依存プロパティを表す
1391 public new static readonly DependencyProperty FontFamilyProperty =
1392 DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(FooTextBox), new PropertyMetadata(new FontFamily("Cambria"), OnPropertyChanged));
1397 public new double FontSize
1399 get { return (double)GetValue(FontSizeProperty); }
1400 set { SetValue(FontSizeProperty, value); }
1404 /// FontSizeの依存プロパティを表す
1406 public new static readonly DependencyProperty FontSizeProperty =
1407 DependencyProperty.Register("FontSize", typeof(double), typeof(FooTextBox), new PropertyMetadata(12.0,OnPropertyChanged));
1412 public new FontStyle FontStyle
1414 get { return (FontStyle)GetValue(FontStyleProperty); }
1415 set { SetValue(FontStyleProperty, value); }
1419 /// FontStyleの依存プロパティを表す
1421 public new static readonly DependencyProperty FontStyleProperty =
1422 DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(FooTextBox), new PropertyMetadata(FontStyle.Normal,OnPropertyChanged));
1427 public new FontWeight FontWeight
1429 get { return (FontWeight)GetValue(FontWeightProperty); }
1430 set { SetValue(FontWeightProperty, value); }
1434 /// FontWeigthの依存プロパティを表す
1436 public new static readonly DependencyProperty FontWeightProperty =
1437 DependencyProperty.Register("FontWeigth", typeof(FontWeight), typeof(FooTextBox), new PropertyMetadata(FontWeights.Normal,OnPropertyChanged));
1440 /// デフォルトの文字色を表す。これは依存プロパティです
1442 public new Windows.UI.Color Foreground
1444 get { return (Windows.UI.Color)GetValue(ForegroundProperty); }
1445 set { SetValue(ForegroundProperty, value); }
1449 /// Foregroundの依存プロパティを表す
1451 public new static readonly DependencyProperty ForegroundProperty =
1452 DependencyProperty.Register("Foreground", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1455 /// 背景色を表す。これは依存プロパティです
1457 public new Windows.UI.Color Background
1459 get { return (Windows.UI.Color)GetValue(BackgroundProperty); }
1460 set { SetValue(BackgroundProperty, value); }
1464 /// Backgroundの依存プロパティを表す
1466 public new static readonly DependencyProperty BackgroundProperty =
1467 DependencyProperty.Register("Background", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));
1470 /// コントロールコードの文字色を表す。これは依存プロパティです
1472 public Windows.UI.Color ControlChar
1474 get { return (Windows.UI.Color)GetValue(ControlCharProperty); }
1475 set { SetValue(ControlCharProperty, value); }
1479 /// ControlCharの依存プロパティを表す
1481 public static readonly DependencyProperty ControlCharProperty =
1482 DependencyProperty.Register("ControlChar", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1485 /// 選択時の背景色を表す。これは依存プロパティです
1487 public Windows.UI.Color Hilight
1489 get { return (Windows.UI.Color)GetValue(HilightProperty); }
1490 set { SetValue(HilightProperty, value); }
1494 /// Hilightの依存プロパティを表す
1496 public static readonly DependencyProperty HilightProperty =
1497 DependencyProperty.Register("Hilight", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DeepSkyBlue, OnPropertyChanged));
1500 /// キーワード1の文字色を表す。これは依存プロパティです
1502 public Windows.UI.Color Keyword1
1504 get { return (Windows.UI.Color)GetValue(Keyword1Property); }
1505 set { SetValue(Keyword1Property, value); }
1509 /// Keyword1の依存プロパティを表す
1511 public static readonly DependencyProperty Keyword1Property =
1512 DependencyProperty.Register("Keyword1", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1515 /// キーワード2の文字色を表す。これは依存プロパティです
1517 public Windows.UI.Color Keyword2
1519 get { return (Windows.UI.Color)GetValue(Keyword2Property); }
1520 set { SetValue(Keyword2Property, value); }
1524 /// Keyword2の依存プロパティを表す
1526 public static readonly DependencyProperty Keyword2Property =
1527 DependencyProperty.Register("Keyword2", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DarkCyan, OnPropertyChanged));
1530 /// コメントの文字色を表す。これは依存プロパティです
1532 public Windows.UI.Color Comment
1534 get { return (Windows.UI.Color)GetValue(CommentProperty); }
1535 set { SetValue(CommentProperty, value); }
1539 /// Commentの依存プロパティを表す
1541 public static readonly DependencyProperty CommentProperty =
1542 DependencyProperty.Register("Comment", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Green, OnPropertyChanged));
1545 /// 文字リテラルの文字色を表す。これは依存プロパティです
1547 public Windows.UI.Color Literal
1549 get { return (Windows.UI.Color)GetValue(LiteralProperty); }
1550 set { SetValue(LiteralProperty, value); }
1554 /// Literalの依存プロパティを表す
1556 public static readonly DependencyProperty LiteralProperty =
1557 DependencyProperty.Register("Literal", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Brown, OnPropertyChanged));
1560 /// URLの文字色を表す。これは依存プロパティです
1562 public Windows.UI.Color URL
1564 get { return (Windows.UI.Color)GetValue(URLProperty); }
1565 set { SetValue(URLProperty, value); }
1571 public static readonly DependencyProperty URLProperty =
1572 DependencyProperty.Register("URL", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1577 public Windows.UI.Color UpdateArea
1579 get { return (Windows.UI.Color)GetValue(UpdateAreaProperty); }
1580 set { SetValue(UpdateAreaProperty, value); }
1584 /// UpdateAreaの依存プロパティを表す
1586 public static readonly DependencyProperty UpdateAreaProperty =
1587 DependencyProperty.Register("UpdateArea", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen, OnPropertyChanged));
1592 public Windows.UI.Color LineMarker
1594 get { return (Windows.UI.Color)GetValue(LineMarkerProperty); }
1595 set { SetValue(LineMarkerProperty, value); }
1599 /// LineMarkerの依存プロパティを表す
1601 public static readonly DependencyProperty LineMarkerProperty =
1602 DependencyProperty.Register("LineMarker", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1605 /// 挿入モード時のキャレットの色を表す
1607 public Windows.UI.Color InsertCaret
1609 get { return (Windows.UI.Color)GetValue(InsertCaretProperty); }
1610 set { SetValue(InsertCaretProperty, value); }
1614 /// InsertCaretの依存プロパティを表す
1616 public static readonly DependencyProperty InsertCaretProperty =
1617 DependencyProperty.Register("InsertCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1620 /// 上書きモード時のキャレット職を表す
1622 public Windows.UI.Color OverwriteCaret
1624 get { return (Windows.UI.Color)GetValue(OverwriteCaretProperty); }
1625 set { SetValue(OverwriteCaretProperty, value); }
1629 /// OverwriteCaretの依存プロパティを表す
1631 public static readonly DependencyProperty OverwriteCaretProperty =
1632 DependencyProperty.Register("OverwriteCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1637 public Windows.UI.Color LineNumber
1639 get { return (Windows.UI.Color)GetValue(LineNumberProperty); }
1640 set { SetValue(LineNumberProperty, value); }
1644 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1646 public static readonly DependencyProperty LineNumberProperty =
1647 DependencyProperty.Register("LineNumber", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray,OnPropertyChanged));
1652 public new Thickness Padding
1654 get { return (Thickness)GetValue(PaddingProperty); }
1655 set { SetValue(PaddingProperty, value); }
1659 /// Paddingの依存プロパティを表す
1661 public new static readonly DependencyProperty PaddingProperty =
1662 DependencyProperty.Register("Padding", typeof(Thickness), typeof(FooTextBox), new PropertyMetadata(new Thickness(),OnPropertyChanged));
1665 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1667 public bool InsertMode
1669 get { return (bool)GetValue(InsertModeProperty); }
1670 set { SetValue(InsertModeProperty, value); }
1674 /// InsertModeの依存プロパティを表す
1676 public static readonly DependencyProperty InsertModeProperty =
1677 DependencyProperty.Register("InsertMode",
1680 new PropertyMetadata(true, OnPropertyChanged));
1683 /// タブの文字数を表す。これは依存プロパティです
1687 get { return (int)GetValue(TabCharsProperty); }
1688 set { SetValue(TabCharsProperty, value); }
1692 /// TabCharsの依存プロパティを表す
1694 public static readonly DependencyProperty TabCharsProperty =
1695 DependencyProperty.Register("TabChars",
1698 new PropertyMetadata(4, OnPropertyChanged));
1701 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1703 public bool RectSelectMode
1705 get { return (bool)GetValue(RectSelectModeProperty); }
1706 set { SetValue(RectSelectModeProperty, value); }
1710 /// RectSelectModeの依存プロパティを表す
1712 public static readonly DependencyProperty RectSelectModeProperty =
1713 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1719 /// 変更した場合、レイアウトの再構築を行う必要があります
1721 public LineBreakMethod LineBreakMethod
1723 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1724 set { SetValue(LineBreakProperty, value); }
1728 /// LineBreakMethodの依存プロパティを表す
1730 public static readonly DependencyProperty LineBreakProperty =
1731 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None, OnPropertyChanged));
1735 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1738 /// 変更した場合、レイアウトの再構築を行う必要があります
1740 public int LineBreakCharCount
1742 get { return (int)GetValue(LineBreakCharCountProperty); }
1743 set { SetValue(LineBreakCharCountProperty, value); }
1747 /// LineBreakCharCountの依存プロパティを表す
1749 public static readonly DependencyProperty LineBreakCharCountProperty =
1750 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80, OnPropertyChanged));
1753 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1755 public bool DrawCaret
1757 get { return (bool)GetValue(DrawCaretProperty); }
1758 set { SetValue(DrawCaretProperty, value); }
1762 /// DrawCaretの依存プロパティを表す
1764 public static readonly DependencyProperty DrawCaretProperty =
1765 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new PropertyMetadata(true, OnPropertyChanged));
1769 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1771 public bool DrawCaretLine
1773 get { return (bool)GetValue(DrawCaretLineProperty); }
1774 set { SetValue(DrawCaretLineProperty, value); }
1778 /// DrawCaretLineの依存プロパティを表す
1780 public static readonly DependencyProperty DrawCaretLineProperty =
1781 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1784 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
1786 public bool DrawLineNumber
1788 get { return (bool)GetValue(DrawLineNumberProperty); }
1789 set { SetValue(DrawLineNumberProperty, value); }
1793 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
1795 public bool DrawRuler
1797 get { return (bool)GetValue(DrawRulerProperty); }
1798 set { SetValue(DrawRulerProperty, value); }
1802 /// DrawRulerの依存プロパティを表す
1804 public static readonly DependencyProperty DrawRulerProperty =
1805 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1809 /// DrawLineNumberの依存プロパティを表す
1811 public static readonly DependencyProperty DrawLineNumberProperty =
1812 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1815 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
1819 get { return (bool)GetValue(MarkURLProperty); }
1820 set { SetValue(MarkURLProperty, value); }
1824 /// MarkURLの依存プロパティを表す
1826 public static readonly DependencyProperty MarkURLProperty =
1827 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1830 /// 全角スペースを表示するなら真。そうでないなら偽
1832 public bool ShowFullSpace
1834 get { return (bool)GetValue(ShowFullSpaceProperty); }
1835 set { SetValue(ShowFullSpaceProperty, value); }
1839 /// ShowFullSpaceの依存プロパティを表す
1841 public static readonly DependencyProperty ShowFullSpaceProperty =
1842 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1845 /// 半角スペースを表示するなら真。そうでないなら偽
1847 public bool ShowHalfSpace
1849 get { return (bool)GetValue(ShowHalfSpaceProperty); }
1850 set { SetValue(ShowHalfSpaceProperty, value); }
1854 /// ShowHalfSpaceの依存プロパティを表す
1856 public static readonly DependencyProperty ShowHalfSpaceProperty =
1857 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1860 /// タブを表示するなら真。そうでないなら偽
1864 get { return (bool)GetValue(ShowTabProperty); }
1865 set { SetValue(ShowTabProperty, value); }
1869 /// ShowTabの依存プロパティを表す
1871 public static readonly DependencyProperty ShowTabProperty =
1872 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1875 /// 改行マークを表示するなら真。そうでないなら偽
1877 public bool ShowLineBreak
1879 get { return (bool)GetValue(ShowLineBreakProperty); }
1880 set { SetValue(ShowLineBreakProperty, value); }
1884 /// ShowLineBreakの依存プロパティを表す
1886 public static readonly DependencyProperty ShowLineBreakProperty =
1887 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false,OnPropertyChanged));
1894 /// コンテキストメニューのイベントデーターを表す
1896 public class FooContextMenuEventArgs
1899 /// 処理済みなら真。そうでないなら偽
1901 public bool Handled = false;
1903 /// コンテキストメニューを表示すべき座標を表す
1905 public Windows.Foundation.Point Postion;
1909 /// <param name="pos"></param>
1910 public FooContextMenuEventArgs(Windows.Foundation.Point pos)