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 /// オートインデントを行うためのデリゲートを表す
33 /// <param name="sender">イベント発生元のオブジェクト</param>
34 /// <param name="e">イベントデーター</param>
35 public delegate void AutoIndentHookerHandler(object sender,EventArgs e);
38 /// WPFでのFooTextBoxの実装
40 public sealed class FooTextBox : Control, IDisposable
42 const double MaxFontSize = 72.0f;
43 const double MinFontSize = 1;
46 Controller _Controller;
49 ScrollBar verticalScrollBar, horizontalScrollBar;
51 DispatcherTimer timer;
52 bool disposed = false;
53 FooTextBoxAutomationPeer peer;
54 bool isNotifyChanged = false;
59 DefaultStyleKeyProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(typeof(FooTextBox)));
60 KeyboardNavigation.IsTabStopProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(true));
61 KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(KeyboardNavigationMode.None));
69 this.image = new Image();
70 this.image.Stretch = Stretch.Fill;
71 this.image.HorizontalAlignment = HorizontalAlignment.Left;
72 this.image.VerticalAlignment = VerticalAlignment.Top;
74 this.textStore = new TextStore();
75 this.textStore.IsLoading += textStore_IsLoading;
76 this.textStore.IsReadOnly += textStore_IsReadOnly;
77 this.textStore.GetStringLength += () => this.Document.Length;
78 this.textStore.GetString += _textStore_GetString;
79 this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;
80 this.textStore.SetSelectionIndex += _textStore_SetSelectionIndex;
81 this.textStore.InsertAtSelection += _textStore_InsertAtSelection;
82 this.textStore.GetHWnd += _textStore_GetHWnd;
83 this.textStore.GetScreenExtent += _textStore_GetScreenExtent;
84 this.textStore.GetStringExtent += _textStore_GetStringExtent;
85 this.textStore.CompositionStarted += textStore_CompositionStarted;
86 this.textStore.CompositionUpdated += textStore_CompositionUpdated;
87 this.textStore.CompositionEnded += textStore_CompositionEnded;
89 this.Render = new D2DRender(this, 200, 200,this.image);
90 this.Render.ShowFullSpace = this.ShowFullSpace;
91 this.Render.ShowHalfSpace = this.ShowHalfSpace;
92 this.Render.ShowTab = this.ShowTab;
94 this.Document = new Document();
96 this.View = new EditView(this.Document, this.Render, new Padding(5, 5, 5, 5));
97 this.View.SrcChanged += View_SrcChanged;
98 this.View.InsertMode = this.InsertMode;
99 this.Document.DrawLineNumber = this.DrawLineNumber;
100 this.View.HideCaret = !this.DrawCaret;
101 this.View.HideLineMarker = !this.DrawCaretLine;
102 this.Document.HideRuler = !this.DrawRuler;
103 this.Document.UrlMark = this.MarkURL;
104 this.Document.TabStops = this.TabChars;
106 this._Controller = new Controller(this.Document, this.View);
107 this._Document.SelectionChanged += new EventHandler(Controller_SelectionChanged);
109 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, CopyCommand, CanExecute));
110 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, CutCommand, CanExecute));
111 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, PasteCommand, CanExecute));
112 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, DeleteCommand, CanExecute));
113 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, SelectAllCommand, CanExecute));
114 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, UndoCommand, CanExecute));
115 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, RedoCommand, CanExecute));
116 this.CommandBindings.Add(new CommandBinding(EditingCommands.ToggleInsert, ToggleInsertCommand, CanExecute));
117 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleRectSelectMode, ToggleRectSelectCommand, CanExecute));
118 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleFlowDirection, ToggleFlowDirectionCommand, CanExecute));
119 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleCodePoint, ToggleCodePointCommand, CanExecute));
121 this.InputBindings.Add(new InputBinding(ApplicationCommands.Copy, new KeyGesture(Key.C, ModifierKeys.Control)));
122 this.InputBindings.Add(new InputBinding(ApplicationCommands.Cut, new KeyGesture(Key.X, ModifierKeys.Control)));
123 this.InputBindings.Add(new InputBinding(ApplicationCommands.Paste, new KeyGesture(Key.V, ModifierKeys.Control)));
124 this.InputBindings.Add(new InputBinding(ApplicationCommands.Delete, new KeyGesture(Key.Delete, ModifierKeys.None)));
125 this.InputBindings.Add(new InputBinding(ApplicationCommands.SelectAll, new KeyGesture(Key.A, ModifierKeys.Control)));
126 this.InputBindings.Add(new InputBinding(ApplicationCommands.Undo, new KeyGesture(Key.Z, ModifierKeys.Control)));
127 this.InputBindings.Add(new InputBinding(ApplicationCommands.Redo, new KeyGesture(Key.Y, ModifierKeys.Control)));
128 this.InputBindings.Add(new InputBinding(EditingCommands.ToggleInsert, new KeyGesture(Key.Insert, ModifierKeys.None)));
129 this.InputBindings.Add(new InputBinding(FooTextBoxCommands.ToggleCodePoint, new KeyGesture(Key.X, ModifierKeys.Alt)));
131 this.timer = new DispatcherTimer();
132 this.timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
133 this.timer.Tick += new EventHandler(timer_Tick);
135 this.Loaded += new RoutedEventHandler(FooTextBox_Loaded);
137 this.AutoIndentHooker = (s,e)=>{};
139 SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
141 this.SystemEvents_UserPreferenceChanged(null, new UserPreferenceChangedEventArgs(UserPreferenceCategory.Keyboard));
143 this.CaretMoved += (s, e) => { };
145 this.IsManipulationEnabled = true;
153 //Dispose(false)を呼び出すと落ちる
158 /// オートインデントを行うためのイベント
160 public AutoIndentHookerHandler AutoIndentHooker;
165 public override void OnApplyTemplate()
167 base.OnApplyTemplate();
169 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
172 Grid.SetRow(this.image, 0);
173 Grid.SetColumn(this.image, 0);
174 grid.Children.Add(this.image);
177 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
178 if (this.horizontalScrollBar != null)
180 this.horizontalScrollBar.SmallChange = 10;
181 this.horizontalScrollBar.LargeChange = 100;
182 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
183 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
185 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
186 if (this.verticalScrollBar != null)
188 this.verticalScrollBar.SmallChange = 1;
189 this.verticalScrollBar.LargeChange = 10;
190 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
191 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
198 /// <param name="start">開始インデックス</param>
199 /// <param name="length">長さ</param>
200 public void Select(int start, int length)
202 this.Document.Select(start, length);
203 this.textStore.NotifySelectionChanged();
207 /// キャレットを指定した行に移動させます
209 /// <param name="index">インデックス</param>
210 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
211 public void JumpCaret(int index)
213 this._Controller.JumpCaret(index);
216 /// キャレットを指定した行と桁に移動させます
218 /// <param name="row">行番号</param>
219 /// <param name="col">桁</param>
220 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
221 public void JumpCaret(int row, int col)
223 this._Controller.JumpCaret(row, col);
227 /// 選択中のテキストをクリップボードにコピーします
231 string text = this._Controller.SelectedText;
232 if (text != null && text != string.Empty)
233 Clipboard.SetText(text);
237 /// 選択中のテキストをクリップボードに切り取ります
241 string text = this._Controller.SelectedText;
242 if (text != null && text != string.Empty)
244 Clipboard.SetText(text);
245 this._Controller.SelectedText = "";
254 if (Clipboard.ContainsText() == false)
256 string text = Clipboard.GetText();
257 this._Controller.SelectedText = text;
263 public void DeSelectAll()
265 this._Controller.DeSelectAll();
266 this.textStore.NotifySelectionChanged();
272 /// <param name="tp">テキストポイント</param>
273 /// <returns>座標</returns>
274 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
275 public System.Windows.Point GetPostionFromTextPoint(TextPoint tp)
277 if (this.Document.FireUpdateEvent == false)
278 throw new InvalidOperationException("");
279 return this.View.GetPostionFromTextPoint(tp);
283 /// 対応するテキストポイントを返します
285 /// <param name="p">クライアント領域の原点を左上とする座標</param>
286 /// <returns>テキストポイント</returns>
287 public TextPoint GetTextPointFromPostion(System.Windows.Point p)
289 if (this.Document.FireUpdateEvent == false)
290 throw new InvalidOperationException("");
291 return this.View.GetTextPointFromPostion(p);
297 /// <param name="row">レイアウト行</param>
298 /// <returns>行の高さ</returns>
299 public double GetLineHeight(int row)
301 if (this.Document.FireUpdateEvent == false)
302 throw new InvalidOperationException("");
303 return this.View.LayoutLines.GetLayout(row).Height;;
307 /// インデックスに対応する座標を得ます
309 /// <param name="index">インデックス</param>
310 /// <returns>座標を返す</returns>
311 public System.Windows.Point GetPostionFromIndex(int index)
313 if (this.Document.FireUpdateEvent == false)
314 throw new InvalidOperationException("");
315 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
316 return this.View.GetPostionFromTextPoint(tp);
322 /// <param name="p">座標</param>
323 /// <returns>インデックスを返す</returns>
324 public int GetIndexFromPostion(System.Windows.Point p)
326 if (this.Document.FireUpdateEvent == false)
327 throw new InvalidOperationException("");
328 TextPoint tp = this.View.GetTextPointFromPostion(p);
329 return this.View.GetIndexFromLayoutLine(tp);
335 public void Refresh()
337 this.Refresh(this.View.PageBound);
341 /// レイアウト行をすべて破棄し、再度レイアウトを行う
343 public void PerfomLayouts()
345 this.View.PerfomLayouts();
351 /// <param name="row">行</param>
352 /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
353 public void ScrollIntoView(int row, bool alignTop)
355 this.View.ScrollIntoView(row, alignTop);
359 /// ストリームからドキュメントを構築する
361 /// <param name="tr">TextReader</param>
362 /// <param name="token">キャンセル用トークン</param>
363 /// <returns>Taskオブジェクト</returns>
364 public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)
366 WinFileReader fs = new WinFileReader(tr);
367 await this.LoadAsyncImpl(fs, token);
371 /// ファイルからドキュメントを構築する
373 /// <param name="filepath">ファイルパス</param>
374 /// <param name="enc">エンコード</param>
375 /// <param name="token">キャンセル用トークン</param>
376 /// <returns>Taskオブジェクト</returns>
377 public async Task LoadFileAsync(string filepath, Encoding enc,System.Threading.CancellationTokenSource token)
379 WinFileReader fs = new WinFileReader(filepath, enc);
380 await this.LoadAsyncImpl(fs, token);
384 async Task LoadAsyncImpl(WinFileReader fs,System.Threading.CancellationTokenSource token)
386 this.IsEnabled = false;
387 await this.Document.LoadAsync(fs, token);
388 TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
389 if (this.verticalScrollBar != null)
390 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
391 this.View.CalculateLineCountOnScreen();
392 this.IsEnabled = true;
396 /// ドキュメントの内容をファイルに保存する
398 /// <param name="filepath">ファイルパス</param>
399 /// <param name="newLine">改行コード</param>
400 /// <param name="enc">エンコード</param>
401 /// <returns>Taskオブジェクト</returns>
402 public async Task SaveFile(string filepath, Encoding enc,string newLine, System.Threading.CancellationTokenSource token)
404 WinFileWriter fs = new WinFileWriter(filepath, enc);
405 fs.NewLine = newLine;
406 await this.Document.SaveAsync(fs, token);
413 public void Dispose()
418 GC.SuppressFinalize(this);
419 this.disposed = true;
425 /// <param name="disposing">真ならマネージドリソースも開放し、そうでないならアンマネージドリソースのみを開放する</param>
426 void Dispose(bool disposing)
430 this.textStore.Dispose();
433 this.Render.Dispose();
435 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
438 void Refresh(Rectangle updateRect)
440 if (this.disposed || this.Visibility == Visibility.Collapsed)
443 this.Render.DrawContent(this.View, this.IsEnabled, updateRect);
447 void CanExecute(object sender, CanExecuteRoutedEventArgs e)
449 e.CanExecute = this.IsEnabled;
452 void ToggleCodePointCommand(object sender, RoutedEventArgs e)
454 if (!this._Controller.ConvertToChar())
455 this._Controller.ConvertToCodePoint();
459 void CopyCommand(object sender, RoutedEventArgs e)
464 void CutCommand(object sender, RoutedEventArgs e)
470 void PasteCommand(object sender, RoutedEventArgs e)
476 void DeleteCommand(object sender, RoutedEventArgs e)
478 int oldLength = this.Document.Length;
479 this._Controller.DoDeleteAction();
483 void SelectAllCommand(object sender, RoutedEventArgs e)
485 this.Select(0, this.Document.Length);
489 void UndoCommand(object sender, RoutedEventArgs e)
491 int oldLength = this.Document.Length;
492 this.Document.UndoManager.undo();
496 void RedoCommand(object sender, RoutedEventArgs e)
498 int oldLength = this.Document.Length;
499 this.Document.UndoManager.redo();
503 void ToggleInsertCommand(object sender, RoutedEventArgs e)
506 this.InsertMode = false;
508 this.InsertMode = true;
512 void ToggleRectSelectCommand(object sender, RoutedEventArgs e)
514 if (this.RectSelectMode)
515 this.RectSelectMode = false;
517 this.RectSelectMode = true;
520 void ToggleFlowDirectionCommand(object sender, RoutedEventArgs e)
522 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
523 this.FlowDirection = System.Windows.FlowDirection.RightToLeft;
525 this.FlowDirection = System.Windows.FlowDirection.LeftToRight;
530 internal TextStore TextStore
532 get { return this.textStore; }
535 bool textStore_IsReadOnly()
540 bool textStore_IsLoading()
545 void textStore_CompositionEnded()
547 TextStoreHelper.EndCompostion(this.Document);
551 void textStore_CompositionUpdated(int start, int end)
553 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
556 bool textStore_CompositionStarted()
558 bool result = TextStoreHelper.StartCompstion(this.Document);
560 System.Media.SystemSounds.Beep.Play();
564 string _textStore_GetString(int start, int length)
566 return this.Document.ToString(start, length);
569 IntPtr _textStore_GetHWnd()
571 var hwndSource = HwndSource.FromVisual(this) as HwndSource;
572 if (hwndSource != null)
573 return hwndSource.Handle;
578 void _textStore_GetStringExtent(
582 out POINT o_bottomRight
585 Point startPos, endPos;
586 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
588 double scale = this.Render.GetScale();
590 startPos = PointToScreen(this.TranslatePoint(startPos.Scale(scale), this));
591 endPos = PointToScreen(this.TranslatePoint(endPos.Scale(scale), this));
593 o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);
594 o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);
597 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
599 var pointTopLeft = new Point(0, 0);
600 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
602 pointTopLeft = PointToScreen(pointTopLeft);
603 pointBottomRight = PointToScreen(pointBottomRight);
605 o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
606 o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
609 void _textStore_GetSelectionIndex(int start_index, int max_count, out DotNetTextStore.TextSelection[] sels)
612 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out selRange);
614 sels = new DotNetTextStore.TextSelection[1];
615 sels[0] = new DotNetTextStore.TextSelection();
616 sels[0].start = selRange.Index;
617 sels[0].end = selRange.Index + selRange.Length;
620 void _textStore_SetSelectionIndex(DotNetTextStore.TextSelection[] sels)
622 TextStoreHelper.SetSelectionIndex(this._Controller, this.View, sels[0].start, sels[0].end);
626 void _textStore_InsertAtSelection(string i_value, ref int o_startIndex, ref int o_endIndex)
628 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
633 /// キーボードフォーカスが取得されたときに呼ばれます
635 /// <param name="e">イベントデーター</param>
636 protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
638 base.OnGotKeyboardFocus(e);
639 this.textStore.SetFocus();
640 this.View.IsFocused = true;
645 /// キーボードフォーカスが失われたときに呼ばれます
647 /// <param name="e">イベントデーター</param>
648 protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
650 base.OnLostKeyboardFocus(e);
651 this.View.IsFocused = false;
657 /// キャレットが移動したときに通知されるイベント
659 public event EventHandler CaretMoved;
662 protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
664 this.peer = new FooTextBoxAutomationPeer(this);
670 protected override void OnTextInput(TextCompositionEventArgs e)
674 this._Controller.DoEnterAction();
675 this.AutoIndentHooker(this, null);
677 else if (e.Text == "\b")
679 this._Controller.DoBackSpaceAction();
683 if(this.IsInputString(e.Text))
684 this._Controller.DoInputString(e.Text);
691 bool IsInputString(string s)
693 foreach (char charCode in s)
695 if ((0x20 <= charCode && charCode <= 0x7e)
703 protected override void OnKeyDown(KeyEventArgs e)
705 if (this.textStore.IsLocked())
708 ModifierKeys modiferKeys = e.KeyboardDevice.Modifiers;
709 bool movedCaret = false;
713 this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
719 this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
725 this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
731 this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
737 this._Controller.Scroll(ScrollDirection.Up,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
742 this._Controller.Scroll(ScrollDirection.Down,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
747 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
748 this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
750 this._Controller.JumpToLineHead(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
755 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
756 this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
758 this._Controller.JumpToLineEnd(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
763 int oldLength = this.Document.Length;
764 if (this.Selection.Length == 0)
765 this._Controller.DoInputChar('\t');
766 else if(this.IsPressedModifierKey(modiferKeys,ModifierKeys.Shift))
767 this._Controller.DownIndent();
769 this._Controller.UpIndent();
774 if (movedCaret && this.peer != null)
775 this.peer.OnNotifyCaretChanged();
779 bool IsPressedModifierKey(ModifierKeys keys, ModifierKeys pressed)
783 if ((keys & pressed) == pressed)
789 /// ダブルクリックされたときに呼ばれます
791 /// <param name="e">イベントパラメーター</param>
793 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
794 /// e.Handledを真にした場合、単語単位の選択が行われなくなります
796 protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
798 var p = this.GetDipFromPoint(e.GetPosition(this));
799 TextPoint tp = this.View.GetTextPointFromPostion(p);
800 if (tp == TextPoint.Null)
802 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
804 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
809 newEventArgs.RoutedEvent = e.RoutedEvent;
810 base.OnMouseDoubleClick(newEventArgs);
812 if (newEventArgs.Handled)
815 if (e.LeftButton == MouseButtonState.Pressed)
818 this.Document.SelectWord((int)index);
819 this.textStore.NotifySelectionChanged();
820 if(this.peer != null)
821 this.peer.OnNotifyCaretChanged();
827 /// マウスボタンが押されたときに呼ばれます
829 /// <param name="e">イベントパラメーター</param>
831 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
832 /// e.Handledを真にした場合、キャレットの移動処理が行われなくなります
834 protected override void OnMouseDown(MouseButtonEventArgs e)
838 var p = this.GetDipFromPoint(e.GetPosition(this));
839 TextPoint tp = this.View.GetTextPointFromPostion(p);
840 if (tp == TextPoint.Null)
842 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
844 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
849 newEventArgs.RoutedEvent = e.RoutedEvent;
850 base.OnMouseDown(newEventArgs);
852 if (newEventArgs.Handled)
855 if (e.LeftButton == MouseButtonState.Pressed)
857 FoldingItem foldingData = this.View.HitFoldingData(p.X,tp.row);
858 if (foldingData != null)
860 if (foldingData.Expand)
861 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
863 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
864 this._Controller.JumpCaret(foldingData.Start,false);
868 this._Controller.JumpCaret(tp.row, tp.col, false);
870 if (this.peer != null)
871 this.peer.OnNotifyCaretChanged();
872 this.View.IsFocused = true;
874 this.Document.SelectGrippers.BottomLeft.Enabled = false;
875 this.Document.SelectGrippers.BottomRight.Enabled = false;
881 /// マウスのボタンが離されたときに呼ばれます
883 /// <param name="e"></param>
884 protected override void OnMouseUp(MouseButtonEventArgs e)
886 this.ReleaseMouseCapture();
893 /// <param name="e">イベントパラメーター</param>
895 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
896 /// e.Handledを真にした場合、選択処理と状況に応じたカーソルの変化が行われなくなります
898 protected override void OnMouseMove(MouseEventArgs e)
900 bool leftPressed = e.LeftButton == MouseButtonState.Pressed;
902 var p = this.GetDipFromPoint(e.GetPosition(this));
904 TextPointSearchRange searchRange;
905 if (this.View.HitTextArea(p.X, p.Y))
906 searchRange = TextPointSearchRange.TextAreaOnly;
907 else if (leftPressed)
908 searchRange = TextPointSearchRange.Full;
910 searchRange = TextPointSearchRange.TextAreaOnly;
912 TextPoint tp = this.View.GetTextPointFromPostion(p, searchRange);
914 if (tp == TextPoint.Null)
920 int index = this.View.GetIndexFromLayoutLine(tp);
922 FooMouseEventArgs newEventArgs = new FooMouseEventArgs(e.MouseDevice, e.Timestamp, e.StylusDevice, index);
923 newEventArgs.RoutedEvent = e.RoutedEvent;
924 base.OnMouseMove(newEventArgs);
926 if (newEventArgs.Handled)
929 //この状態のときはカーソルがテキストエリア内にある
930 if (searchRange == TextPointSearchRange.TextAreaOnly)
932 if (this._Controller.IsMarker(tp, HilightType.Url))
933 this.Cursor = Cursors.Hand;
935 this.Cursor = Cursors.IBeam;
939 this.Cursor = Cursors.Arrow;
944 this._Controller.MoveCaretAndSelect(tp);
945 if (this.peer != null)
946 this.peer.OnNotifyCaretChanged();
951 Gripper hittedGripper;
952 bool touchScrolled = false;
955 protected override void OnTouchDown(TouchEventArgs e)
957 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
958 this.hittedGripper = this.View.HitGripperFromPoint(p);
959 this.CaptureTouch(e.TouchDevice);
963 protected override void OnTouchUp(TouchEventArgs e)
965 this.ReleaseTouchCapture(e.TouchDevice);
966 if(this.hittedGripper != null || this.touchScrolled)
968 this.hittedGripper = null;
969 this.touchScrolled = false;
973 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
974 TextPoint tp = this.View.GetTextPointFromPostion(p);
975 if (tp == TextPoint.Null)
977 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
979 FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
980 if (foldingData != null)
982 if (foldingData.Expand)
983 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
985 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
986 this._Controller.JumpCaret(foldingData.Start, false);
990 this._Controller.JumpCaret(tp.row, tp.col, false);
992 if (this.peer != null)
993 this.peer.OnNotifyCaretChanged();
994 this.View.IsFocused = true;
996 this.Document.SelectGrippers.BottomLeft.Enabled = false;
997 this.Document.SelectGrippers.BottomRight.Enabled = true;
1002 protected override void OnTouchMove(TouchEventArgs e)
1004 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
1005 if (this.Controller.MoveCaretAndGripper(p, this.hittedGripper))
1007 if (this.peer != null)
1008 this.peer.OnNotifyCaretChanged();
1014 protected override void OnManipulationInertiaStarting(ManipulationInertiaStartingEventArgs e)
1019 protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
1021 if (this.hittedGripper != null)
1024 Point translation = new Point(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
1026 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
1027 if (Math.Abs(e.CumulativeManipulation.Translation.X) < Math.Abs(e.CumulativeManipulation.Translation.Y))
1029 int deltay = (int)Math.Abs(Math.Ceiling(translation.Y));
1030 if (translation.Y < 0)
1031 this._Controller.ScrollByPixel(ScrollDirection.Down, deltay, false, false);
1033 this._Controller.ScrollByPixel(ScrollDirection.Up, deltay, false, false);
1034 this.touchScrolled = true;
1039 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
1042 if (translation.X < 0)
1043 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
1045 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
1046 this.touchScrolled = true;
1051 private Point GetDipFromPoint(Point p)
1054 this.Render.GetDpi(out dpi,out dpi);
1055 double scale = dpi / 96.0;
1056 return p.Scale(1 / scale);
1060 protected override void OnMouseWheel(MouseWheelEventArgs e)
1062 if(Keyboard.Modifiers == ModifierKeys.None)
1065 this._Controller.Scroll(ScrollDirection.Up, SystemParameters.WheelScrollLines, false, false);
1067 this._Controller.Scroll(ScrollDirection.Down, SystemParameters.WheelScrollLines, false, false);
1069 else if (Keyboard.Modifiers == ModifierKeys.Control)
1071 double newFontSize = this.Render.FontSize;
1076 if (newFontSize > MaxFontSize)
1078 else if (newFontSize < MinFontSize)
1080 this.Render.FontSize = newFontSize;
1081 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
1084 base.OnMouseWheel(e);
1087 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
1089 if (e.Category == UserPreferenceCategory.Keyboard)
1091 int blinkTime = (int)NativeMethods.GetCaretBlinkTime();
1092 this.View.CaretBlink = blinkTime >= 0;
1093 this.View.CaretBlinkTime = blinkTime * 2;
1095 if (e.Category == UserPreferenceCategory.General)
1097 this.View.CaretWidthOnInsertMode = SystemParameters.CaretWidth;
1101 void Document_Update(object sender, DocumentUpdateEventArgs e)
1103 if (this.textStore.IsLocked())
1105 if(e.type == UpdateType.Replace)
1106 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
1107 if(this.peer != null)
1108 this.peer.OnNotifyTextChanged();
1111 void timer_Tick(object sender, EventArgs e)
1113 if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)
1115 if (this.Resize(this.image.ActualWidth, this.image.ActualHeight))
1121 bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding();
1126 this.Refresh(this.View.GetCurrentCaretRect());
1129 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1131 if (this.horizontalScrollBar == null)
1134 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
1135 toX = this.horizontalScrollBar.Value;
1137 toX = -this.horizontalScrollBar.Value;
1138 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
1142 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1144 if (this.verticalScrollBar == null)
1146 int newRow = (int)this.verticalScrollBar.Value;
1147 if (newRow >= this.View.LayoutLines.Count)
1149 this._Controller.Scroll(this.View.Src.X,newRow, false, false);
1153 void View_SrcChanged(object sender, EventArgs e)
1155 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1157 EditView view = this.View;
1158 if (view.Src.Row > this.verticalScrollBar.Maximum)
1159 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
1160 double absoulteX = Math.Abs(view.Src.X);
1161 if(absoulteX > this.horizontalScrollBar.Maximum)
1162 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1163 if(view.Src.Row != this.verticalScrollBar.Value)
1164 this.verticalScrollBar.Value = view.Src.Row;
1165 if (view.Src.X != this.horizontalScrollBar.Value)
1166 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1169 void Controller_SelectionChanged(object sender, EventArgs e)
1171 this.View.CaretBlink = this.View.CaretBlink;
1172 this.CaretMoved(this, null);
1173 //こうしないと選択できなくなってしまう
1174 this.isNotifyChanged = true;
1175 SetValue(SelectedTextProperty, this._Controller.SelectedText);
1176 SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
1177 SetValue(CaretPostionProperty, this.Document.CaretPostion);
1178 this.isNotifyChanged = false;
1179 if (this.textStore.IsLocked() == false)
1180 this.textStore.NotifySelectionChanged();
1183 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1185 this.Resize(this.image.ActualWidth, this.image.ActualHeight);
1190 bool Resize(double width, double height)
1192 if (width == 0 || height == 0)
1193 throw new ArgumentOutOfRangeException();
1194 if (this.Render.Resize(width, height))
1196 double scale = this.Render.GetScale();
1197 // RenderはレタリングはDIPだが、widthとheightの値はDPI依存なのでDIPに変換する
1198 this.View.PageBound = new Rectangle(0, 0, width / scale, height / scale);
1200 if (this.horizontalScrollBar != null)
1202 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
1203 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1205 if (this.verticalScrollBar != null)
1207 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
1208 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1216 /// プロパティーが変更されたときに呼ばれます
1218 /// <param name="e">イベントパラメーター</param>
1219 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
1221 switch (e.Property.Name)
1224 this.View.Hilighter = this.Hilighter;
1226 case "TextAntialiasMode":
1227 this.Render.TextAntialiasMode = this.TextAntialiasMode;
1229 case "FoldingStrategy":
1230 this.View.LayoutLines.FoldingStrategy = this.FoldingStrategy;
1232 case "SelectedText":
1233 if (!this.isNotifyChanged)
1234 this._Controller.SelectedText = this.SelectedText;
1237 this._Controller.IndentMode = this.IndentMode;
1240 if(!this.isNotifyChanged)
1241 this.Select(this.Selection.Index, this.Selection.Length);
1243 case "CaretPostion":
1244 if (!this.isNotifyChanged)
1245 this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
1247 case "LineBreakMethod":
1248 this.Document.LineBreak = this.LineBreakMethod;
1250 case "LineBreakCharCount":
1251 this.Document.LineBreakCharCount = this.LineBreakCharCount;
1254 this.View.InsertMode = this.InsertMode;
1257 this.Document.TabStops = this.TabChars;
1259 case "RectSelectMode":
1260 this._Controller.RectSelection = this.RectSelectMode;
1263 this.View.HideCaret = !this.DrawCaret;
1265 case "DrawCaretLine":
1266 this.View.HideLineMarker = !this.DrawCaretLine;
1268 case "DrawLineNumber":
1269 this.Document.DrawLineNumber = this.DrawLineNumber;
1272 this.Render.FontFamily = this.FontFamily;
1275 this.Render.FontSize = this.FontSize;
1278 this.Render.FontStyle = this.FontStyle;
1281 this.Render.FontWeigth = this.FontWeight;
1284 this.Render.Foreground = D2DRender.ToColor4(this.Foreground);
1287 this.Render.Background = D2DRender.ToColor4(this.Background);
1290 this.Render.ControlChar =D2DRender.ToColor4( this.ControlChar);
1293 this.Render.Hilight = D2DRender.ToColor4(this.Hilight);
1296 this.Render.Keyword1 = D2DRender.ToColor4(this.Keyword1);
1299 this.Render.Keyword2 = D2DRender.ToColor4(this.Keyword2);
1302 this.Render.Comment = D2DRender.ToColor4(this.Comment);
1305 this.Render.Literal = D2DRender.ToColor4(this.Literal);
1308 this.Render.Url = D2DRender.ToColor4(this.URL);
1311 this.Render.InsertCaret = D2DRender.ToColor4(this.InsertCaret);
1313 case "OverwriteCaret":
1314 this.Render.OverwriteCaret = D2DRender.ToColor4(this.OverwriteCaret);
1317 this.View.Padding = new Padding((int)this.Padding.Left, (int)this.Padding.Top, (int)this.Padding.Right, (int)this.Padding.Bottom);
1320 this.Render.LineMarker = D2DRender.ToColor4(this.LineMarker);
1323 this.Document.UrlMark = this.MarkURL;
1325 case "ShowFullSpace":
1326 this.Document.ShowFullSpace = this.ShowFullSpace;
1328 case "ShowHalfSpace":
1329 this.Document.ShowHalfSpace = this.ShowHalfSpace;
1332 this.Document.ShowTab = this.ShowTab;
1334 case "ShowLineBreak":
1335 this.Document.ShowLineBreak = this.ShowLineBreak;
1337 case "FlowDirection":
1338 this.Document.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;
1339 this.horizontalScrollBar.FlowDirection = this.FlowDirection;
1342 this.Document.HideRuler = !this.DrawRuler;
1343 this._Controller.JumpCaret(this.Document.CaretPostion.row, this.Document.CaretPostion.col);
1346 this.Render.UpdateArea = D2DRender.ToColor4(this.UpdateArea);
1349 this.Render.LineNumber = D2DRender.ToColor4(this.LineNumber);
1352 base.OnPropertyChanged(e);
1357 internal Controller Controller
1361 return this._Controller;
1366 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1368 public TextAntialiasMode TextAntialiasMode
1370 get { return (TextAntialiasMode)GetValue(TextAntialiasModeProperty); }
1371 set { SetValue(TextAntialiasModeProperty, value); }
1375 /// TextAntialiasModeの依存プロパティを表す
1377 public static readonly DependencyProperty TextAntialiasModeProperty =
1378 DependencyProperty.Register("TextAntialiasMode", typeof(TextAntialiasMode), typeof(FooTextBox), new PropertyMetadata(TextAntialiasMode.Default));
1383 public IHilighter Hilighter
1385 get { return (IHilighter)GetValue(HilighterProperty); }
1386 set { SetValue(HilighterProperty, value); }
1390 /// Hilighterの依存プロパティを表す
1392 public static readonly DependencyProperty HilighterProperty =
1393 DependencyProperty.Register("Hilighter", typeof(IHilighter), typeof(FooTextBox), new PropertyMetadata(null));
1396 /// フォールティングを作成するインターフェイスを表す
1398 public IFoldingStrategy FoldingStrategy
1400 get { return (IFoldingStrategy)GetValue(FoldingStrategyProperty); }
1401 set { SetValue(FoldingStrategyProperty, value); }
1405 /// FoldingStrategyの依存プロパティ
1407 public static readonly DependencyProperty FoldingStrategyProperty =
1408 DependencyProperty.Register("FoldingStrategy", typeof(IFoldingStrategy), typeof(FooTextBox), new PropertyMetadata(null));
1414 public MarkerPatternSet MarkerPatternSet
1418 return this.Document.MarkerPatternSet;
1425 public Document Document
1429 return this._Document;
1433 Document old_doc = this._Document;
1435 if(this._Document != null)
1437 old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
1438 old_doc.SelectionChanged += new EventHandler(Controller_SelectionChanged);
1439 oldLength = old_doc.Length;
1442 this._Document = value;
1443 this._Document.LayoutLines.Render = this.Render;
1444 this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
1445 //初期化が終わっていればすべて存在する
1446 if(this.Controller != null && this.View != null && this.textStore != null)
1448 this._Document.SelectionChanged += new EventHandler(Controller_SelectionChanged);
1450 this.Controller.Document = value;
1451 this.View.Document = value;
1452 this.Controller.AdjustCaret();
1453 this.textStore.NotifyTextChanged(oldLength, value.Length);
1455 //依存プロパティとドキュメント内容が食い違っているので再設定する
1456 this.ShowFullSpace = value.ShowFullSpace;
1457 this.ShowHalfSpace = value.ShowHalfSpace;
1458 this.ShowLineBreak = value.ShowLineBreak;
1459 this.ShowTab = value.ShowTab;
1460 this.FlowDirection = value.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
1461 this.IndentMode = value.IndentMode;
1462 this.DrawCaretLine = !value.HideLineMarker;
1463 this.InsertMode = value.InsertMode;
1464 this.DrawRuler = !value.HideRuler;
1465 this.DrawLineNumber = value.DrawLineNumber;
1466 this.MarkURL = value.UrlMark;
1467 this.LineBreakMethod = value.LineBreak;
1468 this.LineBreakCharCount = value.LineBreakCharCount;
1469 this.TabChars = value.TabStops;
1479 public LineToIndexTable LayoutLineCollection
1481 get { return this.View.LayoutLines; }
1487 public string SelectedText
1489 get { return (string)GetValue(SelectedTextProperty); }
1490 set { SetValue(SelectedTextProperty, value); }
1494 /// SelectedTextの依存プロパティを表す
1496 public static readonly DependencyProperty SelectedTextProperty =
1497 DependencyProperty.Register("SelectedText", typeof(string), typeof(FooTextBox), new PropertyMetadata(null));
1502 public IndentMode IndentMode
1504 get { return (IndentMode)GetValue(IndentModeProperty); }
1505 set { SetValue(IndentModeProperty, value); }
1509 /// IndentModeの依存プロパティを表す
1511 public static readonly DependencyProperty IndentModeProperty =
1512 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab));
1518 /// Lengthが0の場合はキャレット位置を表します。
1519 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1521 public TextRange Selection
1523 get { return (TextRange)GetValue(SelectionProperty); }
1524 set { SetValue(SelectionProperty, value); }
1528 /// Selectionの依存プロパティを表す
1530 public static readonly DependencyProperty SelectionProperty =
1531 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null));
1536 public double MagnificationPower
1538 get { return (double)GetValue(MagnificationPowerPropertyKey.DependencyProperty); }
1544 public static readonly DependencyPropertyKey MagnificationPowerPropertyKey =
1545 DependencyProperty.RegisterReadOnly("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0));
1550 public new FlowDirection FlowDirection
1552 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1553 set { SetValue(FlowDirectionProperty, value); }
1557 /// レタリング方向を表す。これは依存プロパティです
1559 public new static readonly DependencyProperty FlowDirectionProperty =
1560 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight));
1563 /// キャレット位置を表す。これは依存プロパティです
1565 public TextPoint CaretPostion
1567 get { return (TextPoint)GetValue(CaretPostionProperty); }
1568 set { SetValue(CaretPostionProperty, value); }
1572 /// CaretPostionの依存プロパティを表す
1574 public static readonly DependencyProperty CaretPostionProperty =
1575 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(TextPoint.Null));
1578 /// デフォルトの文字色を表す。これは依存プロパティです
1580 public new System.Windows.Media.Color Foreground
1582 get { return (System.Windows.Media.Color)GetValue(ForegroundProperty); }
1583 set { SetValue(ForegroundProperty, value); }
1587 /// Foregroundの依存プロパティを表す
1589 public new static readonly DependencyProperty ForegroundProperty =
1590 DependencyProperty.Register("Foreground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1593 /// 背景色を表す。これは依存プロパティです
1595 public new System.Windows.Media.Color Background
1597 get { return (System.Windows.Media.Color)GetValue(BackgroundProperty); }
1598 set { SetValue(BackgroundProperty, value); }
1602 /// Backgroundの依存プロパティを表す
1604 public new static readonly DependencyProperty BackgroundProperty =
1605 DependencyProperty.Register("Background", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowColor));
1608 /// コントロールコードの文字色を表す。これは依存プロパティです
1610 public System.Windows.Media.Color ControlChar
1612 get { return (System.Windows.Media.Color)GetValue(ControlCharProperty); }
1613 set { SetValue(ControlCharProperty, value); }
1617 /// ControlCharの依存プロパティを表す
1619 public static readonly DependencyProperty ControlCharProperty =
1620 DependencyProperty.Register("ControlChar", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Gray));
1623 /// 選択時の背景色を表す。これは依存プロパティです
1625 public System.Windows.Media.Color Hilight
1627 get { return (System.Windows.Media.Color)GetValue(HilightProperty); }
1628 set { SetValue(HilightProperty, value); }
1632 /// Hilightの依存プロパティを表す
1634 public static readonly DependencyProperty HilightProperty =
1635 DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));
1638 /// キーワード1の文字色を表す。これは依存プロパティです
1640 public System.Windows.Media.Color Keyword1
1642 get { return (System.Windows.Media.Color)GetValue(Keyword1Property); }
1643 set { SetValue(Keyword1Property, value); }
1647 /// Keyword1の依存プロパティを表す
1649 public static readonly DependencyProperty Keyword1Property =
1650 DependencyProperty.Register("Keyword1", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1653 /// キーワード2の文字色を表す。これは依存プロパティです
1655 public System.Windows.Media.Color Keyword2
1657 get { return (System.Windows.Media.Color)GetValue(Keyword2Property); }
1658 set { SetValue(Keyword2Property, value); }
1662 /// Keyword2の依存プロパティを表す
1664 public static readonly DependencyProperty Keyword2Property =
1665 DependencyProperty.Register("Keyword2", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DarkCyan));
1668 /// コメントの文字色を表す。これは依存プロパティです
1670 public System.Windows.Media.Color Comment
1672 get { return (System.Windows.Media.Color)GetValue(CommentProperty); }
1673 set { SetValue(CommentProperty, value); }
1677 /// Commentの依存プロパティを表す
1679 public static readonly DependencyProperty CommentProperty =
1680 DependencyProperty.Register("Comment", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Green));
1683 /// 文字リテラルの文字色を表す。これは依存プロパティです
1685 public System.Windows.Media.Color Literal
1687 get { return (System.Windows.Media.Color)GetValue(LiteralProperty); }
1688 set { SetValue(LiteralProperty, value); }
1692 /// Literalの依存プロパティを表す
1694 public static readonly DependencyProperty LiteralProperty =
1695 DependencyProperty.Register("Literal", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Brown));
1698 /// URLの文字色を表す。これは依存プロパティです
1700 public System.Windows.Media.Color URL
1702 get { return (System.Windows.Media.Color)GetValue(URLProperty); }
1703 set { SetValue(URLProperty, value); }
1709 public static readonly DependencyProperty URLProperty =
1710 DependencyProperty.Register("URL", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1716 public System.Windows.Media.Color LineMarker
1718 get { return (System.Windows.Media.Color)GetValue(LineMarkerProperty); }
1719 set { SetValue(LineMarkerProperty, value); }
1723 /// LineMarkerの依存プロパティを表す
1725 public static readonly DependencyProperty LineMarkerProperty =
1726 DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));
1729 /// 挿入モード時のキャレットの色を表す
1731 public System.Windows.Media.Color InsertCaret
1733 get { return (System.Windows.Media.Color)GetValue(InsertCaretProperty); }
1734 set { SetValue(InsertCaretProperty, value); }
1738 /// InsertCaretの依存プロパティを表す
1740 public static readonly DependencyProperty InsertCaretProperty =
1741 DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1746 public System.Windows.Media.Color UpdateArea
1748 get { return (System.Windows.Media.Color)GetValue(UpdateAreaProperty); }
1749 set { SetValue(UpdateAreaProperty, value); }
1753 /// UpdateAreaの依存プロパティを表す
1755 public static readonly DependencyProperty UpdateAreaProperty =
1756 DependencyProperty.Register("UpdateArea", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));
1759 /// 上書きモード時のキャレット職を表す
1761 public System.Windows.Media.Color OverwriteCaret
1763 get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }
1764 set { SetValue(OverwriteCaretProperty, value); }
1768 /// OverwriteCaretの依存プロパティを表す
1770 public static readonly DependencyProperty OverwriteCaretProperty =
1771 DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1776 public System.Windows.Media.Color LineNumber
1778 get { return (System.Windows.Media.Color)GetValue(LineNumberProperty); }
1779 set { SetValue(LineNumberProperty, value); }
1783 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1785 public static readonly DependencyProperty LineNumberProperty =
1786 DependencyProperty.Register("LineNumber", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray));
1789 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1791 public bool InsertMode
1793 get { return (bool)GetValue(InsertModeProperty); }
1794 set { SetValue(InsertModeProperty, value); }
1798 /// InsertModeの依存プロパティを表す
1800 public static readonly DependencyProperty InsertModeProperty =
1801 DependencyProperty.Register("InsertMode",
1804 new FrameworkPropertyMetadata(true));
1807 /// タブの文字数を表す。これは依存プロパティです
1811 get { return (int)GetValue(TabCharsProperty); }
1812 set { SetValue(TabCharsProperty, value); }
1816 /// TabCharsの依存プロパティを表す
1818 public static readonly DependencyProperty TabCharsProperty =
1819 DependencyProperty.Register("TabChars",
1822 new FrameworkPropertyMetadata(4));
1825 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1827 public bool RectSelectMode
1829 get { return (bool)GetValue(RectSelectModeProperty); }
1830 set { SetValue(RectSelectModeProperty, value); }
1834 /// RectSelectModeの依存プロパティを表す
1836 public static readonly DependencyProperty RectSelectModeProperty =
1837 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1843 /// 変更した場合、レイアウトの再構築を行う必要があります
1845 public LineBreakMethod LineBreakMethod
1847 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1848 set { SetValue(LineBreakProperty, value); }
1852 /// LineBreakMethodの依存プロパティを表す
1854 public static readonly DependencyProperty LineBreakProperty =
1855 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None));
1859 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1862 /// 変更した場合、レイアウトの再構築を行う必要があります
1864 public int LineBreakCharCount
1866 get { return (int)GetValue(LineBreakCharCountProperty); }
1867 set { SetValue(LineBreakCharCountProperty, value); }
1871 /// LineBreakCharCountの依存プロパティを表す
1873 public static readonly DependencyProperty LineBreakCharCountProperty =
1874 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
1877 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1879 public bool DrawCaret
1881 get { return (bool)GetValue(DrawCaretProperty); }
1882 set { SetValue(DrawCaretProperty, value); }
1886 /// DrawCaretの依存プロパティを表す
1888 public static readonly DependencyProperty DrawCaretProperty =
1889 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
1893 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1895 public bool DrawCaretLine
1897 get { return (bool)GetValue(DrawCaretLineProperty); }
1898 set { SetValue(DrawCaretLineProperty, value); }
1902 /// DrawCaretLineの依存プロパティを表す
1904 public static readonly DependencyProperty DrawCaretLineProperty =
1905 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1908 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
1910 public bool DrawLineNumber
1912 get { return (bool)GetValue(DrawLineNumberProperty); }
1913 set { SetValue(DrawLineNumberProperty, value); }
1917 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
1919 public bool DrawRuler
1921 get { return (bool)GetValue(DrawRulerProperty); }
1922 set { SetValue(DrawRulerProperty, value); }
1926 /// DrawRulerの依存プロパティを表す
1928 public static readonly DependencyProperty DrawRulerProperty =
1929 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
1933 /// DrawLineNumberの依存プロパティを表す
1935 public static readonly DependencyProperty DrawLineNumberProperty =
1936 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1939 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
1943 get { return (bool)GetValue(MarkURLProperty); }
1944 set { SetValue(MarkURLProperty, value); }
1948 /// MarkURLの依存プロパティを表す
1950 public static readonly DependencyProperty MarkURLProperty =
1951 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1954 /// 全角スペースを表示するなら真。そうでないなら偽
1956 public bool ShowFullSpace
1958 get { return (bool)GetValue(ShowFullSpaceProperty); }
1959 set { SetValue(ShowFullSpaceProperty, value); }
1963 /// ShowFullSpaceの依存プロパティを表す
1965 public static readonly DependencyProperty ShowFullSpaceProperty =
1966 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
1969 /// 半角スペースを表示するなら真。そうでないなら偽
1971 public bool ShowHalfSpace
1973 get { return (bool)GetValue(ShowHalfSpaceProperty); }
1974 set { SetValue(ShowHalfSpaceProperty, value); }
1978 /// ShowHalfSpaceの依存プロパティを表す
1980 public static readonly DependencyProperty ShowHalfSpaceProperty =
1981 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
1984 /// タブを表示するなら真。そうでないなら偽
1988 get { return (bool)GetValue(ShowTabProperty); }
1989 set { SetValue(ShowTabProperty, value); }
1993 /// ShowTabの依存プロパティを表す
1995 public static readonly DependencyProperty ShowTabProperty =
1996 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
1999 /// 改行マークを表示するなら真。そうでないなら偽
2001 public bool ShowLineBreak
2003 get { return (bool)GetValue(ShowLineBreakProperty); }
2004 set { SetValue(ShowLineBreakProperty, value); }
2008 /// ShowLineBreakの依存プロパティを表す
2010 public static readonly DependencyProperty ShowLineBreakProperty =
2011 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
2016 /// マウスボタン関連のイベントクラス
2018 public sealed class FooMouseButtonEventArgs : MouseButtonEventArgs
2021 /// イベントが発生したドキュメントのインデックス
2032 /// <param name="mouse">マウスデバイス</param>
2033 /// <param name="timestamp">タイムスタンプ</param>
2034 /// <param name="button">ボタン</param>
2035 /// <param name="stylusDevice">スタイラスデバイス</param>
2036 /// <param name="index">インデックス</param>
2037 public FooMouseButtonEventArgs(MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice, int index)
2038 : base(mouse, timestamp, button, stylusDevice)
2046 public sealed class FooMouseEventArgs : MouseEventArgs
2049 /// イベントが発生したドキュメントのインデックス
2060 /// <param name="mouse">マウスデバイス</param>
2061 /// <param name="timestamp">タイムスタンプ</param>
2062 /// <param name="stylusDevice">スタイラスデバイス</param>
2063 /// <param name="index">インデックス</param>
2064 public FooMouseEventArgs(MouseDevice mouse,
2066 StylusDevice stylusDevice,
2068 : base(mouse, timestamp, stylusDevice)