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 this.View.LayoutLines.IsFrozneDirtyFlag = true;
388 await this.Document.LoadAsync(fs, token);
389 this.View.LayoutLines.IsFrozneDirtyFlag = false;
390 TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
391 if (this.verticalScrollBar != null)
392 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
393 this.View.CalculateLineCountOnScreen();
394 this.IsEnabled = true;
398 /// ドキュメントの内容をファイルに保存する
400 /// <param name="filepath">ファイルパス</param>
401 /// <param name="newLine">改行コード</param>
402 /// <param name="enc">エンコード</param>
403 /// <returns>Taskオブジェクト</returns>
404 public async Task SaveFile(string filepath, Encoding enc,string newLine, System.Threading.CancellationTokenSource token)
406 WinFileWriter fs = new WinFileWriter(filepath, enc);
407 fs.NewLine = newLine;
408 await this.Document.SaveAsync(fs, token);
415 public void Dispose()
420 GC.SuppressFinalize(this);
421 this.disposed = true;
427 /// <param name="disposing">真ならマネージドリソースも開放し、そうでないならアンマネージドリソースのみを開放する</param>
428 void Dispose(bool disposing)
432 this.textStore.Dispose();
435 this.Render.Dispose();
437 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
440 void Refresh(Rectangle updateRect)
442 if (this.disposed || this.Visibility == Visibility.Collapsed)
445 this.Render.DrawContent(this.View, this.IsEnabled, updateRect);
449 void CanExecute(object sender, CanExecuteRoutedEventArgs e)
451 e.CanExecute = this.IsEnabled;
454 void ToggleCodePointCommand(object sender, RoutedEventArgs e)
456 if (!this._Controller.ConvertToChar())
457 this._Controller.ConvertToCodePoint();
461 void CopyCommand(object sender, RoutedEventArgs e)
466 void CutCommand(object sender, RoutedEventArgs e)
472 void PasteCommand(object sender, RoutedEventArgs e)
478 void DeleteCommand(object sender, RoutedEventArgs e)
480 int oldLength = this.Document.Length;
481 this._Controller.DoDeleteAction();
485 void SelectAllCommand(object sender, RoutedEventArgs e)
487 this.Select(0, this.Document.Length);
491 void UndoCommand(object sender, RoutedEventArgs e)
493 int oldLength = this.Document.Length;
494 this.Document.UndoManager.undo();
498 void RedoCommand(object sender, RoutedEventArgs e)
500 int oldLength = this.Document.Length;
501 this.Document.UndoManager.redo();
505 void ToggleInsertCommand(object sender, RoutedEventArgs e)
508 this.InsertMode = false;
510 this.InsertMode = true;
514 void ToggleRectSelectCommand(object sender, RoutedEventArgs e)
516 if (this.RectSelectMode)
517 this.RectSelectMode = false;
519 this.RectSelectMode = true;
522 void ToggleFlowDirectionCommand(object sender, RoutedEventArgs e)
524 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
525 this.FlowDirection = System.Windows.FlowDirection.RightToLeft;
527 this.FlowDirection = System.Windows.FlowDirection.LeftToRight;
532 internal TextStore TextStore
534 get { return this.textStore; }
537 bool textStore_IsReadOnly()
542 bool textStore_IsLoading()
547 void textStore_CompositionEnded()
549 TextStoreHelper.EndCompostion(this.Document);
553 void textStore_CompositionUpdated(int start, int end)
555 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
558 bool textStore_CompositionStarted()
560 bool result = TextStoreHelper.StartCompstion(this.Document);
562 System.Media.SystemSounds.Beep.Play();
566 string _textStore_GetString(int start, int length)
568 return this.Document.ToString(start, length);
571 IntPtr _textStore_GetHWnd()
573 var hwndSource = HwndSource.FromVisual(this) as HwndSource;
574 if (hwndSource != null)
575 return hwndSource.Handle;
580 void _textStore_GetStringExtent(
584 out POINT o_bottomRight
587 Point startPos, endPos;
588 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
590 double scale = this.Render.GetScale();
592 startPos = PointToScreen(this.TranslatePoint(startPos.Scale(scale), this));
593 endPos = PointToScreen(this.TranslatePoint(endPos.Scale(scale), this));
595 o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);
596 o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);
599 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
601 var pointTopLeft = new Point(0, 0);
602 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
604 pointTopLeft = PointToScreen(pointTopLeft);
605 pointBottomRight = PointToScreen(pointBottomRight);
607 o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
608 o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
611 void _textStore_GetSelectionIndex(int start_index, int max_count, out DotNetTextStore.TextSelection[] sels)
613 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out sels);
616 void _textStore_SetSelectionIndex(DotNetTextStore.TextSelection[] sels)
618 TextStoreHelper.SetSelectionIndex(this._Controller, this.View, sels);
622 void _textStore_InsertAtSelection(string i_value, ref int o_startIndex, ref int o_endIndex)
624 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
629 /// キーボードフォーカスが取得されたときに呼ばれます
631 /// <param name="e">イベントデーター</param>
632 protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
634 base.OnGotKeyboardFocus(e);
635 this.textStore.SetFocus();
636 this.View.IsFocused = true;
641 /// キーボードフォーカスが失われたときに呼ばれます
643 /// <param name="e">イベントデーター</param>
644 protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
646 base.OnLostKeyboardFocus(e);
647 this.View.IsFocused = false;
653 /// キャレットが移動したときに通知されるイベント
655 public event EventHandler CaretMoved;
658 protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
660 this.peer = new FooTextBoxAutomationPeer(this);
666 protected override void OnTextInput(TextCompositionEventArgs e)
670 this._Controller.DoEnterAction();
671 this.AutoIndentHooker(this, null);
673 else if (e.Text == "\b")
675 this._Controller.DoBackSpaceAction();
679 if(this.IsInputString(e.Text))
680 this._Controller.DoInputString(e.Text);
687 bool IsInputString(string s)
689 foreach (char charCode in s)
691 if ((0x20 <= charCode && charCode <= 0x7e)
699 protected override void OnKeyDown(KeyEventArgs e)
701 if (this.textStore.IsLocked())
704 ModifierKeys modiferKeys = e.KeyboardDevice.Modifiers;
705 bool movedCaret = false;
709 this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
715 this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
721 this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
727 this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
733 this._Controller.Scroll(ScrollDirection.Up,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
738 this._Controller.Scroll(ScrollDirection.Down,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
743 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
744 this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
746 this._Controller.JumpToLineHead(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
751 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
752 this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
754 this._Controller.JumpToLineEnd(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
759 int oldLength = this.Document.Length;
760 if (this.Selection.Length == 0)
761 this._Controller.DoInputChar('\t');
762 else if(this.IsPressedModifierKey(modiferKeys,ModifierKeys.Shift))
763 this._Controller.DownIndent();
765 this._Controller.UpIndent();
770 if (movedCaret && this.peer != null)
771 this.peer.OnNotifyCaretChanged();
775 bool IsPressedModifierKey(ModifierKeys keys, ModifierKeys pressed)
779 if ((keys & pressed) == pressed)
785 /// ダブルクリックされたときに呼ばれます
787 /// <param name="e">イベントパラメーター</param>
789 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
790 /// e.Handledを真にした場合、単語単位の選択が行われなくなります
792 protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
794 var p = this.GetDipFromPoint(e.GetPosition(this));
795 TextPoint tp = this.View.GetTextPointFromPostion(p);
796 if (tp == TextPoint.Null)
798 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
800 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
805 newEventArgs.RoutedEvent = e.RoutedEvent;
806 base.OnMouseDoubleClick(newEventArgs);
808 if (newEventArgs.Handled)
811 if (e.LeftButton == MouseButtonState.Pressed)
814 this.Document.SelectWord((int)index);
815 this.textStore.NotifySelectionChanged();
816 if(this.peer != null)
817 this.peer.OnNotifyCaretChanged();
823 /// マウスボタンが押されたときに呼ばれます
825 /// <param name="e">イベントパラメーター</param>
827 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
828 /// e.Handledを真にした場合、キャレットの移動処理が行われなくなります
830 protected override void OnMouseDown(MouseButtonEventArgs e)
832 var p = this.GetDipFromPoint(e.GetPosition(this));
833 TextPoint tp = this.View.GetTextPointFromPostion(p);
834 if (tp == TextPoint.Null)
836 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
838 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
843 newEventArgs.RoutedEvent = e.RoutedEvent;
844 base.OnMouseDown(newEventArgs);
846 if (newEventArgs.Handled)
849 if (e.LeftButton == MouseButtonState.Pressed)
851 FoldingItem foldingData = this.View.HitFoldingData(p.X,tp.row);
852 if (foldingData != null)
854 if (foldingData.Expand)
855 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
857 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
858 this._Controller.JumpCaret(foldingData.Start,false);
862 this._Controller.JumpCaret(tp.row, tp.col, false);
864 if (this.peer != null)
865 this.peer.OnNotifyCaretChanged();
866 this.View.IsFocused = true;
868 this.Document.SelectGrippers.BottomLeft.Enabled = false;
869 this.Document.SelectGrippers.BottomRight.Enabled = false;
877 /// <param name="e">イベントパラメーター</param>
879 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
880 /// e.Handledを真にした場合、選択処理と状況に応じたカーソルの変化が行われなくなります
882 protected override void OnMouseMove(MouseEventArgs e)
884 var p = this.GetDipFromPoint(e.GetPosition(this));
885 TextPoint tp = this.View.GetTextPointFromPostion(p);
886 if (tp == TextPoint.Null)
891 int index = this.View.GetIndexFromLayoutLine(tp);
893 FooMouseEventArgs newEventArgs = new FooMouseEventArgs(e.MouseDevice, e.Timestamp, e.StylusDevice, index);
894 newEventArgs.RoutedEvent = e.RoutedEvent;
895 base.OnMouseMove(newEventArgs);
897 if (newEventArgs.Handled)
900 if (this.View.HitTextArea(p.X,p.Y))
902 if (this._Controller.IsMarker(tp, HilightType.Url))
903 this.Cursor = Cursors.Hand;
905 this.Cursor = Cursors.IBeam;
907 if (e.LeftButton == MouseButtonState.Pressed)
909 this._Controller.MoveCaretAndSelect(tp);
910 if (this.peer != null)
911 this.peer.OnNotifyCaretChanged();
917 this.Cursor = Cursors.Arrow;
921 Gripper hittedGripper;
922 bool touchScrolled = false;
925 protected override void OnTouchDown(TouchEventArgs e)
927 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
928 this.hittedGripper = this.View.HitGripperFromPoint(p);
932 protected override void OnTouchUp(TouchEventArgs e)
934 if(this.hittedGripper != null || this.touchScrolled)
936 this.hittedGripper = null;
937 this.touchScrolled = false;
941 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
942 TextPoint tp = this.View.GetTextPointFromPostion(p);
943 if (tp == TextPoint.Null)
945 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
947 FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
948 if (foldingData != null)
950 if (foldingData.Expand)
951 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
953 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
954 this._Controller.JumpCaret(foldingData.Start, false);
958 this._Controller.JumpCaret(tp.row, tp.col, false);
960 if (this.peer != null)
961 this.peer.OnNotifyCaretChanged();
962 this.View.IsFocused = true;
964 this.Document.SelectGrippers.BottomRight.Enabled = true;
969 protected override void OnTouchMove(TouchEventArgs e)
971 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
972 if (this.Controller.MoveCaretAndGripper(p, this.hittedGripper))
974 if (this.peer != null)
975 this.peer.OnNotifyCaretChanged();
981 protected override void OnManipulationInertiaStarting(ManipulationInertiaStartingEventArgs e)
986 protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
988 if (this.hittedGripper != null)
991 Point translation = new Point(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
993 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
994 if (Math.Abs(e.CumulativeManipulation.Translation.X) < Math.Abs(e.CumulativeManipulation.Translation.Y))
996 //下に動かした場合はマイナスの値が飛んでくる、上に動かした場合はプラスの値が飛んでくる
997 this.View.Scroll(this.Document.Src.X, this.Document.Src.Y - translation.Y);
998 this.View.IsFocused = false;
999 this.Document.SelectGrippers.BottomLeft.Enabled = false;
1000 this.Document.SelectGrippers.BottomRight.Enabled = false;
1001 this.touchScrolled = true;
1006 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
1009 if (translation.X < 0)
1010 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
1012 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
1013 this.Document.SelectGrippers.BottomLeft.Enabled = false;
1014 this.Document.SelectGrippers.BottomRight.Enabled = false;
1015 this.touchScrolled = true;
1020 private Point GetDipFromPoint(Point p)
1023 this.Render.GetDpi(out dpi,out dpi);
1024 double scale = dpi / 96.0;
1025 return p.Scale(1 / scale);
1029 protected override void OnMouseWheel(MouseWheelEventArgs e)
1031 if(Keyboard.Modifiers == ModifierKeys.None)
1034 this._Controller.Scroll(ScrollDirection.Up, SystemParameters.WheelScrollLines, false, false);
1036 this._Controller.Scroll(ScrollDirection.Down, SystemParameters.WheelScrollLines, false, false);
1038 else if (Keyboard.Modifiers == ModifierKeys.Control)
1040 double newFontSize = this.Render.FontSize;
1045 if (newFontSize > MaxFontSize)
1047 else if (newFontSize < MinFontSize)
1049 this.Render.FontSize = newFontSize;
1050 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
1053 base.OnMouseWheel(e);
1056 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
1058 if (e.Category == UserPreferenceCategory.Keyboard)
1060 int blinkTime = (int)NativeMethods.GetCaretBlinkTime();
1061 this.View.CaretBlink = blinkTime >= 0;
1062 this.View.CaretBlinkTime = blinkTime * 2;
1064 if (e.Category == UserPreferenceCategory.General)
1066 this.View.CaretWidthOnInsertMode = SystemParameters.CaretWidth;
1070 void Document_Update(object sender, DocumentUpdateEventArgs e)
1072 if (this.textStore.IsLocked())
1074 if(e.type == UpdateType.Replace)
1075 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
1076 if(this.peer != null)
1077 this.peer.OnNotifyTextChanged();
1080 void timer_Tick(object sender, EventArgs e)
1082 if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)
1084 if (this.Resize(this.image.ActualWidth, this.image.ActualHeight))
1090 bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding();
1095 this.Refresh(this.View.GetCurrentCaretRect());
1098 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1100 if (this.horizontalScrollBar == null)
1103 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
1104 toX = this.horizontalScrollBar.Value;
1106 toX = -this.horizontalScrollBar.Value;
1107 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
1111 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1113 if (this.verticalScrollBar == null)
1115 int newRow = (int)this.verticalScrollBar.Value;
1116 if (newRow >= this.View.LayoutLines.Count)
1118 this._Controller.Scroll(this.View.Src.X,newRow, false, false);
1122 void View_SrcChanged(object sender, EventArgs e)
1124 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1126 EditView view = this.View;
1127 if (view.Src.Row > this.verticalScrollBar.Maximum)
1128 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
1129 double absoulteX = Math.Abs(view.Src.X);
1130 if(absoulteX > this.horizontalScrollBar.Maximum)
1131 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1132 if(view.Src.Row != this.verticalScrollBar.Value)
1133 this.verticalScrollBar.Value = view.Src.Row;
1134 if (view.Src.X != this.horizontalScrollBar.Value)
1135 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1138 void Controller_SelectionChanged(object sender, EventArgs e)
1140 this.View.CaretBlink = this.View.CaretBlink;
1141 this.CaretMoved(this, null);
1142 //こうしないと選択できなくなってしまう
1143 this.isNotifyChanged = true;
1144 SetValue(SelectedTextProperty, this._Controller.SelectedText);
1145 SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
1146 SetValue(CaretPostionProperty, this.Document.CaretPostion);
1147 this.isNotifyChanged = false;
1148 this.Document.SelectGrippers.BottomLeft.MoveByIndex(this.View, this.Controller.SelectionStart);
1149 this.Document.SelectGrippers.BottomRight.MoveByIndex(this.View, this.Controller.SelectionStart + this.Controller.SelectionLength);
1150 if (this.textStore.IsLocked() == false)
1151 this.textStore.NotifySelectionChanged();
1154 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1156 this.Resize(this.image.ActualWidth, this.image.ActualHeight);
1161 bool Resize(double width, double height)
1163 if (width == 0 || height == 0)
1164 throw new ArgumentOutOfRangeException();
1165 if (this.Render.Resize(width, height))
1167 double scale = this.Render.GetScale();
1168 // RenderはレタリングはDIPだが、widthとheightの値はDPI依存なのでDIPに変換する
1169 this.View.PageBound = new Rectangle(0, 0, width / scale, height / scale);
1171 if (this.horizontalScrollBar != null)
1173 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
1174 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1176 if (this.verticalScrollBar != null)
1178 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
1179 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1187 /// プロパティーが変更されたときに呼ばれます
1189 /// <param name="e">イベントパラメーター</param>
1190 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
1192 switch (e.Property.Name)
1195 this.View.Hilighter = this.Hilighter;
1197 case "TextAntialiasMode":
1198 this.Render.TextAntialiasMode = this.TextAntialiasMode;
1200 case "FoldingStrategy":
1201 this.View.LayoutLines.FoldingStrategy = this.FoldingStrategy;
1203 case "SelectedText":
1204 if (!this.isNotifyChanged)
1205 this._Controller.SelectedText = this.SelectedText;
1208 this._Controller.IndentMode = this.IndentMode;
1211 if(!this.isNotifyChanged)
1212 this.Select(this.Selection.Index, this.Selection.Length);
1214 case "CaretPostion":
1215 if (!this.isNotifyChanged)
1216 this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
1218 case "LineBreakMethod":
1219 this.Document.LineBreak = this.LineBreakMethod;
1221 case "LineBreakCharCount":
1222 this.Document.LineBreakCharCount = this.LineBreakCharCount;
1225 this.View.InsertMode = this.InsertMode;
1228 this.Document.TabStops = this.TabChars;
1230 case "RectSelectMode":
1231 this._Controller.RectSelection = this.RectSelectMode;
1234 this.View.HideCaret = !this.DrawCaret;
1236 case "DrawCaretLine":
1237 this.View.HideLineMarker = !this.DrawCaretLine;
1239 case "DrawLineNumber":
1240 this.Document.DrawLineNumber = this.DrawLineNumber;
1243 this.Render.FontFamily = this.FontFamily;
1246 this.Render.FontSize = this.FontSize;
1249 this.Render.FontStyle = this.FontStyle;
1252 this.Render.FontWeigth = this.FontWeight;
1255 this.Render.Foreground = D2DRender.ToColor4(this.Foreground);
1258 this.Render.Background = D2DRender.ToColor4(this.Background);
1261 this.Render.ControlChar =D2DRender.ToColor4( this.ControlChar);
1264 this.Render.Hilight = D2DRender.ToColor4(this.Hilight);
1267 this.Render.Keyword1 = D2DRender.ToColor4(this.Keyword1);
1270 this.Render.Keyword2 = D2DRender.ToColor4(this.Keyword2);
1273 this.Render.Comment = D2DRender.ToColor4(this.Comment);
1276 this.Render.Literal = D2DRender.ToColor4(this.Literal);
1279 this.Render.Url = D2DRender.ToColor4(this.URL);
1282 this.Render.InsertCaret = D2DRender.ToColor4(this.InsertCaret);
1284 case "OverwriteCaret":
1285 this.Render.OverwriteCaret = D2DRender.ToColor4(this.OverwriteCaret);
1288 this.View.Padding = new Padding((int)this.Padding.Left, (int)this.Padding.Top, (int)this.Padding.Right, (int)this.Padding.Bottom);
1291 this.Render.LineMarker = D2DRender.ToColor4(this.LineMarker);
1294 this.Document.UrlMark = this.MarkURL;
1296 case "ShowFullSpace":
1297 this.Document.ShowFullSpace = this.ShowFullSpace;
1299 case "ShowHalfSpace":
1300 this.Document.ShowHalfSpace = this.ShowHalfSpace;
1303 this.Document.ShowTab = this.ShowTab;
1305 case "ShowLineBreak":
1306 this.Document.ShowLineBreak = this.ShowLineBreak;
1308 case "FlowDirection":
1309 this.Document.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;
1310 this.horizontalScrollBar.FlowDirection = this.FlowDirection;
1313 this.Document.HideRuler = !this.DrawRuler;
1314 this._Controller.JumpCaret(this.Document.CaretPostion.row, this.Document.CaretPostion.col);
1317 this.Render.UpdateArea = D2DRender.ToColor4(this.UpdateArea);
1320 this.Render.LineNumber = D2DRender.ToColor4(this.LineNumber);
1323 base.OnPropertyChanged(e);
1328 internal Controller Controller
1332 return this._Controller;
1337 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1339 public TextAntialiasMode TextAntialiasMode
1341 get { return (TextAntialiasMode)GetValue(TextAntialiasModeProperty); }
1342 set { SetValue(TextAntialiasModeProperty, value); }
1346 /// TextAntialiasModeの依存プロパティを表す
1348 public static readonly DependencyProperty TextAntialiasModeProperty =
1349 DependencyProperty.Register("TextAntialiasMode", typeof(TextAntialiasMode), typeof(FooTextBox), new PropertyMetadata(TextAntialiasMode.Default));
1354 public IHilighter Hilighter
1356 get { return (IHilighter)GetValue(HilighterProperty); }
1357 set { SetValue(HilighterProperty, value); }
1361 /// Hilighterの依存プロパティを表す
1363 public static readonly DependencyProperty HilighterProperty =
1364 DependencyProperty.Register("Hilighter", typeof(IHilighter), typeof(FooTextBox), new PropertyMetadata(null));
1367 /// フォールティングを作成するインターフェイスを表す
1369 public IFoldingStrategy FoldingStrategy
1371 get { return (IFoldingStrategy)GetValue(FoldingStrategyProperty); }
1372 set { SetValue(FoldingStrategyProperty, value); }
1376 /// FoldingStrategyの依存プロパティ
1378 public static readonly DependencyProperty FoldingStrategyProperty =
1379 DependencyProperty.Register("FoldingStrategy", typeof(IFoldingStrategy), typeof(FooTextBox), new PropertyMetadata(null));
1385 public MarkerPatternSet MarkerPatternSet
1389 return this.Document.MarkerPatternSet;
1396 public Document Document
1400 return this._Document;
1404 Document old_doc = this._Document;
1406 if(this._Document != null)
1408 old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
1409 oldLength = old_doc.Length;
1412 this._Document = value;
1413 this._Document.LayoutLines.Render = this.Render;
1414 this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
1415 //初期化が終わっていればすべて存在する
1416 if(this.Controller != null && this.View != null && this.textStore != null)
1418 this.Controller.Document = value;
1419 this.View.Document = value;
1420 this.Controller.AdjustCaret();
1421 this.textStore.NotifyTextChanged(oldLength, value.Length);
1423 //依存プロパティとドキュメント内容が食い違っているので再設定する
1424 this.ShowFullSpace = value.ShowFullSpace;
1425 this.ShowHalfSpace = value.ShowHalfSpace;
1426 this.ShowLineBreak = value.ShowLineBreak;
1427 this.ShowTab = value.ShowTab;
1428 this.FlowDirection = value.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
1429 this.IndentMode = value.IndentMode;
1430 this.DrawCaretLine = !value.HideLineMarker;
1431 this.InsertMode = value.InsertMode;
1432 this.DrawRuler = !value.HideRuler;
1433 this.DrawLineNumber = value.DrawLineNumber;
1434 this.MarkURL = value.UrlMark;
1435 this.LineBreakMethod = value.LineBreak;
1436 this.LineBreakCharCount = value.LineBreakCharCount;
1437 this.TabChars = value.TabStops;
1447 public LineToIndexTable LayoutLineCollection
1449 get { return this.View.LayoutLines; }
1455 public string SelectedText
1457 get { return (string)GetValue(SelectedTextProperty); }
1458 set { SetValue(SelectedTextProperty, value); }
1462 /// SelectedTextの依存プロパティを表す
1464 public static readonly DependencyProperty SelectedTextProperty =
1465 DependencyProperty.Register("SelectedText", typeof(string), typeof(FooTextBox), new PropertyMetadata(null));
1470 public IndentMode IndentMode
1472 get { return (IndentMode)GetValue(IndentModeProperty); }
1473 set { SetValue(IndentModeProperty, value); }
1477 /// IndentModeの依存プロパティを表す
1479 public static readonly DependencyProperty IndentModeProperty =
1480 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab));
1486 /// Lengthが0の場合はキャレット位置を表します。
1487 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1489 public TextRange Selection
1491 get { return (TextRange)GetValue(SelectionProperty); }
1492 set { SetValue(SelectionProperty, value); }
1496 /// Selectionの依存プロパティを表す
1498 public static readonly DependencyProperty SelectionProperty =
1499 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null));
1504 public double MagnificationPower
1506 get { return (double)GetValue(MagnificationPowerPropertyKey.DependencyProperty); }
1512 public static readonly DependencyPropertyKey MagnificationPowerPropertyKey =
1513 DependencyProperty.RegisterReadOnly("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0));
1518 public new FlowDirection FlowDirection
1520 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1521 set { SetValue(FlowDirectionProperty, value); }
1525 /// レタリング方向を表す。これは依存プロパティです
1527 public new static readonly DependencyProperty FlowDirectionProperty =
1528 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight));
1531 /// キャレット位置を表す。これは依存プロパティです
1533 public TextPoint CaretPostion
1535 get { return (TextPoint)GetValue(CaretPostionProperty); }
1536 set { SetValue(CaretPostionProperty, value); }
1540 /// CaretPostionの依存プロパティを表す
1542 public static readonly DependencyProperty CaretPostionProperty =
1543 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(TextPoint.Null));
1546 /// デフォルトの文字色を表す。これは依存プロパティです
1548 public new System.Windows.Media.Color Foreground
1550 get { return (System.Windows.Media.Color)GetValue(ForegroundProperty); }
1551 set { SetValue(ForegroundProperty, value); }
1555 /// Foregroundの依存プロパティを表す
1557 public new static readonly DependencyProperty ForegroundProperty =
1558 DependencyProperty.Register("Foreground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1561 /// 背景色を表す。これは依存プロパティです
1563 public new System.Windows.Media.Color Background
1565 get { return (System.Windows.Media.Color)GetValue(BackgroundProperty); }
1566 set { SetValue(BackgroundProperty, value); }
1570 /// Backgroundの依存プロパティを表す
1572 public new static readonly DependencyProperty BackgroundProperty =
1573 DependencyProperty.Register("Background", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowColor));
1576 /// コントロールコードの文字色を表す。これは依存プロパティです
1578 public System.Windows.Media.Color ControlChar
1580 get { return (System.Windows.Media.Color)GetValue(ControlCharProperty); }
1581 set { SetValue(ControlCharProperty, value); }
1585 /// ControlCharの依存プロパティを表す
1587 public static readonly DependencyProperty ControlCharProperty =
1588 DependencyProperty.Register("ControlChar", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Gray));
1591 /// 選択時の背景色を表す。これは依存プロパティです
1593 public System.Windows.Media.Color Hilight
1595 get { return (System.Windows.Media.Color)GetValue(HilightProperty); }
1596 set { SetValue(HilightProperty, value); }
1600 /// Hilightの依存プロパティを表す
1602 public static readonly DependencyProperty HilightProperty =
1603 DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));
1606 /// キーワード1の文字色を表す。これは依存プロパティです
1608 public System.Windows.Media.Color Keyword1
1610 get { return (System.Windows.Media.Color)GetValue(Keyword1Property); }
1611 set { SetValue(Keyword1Property, value); }
1615 /// Keyword1の依存プロパティを表す
1617 public static readonly DependencyProperty Keyword1Property =
1618 DependencyProperty.Register("Keyword1", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1621 /// キーワード2の文字色を表す。これは依存プロパティです
1623 public System.Windows.Media.Color Keyword2
1625 get { return (System.Windows.Media.Color)GetValue(Keyword2Property); }
1626 set { SetValue(Keyword2Property, value); }
1630 /// Keyword2の依存プロパティを表す
1632 public static readonly DependencyProperty Keyword2Property =
1633 DependencyProperty.Register("Keyword2", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DarkCyan));
1636 /// コメントの文字色を表す。これは依存プロパティです
1638 public System.Windows.Media.Color Comment
1640 get { return (System.Windows.Media.Color)GetValue(CommentProperty); }
1641 set { SetValue(CommentProperty, value); }
1645 /// Commentの依存プロパティを表す
1647 public static readonly DependencyProperty CommentProperty =
1648 DependencyProperty.Register("Comment", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Green));
1651 /// 文字リテラルの文字色を表す。これは依存プロパティです
1653 public System.Windows.Media.Color Literal
1655 get { return (System.Windows.Media.Color)GetValue(LiteralProperty); }
1656 set { SetValue(LiteralProperty, value); }
1660 /// Literalの依存プロパティを表す
1662 public static readonly DependencyProperty LiteralProperty =
1663 DependencyProperty.Register("Literal", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Brown));
1666 /// URLの文字色を表す。これは依存プロパティです
1668 public System.Windows.Media.Color URL
1670 get { return (System.Windows.Media.Color)GetValue(URLProperty); }
1671 set { SetValue(URLProperty, value); }
1677 public static readonly DependencyProperty URLProperty =
1678 DependencyProperty.Register("URL", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1684 public System.Windows.Media.Color LineMarker
1686 get { return (System.Windows.Media.Color)GetValue(LineMarkerProperty); }
1687 set { SetValue(LineMarkerProperty, value); }
1691 /// LineMarkerの依存プロパティを表す
1693 public static readonly DependencyProperty LineMarkerProperty =
1694 DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));
1697 /// 挿入モード時のキャレットの色を表す
1699 public System.Windows.Media.Color InsertCaret
1701 get { return (System.Windows.Media.Color)GetValue(InsertCaretProperty); }
1702 set { SetValue(InsertCaretProperty, value); }
1706 /// InsertCaretの依存プロパティを表す
1708 public static readonly DependencyProperty InsertCaretProperty =
1709 DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1714 public System.Windows.Media.Color UpdateArea
1716 get { return (System.Windows.Media.Color)GetValue(UpdateAreaProperty); }
1717 set { SetValue(UpdateAreaProperty, value); }
1721 /// UpdateAreaの依存プロパティを表す
1723 public static readonly DependencyProperty UpdateAreaProperty =
1724 DependencyProperty.Register("UpdateArea", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));
1727 /// 上書きモード時のキャレット職を表す
1729 public System.Windows.Media.Color OverwriteCaret
1731 get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }
1732 set { SetValue(OverwriteCaretProperty, value); }
1736 /// OverwriteCaretの依存プロパティを表す
1738 public static readonly DependencyProperty OverwriteCaretProperty =
1739 DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1744 public System.Windows.Media.Color LineNumber
1746 get { return (System.Windows.Media.Color)GetValue(LineNumberProperty); }
1747 set { SetValue(LineNumberProperty, value); }
1751 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1753 public static readonly DependencyProperty LineNumberProperty =
1754 DependencyProperty.Register("LineNumber", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray));
1757 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1759 public bool InsertMode
1761 get { return (bool)GetValue(InsertModeProperty); }
1762 set { SetValue(InsertModeProperty, value); }
1766 /// InsertModeの依存プロパティを表す
1768 public static readonly DependencyProperty InsertModeProperty =
1769 DependencyProperty.Register("InsertMode",
1772 new FrameworkPropertyMetadata(true));
1775 /// タブの文字数を表す。これは依存プロパティです
1779 get { return (int)GetValue(TabCharsProperty); }
1780 set { SetValue(TabCharsProperty, value); }
1784 /// TabCharsの依存プロパティを表す
1786 public static readonly DependencyProperty TabCharsProperty =
1787 DependencyProperty.Register("TabChars",
1790 new FrameworkPropertyMetadata(4));
1793 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1795 public bool RectSelectMode
1797 get { return (bool)GetValue(RectSelectModeProperty); }
1798 set { SetValue(RectSelectModeProperty, value); }
1802 /// RectSelectModeの依存プロパティを表す
1804 public static readonly DependencyProperty RectSelectModeProperty =
1805 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1811 /// 変更した場合、レイアウトの再構築を行う必要があります
1813 public LineBreakMethod LineBreakMethod
1815 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1816 set { SetValue(LineBreakProperty, value); }
1820 /// LineBreakMethodの依存プロパティを表す
1822 public static readonly DependencyProperty LineBreakProperty =
1823 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None));
1827 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1830 /// 変更した場合、レイアウトの再構築を行う必要があります
1832 public int LineBreakCharCount
1834 get { return (int)GetValue(LineBreakCharCountProperty); }
1835 set { SetValue(LineBreakCharCountProperty, value); }
1839 /// LineBreakCharCountの依存プロパティを表す
1841 public static readonly DependencyProperty LineBreakCharCountProperty =
1842 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
1845 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1847 public bool DrawCaret
1849 get { return (bool)GetValue(DrawCaretProperty); }
1850 set { SetValue(DrawCaretProperty, value); }
1854 /// DrawCaretの依存プロパティを表す
1856 public static readonly DependencyProperty DrawCaretProperty =
1857 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
1861 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1863 public bool DrawCaretLine
1865 get { return (bool)GetValue(DrawCaretLineProperty); }
1866 set { SetValue(DrawCaretLineProperty, value); }
1870 /// DrawCaretLineの依存プロパティを表す
1872 public static readonly DependencyProperty DrawCaretLineProperty =
1873 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1876 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
1878 public bool DrawLineNumber
1880 get { return (bool)GetValue(DrawLineNumberProperty); }
1881 set { SetValue(DrawLineNumberProperty, value); }
1885 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
1887 public bool DrawRuler
1889 get { return (bool)GetValue(DrawRulerProperty); }
1890 set { SetValue(DrawRulerProperty, value); }
1894 /// DrawRulerの依存プロパティを表す
1896 public static readonly DependencyProperty DrawRulerProperty =
1897 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
1901 /// DrawLineNumberの依存プロパティを表す
1903 public static readonly DependencyProperty DrawLineNumberProperty =
1904 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1907 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
1911 get { return (bool)GetValue(MarkURLProperty); }
1912 set { SetValue(MarkURLProperty, value); }
1916 /// MarkURLの依存プロパティを表す
1918 public static readonly DependencyProperty MarkURLProperty =
1919 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1922 /// 全角スペースを表示するなら真。そうでないなら偽
1924 public bool ShowFullSpace
1926 get { return (bool)GetValue(ShowFullSpaceProperty); }
1927 set { SetValue(ShowFullSpaceProperty, value); }
1931 /// ShowFullSpaceの依存プロパティを表す
1933 public static readonly DependencyProperty ShowFullSpaceProperty =
1934 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
1937 /// 半角スペースを表示するなら真。そうでないなら偽
1939 public bool ShowHalfSpace
1941 get { return (bool)GetValue(ShowHalfSpaceProperty); }
1942 set { SetValue(ShowHalfSpaceProperty, value); }
1946 /// ShowHalfSpaceの依存プロパティを表す
1948 public static readonly DependencyProperty ShowHalfSpaceProperty =
1949 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
1952 /// タブを表示するなら真。そうでないなら偽
1956 get { return (bool)GetValue(ShowTabProperty); }
1957 set { SetValue(ShowTabProperty, value); }
1961 /// ShowTabの依存プロパティを表す
1963 public static readonly DependencyProperty ShowTabProperty =
1964 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
1967 /// 改行マークを表示するなら真。そうでないなら偽
1969 public bool ShowLineBreak
1971 get { return (bool)GetValue(ShowLineBreakProperty); }
1972 set { SetValue(ShowLineBreakProperty, value); }
1976 /// ShowLineBreakの依存プロパティを表す
1978 public static readonly DependencyProperty ShowLineBreakProperty =
1979 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
1984 /// マウスボタン関連のイベントクラス
1986 public sealed class FooMouseButtonEventArgs : MouseButtonEventArgs
1989 /// イベントが発生したドキュメントのインデックス
2000 /// <param name="mouse">マウスデバイス</param>
2001 /// <param name="timestamp">タイムスタンプ</param>
2002 /// <param name="button">ボタン</param>
2003 /// <param name="stylusDevice">スタイラスデバイス</param>
2004 /// <param name="index">インデックス</param>
2005 public FooMouseButtonEventArgs(MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice, int index)
2006 : base(mouse, timestamp, button, stylusDevice)
2014 public sealed class FooMouseEventArgs : MouseEventArgs
2017 /// イベントが発生したドキュメントのインデックス
2028 /// <param name="mouse">マウスデバイス</param>
2029 /// <param name="timestamp">タイムスタンプ</param>
2030 /// <param name="stylusDevice">スタイラスデバイス</param>
2031 /// <param name="index">インデックス</param>
2032 public FooMouseEventArgs(MouseDevice mouse,
2034 StylusDevice stylusDevice,
2036 : base(mouse, timestamp, stylusDevice)