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.Threading.Tasks;
14 using System.Runtime.InteropServices;
16 using System.Windows.Input;
17 using System.Windows.Media;
18 using System.Windows.Controls;
19 using System.Windows.Controls.Primitives;
20 using System.Windows.Documents;
21 using System.Windows.Interop;
22 using System.Windows.Threading;
23 using DotNetTextStore;
24 using DotNetTextStore.UnmanagedAPI.TSF;
25 using DotNetTextStore.UnmanagedAPI.WinDef;
26 using Microsoft.Win32;
28 namespace FooEditEngine.WPF
31 /// WPFでのFooTextBoxの実装
33 public sealed class FooTextBox : Control, IDisposable
35 const double MaxFontSize = 72.0f;
36 const double MinFontSize = 1;
39 Controller _Controller;
42 ScrollBar verticalScrollBar, horizontalScrollBar;
44 DispatcherTimer timer;
45 bool disposed = false;
46 FooTextBoxAutomationPeer peer;
47 bool isNotifyChanged = false;
51 const int Interval = 96;
52 const int IntervalWhenLostFocuse = 160;
56 DefaultStyleKeyProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(typeof(FooTextBox)));
57 KeyboardNavigation.IsTabStopProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(true));
58 KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(KeyboardNavigationMode.None));
66 this.popup = new Popup();
68 this.image = new Image();
69 this.image.Stretch = Stretch.Fill;
70 this.image.HorizontalAlignment = HorizontalAlignment.Left;
71 this.image.VerticalAlignment = VerticalAlignment.Top;
73 this.textStore = new TextStore();
74 this.textStore.IsLoading += textStore_IsLoading;
75 this.textStore.IsReadOnly += textStore_IsReadOnly;
76 this.textStore.GetStringLength += () => this.Document.Length;
77 this.textStore.GetString += _textStore_GetString;
78 this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;
79 this.textStore.SetSelectionIndex += _textStore_SetSelectionIndex;
80 this.textStore.InsertAtSelection += _textStore_InsertAtSelection;
81 this.textStore.GetHWnd += _textStore_GetHWnd;
82 this.textStore.GetScreenExtent += _textStore_GetScreenExtent;
83 this.textStore.GetStringExtent += _textStore_GetStringExtent;
84 this.textStore.CompositionStarted += textStore_CompositionStarted;
85 this.textStore.CompositionUpdated += textStore_CompositionUpdated;
86 this.textStore.CompositionEnded += textStore_CompositionEnded;
88 this.Render = new D2DRender(this, 200, 200,this.image);
90 this.Document = new Document();
92 this._View = new EditView(this.Document, this.Render, new Padding(5, 5, 5, 5));
93 this._View.SrcChanged += View_SrcChanged;
94 this._View.InsertMode = this.InsertMode;
95 this.Document.DrawLineNumber = this.DrawLineNumber;
96 this._View.HideCaret = !this.DrawCaret;
97 this._View.HideLineMarker = !this.DrawCaretLine;
98 this.Document.HideRuler = !this.DrawRuler;
99 this.Document.UrlMark = this.MarkURL;
100 this.Document.TabStops = this.TabChars;
101 this.Document.ShowFullSpace = this.ShowFullSpace;
102 this.Document.ShowHalfSpace = this.ShowHalfSpace;
103 this.Document.ShowTab = this.ShowTab;
105 this._Controller = new Controller(this.Document, this._View);
106 this._Document.SelectionChanged += new EventHandler(Controller_SelectionChanged);
108 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, CopyCommand, CanExecute));
109 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, CutCommand, CanExecute));
110 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, PasteCommand, CanExecute));
111 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, DeleteCommand, CanExecute));
112 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, SelectAllCommand, CanExecute));
113 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, UndoCommand, CanExecute));
114 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, RedoCommand, CanExecute));
115 this.CommandBindings.Add(new CommandBinding(EditingCommands.ToggleInsert, ToggleInsertCommand, CanExecute));
116 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleRectSelectMode, ToggleRectSelectCommand, CanExecute));
117 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleFlowDirection, ToggleFlowDirectionCommand, CanExecute));
118 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleCodePoint, ToggleCodePointCommand, CanExecute));
120 this.InputBindings.Add(new InputBinding(ApplicationCommands.Copy, new KeyGesture(Key.C, ModifierKeys.Control)));
121 this.InputBindings.Add(new InputBinding(ApplicationCommands.Cut, new KeyGesture(Key.X, ModifierKeys.Control)));
122 this.InputBindings.Add(new InputBinding(ApplicationCommands.Paste, new KeyGesture(Key.V, ModifierKeys.Control)));
123 this.InputBindings.Add(new InputBinding(ApplicationCommands.Delete, new KeyGesture(Key.Delete, ModifierKeys.None)));
124 this.InputBindings.Add(new InputBinding(ApplicationCommands.SelectAll, new KeyGesture(Key.A, ModifierKeys.Control)));
125 this.InputBindings.Add(new InputBinding(ApplicationCommands.Undo, new KeyGesture(Key.Z, ModifierKeys.Control)));
126 this.InputBindings.Add(new InputBinding(ApplicationCommands.Redo, new KeyGesture(Key.Y, ModifierKeys.Control)));
127 this.InputBindings.Add(new InputBinding(EditingCommands.ToggleInsert, new KeyGesture(Key.Insert, ModifierKeys.None)));
128 this.InputBindings.Add(new InputBinding(FooTextBoxCommands.ToggleCodePoint, new KeyGesture(Key.X, ModifierKeys.Alt)));
130 this.timer = new DispatcherTimer();
131 this.timer.Interval = new TimeSpan(0, 0, 0, 0, Interval);
132 this.timer.Tick += new EventHandler(timer_Tick);
134 this.Loaded += new RoutedEventHandler(FooTextBox_Loaded);
136 SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
138 this.SystemEvents_UserPreferenceChanged(null, new UserPreferenceChangedEventArgs(UserPreferenceCategory.Keyboard));
140 this.CaretMoved += (s, e) => { };
142 this.IsManipulationEnabled = true;
150 //Dispose(false)を呼び出すと落ちる
157 public override void OnApplyTemplate()
159 base.OnApplyTemplate();
161 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
164 Grid.SetRow(this.image, 0);
165 Grid.SetColumn(this.image, 0);
166 grid.Children.Add(this.image);
168 Grid.SetRow(this.popup, 0);
169 Grid.SetColumn(this.popup, 0);
170 grid.Children.Add(this.popup);
171 //this.popup.PlacementTarget = this;
172 this.popup.Placement = PlacementMode.Absolute;
175 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
176 if (this.horizontalScrollBar != null)
178 this.horizontalScrollBar.SmallChange = 10;
179 this.horizontalScrollBar.LargeChange = 100;
180 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
181 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
183 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
184 if (this.verticalScrollBar != null)
186 this.verticalScrollBar.SmallChange = 1;
187 this.verticalScrollBar.LargeChange = 10;
188 this.verticalScrollBar.Maximum = this.Document.LayoutLines.Count - 1;
189 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
196 /// <param name="start">開始インデックス</param>
197 /// <param name="length">長さ</param>
198 public void Select(int start, int length)
200 this.Document.Select(start, length);
201 this.textStore.NotifySelectionChanged();
205 /// キャレットを指定した行に移動させます
207 /// <param name="index">インデックス</param>
208 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
209 public void JumpCaret(int index)
211 this._Controller.JumpCaret(index);
214 /// キャレットを指定した行と桁に移動させます
216 /// <param name="row">行番号</param>
217 /// <param name="col">桁</param>
218 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
219 public void JumpCaret(int row, int col)
221 this._Controller.JumpCaret(row, col);
225 /// 選択中のテキストをクリップボードにコピーします
229 string text = this._Controller.SelectedText;
230 if (text != null && text != string.Empty)
231 Clipboard.SetText(text);
235 /// 選択中のテキストをクリップボードに切り取ります
239 string text = this._Controller.SelectedText;
240 if (text != null && text != string.Empty)
242 Clipboard.SetText(text);
243 this._Controller.SelectedText = "";
252 if (Clipboard.ContainsText() == false)
254 string text = Clipboard.GetText();
255 this._Controller.SelectedText = text;
261 public void DeSelectAll()
263 this._Controller.DeSelectAll();
264 this.textStore.NotifySelectionChanged();
270 /// <param name="tp">テキストポイント</param>
271 /// <returns>座標</returns>
272 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
273 public System.Windows.Point GetPostionFromTextPoint(TextPoint tp)
275 if (this.Document.FireUpdateEvent == false)
276 throw new InvalidOperationException("");
277 return this.image.TranslatePoint(this._View.GetPostionFromTextPoint(tp),this);
281 /// 対応するテキストポイントを返します
283 /// <param name="p">クライアント領域の原点を左上とする座標</param>
284 /// <returns>テキストポイント</returns>
285 public TextPoint GetTextPointFromPostion(System.Windows.Point p)
287 if (this.Document.FireUpdateEvent == false)
288 throw new InvalidOperationException("");
289 System.Windows.Point relP = this.TranslatePoint(p, this.image);
290 return this._View.GetTextPointFromPostion(p);
296 /// <param name="row">レイアウト行</param>
297 /// <returns>行の高さ</returns>
298 public double GetLineHeight(int row)
300 if (this.Document.FireUpdateEvent == false)
301 throw new InvalidOperationException("");
302 return this._View.LayoutLines.GetLayout(row).Height;;
306 /// インデックスに対応する座標を得ます
308 /// <param name="index">インデックス</param>
309 /// <returns>座標を返す</returns>
310 public System.Windows.Point GetPostionFromIndex(int index)
312 if (this.Document.FireUpdateEvent == false)
313 throw new InvalidOperationException("");
314 TextPoint tp = this._View.GetLayoutLineFromIndex(index);
315 return this._View.GetPostionFromTextPoint(tp);
321 /// <param name="p">座標</param>
322 /// <returns>インデックスを返す</returns>
323 public int GetIndexFromPostion(System.Windows.Point p)
325 if (this.Document.FireUpdateEvent == false)
326 throw new InvalidOperationException("");
327 TextPoint tp = this._View.GetTextPointFromPostion(p);
328 return this._View.GetIndexFromLayoutLine(tp);
334 public void Refresh()
336 this.Refresh(this._View.PageBound);
340 /// レイアウト行をすべて破棄し、再度レイアウトを行う
342 public void PerfomLayouts()
344 this.Document.PerformLayout();
350 /// <param name="row">行</param>
351 /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
352 public void ScrollIntoView(int row, bool alignTop)
354 this._View.ScrollIntoView(row, alignTop);
358 /// ストリームからドキュメントを構築する
360 /// <param name="tr">TextReader</param>
361 /// <param name="token">キャンセル用トークン</param>
362 /// <returns>Taskオブジェクト</returns>
363 public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)
365 await this.Document.LoadAsync(tr, token);
369 /// ファイルからドキュメントを構築する
371 /// <param name="filepath">ファイルパス</param>
372 /// <param name="enc">エンコード</param>
373 /// <param name="token">キャンセル用トークン</param>
374 /// <returns>Taskオブジェクト</returns>
375 public async Task LoadFileAsync(string filepath, Encoding enc,System.Threading.CancellationTokenSource token)
377 var fs = new System.IO.StreamReader(filepath, enc);
378 await this.Document.LoadAsync(fs, token);
382 private void Document_LoadProgress(object sender, ProgressEventArgs e)
384 if (e.state == ProgressState.Start)
386 this.IsEnabled = false;
388 else if (e.state == ProgressState.Complete)
390 TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
391 if (this.verticalScrollBar != null)
392 this.verticalScrollBar.Maximum = this._View.LayoutLines.Count;
393 this._View.CalculateWhloeViewPort();
394 this._View.CalculateLineCountOnScreen();
395 this.IsEnabled = true;
396 this.Refresh(this._View.PageBound);
401 /// ドキュメントの内容をファイルに保存する
403 /// <param name="filepath">ファイルパス</param>
404 /// <param name="newLine">改行コード</param>
405 /// <param name="enc">エンコード</param>
406 /// <param name="token">キャンセル用トークン</param>
407 /// <returns>Taskオブジェクト</returns>
408 public async Task SaveFile(string filepath, Encoding enc,string newLine, System.Threading.CancellationTokenSource token)
410 var fs = new System.IO.StreamWriter(filepath, false , enc);
411 fs.NewLine = newLine;
412 await this.Document.SaveAsync(fs, token);
419 public void Dispose()
424 GC.SuppressFinalize(this);
425 this.disposed = true;
431 /// <param name="disposing">真ならマネージドリソースも開放し、そうでないならアンマネージドリソースのみを開放する</param>
432 void Dispose(bool disposing)
436 this.textStore.Dispose();
438 this._View.Dispose();
439 this.Render.Dispose();
441 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
444 void Refresh(Rectangle updateRect)
446 if (this.disposed || this.Visibility == Visibility.Collapsed)
449 this.Render.DrawContent(this._View, this.IsEnabled, updateRect);
450 this.Document.IsRequestRedraw = false;
454 void CanExecute(object sender, CanExecuteRoutedEventArgs e)
456 e.CanExecute = this.IsEnabled;
459 void ToggleCodePointCommand(object sender, RoutedEventArgs e)
461 if (!this._Controller.ConvertToChar())
462 this._Controller.ConvertToCodePoint();
466 void CopyCommand(object sender, RoutedEventArgs e)
471 void CutCommand(object sender, RoutedEventArgs e)
477 void PasteCommand(object sender, RoutedEventArgs e)
483 void DeleteCommand(object sender, RoutedEventArgs e)
485 int oldLength = this.Document.Length;
486 this._Controller.DoDeleteAction();
490 void SelectAllCommand(object sender, RoutedEventArgs e)
492 this.Select(0, this.Document.Length);
496 void UndoCommand(object sender, RoutedEventArgs e)
498 int oldLength = this.Document.Length;
499 this.Document.UndoManager.undo();
503 void RedoCommand(object sender, RoutedEventArgs e)
505 int oldLength = this.Document.Length;
506 this.Document.UndoManager.redo();
510 void ToggleInsertCommand(object sender, RoutedEventArgs e)
513 this.InsertMode = false;
515 this.InsertMode = true;
519 void ToggleRectSelectCommand(object sender, RoutedEventArgs e)
521 if (this.RectSelectMode)
522 this.RectSelectMode = false;
524 this.RectSelectMode = true;
527 void ToggleFlowDirectionCommand(object sender, RoutedEventArgs e)
529 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
530 this.FlowDirection = System.Windows.FlowDirection.RightToLeft;
532 this.FlowDirection = System.Windows.FlowDirection.LeftToRight;
537 internal TextStore TextStore
539 get { return this.textStore; }
542 bool textStore_IsReadOnly()
547 bool textStore_IsLoading()
552 void textStore_CompositionEnded()
554 TextStoreHelper.EndCompostion(this.Document);
558 void textStore_CompositionUpdated(int start, int end)
560 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this._View, start, end))
563 bool textStore_CompositionStarted()
565 bool result = TextStoreHelper.StartCompstion(this.Document);
567 System.Media.SystemSounds.Beep.Play();
571 string _textStore_GetString(int start, int length)
573 return this.Document.ToString(start, length);
576 IntPtr _textStore_GetHWnd()
578 var hwndSource = HwndSource.FromVisual(this) as HwndSource;
579 if (hwndSource != null)
580 return hwndSource.Handle;
585 void _textStore_GetStringExtent(
589 out POINT o_bottomRight
592 Point startPos, endPos;
593 TextStoreHelper.GetStringExtent(this.Document, this._View, i_startIndex, i_endIndex, out startPos, out endPos);
595 double scale = this.Render.GetScale();
597 startPos = PointToScreen(this.TranslatePoint(startPos.Scale(scale), this));
598 endPos = PointToScreen(this.TranslatePoint(endPos.Scale(scale), this));
600 o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);
601 o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);
604 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
606 var pointTopLeft = new Point(0, 0);
607 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
609 pointTopLeft = PointToScreen(pointTopLeft);
610 pointBottomRight = PointToScreen(pointBottomRight);
612 o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
613 o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
616 void _textStore_GetSelectionIndex(int start_index, int max_count, out DotNetTextStore.TextSelection[] sels)
619 TextStoreHelper.GetSelection(this._Controller, this._View.Selections, out selRange);
621 sels = new DotNetTextStore.TextSelection[1];
622 sels[0] = new DotNetTextStore.TextSelection();
623 sels[0].start = selRange.Index;
624 sels[0].end = selRange.Index + selRange.Length;
627 void _textStore_SetSelectionIndex(DotNetTextStore.TextSelection[] sels)
629 TextStoreHelper.SetSelectionIndex(this._Controller, this._View, sels[0].start, sels[0].end);
633 void _textStore_InsertAtSelection(string i_value, ref int o_startIndex, ref int o_endIndex)
635 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
640 /// キーボードフォーカスが取得されたときに呼ばれます
642 /// <param name="e">イベントデーター</param>
643 protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
645 base.OnGotKeyboardFocus(e);
646 this.textStore.SetFocus();
647 this._View.IsFocused = true;
648 this.timer.Interval = new TimeSpan(0,0,0,0,Interval);
653 /// キーボードフォーカスが失われたときに呼ばれます
655 /// <param name="e">イベントデーター</param>
656 protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
658 base.OnLostKeyboardFocus(e);
659 this._View.IsFocused = false;
660 this.timer.Interval = new TimeSpan(0, 0, 0, 0, IntervalWhenLostFocuse);
666 /// キャレットが移動したときに通知されるイベント
668 public event EventHandler CaretMoved;
671 protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
673 this.peer = new FooTextBoxAutomationPeer(this);
679 protected override void OnTextInput(TextCompositionEventArgs e)
683 this._Controller.DoEnterAction();
685 else if (e.Text == "\b")
687 this._Controller.DoBackSpaceAction();
691 if(this.IsInputString(e.Text))
692 this._Controller.DoInputString(e.Text);
699 bool IsInputString(string s)
701 foreach (char charCode in s)
703 if ((0x20 <= charCode && charCode <= 0x7e)
711 protected override void OnKeyDown(KeyEventArgs e)
713 if (this.textStore.IsLocked())
716 ModifierKeys modiferKeys = e.KeyboardDevice.Modifiers;
718 var autocomplete = this.Document.AutoComplete as AutoCompleteBox;
719 if (autocomplete != null &&
720 autocomplete.ProcessKeyDown(this,e, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift)))
726 bool movedCaret = false;
730 this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
736 this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
742 this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
748 this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
754 this._Controller.Scroll(ScrollDirection.Up,this._View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
759 this._Controller.Scroll(ScrollDirection.Down,this._View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
764 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
765 this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
767 this._Controller.JumpToLineHead(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
772 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
773 this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
775 this._Controller.JumpToLineEnd(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
780 int oldLength = this.Document.Length;
781 if (this.Selection.Length == 0)
782 this._Controller.DoInputChar('\t');
783 else if(this.IsPressedModifierKey(modiferKeys,ModifierKeys.Shift))
784 this._Controller.DownIndent();
786 this._Controller.UpIndent();
791 if (movedCaret && this.peer != null)
792 this.peer.OnNotifyCaretChanged();
796 bool IsPressedModifierKey(ModifierKeys keys, ModifierKeys pressed)
800 if ((keys & pressed) == pressed)
806 /// ダブルクリックされたときに呼ばれます
808 /// <param name="e">イベントパラメーター</param>
810 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
811 /// e.Handledを真にした場合、単語単位の選択が行われなくなります
813 protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
815 var p = this.GetDipFromPoint(e.GetPosition(this));
816 TextPoint tp = this._View.GetTextPointFromPostion(p);
817 if (tp == TextPoint.Null)
819 int index = this._View.LayoutLines.GetIndexFromTextPoint(tp);
821 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
826 newEventArgs.RoutedEvent = e.RoutedEvent;
827 base.OnMouseDoubleClick(newEventArgs);
829 if (newEventArgs.Handled)
832 if (e.LeftButton == MouseButtonState.Pressed)
834 if (p.X < this.Render.TextArea.X)
835 this.Document.SelectLine((int)index);
837 this.Document.SelectWord((int)index);
839 this.textStore.NotifySelectionChanged();
840 if(this.peer != null)
841 this.peer.OnNotifyCaretChanged();
847 /// マウスボタンが押されたときに呼ばれます
849 /// <param name="e">イベントパラメーター</param>
851 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
852 /// e.Handledを真にした場合、キャレットの移動処理が行われなくなります
854 protected override void OnMouseDown(MouseButtonEventArgs e)
858 var p = this.GetDipFromPoint(e.GetPosition(this));
859 TextPoint tp = this._View.GetTextPointFromPostion(p);
860 if (tp == TextPoint.Null)
862 int index = this._View.LayoutLines.GetIndexFromTextPoint(tp);
864 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
869 newEventArgs.RoutedEvent = e.RoutedEvent;
870 base.OnMouseDown(newEventArgs);
872 if (newEventArgs.Handled)
875 if (e.LeftButton == MouseButtonState.Pressed)
877 FoldingItem foldingData = this._View.HitFoldingData(p.X,tp.row);
878 if (foldingData != null)
880 if (foldingData.Expand)
881 this._View.LayoutLines.FoldingCollection.Collapse(foldingData);
883 this._View.LayoutLines.FoldingCollection.Expand(foldingData);
884 this._Controller.JumpCaret(foldingData.Start,false);
888 this._Controller.JumpCaret(tp.row, tp.col, false);
890 if (this.peer != null)
891 this.peer.OnNotifyCaretChanged();
892 this._View.IsFocused = true;
894 this.Document.SelectGrippers.BottomLeft.Enabled = false;
895 this.Document.SelectGrippers.BottomRight.Enabled = false;
901 /// マウスのボタンが離されたときに呼ばれます
903 /// <param name="e"></param>
904 protected override void OnMouseUp(MouseButtonEventArgs e)
906 this.ReleaseMouseCapture();
913 /// <param name="e">イベントパラメーター</param>
915 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
916 /// e.Handledを真にした場合、選択処理と状況に応じたカーソルの変化が行われなくなります
918 protected override void OnMouseMove(MouseEventArgs e)
920 bool leftPressed = e.LeftButton == MouseButtonState.Pressed;
922 var p = this.GetDipFromPoint(e.GetPosition(this));
924 TextPointSearchRange searchRange;
925 if (this._View.HitTextArea(p.X, p.Y))
927 searchRange = TextPointSearchRange.TextAreaOnly;
929 else if (leftPressed)
931 searchRange = TextPointSearchRange.Full;
935 this.Cursor = Cursors.Arrow;
940 TextPoint tp = this._View.GetTextPointFromPostion(p, searchRange);
942 if (tp == TextPoint.Null)
944 this.Cursor = Cursors.Arrow;
949 int index = this._View.GetIndexFromLayoutLine(tp);
951 FooMouseEventArgs newEventArgs = new FooMouseEventArgs(e.MouseDevice, e.Timestamp, e.StylusDevice, index);
952 newEventArgs.RoutedEvent = e.RoutedEvent;
953 base.OnMouseMove(newEventArgs);
955 if (newEventArgs.Handled)
958 //この状態のときはカーソルがテキストエリア内にある
959 if (searchRange == TextPointSearchRange.TextAreaOnly)
961 if (this._Controller.IsMarker(tp, HilightType.Url))
962 this.Cursor = Cursors.Hand;
964 this.Cursor = Cursors.IBeam;
968 this.Cursor = Cursors.Arrow;
971 //スクロールバーを押した場合はキャレットを移動させる必要がない
972 if (leftPressed && e.OriginalSource.GetType() == typeof(FooTextBox))
974 bool controlPressed = (Keyboard.GetKeyStates(Key.LeftCtrl) & KeyStates.Down) == KeyStates.Down;
975 this._Controller.MoveCaretAndSelect(tp, controlPressed);
976 if (this.peer != null)
977 this.peer.OnNotifyCaretChanged();
982 Gripper hittedGripper;
983 bool touchScrolled = false;
986 protected override void OnTouchDown(TouchEventArgs e)
988 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
989 this.hittedGripper = this._View.HitGripperFromPoint(p);
990 this.CaptureTouch(e.TouchDevice);
994 protected override void OnTouchUp(TouchEventArgs e)
996 this.ReleaseTouchCapture(e.TouchDevice);
997 if(this.hittedGripper != null || this.touchScrolled)
999 this.hittedGripper = null;
1000 this.touchScrolled = false;
1004 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
1005 TextPoint tp = this._View.GetTextPointFromPostion(p);
1006 if (tp == TextPoint.Null)
1008 int index = this._View.LayoutLines.GetIndexFromTextPoint(tp);
1010 FoldingItem foldingData = this._View.HitFoldingData(p.X, tp.row);
1011 if (foldingData != null)
1013 if (foldingData.Expand)
1014 this._View.LayoutLines.FoldingCollection.Collapse(foldingData);
1016 this._View.LayoutLines.FoldingCollection.Expand(foldingData);
1017 this._Controller.JumpCaret(foldingData.Start, false);
1021 this._Controller.JumpCaret(tp.row, tp.col, false);
1023 if (this.peer != null)
1024 this.peer.OnNotifyCaretChanged();
1025 this._View.IsFocused = true;
1027 this.Document.SelectGrippers.BottomLeft.Enabled = false;
1028 this.Document.SelectGrippers.BottomRight.Enabled = true;
1033 protected override void OnTouchMove(TouchEventArgs e)
1035 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
1036 if (this.Controller.MoveCaretAndGripper(p, this.hittedGripper))
1038 if (this.peer != null)
1039 this.peer.OnNotifyCaretChanged();
1045 protected override void OnManipulationInertiaStarting(ManipulationInertiaStartingEventArgs e)
1050 protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
1052 if (this.hittedGripper != null)
1055 Point translation = new Point(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
1057 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
1058 if (Math.Abs(e.CumulativeManipulation.Translation.X) < Math.Abs(e.CumulativeManipulation.Translation.Y))
1060 int deltay = (int)Math.Abs(Math.Ceiling(translation.Y));
1061 if (translation.Y < 0)
1062 this._Controller.ScrollByPixel(ScrollDirection.Down, deltay, false, false);
1064 this._Controller.ScrollByPixel(ScrollDirection.Up, deltay, false, false);
1065 this.touchScrolled = true;
1070 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
1073 if (translation.X < 0)
1074 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
1076 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
1077 this.touchScrolled = true;
1082 private Point GetDipFromPoint(Point p)
1085 this.Render.GetDpi(out dpi,out dpi);
1086 double scale = dpi / 96.0;
1087 return p.Scale(1 / scale);
1091 protected override void OnMouseWheel(MouseWheelEventArgs e)
1093 if(Keyboard.Modifiers == ModifierKeys.None)
1096 this._Controller.Scroll(ScrollDirection.Up, SystemParameters.WheelScrollLines, false, false);
1098 this._Controller.Scroll(ScrollDirection.Down, SystemParameters.WheelScrollLines, false, false);
1100 else if (Keyboard.Modifiers == ModifierKeys.Control)
1102 double newFontSize = this.Render.FontSize;
1107 if (newFontSize > MaxFontSize)
1109 else if (newFontSize < MinFontSize)
1111 this.Render.FontSize = newFontSize;
1112 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
1115 base.OnMouseWheel(e);
1118 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
1120 if (e.Category == UserPreferenceCategory.Keyboard)
1122 int blinkTime = (int)NativeMethods.GetCaretBlinkTime();
1123 this._View.CaretBlink = blinkTime >= 0;
1124 this._View.CaretBlinkTime = blinkTime * 2;
1126 if (e.Category == UserPreferenceCategory.General)
1128 this._View.CaretWidthOnInsertMode = SystemParameters.CaretWidth;
1132 void Document_Update(object sender, DocumentUpdateEventArgs e)
1134 if (this.textStore.IsLocked())
1136 if(e.type == UpdateType.Replace)
1137 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
1138 if(this.peer != null)
1139 this.peer.OnNotifyTextChanged();
1142 void timer_Tick(object sender, EventArgs e)
1144 if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)
1146 if (this.Resize(this.image.ActualWidth, this.image.ActualHeight))
1148 this.Refresh(this._View.PageBound);
1152 bool updateAll = this._View.LayoutLines.HilightAll() || this._View.LayoutLines.GenerateFolding() || this.Document.IsRequestRedraw;
1155 this.Refresh(this._View.PageBound);
1157 this.Refresh(this._View.GetCurrentCaretRect());
1160 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1162 if (this.horizontalScrollBar == null)
1165 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
1166 toX = this.horizontalScrollBar.Value;
1168 toX = -this.horizontalScrollBar.Value;
1169 this.Controller.ScrollByPixel(ScrollDirection.Left, (int)toX, false, false);
1173 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1175 if (this.verticalScrollBar == null)
1177 this.Controller.Scroll(this.Document.Src.X, (int)this.verticalScrollBar.Value, false, false);
1181 void View_SrcChanged(object sender, EventArgs e)
1183 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1185 EditView view = this._View;
1186 if (view.Src.Row > this.Document.LayoutLines.Count)
1187 this.verticalScrollBar.Maximum = this.Document.LayoutLines.Count - 1;
1188 double absoulteX = Math.Abs(view.Src.X);
1189 if(absoulteX > this.horizontalScrollBar.Maximum)
1190 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1191 if(view.Src.Row != this.verticalScrollBar.Value)
1192 this.verticalScrollBar.Value = view.Src.Row;
1193 if (view.Src.X != this.horizontalScrollBar.Value)
1194 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1197 void Controller_SelectionChanged(object sender, EventArgs e)
1199 this._View.CaretBlink = this._View.CaretBlink;
1200 this.CaretMoved(this, null);
1201 //こうしないと選択できなくなってしまう
1202 this.isNotifyChanged = true;
1203 SetValue(SelectedTextProperty, this._Controller.SelectedText);
1204 SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
1205 SetValue(CaretPostionProperty, this.Document.CaretPostion);
1206 this.isNotifyChanged = false;
1207 if (this.textStore.IsLocked() == false)
1208 this.textStore.NotifySelectionChanged();
1211 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1213 this.Resize(this.image.ActualWidth, this.image.ActualHeight);
1218 bool Resize(double width, double height)
1220 if (width == 0 || height == 0)
1221 throw new ArgumentOutOfRangeException();
1222 if (this.Render.Resize(width, height))
1224 double scale = this.Render.GetScale();
1225 // RenderはレタリングはDIPだが、widthとheightの値はDPI依存なのでDIPに変換する
1226 this._View.PageBound = new Rectangle(0, 0, width / scale, height / scale);
1228 if (this.horizontalScrollBar != null)
1230 this.horizontalScrollBar.LargeChange = this._View.PageBound.Width;
1231 this.horizontalScrollBar.Maximum = this._View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1233 if (this.verticalScrollBar != null)
1235 this.verticalScrollBar.LargeChange = this._View.LineCountOnScreen;
1236 this.verticalScrollBar.Maximum = this._View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1243 private void SetDocument(Document value)
1248 Document old_doc = this._Document;
1250 if (this._Document != null)
1252 old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
1253 old_doc.LoadProgress -= Document_LoadProgress;
1254 old_doc.SelectionChanged -= new EventHandler(Controller_SelectionChanged);
1255 old_doc.AutoCompleteChanged -= _Document_AutoCompleteChanged;
1256 oldLength = old_doc.Length;
1257 if (this._Document.AutoComplete != null)
1259 ((AutoCompleteBox)this._Document.AutoComplete).TargetPopup = null;
1260 this._Document.AutoComplete.GetPostion = null;
1261 this._Document.AutoComplete = null;
1265 this._Document = value;
1266 this._Document.LayoutLines.Render = this.Render;
1267 this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
1268 this._Document.LoadProgress += Document_LoadProgress;
1269 this._Document.AutoCompleteChanged += _Document_AutoCompleteChanged;
1270 if (this._Document.AutoComplete != null && this.Document.AutoComplete.GetPostion == null)
1271 this._Document_AutoCompleteChanged(this.Document, null);
1272 //初期化が終わっていればすべて存在する
1273 if (this.Controller != null && this._View != null && this.textStore != null)
1275 this._Document.SelectionChanged += new EventHandler(Controller_SelectionChanged);
1277 this.Controller.Document = value;
1278 this._View.Document = value;
1279 this.Controller.AdjustCaret();
1280 this.textStore.NotifyTextChanged(oldLength, value.Length);
1282 //依存プロパティとドキュメント内容が食い違っているので再設定する
1283 this.ShowFullSpace = value.ShowFullSpace;
1284 this.ShowHalfSpace = value.ShowHalfSpace;
1285 this.ShowLineBreak = value.ShowLineBreak;
1286 this.ShowTab = value.ShowTab;
1287 this.FlowDirection = value.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
1288 this.IndentMode = value.IndentMode;
1289 this.DrawCaretLine = !value.HideLineMarker;
1290 this.InsertMode = value.InsertMode;
1291 this.DrawRuler = !value.HideRuler;
1292 this.DrawLineNumber = value.DrawLineNumber;
1293 this.MarkURL = value.UrlMark;
1294 this.LineBreakMethod = value.LineBreak;
1295 this.LineBreakCharCount = value.LineBreakCharCount;
1296 this.TabChars = value.TabStops;
1302 private void _Document_AutoCompleteChanged(object sender, EventArgs e)
1304 Document doc = (Document)sender;
1305 ((AutoCompleteBox)this._Document.AutoComplete).TargetPopup = this.popup;
1306 this._Document.AutoComplete.GetPostion = (tp, edoc) =>
1308 var p = this._View.GetPostionFromTextPoint(tp);
1309 int height = (int)this.Render.emSize.Height;
1311 return PointToScreen(this.TranslatePoint(p.Scale(Util.GetScale()), this));
1316 /// プロパティーが変更されたときに呼ばれます
1318 /// <param name="e">イベントパラメーター</param>
1319 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
1321 switch (e.Property.Name)
1324 this.SetDocument(this.Document);
1327 this._View.Hilighter = this.Hilighter;
1329 case "TextAntialiasMode":
1330 this.Render.TextAntialiasMode = this.TextAntialiasMode;
1332 case "FoldingStrategy":
1333 this._View.LayoutLines.FoldingStrategy = this.FoldingStrategy;
1335 case "SelectedText":
1336 if (!this.isNotifyChanged)
1337 this._Controller.SelectedText = this.SelectedText;
1340 this._Controller.IndentMode = this.IndentMode;
1343 if(!this.isNotifyChanged)
1344 this.Select(this.Selection.Index, this.Selection.Length);
1346 case "CaretPostion":
1347 if (!this.isNotifyChanged)
1348 this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
1350 case "LineBreakMethod":
1351 this.Document.LineBreak = this.LineBreakMethod;
1353 case "LineBreakCharCount":
1354 this.Document.LineBreakCharCount = this.LineBreakCharCount;
1357 this._View.InsertMode = this.InsertMode;
1360 this.Document.TabStops = this.TabChars;
1362 case "RectSelectMode":
1363 this._Controller.RectSelection = this.RectSelectMode;
1366 this._View.HideCaret = !this.DrawCaret;
1368 case "DrawCaretLine":
1369 this._View.HideLineMarker = !this.DrawCaretLine;
1371 case "DrawLineNumber":
1372 this.Document.DrawLineNumber = this.DrawLineNumber;
1375 this.Render.FontFamily = this.FontFamily;
1378 this.Render.FontSize = this.FontSize;
1381 this.Render.FontStyle = this.FontStyle;
1384 this.Render.FontWeigth = this.FontWeight;
1387 this.Render.Foreground = D2DRender.ToColor4(this.Foreground);
1389 case "HilightForeground":
1390 this.Render.HilightForeground = D2DRender.ToColor4(this.HilightForeground);
1393 this.Render.Background = D2DRender.ToColor4(this.Background);
1396 this.Render.ControlChar =D2DRender.ToColor4( this.ControlChar);
1399 this.Render.Hilight = D2DRender.ToColor4(this.Hilight);
1402 this.Render.Keyword1 = D2DRender.ToColor4(this.Keyword1);
1405 this.Render.Keyword2 = D2DRender.ToColor4(this.Keyword2);
1408 this.Render.Comment = D2DRender.ToColor4(this.Comment);
1411 this.Render.Literal = D2DRender.ToColor4(this.Literal);
1414 this.Render.Url = D2DRender.ToColor4(this.URL);
1417 this.Render.InsertCaret = D2DRender.ToColor4(this.InsertCaret);
1419 case "OverwriteCaret":
1420 this.Render.OverwriteCaret = D2DRender.ToColor4(this.OverwriteCaret);
1423 this._View.Padding = new Padding((int)this.Padding.Left, (int)this.Padding.Top, (int)this.Padding.Right, (int)this.Padding.Bottom);
1426 this.Render.LineMarker = D2DRender.ToColor4(this.LineMarker);
1429 this.Document.UrlMark = this.MarkURL;
1431 case "ShowFullSpace":
1432 this.Document.ShowFullSpace = this.ShowFullSpace;
1434 case "ShowHalfSpace":
1435 this.Document.ShowHalfSpace = this.ShowHalfSpace;
1438 this.Document.ShowTab = this.ShowTab;
1440 case "ShowLineBreak":
1441 this.Document.ShowLineBreak = this.ShowLineBreak;
1443 case "FlowDirection":
1444 this.Document.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;
1445 this.horizontalScrollBar.FlowDirection = this.FlowDirection;
1448 this.Document.HideRuler = !this.DrawRuler;
1449 this._Controller.JumpCaret(this.Document.CaretPostion.row, this.Document.CaretPostion.col);
1452 this.Render.UpdateArea = D2DRender.ToColor4(this.UpdateArea);
1455 this.Render.LineNumber = D2DRender.ToColor4(this.LineNumber);
1458 base.OnPropertyChanged(e);
1463 internal EditView View
1471 internal Controller Controller
1475 return this._Controller;
1480 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1482 public TextAntialiasMode TextAntialiasMode
1484 get { return (TextAntialiasMode)GetValue(TextAntialiasModeProperty); }
1485 set { SetValue(TextAntialiasModeProperty, value); }
1489 /// TextAntialiasModeの依存プロパティを表す
1491 public static readonly DependencyProperty TextAntialiasModeProperty =
1492 DependencyProperty.Register("TextAntialiasMode", typeof(TextAntialiasMode), typeof(FooTextBox), new PropertyMetadata(TextAntialiasMode.Default));
1497 public IHilighter Hilighter
1499 get { return (IHilighter)GetValue(HilighterProperty); }
1500 set { SetValue(HilighterProperty, value); }
1504 /// Hilighterの依存プロパティを表す
1506 public static readonly DependencyProperty HilighterProperty =
1507 DependencyProperty.Register("Hilighter", typeof(IHilighter), typeof(FooTextBox), new PropertyMetadata(null));
1510 /// フォールティングを作成するインターフェイスを表す
1512 public IFoldingStrategy FoldingStrategy
1514 get { return (IFoldingStrategy)GetValue(FoldingStrategyProperty); }
1515 set { SetValue(FoldingStrategyProperty, value); }
1519 /// FoldingStrategyの依存プロパティ
1521 public static readonly DependencyProperty FoldingStrategyProperty =
1522 DependencyProperty.Register("FoldingStrategy", typeof(IFoldingStrategy), typeof(FooTextBox), new PropertyMetadata(null));
1528 public MarkerPatternSet MarkerPatternSet
1532 return this.Document.MarkerPatternSet;
1539 public Document Document
1541 get { return (Document)GetValue(DocumentProperty); }
1542 set { SetValue(DocumentProperty, value); }
1548 public static readonly DependencyProperty DocumentProperty =
1549 DependencyProperty.Register("Document", typeof(Document), typeof(FooTextBox), new PropertyMetadata(null));
1555 public LineToIndexTable LayoutLineCollection
1557 get { return this._View.LayoutLines; }
1563 public string SelectedText
1565 get { return (string)GetValue(SelectedTextProperty); }
1566 set { SetValue(SelectedTextProperty, value); }
1570 /// SelectedTextの依存プロパティを表す
1572 public static readonly DependencyProperty SelectedTextProperty =
1573 DependencyProperty.Register("SelectedText", typeof(string), typeof(FooTextBox), new PropertyMetadata(null));
1578 public IndentMode IndentMode
1580 get { return (IndentMode)GetValue(IndentModeProperty); }
1581 set { SetValue(IndentModeProperty, value); }
1585 /// IndentModeの依存プロパティを表す
1587 public static readonly DependencyProperty IndentModeProperty =
1588 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab));
1594 /// Lengthが0の場合はキャレット位置を表します。
1595 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1597 public TextRange Selection
1599 get { return (TextRange)GetValue(SelectionProperty); }
1600 set { SetValue(SelectionProperty, value); }
1604 /// Selectionの依存プロパティを表す
1606 public static readonly DependencyProperty SelectionProperty =
1607 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null));
1612 public double MagnificationPower
1614 get { return (double)GetValue(MagnificationPowerPropertyKey.DependencyProperty); }
1620 public static readonly DependencyPropertyKey MagnificationPowerPropertyKey =
1621 DependencyProperty.RegisterReadOnly("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0));
1626 public new FlowDirection FlowDirection
1628 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1629 set { SetValue(FlowDirectionProperty, value); }
1633 /// レタリング方向を表す。これは依存プロパティです
1635 public new static readonly DependencyProperty FlowDirectionProperty =
1636 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight));
1639 /// キャレット位置を表す。これは依存プロパティです
1641 public TextPoint CaretPostion
1643 get { return (TextPoint)GetValue(CaretPostionProperty); }
1644 set { SetValue(CaretPostionProperty, value); }
1648 /// CaretPostionの依存プロパティを表す
1650 public static readonly DependencyProperty CaretPostionProperty =
1651 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(TextPoint.Null));
1654 /// デフォルトの文字色を表す。これは依存プロパティです
1656 public new System.Windows.Media.Color Foreground
1658 get { return (System.Windows.Media.Color)GetValue(ForegroundProperty); }
1659 set { SetValue(ForegroundProperty, value); }
1663 /// Foregroundの依存プロパティを表す
1665 public new static readonly DependencyProperty ForegroundProperty =
1666 DependencyProperty.Register("Foreground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1669 /// 背景色を表す。これは依存プロパティです
1671 public new System.Windows.Media.Color Background
1673 get { return (System.Windows.Media.Color)GetValue(BackgroundProperty); }
1674 set { SetValue(BackgroundProperty, value); }
1678 /// Backgroundの依存プロパティを表す
1680 public new static readonly DependencyProperty BackgroundProperty =
1681 DependencyProperty.Register("Background", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowColor));
1684 /// 選択時の文字色を表す。これは依存プロパティです
1686 public System.Windows.Media.Color HilightForeground
1688 get { return (System.Windows.Media.Color)GetValue(HilightForegroundProperty); }
1689 set { SetValue(HilightForegroundProperty, value); }
1693 /// ControlCharの依存プロパティを表す
1695 public static readonly DependencyProperty HilightForegroundProperty =
1696 DependencyProperty.Register("HilightForeground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.White));
1699 /// コントロールコードの文字色を表す。これは依存プロパティです
1701 public System.Windows.Media.Color ControlChar
1703 get { return (System.Windows.Media.Color)GetValue(ControlCharProperty); }
1704 set { SetValue(ControlCharProperty, value); }
1708 /// ControlCharの依存プロパティを表す
1710 public static readonly DependencyProperty ControlCharProperty =
1711 DependencyProperty.Register("ControlChar", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Gray));
1714 /// 選択時の背景色を表す。これは依存プロパティです
1716 public System.Windows.Media.Color Hilight
1718 get { return (System.Windows.Media.Color)GetValue(HilightProperty); }
1719 set { SetValue(HilightProperty, value); }
1723 /// Hilightの依存プロパティを表す
1725 public static readonly DependencyProperty HilightProperty =
1726 DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));
1729 /// キーワード1の文字色を表す。これは依存プロパティです
1731 public System.Windows.Media.Color Keyword1
1733 get { return (System.Windows.Media.Color)GetValue(Keyword1Property); }
1734 set { SetValue(Keyword1Property, value); }
1738 /// Keyword1の依存プロパティを表す
1740 public static readonly DependencyProperty Keyword1Property =
1741 DependencyProperty.Register("Keyword1", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1744 /// キーワード2の文字色を表す。これは依存プロパティです
1746 public System.Windows.Media.Color Keyword2
1748 get { return (System.Windows.Media.Color)GetValue(Keyword2Property); }
1749 set { SetValue(Keyword2Property, value); }
1753 /// Keyword2の依存プロパティを表す
1755 public static readonly DependencyProperty Keyword2Property =
1756 DependencyProperty.Register("Keyword2", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DarkCyan));
1759 /// コメントの文字色を表す。これは依存プロパティです
1761 public System.Windows.Media.Color Comment
1763 get { return (System.Windows.Media.Color)GetValue(CommentProperty); }
1764 set { SetValue(CommentProperty, value); }
1768 /// Commentの依存プロパティを表す
1770 public static readonly DependencyProperty CommentProperty =
1771 DependencyProperty.Register("Comment", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Green));
1774 /// 文字リテラルの文字色を表す。これは依存プロパティです
1776 public System.Windows.Media.Color Literal
1778 get { return (System.Windows.Media.Color)GetValue(LiteralProperty); }
1779 set { SetValue(LiteralProperty, value); }
1783 /// Literalの依存プロパティを表す
1785 public static readonly DependencyProperty LiteralProperty =
1786 DependencyProperty.Register("Literal", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Brown));
1789 /// URLの文字色を表す。これは依存プロパティです
1791 public System.Windows.Media.Color URL
1793 get { return (System.Windows.Media.Color)GetValue(URLProperty); }
1794 set { SetValue(URLProperty, value); }
1800 public static readonly DependencyProperty URLProperty =
1801 DependencyProperty.Register("URL", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1807 public System.Windows.Media.Color LineMarker
1809 get { return (System.Windows.Media.Color)GetValue(LineMarkerProperty); }
1810 set { SetValue(LineMarkerProperty, value); }
1814 /// LineMarkerの依存プロパティを表す
1816 public static readonly DependencyProperty LineMarkerProperty =
1817 DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));
1820 /// 挿入モード時のキャレットの色を表す
1822 public System.Windows.Media.Color InsertCaret
1824 get { return (System.Windows.Media.Color)GetValue(InsertCaretProperty); }
1825 set { SetValue(InsertCaretProperty, value); }
1829 /// InsertCaretの依存プロパティを表す
1831 public static readonly DependencyProperty InsertCaretProperty =
1832 DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1837 public System.Windows.Media.Color UpdateArea
1839 get { return (System.Windows.Media.Color)GetValue(UpdateAreaProperty); }
1840 set { SetValue(UpdateAreaProperty, value); }
1844 /// UpdateAreaの依存プロパティを表す
1846 public static readonly DependencyProperty UpdateAreaProperty =
1847 DependencyProperty.Register("UpdateArea", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));
1850 /// 上書きモード時のキャレット職を表す
1852 public System.Windows.Media.Color OverwriteCaret
1854 get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }
1855 set { SetValue(OverwriteCaretProperty, value); }
1859 /// OverwriteCaretの依存プロパティを表す
1861 public static readonly DependencyProperty OverwriteCaretProperty =
1862 DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1867 public System.Windows.Media.Color LineNumber
1869 get { return (System.Windows.Media.Color)GetValue(LineNumberProperty); }
1870 set { SetValue(LineNumberProperty, value); }
1874 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1876 public static readonly DependencyProperty LineNumberProperty =
1877 DependencyProperty.Register("LineNumber", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray));
1880 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1882 public bool InsertMode
1884 get { return (bool)GetValue(InsertModeProperty); }
1885 set { SetValue(InsertModeProperty, value); }
1889 /// InsertModeの依存プロパティを表す
1891 public static readonly DependencyProperty InsertModeProperty =
1892 DependencyProperty.Register("InsertMode",
1895 new FrameworkPropertyMetadata(true));
1898 /// タブの文字数を表す。これは依存プロパティです
1902 get { return (int)GetValue(TabCharsProperty); }
1903 set { SetValue(TabCharsProperty, value); }
1907 /// TabCharsの依存プロパティを表す
1909 public static readonly DependencyProperty TabCharsProperty =
1910 DependencyProperty.Register("TabChars",
1913 new FrameworkPropertyMetadata(4));
1916 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1918 public bool RectSelectMode
1920 get { return (bool)GetValue(RectSelectModeProperty); }
1921 set { SetValue(RectSelectModeProperty, value); }
1925 /// RectSelectModeの依存プロパティを表す
1927 public static readonly DependencyProperty RectSelectModeProperty =
1928 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1934 /// 変更した場合、レイアウトの再構築を行う必要があります
1936 public LineBreakMethod LineBreakMethod
1938 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1939 set { SetValue(LineBreakProperty, value); }
1943 /// LineBreakMethodの依存プロパティを表す
1945 public static readonly DependencyProperty LineBreakProperty =
1946 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None));
1950 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1953 /// 変更した場合、レイアウトの再構築を行う必要があります
1955 public int LineBreakCharCount
1957 get { return (int)GetValue(LineBreakCharCountProperty); }
1958 set { SetValue(LineBreakCharCountProperty, value); }
1962 /// LineBreakCharCountの依存プロパティを表す
1964 public static readonly DependencyProperty LineBreakCharCountProperty =
1965 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
1968 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1970 public bool DrawCaret
1972 get { return (bool)GetValue(DrawCaretProperty); }
1973 set { SetValue(DrawCaretProperty, value); }
1977 /// DrawCaretの依存プロパティを表す
1979 public static readonly DependencyProperty DrawCaretProperty =
1980 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
1984 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1986 public bool DrawCaretLine
1988 get { return (bool)GetValue(DrawCaretLineProperty); }
1989 set { SetValue(DrawCaretLineProperty, value); }
1993 /// DrawCaretLineの依存プロパティを表す
1995 public static readonly DependencyProperty DrawCaretLineProperty =
1996 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1999 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
2001 public bool DrawLineNumber
2003 get { return (bool)GetValue(DrawLineNumberProperty); }
2004 set { SetValue(DrawLineNumberProperty, value); }
2008 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
2010 public bool DrawRuler
2012 get { return (bool)GetValue(DrawRulerProperty); }
2013 set { SetValue(DrawRulerProperty, value); }
2017 /// DrawRulerの依存プロパティを表す
2019 public static readonly DependencyProperty DrawRulerProperty =
2020 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
2024 /// DrawLineNumberの依存プロパティを表す
2026 public static readonly DependencyProperty DrawLineNumberProperty =
2027 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
2030 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
2034 get { return (bool)GetValue(MarkURLProperty); }
2035 set { SetValue(MarkURLProperty, value); }
2039 /// MarkURLの依存プロパティを表す
2041 public static readonly DependencyProperty MarkURLProperty =
2042 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
2045 /// 全角スペースを表示するなら真。そうでないなら偽
2047 public bool ShowFullSpace
2049 get { return (bool)GetValue(ShowFullSpaceProperty); }
2050 set { SetValue(ShowFullSpaceProperty, value); }
2054 /// ShowFullSpaceの依存プロパティを表す
2056 public static readonly DependencyProperty ShowFullSpaceProperty =
2057 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
2060 /// 半角スペースを表示するなら真。そうでないなら偽
2062 public bool ShowHalfSpace
2064 get { return (bool)GetValue(ShowHalfSpaceProperty); }
2065 set { SetValue(ShowHalfSpaceProperty, value); }
2069 /// ShowHalfSpaceの依存プロパティを表す
2071 public static readonly DependencyProperty ShowHalfSpaceProperty =
2072 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
2075 /// タブを表示するなら真。そうでないなら偽
2079 get { return (bool)GetValue(ShowTabProperty); }
2080 set { SetValue(ShowTabProperty, value); }
2084 /// ShowTabの依存プロパティを表す
2086 public static readonly DependencyProperty ShowTabProperty =
2087 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
2090 /// 改行マークを表示するなら真。そうでないなら偽
2092 public bool ShowLineBreak
2094 get { return (bool)GetValue(ShowLineBreakProperty); }
2095 set { SetValue(ShowLineBreakProperty, value); }
2099 /// ShowLineBreakの依存プロパティを表す
2101 public static readonly DependencyProperty ShowLineBreakProperty =
2102 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
2107 /// マウスボタン関連のイベントクラス
2109 public sealed class FooMouseButtonEventArgs : MouseButtonEventArgs
2112 /// イベントが発生したドキュメントのインデックス
2123 /// <param name="mouse">マウスデバイス</param>
2124 /// <param name="timestamp">タイムスタンプ</param>
2125 /// <param name="button">ボタン</param>
2126 /// <param name="stylusDevice">スタイラスデバイス</param>
2127 /// <param name="index">インデックス</param>
2128 public FooMouseButtonEventArgs(MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice, int index)
2129 : base(mouse, timestamp, button, stylusDevice)
2137 public sealed class FooMouseEventArgs : MouseEventArgs
2140 /// イベントが発生したドキュメントのインデックス
2151 /// <param name="mouse">マウスデバイス</param>
2152 /// <param name="timestamp">タイムスタンプ</param>
2153 /// <param name="stylusDevice">スタイラスデバイス</param>
2154 /// <param name="index">インデックス</param>
2155 public FooMouseEventArgs(MouseDevice mouse,
2157 StylusDevice stylusDevice,
2159 : base(mouse, timestamp, stylusDevice)