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, GripperView.HitAreaWidth, GripperView.HitAreaWidth / 2, GripperView.HitAreaWidth));
83 this.View.SrcChanged += View_SrcChanged;
84 this.View.InsertMode = this.InsertMode;
85 this.View.DrawLineNumber = this.DrawLineNumber;
86 this.View.HideCaret = !this.DrawCaret;
87 this.View.HideLineMarker = !this.DrawCaretLine;
88 this.View.HideRuler = !this.DrawRuler;
89 this.View.UrlMark = this.MarkURL;
90 this.View.TabStops = this.TabChars;
92 this._Controller = new Controller(this.Document, this.View);
93 this._Controller.SelectionChanged += Controller_SelectionChanged;
95 this.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);
117 //Viewの初期化が終わった直後に置かないと例外が発生する
118 this.Document.Update += Document_Update;
120 Window.Current.CoreWindow.CharacterReceived += CoreWindow_CharacterReceived;
122 this.SizeChanged += FooTextBox_SizeChanged;
124 this.Loaded += FooTextBox_Loaded;
138 public void Dispose()
141 GC.SuppressFinalize(this);
144 bool Disposed = false;
145 private void Dispose(bool disposing)
151 this.textStore.Dispose();
153 this.Render.Dispose();
160 /// <param name="start">開始インデックス</param>
161 /// <param name="length">長さ</param>
162 public void Select(int start, int length)
164 this._Controller.Select(start, length);
168 /// キャレットを指定した行に移動させます
170 /// <param name="index">インデックス</param>
171 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
172 public void JumpCaret(int index)
174 this._Controller.JumpCaret(index);
177 /// キャレットを指定した行と桁に移動させます
179 /// <param name="row">行番号</param>
180 /// <param name="col">桁</param>
181 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
182 public void JumpCaret(int row, int col)
184 this._Controller.JumpCaret(row, col);
188 /// 選択中のテキストをクリップボードにコピーします
192 string text = this._Controller.SelectedText;
193 if (text != null && text != string.Empty)
195 DataPackage dataPackage = new DataPackage();
196 dataPackage.RequestedOperation = DataPackageOperation.Copy;
197 dataPackage.SetText(text);
199 Clipboard.SetContent(dataPackage);
204 /// 選択中のテキストをクリップボードに切り取ります
208 string text = this._Controller.SelectedText;
209 if (text != null && text != string.Empty)
211 DataPackage dataPackage = new DataPackage();
212 dataPackage.RequestedOperation = DataPackageOperation.Copy;
213 dataPackage.SetText(text);
215 Clipboard.SetContent(dataPackage);
217 this._Controller.SelectedText = "";
224 public async Task PasteAsync()
226 var dataPackageView = Clipboard.GetContent();
227 if (dataPackageView.Contains(StandardDataFormats.Text))
229 this._Controller.SelectedText = await dataPackageView.GetTextAsync();
236 public void SelectAll()
238 this._Controller.Select(0, this.Document.Length);
244 public void DeSelectAll()
246 this._Controller.DeSelectAll();
252 /// <param name="tp">テキストポイント</param>
253 /// <returns>座標</returns>
254 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
255 public Windows.Foundation.Point GetPostionFromTextPoint(TextPoint tp)
257 if (this.Document.FireUpdateEvent == false)
258 throw new InvalidOperationException("");
259 return this.View.GetPostionFromTextPoint(tp);
263 /// 対応するテキストポイントを返します
265 /// <param name="p">クライアント領域の原点を左上とする座標</param>
266 /// <returns>テキストポイント</returns>
267 public TextPoint GetTextPointFromPostion(Windows.Foundation.Point p)
269 if (this.Document.FireUpdateEvent == false)
270 throw new InvalidOperationException("");
271 return this.View.GetTextPointFromPostion(p);
277 /// <param name="row">レイアウト行</param>
278 /// <returns>行の高さ</returns>
279 public double GetLineHeight(int row)
281 if (this.Document.FireUpdateEvent == false)
282 throw new InvalidOperationException("");
283 return this.View.LayoutLines.GetLayout(row).Height; ;
287 /// インデックスに対応する座標を得ます
289 /// <param name="index">インデックス</param>
290 /// <returns>座標を返す</returns>
291 public Windows.Foundation.Point GetPostionFromIndex(int index)
293 if (this.Document.FireUpdateEvent == false)
294 throw new InvalidOperationException("");
295 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
296 return this.View.GetPostionFromTextPoint(tp);
302 /// <param name="p">座標</param>
303 /// <returns>インデックスを返す</returns>
304 public int GetIndexFromPostion(Windows.Foundation.Point p)
306 if (this.Document.FireUpdateEvent == false)
307 throw new InvalidOperationException("");
308 TextPoint tp = this.View.GetTextPointFromPostion(p);
309 return this.View.GetIndexFromLayoutLine(tp);
315 public void Refresh()
317 this.Refresh(this.View.PageBound);
321 /// レイアウト行をすべて破棄し、再度レイアウトを行う
323 public void PerfomLayouts()
325 this.View.PerfomLayouts();
331 /// <param name="row">行</param>
332 /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
333 public void ScrollIntoView(int row, bool alignTop)
335 this.View.ScrollIntoView(row, alignTop);
339 /// ファイルからドキュメントを構築する
341 /// <param name="sr">StremReader</param>
342 /// <returns>Taskオブジェクト</returns>
343 public async Task LoadFileAsync(System.IO.StreamReader sr, System.Threading.CancellationTokenSource token)
345 this.IsEnabled = false;
346 this.View.LayoutLines.IsFrozneDirtyFlag = true;
347 WinFileReader fs = new WinFileReader(sr);
348 await this.Document.LoadAsync(fs, token);
349 this.View.LayoutLines.IsFrozneDirtyFlag = false;
350 TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
351 if (this.verticalScrollBar != null)
352 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
353 this.View.CalculateLineCountOnScreen();
354 this.IsEnabled = true;
358 /// ドキュメントの内容をファイルに保存する
360 /// <param name="sw">StreamWriter</param>
361 /// <param name="enc">エンコード</param>
362 /// <returns>Taskオブジェクト</returns>
363 public async Task SaveFile(System.IO.StreamWriter sw, System.Threading.CancellationTokenSource token)
365 WinFileWriter fs = new WinFileWriter(sw);
366 await this.Document.SaveAsync(fs, token);
381 async Task PasteCommand()
383 await this.PasteAsync();
391 protected override Windows.UI.Xaml.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
393 this.peer = new FooTextBoxAutomationPeer(this);
398 protected override void OnApplyTemplate()
400 base.OnApplyTemplate();
402 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
405 Grid.SetRow(this.rectangle, 0);
406 Grid.SetColumn(this.rectangle, 0);
407 grid.Children.Add(this.rectangle);
410 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
411 if (this.horizontalScrollBar != null)
413 this.horizontalScrollBar.SmallChange = 10;
414 this.horizontalScrollBar.LargeChange = 100;
415 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
416 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
418 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
419 if (this.verticalScrollBar != null)
421 this.verticalScrollBar.SmallChange = 1;
422 this.verticalScrollBar.LargeChange = 10;
423 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
424 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
429 protected override void OnGotFocus(RoutedEventArgs e)
432 this.textStore.SetFocus();
433 this.View.IsFocused = true;
438 protected override void OnLostFocus(RoutedEventArgs e)
441 this.View.IsFocused = false;
446 protected override async void OnKeyDown(KeyRoutedEventArgs e)
448 bool isControlPressed = this.IsModiferKeyPressed(VirtualKey.Control);
449 bool isShiftPressed = this.IsModiferKeyPressed(VirtualKey.Shift);
450 bool isMovedCaret = false;
454 this._Controller.MoveCaretVertical(-1, isShiftPressed);
459 case VirtualKey.Down:
460 this._Controller.MoveCaretVertical(+1, isShiftPressed);
465 case VirtualKey.Left:
466 this._Controller.MoveCaretHorizontical(-1, isShiftPressed, isControlPressed);
471 case VirtualKey.Right:
472 this._Controller.MoveCaretHorizontical(1, isShiftPressed, isControlPressed);
477 case VirtualKey.PageUp:
478 this._Controller.Scroll(ScrollDirection.Up, this.View.LineCountOnScreen, isShiftPressed, true);
482 case VirtualKey.PageDown:
483 this._Controller.Scroll(ScrollDirection.Down, this.View.LineCountOnScreen, isShiftPressed, true);
487 case VirtualKey.Home:
488 if (isControlPressed)
489 this._Controller.JumpToHead(isShiftPressed);
491 this.Controller.JumpToLineHead(this.View.CaretPostion.row,isShiftPressed);
496 if (isControlPressed)
497 this._Controller.JumpToEnd(isShiftPressed);
499 this.Controller.JumpToLineEnd(this.View.CaretPostion.row,isShiftPressed);
504 if (!isControlPressed)
506 if (this._Controller.SelectionLength == 0)
507 this._Controller.DoInputChar('\t');
508 else if (isShiftPressed)
509 this._Controller.DownIndent();
511 this._Controller.UpIndent();
516 case VirtualKey.Enter:
517 this._Controller.DoEnterAction();
521 case VirtualKey.Insert:
522 if(this.View.InsertMode)
523 this.View.InsertMode = false;
525 this.View.InsertMode = true;
530 if (isControlPressed)
538 if (isControlPressed)
540 if (this._Controller.RectSelection)
541 this._Controller.RectSelection = false;
543 this._Controller.RectSelection = true;
549 if (isControlPressed)
556 if (isControlPressed)
563 if (isControlPressed)
565 await this.PasteCommand();
570 if (isControlPressed)
572 this.Document.UndoManager.redo();
578 if (isControlPressed)
580 this.Document.UndoManager.undo();
585 case VirtualKey.Back:
586 this._Controller.DoBackSpaceAction();
590 case VirtualKey.Delete:
591 this._Controller.DoDeleteAction();
596 if (isMovedCaret && this.peer != null)
597 this.peer.OnNotifyCaretChanged();
602 protected override void OnPointerPressed(PointerRoutedEventArgs e)
605 this.gestureRecongnizer.AutoProcessInertia = e.Pointer.PointerDeviceType != PointerDeviceType.Mouse;
607 this.CapturePointer(e.Pointer);
608 this.gestureRecongnizer.ProcessDownEvent(e.GetCurrentPoint(this));
613 protected override void OnPointerMoved(PointerRoutedEventArgs e)
616 this.gestureRecongnizer.AutoProcessInertia = e.Pointer.PointerDeviceType != PointerDeviceType.Mouse;
618 this.gestureRecongnizer.ProcessMoveEvents(e.GetIntermediatePoints(this));
621 if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
623 Point p = e.GetCurrentPoint(this).Position;
624 if (this.View.HitTextArea(p.X, p.Y))
626 TextPoint tp = this.View.GetTextPointFromPostion(p);
627 if (this._Controller.IsMarker(tp, HilightType.Url))
628 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Hand, 101);
630 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.IBeam, 101);
634 Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 101);
640 protected override void OnPointerReleased(PointerRoutedEventArgs e)
642 this.gestureRecongnizer.ProcessUpEvent(e.GetCurrentPoint(this));
643 this.ReleasePointerCapture(e.Pointer);
648 protected override void OnPointerCanceled(PointerRoutedEventArgs e)
650 this.gestureRecongnizer.CompleteGesture();
651 this.ReleasePointerCapture(e.Pointer);
656 protected override void OnPointerCaptureLost(PointerRoutedEventArgs e)
658 this.gestureRecongnizer.CompleteGesture();
659 this.ReleasePointerCapture(e.Pointer);
664 protected override void OnPointerWheelChanged(PointerRoutedEventArgs e)
667 this.gestureRecongnizer.AutoProcessInertia = e.Pointer.PointerDeviceType != PointerDeviceType.Mouse;
669 bool shift = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Shift) ==
670 Windows.System.VirtualKeyModifiers.Shift;
671 bool ctrl = (e.KeyModifiers & Windows.System.VirtualKeyModifiers.Control) ==
672 Windows.System.VirtualKeyModifiers.Control;
673 this.gestureRecongnizer.ProcessMouseWheelEvent(e.GetCurrentPoint(this), shift, ctrl);
677 void CoreWindow_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)
679 if (this.FocusState == FocusState.Unfocused || !this.IsEnabled)
681 if (args.KeyCode >= 00 && args.KeyCode <= 0x1f)
683 this._Controller.DoInputString(Char.ConvertFromUtf32((int)args.KeyCode));
687 bool textStore_IsReadOnly()
692 bool textStore_IsLoading()
697 void textStore_CompositionEnded()
699 TextStoreHelper.EndCompostion(this.Document);
703 void textStore_CompositionUpdated(int start, int end)
705 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
708 bool textStore_CompositionStarted()
710 return TextStoreHelper.StartCompstion(this.Document);
713 string _textStore_GetString(int start, int length)
715 return this.Document.ToString(start, length);
718 void _textStore_GetStringExtent(
722 out POINT o_bottomRight
725 Point startPos, endPos;
726 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
729 this.Render.GetDpi(out dpi, out dpi);
730 double scale = dpi / 96.0;
732 var gt = this.TransformToVisual(Window.Current.Content);
733 startPos = gt.TransformPoint(startPos.Scale(scale));
734 endPos = gt.TransformPoint(endPos.Scale(scale));
736 o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);
737 o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);
740 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
742 var pointTopLeft = new Point(0, 0);
743 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
745 var gt = this.TransformToVisual(Window.Current.Content);
746 pointTopLeft = gt.TransformPoint(pointTopLeft);
747 pointBottomRight = gt.TransformPoint(pointBottomRight);
749 o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
750 o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
753 void _textStore_GetSelectionIndex(out int o_startIndex, out int o_endIndex)
755 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out o_startIndex, out o_endIndex);
758 void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)
760 TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);
764 void _textStore_InsertAtSelection(string i_value,ref int o_stratIndex,ref int o_endIndex)
766 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
770 void Controller_SelectionChanged(object sender, EventArgs e)
773 this.nowCaretMove = true;
774 SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
775 SetValue(CaretPostionPropertyKey, this.View.CaretPostion);
776 this.nowCaretMove = false;
777 this.View.SelectGrippers.BottomLeft.MoveByIndex(this.View, this.Controller.SelectionStart);
778 this.View.SelectGrippers.BottomRight.MoveByIndex(this.View, this.Controller.SelectionStart + this.Controller.SelectionLength);
779 if (this.textStore.IsLocked() == false)
780 this.textStore.NotifySelectionChanged();
783 private void gestureRecongnizer_ManipulationInertiaStarting(GestureRecognizer sender, ManipulationInertiaStartingEventArgs e)
785 //sender.InertiaTranslationDeceleration = 0.001f;
786 //sender.InertiaExpansionDeceleration = 100.0f * 96.0f / 1000.0f;
787 //sender.InertiaRotationDeceleration = 720.0f / (1000.0f * 1000.0f);
790 GripperView hittedGripper;
791 void gestureRecongnizer_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs e)
793 //Updateedの段階でヒットテストしてしまうとグリッパーを触ってもヒットしないことがある
794 this.hittedGripper = this.View.HitGripperFromPoint(e.Position);
797 const int WheelNoti = 120;
798 const int WheelScrollLines = 3;
799 double TotalWheelCount = 0;
801 void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)
803 if (this._Controller.MoveCaretAndGripper(e.Position, this.hittedGripper))
805 if (this.peer != null)
806 this.peer.OnNotifyCaretChanged();
811 if (e.Delta.Scale < 1)
813 double newSize = this.Render.FontSize - 1;
816 this.Render.FontSize = newSize;
818 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
822 if (e.Delta.Scale > 1)
824 double newSize = this.Render.FontSize + 1;
827 this.Render.FontSize = newSize;
829 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
833 Point translation = e.Delta.Translation;
835 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
836 if (Math.Abs(e.Cumulative.Translation.X) < Math.Abs(e.Cumulative.Translation.Y))
839 if (e.PointerDeviceType == PointerDeviceType.Mouse) {
840 //テキストボックスはWheelNotiごとにWheelScrollLinesずつスクロールするらしい
841 scrollCount = (int)Math.Abs(this.TotalWheelCount / WheelNoti * WheelScrollLines);
844 else if (scrollCount > WheelScrollLines)
845 scrollCount = WheelScrollLines;
846 if (this.TotalWheelCount >= WheelNoti) //0にすると違和感を感じる
847 this.TotalWheelCount = this.TotalWheelCount % WheelNoti;
848 this.TotalWheelCount += Math.Abs(translation.Y);
852 scrollCount = (int)Math.Abs(translation.Y + 0.5);
855 if (translation.Y > 0)
856 this._Controller.Scroll(ScrollDirection.Up, scrollCount, false, false);
858 this._Controller.Scroll(ScrollDirection.Down, scrollCount, false, false);
859 this.View.SelectGrippers.BottomLeft.Enabled = false;
860 this.View.SelectGrippers.BottomRight.Enabled = false;
865 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
868 if (translation.X < 0)
869 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
871 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
872 this.View.SelectGrippers.BottomLeft.Enabled = false;
873 this.View.SelectGrippers.BottomRight.Enabled = false;
878 void gestureRecongnizer_ManipulationCompleted(GestureRecognizer sender, ManipulationCompletedEventArgs e)
882 async void gestureRecongnizer_RightTapped(GestureRecognizer sender, RightTappedEventArgs e)
884 ResourceMap map = ResourceManager.Current.MainResourceMap.GetSubtree("FooEditEngine.Metro/Resources");
885 ResourceContext context = ResourceContext.GetForCurrentView();
886 if (this.View.HitTextArea(e.Position.X, e.Position.Y))
888 FooContextMenuEventArgs args = new FooContextMenuEventArgs(e.Position);
889 if (this.ContextMenuOpening != null)
890 this.ContextMenuOpening(this, args);
893 PopupMenu ContextMenu = new PopupMenu();
894 ContextMenu.Commands.Add(new UICommand(map.GetValue("CopyMenuName", context).ValueAsString, (command) =>
898 ContextMenu.Commands.Add(new UICommand(map.GetValue("CutMenuName", context).ValueAsString, (command) =>
902 ContextMenu.Commands.Add(new UICommand(map.GetValue("PasteMenuName", context).ValueAsString, async (command) =>
904 await this.PasteCommand();
906 if (this._Controller.RectSelection)
908 ContextMenu.Commands.Add(new UICommand(map.GetValue("LineSelectMenuName", context).ValueAsString, (command) =>
910 this._Controller.RectSelection = false;
915 ContextMenu.Commands.Add(new UICommand(map.GetValue("RectSelectMenuName", context).ValueAsString, (command) =>
917 this._Controller.RectSelection = true;
920 await ContextMenu.ShowAsync(Util.GetScreentPoint(e.Position,this));
925 void gestureRecongnizer_Tapped(GestureRecognizer sender, TappedEventArgs e)
927 bool touched = e.PointerDeviceType == PointerDeviceType.Touch;
928 this.View.SelectGrippers.BottomLeft.Enabled = false;
929 this.View.SelectGrippers.BottomRight.Enabled = touched;
930 this.JumpCaret(e.Position);
931 System.Diagnostics.Debug.WriteLine(e.TapCount);
934 this.View.SelectGrippers.BottomLeft.Enabled = touched;
935 //タッチスクリーンでダブルタップした場合、アンカーインデックスを単語の先頭にしないとバグる
936 this.Controller.SelectWord(this.Controller.SelectionStart, touched);
940 void JumpCaret(Point p)
942 TextPoint tp = this.View.GetTextPointFromPostion(p);
943 if (tp == TextPoint.Null)
946 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
948 FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
949 if (foldingData != null)
951 if (foldingData.Expand)
952 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
954 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
955 this._Controller.JumpCaret(foldingData.Start, false);
959 this._Controller.JumpCaret(tp.row, tp.col, false);
961 if (this.peer != null)
962 this.peer.OnNotifyCaretChanged();
963 this.View.IsFocused = true;
964 this.Focus(FocusState.Programmatic);
968 void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)
970 Point p = e.Position;
971 if (this.View.HitTextArea(p.X, p.Y))
973 TextPoint tp = this.View.GetTextPointFromPostion(p);
974 this._Controller.MoveCaretAndSelect(tp);
975 if (this.peer != null)
976 this.peer.OnNotifyCaretChanged();
981 bool IsModiferKeyPressed(VirtualKey key)
983 CoreVirtualKeyStates state = Window.Current.CoreWindow.GetKeyState(key);
984 return (state & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
986 void Refresh(Rectangle updateRect)
988 if (this.rectangle.ActualWidth == 0 || this.rectangle.ActualHeight == 0 || this.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
991 this.Render.BegineDraw();
993 this.View.Draw(updateRect);
995 this.Render.FillBackground(updateRect);
996 this.Render.EndDraw();
1000 bool Resize(double width, double height)
1002 if (width == 0 || height == 0)
1003 throw new ArgumentOutOfRangeException();
1004 if (this.Render.Resize(this.rectangle, width, height))
1006 this.View.PageBound = new Rectangle(0, 0, width, height);
1008 if (this.horizontalScrollBar != null)
1010 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
1011 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1013 if (this.verticalScrollBar != null)
1015 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
1016 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1023 void View_SrcChanged(object sender, EventArgs e)
1025 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1027 EditView view = this.View;
1028 if (view.Src.Row > this.verticalScrollBar.Maximum)
1029 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
1030 double absoulteX = Math.Abs(view.Src.X);
1031 if (absoulteX > this.horizontalScrollBar.Maximum)
1032 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1033 if (view.Src.Row != this.verticalScrollBar.Value)
1034 this.verticalScrollBar.Value = view.Src.Row;
1035 if (view.Src.X != this.horizontalScrollBar.Value)
1036 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1039 void FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)
1041 if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))
1048 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1050 if (this.horizontalScrollBar == null)
1053 if (this.FlowDirection == FlowDirection.LeftToRight)
1054 toX = this.horizontalScrollBar.Value;
1056 toX = -this.horizontalScrollBar.Value;
1057 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
1058 this.View.SelectGrippers.BottomLeft.Enabled = false;
1059 this.View.SelectGrippers.BottomRight.Enabled = false;
1063 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1065 if (this.verticalScrollBar == null)
1067 int newRow = (int)this.verticalScrollBar.Value;
1068 if (newRow >= this.View.LayoutLines.Count)
1070 this._Controller.Scroll(this.View.Src.X, newRow, false, false);
1071 this.View.SelectGrippers.BottomLeft.Enabled = false;
1072 this.View.SelectGrippers.BottomRight.Enabled = false;
1076 void Document_Update(object sender, DocumentUpdateEventArgs e)
1078 if (this.textStore.IsLocked())
1080 if (e.type == UpdateType.Replace)
1081 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
1084 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1086 this.Focus(FocusState.Programmatic);
1089 void timer_Tick(object sender, object e)
1091 bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding();
1097 public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
1099 FooTextBox source = (FooTextBox)sender;
1100 if (e.Property.Equals(IndentModeProperty))
1101 source.Controller.IndentMode = source.IndentMode;
1102 if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)
1103 source._Controller.Select(source.Selection.Index,source.Selection.Length);
1104 if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)
1105 source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col);
1106 if (e.Property.Equals(InsertModeProperty))
1107 source.View.InsertMode = source.InsertMode;
1108 if (e.Property.Equals(TabCharsProperty))
1109 source.View.TabStops = source.TabChars;
1110 if (e.Property.Equals(RectSelectModeProperty))
1111 source._Controller.RectSelection = source.RectSelectMode;
1112 if (e.Property.Equals(DrawCaretProperty))
1113 source.View.HideCaret = !source.DrawCaret;
1114 if (e.Property.Equals(DrawCaretLineProperty))
1115 source.View.HideLineMarker = !source.DrawCaretLine;
1116 if (e.Property.Equals(DrawLineNumberProperty))
1118 source.View.DrawLineNumber = source.DrawLineNumber;
1119 source._Controller.JumpCaret(source.View.CaretPostion.row, source.View.CaretPostion.col);
1121 if(e.Property.Equals(MagnificationPowerPropertyKey))
1122 source.Render.FontSize = source.FontSize * source.MagnificationPower;
1123 if (e.Property.Equals(FontFamilyProperty))
1124 source.Render.FontFamily = source.FontFamily;
1125 if (e.Property.Equals(FontStyleProperty))
1126 source.Render.FontStyle = source.FontStyle;
1127 if (e.Property.Equals(FontWeightProperty))
1128 source.Render.FontWeigth = source.FontWeight;
1129 if (e.Property.Equals(FontSizeProperty))
1130 source.Render.FontSize = source.FontSize;
1131 if (e.Property.Equals(ForegroundProperty))
1132 source.Render.Foreground = D2DRenderBase.ToColor4(source.Foreground);
1133 if (e.Property.Equals(BackgroundProperty))
1134 source.Render.Background = D2DRenderBase.ToColor4(source.Background);
1135 if (e.Property.Equals(ControlCharProperty))
1136 source.Render.ControlChar = D2DRenderBase.ToColor4(source.ControlChar);
1137 if (e.Property.Equals(HilightProperty))
1138 source.Render.Hilight = D2DRenderBase.ToColor4(source.Hilight);
1139 if (e.Property.Equals(Keyword1Property))
1140 source.Render.Keyword1 = D2DRenderBase.ToColor4(source.Keyword1);
1141 if (e.Property.Equals(Keyword2Property))
1142 source.Render.Keyword2 = D2DRenderBase.ToColor4(source.Keyword2);
1143 if (e.Property.Equals(CommentProperty))
1144 source.Render.Comment = D2DRenderBase.ToColor4(source.Comment);
1145 if (e.Property.Equals(LiteralProperty))
1146 source.Render.Literal = D2DRenderBase.ToColor4(source.Literal);
1147 if (e.Property.Equals(URLProperty))
1148 source.Render.Url = D2DRenderBase.ToColor4(source.URL);
1149 if (e.Property.Equals(InsertCaretProperty))
1150 source.Render.InsertCaret = D2DRenderBase.ToColor4(source.InsertCaret);
1151 if (e.Property.Equals(OverwriteCaretProperty))
1152 source.Render.OverwriteCaret = D2DRenderBase.ToColor4(source.OverwriteCaret);
1153 if (e.Property.Equals(PaddingProperty))
1154 source.View.Padding = new Padding((int)source.Padding.Left, (int)source.Padding.Top, (int)source.Padding.Right, (int)source.Padding.Bottom);
1155 if (e.Property.Equals(LineMarkerProperty))
1156 source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);
1157 if (e.Property.Equals(MarkURLProperty))
1158 source.View.UrlMark = source.MarkURL;
1159 if (e.Property.Equals(ShowFullSpaceProperty))
1160 source.Render.ShowFullSpace = source.ShowFullSpace;
1161 if (e.Property.Equals(ShowHalfSpaceProperty))
1162 source.Render.ShowHalfSpace = source.ShowHalfSpace;
1163 if (e.Property.Equals(ShowTabProperty))
1164 source.Render.ShowTab = source.ShowTab;
1165 if (e.Property.Equals(ShowLineBreakProperty))
1166 source.Render.ShowLineBreak = source.ShowLineBreak;
1167 if (e.Property.Equals(LineBreakProperty))
1168 source.View.LineBreak = source.LineBreakMethod;
1169 if (e.Property.Equals(LineBreakCharCountProperty))
1170 source.View.LineBreakCharCount = source.LineBreakCharCount;
1171 if (e.Property.Equals(UpdateAreaProperty))
1172 source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);
1173 if (e.Property.Equals(LineNumberProperty))
1174 source.Render.LineNumber = D2DRenderBase.ToColor4(source.LineNumber);
1175 if (e.Property.Equals(FlowDirectionProperty))
1177 source.Document.RightToLeft = source.FlowDirection == Windows.UI.Xaml.FlowDirection.RightToLeft;
1178 if(source.horizontalScrollBar != null)
1179 source.horizontalScrollBar.FlowDirection = source.FlowDirection;
1181 if (e.Property.Equals(DrawRulerProperty))
1183 source.View.HideRuler = !source.DrawRuler;
1184 source._Controller.JumpCaret(source.View.CaretPostion.row, source.View.CaretPostion.col);
1192 /// コンテキストメニューが表示されるときに呼び出されます
1194 public event EventHandler<FooContextMenuEventArgs> ContextMenuOpening;
1200 internal Controller Controller
1204 return this._Controller;
1209 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1211 public TextAntialiasMode TextAntialiasMode
1215 return this.Render.TextAntialiasMode;
1219 this.Render.TextAntialiasMode = value;
1226 public IHilighter Hilighter
1230 return this.View.Hilighter;
1234 this.View.Hilighter = value;
1235 this.View.LayoutLines.ClearLayoutCache();
1240 /// フォールティングを作成するインターフェイスを表す
1242 public IFoldingStrategy FoldingStrategy
1246 return this.View.LayoutLines.FoldingStrategy;
1250 this.View.LayoutLines.FoldingStrategy = value;
1252 this.View.LayoutLines.FoldingCollection.Clear();
1259 public MarkerPatternSet MarkerPatternSet
1263 return this.View.MarkerPatternSet;
1270 public Document Document
1279 public LineToIndexTable LayoutLineCollection
1281 get { return this.View.LayoutLines; }
1287 public string SelectedText
1291 return this._Controller.SelectedText;
1295 int oldLength = this.Document.Length;
1296 this._Controller.SelectedText = value;
1303 public IndentMode IndentMode
1305 get { return (IndentMode)GetValue(IndentModeProperty); }
1306 set { SetValue(IndentModeProperty, value); }
1310 /// IndentModeの依存プロパティを表す
1312 public static readonly DependencyProperty IndentModeProperty =
1313 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab,OnPropertyChanged));
1319 /// Lengthが0の場合はキャレット位置を表します。
1320 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1322 public TextRange Selection
1324 get { return (TextRange)GetValue(SelectionProperty); }
1325 set { SetValue(SelectionProperty, value); }
1329 /// Selectionの依存プロパティを表す
1331 public static readonly DependencyProperty SelectionProperty =
1332 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(0));
1337 public double MagnificationPower
1339 get { return (double)GetValue(MagnificationPowerPropertyKey); }
1340 set { SetValue(MagnificationPowerPropertyKey, value); }
1346 public static readonly DependencyProperty MagnificationPowerPropertyKey =
1347 DependencyProperty.Register("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0, OnPropertyChanged));
1352 public TextPoint CaretPostion
1354 get { return (TextPoint)GetValue(CaretPostionPropertyKey); }
1355 set { SetValue(CaretPostionPropertyKey, value); }
1358 static readonly DependencyProperty CaretPostionPropertyKey =
1359 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(new TextPoint(), OnPropertyChanged));
1364 public new FlowDirection FlowDirection
1366 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1367 set { SetValue(FlowDirectionProperty, value); }
1371 /// レタリング方向を表す。これは依存プロパティです
1373 public new static readonly DependencyProperty FlowDirectionProperty =
1374 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight,OnPropertyChanged));
1379 public new FontFamily FontFamily
1381 get { return (FontFamily)GetValue(FontFamilyProperty); }
1382 set { SetValue(FontFamilyProperty, value); }
1386 /// FontFamilyの依存プロパティを表す
1388 public new static readonly DependencyProperty FontFamilyProperty =
1389 DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(FooTextBox), new PropertyMetadata(new FontFamily("Cambria"), OnPropertyChanged));
1394 public new double FontSize
1396 get { return (double)GetValue(FontSizeProperty); }
1397 set { SetValue(FontSizeProperty, value); }
1401 /// FontSizeの依存プロパティを表す
1403 public new static readonly DependencyProperty FontSizeProperty =
1404 DependencyProperty.Register("FontSize", typeof(double), typeof(FooTextBox), new PropertyMetadata(12.0,OnPropertyChanged));
1409 public new FontStyle FontStyle
1411 get { return (FontStyle)GetValue(FontStyleProperty); }
1412 set { SetValue(FontStyleProperty, value); }
1416 /// FontStyleの依存プロパティを表す
1418 public new static readonly DependencyProperty FontStyleProperty =
1419 DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(FooTextBox), new PropertyMetadata(FontStyle.Normal,OnPropertyChanged));
1424 public new FontWeight FontWeight
1426 get { return (FontWeight)GetValue(FontWeightProperty); }
1427 set { SetValue(FontWeightProperty, value); }
1431 /// FontWeigthの依存プロパティを表す
1433 public new static readonly DependencyProperty FontWeightProperty =
1434 DependencyProperty.Register("FontWeigth", typeof(FontWeight), typeof(FooTextBox), new PropertyMetadata(FontWeights.Normal,OnPropertyChanged));
1437 /// デフォルトの文字色を表す。これは依存プロパティです
1439 public new Windows.UI.Color Foreground
1441 get { return (Windows.UI.Color)GetValue(ForegroundProperty); }
1442 set { SetValue(ForegroundProperty, value); }
1446 /// Foregroundの依存プロパティを表す
1448 public new static readonly DependencyProperty ForegroundProperty =
1449 DependencyProperty.Register("Foreground", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1452 /// 背景色を表す。これは依存プロパティです
1454 public new Windows.UI.Color Background
1456 get { return (Windows.UI.Color)GetValue(BackgroundProperty); }
1457 set { SetValue(BackgroundProperty, value); }
1461 /// Backgroundの依存プロパティを表す
1463 public new static readonly DependencyProperty BackgroundProperty =
1464 DependencyProperty.Register("Background", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.White, OnPropertyChanged));
1467 /// コントロールコードの文字色を表す。これは依存プロパティです
1469 public Windows.UI.Color ControlChar
1471 get { return (Windows.UI.Color)GetValue(ControlCharProperty); }
1472 set { SetValue(ControlCharProperty, value); }
1476 /// ControlCharの依存プロパティを表す
1478 public static readonly DependencyProperty ControlCharProperty =
1479 DependencyProperty.Register("ControlChar", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1482 /// 選択時の背景色を表す。これは依存プロパティです
1484 public Windows.UI.Color Hilight
1486 get { return (Windows.UI.Color)GetValue(HilightProperty); }
1487 set { SetValue(HilightProperty, value); }
1491 /// Hilightの依存プロパティを表す
1493 public static readonly DependencyProperty HilightProperty =
1494 DependencyProperty.Register("Hilight", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DeepSkyBlue, OnPropertyChanged));
1497 /// キーワード1の文字色を表す。これは依存プロパティです
1499 public Windows.UI.Color Keyword1
1501 get { return (Windows.UI.Color)GetValue(Keyword1Property); }
1502 set { SetValue(Keyword1Property, value); }
1506 /// Keyword1の依存プロパティを表す
1508 public static readonly DependencyProperty Keyword1Property =
1509 DependencyProperty.Register("Keyword1", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1512 /// キーワード2の文字色を表す。これは依存プロパティです
1514 public Windows.UI.Color Keyword2
1516 get { return (Windows.UI.Color)GetValue(Keyword2Property); }
1517 set { SetValue(Keyword2Property, value); }
1521 /// Keyword2の依存プロパティを表す
1523 public static readonly DependencyProperty Keyword2Property =
1524 DependencyProperty.Register("Keyword2", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DarkCyan, OnPropertyChanged));
1527 /// コメントの文字色を表す。これは依存プロパティです
1529 public Windows.UI.Color Comment
1531 get { return (Windows.UI.Color)GetValue(CommentProperty); }
1532 set { SetValue(CommentProperty, value); }
1536 /// Commentの依存プロパティを表す
1538 public static readonly DependencyProperty CommentProperty =
1539 DependencyProperty.Register("Comment", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Green, OnPropertyChanged));
1542 /// 文字リテラルの文字色を表す。これは依存プロパティです
1544 public Windows.UI.Color Literal
1546 get { return (Windows.UI.Color)GetValue(LiteralProperty); }
1547 set { SetValue(LiteralProperty, value); }
1551 /// Literalの依存プロパティを表す
1553 public static readonly DependencyProperty LiteralProperty =
1554 DependencyProperty.Register("Literal", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Brown, OnPropertyChanged));
1557 /// URLの文字色を表す。これは依存プロパティです
1559 public Windows.UI.Color URL
1561 get { return (Windows.UI.Color)GetValue(URLProperty); }
1562 set { SetValue(URLProperty, value); }
1568 public static readonly DependencyProperty URLProperty =
1569 DependencyProperty.Register("URL", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Blue, OnPropertyChanged));
1574 public Windows.UI.Color UpdateArea
1576 get { return (Windows.UI.Color)GetValue(UpdateAreaProperty); }
1577 set { SetValue(UpdateAreaProperty, value); }
1581 /// UpdateAreaの依存プロパティを表す
1583 public static readonly DependencyProperty UpdateAreaProperty =
1584 DependencyProperty.Register("UpdateArea", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));
1589 public Windows.UI.Color LineMarker
1591 get { return (Windows.UI.Color)GetValue(LineMarkerProperty); }
1592 set { SetValue(LineMarkerProperty, value); }
1596 /// LineMarkerの依存プロパティを表す
1598 public static readonly DependencyProperty LineMarkerProperty =
1599 DependencyProperty.Register("LineMarker", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Gray, OnPropertyChanged));
1602 /// 挿入モード時のキャレットの色を表す
1604 public Windows.UI.Color InsertCaret
1606 get { return (Windows.UI.Color)GetValue(InsertCaretProperty); }
1607 set { SetValue(InsertCaretProperty, value); }
1611 /// InsertCaretの依存プロパティを表す
1613 public static readonly DependencyProperty InsertCaretProperty =
1614 DependencyProperty.Register("InsertCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1617 /// 上書きモード時のキャレット職を表す
1619 public Windows.UI.Color OverwriteCaret
1621 get { return (Windows.UI.Color)GetValue(OverwriteCaretProperty); }
1622 set { SetValue(OverwriteCaretProperty, value); }
1626 /// OverwriteCaretの依存プロパティを表す
1628 public static readonly DependencyProperty OverwriteCaretProperty =
1629 DependencyProperty.Register("OverwriteCaret", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.Black, OnPropertyChanged));
1634 public Windows.UI.Color LineNumber
1636 get { return (Windows.UI.Color)GetValue(LineNumberProperty); }
1637 set { SetValue(LineNumberProperty, value); }
1641 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1643 public static readonly DependencyProperty LineNumberProperty =
1644 DependencyProperty.Register("LineNumber", typeof(Windows.UI.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray,OnPropertyChanged));
1649 public new Thickness Padding
1651 get { return (Thickness)GetValue(PaddingProperty); }
1652 set { SetValue(PaddingProperty, value); }
1656 /// Paddingの依存プロパティを表す
1658 public new static readonly DependencyProperty PaddingProperty =
1659 DependencyProperty.Register("Padding", typeof(Thickness), typeof(FooTextBox), new PropertyMetadata(new Thickness(),OnPropertyChanged));
1662 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1664 public bool InsertMode
1666 get { return (bool)GetValue(InsertModeProperty); }
1667 set { SetValue(InsertModeProperty, value); }
1671 /// InsertModeの依存プロパティを表す
1673 public static readonly DependencyProperty InsertModeProperty =
1674 DependencyProperty.Register("InsertMode",
1677 new PropertyMetadata(true, OnPropertyChanged));
1680 /// タブの文字数を表す。これは依存プロパティです
1684 get { return (int)GetValue(TabCharsProperty); }
1685 set { SetValue(TabCharsProperty, value); }
1689 /// TabCharsの依存プロパティを表す
1691 public static readonly DependencyProperty TabCharsProperty =
1692 DependencyProperty.Register("TabChars",
1695 new PropertyMetadata(4, OnPropertyChanged));
1698 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1700 public bool RectSelectMode
1702 get { return (bool)GetValue(RectSelectModeProperty); }
1703 set { SetValue(RectSelectModeProperty, value); }
1707 /// RectSelectModeの依存プロパティを表す
1709 public static readonly DependencyProperty RectSelectModeProperty =
1710 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1716 /// 変更した場合、レイアウトの再構築を行う必要があります
1718 public LineBreakMethod LineBreakMethod
1720 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1721 set { SetValue(LineBreakProperty, value); }
1725 /// LineBreakMethodの依存プロパティを表す
1727 public static readonly DependencyProperty LineBreakProperty =
1728 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None, OnPropertyChanged));
1732 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1735 /// 変更した場合、レイアウトの再構築を行う必要があります
1737 public int LineBreakCharCount
1739 get { return (int)GetValue(LineBreakCharCountProperty); }
1740 set { SetValue(LineBreakCharCountProperty, value); }
1744 /// LineBreakCharCountの依存プロパティを表す
1746 public static readonly DependencyProperty LineBreakCharCountProperty =
1747 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
1750 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1752 public bool DrawCaret
1754 get { return (bool)GetValue(DrawCaretProperty); }
1755 set { SetValue(DrawCaretProperty, value); }
1759 /// DrawCaretの依存プロパティを表す
1761 public static readonly DependencyProperty DrawCaretProperty =
1762 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new PropertyMetadata(true, OnPropertyChanged));
1766 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1768 public bool DrawCaretLine
1770 get { return (bool)GetValue(DrawCaretLineProperty); }
1771 set { SetValue(DrawCaretLineProperty, value); }
1775 /// DrawCaretLineの依存プロパティを表す
1777 public static readonly DependencyProperty DrawCaretLineProperty =
1778 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1781 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
1783 public bool DrawLineNumber
1785 get { return (bool)GetValue(DrawLineNumberProperty); }
1786 set { SetValue(DrawLineNumberProperty, value); }
1790 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
1792 public bool DrawRuler
1794 get { return (bool)GetValue(DrawRulerProperty); }
1795 set { SetValue(DrawRulerProperty, value); }
1799 /// DrawRulerの依存プロパティを表す
1801 public static readonly DependencyProperty DrawRulerProperty =
1802 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1806 /// DrawLineNumberの依存プロパティを表す
1808 public static readonly DependencyProperty DrawLineNumberProperty =
1809 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1812 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
1816 get { return (bool)GetValue(MarkURLProperty); }
1817 set { SetValue(MarkURLProperty, value); }
1821 /// MarkURLの依存プロパティを表す
1823 public static readonly DependencyProperty MarkURLProperty =
1824 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1827 /// 全角スペースを表示するなら真。そうでないなら偽
1829 public bool ShowFullSpace
1831 get { return (bool)GetValue(ShowFullSpaceProperty); }
1832 set { SetValue(ShowFullSpaceProperty, value); }
1836 /// ShowFullSpaceの依存プロパティを表す
1838 public static readonly DependencyProperty ShowFullSpaceProperty =
1839 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1842 /// 半角スペースを表示するなら真。そうでないなら偽
1844 public bool ShowHalfSpace
1846 get { return (bool)GetValue(ShowHalfSpaceProperty); }
1847 set { SetValue(ShowHalfSpaceProperty, value); }
1851 /// ShowHalfSpaceの依存プロパティを表す
1853 public static readonly DependencyProperty ShowHalfSpaceProperty =
1854 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1857 /// タブを表示するなら真。そうでないなら偽
1861 get { return (bool)GetValue(ShowTabProperty); }
1862 set { SetValue(ShowTabProperty, value); }
1866 /// ShowTabの依存プロパティを表す
1868 public static readonly DependencyProperty ShowTabProperty =
1869 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false, OnPropertyChanged));
1872 /// 改行マークを表示するなら真。そうでないなら偽
1874 public bool ShowLineBreak
1876 get { return (bool)GetValue(ShowLineBreakProperty); }
1877 set { SetValue(ShowLineBreakProperty, value); }
1881 /// ShowLineBreakの依存プロパティを表す
1883 public static readonly DependencyProperty ShowLineBreakProperty =
1884 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false,OnPropertyChanged));
1891 /// コンテキストメニューのイベントデーターを表す
1893 public class FooContextMenuEventArgs
1896 /// 処理済みなら真。そうでないなら偽
1898 public bool Handled = false;
1900 /// コンテキストメニューを表示すべき座標を表す
1902 public Windows.Foundation.Point Postion;
1906 /// <param name="pos"></param>
1907 public FooContextMenuEventArgs(Windows.Foundation.Point pos)