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;
53 DefaultStyleKeyProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(typeof(FooTextBox)));
54 KeyboardNavigation.IsTabStopProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(true));
55 KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(KeyboardNavigationMode.None));
63 this.popup = new Popup();
65 this.image = new Image();
66 this.image.Stretch = Stretch.Fill;
67 this.image.HorizontalAlignment = HorizontalAlignment.Left;
68 this.image.VerticalAlignment = VerticalAlignment.Top;
70 this.textStore = new TextStore();
71 this.textStore.IsLoading += textStore_IsLoading;
72 this.textStore.IsReadOnly += textStore_IsReadOnly;
73 this.textStore.GetStringLength += () => this.Document.Length;
74 this.textStore.GetString += _textStore_GetString;
75 this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;
76 this.textStore.SetSelectionIndex += _textStore_SetSelectionIndex;
77 this.textStore.InsertAtSelection += _textStore_InsertAtSelection;
78 this.textStore.GetHWnd += _textStore_GetHWnd;
79 this.textStore.GetScreenExtent += _textStore_GetScreenExtent;
80 this.textStore.GetStringExtent += _textStore_GetStringExtent;
81 this.textStore.CompositionStarted += textStore_CompositionStarted;
82 this.textStore.CompositionUpdated += textStore_CompositionUpdated;
83 this.textStore.CompositionEnded += textStore_CompositionEnded;
85 this.Render = new D2DRender(this, 200, 200,this.image);
86 this.Render.ShowFullSpace = this.ShowFullSpace;
87 this.Render.ShowHalfSpace = this.ShowHalfSpace;
88 this.Render.ShowTab = this.ShowTab;
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;
102 this._Controller = new Controller(this.Document, this.View);
103 this._Document.SelectionChanged += new EventHandler(Controller_SelectionChanged);
105 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, CopyCommand, CanExecute));
106 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, CutCommand, CanExecute));
107 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, PasteCommand, CanExecute));
108 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, DeleteCommand, CanExecute));
109 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, SelectAllCommand, CanExecute));
110 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, UndoCommand, CanExecute));
111 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, RedoCommand, CanExecute));
112 this.CommandBindings.Add(new CommandBinding(EditingCommands.ToggleInsert, ToggleInsertCommand, CanExecute));
113 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleRectSelectMode, ToggleRectSelectCommand, CanExecute));
114 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleFlowDirection, ToggleFlowDirectionCommand, CanExecute));
115 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleCodePoint, ToggleCodePointCommand, CanExecute));
117 this.InputBindings.Add(new InputBinding(ApplicationCommands.Copy, new KeyGesture(Key.C, ModifierKeys.Control)));
118 this.InputBindings.Add(new InputBinding(ApplicationCommands.Cut, new KeyGesture(Key.X, ModifierKeys.Control)));
119 this.InputBindings.Add(new InputBinding(ApplicationCommands.Paste, new KeyGesture(Key.V, ModifierKeys.Control)));
120 this.InputBindings.Add(new InputBinding(ApplicationCommands.Delete, new KeyGesture(Key.Delete, ModifierKeys.None)));
121 this.InputBindings.Add(new InputBinding(ApplicationCommands.SelectAll, new KeyGesture(Key.A, ModifierKeys.Control)));
122 this.InputBindings.Add(new InputBinding(ApplicationCommands.Undo, new KeyGesture(Key.Z, ModifierKeys.Control)));
123 this.InputBindings.Add(new InputBinding(ApplicationCommands.Redo, new KeyGesture(Key.Y, ModifierKeys.Control)));
124 this.InputBindings.Add(new InputBinding(EditingCommands.ToggleInsert, new KeyGesture(Key.Insert, ModifierKeys.None)));
125 this.InputBindings.Add(new InputBinding(FooTextBoxCommands.ToggleCodePoint, new KeyGesture(Key.X, ModifierKeys.Alt)));
127 this.timer = new DispatcherTimer();
128 this.timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
129 this.timer.Tick += new EventHandler(timer_Tick);
131 this.Loaded += new RoutedEventHandler(FooTextBox_Loaded);
133 this.AutoIndentHooker = (s,e)=>{};
135 SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
137 this.SystemEvents_UserPreferenceChanged(null, new UserPreferenceChangedEventArgs(UserPreferenceCategory.Keyboard));
139 this.CaretMoved += (s, e) => { };
141 this.IsManipulationEnabled = true;
149 //Dispose(false)を呼び出すと落ちる
154 /// オートインデントを行うためのイベント
157 public AutoIndentHookerHandler AutoIndentHooker;
162 public override void OnApplyTemplate()
164 base.OnApplyTemplate();
166 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
169 Grid.SetRow(this.image, 0);
170 Grid.SetColumn(this.image, 0);
171 grid.Children.Add(this.image);
173 Grid.SetRow(this.popup, 0);
174 Grid.SetColumn(this.popup, 0);
175 grid.Children.Add(this.popup);
176 //this.popup.PlacementTarget = this;
177 this.popup.Placement = PlacementMode.Absolute;
180 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
181 if (this.horizontalScrollBar != null)
183 this.horizontalScrollBar.SmallChange = 10;
184 this.horizontalScrollBar.LargeChange = 100;
185 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
186 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
188 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
189 if (this.verticalScrollBar != null)
191 this.verticalScrollBar.SmallChange = 1;
192 this.verticalScrollBar.LargeChange = 10;
193 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
194 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
201 /// <param name="start">開始インデックス</param>
202 /// <param name="length">長さ</param>
203 public void Select(int start, int length)
205 this.Document.Select(start, length);
206 this.textStore.NotifySelectionChanged();
210 /// キャレットを指定した行に移動させます
212 /// <param name="index">インデックス</param>
213 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
214 public void JumpCaret(int index)
216 this._Controller.JumpCaret(index);
219 /// キャレットを指定した行と桁に移動させます
221 /// <param name="row">行番号</param>
222 /// <param name="col">桁</param>
223 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
224 public void JumpCaret(int row, int col)
226 this._Controller.JumpCaret(row, col);
230 /// 選択中のテキストをクリップボードにコピーします
234 string text = this._Controller.SelectedText;
235 if (text != null && text != string.Empty)
236 Clipboard.SetText(text);
240 /// 選択中のテキストをクリップボードに切り取ります
244 string text = this._Controller.SelectedText;
245 if (text != null && text != string.Empty)
247 Clipboard.SetText(text);
248 this._Controller.SelectedText = "";
257 if (Clipboard.ContainsText() == false)
259 string text = Clipboard.GetText();
260 this._Controller.SelectedText = text;
266 public void DeSelectAll()
268 this._Controller.DeSelectAll();
269 this.textStore.NotifySelectionChanged();
275 /// <param name="tp">テキストポイント</param>
276 /// <returns>座標</returns>
277 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
278 public System.Windows.Point GetPostionFromTextPoint(TextPoint tp)
280 if (this.Document.FireUpdateEvent == false)
281 throw new InvalidOperationException("");
282 return this.View.GetPostionFromTextPoint(tp);
286 /// 対応するテキストポイントを返します
288 /// <param name="p">クライアント領域の原点を左上とする座標</param>
289 /// <returns>テキストポイント</returns>
290 public TextPoint GetTextPointFromPostion(System.Windows.Point p)
292 if (this.Document.FireUpdateEvent == false)
293 throw new InvalidOperationException("");
294 return this.View.GetTextPointFromPostion(p);
300 /// <param name="row">レイアウト行</param>
301 /// <returns>行の高さ</returns>
302 public double GetLineHeight(int row)
304 if (this.Document.FireUpdateEvent == false)
305 throw new InvalidOperationException("");
306 return this.View.LayoutLines.GetLayout(row).Height;;
310 /// インデックスに対応する座標を得ます
312 /// <param name="index">インデックス</param>
313 /// <returns>座標を返す</returns>
314 public System.Windows.Point GetPostionFromIndex(int index)
316 if (this.Document.FireUpdateEvent == false)
317 throw new InvalidOperationException("");
318 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
319 return this.View.GetPostionFromTextPoint(tp);
325 /// <param name="p">座標</param>
326 /// <returns>インデックスを返す</returns>
327 public int GetIndexFromPostion(System.Windows.Point p)
329 if (this.Document.FireUpdateEvent == false)
330 throw new InvalidOperationException("");
331 TextPoint tp = this.View.GetTextPointFromPostion(p);
332 return this.View.GetIndexFromLayoutLine(tp);
338 public void Refresh()
340 this.Refresh(this.View.PageBound);
344 /// レイアウト行をすべて破棄し、再度レイアウトを行う
346 public void PerfomLayouts()
348 this.View.PerfomLayouts();
354 /// <param name="row">行</param>
355 /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
356 public void ScrollIntoView(int row, bool alignTop)
358 this.View.ScrollIntoView(row, alignTop);
362 /// ストリームからドキュメントを構築する
364 /// <param name="tr">TextReader</param>
365 /// <param name="token">キャンセル用トークン</param>
366 /// <returns>Taskオブジェクト</returns>
367 public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)
369 await this.Document.LoadAsync(tr, token);
373 /// ファイルからドキュメントを構築する
375 /// <param name="filepath">ファイルパス</param>
376 /// <param name="enc">エンコード</param>
377 /// <param name="token">キャンセル用トークン</param>
378 /// <returns>Taskオブジェクト</returns>
379 public async Task LoadFileAsync(string filepath, Encoding enc,System.Threading.CancellationTokenSource token)
381 var fs = new System.IO.StreamReader(filepath, enc);
382 await this.Document.LoadAsync(fs, token);
386 private void Document_LoadProgress(object sender, ProgressEventArgs e)
388 if (e.state == ProgressState.Start)
390 this.IsEnabled = false;
392 else if (e.state == ProgressState.Complete)
394 TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
395 if (this.verticalScrollBar != null)
396 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
397 this.View.CalculateLineCountOnScreen();
398 this.IsEnabled = true;
403 /// ドキュメントの内容をファイルに保存する
405 /// <param name="filepath">ファイルパス</param>
406 /// <param name="newLine">改行コード</param>
407 /// <param name="enc">エンコード</param>
408 /// <param name="token">キャンセル用トークン</param>
409 /// <returns>Taskオブジェクト</returns>
410 public async Task SaveFile(string filepath, Encoding enc,string newLine, System.Threading.CancellationTokenSource token)
412 var fs = new System.IO.StreamWriter(filepath, false , enc);
413 fs.NewLine = newLine;
414 await this.Document.SaveAsync(fs, token);
421 public void Dispose()
426 GC.SuppressFinalize(this);
427 this.disposed = true;
433 /// <param name="disposing">真ならマネージドリソースも開放し、そうでないならアンマネージドリソースのみを開放する</param>
434 void Dispose(bool disposing)
438 this.textStore.Dispose();
441 this.Render.Dispose();
443 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
446 void Refresh(Rectangle updateRect)
448 if (this.disposed || this.Visibility == Visibility.Collapsed)
451 this.Render.DrawContent(this.View, this.IsEnabled, updateRect);
452 this.Document.IsRequestRedraw = false;
456 void CanExecute(object sender, CanExecuteRoutedEventArgs e)
458 e.CanExecute = this.IsEnabled;
461 void ToggleCodePointCommand(object sender, RoutedEventArgs e)
463 if (!this._Controller.ConvertToChar())
464 this._Controller.ConvertToCodePoint();
468 void CopyCommand(object sender, RoutedEventArgs e)
473 void CutCommand(object sender, RoutedEventArgs e)
479 void PasteCommand(object sender, RoutedEventArgs e)
485 void DeleteCommand(object sender, RoutedEventArgs e)
487 int oldLength = this.Document.Length;
488 this._Controller.DoDeleteAction();
492 void SelectAllCommand(object sender, RoutedEventArgs e)
494 this.Select(0, this.Document.Length);
498 void UndoCommand(object sender, RoutedEventArgs e)
500 int oldLength = this.Document.Length;
501 this.Document.UndoManager.undo();
505 void RedoCommand(object sender, RoutedEventArgs e)
507 int oldLength = this.Document.Length;
508 this.Document.UndoManager.redo();
512 void ToggleInsertCommand(object sender, RoutedEventArgs e)
515 this.InsertMode = false;
517 this.InsertMode = true;
521 void ToggleRectSelectCommand(object sender, RoutedEventArgs e)
523 if (this.RectSelectMode)
524 this.RectSelectMode = false;
526 this.RectSelectMode = true;
529 void ToggleFlowDirectionCommand(object sender, RoutedEventArgs e)
531 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
532 this.FlowDirection = System.Windows.FlowDirection.RightToLeft;
534 this.FlowDirection = System.Windows.FlowDirection.LeftToRight;
539 internal TextStore TextStore
541 get { return this.textStore; }
544 bool textStore_IsReadOnly()
549 bool textStore_IsLoading()
554 void textStore_CompositionEnded()
556 TextStoreHelper.EndCompostion(this.Document);
560 void textStore_CompositionUpdated(int start, int end)
562 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
565 bool textStore_CompositionStarted()
567 bool result = TextStoreHelper.StartCompstion(this.Document);
569 System.Media.SystemSounds.Beep.Play();
573 string _textStore_GetString(int start, int length)
575 return this.Document.ToString(start, length);
578 IntPtr _textStore_GetHWnd()
580 var hwndSource = HwndSource.FromVisual(this) as HwndSource;
581 if (hwndSource != null)
582 return hwndSource.Handle;
587 void _textStore_GetStringExtent(
591 out POINT o_bottomRight
594 Point startPos, endPos;
595 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
597 double scale = this.Render.GetScale();
599 startPos = PointToScreen(this.TranslatePoint(startPos.Scale(scale), this));
600 endPos = PointToScreen(this.TranslatePoint(endPos.Scale(scale), this));
602 o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);
603 o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);
606 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
608 var pointTopLeft = new Point(0, 0);
609 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
611 pointTopLeft = PointToScreen(pointTopLeft);
612 pointBottomRight = PointToScreen(pointBottomRight);
614 o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
615 o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
618 void _textStore_GetSelectionIndex(int start_index, int max_count, out DotNetTextStore.TextSelection[] sels)
621 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out selRange);
623 sels = new DotNetTextStore.TextSelection[1];
624 sels[0] = new DotNetTextStore.TextSelection();
625 sels[0].start = selRange.Index;
626 sels[0].end = selRange.Index + selRange.Length;
629 void _textStore_SetSelectionIndex(DotNetTextStore.TextSelection[] sels)
631 TextStoreHelper.SetSelectionIndex(this._Controller, this.View, sels[0].start, sels[0].end);
635 void _textStore_InsertAtSelection(string i_value, ref int o_startIndex, ref int o_endIndex)
637 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
642 /// キーボードフォーカスが取得されたときに呼ばれます
644 /// <param name="e">イベントデーター</param>
645 protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
647 base.OnGotKeyboardFocus(e);
648 this.textStore.SetFocus();
649 this.View.IsFocused = true;
654 /// キーボードフォーカスが失われたときに呼ばれます
656 /// <param name="e">イベントデーター</param>
657 protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
659 base.OnLostKeyboardFocus(e);
660 this.View.IsFocused = false;
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();
684 this.AutoIndentHooker(this, null);
686 else if (e.Text == "\b")
688 this._Controller.DoBackSpaceAction();
692 if(this.IsInputString(e.Text))
693 this._Controller.DoInputString(e.Text);
700 bool IsInputString(string s)
702 foreach (char charCode in s)
704 if ((0x20 <= charCode && charCode <= 0x7e)
712 protected override void OnKeyDown(KeyEventArgs e)
714 if (this.textStore.IsLocked())
717 ModifierKeys modiferKeys = e.KeyboardDevice.Modifiers;
719 var autocomplete = this.Document.AutoComplete as AutoCompleteBox;
720 if (autocomplete != null &&
721 autocomplete.ProcessKeyDown(this,e, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift)))
727 bool movedCaret = false;
731 this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
737 this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
743 this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
749 this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
755 this._Controller.Scroll(ScrollDirection.Up,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
760 this._Controller.Scroll(ScrollDirection.Down,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
765 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
766 this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
768 this._Controller.JumpToLineHead(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
773 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
774 this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
776 this._Controller.JumpToLineEnd(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
781 int oldLength = this.Document.Length;
782 if (this.Selection.Length == 0)
783 this._Controller.DoInputChar('\t');
784 else if(this.IsPressedModifierKey(modiferKeys,ModifierKeys.Shift))
785 this._Controller.DownIndent();
787 this._Controller.UpIndent();
792 if (movedCaret && this.peer != null)
793 this.peer.OnNotifyCaretChanged();
797 bool IsPressedModifierKey(ModifierKeys keys, ModifierKeys pressed)
801 if ((keys & pressed) == pressed)
807 /// ダブルクリックされたときに呼ばれます
809 /// <param name="e">イベントパラメーター</param>
811 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
812 /// e.Handledを真にした場合、単語単位の選択が行われなくなります
814 protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
816 var p = this.GetDipFromPoint(e.GetPosition(this));
817 TextPoint tp = this.View.GetTextPointFromPostion(p);
818 if (tp == TextPoint.Null)
820 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
822 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
827 newEventArgs.RoutedEvent = e.RoutedEvent;
828 base.OnMouseDoubleClick(newEventArgs);
830 if (newEventArgs.Handled)
833 if (e.LeftButton == MouseButtonState.Pressed)
836 this.Document.SelectWord((int)index);
837 this.textStore.NotifySelectionChanged();
838 if(this.peer != null)
839 this.peer.OnNotifyCaretChanged();
845 /// マウスボタンが押されたときに呼ばれます
847 /// <param name="e">イベントパラメーター</param>
849 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
850 /// e.Handledを真にした場合、キャレットの移動処理が行われなくなります
852 protected override void OnMouseDown(MouseButtonEventArgs e)
856 var p = this.GetDipFromPoint(e.GetPosition(this));
857 TextPoint tp = this.View.GetTextPointFromPostion(p);
858 if (tp == TextPoint.Null)
860 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
862 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
867 newEventArgs.RoutedEvent = e.RoutedEvent;
868 base.OnMouseDown(newEventArgs);
870 if (newEventArgs.Handled)
873 if (e.LeftButton == MouseButtonState.Pressed)
875 FoldingItem foldingData = this.View.HitFoldingData(p.X,tp.row);
876 if (foldingData != null)
878 if (foldingData.Expand)
879 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
881 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
882 this._Controller.JumpCaret(foldingData.Start,false);
886 this._Controller.JumpCaret(tp.row, tp.col, false);
888 if (this.peer != null)
889 this.peer.OnNotifyCaretChanged();
890 this.View.IsFocused = true;
892 this.Document.SelectGrippers.BottomLeft.Enabled = false;
893 this.Document.SelectGrippers.BottomRight.Enabled = false;
899 /// マウスのボタンが離されたときに呼ばれます
901 /// <param name="e"></param>
902 protected override void OnMouseUp(MouseButtonEventArgs e)
904 this.ReleaseMouseCapture();
911 /// <param name="e">イベントパラメーター</param>
913 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
914 /// e.Handledを真にした場合、選択処理と状況に応じたカーソルの変化が行われなくなります
916 protected override void OnMouseMove(MouseEventArgs e)
918 bool leftPressed = e.LeftButton == MouseButtonState.Pressed;
920 var p = this.GetDipFromPoint(e.GetPosition(this));
922 TextPointSearchRange searchRange;
923 if (this.View.HitTextArea(p.X, p.Y))
924 searchRange = TextPointSearchRange.TextAreaOnly;
925 else if (leftPressed)
926 searchRange = TextPointSearchRange.Full;
928 searchRange = TextPointSearchRange.TextAreaOnly;
930 TextPoint tp = this.View.GetTextPointFromPostion(p, searchRange);
932 if (tp == TextPoint.Null)
938 int index = this.View.GetIndexFromLayoutLine(tp);
940 FooMouseEventArgs newEventArgs = new FooMouseEventArgs(e.MouseDevice, e.Timestamp, e.StylusDevice, index);
941 newEventArgs.RoutedEvent = e.RoutedEvent;
942 base.OnMouseMove(newEventArgs);
944 if (newEventArgs.Handled)
947 //この状態のときはカーソルがテキストエリア内にある
948 if (searchRange == TextPointSearchRange.TextAreaOnly)
950 if (this._Controller.IsMarker(tp, HilightType.Url))
951 this.Cursor = Cursors.Hand;
953 this.Cursor = Cursors.IBeam;
957 this.Cursor = Cursors.Arrow;
962 this._Controller.MoveCaretAndSelect(tp);
963 if (this.peer != null)
964 this.peer.OnNotifyCaretChanged();
969 Gripper hittedGripper;
970 bool touchScrolled = false;
973 protected override void OnTouchDown(TouchEventArgs e)
975 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
976 this.hittedGripper = this.View.HitGripperFromPoint(p);
977 this.CaptureTouch(e.TouchDevice);
981 protected override void OnTouchUp(TouchEventArgs e)
983 this.ReleaseTouchCapture(e.TouchDevice);
984 if(this.hittedGripper != null || this.touchScrolled)
986 this.hittedGripper = null;
987 this.touchScrolled = false;
991 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
992 TextPoint tp = this.View.GetTextPointFromPostion(p);
993 if (tp == TextPoint.Null)
995 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
997 FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
998 if (foldingData != null)
1000 if (foldingData.Expand)
1001 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
1003 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
1004 this._Controller.JumpCaret(foldingData.Start, false);
1008 this._Controller.JumpCaret(tp.row, tp.col, false);
1010 if (this.peer != null)
1011 this.peer.OnNotifyCaretChanged();
1012 this.View.IsFocused = true;
1014 this.Document.SelectGrippers.BottomLeft.Enabled = false;
1015 this.Document.SelectGrippers.BottomRight.Enabled = true;
1020 protected override void OnTouchMove(TouchEventArgs e)
1022 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
1023 if (this.Controller.MoveCaretAndGripper(p, this.hittedGripper))
1025 if (this.peer != null)
1026 this.peer.OnNotifyCaretChanged();
1032 protected override void OnManipulationInertiaStarting(ManipulationInertiaStartingEventArgs e)
1037 protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
1039 if (this.hittedGripper != null)
1042 Point translation = new Point(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
1044 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
1045 if (Math.Abs(e.CumulativeManipulation.Translation.X) < Math.Abs(e.CumulativeManipulation.Translation.Y))
1047 int deltay = (int)Math.Abs(Math.Ceiling(translation.Y));
1048 if (translation.Y < 0)
1049 this._Controller.ScrollByPixel(ScrollDirection.Down, deltay, false, false);
1051 this._Controller.ScrollByPixel(ScrollDirection.Up, deltay, false, false);
1052 this.touchScrolled = true;
1057 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
1060 if (translation.X < 0)
1061 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
1063 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
1064 this.touchScrolled = true;
1069 private Point GetDipFromPoint(Point p)
1072 this.Render.GetDpi(out dpi,out dpi);
1073 double scale = dpi / 96.0;
1074 return p.Scale(1 / scale);
1078 protected override void OnMouseWheel(MouseWheelEventArgs e)
1080 if(Keyboard.Modifiers == ModifierKeys.None)
1083 this._Controller.Scroll(ScrollDirection.Up, SystemParameters.WheelScrollLines, false, false);
1085 this._Controller.Scroll(ScrollDirection.Down, SystemParameters.WheelScrollLines, false, false);
1087 else if (Keyboard.Modifiers == ModifierKeys.Control)
1089 double newFontSize = this.Render.FontSize;
1094 if (newFontSize > MaxFontSize)
1096 else if (newFontSize < MinFontSize)
1098 this.Render.FontSize = newFontSize;
1099 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
1102 base.OnMouseWheel(e);
1105 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
1107 if (e.Category == UserPreferenceCategory.Keyboard)
1109 int blinkTime = (int)NativeMethods.GetCaretBlinkTime();
1110 this.View.CaretBlink = blinkTime >= 0;
1111 this.View.CaretBlinkTime = blinkTime * 2;
1113 if (e.Category == UserPreferenceCategory.General)
1115 this.View.CaretWidthOnInsertMode = SystemParameters.CaretWidth;
1119 void Document_Update(object sender, DocumentUpdateEventArgs e)
1121 if (this.textStore.IsLocked())
1123 if(e.type == UpdateType.Replace)
1124 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
1125 if(this.peer != null)
1126 this.peer.OnNotifyTextChanged();
1129 void timer_Tick(object sender, EventArgs e)
1131 if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)
1133 if (this.Resize(this.image.ActualWidth, this.image.ActualHeight))
1139 bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding() || this.Document.IsRequestRedraw;
1144 this.Refresh(this.View.GetCurrentCaretRect());
1147 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1149 if (this.horizontalScrollBar == null)
1152 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
1153 toX = this.horizontalScrollBar.Value;
1155 toX = -this.horizontalScrollBar.Value;
1156 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
1160 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1162 if (this.verticalScrollBar == null)
1164 int newRow = (int)this.verticalScrollBar.Value;
1165 if (newRow >= this.View.LayoutLines.Count)
1167 this._Controller.Scroll(this.View.Src.X,newRow, false, false);
1171 void View_SrcChanged(object sender, EventArgs e)
1173 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1175 EditView view = this.View;
1176 if (view.Src.Row > this.verticalScrollBar.Maximum)
1177 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
1178 double absoulteX = Math.Abs(view.Src.X);
1179 if(absoulteX > this.horizontalScrollBar.Maximum)
1180 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1181 if(view.Src.Row != this.verticalScrollBar.Value)
1182 this.verticalScrollBar.Value = view.Src.Row;
1183 if (view.Src.X != this.horizontalScrollBar.Value)
1184 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1187 void Controller_SelectionChanged(object sender, EventArgs e)
1189 this.View.CaretBlink = this.View.CaretBlink;
1190 this.CaretMoved(this, null);
1191 //こうしないと選択できなくなってしまう
1192 this.isNotifyChanged = true;
1193 SetValue(SelectedTextProperty, this._Controller.SelectedText);
1194 SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
1195 SetValue(CaretPostionProperty, this.Document.CaretPostion);
1196 this.isNotifyChanged = false;
1197 if (this.textStore.IsLocked() == false)
1198 this.textStore.NotifySelectionChanged();
1201 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1203 this.Resize(this.image.ActualWidth, this.image.ActualHeight);
1208 bool Resize(double width, double height)
1210 if (width == 0 || height == 0)
1211 throw new ArgumentOutOfRangeException();
1212 if (this.Render.Resize(width, height))
1214 double scale = this.Render.GetScale();
1215 // RenderはレタリングはDIPだが、widthとheightの値はDPI依存なのでDIPに変換する
1216 this.View.PageBound = new Rectangle(0, 0, width / scale, height / scale);
1218 if (this.horizontalScrollBar != null)
1220 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
1221 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1223 if (this.verticalScrollBar != null)
1225 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
1226 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1233 private void SetDocument(Document value)
1238 Document old_doc = this._Document;
1240 if (this._Document != null)
1242 old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
1243 old_doc.LoadProgress -= Document_LoadProgress;
1244 old_doc.SelectionChanged += new EventHandler(Controller_SelectionChanged);
1245 oldLength = old_doc.Length;
1246 if (this._Document.AutoComplete != null)
1248 ((AutoCompleteBox)this._Document.AutoComplete).TargetPopup = null;
1249 this._Document.AutoComplete.GetPostion = null;
1250 this._Document.AutoComplete = null;
1254 this._Document = value;
1255 this._Document.LayoutLines.Render = this.Render;
1256 this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
1257 this._Document.LoadProgress += Document_LoadProgress;
1258 if (this._Document.AutoComplete != null)
1260 ((AutoCompleteBox)this._Document.AutoComplete).TargetPopup = this.popup;
1261 this._Document.AutoComplete.GetPostion = (tp, doc) =>
1263 var p = this.View.GetPostionFromTextPoint(tp);
1264 int height = (int)doc.LayoutLines.GetLayout(doc.CaretPostion.row).Height;
1266 return PointToScreen(this.TranslatePoint(p.Scale(Util.GetScale()), this));
1269 //初期化が終わっていればすべて存在する
1270 if (this.Controller != null && this.View != null && this.textStore != null)
1272 this._Document.SelectionChanged += new EventHandler(Controller_SelectionChanged);
1274 this.Controller.Document = value;
1275 this.View.Document = value;
1276 this.Controller.AdjustCaret();
1277 this.textStore.NotifyTextChanged(oldLength, value.Length);
1279 //依存プロパティとドキュメント内容が食い違っているので再設定する
1280 this.ShowFullSpace = value.ShowFullSpace;
1281 this.ShowHalfSpace = value.ShowHalfSpace;
1282 this.ShowLineBreak = value.ShowLineBreak;
1283 this.ShowTab = value.ShowTab;
1284 this.FlowDirection = value.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
1285 this.IndentMode = value.IndentMode;
1286 this.DrawCaretLine = !value.HideLineMarker;
1287 this.InsertMode = value.InsertMode;
1288 this.DrawRuler = !value.HideRuler;
1289 this.DrawLineNumber = value.DrawLineNumber;
1290 this.MarkURL = value.UrlMark;
1291 this.LineBreakMethod = value.LineBreak;
1292 this.LineBreakCharCount = value.LineBreakCharCount;
1293 this.TabChars = value.TabStops;
1299 /// プロパティーが変更されたときに呼ばれます
1301 /// <param name="e">イベントパラメーター</param>
1302 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
1304 switch (e.Property.Name)
1307 this.SetDocument(this.Document);
1310 this.View.Hilighter = this.Hilighter;
1312 case "TextAntialiasMode":
1313 this.Render.TextAntialiasMode = this.TextAntialiasMode;
1315 case "FoldingStrategy":
1316 this.View.LayoutLines.FoldingStrategy = this.FoldingStrategy;
1318 case "SelectedText":
1319 if (!this.isNotifyChanged)
1320 this._Controller.SelectedText = this.SelectedText;
1323 this._Controller.IndentMode = this.IndentMode;
1326 if(!this.isNotifyChanged)
1327 this.Select(this.Selection.Index, this.Selection.Length);
1329 case "CaretPostion":
1330 if (!this.isNotifyChanged)
1331 this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
1333 case "LineBreakMethod":
1334 this.Document.LineBreak = this.LineBreakMethod;
1336 case "LineBreakCharCount":
1337 this.Document.LineBreakCharCount = this.LineBreakCharCount;
1340 this.View.InsertMode = this.InsertMode;
1343 this.Document.TabStops = this.TabChars;
1345 case "RectSelectMode":
1346 this._Controller.RectSelection = this.RectSelectMode;
1349 this.View.HideCaret = !this.DrawCaret;
1351 case "DrawCaretLine":
1352 this.View.HideLineMarker = !this.DrawCaretLine;
1354 case "DrawLineNumber":
1355 this.Document.DrawLineNumber = this.DrawLineNumber;
1358 this.Render.FontFamily = this.FontFamily;
1361 this.Render.FontSize = this.FontSize;
1364 this.Render.FontStyle = this.FontStyle;
1367 this.Render.FontWeigth = this.FontWeight;
1370 this.Render.Foreground = D2DRender.ToColor4(this.Foreground);
1373 this.Render.Background = D2DRender.ToColor4(this.Background);
1376 this.Render.ControlChar =D2DRender.ToColor4( this.ControlChar);
1379 this.Render.Hilight = D2DRender.ToColor4(this.Hilight);
1382 this.Render.Keyword1 = D2DRender.ToColor4(this.Keyword1);
1385 this.Render.Keyword2 = D2DRender.ToColor4(this.Keyword2);
1388 this.Render.Comment = D2DRender.ToColor4(this.Comment);
1391 this.Render.Literal = D2DRender.ToColor4(this.Literal);
1394 this.Render.Url = D2DRender.ToColor4(this.URL);
1397 this.Render.InsertCaret = D2DRender.ToColor4(this.InsertCaret);
1399 case "OverwriteCaret":
1400 this.Render.OverwriteCaret = D2DRender.ToColor4(this.OverwriteCaret);
1403 this.View.Padding = new Padding((int)this.Padding.Left, (int)this.Padding.Top, (int)this.Padding.Right, (int)this.Padding.Bottom);
1406 this.Render.LineMarker = D2DRender.ToColor4(this.LineMarker);
1409 this.Document.UrlMark = this.MarkURL;
1411 case "ShowFullSpace":
1412 this.Document.ShowFullSpace = this.ShowFullSpace;
1414 case "ShowHalfSpace":
1415 this.Document.ShowHalfSpace = this.ShowHalfSpace;
1418 this.Document.ShowTab = this.ShowTab;
1420 case "ShowLineBreak":
1421 this.Document.ShowLineBreak = this.ShowLineBreak;
1423 case "FlowDirection":
1424 this.Document.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;
1425 this.horizontalScrollBar.FlowDirection = this.FlowDirection;
1428 this.Document.HideRuler = !this.DrawRuler;
1429 this._Controller.JumpCaret(this.Document.CaretPostion.row, this.Document.CaretPostion.col);
1432 this.Render.UpdateArea = D2DRender.ToColor4(this.UpdateArea);
1435 this.Render.LineNumber = D2DRender.ToColor4(this.LineNumber);
1438 base.OnPropertyChanged(e);
1443 internal Controller Controller
1447 return this._Controller;
1452 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1454 public TextAntialiasMode TextAntialiasMode
1456 get { return (TextAntialiasMode)GetValue(TextAntialiasModeProperty); }
1457 set { SetValue(TextAntialiasModeProperty, value); }
1461 /// TextAntialiasModeの依存プロパティを表す
1463 public static readonly DependencyProperty TextAntialiasModeProperty =
1464 DependencyProperty.Register("TextAntialiasMode", typeof(TextAntialiasMode), typeof(FooTextBox), new PropertyMetadata(TextAntialiasMode.Default));
1469 public IHilighter Hilighter
1471 get { return (IHilighter)GetValue(HilighterProperty); }
1472 set { SetValue(HilighterProperty, value); }
1476 /// Hilighterの依存プロパティを表す
1478 public static readonly DependencyProperty HilighterProperty =
1479 DependencyProperty.Register("Hilighter", typeof(IHilighter), typeof(FooTextBox), new PropertyMetadata(null));
1482 /// フォールティングを作成するインターフェイスを表す
1484 public IFoldingStrategy FoldingStrategy
1486 get { return (IFoldingStrategy)GetValue(FoldingStrategyProperty); }
1487 set { SetValue(FoldingStrategyProperty, value); }
1491 /// FoldingStrategyの依存プロパティ
1493 public static readonly DependencyProperty FoldingStrategyProperty =
1494 DependencyProperty.Register("FoldingStrategy", typeof(IFoldingStrategy), typeof(FooTextBox), new PropertyMetadata(null));
1500 public MarkerPatternSet MarkerPatternSet
1504 return this.Document.MarkerPatternSet;
1511 public Document Document
1513 get { return (Document)GetValue(DocumentProperty); }
1514 set { SetValue(DocumentProperty, value); }
1520 public static readonly DependencyProperty DocumentProperty =
1521 DependencyProperty.Register("Document", typeof(Document), typeof(FooTextBox), new PropertyMetadata(null));
1527 public LineToIndexTable LayoutLineCollection
1529 get { return this.View.LayoutLines; }
1535 public string SelectedText
1537 get { return (string)GetValue(SelectedTextProperty); }
1538 set { SetValue(SelectedTextProperty, value); }
1542 /// SelectedTextの依存プロパティを表す
1544 public static readonly DependencyProperty SelectedTextProperty =
1545 DependencyProperty.Register("SelectedText", typeof(string), typeof(FooTextBox), new PropertyMetadata(null));
1550 public IndentMode IndentMode
1552 get { return (IndentMode)GetValue(IndentModeProperty); }
1553 set { SetValue(IndentModeProperty, value); }
1557 /// IndentModeの依存プロパティを表す
1559 public static readonly DependencyProperty IndentModeProperty =
1560 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab));
1566 /// Lengthが0の場合はキャレット位置を表します。
1567 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1569 public TextRange Selection
1571 get { return (TextRange)GetValue(SelectionProperty); }
1572 set { SetValue(SelectionProperty, value); }
1576 /// Selectionの依存プロパティを表す
1578 public static readonly DependencyProperty SelectionProperty =
1579 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null));
1584 public double MagnificationPower
1586 get { return (double)GetValue(MagnificationPowerPropertyKey.DependencyProperty); }
1592 public static readonly DependencyPropertyKey MagnificationPowerPropertyKey =
1593 DependencyProperty.RegisterReadOnly("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0));
1598 public new FlowDirection FlowDirection
1600 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1601 set { SetValue(FlowDirectionProperty, value); }
1605 /// レタリング方向を表す。これは依存プロパティです
1607 public new static readonly DependencyProperty FlowDirectionProperty =
1608 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight));
1611 /// キャレット位置を表す。これは依存プロパティです
1613 public TextPoint CaretPostion
1615 get { return (TextPoint)GetValue(CaretPostionProperty); }
1616 set { SetValue(CaretPostionProperty, value); }
1620 /// CaretPostionの依存プロパティを表す
1622 public static readonly DependencyProperty CaretPostionProperty =
1623 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(TextPoint.Null));
1626 /// デフォルトの文字色を表す。これは依存プロパティです
1628 public new System.Windows.Media.Color Foreground
1630 get { return (System.Windows.Media.Color)GetValue(ForegroundProperty); }
1631 set { SetValue(ForegroundProperty, value); }
1635 /// Foregroundの依存プロパティを表す
1637 public new static readonly DependencyProperty ForegroundProperty =
1638 DependencyProperty.Register("Foreground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1641 /// 背景色を表す。これは依存プロパティです
1643 public new System.Windows.Media.Color Background
1645 get { return (System.Windows.Media.Color)GetValue(BackgroundProperty); }
1646 set { SetValue(BackgroundProperty, value); }
1650 /// Backgroundの依存プロパティを表す
1652 public new static readonly DependencyProperty BackgroundProperty =
1653 DependencyProperty.Register("Background", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowColor));
1656 /// コントロールコードの文字色を表す。これは依存プロパティです
1658 public System.Windows.Media.Color ControlChar
1660 get { return (System.Windows.Media.Color)GetValue(ControlCharProperty); }
1661 set { SetValue(ControlCharProperty, value); }
1665 /// ControlCharの依存プロパティを表す
1667 public static readonly DependencyProperty ControlCharProperty =
1668 DependencyProperty.Register("ControlChar", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Gray));
1671 /// 選択時の背景色を表す。これは依存プロパティです
1673 public System.Windows.Media.Color Hilight
1675 get { return (System.Windows.Media.Color)GetValue(HilightProperty); }
1676 set { SetValue(HilightProperty, value); }
1680 /// Hilightの依存プロパティを表す
1682 public static readonly DependencyProperty HilightProperty =
1683 DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));
1686 /// キーワード1の文字色を表す。これは依存プロパティです
1688 public System.Windows.Media.Color Keyword1
1690 get { return (System.Windows.Media.Color)GetValue(Keyword1Property); }
1691 set { SetValue(Keyword1Property, value); }
1695 /// Keyword1の依存プロパティを表す
1697 public static readonly DependencyProperty Keyword1Property =
1698 DependencyProperty.Register("Keyword1", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1701 /// キーワード2の文字色を表す。これは依存プロパティです
1703 public System.Windows.Media.Color Keyword2
1705 get { return (System.Windows.Media.Color)GetValue(Keyword2Property); }
1706 set { SetValue(Keyword2Property, value); }
1710 /// Keyword2の依存プロパティを表す
1712 public static readonly DependencyProperty Keyword2Property =
1713 DependencyProperty.Register("Keyword2", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DarkCyan));
1716 /// コメントの文字色を表す。これは依存プロパティです
1718 public System.Windows.Media.Color Comment
1720 get { return (System.Windows.Media.Color)GetValue(CommentProperty); }
1721 set { SetValue(CommentProperty, value); }
1725 /// Commentの依存プロパティを表す
1727 public static readonly DependencyProperty CommentProperty =
1728 DependencyProperty.Register("Comment", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Green));
1731 /// 文字リテラルの文字色を表す。これは依存プロパティです
1733 public System.Windows.Media.Color Literal
1735 get { return (System.Windows.Media.Color)GetValue(LiteralProperty); }
1736 set { SetValue(LiteralProperty, value); }
1740 /// Literalの依存プロパティを表す
1742 public static readonly DependencyProperty LiteralProperty =
1743 DependencyProperty.Register("Literal", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Brown));
1746 /// URLの文字色を表す。これは依存プロパティです
1748 public System.Windows.Media.Color URL
1750 get { return (System.Windows.Media.Color)GetValue(URLProperty); }
1751 set { SetValue(URLProperty, value); }
1757 public static readonly DependencyProperty URLProperty =
1758 DependencyProperty.Register("URL", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1764 public System.Windows.Media.Color LineMarker
1766 get { return (System.Windows.Media.Color)GetValue(LineMarkerProperty); }
1767 set { SetValue(LineMarkerProperty, value); }
1771 /// LineMarkerの依存プロパティを表す
1773 public static readonly DependencyProperty LineMarkerProperty =
1774 DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));
1777 /// 挿入モード時のキャレットの色を表す
1779 public System.Windows.Media.Color InsertCaret
1781 get { return (System.Windows.Media.Color)GetValue(InsertCaretProperty); }
1782 set { SetValue(InsertCaretProperty, value); }
1786 /// InsertCaretの依存プロパティを表す
1788 public static readonly DependencyProperty InsertCaretProperty =
1789 DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1794 public System.Windows.Media.Color UpdateArea
1796 get { return (System.Windows.Media.Color)GetValue(UpdateAreaProperty); }
1797 set { SetValue(UpdateAreaProperty, value); }
1801 /// UpdateAreaの依存プロパティを表す
1803 public static readonly DependencyProperty UpdateAreaProperty =
1804 DependencyProperty.Register("UpdateArea", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));
1807 /// 上書きモード時のキャレット職を表す
1809 public System.Windows.Media.Color OverwriteCaret
1811 get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }
1812 set { SetValue(OverwriteCaretProperty, value); }
1816 /// OverwriteCaretの依存プロパティを表す
1818 public static readonly DependencyProperty OverwriteCaretProperty =
1819 DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1824 public System.Windows.Media.Color LineNumber
1826 get { return (System.Windows.Media.Color)GetValue(LineNumberProperty); }
1827 set { SetValue(LineNumberProperty, value); }
1831 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1833 public static readonly DependencyProperty LineNumberProperty =
1834 DependencyProperty.Register("LineNumber", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray));
1837 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1839 public bool InsertMode
1841 get { return (bool)GetValue(InsertModeProperty); }
1842 set { SetValue(InsertModeProperty, value); }
1846 /// InsertModeの依存プロパティを表す
1848 public static readonly DependencyProperty InsertModeProperty =
1849 DependencyProperty.Register("InsertMode",
1852 new FrameworkPropertyMetadata(true));
1855 /// タブの文字数を表す。これは依存プロパティです
1859 get { return (int)GetValue(TabCharsProperty); }
1860 set { SetValue(TabCharsProperty, value); }
1864 /// TabCharsの依存プロパティを表す
1866 public static readonly DependencyProperty TabCharsProperty =
1867 DependencyProperty.Register("TabChars",
1870 new FrameworkPropertyMetadata(4));
1873 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1875 public bool RectSelectMode
1877 get { return (bool)GetValue(RectSelectModeProperty); }
1878 set { SetValue(RectSelectModeProperty, value); }
1882 /// RectSelectModeの依存プロパティを表す
1884 public static readonly DependencyProperty RectSelectModeProperty =
1885 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1891 /// 変更した場合、レイアウトの再構築を行う必要があります
1893 public LineBreakMethod LineBreakMethod
1895 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1896 set { SetValue(LineBreakProperty, value); }
1900 /// LineBreakMethodの依存プロパティを表す
1902 public static readonly DependencyProperty LineBreakProperty =
1903 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None));
1907 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1910 /// 変更した場合、レイアウトの再構築を行う必要があります
1912 public int LineBreakCharCount
1914 get { return (int)GetValue(LineBreakCharCountProperty); }
1915 set { SetValue(LineBreakCharCountProperty, value); }
1919 /// LineBreakCharCountの依存プロパティを表す
1921 public static readonly DependencyProperty LineBreakCharCountProperty =
1922 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
1925 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1927 public bool DrawCaret
1929 get { return (bool)GetValue(DrawCaretProperty); }
1930 set { SetValue(DrawCaretProperty, value); }
1934 /// DrawCaretの依存プロパティを表す
1936 public static readonly DependencyProperty DrawCaretProperty =
1937 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
1941 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1943 public bool DrawCaretLine
1945 get { return (bool)GetValue(DrawCaretLineProperty); }
1946 set { SetValue(DrawCaretLineProperty, value); }
1950 /// DrawCaretLineの依存プロパティを表す
1952 public static readonly DependencyProperty DrawCaretLineProperty =
1953 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1956 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
1958 public bool DrawLineNumber
1960 get { return (bool)GetValue(DrawLineNumberProperty); }
1961 set { SetValue(DrawLineNumberProperty, value); }
1965 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
1967 public bool DrawRuler
1969 get { return (bool)GetValue(DrawRulerProperty); }
1970 set { SetValue(DrawRulerProperty, value); }
1974 /// DrawRulerの依存プロパティを表す
1976 public static readonly DependencyProperty DrawRulerProperty =
1977 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
1981 /// DrawLineNumberの依存プロパティを表す
1983 public static readonly DependencyProperty DrawLineNumberProperty =
1984 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1987 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
1991 get { return (bool)GetValue(MarkURLProperty); }
1992 set { SetValue(MarkURLProperty, value); }
1996 /// MarkURLの依存プロパティを表す
1998 public static readonly DependencyProperty MarkURLProperty =
1999 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
2002 /// 全角スペースを表示するなら真。そうでないなら偽
2004 public bool ShowFullSpace
2006 get { return (bool)GetValue(ShowFullSpaceProperty); }
2007 set { SetValue(ShowFullSpaceProperty, value); }
2011 /// ShowFullSpaceの依存プロパティを表す
2013 public static readonly DependencyProperty ShowFullSpaceProperty =
2014 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
2017 /// 半角スペースを表示するなら真。そうでないなら偽
2019 public bool ShowHalfSpace
2021 get { return (bool)GetValue(ShowHalfSpaceProperty); }
2022 set { SetValue(ShowHalfSpaceProperty, value); }
2026 /// ShowHalfSpaceの依存プロパティを表す
2028 public static readonly DependencyProperty ShowHalfSpaceProperty =
2029 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
2032 /// タブを表示するなら真。そうでないなら偽
2036 get { return (bool)GetValue(ShowTabProperty); }
2037 set { SetValue(ShowTabProperty, value); }
2041 /// ShowTabの依存プロパティを表す
2043 public static readonly DependencyProperty ShowTabProperty =
2044 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
2047 /// 改行マークを表示するなら真。そうでないなら偽
2049 public bool ShowLineBreak
2051 get { return (bool)GetValue(ShowLineBreakProperty); }
2052 set { SetValue(ShowLineBreakProperty, value); }
2056 /// ShowLineBreakの依存プロパティを表す
2058 public static readonly DependencyProperty ShowLineBreakProperty =
2059 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
2064 /// マウスボタン関連のイベントクラス
2066 public sealed class FooMouseButtonEventArgs : MouseButtonEventArgs
2069 /// イベントが発生したドキュメントのインデックス
2080 /// <param name="mouse">マウスデバイス</param>
2081 /// <param name="timestamp">タイムスタンプ</param>
2082 /// <param name="button">ボタン</param>
2083 /// <param name="stylusDevice">スタイラスデバイス</param>
2084 /// <param name="index">インデックス</param>
2085 public FooMouseButtonEventArgs(MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice, int index)
2086 : base(mouse, timestamp, button, stylusDevice)
2094 public sealed class FooMouseEventArgs : MouseEventArgs
2097 /// イベントが発生したドキュメントのインデックス
2108 /// <param name="mouse">マウスデバイス</param>
2109 /// <param name="timestamp">タイムスタンプ</param>
2110 /// <param name="stylusDevice">スタイラスデバイス</param>
2111 /// <param name="index">インデックス</param>
2112 public FooMouseEventArgs(MouseDevice mouse,
2114 StylusDevice stylusDevice,
2116 : base(mouse, timestamp, stylusDevice)