2 * Copyright (C) 2013 FooProject
3 * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
13 using System.Threading.Tasks;
14 using System.Runtime.InteropServices;
16 using System.Windows.Input;
17 using System.Windows.Media;
18 using System.Windows.Controls;
19 using System.Windows.Controls.Primitives;
20 using System.Windows.Documents;
21 using System.Windows.Interop;
22 using System.Windows.Threading;
23 using DotNetTextStore;
24 using DotNetTextStore.UnmanagedAPI.TSF;
25 using DotNetTextStore.UnmanagedAPI.WinDef;
26 using Microsoft.Win32;
28 namespace FooEditEngine.WPF
31 /// WPFでのFooTextBoxの実装
33 public sealed class FooTextBox : Control, IDisposable
35 const double MaxFontSize = 72.0f;
36 const double MinFontSize = 1;
39 Controller _Controller;
42 ScrollBar verticalScrollBar, horizontalScrollBar;
44 DispatcherTimer timer;
45 bool disposed = false;
46 FooTextBoxAutomationPeer peer;
47 bool isNotifyChanged = false;
51 const int Interval = 96;
52 const int IntervalWhenLostFocuse = 160;
56 DefaultStyleKeyProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(typeof(FooTextBox)));
57 KeyboardNavigation.IsTabStopProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(true));
58 KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(KeyboardNavigationMode.None));
66 this.popup = new Popup();
68 this.image = new Image();
69 this.image.Stretch = Stretch.Fill;
70 this.image.HorizontalAlignment = HorizontalAlignment.Left;
71 this.image.VerticalAlignment = VerticalAlignment.Top;
73 this.textStore = new TextStore();
74 this.textStore.IsLoading += textStore_IsLoading;
75 this.textStore.IsReadOnly += textStore_IsReadOnly;
76 this.textStore.GetStringLength += () => this.Document.Length;
77 this.textStore.GetString += _textStore_GetString;
78 this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;
79 this.textStore.SetSelectionIndex += _textStore_SetSelectionIndex;
80 this.textStore.InsertAtSelection += _textStore_InsertAtSelection;
81 this.textStore.GetHWnd += _textStore_GetHWnd;
82 this.textStore.GetScreenExtent += _textStore_GetScreenExtent;
83 this.textStore.GetStringExtent += _textStore_GetStringExtent;
84 this.textStore.CompositionStarted += textStore_CompositionStarted;
85 this.textStore.CompositionUpdated += textStore_CompositionUpdated;
86 this.textStore.CompositionEnded += textStore_CompositionEnded;
88 this.Render = new D2DRender(this, 200, 200,this.image);
90 this.Document = new Document();
92 this._View = new EditView(this.Document, this.Render, new Padding(5, 5, 5, 5));
93 this._View.SrcChanged += View_SrcChanged;
94 this._View.InsertMode = this.InsertMode;
95 this.Document.DrawLineNumber = this.DrawLineNumber;
96 this._View.HideCaret = !this.DrawCaret;
97 this._View.HideLineMarker = !this.DrawCaretLine;
98 this.Document.HideRuler = !this.DrawRuler;
99 this.Document.UrlMark = this.MarkURL;
100 this.Document.TabStops = this.TabChars;
101 this.Document.ShowFullSpace = this.ShowFullSpace;
102 this.Document.ShowHalfSpace = this.ShowHalfSpace;
103 this.Document.ShowTab = this.ShowTab;
105 this._Controller = new Controller(this.Document, this._View);
106 this._Document.SelectionChanged += new EventHandler(Controller_SelectionChanged);
108 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, CopyCommand, CanExecute));
109 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, CutCommand, CanExecute));
110 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, PasteCommand, CanExecute));
111 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, DeleteCommand, CanExecute));
112 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, SelectAllCommand, CanExecute));
113 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, UndoCommand, CanExecute));
114 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, RedoCommand, CanExecute));
115 this.CommandBindings.Add(new CommandBinding(EditingCommands.ToggleInsert, ToggleInsertCommand, CanExecute));
116 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleRectSelectMode, ToggleRectSelectCommand, CanExecute));
117 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleFlowDirection, ToggleFlowDirectionCommand, CanExecute));
118 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleCodePoint, ToggleCodePointCommand, CanExecute));
120 this.InputBindings.Add(new InputBinding(ApplicationCommands.Copy, new KeyGesture(Key.C, ModifierKeys.Control)));
121 this.InputBindings.Add(new InputBinding(ApplicationCommands.Cut, new KeyGesture(Key.X, ModifierKeys.Control)));
122 this.InputBindings.Add(new InputBinding(ApplicationCommands.Paste, new KeyGesture(Key.V, ModifierKeys.Control)));
123 this.InputBindings.Add(new InputBinding(ApplicationCommands.Delete, new KeyGesture(Key.Delete, ModifierKeys.None)));
124 this.InputBindings.Add(new InputBinding(ApplicationCommands.SelectAll, new KeyGesture(Key.A, ModifierKeys.Control)));
125 this.InputBindings.Add(new InputBinding(ApplicationCommands.Undo, new KeyGesture(Key.Z, ModifierKeys.Control)));
126 this.InputBindings.Add(new InputBinding(ApplicationCommands.Redo, new KeyGesture(Key.Y, ModifierKeys.Control)));
127 this.InputBindings.Add(new InputBinding(EditingCommands.ToggleInsert, new KeyGesture(Key.Insert, ModifierKeys.None)));
128 this.InputBindings.Add(new InputBinding(FooTextBoxCommands.ToggleCodePoint, new KeyGesture(Key.X, ModifierKeys.Alt)));
130 this.timer = new DispatcherTimer();
131 this.timer.Interval = new TimeSpan(0, 0, 0, 0, Interval);
132 this.timer.Tick += new EventHandler(timer_Tick);
134 this.Loaded += new RoutedEventHandler(FooTextBox_Loaded);
136 SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
138 this.SystemEvents_UserPreferenceChanged(null, new UserPreferenceChangedEventArgs(UserPreferenceCategory.Keyboard));
140 this.CaretMoved += (s, e) => { };
142 this.IsManipulationEnabled = true;
150 //Dispose(false)を呼び出すと落ちる
157 public override void OnApplyTemplate()
159 base.OnApplyTemplate();
161 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
164 Grid.SetRow(this.image, 0);
165 Grid.SetColumn(this.image, 0);
166 grid.Children.Add(this.image);
168 Grid.SetRow(this.popup, 0);
169 Grid.SetColumn(this.popup, 0);
170 grid.Children.Add(this.popup);
171 //this.popup.PlacementTarget = this;
172 this.popup.Placement = PlacementMode.Absolute;
175 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
176 if (this.horizontalScrollBar != null)
178 this.horizontalScrollBar.SmallChange = 10;
179 this.horizontalScrollBar.LargeChange = 100;
180 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
181 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
183 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
184 if (this.verticalScrollBar != null)
186 this.verticalScrollBar.SmallChange = 1;
187 this.verticalScrollBar.LargeChange = 10;
188 this.verticalScrollBar.Maximum = this.Document.LayoutLines.Count - 1;
189 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
196 /// <param name="start">開始インデックス</param>
197 /// <param name="length">長さ</param>
198 public void Select(int start, int length)
200 this.Document.Select(start, length);
201 this.textStore.NotifySelectionChanged();
205 /// キャレットを指定した行に移動させます
207 /// <param name="index">インデックス</param>
208 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
209 public void JumpCaret(int index)
211 this._Controller.JumpCaret(index);
214 /// キャレットを指定した行と桁に移動させます
216 /// <param name="row">行番号</param>
217 /// <param name="col">桁</param>
218 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
219 public void JumpCaret(int row, int col)
221 this._Controller.JumpCaret(row, col);
225 /// 選択中のテキストをクリップボードにコピーします
229 string text = this._Controller.SelectedText;
230 if (text != null && text != string.Empty)
231 Clipboard.SetText(text);
235 /// 選択中のテキストをクリップボードに切り取ります
239 string text = this._Controller.SelectedText;
240 if (text != null && text != string.Empty)
242 Clipboard.SetText(text);
243 this._Controller.SelectedText = "";
252 if (Clipboard.ContainsText() == false)
254 string text = Clipboard.GetText();
255 this._Controller.SelectedText = text;
261 public void DeSelectAll()
263 this._Controller.DeSelectAll();
264 this.textStore.NotifySelectionChanged();
270 /// <param name="tp">テキストポイント</param>
271 /// <returns>座標</returns>
272 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
273 public System.Windows.Point GetPostionFromTextPoint(TextPoint tp)
275 if (this.Document.FireUpdateEvent == false)
276 throw new InvalidOperationException("");
277 return this.image.TranslatePoint(this._View.GetPostionFromTextPoint(tp),this);
281 /// 対応するテキストポイントを返します
283 /// <param name="p">クライアント領域の原点を左上とする座標</param>
284 /// <returns>テキストポイント</returns>
285 public TextPoint GetTextPointFromPostion(System.Windows.Point p)
287 if (this.Document.FireUpdateEvent == false)
288 throw new InvalidOperationException("");
289 System.Windows.Point relP = this.TranslatePoint(p, this.image);
290 return this._View.GetTextPointFromPostion(p);
296 /// <param name="row">レイアウト行</param>
297 /// <returns>行の高さ</returns>
298 public double GetLineHeight(int row)
300 if (this.Document.FireUpdateEvent == false)
301 throw new InvalidOperationException("");
302 return this._View.LayoutLines.GetLayout(row).Height;;
306 /// インデックスに対応する座標を得ます
308 /// <param name="index">インデックス</param>
309 /// <returns>座標を返す</returns>
310 public System.Windows.Point GetPostionFromIndex(int index)
312 if (this.Document.FireUpdateEvent == false)
313 throw new InvalidOperationException("");
314 TextPoint tp = this._View.GetLayoutLineFromIndex(index);
315 return this._View.GetPostionFromTextPoint(tp);
321 /// <param name="p">座標</param>
322 /// <returns>インデックスを返す</returns>
323 public int GetIndexFromPostion(System.Windows.Point p)
325 if (this.Document.FireUpdateEvent == false)
326 throw new InvalidOperationException("");
327 TextPoint tp = this._View.GetTextPointFromPostion(p);
328 return this._View.GetIndexFromLayoutLine(tp);
334 public void Refresh()
336 this.Refresh(this._View.PageBound);
340 /// レイアウト行をすべて破棄し、再度レイアウトを行う
342 public void PerfomLayouts()
344 this.Document.PerformLayout();
350 /// <param name="row">行</param>
351 /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
352 public void ScrollIntoView(int row, bool alignTop)
354 this._View.ScrollIntoView(row, alignTop);
358 /// ストリームからドキュメントを構築する
360 /// <param name="tr">TextReader</param>
361 /// <param name="token">キャンセル用トークン</param>
362 /// <returns>Taskオブジェクト</returns>
363 public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)
365 await this.Document.LoadAsync(tr, token);
369 /// ファイルからドキュメントを構築する
371 /// <param name="filepath">ファイルパス</param>
372 /// <param name="enc">エンコード</param>
373 /// <param name="token">キャンセル用トークン</param>
374 /// <returns>Taskオブジェクト</returns>
375 public async Task LoadFileAsync(string filepath, Encoding enc,System.Threading.CancellationTokenSource token)
377 var fs = new System.IO.StreamReader(filepath, enc);
378 await this.Document.LoadAsync(fs, token);
382 private void Document_LoadProgress(object sender, ProgressEventArgs e)
384 if (e.state == ProgressState.Start)
386 this.IsEnabled = false;
388 else if (e.state == ProgressState.Complete)
390 TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
391 if (this.verticalScrollBar != null)
392 this.verticalScrollBar.Maximum = this._View.LayoutLines.Count;
393 this._View.CalculateWhloeViewPort();
394 this._View.CalculateLineCountOnScreen();
395 this.IsEnabled = true;
396 this.Refresh(this._View.PageBound);
401 /// ドキュメントの内容をファイルに保存する
403 /// <param name="filepath">ファイルパス</param>
404 /// <param name="newLine">改行コード</param>
405 /// <param name="enc">エンコード</param>
406 /// <param name="token">キャンセル用トークン</param>
407 /// <returns>Taskオブジェクト</returns>
408 public async Task SaveFile(string filepath, Encoding enc,string newLine, System.Threading.CancellationTokenSource token)
410 var fs = new System.IO.StreamWriter(filepath, false , enc);
411 fs.NewLine = newLine;
412 await this.Document.SaveAsync(fs, token);
419 public void Dispose()
424 GC.SuppressFinalize(this);
425 this.disposed = true;
431 /// <param name="disposing">真ならマネージドリソースも開放し、そうでないならアンマネージドリソースのみを開放する</param>
432 void Dispose(bool disposing)
436 this.textStore.Dispose();
438 this._View.Dispose();
439 this.Render.Dispose();
441 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
444 void Refresh(Rectangle updateRect)
446 if (this.disposed || this.Visibility == Visibility.Collapsed)
449 this.Render.DrawContent(this._View, this.IsEnabled, updateRect);
450 this.Document.IsRequestRedraw = false;
454 void CanExecute(object sender, CanExecuteRoutedEventArgs e)
456 e.CanExecute = this.IsEnabled;
459 void ToggleCodePointCommand(object sender, RoutedEventArgs e)
461 if (!this._Controller.ConvertToChar())
462 this._Controller.ConvertToCodePoint();
466 void CopyCommand(object sender, RoutedEventArgs e)
471 void CutCommand(object sender, RoutedEventArgs e)
477 void PasteCommand(object sender, RoutedEventArgs e)
483 void DeleteCommand(object sender, RoutedEventArgs e)
485 int oldLength = this.Document.Length;
486 this._Controller.DoDeleteAction();
490 void SelectAllCommand(object sender, RoutedEventArgs e)
492 this.Select(0, this.Document.Length);
496 void UndoCommand(object sender, RoutedEventArgs e)
498 int oldLength = this.Document.Length;
499 this.Document.UndoManager.undo();
503 void RedoCommand(object sender, RoutedEventArgs e)
505 int oldLength = this.Document.Length;
506 this.Document.UndoManager.redo();
510 void ToggleInsertCommand(object sender, RoutedEventArgs e)
513 this.InsertMode = false;
515 this.InsertMode = true;
519 void ToggleRectSelectCommand(object sender, RoutedEventArgs e)
521 if (this.RectSelectMode)
522 this.RectSelectMode = false;
524 this.RectSelectMode = true;
527 void ToggleFlowDirectionCommand(object sender, RoutedEventArgs e)
529 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
530 this.FlowDirection = System.Windows.FlowDirection.RightToLeft;
532 this.FlowDirection = System.Windows.FlowDirection.LeftToRight;
537 internal TextStore TextStore
539 get { return this.textStore; }
542 bool textStore_IsReadOnly()
547 bool textStore_IsLoading()
552 void textStore_CompositionEnded()
554 TextStoreHelper.EndCompostion(this.Document);
558 void textStore_CompositionUpdated(int start, int end)
560 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this._View, start, end))
563 bool textStore_CompositionStarted()
565 bool result = TextStoreHelper.StartCompstion(this.Document);
567 System.Media.SystemSounds.Beep.Play();
571 string _textStore_GetString(int start, int length)
573 return this.Document.ToString(start, length);
576 IntPtr _textStore_GetHWnd()
578 var hwndSource = HwndSource.FromVisual(this) as HwndSource;
579 if (hwndSource != null)
580 return hwndSource.Handle;
585 void _textStore_GetStringExtent(
589 out POINT o_bottomRight
592 Point startPos, endPos;
593 TextStoreHelper.GetStringExtent(this.Document, this._View, i_startIndex, i_endIndex, out startPos, out endPos);
595 double scale = this.Render.GetScale();
597 startPos = PointToScreen(this.TranslatePoint(startPos.Scale(scale), this));
598 endPos = PointToScreen(this.TranslatePoint(endPos.Scale(scale), this));
600 o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);
601 o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);
604 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
606 var pointTopLeft = new Point(0, 0);
607 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
609 pointTopLeft = PointToScreen(pointTopLeft);
610 pointBottomRight = PointToScreen(pointBottomRight);
612 o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
613 o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
616 void _textStore_GetSelectionIndex(int start_index, int max_count, out DotNetTextStore.TextSelection[] sels)
619 TextStoreHelper.GetSelection(this._Controller, this._View.Selections, out selRange);
621 sels = new DotNetTextStore.TextSelection[1];
622 sels[0] = new DotNetTextStore.TextSelection();
623 sels[0].start = selRange.Index;
624 sels[0].end = selRange.Index + selRange.Length;
627 void _textStore_SetSelectionIndex(DotNetTextStore.TextSelection[] sels)
629 TextStoreHelper.SetSelectionIndex(this._Controller, this._View, sels[0].start, sels[0].end);
633 void _textStore_InsertAtSelection(string i_value, ref int o_startIndex, ref int o_endIndex)
635 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
640 /// キーボードフォーカスが取得されたときに呼ばれます
642 /// <param name="e">イベントデーター</param>
643 protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
645 base.OnGotKeyboardFocus(e);
646 this.textStore.SetFocus();
647 this._View.IsFocused = true;
648 this.timer.Interval = new TimeSpan(0,0,0,0,Interval);
653 /// キーボードフォーカスが失われたときに呼ばれます
655 /// <param name="e">イベントデーター</param>
656 protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
658 base.OnLostKeyboardFocus(e);
659 this._View.IsFocused = false;
660 this.timer.Interval = new TimeSpan(0, 0, 0, 0, IntervalWhenLostFocuse);
666 /// キャレットが移動したときに通知されるイベント
668 public event EventHandler CaretMoved;
671 protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
673 this.peer = new FooTextBoxAutomationPeer(this);
679 protected override void OnTextInput(TextCompositionEventArgs e)
683 this._Controller.DoEnterAction();
685 else if (e.Text == "\b")
687 this._Controller.DoBackSpaceAction();
691 if(this.IsInputString(e.Text))
692 this._Controller.DoInputString(e.Text);
699 bool IsInputString(string s)
701 foreach (char charCode in s)
703 if ((0x20 <= charCode && charCode <= 0x7e)
711 protected override void OnKeyDown(KeyEventArgs e)
713 if (this.textStore.IsLocked())
716 ModifierKeys modiferKeys = e.KeyboardDevice.Modifiers;
718 var autocomplete = this.Document.AutoComplete as AutoCompleteBox;
719 if (autocomplete != null &&
720 autocomplete.ProcessKeyDown(this,e, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift)))
726 bool movedCaret = false;
727 double alignedPage = (int)(this.Render.TextArea.Height / this.Render.emSize.Height) * this.Render.emSize.Height;
731 this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
737 this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
743 this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
749 this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
755 this._Controller.ScrollByPixel(ScrollDirection.Up, alignedPage, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), true);
760 this._Controller.ScrollByPixel(ScrollDirection.Down, alignedPage, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), true);
765 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
766 this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
768 this._Controller.JumpToLineHead(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
773 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
774 this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
776 this._Controller.JumpToLineEnd(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
781 int oldLength = this.Document.Length;
782 if (this.Selection.Length == 0)
783 this._Controller.DoInputChar('\t');
784 else if(this.IsPressedModifierKey(modiferKeys,ModifierKeys.Shift))
785 this._Controller.DownIndent();
787 this._Controller.UpIndent();
792 if (movedCaret && this.peer != null)
793 this.peer.OnNotifyCaretChanged();
797 bool IsPressedModifierKey(ModifierKeys keys, ModifierKeys pressed)
801 if ((keys & pressed) == pressed)
807 /// ダブルクリックされたときに呼ばれます
809 /// <param name="e">イベントパラメーター</param>
811 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
812 /// e.Handledを真にした場合、単語単位の選択が行われなくなります
814 protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
816 var p = this.GetDipFromPoint(e.GetPosition(this));
817 TextPoint tp = this._View.GetTextPointFromPostion(p);
818 if (tp == TextPoint.Null)
820 int index = this._View.LayoutLines.GetIndexFromTextPoint(tp);
822 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
827 newEventArgs.RoutedEvent = e.RoutedEvent;
828 base.OnMouseDoubleClick(newEventArgs);
830 if (newEventArgs.Handled)
833 if (e.LeftButton == MouseButtonState.Pressed)
835 if (p.X < this.Render.TextArea.X)
836 this.Document.SelectLine((int)index);
838 this.Document.SelectWord((int)index);
840 this.textStore.NotifySelectionChanged();
841 if(this.peer != null)
842 this.peer.OnNotifyCaretChanged();
848 /// マウスボタンが押されたときに呼ばれます
850 /// <param name="e">イベントパラメーター</param>
852 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
853 /// e.Handledを真にした場合、キャレットの移動処理が行われなくなります
855 protected override void OnMouseDown(MouseButtonEventArgs e)
859 var p = this.GetDipFromPoint(e.GetPosition(this));
860 TextPoint tp = this._View.GetTextPointFromPostion(p);
861 if (tp == TextPoint.Null)
863 int index = this._View.LayoutLines.GetIndexFromTextPoint(tp);
865 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
870 newEventArgs.RoutedEvent = e.RoutedEvent;
871 base.OnMouseDown(newEventArgs);
873 if (newEventArgs.Handled)
876 if (e.LeftButton == MouseButtonState.Pressed)
878 FoldingItem foldingData = this._View.HitFoldingData(p.X,tp.row);
879 if (foldingData != null)
881 if (foldingData.Expand)
882 this._View.LayoutLines.FoldingCollection.Collapse(foldingData);
884 this._View.LayoutLines.FoldingCollection.Expand(foldingData);
885 this._Controller.JumpCaret(foldingData.Start,false);
889 this._Controller.JumpCaret(tp.row, tp.col, false);
891 if (this.peer != null)
892 this.peer.OnNotifyCaretChanged();
893 this._View.IsFocused = true;
895 this.Document.SelectGrippers.BottomLeft.Enabled = false;
896 this.Document.SelectGrippers.BottomRight.Enabled = false;
902 /// マウスのボタンが離されたときに呼ばれます
904 /// <param name="e"></param>
905 protected override void OnMouseUp(MouseButtonEventArgs e)
907 this.ReleaseMouseCapture();
914 /// <param name="e">イベントパラメーター</param>
916 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
917 /// e.Handledを真にした場合、選択処理と状況に応じたカーソルの変化が行われなくなります
919 protected override void OnMouseMove(MouseEventArgs e)
921 bool leftPressed = e.LeftButton == MouseButtonState.Pressed;
923 var p = this.GetDipFromPoint(e.GetPosition(this));
925 TextPointSearchRange searchRange;
926 if (this._View.HitTextArea(p.X, p.Y))
928 searchRange = TextPointSearchRange.TextAreaOnly;
930 else if (leftPressed)
932 searchRange = TextPointSearchRange.Full;
936 this.Cursor = Cursors.Arrow;
941 TextPoint tp = this._View.GetTextPointFromPostion(p, searchRange);
943 if (tp == TextPoint.Null)
945 this.Cursor = Cursors.Arrow;
950 int index = this._View.GetIndexFromLayoutLine(tp);
952 FooMouseEventArgs newEventArgs = new FooMouseEventArgs(e.MouseDevice, e.Timestamp, e.StylusDevice, index);
953 newEventArgs.RoutedEvent = e.RoutedEvent;
954 base.OnMouseMove(newEventArgs);
956 if (newEventArgs.Handled)
959 //この状態のときはカーソルがテキストエリア内にある
960 if (searchRange == TextPointSearchRange.TextAreaOnly)
962 if (this._Controller.IsMarker(tp, HilightType.Url))
963 this.Cursor = Cursors.Hand;
965 this.Cursor = Cursors.IBeam;
969 this.Cursor = Cursors.Arrow;
972 //スクロールバーを押した場合はキャレットを移動させる必要がない
973 if (leftPressed && e.OriginalSource.GetType() == typeof(FooTextBox))
975 bool controlPressed = (Keyboard.GetKeyStates(Key.LeftCtrl) & KeyStates.Down) == KeyStates.Down;
976 this._Controller.MoveCaretAndSelect(tp, controlPressed);
977 if (this.peer != null)
978 this.peer.OnNotifyCaretChanged();
983 Gripper hittedGripper;
984 bool touchScrolled = false;
987 protected override void OnTouchDown(TouchEventArgs e)
989 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
990 this.hittedGripper = this._View.HitGripperFromPoint(p);
991 this.CaptureTouch(e.TouchDevice);
995 protected override void OnTouchUp(TouchEventArgs e)
997 this.ReleaseTouchCapture(e.TouchDevice);
998 if(this.hittedGripper != null || this.touchScrolled)
1000 this.hittedGripper = null;
1001 this.touchScrolled = false;
1005 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
1006 TextPoint tp = this._View.GetTextPointFromPostion(p);
1007 if (tp == TextPoint.Null)
1009 int index = this._View.LayoutLines.GetIndexFromTextPoint(tp);
1011 FoldingItem foldingData = this._View.HitFoldingData(p.X, tp.row);
1012 if (foldingData != null)
1014 if (foldingData.Expand)
1015 this._View.LayoutLines.FoldingCollection.Collapse(foldingData);
1017 this._View.LayoutLines.FoldingCollection.Expand(foldingData);
1018 this._Controller.JumpCaret(foldingData.Start, false);
1022 this._Controller.JumpCaret(tp.row, tp.col, false);
1024 if (this.peer != null)
1025 this.peer.OnNotifyCaretChanged();
1026 this._View.IsFocused = true;
1028 this.Document.SelectGrippers.BottomLeft.Enabled = false;
1029 this.Document.SelectGrippers.BottomRight.Enabled = true;
1034 protected override void OnTouchMove(TouchEventArgs e)
1036 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
1037 if (this.Controller.MoveCaretAndGripper(p, this.hittedGripper))
1039 if (this.peer != null)
1040 this.peer.OnNotifyCaretChanged();
1046 protected override void OnManipulationInertiaStarting(ManipulationInertiaStartingEventArgs e)
1051 protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
1053 if (this.hittedGripper != null)
1056 Point translation = new Point(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
1058 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
1059 if (Math.Abs(e.CumulativeManipulation.Translation.X) < Math.Abs(e.CumulativeManipulation.Translation.Y))
1061 int deltay = (int)Math.Abs(Math.Ceiling(translation.Y));
1062 if (translation.Y < 0)
1063 this._Controller.ScrollByPixel(ScrollDirection.Down, deltay, false, false);
1065 this._Controller.ScrollByPixel(ScrollDirection.Up, deltay, false, false);
1066 this.touchScrolled = true;
1071 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
1074 if (translation.X < 0)
1075 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
1077 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
1078 this.touchScrolled = true;
1083 private Point GetDipFromPoint(Point p)
1086 this.Render.GetDpi(out dpi,out dpi);
1087 double scale = dpi / 96.0;
1088 return p.Scale(1 / scale);
1092 protected override void OnMouseWheel(MouseWheelEventArgs e)
1094 if(Keyboard.Modifiers == ModifierKeys.None)
1097 this._Controller.Scroll(ScrollDirection.Up, SystemParameters.WheelScrollLines, false, false);
1099 this._Controller.Scroll(ScrollDirection.Down, SystemParameters.WheelScrollLines, false, false);
1101 else if (Keyboard.Modifiers == ModifierKeys.Control)
1103 double newFontSize = this.Render.FontSize;
1108 if (newFontSize > MaxFontSize)
1110 else if (newFontSize < MinFontSize)
1112 this.Render.FontSize = newFontSize;
1113 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
1116 base.OnMouseWheel(e);
1119 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
1121 if (e.Category == UserPreferenceCategory.Keyboard)
1123 int blinkTime = (int)NativeMethods.GetCaretBlinkTime();
1124 this._View.CaretBlink = blinkTime >= 0;
1125 this._View.CaretBlinkTime = blinkTime * 2;
1127 if (e.Category == UserPreferenceCategory.General)
1129 this._View.CaretWidthOnInsertMode = SystemParameters.CaretWidth;
1133 void Document_Update(object sender, DocumentUpdateEventArgs e)
1135 if (this.textStore.IsLocked())
1137 if(e.type == UpdateType.Replace)
1138 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
1139 if(this.peer != null)
1140 this.peer.OnNotifyTextChanged();
1143 void timer_Tick(object sender, EventArgs e)
1145 if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)
1147 if (this.Resize(this.image.ActualWidth, this.image.ActualHeight))
1149 this.Refresh(this._View.PageBound);
1153 bool updateAll = this._View.LayoutLines.HilightAll() || this._View.LayoutLines.GenerateFolding() || this.Document.IsRequestRedraw;
1156 this.Refresh(this._View.PageBound);
1158 this.Refresh(this._View.GetCurrentCaretRect());
1161 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1163 if (this.horizontalScrollBar == null)
1166 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
1167 toX = this.horizontalScrollBar.Value;
1169 toX = -this.horizontalScrollBar.Value;
1170 this.Controller.ScrollByPixel(ScrollDirection.Left, (int)toX, false, false);
1174 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1176 if (this.verticalScrollBar == null)
1178 this.Controller.Scroll(this.Document.Src.X, (int)this.verticalScrollBar.Value, false, false);
1182 void View_SrcChanged(object sender, EventArgs e)
1184 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1186 EditView view = this._View;
1187 if (view.Src.Row > this.Document.LayoutLines.Count)
1188 this.verticalScrollBar.Maximum = this.Document.LayoutLines.Count - 1;
1189 double absoulteX = Math.Abs(view.Src.X);
1190 if(absoulteX > this.horizontalScrollBar.Maximum)
1191 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1192 if(view.Src.Row != this.verticalScrollBar.Value)
1193 this.verticalScrollBar.Value = view.Src.Row;
1194 if (view.Src.X != this.horizontalScrollBar.Value)
1195 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1198 void Controller_SelectionChanged(object sender, EventArgs e)
1200 this._View.CaretBlink = this._View.CaretBlink;
1201 this.CaretMoved(this, null);
1202 //こうしないと選択できなくなってしまう
1203 this.isNotifyChanged = true;
1204 SetValue(SelectedTextProperty, this._Controller.SelectedText);
1205 SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
1206 SetValue(CaretPostionProperty, this.Document.CaretPostion);
1207 this.isNotifyChanged = false;
1208 if (this.textStore.IsLocked() == false)
1209 this.textStore.NotifySelectionChanged();
1212 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1214 this.Resize(this.image.ActualWidth, this.image.ActualHeight);
1219 bool Resize(double width, double height)
1221 if (width == 0 || height == 0)
1222 throw new ArgumentOutOfRangeException();
1223 if (this.Render.Resize(width, height))
1225 double scale = this.Render.GetScale();
1226 // RenderはレタリングはDIPだが、widthとheightの値はDPI依存なのでDIPに変換する
1227 this._View.PageBound = new Rectangle(0, 0, width / scale, height / scale);
1229 if (this.horizontalScrollBar != null)
1231 this.horizontalScrollBar.LargeChange = this._View.PageBound.Width;
1232 this.horizontalScrollBar.Maximum = this._View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1234 if (this.verticalScrollBar != null)
1236 this.verticalScrollBar.LargeChange = this._View.LineCountOnScreen;
1237 this.verticalScrollBar.Maximum = this._View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1244 private void SetDocument(Document value)
1249 Document old_doc = this._Document;
1251 if (this._Document != null)
1253 old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
1254 old_doc.LoadProgress -= Document_LoadProgress;
1255 old_doc.SelectionChanged -= new EventHandler(Controller_SelectionChanged);
1256 old_doc.AutoCompleteChanged -= _Document_AutoCompleteChanged;
1257 oldLength = old_doc.Length;
1258 if (this._Document.AutoComplete != null)
1260 ((AutoCompleteBox)this._Document.AutoComplete).TargetPopup = null;
1261 this._Document.AutoComplete.GetPostion = null;
1262 this._Document.AutoComplete = null;
1266 this._Document = value;
1267 this._Document.LayoutLines.Render = this.Render;
1268 this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
1269 this._Document.LoadProgress += Document_LoadProgress;
1270 this._Document.AutoCompleteChanged += _Document_AutoCompleteChanged;
1271 if (this._Document.AutoComplete != null && this.Document.AutoComplete.GetPostion == null)
1272 this._Document_AutoCompleteChanged(this.Document, null);
1273 //初期化が終わっていればすべて存在する
1274 if (this.Controller != null && this._View != null && this.textStore != null)
1276 this._Document.SelectionChanged += new EventHandler(Controller_SelectionChanged);
1278 this.Controller.Document = value;
1279 this._View.Document = value;
1280 this.Controller.AdjustCaret();
1281 this.textStore.NotifyTextChanged(oldLength, value.Length);
1283 //依存プロパティとドキュメント内容が食い違っているので再設定する
1284 this.ShowFullSpace = value.ShowFullSpace;
1285 this.ShowHalfSpace = value.ShowHalfSpace;
1286 this.ShowLineBreak = value.ShowLineBreak;
1287 this.ShowTab = value.ShowTab;
1288 this.FlowDirection = value.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
1289 this.IndentMode = value.IndentMode;
1290 this.DrawCaretLine = !value.HideLineMarker;
1291 this.InsertMode = value.InsertMode;
1292 this.DrawRuler = !value.HideRuler;
1293 this.DrawLineNumber = value.DrawLineNumber;
1294 this.MarkURL = value.UrlMark;
1295 this.LineBreakMethod = value.LineBreak;
1296 this.LineBreakCharCount = value.LineBreakCharCount;
1297 this.TabChars = value.TabStops;
1303 private void _Document_AutoCompleteChanged(object sender, EventArgs e)
1305 Document doc = (Document)sender;
1306 ((AutoCompleteBox)this._Document.AutoComplete).TargetPopup = this.popup;
1307 this._Document.AutoComplete.GetPostion = (tp, edoc) =>
1309 var p = this._View.GetPostionFromTextPoint(tp);
1310 int height = (int)this.Render.emSize.Height;
1312 return PointToScreen(this.TranslatePoint(p.Scale(Util.GetScale()), this));
1317 /// プロパティーが変更されたときに呼ばれます
1319 /// <param name="e">イベントパラメーター</param>
1320 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
1322 switch (e.Property.Name)
1325 this.SetDocument(this.Document);
1328 this._View.Hilighter = this.Hilighter;
1330 case "TextAntialiasMode":
1331 this.Render.TextAntialiasMode = this.TextAntialiasMode;
1333 case "FoldingStrategy":
1334 this._View.LayoutLines.FoldingStrategy = this.FoldingStrategy;
1336 case "SelectedText":
1337 if (!this.isNotifyChanged)
1338 this._Controller.SelectedText = this.SelectedText;
1341 this._Controller.IndentMode = this.IndentMode;
1344 if(!this.isNotifyChanged)
1345 this.Select(this.Selection.Index, this.Selection.Length);
1347 case "CaretPostion":
1348 if (!this.isNotifyChanged)
1349 this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
1351 case "LineBreakMethod":
1352 this.Document.LineBreak = this.LineBreakMethod;
1354 case "LineBreakCharCount":
1355 this.Document.LineBreakCharCount = this.LineBreakCharCount;
1358 this._View.InsertMode = this.InsertMode;
1361 this.Document.TabStops = this.TabChars;
1363 case "RectSelectMode":
1364 this._Controller.RectSelection = this.RectSelectMode;
1367 this._View.HideCaret = !this.DrawCaret;
1369 case "DrawCaretLine":
1370 this._View.HideLineMarker = !this.DrawCaretLine;
1372 case "DrawLineNumber":
1373 this.Document.DrawLineNumber = this.DrawLineNumber;
1376 this.Render.FontFamily = this.FontFamily;
1379 this.Render.FontSize = this.FontSize;
1382 this.Render.FontStyle = this.FontStyle;
1385 this.Render.FontWeigth = this.FontWeight;
1388 this.Render.Foreground = D2DRender.ToColor4(this.Foreground);
1390 case "HilightForeground":
1391 this.Render.HilightForeground = D2DRender.ToColor4(this.HilightForeground);
1394 this.Render.Background = D2DRender.ToColor4(this.Background);
1397 this.Render.ControlChar =D2DRender.ToColor4( this.ControlChar);
1400 this.Render.Hilight = D2DRender.ToColor4(this.Hilight);
1403 this.Render.Keyword1 = D2DRender.ToColor4(this.Keyword1);
1406 this.Render.Keyword2 = D2DRender.ToColor4(this.Keyword2);
1409 this.Render.Comment = D2DRender.ToColor4(this.Comment);
1412 this.Render.Literal = D2DRender.ToColor4(this.Literal);
1415 this.Render.Url = D2DRender.ToColor4(this.URL);
1418 this.Render.InsertCaret = D2DRender.ToColor4(this.InsertCaret);
1420 case "OverwriteCaret":
1421 this.Render.OverwriteCaret = D2DRender.ToColor4(this.OverwriteCaret);
1424 this._View.Padding = new Padding((int)this.Padding.Left, (int)this.Padding.Top, (int)this.Padding.Right, (int)this.Padding.Bottom);
1427 this.Render.LineMarker = D2DRender.ToColor4(this.LineMarker);
1430 this.Document.UrlMark = this.MarkURL;
1432 case "ShowFullSpace":
1433 this.Document.ShowFullSpace = this.ShowFullSpace;
1435 case "ShowHalfSpace":
1436 this.Document.ShowHalfSpace = this.ShowHalfSpace;
1439 this.Document.ShowTab = this.ShowTab;
1441 case "ShowLineBreak":
1442 this.Document.ShowLineBreak = this.ShowLineBreak;
1444 case "FlowDirection":
1445 this.Document.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;
1446 this.horizontalScrollBar.FlowDirection = this.FlowDirection;
1449 this.Document.HideRuler = !this.DrawRuler;
1450 this._Controller.JumpCaret(this.Document.CaretPostion.row, this.Document.CaretPostion.col);
1453 this.Render.UpdateArea = D2DRender.ToColor4(this.UpdateArea);
1456 this.Render.LineNumber = D2DRender.ToColor4(this.LineNumber);
1459 base.OnPropertyChanged(e);
1464 internal EditView View
1472 internal Controller Controller
1476 return this._Controller;
1481 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1483 public TextAntialiasMode TextAntialiasMode
1485 get { return (TextAntialiasMode)GetValue(TextAntialiasModeProperty); }
1486 set { SetValue(TextAntialiasModeProperty, value); }
1490 /// TextAntialiasModeの依存プロパティを表す
1492 public static readonly DependencyProperty TextAntialiasModeProperty =
1493 DependencyProperty.Register("TextAntialiasMode", typeof(TextAntialiasMode), typeof(FooTextBox), new PropertyMetadata(TextAntialiasMode.Default));
1498 public IHilighter Hilighter
1500 get { return (IHilighter)GetValue(HilighterProperty); }
1501 set { SetValue(HilighterProperty, value); }
1505 /// Hilighterの依存プロパティを表す
1507 public static readonly DependencyProperty HilighterProperty =
1508 DependencyProperty.Register("Hilighter", typeof(IHilighter), typeof(FooTextBox), new PropertyMetadata(null));
1511 /// フォールティングを作成するインターフェイスを表す
1513 public IFoldingStrategy FoldingStrategy
1515 get { return (IFoldingStrategy)GetValue(FoldingStrategyProperty); }
1516 set { SetValue(FoldingStrategyProperty, value); }
1520 /// FoldingStrategyの依存プロパティ
1522 public static readonly DependencyProperty FoldingStrategyProperty =
1523 DependencyProperty.Register("FoldingStrategy", typeof(IFoldingStrategy), typeof(FooTextBox), new PropertyMetadata(null));
1529 public MarkerPatternSet MarkerPatternSet
1533 return this.Document.MarkerPatternSet;
1540 public Document Document
1542 get { return (Document)GetValue(DocumentProperty); }
1543 set { SetValue(DocumentProperty, value); }
1549 public static readonly DependencyProperty DocumentProperty =
1550 DependencyProperty.Register("Document", typeof(Document), typeof(FooTextBox), new PropertyMetadata(null));
1556 public LineToIndexTable LayoutLineCollection
1558 get { return this._View.LayoutLines; }
1564 public string SelectedText
1566 get { return (string)GetValue(SelectedTextProperty); }
1567 set { SetValue(SelectedTextProperty, value); }
1571 /// SelectedTextの依存プロパティを表す
1573 public static readonly DependencyProperty SelectedTextProperty =
1574 DependencyProperty.Register("SelectedText", typeof(string), typeof(FooTextBox), new PropertyMetadata(null));
1579 public IndentMode IndentMode
1581 get { return (IndentMode)GetValue(IndentModeProperty); }
1582 set { SetValue(IndentModeProperty, value); }
1586 /// IndentModeの依存プロパティを表す
1588 public static readonly DependencyProperty IndentModeProperty =
1589 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab));
1595 /// Lengthが0の場合はキャレット位置を表します。
1596 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1598 public TextRange Selection
1600 get { return (TextRange)GetValue(SelectionProperty); }
1601 set { SetValue(SelectionProperty, value); }
1605 /// Selectionの依存プロパティを表す
1607 public static readonly DependencyProperty SelectionProperty =
1608 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null));
1613 public double MagnificationPower
1615 get { return (double)GetValue(MagnificationPowerPropertyKey.DependencyProperty); }
1621 public static readonly DependencyPropertyKey MagnificationPowerPropertyKey =
1622 DependencyProperty.RegisterReadOnly("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0));
1627 public new FlowDirection FlowDirection
1629 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1630 set { SetValue(FlowDirectionProperty, value); }
1634 /// レタリング方向を表す。これは依存プロパティです
1636 public new static readonly DependencyProperty FlowDirectionProperty =
1637 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight));
1640 /// キャレット位置を表す。これは依存プロパティです
1642 public TextPoint CaretPostion
1644 get { return (TextPoint)GetValue(CaretPostionProperty); }
1645 set { SetValue(CaretPostionProperty, value); }
1649 /// CaretPostionの依存プロパティを表す
1651 public static readonly DependencyProperty CaretPostionProperty =
1652 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(TextPoint.Null));
1655 /// デフォルトの文字色を表す。これは依存プロパティです
1657 public new System.Windows.Media.Color Foreground
1659 get { return (System.Windows.Media.Color)GetValue(ForegroundProperty); }
1660 set { SetValue(ForegroundProperty, value); }
1664 /// Foregroundの依存プロパティを表す
1666 public new static readonly DependencyProperty ForegroundProperty =
1667 DependencyProperty.Register("Foreground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1670 /// 背景色を表す。これは依存プロパティです
1672 public new System.Windows.Media.Color Background
1674 get { return (System.Windows.Media.Color)GetValue(BackgroundProperty); }
1675 set { SetValue(BackgroundProperty, value); }
1679 /// Backgroundの依存プロパティを表す
1681 public new static readonly DependencyProperty BackgroundProperty =
1682 DependencyProperty.Register("Background", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowColor));
1685 /// 選択時の文字色を表す。これは依存プロパティです
1687 public System.Windows.Media.Color HilightForeground
1689 get { return (System.Windows.Media.Color)GetValue(HilightForegroundProperty); }
1690 set { SetValue(HilightForegroundProperty, value); }
1694 /// ControlCharの依存プロパティを表す
1696 public static readonly DependencyProperty HilightForegroundProperty =
1697 DependencyProperty.Register("HilightForeground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.White));
1700 /// コントロールコードの文字色を表す。これは依存プロパティです
1702 public System.Windows.Media.Color ControlChar
1704 get { return (System.Windows.Media.Color)GetValue(ControlCharProperty); }
1705 set { SetValue(ControlCharProperty, value); }
1709 /// ControlCharの依存プロパティを表す
1711 public static readonly DependencyProperty ControlCharProperty =
1712 DependencyProperty.Register("ControlChar", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Gray));
1715 /// 選択時の背景色を表す。これは依存プロパティです
1717 public System.Windows.Media.Color Hilight
1719 get { return (System.Windows.Media.Color)GetValue(HilightProperty); }
1720 set { SetValue(HilightProperty, value); }
1724 /// Hilightの依存プロパティを表す
1726 public static readonly DependencyProperty HilightProperty =
1727 DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));
1730 /// キーワード1の文字色を表す。これは依存プロパティです
1732 public System.Windows.Media.Color Keyword1
1734 get { return (System.Windows.Media.Color)GetValue(Keyword1Property); }
1735 set { SetValue(Keyword1Property, value); }
1739 /// Keyword1の依存プロパティを表す
1741 public static readonly DependencyProperty Keyword1Property =
1742 DependencyProperty.Register("Keyword1", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1745 /// キーワード2の文字色を表す。これは依存プロパティです
1747 public System.Windows.Media.Color Keyword2
1749 get { return (System.Windows.Media.Color)GetValue(Keyword2Property); }
1750 set { SetValue(Keyword2Property, value); }
1754 /// Keyword2の依存プロパティを表す
1756 public static readonly DependencyProperty Keyword2Property =
1757 DependencyProperty.Register("Keyword2", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DarkCyan));
1760 /// コメントの文字色を表す。これは依存プロパティです
1762 public System.Windows.Media.Color Comment
1764 get { return (System.Windows.Media.Color)GetValue(CommentProperty); }
1765 set { SetValue(CommentProperty, value); }
1769 /// Commentの依存プロパティを表す
1771 public static readonly DependencyProperty CommentProperty =
1772 DependencyProperty.Register("Comment", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Green));
1775 /// 文字リテラルの文字色を表す。これは依存プロパティです
1777 public System.Windows.Media.Color Literal
1779 get { return (System.Windows.Media.Color)GetValue(LiteralProperty); }
1780 set { SetValue(LiteralProperty, value); }
1784 /// Literalの依存プロパティを表す
1786 public static readonly DependencyProperty LiteralProperty =
1787 DependencyProperty.Register("Literal", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Brown));
1790 /// URLの文字色を表す。これは依存プロパティです
1792 public System.Windows.Media.Color URL
1794 get { return (System.Windows.Media.Color)GetValue(URLProperty); }
1795 set { SetValue(URLProperty, value); }
1801 public static readonly DependencyProperty URLProperty =
1802 DependencyProperty.Register("URL", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1808 public System.Windows.Media.Color LineMarker
1810 get { return (System.Windows.Media.Color)GetValue(LineMarkerProperty); }
1811 set { SetValue(LineMarkerProperty, value); }
1815 /// LineMarkerの依存プロパティを表す
1817 public static readonly DependencyProperty LineMarkerProperty =
1818 DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));
1821 /// 挿入モード時のキャレットの色を表す
1823 public System.Windows.Media.Color InsertCaret
1825 get { return (System.Windows.Media.Color)GetValue(InsertCaretProperty); }
1826 set { SetValue(InsertCaretProperty, value); }
1830 /// InsertCaretの依存プロパティを表す
1832 public static readonly DependencyProperty InsertCaretProperty =
1833 DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1838 public System.Windows.Media.Color UpdateArea
1840 get { return (System.Windows.Media.Color)GetValue(UpdateAreaProperty); }
1841 set { SetValue(UpdateAreaProperty, value); }
1845 /// UpdateAreaの依存プロパティを表す
1847 public static readonly DependencyProperty UpdateAreaProperty =
1848 DependencyProperty.Register("UpdateArea", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));
1851 /// 上書きモード時のキャレット職を表す
1853 public System.Windows.Media.Color OverwriteCaret
1855 get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }
1856 set { SetValue(OverwriteCaretProperty, value); }
1860 /// OverwriteCaretの依存プロパティを表す
1862 public static readonly DependencyProperty OverwriteCaretProperty =
1863 DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1868 public System.Windows.Media.Color LineNumber
1870 get { return (System.Windows.Media.Color)GetValue(LineNumberProperty); }
1871 set { SetValue(LineNumberProperty, value); }
1875 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1877 public static readonly DependencyProperty LineNumberProperty =
1878 DependencyProperty.Register("LineNumber", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray));
1881 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1883 public bool InsertMode
1885 get { return (bool)GetValue(InsertModeProperty); }
1886 set { SetValue(InsertModeProperty, value); }
1890 /// InsertModeの依存プロパティを表す
1892 public static readonly DependencyProperty InsertModeProperty =
1893 DependencyProperty.Register("InsertMode",
1896 new FrameworkPropertyMetadata(true));
1899 /// タブの文字数を表す。これは依存プロパティです
1903 get { return (int)GetValue(TabCharsProperty); }
1904 set { SetValue(TabCharsProperty, value); }
1908 /// TabCharsの依存プロパティを表す
1910 public static readonly DependencyProperty TabCharsProperty =
1911 DependencyProperty.Register("TabChars",
1914 new FrameworkPropertyMetadata(4));
1917 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1919 public bool RectSelectMode
1921 get { return (bool)GetValue(RectSelectModeProperty); }
1922 set { SetValue(RectSelectModeProperty, value); }
1926 /// RectSelectModeの依存プロパティを表す
1928 public static readonly DependencyProperty RectSelectModeProperty =
1929 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1935 /// 変更した場合、レイアウトの再構築を行う必要があります
1937 public LineBreakMethod LineBreakMethod
1939 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1940 set { SetValue(LineBreakProperty, value); }
1944 /// LineBreakMethodの依存プロパティを表す
1946 public static readonly DependencyProperty LineBreakProperty =
1947 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None));
1951 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1954 /// 変更した場合、レイアウトの再構築を行う必要があります
1956 public int LineBreakCharCount
1958 get { return (int)GetValue(LineBreakCharCountProperty); }
1959 set { SetValue(LineBreakCharCountProperty, value); }
1963 /// LineBreakCharCountの依存プロパティを表す
1965 public static readonly DependencyProperty LineBreakCharCountProperty =
1966 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
1969 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1971 public bool DrawCaret
1973 get { return (bool)GetValue(DrawCaretProperty); }
1974 set { SetValue(DrawCaretProperty, value); }
1978 /// DrawCaretの依存プロパティを表す
1980 public static readonly DependencyProperty DrawCaretProperty =
1981 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
1985 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1987 public bool DrawCaretLine
1989 get { return (bool)GetValue(DrawCaretLineProperty); }
1990 set { SetValue(DrawCaretLineProperty, value); }
1994 /// DrawCaretLineの依存プロパティを表す
1996 public static readonly DependencyProperty DrawCaretLineProperty =
1997 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
2000 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
2002 public bool DrawLineNumber
2004 get { return (bool)GetValue(DrawLineNumberProperty); }
2005 set { SetValue(DrawLineNumberProperty, value); }
2009 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
2011 public bool DrawRuler
2013 get { return (bool)GetValue(DrawRulerProperty); }
2014 set { SetValue(DrawRulerProperty, value); }
2018 /// DrawRulerの依存プロパティを表す
2020 public static readonly DependencyProperty DrawRulerProperty =
2021 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
2025 /// DrawLineNumberの依存プロパティを表す
2027 public static readonly DependencyProperty DrawLineNumberProperty =
2028 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
2031 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
2035 get { return (bool)GetValue(MarkURLProperty); }
2036 set { SetValue(MarkURLProperty, value); }
2040 /// MarkURLの依存プロパティを表す
2042 public static readonly DependencyProperty MarkURLProperty =
2043 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
2046 /// 全角スペースを表示するなら真。そうでないなら偽
2048 public bool ShowFullSpace
2050 get { return (bool)GetValue(ShowFullSpaceProperty); }
2051 set { SetValue(ShowFullSpaceProperty, value); }
2055 /// ShowFullSpaceの依存プロパティを表す
2057 public static readonly DependencyProperty ShowFullSpaceProperty =
2058 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
2061 /// 半角スペースを表示するなら真。そうでないなら偽
2063 public bool ShowHalfSpace
2065 get { return (bool)GetValue(ShowHalfSpaceProperty); }
2066 set { SetValue(ShowHalfSpaceProperty, value); }
2070 /// ShowHalfSpaceの依存プロパティを表す
2072 public static readonly DependencyProperty ShowHalfSpaceProperty =
2073 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
2076 /// タブを表示するなら真。そうでないなら偽
2080 get { return (bool)GetValue(ShowTabProperty); }
2081 set { SetValue(ShowTabProperty, value); }
2085 /// ShowTabの依存プロパティを表す
2087 public static readonly DependencyProperty ShowTabProperty =
2088 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
2091 /// 改行マークを表示するなら真。そうでないなら偽
2093 public bool ShowLineBreak
2095 get { return (bool)GetValue(ShowLineBreakProperty); }
2096 set { SetValue(ShowLineBreakProperty, value); }
2100 /// ShowLineBreakの依存プロパティを表す
2102 public static readonly DependencyProperty ShowLineBreakProperty =
2103 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
2108 /// マウスボタン関連のイベントクラス
2110 public sealed class FooMouseButtonEventArgs : MouseButtonEventArgs
2113 /// イベントが発生したドキュメントのインデックス
2124 /// <param name="mouse">マウスデバイス</param>
2125 /// <param name="timestamp">タイムスタンプ</param>
2126 /// <param name="button">ボタン</param>
2127 /// <param name="stylusDevice">スタイラスデバイス</param>
2128 /// <param name="index">インデックス</param>
2129 public FooMouseButtonEventArgs(MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice, int index)
2130 : base(mouse, timestamp, button, stylusDevice)
2138 public sealed class FooMouseEventArgs : MouseEventArgs
2141 /// イベントが発生したドキュメントのインデックス
2152 /// <param name="mouse">マウスデバイス</param>
2153 /// <param name="timestamp">タイムスタンプ</param>
2154 /// <param name="stylusDevice">スタイラスデバイス</param>
2155 /// <param name="index">インデックス</param>
2156 public FooMouseEventArgs(MouseDevice mouse,
2158 StylusDevice stylusDevice,
2160 : base(mouse, timestamp, stylusDevice)