2 * Copyright (C) 2013 FooProject
3 * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
13 using System.Threading.Tasks;
14 using System.Runtime.InteropServices;
16 using System.Windows.Input;
17 using System.Windows.Media;
18 using System.Windows.Controls;
19 using System.Windows.Controls.Primitives;
20 using System.Windows.Documents;
21 using System.Windows.Interop;
22 using System.Windows.Threading;
23 using DotNetTextStore;
24 using DotNetTextStore.UnmanagedAPI.TSF;
25 using DotNetTextStore.UnmanagedAPI.WinDef;
26 using Microsoft.Win32;
28 namespace FooEditEngine.WPF
31 /// WPFでのFooTextBoxの実装
33 public sealed class FooTextBox : Control, IDisposable
35 const double MaxFontSize = 72.0f;
36 const double MinFontSize = 1;
39 Controller _Controller;
42 ScrollBar verticalScrollBar, horizontalScrollBar;
44 DispatcherTimer timer;
45 bool disposed = false;
46 FooTextBoxAutomationPeer peer;
47 bool isNotifyChanged = false;
51 const int Interval = 96;
52 const int IntervalWhenLostFocuse = 160;
56 DefaultStyleKeyProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(typeof(FooTextBox)));
57 KeyboardNavigation.IsTabStopProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(true));
58 KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(KeyboardNavigationMode.None));
66 this.popup = new Popup();
68 this.image = new Image();
69 this.image.Stretch = Stretch.Fill;
70 this.image.HorizontalAlignment = HorizontalAlignment.Left;
71 this.image.VerticalAlignment = VerticalAlignment.Top;
73 this.textStore = new TextStore();
74 this.textStore.IsLoading += textStore_IsLoading;
75 this.textStore.IsReadOnly += textStore_IsReadOnly;
76 this.textStore.GetStringLength += () => this.Document.Length;
77 this.textStore.GetString += _textStore_GetString;
78 this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;
79 this.textStore.SetSelectionIndex += _textStore_SetSelectionIndex;
80 this.textStore.InsertAtSelection += _textStore_InsertAtSelection;
81 this.textStore.GetHWnd += _textStore_GetHWnd;
82 this.textStore.GetScreenExtent += _textStore_GetScreenExtent;
83 this.textStore.GetStringExtent += _textStore_GetStringExtent;
84 this.textStore.CompositionStarted += textStore_CompositionStarted;
85 this.textStore.CompositionUpdated += textStore_CompositionUpdated;
86 this.textStore.CompositionEnded += textStore_CompositionEnded;
88 this.Render = new D2DRender(this, 200, 200,this.image);
90 this.Document = new Document();
92 this.View = new EditView(this.Document, this.Render, new Padding(5, 5, 5, 5));
93 this.View.SrcChanged += View_SrcChanged;
94 this.View.InsertMode = this.InsertMode;
95 this.Document.DrawLineNumber = this.DrawLineNumber;
96 this.View.HideCaret = !this.DrawCaret;
97 this.View.HideLineMarker = !this.DrawCaretLine;
98 this.Document.HideRuler = !this.DrawRuler;
99 this.Document.UrlMark = this.MarkURL;
100 this.Document.TabStops = this.TabChars;
101 this.Document.ShowFullSpace = this.ShowFullSpace;
102 this.Document.ShowHalfSpace = this.ShowHalfSpace;
103 this.Document.ShowTab = this.ShowTab;
105 this._Controller = new Controller(this.Document, this.View);
106 this._Document.SelectionChanged += new EventHandler(Controller_SelectionChanged);
108 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, CopyCommand, CanExecute));
109 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, CutCommand, CanExecute));
110 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, PasteCommand, CanExecute));
111 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, DeleteCommand, CanExecute));
112 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, SelectAllCommand, CanExecute));
113 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, UndoCommand, CanExecute));
114 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, RedoCommand, CanExecute));
115 this.CommandBindings.Add(new CommandBinding(EditingCommands.ToggleInsert, ToggleInsertCommand, CanExecute));
116 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleRectSelectMode, ToggleRectSelectCommand, CanExecute));
117 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleFlowDirection, ToggleFlowDirectionCommand, CanExecute));
118 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleCodePoint, ToggleCodePointCommand, CanExecute));
120 this.InputBindings.Add(new InputBinding(ApplicationCommands.Copy, new KeyGesture(Key.C, ModifierKeys.Control)));
121 this.InputBindings.Add(new InputBinding(ApplicationCommands.Cut, new KeyGesture(Key.X, ModifierKeys.Control)));
122 this.InputBindings.Add(new InputBinding(ApplicationCommands.Paste, new KeyGesture(Key.V, ModifierKeys.Control)));
123 this.InputBindings.Add(new InputBinding(ApplicationCommands.Delete, new KeyGesture(Key.Delete, ModifierKeys.None)));
124 this.InputBindings.Add(new InputBinding(ApplicationCommands.SelectAll, new KeyGesture(Key.A, ModifierKeys.Control)));
125 this.InputBindings.Add(new InputBinding(ApplicationCommands.Undo, new KeyGesture(Key.Z, ModifierKeys.Control)));
126 this.InputBindings.Add(new InputBinding(ApplicationCommands.Redo, new KeyGesture(Key.Y, ModifierKeys.Control)));
127 this.InputBindings.Add(new InputBinding(EditingCommands.ToggleInsert, new KeyGesture(Key.Insert, ModifierKeys.None)));
128 this.InputBindings.Add(new InputBinding(FooTextBoxCommands.ToggleCodePoint, new KeyGesture(Key.X, ModifierKeys.Alt)));
130 this.timer = new DispatcherTimer();
131 this.timer.Interval = new TimeSpan(0, 0, 0, 0, Interval);
132 this.timer.Tick += new EventHandler(timer_Tick);
134 this.Loaded += new RoutedEventHandler(FooTextBox_Loaded);
136 this.AutoIndentHooker = (s,e)=>{};
138 SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
140 this.SystemEvents_UserPreferenceChanged(null, new UserPreferenceChangedEventArgs(UserPreferenceCategory.Keyboard));
142 this.CaretMoved += (s, e) => { };
144 this.IsManipulationEnabled = true;
152 //Dispose(false)を呼び出すと落ちる
157 /// オートインデントを行うためのイベント
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);
176 Grid.SetRow(this.popup, 0);
177 Grid.SetColumn(this.popup, 0);
178 grid.Children.Add(this.popup);
179 //this.popup.PlacementTarget = this;
180 this.popup.Placement = PlacementMode.Absolute;
183 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
184 if (this.horizontalScrollBar != null)
186 this.horizontalScrollBar.SmallChange = 10;
187 this.horizontalScrollBar.LargeChange = 100;
188 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
189 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
191 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
192 if (this.verticalScrollBar != null)
194 this.verticalScrollBar.SmallChange = 1;
195 this.verticalScrollBar.LargeChange = 10;
196 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
197 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
204 /// <param name="start">開始インデックス</param>
205 /// <param name="length">長さ</param>
206 public void Select(int start, int length)
208 this.Document.Select(start, length);
209 this.textStore.NotifySelectionChanged();
213 /// キャレットを指定した行に移動させます
215 /// <param name="index">インデックス</param>
216 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
217 public void JumpCaret(int index)
219 this._Controller.JumpCaret(index);
222 /// キャレットを指定した行と桁に移動させます
224 /// <param name="row">行番号</param>
225 /// <param name="col">桁</param>
226 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
227 public void JumpCaret(int row, int col)
229 this._Controller.JumpCaret(row, col);
233 /// 選択中のテキストをクリップボードにコピーします
237 string text = this._Controller.SelectedText;
238 if (text != null && text != string.Empty)
239 Clipboard.SetText(text);
243 /// 選択中のテキストをクリップボードに切り取ります
247 string text = this._Controller.SelectedText;
248 if (text != null && text != string.Empty)
250 Clipboard.SetText(text);
251 this._Controller.SelectedText = "";
260 if (Clipboard.ContainsText() == false)
262 string text = Clipboard.GetText();
263 this._Controller.SelectedText = text;
269 public void DeSelectAll()
271 this._Controller.DeSelectAll();
272 this.textStore.NotifySelectionChanged();
278 /// <param name="tp">テキストポイント</param>
279 /// <returns>座標</returns>
280 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
281 public System.Windows.Point GetPostionFromTextPoint(TextPoint tp)
283 if (this.Document.FireUpdateEvent == false)
284 throw new InvalidOperationException("");
285 return this.View.GetPostionFromTextPoint(tp);
289 /// 対応するテキストポイントを返します
291 /// <param name="p">クライアント領域の原点を左上とする座標</param>
292 /// <returns>テキストポイント</returns>
293 public TextPoint GetTextPointFromPostion(System.Windows.Point p)
295 if (this.Document.FireUpdateEvent == false)
296 throw new InvalidOperationException("");
297 return this.View.GetTextPointFromPostion(p);
303 /// <param name="row">レイアウト行</param>
304 /// <returns>行の高さ</returns>
305 public double GetLineHeight(int row)
307 if (this.Document.FireUpdateEvent == false)
308 throw new InvalidOperationException("");
309 return this.View.LayoutLines.GetLayout(row).Height;;
313 /// インデックスに対応する座標を得ます
315 /// <param name="index">インデックス</param>
316 /// <returns>座標を返す</returns>
317 public System.Windows.Point GetPostionFromIndex(int index)
319 if (this.Document.FireUpdateEvent == false)
320 throw new InvalidOperationException("");
321 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
322 return this.View.GetPostionFromTextPoint(tp);
328 /// <param name="p">座標</param>
329 /// <returns>インデックスを返す</returns>
330 public int GetIndexFromPostion(System.Windows.Point p)
332 if (this.Document.FireUpdateEvent == false)
333 throw new InvalidOperationException("");
334 TextPoint tp = this.View.GetTextPointFromPostion(p);
335 return this.View.GetIndexFromLayoutLine(tp);
341 public void Refresh()
343 this.Refresh(this.View.PageBound);
347 /// レイアウト行をすべて破棄し、再度レイアウトを行う
349 public void PerfomLayouts()
351 this.View.PerfomLayouts();
357 /// <param name="row">行</param>
358 /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
359 public void ScrollIntoView(int row, bool alignTop)
361 this.View.ScrollIntoView(row, alignTop);
365 /// ストリームからドキュメントを構築する
367 /// <param name="tr">TextReader</param>
368 /// <param name="token">キャンセル用トークン</param>
369 /// <returns>Taskオブジェクト</returns>
370 public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)
372 await this.Document.LoadAsync(tr, token);
376 /// ファイルからドキュメントを構築する
378 /// <param name="filepath">ファイルパス</param>
379 /// <param name="enc">エンコード</param>
380 /// <param name="token">キャンセル用トークン</param>
381 /// <returns>Taskオブジェクト</returns>
382 public async Task LoadFileAsync(string filepath, Encoding enc,System.Threading.CancellationTokenSource token)
384 var fs = new System.IO.StreamReader(filepath, enc);
385 await this.Document.LoadAsync(fs, token);
389 private void Document_LoadProgress(object sender, ProgressEventArgs e)
391 if (e.state == ProgressState.Start)
393 this.IsEnabled = false;
395 else if (e.state == ProgressState.Complete)
397 TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
398 if (this.verticalScrollBar != null)
399 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
400 this.View.CalculateLineCountOnScreen();
401 this.IsEnabled = true;
402 this.Refresh(this.View.PageBound);
407 /// ドキュメントの内容をファイルに保存する
409 /// <param name="filepath">ファイルパス</param>
410 /// <param name="newLine">改行コード</param>
411 /// <param name="enc">エンコード</param>
412 /// <param name="token">キャンセル用トークン</param>
413 /// <returns>Taskオブジェクト</returns>
414 public async Task SaveFile(string filepath, Encoding enc,string newLine, System.Threading.CancellationTokenSource token)
416 var fs = new System.IO.StreamWriter(filepath, false , enc);
417 fs.NewLine = newLine;
418 await this.Document.SaveAsync(fs, token);
425 public void Dispose()
430 GC.SuppressFinalize(this);
431 this.disposed = true;
437 /// <param name="disposing">真ならマネージドリソースも開放し、そうでないならアンマネージドリソースのみを開放する</param>
438 void Dispose(bool disposing)
442 this.textStore.Dispose();
445 this.Render.Dispose();
447 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
450 void Refresh(Rectangle updateRect)
452 if (this.disposed || this.Visibility == Visibility.Collapsed)
455 this.Render.DrawContent(this.View, this.IsEnabled, updateRect);
456 this.Document.IsRequestRedraw = false;
460 void CanExecute(object sender, CanExecuteRoutedEventArgs e)
462 e.CanExecute = this.IsEnabled;
465 void ToggleCodePointCommand(object sender, RoutedEventArgs e)
467 if (!this._Controller.ConvertToChar())
468 this._Controller.ConvertToCodePoint();
472 void CopyCommand(object sender, RoutedEventArgs e)
477 void CutCommand(object sender, RoutedEventArgs e)
483 void PasteCommand(object sender, RoutedEventArgs e)
489 void DeleteCommand(object sender, RoutedEventArgs e)
491 int oldLength = this.Document.Length;
492 this._Controller.DoDeleteAction();
496 void SelectAllCommand(object sender, RoutedEventArgs e)
498 this.Select(0, this.Document.Length);
502 void UndoCommand(object sender, RoutedEventArgs e)
504 int oldLength = this.Document.Length;
505 this.Document.UndoManager.undo();
509 void RedoCommand(object sender, RoutedEventArgs e)
511 int oldLength = this.Document.Length;
512 this.Document.UndoManager.redo();
516 void ToggleInsertCommand(object sender, RoutedEventArgs e)
519 this.InsertMode = false;
521 this.InsertMode = true;
525 void ToggleRectSelectCommand(object sender, RoutedEventArgs e)
527 if (this.RectSelectMode)
528 this.RectSelectMode = false;
530 this.RectSelectMode = true;
533 void ToggleFlowDirectionCommand(object sender, RoutedEventArgs e)
535 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
536 this.FlowDirection = System.Windows.FlowDirection.RightToLeft;
538 this.FlowDirection = System.Windows.FlowDirection.LeftToRight;
543 internal TextStore TextStore
545 get { return this.textStore; }
548 bool textStore_IsReadOnly()
553 bool textStore_IsLoading()
558 void textStore_CompositionEnded()
560 TextStoreHelper.EndCompostion(this.Document);
564 void textStore_CompositionUpdated(int start, int end)
566 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
569 bool textStore_CompositionStarted()
571 bool result = TextStoreHelper.StartCompstion(this.Document);
573 System.Media.SystemSounds.Beep.Play();
577 string _textStore_GetString(int start, int length)
579 return this.Document.ToString(start, length);
582 IntPtr _textStore_GetHWnd()
584 var hwndSource = HwndSource.FromVisual(this) as HwndSource;
585 if (hwndSource != null)
586 return hwndSource.Handle;
591 void _textStore_GetStringExtent(
595 out POINT o_bottomRight
598 Point startPos, endPos;
599 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
601 double scale = this.Render.GetScale();
603 startPos = PointToScreen(this.TranslatePoint(startPos.Scale(scale), this));
604 endPos = PointToScreen(this.TranslatePoint(endPos.Scale(scale), this));
606 o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);
607 o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);
610 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
612 var pointTopLeft = new Point(0, 0);
613 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
615 pointTopLeft = PointToScreen(pointTopLeft);
616 pointBottomRight = PointToScreen(pointBottomRight);
618 o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
619 o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
622 void _textStore_GetSelectionIndex(int start_index, int max_count, out DotNetTextStore.TextSelection[] sels)
625 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out selRange);
627 sels = new DotNetTextStore.TextSelection[1];
628 sels[0] = new DotNetTextStore.TextSelection();
629 sels[0].start = selRange.Index;
630 sels[0].end = selRange.Index + selRange.Length;
633 void _textStore_SetSelectionIndex(DotNetTextStore.TextSelection[] sels)
635 TextStoreHelper.SetSelectionIndex(this._Controller, this.View, sels[0].start, sels[0].end);
639 void _textStore_InsertAtSelection(string i_value, ref int o_startIndex, ref int o_endIndex)
641 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
646 /// キーボードフォーカスが取得されたときに呼ばれます
648 /// <param name="e">イベントデーター</param>
649 protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
651 base.OnGotKeyboardFocus(e);
652 this.textStore.SetFocus();
653 this.View.IsFocused = true;
654 this.timer.Interval = new TimeSpan(0,0,0,0,Interval);
659 /// キーボードフォーカスが失われたときに呼ばれます
661 /// <param name="e">イベントデーター</param>
662 protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
664 base.OnLostKeyboardFocus(e);
665 this.View.IsFocused = false;
666 this.timer.Interval = new TimeSpan(0, 0, 0, 0, IntervalWhenLostFocuse);
672 /// キャレットが移動したときに通知されるイベント
674 public event EventHandler CaretMoved;
677 protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
679 this.peer = new FooTextBoxAutomationPeer(this);
685 protected override void OnTextInput(TextCompositionEventArgs e)
689 this._Controller.DoEnterAction();
690 this.AutoIndentHooker(this, null);
692 else if (e.Text == "\b")
694 this._Controller.DoBackSpaceAction();
698 if(this.IsInputString(e.Text))
699 this._Controller.DoInputString(e.Text);
706 bool IsInputString(string s)
708 foreach (char charCode in s)
710 if ((0x20 <= charCode && charCode <= 0x7e)
718 protected override void OnKeyDown(KeyEventArgs e)
720 if (this.textStore.IsLocked())
723 ModifierKeys modiferKeys = e.KeyboardDevice.Modifiers;
725 var autocomplete = this.Document.AutoComplete as AutoCompleteBox;
726 if (autocomplete != null &&
727 autocomplete.ProcessKeyDown(this,e, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift)))
733 bool movedCaret = false;
737 this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
743 this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
749 this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
755 this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
761 this._Controller.Scroll(ScrollDirection.Up,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
766 this._Controller.Scroll(ScrollDirection.Down,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
771 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
772 this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
774 this._Controller.JumpToLineHead(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
779 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
780 this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
782 this._Controller.JumpToLineEnd(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
787 int oldLength = this.Document.Length;
788 if (this.Selection.Length == 0)
789 this._Controller.DoInputChar('\t');
790 else if(this.IsPressedModifierKey(modiferKeys,ModifierKeys.Shift))
791 this._Controller.DownIndent();
793 this._Controller.UpIndent();
798 if (movedCaret && this.peer != null)
799 this.peer.OnNotifyCaretChanged();
803 bool IsPressedModifierKey(ModifierKeys keys, ModifierKeys pressed)
807 if ((keys & pressed) == pressed)
813 /// ダブルクリックされたときに呼ばれます
815 /// <param name="e">イベントパラメーター</param>
817 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
818 /// e.Handledを真にした場合、単語単位の選択が行われなくなります
820 protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
822 var p = this.GetDipFromPoint(e.GetPosition(this));
823 TextPoint tp = this.View.GetTextPointFromPostion(p);
824 if (tp == TextPoint.Null)
826 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
828 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
833 newEventArgs.RoutedEvent = e.RoutedEvent;
834 base.OnMouseDoubleClick(newEventArgs);
836 if (newEventArgs.Handled)
839 if (e.LeftButton == MouseButtonState.Pressed)
841 if (p.X < this.Render.TextArea.X)
842 this.Document.SelectLine((int)index);
844 this.Document.SelectWord((int)index);
846 this.textStore.NotifySelectionChanged();
847 if(this.peer != null)
848 this.peer.OnNotifyCaretChanged();
854 /// マウスボタンが押されたときに呼ばれます
856 /// <param name="e">イベントパラメーター</param>
858 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
859 /// e.Handledを真にした場合、キャレットの移動処理が行われなくなります
861 protected override void OnMouseDown(MouseButtonEventArgs e)
865 var p = this.GetDipFromPoint(e.GetPosition(this));
866 TextPoint tp = this.View.GetTextPointFromPostion(p);
867 if (tp == TextPoint.Null)
869 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
871 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
876 newEventArgs.RoutedEvent = e.RoutedEvent;
877 base.OnMouseDown(newEventArgs);
879 if (newEventArgs.Handled)
882 if (e.LeftButton == MouseButtonState.Pressed)
884 FoldingItem foldingData = this.View.HitFoldingData(p.X,tp.row);
885 if (foldingData != null)
887 if (foldingData.Expand)
888 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
890 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
891 this._Controller.JumpCaret(foldingData.Start,false);
895 this._Controller.JumpCaret(tp.row, tp.col, false);
897 if (this.peer != null)
898 this.peer.OnNotifyCaretChanged();
899 this.View.IsFocused = true;
901 this.Document.SelectGrippers.BottomLeft.Enabled = false;
902 this.Document.SelectGrippers.BottomRight.Enabled = false;
908 /// マウスのボタンが離されたときに呼ばれます
910 /// <param name="e"></param>
911 protected override void OnMouseUp(MouseButtonEventArgs e)
913 this.ReleaseMouseCapture();
920 /// <param name="e">イベントパラメーター</param>
922 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
923 /// e.Handledを真にした場合、選択処理と状況に応じたカーソルの変化が行われなくなります
925 protected override void OnMouseMove(MouseEventArgs e)
927 bool leftPressed = e.LeftButton == MouseButtonState.Pressed;
929 var p = this.GetDipFromPoint(e.GetPosition(this));
931 TextPointSearchRange searchRange;
932 if (this.View.HitTextArea(p.X, p.Y))
933 searchRange = TextPointSearchRange.TextAreaOnly;
934 else if (leftPressed)
935 searchRange = TextPointSearchRange.Full;
937 searchRange = TextPointSearchRange.TextAreaOnly;
939 TextPoint tp = this.View.GetTextPointFromPostion(p, searchRange);
941 if (tp == TextPoint.Null)
947 int index = this.View.GetIndexFromLayoutLine(tp);
949 FooMouseEventArgs newEventArgs = new FooMouseEventArgs(e.MouseDevice, e.Timestamp, e.StylusDevice, index);
950 newEventArgs.RoutedEvent = e.RoutedEvent;
951 base.OnMouseMove(newEventArgs);
953 if (newEventArgs.Handled)
956 //この状態のときはカーソルがテキストエリア内にある
957 if (searchRange == TextPointSearchRange.TextAreaOnly)
959 if (this._Controller.IsMarker(tp, HilightType.Url))
960 this.Cursor = Cursors.Hand;
962 this.Cursor = Cursors.IBeam;
966 this.Cursor = Cursors.Arrow;
971 bool controlPressed = (Keyboard.GetKeyStates(Key.LeftCtrl) & KeyStates.Down) == KeyStates.Down;
972 this._Controller.MoveCaretAndSelect(tp, controlPressed);
973 if (this.peer != null)
974 this.peer.OnNotifyCaretChanged();
979 Gripper hittedGripper;
980 bool touchScrolled = false;
983 protected override void OnTouchDown(TouchEventArgs e)
985 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
986 this.hittedGripper = this.View.HitGripperFromPoint(p);
987 this.CaptureTouch(e.TouchDevice);
991 protected override void OnTouchUp(TouchEventArgs e)
993 this.ReleaseTouchCapture(e.TouchDevice);
994 if(this.hittedGripper != null || this.touchScrolled)
996 this.hittedGripper = null;
997 this.touchScrolled = false;
1001 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
1002 TextPoint tp = this.View.GetTextPointFromPostion(p);
1003 if (tp == TextPoint.Null)
1005 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
1007 FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
1008 if (foldingData != null)
1010 if (foldingData.Expand)
1011 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
1013 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
1014 this._Controller.JumpCaret(foldingData.Start, false);
1018 this._Controller.JumpCaret(tp.row, tp.col, false);
1020 if (this.peer != null)
1021 this.peer.OnNotifyCaretChanged();
1022 this.View.IsFocused = true;
1024 this.Document.SelectGrippers.BottomLeft.Enabled = false;
1025 this.Document.SelectGrippers.BottomRight.Enabled = true;
1030 protected override void OnTouchMove(TouchEventArgs e)
1032 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
1033 if (this.Controller.MoveCaretAndGripper(p, this.hittedGripper))
1035 if (this.peer != null)
1036 this.peer.OnNotifyCaretChanged();
1042 protected override void OnManipulationInertiaStarting(ManipulationInertiaStartingEventArgs e)
1047 protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
1049 if (this.hittedGripper != null)
1052 Point translation = new Point(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
1054 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
1055 if (Math.Abs(e.CumulativeManipulation.Translation.X) < Math.Abs(e.CumulativeManipulation.Translation.Y))
1057 int deltay = (int)Math.Abs(Math.Ceiling(translation.Y));
1058 if (translation.Y < 0)
1059 this._Controller.ScrollByPixel(ScrollDirection.Down, deltay, false, false);
1061 this._Controller.ScrollByPixel(ScrollDirection.Up, deltay, false, false);
1062 this.touchScrolled = true;
1067 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
1070 if (translation.X < 0)
1071 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
1073 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
1074 this.touchScrolled = true;
1079 private Point GetDipFromPoint(Point p)
1082 this.Render.GetDpi(out dpi,out dpi);
1083 double scale = dpi / 96.0;
1084 return p.Scale(1 / scale);
1088 protected override void OnMouseWheel(MouseWheelEventArgs e)
1090 if(Keyboard.Modifiers == ModifierKeys.None)
1093 this._Controller.Scroll(ScrollDirection.Up, SystemParameters.WheelScrollLines, false, false);
1095 this._Controller.Scroll(ScrollDirection.Down, SystemParameters.WheelScrollLines, false, false);
1097 else if (Keyboard.Modifiers == ModifierKeys.Control)
1099 double newFontSize = this.Render.FontSize;
1104 if (newFontSize > MaxFontSize)
1106 else if (newFontSize < MinFontSize)
1108 this.Render.FontSize = newFontSize;
1109 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
1112 base.OnMouseWheel(e);
1115 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
1117 if (e.Category == UserPreferenceCategory.Keyboard)
1119 int blinkTime = (int)NativeMethods.GetCaretBlinkTime();
1120 this.View.CaretBlink = blinkTime >= 0;
1121 this.View.CaretBlinkTime = blinkTime * 2;
1123 if (e.Category == UserPreferenceCategory.General)
1125 this.View.CaretWidthOnInsertMode = SystemParameters.CaretWidth;
1129 void Document_Update(object sender, DocumentUpdateEventArgs e)
1131 if (this.textStore.IsLocked())
1133 if(e.type == UpdateType.Replace)
1134 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
1135 if(this.peer != null)
1136 this.peer.OnNotifyTextChanged();
1139 void timer_Tick(object sender, EventArgs e)
1141 if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)
1143 if (this.Resize(this.image.ActualWidth, this.image.ActualHeight))
1145 this.Refresh(this.View.PageBound);
1149 bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding() || this.Document.IsRequestRedraw;
1152 this.Refresh(this.View.PageBound);
1154 this.Refresh(this.View.GetCurrentCaretRect());
1157 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1159 if (this.horizontalScrollBar == null)
1162 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
1163 toX = this.horizontalScrollBar.Value;
1165 toX = -this.horizontalScrollBar.Value;
1166 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
1170 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1172 if (this.verticalScrollBar == null)
1174 int newRow = (int)this.verticalScrollBar.Value;
1175 if (newRow >= this.View.LayoutLines.Count)
1177 this._Controller.Scroll(this.View.Src.X,newRow, false, false);
1181 void View_SrcChanged(object sender, EventArgs e)
1183 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1185 EditView view = this.View;
1186 if (view.Src.Row > this.verticalScrollBar.Maximum)
1187 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
1188 double absoulteX = Math.Abs(view.Src.X);
1189 if(absoulteX > this.horizontalScrollBar.Maximum)
1190 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1191 if(view.Src.Row != this.verticalScrollBar.Value)
1192 this.verticalScrollBar.Value = view.Src.Row;
1193 if (view.Src.X != this.horizontalScrollBar.Value)
1194 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1197 void Controller_SelectionChanged(object sender, EventArgs e)
1199 this.View.CaretBlink = this.View.CaretBlink;
1200 this.CaretMoved(this, null);
1201 //こうしないと選択できなくなってしまう
1202 this.isNotifyChanged = true;
1203 SetValue(SelectedTextProperty, this._Controller.SelectedText);
1204 SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
1205 SetValue(CaretPostionProperty, this.Document.CaretPostion);
1206 this.isNotifyChanged = false;
1207 if (this.textStore.IsLocked() == false)
1208 this.textStore.NotifySelectionChanged();
1211 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1213 this.Resize(this.image.ActualWidth, this.image.ActualHeight);
1218 bool Resize(double width, double height)
1220 if (width == 0 || height == 0)
1221 throw new ArgumentOutOfRangeException();
1222 if (this.Render.Resize(width, height))
1224 double scale = this.Render.GetScale();
1225 // RenderはレタリングはDIPだが、widthとheightの値はDPI依存なのでDIPに変換する
1226 this.View.PageBound = new Rectangle(0, 0, width / scale, height / scale);
1228 if (this.horizontalScrollBar != null)
1230 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
1231 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1233 if (this.verticalScrollBar != null)
1235 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
1236 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1243 private void SetDocument(Document value)
1248 Document old_doc = this._Document;
1250 if (this._Document != null)
1252 old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
1253 old_doc.LoadProgress -= Document_LoadProgress;
1254 old_doc.SelectionChanged -= new EventHandler(Controller_SelectionChanged);
1255 old_doc.AutoCompleteChanged -= _Document_AutoCompleteChanged;
1256 oldLength = old_doc.Length;
1257 if (this._Document.AutoComplete != null)
1259 ((AutoCompleteBox)this._Document.AutoComplete).TargetPopup = null;
1260 this._Document.AutoComplete.GetPostion = null;
1261 this._Document.AutoComplete = null;
1265 this._Document = value;
1266 this._Document.LayoutLines.Render = this.Render;
1267 this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
1268 this._Document.LoadProgress += Document_LoadProgress;
1269 this._Document.AutoCompleteChanged += _Document_AutoCompleteChanged;
1270 if (this._Document.AutoComplete != null && this.Document.AutoComplete.GetPostion == null)
1271 this._Document_AutoCompleteChanged(this.Document, null);
1272 //初期化が終わっていればすべて存在する
1273 if (this.Controller != null && this.View != null && this.textStore != null)
1275 this._Document.SelectionChanged += new EventHandler(Controller_SelectionChanged);
1277 this.Controller.Document = value;
1278 this.View.Document = value;
1279 this.Controller.AdjustCaret();
1280 this.textStore.NotifyTextChanged(oldLength, value.Length);
1282 //依存プロパティとドキュメント内容が食い違っているので再設定する
1283 this.ShowFullSpace = value.ShowFullSpace;
1284 this.ShowHalfSpace = value.ShowHalfSpace;
1285 this.ShowLineBreak = value.ShowLineBreak;
1286 this.ShowTab = value.ShowTab;
1287 this.FlowDirection = value.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
1288 this.IndentMode = value.IndentMode;
1289 this.DrawCaretLine = !value.HideLineMarker;
1290 this.InsertMode = value.InsertMode;
1291 this.DrawRuler = !value.HideRuler;
1292 this.DrawLineNumber = value.DrawLineNumber;
1293 this.MarkURL = value.UrlMark;
1294 this.LineBreakMethod = value.LineBreak;
1295 this.LineBreakCharCount = value.LineBreakCharCount;
1296 this.TabChars = value.TabStops;
1302 private void _Document_AutoCompleteChanged(object sender, EventArgs e)
1304 Document doc = (Document)sender;
1305 ((AutoCompleteBox)this._Document.AutoComplete).TargetPopup = this.popup;
1306 this._Document.AutoComplete.GetPostion = (tp, edoc) =>
1308 var p = this.View.GetPostionFromTextPoint(tp);
1309 int height = (int)doc.LayoutLines.GetLayout(edoc.CaretPostion.row).Height;
1311 return PointToScreen(this.TranslatePoint(p.Scale(Util.GetScale()), this));
1316 /// プロパティーが変更されたときに呼ばれます
1318 /// <param name="e">イベントパラメーター</param>
1319 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
1321 switch (e.Property.Name)
1324 this.SetDocument(this.Document);
1327 this.View.Hilighter = this.Hilighter;
1329 case "TextAntialiasMode":
1330 this.Render.TextAntialiasMode = this.TextAntialiasMode;
1332 case "FoldingStrategy":
1333 this.View.LayoutLines.FoldingStrategy = this.FoldingStrategy;
1335 case "SelectedText":
1336 if (!this.isNotifyChanged)
1337 this._Controller.SelectedText = this.SelectedText;
1340 this._Controller.IndentMode = this.IndentMode;
1343 if(!this.isNotifyChanged)
1344 this.Select(this.Selection.Index, this.Selection.Length);
1346 case "CaretPostion":
1347 if (!this.isNotifyChanged)
1348 this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
1350 case "LineBreakMethod":
1351 this.Document.LineBreak = this.LineBreakMethod;
1353 case "LineBreakCharCount":
1354 this.Document.LineBreakCharCount = this.LineBreakCharCount;
1357 this.View.InsertMode = this.InsertMode;
1360 this.Document.TabStops = this.TabChars;
1362 case "RectSelectMode":
1363 this._Controller.RectSelection = this.RectSelectMode;
1366 this.View.HideCaret = !this.DrawCaret;
1368 case "DrawCaretLine":
1369 this.View.HideLineMarker = !this.DrawCaretLine;
1371 case "DrawLineNumber":
1372 this.Document.DrawLineNumber = this.DrawLineNumber;
1375 this.Render.FontFamily = this.FontFamily;
1378 this.Render.FontSize = this.FontSize;
1381 this.Render.FontStyle = this.FontStyle;
1384 this.Render.FontWeigth = this.FontWeight;
1387 this.Render.Foreground = D2DRender.ToColor4(this.Foreground);
1389 case "HilightForeground":
1390 this.Render.HilightForeground = D2DRender.ToColor4(this.HilightForeground);
1393 this.Render.Background = D2DRender.ToColor4(this.Background);
1396 this.Render.ControlChar =D2DRender.ToColor4( this.ControlChar);
1399 this.Render.Hilight = D2DRender.ToColor4(this.Hilight);
1402 this.Render.Keyword1 = D2DRender.ToColor4(this.Keyword1);
1405 this.Render.Keyword2 = D2DRender.ToColor4(this.Keyword2);
1408 this.Render.Comment = D2DRender.ToColor4(this.Comment);
1411 this.Render.Literal = D2DRender.ToColor4(this.Literal);
1414 this.Render.Url = D2DRender.ToColor4(this.URL);
1417 this.Render.InsertCaret = D2DRender.ToColor4(this.InsertCaret);
1419 case "OverwriteCaret":
1420 this.Render.OverwriteCaret = D2DRender.ToColor4(this.OverwriteCaret);
1423 this.View.Padding = new Padding((int)this.Padding.Left, (int)this.Padding.Top, (int)this.Padding.Right, (int)this.Padding.Bottom);
1426 this.Render.LineMarker = D2DRender.ToColor4(this.LineMarker);
1429 this.Document.UrlMark = this.MarkURL;
1431 case "ShowFullSpace":
1432 this.Document.ShowFullSpace = this.ShowFullSpace;
1434 case "ShowHalfSpace":
1435 this.Document.ShowHalfSpace = this.ShowHalfSpace;
1438 this.Document.ShowTab = this.ShowTab;
1440 case "ShowLineBreak":
1441 this.Document.ShowLineBreak = this.ShowLineBreak;
1443 case "FlowDirection":
1444 this.Document.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;
1445 this.horizontalScrollBar.FlowDirection = this.FlowDirection;
1448 this.Document.HideRuler = !this.DrawRuler;
1449 this._Controller.JumpCaret(this.Document.CaretPostion.row, this.Document.CaretPostion.col);
1452 this.Render.UpdateArea = D2DRender.ToColor4(this.UpdateArea);
1455 this.Render.LineNumber = D2DRender.ToColor4(this.LineNumber);
1458 base.OnPropertyChanged(e);
1463 internal Controller Controller
1467 return this._Controller;
1472 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1474 public TextAntialiasMode TextAntialiasMode
1476 get { return (TextAntialiasMode)GetValue(TextAntialiasModeProperty); }
1477 set { SetValue(TextAntialiasModeProperty, value); }
1481 /// TextAntialiasModeの依存プロパティを表す
1483 public static readonly DependencyProperty TextAntialiasModeProperty =
1484 DependencyProperty.Register("TextAntialiasMode", typeof(TextAntialiasMode), typeof(FooTextBox), new PropertyMetadata(TextAntialiasMode.Default));
1489 public IHilighter Hilighter
1491 get { return (IHilighter)GetValue(HilighterProperty); }
1492 set { SetValue(HilighterProperty, value); }
1496 /// Hilighterの依存プロパティを表す
1498 public static readonly DependencyProperty HilighterProperty =
1499 DependencyProperty.Register("Hilighter", typeof(IHilighter), typeof(FooTextBox), new PropertyMetadata(null));
1502 /// フォールティングを作成するインターフェイスを表す
1504 public IFoldingStrategy FoldingStrategy
1506 get { return (IFoldingStrategy)GetValue(FoldingStrategyProperty); }
1507 set { SetValue(FoldingStrategyProperty, value); }
1511 /// FoldingStrategyの依存プロパティ
1513 public static readonly DependencyProperty FoldingStrategyProperty =
1514 DependencyProperty.Register("FoldingStrategy", typeof(IFoldingStrategy), typeof(FooTextBox), new PropertyMetadata(null));
1520 public MarkerPatternSet MarkerPatternSet
1524 return this.Document.MarkerPatternSet;
1531 public Document Document
1533 get { return (Document)GetValue(DocumentProperty); }
1534 set { SetValue(DocumentProperty, value); }
1540 public static readonly DependencyProperty DocumentProperty =
1541 DependencyProperty.Register("Document", typeof(Document), typeof(FooTextBox), new PropertyMetadata(null));
1547 public LineToIndexTable LayoutLineCollection
1549 get { return this.View.LayoutLines; }
1555 public string SelectedText
1557 get { return (string)GetValue(SelectedTextProperty); }
1558 set { SetValue(SelectedTextProperty, value); }
1562 /// SelectedTextの依存プロパティを表す
1564 public static readonly DependencyProperty SelectedTextProperty =
1565 DependencyProperty.Register("SelectedText", typeof(string), typeof(FooTextBox), new PropertyMetadata(null));
1570 public IndentMode IndentMode
1572 get { return (IndentMode)GetValue(IndentModeProperty); }
1573 set { SetValue(IndentModeProperty, value); }
1577 /// IndentModeの依存プロパティを表す
1579 public static readonly DependencyProperty IndentModeProperty =
1580 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab));
1586 /// Lengthが0の場合はキャレット位置を表します。
1587 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1589 public TextRange Selection
1591 get { return (TextRange)GetValue(SelectionProperty); }
1592 set { SetValue(SelectionProperty, value); }
1596 /// Selectionの依存プロパティを表す
1598 public static readonly DependencyProperty SelectionProperty =
1599 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null));
1604 public double MagnificationPower
1606 get { return (double)GetValue(MagnificationPowerPropertyKey.DependencyProperty); }
1612 public static readonly DependencyPropertyKey MagnificationPowerPropertyKey =
1613 DependencyProperty.RegisterReadOnly("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0));
1618 public new FlowDirection FlowDirection
1620 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1621 set { SetValue(FlowDirectionProperty, value); }
1625 /// レタリング方向を表す。これは依存プロパティです
1627 public new static readonly DependencyProperty FlowDirectionProperty =
1628 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight));
1631 /// キャレット位置を表す。これは依存プロパティです
1633 public TextPoint CaretPostion
1635 get { return (TextPoint)GetValue(CaretPostionProperty); }
1636 set { SetValue(CaretPostionProperty, value); }
1640 /// CaretPostionの依存プロパティを表す
1642 public static readonly DependencyProperty CaretPostionProperty =
1643 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(TextPoint.Null));
1646 /// デフォルトの文字色を表す。これは依存プロパティです
1648 public new System.Windows.Media.Color Foreground
1650 get { return (System.Windows.Media.Color)GetValue(ForegroundProperty); }
1651 set { SetValue(ForegroundProperty, value); }
1655 /// Foregroundの依存プロパティを表す
1657 public new static readonly DependencyProperty ForegroundProperty =
1658 DependencyProperty.Register("Foreground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1661 /// 背景色を表す。これは依存プロパティです
1663 public new System.Windows.Media.Color Background
1665 get { return (System.Windows.Media.Color)GetValue(BackgroundProperty); }
1666 set { SetValue(BackgroundProperty, value); }
1670 /// Backgroundの依存プロパティを表す
1672 public new static readonly DependencyProperty BackgroundProperty =
1673 DependencyProperty.Register("Background", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowColor));
1676 /// 選択時の文字色を表す。これは依存プロパティです
1678 public System.Windows.Media.Color HilightForeground
1680 get { return (System.Windows.Media.Color)GetValue(HilightForegroundProperty); }
1681 set { SetValue(HilightForegroundProperty, value); }
1685 /// ControlCharの依存プロパティを表す
1687 public static readonly DependencyProperty HilightForegroundProperty =
1688 DependencyProperty.Register("HilightForeground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.White));
1691 /// コントロールコードの文字色を表す。これは依存プロパティです
1693 public System.Windows.Media.Color ControlChar
1695 get { return (System.Windows.Media.Color)GetValue(ControlCharProperty); }
1696 set { SetValue(ControlCharProperty, value); }
1700 /// ControlCharの依存プロパティを表す
1702 public static readonly DependencyProperty ControlCharProperty =
1703 DependencyProperty.Register("ControlChar", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Gray));
1706 /// 選択時の背景色を表す。これは依存プロパティです
1708 public System.Windows.Media.Color Hilight
1710 get { return (System.Windows.Media.Color)GetValue(HilightProperty); }
1711 set { SetValue(HilightProperty, value); }
1715 /// Hilightの依存プロパティを表す
1717 public static readonly DependencyProperty HilightProperty =
1718 DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));
1721 /// キーワード1の文字色を表す。これは依存プロパティです
1723 public System.Windows.Media.Color Keyword1
1725 get { return (System.Windows.Media.Color)GetValue(Keyword1Property); }
1726 set { SetValue(Keyword1Property, value); }
1730 /// Keyword1の依存プロパティを表す
1732 public static readonly DependencyProperty Keyword1Property =
1733 DependencyProperty.Register("Keyword1", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1736 /// キーワード2の文字色を表す。これは依存プロパティです
1738 public System.Windows.Media.Color Keyword2
1740 get { return (System.Windows.Media.Color)GetValue(Keyword2Property); }
1741 set { SetValue(Keyword2Property, value); }
1745 /// Keyword2の依存プロパティを表す
1747 public static readonly DependencyProperty Keyword2Property =
1748 DependencyProperty.Register("Keyword2", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DarkCyan));
1751 /// コメントの文字色を表す。これは依存プロパティです
1753 public System.Windows.Media.Color Comment
1755 get { return (System.Windows.Media.Color)GetValue(CommentProperty); }
1756 set { SetValue(CommentProperty, value); }
1760 /// Commentの依存プロパティを表す
1762 public static readonly DependencyProperty CommentProperty =
1763 DependencyProperty.Register("Comment", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Green));
1766 /// 文字リテラルの文字色を表す。これは依存プロパティです
1768 public System.Windows.Media.Color Literal
1770 get { return (System.Windows.Media.Color)GetValue(LiteralProperty); }
1771 set { SetValue(LiteralProperty, value); }
1775 /// Literalの依存プロパティを表す
1777 public static readonly DependencyProperty LiteralProperty =
1778 DependencyProperty.Register("Literal", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Brown));
1781 /// URLの文字色を表す。これは依存プロパティです
1783 public System.Windows.Media.Color URL
1785 get { return (System.Windows.Media.Color)GetValue(URLProperty); }
1786 set { SetValue(URLProperty, value); }
1792 public static readonly DependencyProperty URLProperty =
1793 DependencyProperty.Register("URL", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1799 public System.Windows.Media.Color LineMarker
1801 get { return (System.Windows.Media.Color)GetValue(LineMarkerProperty); }
1802 set { SetValue(LineMarkerProperty, value); }
1806 /// LineMarkerの依存プロパティを表す
1808 public static readonly DependencyProperty LineMarkerProperty =
1809 DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));
1812 /// 挿入モード時のキャレットの色を表す
1814 public System.Windows.Media.Color InsertCaret
1816 get { return (System.Windows.Media.Color)GetValue(InsertCaretProperty); }
1817 set { SetValue(InsertCaretProperty, value); }
1821 /// InsertCaretの依存プロパティを表す
1823 public static readonly DependencyProperty InsertCaretProperty =
1824 DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1829 public System.Windows.Media.Color UpdateArea
1831 get { return (System.Windows.Media.Color)GetValue(UpdateAreaProperty); }
1832 set { SetValue(UpdateAreaProperty, value); }
1836 /// UpdateAreaの依存プロパティを表す
1838 public static readonly DependencyProperty UpdateAreaProperty =
1839 DependencyProperty.Register("UpdateArea", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));
1842 /// 上書きモード時のキャレット職を表す
1844 public System.Windows.Media.Color OverwriteCaret
1846 get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }
1847 set { SetValue(OverwriteCaretProperty, value); }
1851 /// OverwriteCaretの依存プロパティを表す
1853 public static readonly DependencyProperty OverwriteCaretProperty =
1854 DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1859 public System.Windows.Media.Color LineNumber
1861 get { return (System.Windows.Media.Color)GetValue(LineNumberProperty); }
1862 set { SetValue(LineNumberProperty, value); }
1866 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1868 public static readonly DependencyProperty LineNumberProperty =
1869 DependencyProperty.Register("LineNumber", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray));
1872 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1874 public bool InsertMode
1876 get { return (bool)GetValue(InsertModeProperty); }
1877 set { SetValue(InsertModeProperty, value); }
1881 /// InsertModeの依存プロパティを表す
1883 public static readonly DependencyProperty InsertModeProperty =
1884 DependencyProperty.Register("InsertMode",
1887 new FrameworkPropertyMetadata(true));
1890 /// タブの文字数を表す。これは依存プロパティです
1894 get { return (int)GetValue(TabCharsProperty); }
1895 set { SetValue(TabCharsProperty, value); }
1899 /// TabCharsの依存プロパティを表す
1901 public static readonly DependencyProperty TabCharsProperty =
1902 DependencyProperty.Register("TabChars",
1905 new FrameworkPropertyMetadata(4));
1908 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1910 public bool RectSelectMode
1912 get { return (bool)GetValue(RectSelectModeProperty); }
1913 set { SetValue(RectSelectModeProperty, value); }
1917 /// RectSelectModeの依存プロパティを表す
1919 public static readonly DependencyProperty RectSelectModeProperty =
1920 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1926 /// 変更した場合、レイアウトの再構築を行う必要があります
1928 public LineBreakMethod LineBreakMethod
1930 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1931 set { SetValue(LineBreakProperty, value); }
1935 /// LineBreakMethodの依存プロパティを表す
1937 public static readonly DependencyProperty LineBreakProperty =
1938 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None));
1942 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1945 /// 変更した場合、レイアウトの再構築を行う必要があります
1947 public int LineBreakCharCount
1949 get { return (int)GetValue(LineBreakCharCountProperty); }
1950 set { SetValue(LineBreakCharCountProperty, value); }
1954 /// LineBreakCharCountの依存プロパティを表す
1956 public static readonly DependencyProperty LineBreakCharCountProperty =
1957 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
1960 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1962 public bool DrawCaret
1964 get { return (bool)GetValue(DrawCaretProperty); }
1965 set { SetValue(DrawCaretProperty, value); }
1969 /// DrawCaretの依存プロパティを表す
1971 public static readonly DependencyProperty DrawCaretProperty =
1972 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
1976 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1978 public bool DrawCaretLine
1980 get { return (bool)GetValue(DrawCaretLineProperty); }
1981 set { SetValue(DrawCaretLineProperty, value); }
1985 /// DrawCaretLineの依存プロパティを表す
1987 public static readonly DependencyProperty DrawCaretLineProperty =
1988 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1991 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
1993 public bool DrawLineNumber
1995 get { return (bool)GetValue(DrawLineNumberProperty); }
1996 set { SetValue(DrawLineNumberProperty, value); }
2000 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
2002 public bool DrawRuler
2004 get { return (bool)GetValue(DrawRulerProperty); }
2005 set { SetValue(DrawRulerProperty, value); }
2009 /// DrawRulerの依存プロパティを表す
2011 public static readonly DependencyProperty DrawRulerProperty =
2012 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
2016 /// DrawLineNumberの依存プロパティを表す
2018 public static readonly DependencyProperty DrawLineNumberProperty =
2019 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
2022 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
2026 get { return (bool)GetValue(MarkURLProperty); }
2027 set { SetValue(MarkURLProperty, value); }
2031 /// MarkURLの依存プロパティを表す
2033 public static readonly DependencyProperty MarkURLProperty =
2034 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
2037 /// 全角スペースを表示するなら真。そうでないなら偽
2039 public bool ShowFullSpace
2041 get { return (bool)GetValue(ShowFullSpaceProperty); }
2042 set { SetValue(ShowFullSpaceProperty, value); }
2046 /// ShowFullSpaceの依存プロパティを表す
2048 public static readonly DependencyProperty ShowFullSpaceProperty =
2049 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
2052 /// 半角スペースを表示するなら真。そうでないなら偽
2054 public bool ShowHalfSpace
2056 get { return (bool)GetValue(ShowHalfSpaceProperty); }
2057 set { SetValue(ShowHalfSpaceProperty, value); }
2061 /// ShowHalfSpaceの依存プロパティを表す
2063 public static readonly DependencyProperty ShowHalfSpaceProperty =
2064 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
2067 /// タブを表示するなら真。そうでないなら偽
2071 get { return (bool)GetValue(ShowTabProperty); }
2072 set { SetValue(ShowTabProperty, value); }
2076 /// ShowTabの依存プロパティを表す
2078 public static readonly DependencyProperty ShowTabProperty =
2079 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
2082 /// 改行マークを表示するなら真。そうでないなら偽
2084 public bool ShowLineBreak
2086 get { return (bool)GetValue(ShowLineBreakProperty); }
2087 set { SetValue(ShowLineBreakProperty, value); }
2091 /// ShowLineBreakの依存プロパティを表す
2093 public static readonly DependencyProperty ShowLineBreakProperty =
2094 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
2099 /// マウスボタン関連のイベントクラス
2101 public sealed class FooMouseButtonEventArgs : MouseButtonEventArgs
2104 /// イベントが発生したドキュメントのインデックス
2115 /// <param name="mouse">マウスデバイス</param>
2116 /// <param name="timestamp">タイムスタンプ</param>
2117 /// <param name="button">ボタン</param>
2118 /// <param name="stylusDevice">スタイラスデバイス</param>
2119 /// <param name="index">インデックス</param>
2120 public FooMouseButtonEventArgs(MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice, int index)
2121 : base(mouse, timestamp, button, stylusDevice)
2129 public sealed class FooMouseEventArgs : MouseEventArgs
2132 /// イベントが発生したドキュメントのインデックス
2143 /// <param name="mouse">マウスデバイス</param>
2144 /// <param name="timestamp">タイムスタンプ</param>
2145 /// <param name="stylusDevice">スタイラスデバイス</param>
2146 /// <param name="index">インデックス</param>
2147 public FooMouseEventArgs(MouseDevice mouse,
2149 StylusDevice stylusDevice,
2151 : base(mouse, timestamp, stylusDevice)