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.Document.LayoutLines.Count - 1;
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.CalculateWhloeViewPort();
401 this.View.CalculateLineCountOnScreen();
402 this.IsEnabled = true;
403 this.Refresh(this.View.PageBound);
408 /// ドキュメントの内容をファイルに保存する
410 /// <param name="filepath">ファイルパス</param>
411 /// <param name="newLine">改行コード</param>
412 /// <param name="enc">エンコード</param>
413 /// <param name="token">キャンセル用トークン</param>
414 /// <returns>Taskオブジェクト</returns>
415 public async Task SaveFile(string filepath, Encoding enc,string newLine, System.Threading.CancellationTokenSource token)
417 var fs = new System.IO.StreamWriter(filepath, false , enc);
418 fs.NewLine = newLine;
419 await this.Document.SaveAsync(fs, token);
426 public void Dispose()
431 GC.SuppressFinalize(this);
432 this.disposed = true;
438 /// <param name="disposing">真ならマネージドリソースも開放し、そうでないならアンマネージドリソースのみを開放する</param>
439 void Dispose(bool disposing)
443 this.textStore.Dispose();
446 this.Render.Dispose();
448 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
451 void Refresh(Rectangle updateRect)
453 if (this.disposed || this.Visibility == Visibility.Collapsed)
456 this.Render.DrawContent(this.View, this.IsEnabled, updateRect);
457 this.Document.IsRequestRedraw = false;
461 void CanExecute(object sender, CanExecuteRoutedEventArgs e)
463 e.CanExecute = this.IsEnabled;
466 void ToggleCodePointCommand(object sender, RoutedEventArgs e)
468 if (!this._Controller.ConvertToChar())
469 this._Controller.ConvertToCodePoint();
473 void CopyCommand(object sender, RoutedEventArgs e)
478 void CutCommand(object sender, RoutedEventArgs e)
484 void PasteCommand(object sender, RoutedEventArgs e)
490 void DeleteCommand(object sender, RoutedEventArgs e)
492 int oldLength = this.Document.Length;
493 this._Controller.DoDeleteAction();
497 void SelectAllCommand(object sender, RoutedEventArgs e)
499 this.Select(0, this.Document.Length);
503 void UndoCommand(object sender, RoutedEventArgs e)
505 int oldLength = this.Document.Length;
506 this.Document.UndoManager.undo();
510 void RedoCommand(object sender, RoutedEventArgs e)
512 int oldLength = this.Document.Length;
513 this.Document.UndoManager.redo();
517 void ToggleInsertCommand(object sender, RoutedEventArgs e)
520 this.InsertMode = false;
522 this.InsertMode = true;
526 void ToggleRectSelectCommand(object sender, RoutedEventArgs e)
528 if (this.RectSelectMode)
529 this.RectSelectMode = false;
531 this.RectSelectMode = true;
534 void ToggleFlowDirectionCommand(object sender, RoutedEventArgs e)
536 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
537 this.FlowDirection = System.Windows.FlowDirection.RightToLeft;
539 this.FlowDirection = System.Windows.FlowDirection.LeftToRight;
544 internal TextStore TextStore
546 get { return this.textStore; }
549 bool textStore_IsReadOnly()
554 bool textStore_IsLoading()
559 void textStore_CompositionEnded()
561 TextStoreHelper.EndCompostion(this.Document);
565 void textStore_CompositionUpdated(int start, int end)
567 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
570 bool textStore_CompositionStarted()
572 bool result = TextStoreHelper.StartCompstion(this.Document);
574 System.Media.SystemSounds.Beep.Play();
578 string _textStore_GetString(int start, int length)
580 return this.Document.ToString(start, length);
583 IntPtr _textStore_GetHWnd()
585 var hwndSource = HwndSource.FromVisual(this) as HwndSource;
586 if (hwndSource != null)
587 return hwndSource.Handle;
592 void _textStore_GetStringExtent(
596 out POINT o_bottomRight
599 Point startPos, endPos;
600 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
602 double scale = this.Render.GetScale();
604 startPos = PointToScreen(this.TranslatePoint(startPos.Scale(scale), this));
605 endPos = PointToScreen(this.TranslatePoint(endPos.Scale(scale), this));
607 o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);
608 o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);
611 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
613 var pointTopLeft = new Point(0, 0);
614 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
616 pointTopLeft = PointToScreen(pointTopLeft);
617 pointBottomRight = PointToScreen(pointBottomRight);
619 o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
620 o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
623 void _textStore_GetSelectionIndex(int start_index, int max_count, out DotNetTextStore.TextSelection[] sels)
626 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out selRange);
628 sels = new DotNetTextStore.TextSelection[1];
629 sels[0] = new DotNetTextStore.TextSelection();
630 sels[0].start = selRange.Index;
631 sels[0].end = selRange.Index + selRange.Length;
634 void _textStore_SetSelectionIndex(DotNetTextStore.TextSelection[] sels)
636 TextStoreHelper.SetSelectionIndex(this._Controller, this.View, sels[0].start, sels[0].end);
640 void _textStore_InsertAtSelection(string i_value, ref int o_startIndex, ref int o_endIndex)
642 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
647 /// キーボードフォーカスが取得されたときに呼ばれます
649 /// <param name="e">イベントデーター</param>
650 protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
652 base.OnGotKeyboardFocus(e);
653 this.textStore.SetFocus();
654 this.View.IsFocused = true;
655 this.timer.Interval = new TimeSpan(0,0,0,0,Interval);
660 /// キーボードフォーカスが失われたときに呼ばれます
662 /// <param name="e">イベントデーター</param>
663 protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
665 base.OnLostKeyboardFocus(e);
666 this.View.IsFocused = false;
667 this.timer.Interval = new TimeSpan(0, 0, 0, 0, IntervalWhenLostFocuse);
673 /// キャレットが移動したときに通知されるイベント
675 public event EventHandler CaretMoved;
678 protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
680 this.peer = new FooTextBoxAutomationPeer(this);
686 protected override void OnTextInput(TextCompositionEventArgs e)
690 this._Controller.DoEnterAction();
691 this.AutoIndentHooker(this, null);
693 else if (e.Text == "\b")
695 this._Controller.DoBackSpaceAction();
699 if(this.IsInputString(e.Text))
700 this._Controller.DoInputString(e.Text);
707 bool IsInputString(string s)
709 foreach (char charCode in s)
711 if ((0x20 <= charCode && charCode <= 0x7e)
719 protected override void OnKeyDown(KeyEventArgs e)
721 if (this.textStore.IsLocked())
724 ModifierKeys modiferKeys = e.KeyboardDevice.Modifiers;
726 var autocomplete = this.Document.AutoComplete as AutoCompleteBox;
727 if (autocomplete != null &&
728 autocomplete.ProcessKeyDown(this,e, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift)))
734 bool movedCaret = false;
738 this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
744 this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
750 this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
756 this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
762 this._Controller.Scroll(ScrollDirection.Up,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
767 this._Controller.Scroll(ScrollDirection.Down,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
772 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
773 this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
775 this._Controller.JumpToLineHead(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
780 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
781 this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
783 this._Controller.JumpToLineEnd(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
788 int oldLength = this.Document.Length;
789 if (this.Selection.Length == 0)
790 this._Controller.DoInputChar('\t');
791 else if(this.IsPressedModifierKey(modiferKeys,ModifierKeys.Shift))
792 this._Controller.DownIndent();
794 this._Controller.UpIndent();
799 if (movedCaret && this.peer != null)
800 this.peer.OnNotifyCaretChanged();
804 bool IsPressedModifierKey(ModifierKeys keys, ModifierKeys pressed)
808 if ((keys & pressed) == pressed)
814 /// ダブルクリックされたときに呼ばれます
816 /// <param name="e">イベントパラメーター</param>
818 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
819 /// e.Handledを真にした場合、単語単位の選択が行われなくなります
821 protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
823 var p = this.GetDipFromPoint(e.GetPosition(this));
824 TextPoint tp = this.View.GetTextPointFromPostion(p);
825 if (tp == TextPoint.Null)
827 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
829 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
834 newEventArgs.RoutedEvent = e.RoutedEvent;
835 base.OnMouseDoubleClick(newEventArgs);
837 if (newEventArgs.Handled)
840 if (e.LeftButton == MouseButtonState.Pressed)
842 if (p.X < this.Render.TextArea.X)
843 this.Document.SelectLine((int)index);
845 this.Document.SelectWord((int)index);
847 this.textStore.NotifySelectionChanged();
848 if(this.peer != null)
849 this.peer.OnNotifyCaretChanged();
855 /// マウスボタンが押されたときに呼ばれます
857 /// <param name="e">イベントパラメーター</param>
859 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
860 /// e.Handledを真にした場合、キャレットの移動処理が行われなくなります
862 protected override void OnMouseDown(MouseButtonEventArgs e)
866 var p = this.GetDipFromPoint(e.GetPosition(this));
867 TextPoint tp = this.View.GetTextPointFromPostion(p);
868 if (tp == TextPoint.Null)
870 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
872 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
877 newEventArgs.RoutedEvent = e.RoutedEvent;
878 base.OnMouseDown(newEventArgs);
880 if (newEventArgs.Handled)
883 if (e.LeftButton == MouseButtonState.Pressed)
885 FoldingItem foldingData = this.View.HitFoldingData(p.X,tp.row);
886 if (foldingData != null)
888 if (foldingData.Expand)
889 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
891 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
892 this._Controller.JumpCaret(foldingData.Start,false);
896 this._Controller.JumpCaret(tp.row, tp.col, false);
898 if (this.peer != null)
899 this.peer.OnNotifyCaretChanged();
900 this.View.IsFocused = true;
902 this.Document.SelectGrippers.BottomLeft.Enabled = false;
903 this.Document.SelectGrippers.BottomRight.Enabled = false;
909 /// マウスのボタンが離されたときに呼ばれます
911 /// <param name="e"></param>
912 protected override void OnMouseUp(MouseButtonEventArgs e)
914 this.ReleaseMouseCapture();
921 /// <param name="e">イベントパラメーター</param>
923 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
924 /// e.Handledを真にした場合、選択処理と状況に応じたカーソルの変化が行われなくなります
926 protected override void OnMouseMove(MouseEventArgs e)
928 bool leftPressed = e.LeftButton == MouseButtonState.Pressed;
930 var p = this.GetDipFromPoint(e.GetPosition(this));
932 TextPointSearchRange searchRange;
933 if (this.View.HitTextArea(p.X, p.Y))
934 searchRange = TextPointSearchRange.TextAreaOnly;
935 else if (leftPressed)
936 searchRange = TextPointSearchRange.Full;
938 searchRange = TextPointSearchRange.TextAreaOnly;
940 TextPoint tp = this.View.GetTextPointFromPostion(p, searchRange);
942 if (tp == TextPoint.Null)
948 int index = this.View.GetIndexFromLayoutLine(tp);
950 FooMouseEventArgs newEventArgs = new FooMouseEventArgs(e.MouseDevice, e.Timestamp, e.StylusDevice, index);
951 newEventArgs.RoutedEvent = e.RoutedEvent;
952 base.OnMouseMove(newEventArgs);
954 if (newEventArgs.Handled)
957 //この状態のときはカーソルがテキストエリア内にある
958 if (searchRange == TextPointSearchRange.TextAreaOnly)
960 if (this._Controller.IsMarker(tp, HilightType.Url))
961 this.Cursor = Cursors.Hand;
963 this.Cursor = Cursors.IBeam;
967 this.Cursor = Cursors.Arrow;
972 bool controlPressed = (Keyboard.GetKeyStates(Key.LeftCtrl) & KeyStates.Down) == KeyStates.Down;
973 this._Controller.MoveCaretAndSelect(tp, controlPressed);
974 if (this.peer != null)
975 this.peer.OnNotifyCaretChanged();
980 Gripper hittedGripper;
981 bool touchScrolled = false;
984 protected override void OnTouchDown(TouchEventArgs e)
986 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
987 this.hittedGripper = this.View.HitGripperFromPoint(p);
988 this.CaptureTouch(e.TouchDevice);
992 protected override void OnTouchUp(TouchEventArgs e)
994 this.ReleaseTouchCapture(e.TouchDevice);
995 if(this.hittedGripper != null || this.touchScrolled)
997 this.hittedGripper = null;
998 this.touchScrolled = false;
1002 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
1003 TextPoint tp = this.View.GetTextPointFromPostion(p);
1004 if (tp == TextPoint.Null)
1006 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
1008 FoldingItem foldingData = this.View.HitFoldingData(p.X, tp.row);
1009 if (foldingData != null)
1011 if (foldingData.Expand)
1012 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
1014 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
1015 this._Controller.JumpCaret(foldingData.Start, false);
1019 this._Controller.JumpCaret(tp.row, tp.col, false);
1021 if (this.peer != null)
1022 this.peer.OnNotifyCaretChanged();
1023 this.View.IsFocused = true;
1025 this.Document.SelectGrippers.BottomLeft.Enabled = false;
1026 this.Document.SelectGrippers.BottomRight.Enabled = true;
1031 protected override void OnTouchMove(TouchEventArgs e)
1033 var p = this.GetDipFromPoint(e.GetTouchPoint(this).Position);
1034 if (this.Controller.MoveCaretAndGripper(p, this.hittedGripper))
1036 if (this.peer != null)
1037 this.peer.OnNotifyCaretChanged();
1043 protected override void OnManipulationInertiaStarting(ManipulationInertiaStartingEventArgs e)
1048 protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
1050 if (this.hittedGripper != null)
1053 Point translation = new Point(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
1055 //Xの絶対値が大きければ横方向のスクロールで、そうでなければ縦方向らしい
1056 if (Math.Abs(e.CumulativeManipulation.Translation.X) < Math.Abs(e.CumulativeManipulation.Translation.Y))
1058 int deltay = (int)Math.Abs(Math.Ceiling(translation.Y));
1059 if (translation.Y < 0)
1060 this._Controller.ScrollByPixel(ScrollDirection.Down, deltay, false, false);
1062 this._Controller.ScrollByPixel(ScrollDirection.Up, deltay, false, false);
1063 this.touchScrolled = true;
1068 int deltax = (int)Math.Abs(Math.Ceiling(translation.X));
1071 if (translation.X < 0)
1072 this._Controller.Scroll(ScrollDirection.Left, deltax, false, false);
1074 this._Controller.Scroll(ScrollDirection.Right, deltax, false, false);
1075 this.touchScrolled = true;
1080 private Point GetDipFromPoint(Point p)
1083 this.Render.GetDpi(out dpi,out dpi);
1084 double scale = dpi / 96.0;
1085 return p.Scale(1 / scale);
1089 protected override void OnMouseWheel(MouseWheelEventArgs e)
1091 if(Keyboard.Modifiers == ModifierKeys.None)
1094 this._Controller.Scroll(ScrollDirection.Up, SystemParameters.WheelScrollLines, false, false);
1096 this._Controller.Scroll(ScrollDirection.Down, SystemParameters.WheelScrollLines, false, false);
1098 else if (Keyboard.Modifiers == ModifierKeys.Control)
1100 double newFontSize = this.Render.FontSize;
1105 if (newFontSize > MaxFontSize)
1107 else if (newFontSize < MinFontSize)
1109 this.Render.FontSize = newFontSize;
1110 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
1113 base.OnMouseWheel(e);
1116 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
1118 if (e.Category == UserPreferenceCategory.Keyboard)
1120 int blinkTime = (int)NativeMethods.GetCaretBlinkTime();
1121 this.View.CaretBlink = blinkTime >= 0;
1122 this.View.CaretBlinkTime = blinkTime * 2;
1124 if (e.Category == UserPreferenceCategory.General)
1126 this.View.CaretWidthOnInsertMode = SystemParameters.CaretWidth;
1130 void Document_Update(object sender, DocumentUpdateEventArgs e)
1132 if (this.textStore.IsLocked())
1134 if(e.type == UpdateType.Replace)
1135 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
1136 if(this.peer != null)
1137 this.peer.OnNotifyTextChanged();
1140 void timer_Tick(object sender, EventArgs e)
1142 if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)
1144 if (this.Resize(this.image.ActualWidth, this.image.ActualHeight))
1146 this.Refresh(this.View.PageBound);
1150 bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding() || this.Document.IsRequestRedraw;
1153 this.Refresh(this.View.PageBound);
1155 this.Refresh(this.View.GetCurrentCaretRect());
1158 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1160 if (this.horizontalScrollBar == null)
1163 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
1164 toX = this.horizontalScrollBar.Value;
1166 toX = -this.horizontalScrollBar.Value;
1167 this.Controller.ScrollByPixel(ScrollDirection.Left, (int)toX, false, false);
1171 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1173 if (this.verticalScrollBar == null)
1175 this.Controller.Scroll(this.Document.Src.X, (int)this.verticalScrollBar.Value, false, false);
1179 void View_SrcChanged(object sender, EventArgs e)
1181 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1183 EditView view = this.View;
1184 if (view.Src.Row > this.Document.LayoutLines.Count)
1185 this.verticalScrollBar.Maximum = this.Document.LayoutLines.Count - 1;
1186 double absoulteX = Math.Abs(view.Src.X);
1187 if(absoulteX > this.horizontalScrollBar.Maximum)
1188 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1189 if(view.Src.Row != this.verticalScrollBar.Value)
1190 this.verticalScrollBar.Value = view.Src.Row;
1191 if (view.Src.X != this.horizontalScrollBar.Value)
1192 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1195 void Controller_SelectionChanged(object sender, EventArgs e)
1197 this.View.CaretBlink = this.View.CaretBlink;
1198 this.CaretMoved(this, null);
1199 //こうしないと選択できなくなってしまう
1200 this.isNotifyChanged = true;
1201 SetValue(SelectedTextProperty, this._Controller.SelectedText);
1202 SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
1203 SetValue(CaretPostionProperty, this.Document.CaretPostion);
1204 this.isNotifyChanged = false;
1205 if (this.textStore.IsLocked() == false)
1206 this.textStore.NotifySelectionChanged();
1209 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1211 this.Resize(this.image.ActualWidth, this.image.ActualHeight);
1216 bool Resize(double width, double height)
1218 if (width == 0 || height == 0)
1219 throw new ArgumentOutOfRangeException();
1220 if (this.Render.Resize(width, height))
1222 double scale = this.Render.GetScale();
1223 // RenderはレタリングはDIPだが、widthとheightの値はDPI依存なのでDIPに変換する
1224 this.View.PageBound = new Rectangle(0, 0, width / scale, height / scale);
1226 if (this.horizontalScrollBar != null)
1228 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
1229 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1231 if (this.verticalScrollBar != null)
1233 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
1234 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1241 private void SetDocument(Document value)
1246 Document old_doc = this._Document;
1248 if (this._Document != null)
1250 old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
1251 old_doc.LoadProgress -= Document_LoadProgress;
1252 old_doc.SelectionChanged -= new EventHandler(Controller_SelectionChanged);
1253 old_doc.AutoCompleteChanged -= _Document_AutoCompleteChanged;
1254 oldLength = old_doc.Length;
1255 if (this._Document.AutoComplete != null)
1257 ((AutoCompleteBox)this._Document.AutoComplete).TargetPopup = null;
1258 this._Document.AutoComplete.GetPostion = null;
1259 this._Document.AutoComplete = null;
1263 this._Document = value;
1264 this._Document.LayoutLines.Render = this.Render;
1265 this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
1266 this._Document.LoadProgress += Document_LoadProgress;
1267 this._Document.AutoCompleteChanged += _Document_AutoCompleteChanged;
1268 if (this._Document.AutoComplete != null && this.Document.AutoComplete.GetPostion == null)
1269 this._Document_AutoCompleteChanged(this.Document, null);
1270 //初期化が終わっていればすべて存在する
1271 if (this.Controller != null && this.View != null && this.textStore != null)
1273 this._Document.SelectionChanged += new EventHandler(Controller_SelectionChanged);
1275 this.Controller.Document = value;
1276 this.View.Document = value;
1277 this.Controller.AdjustCaret();
1278 this.textStore.NotifyTextChanged(oldLength, value.Length);
1280 //依存プロパティとドキュメント内容が食い違っているので再設定する
1281 this.ShowFullSpace = value.ShowFullSpace;
1282 this.ShowHalfSpace = value.ShowHalfSpace;
1283 this.ShowLineBreak = value.ShowLineBreak;
1284 this.ShowTab = value.ShowTab;
1285 this.FlowDirection = value.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
1286 this.IndentMode = value.IndentMode;
1287 this.DrawCaretLine = !value.HideLineMarker;
1288 this.InsertMode = value.InsertMode;
1289 this.DrawRuler = !value.HideRuler;
1290 this.DrawLineNumber = value.DrawLineNumber;
1291 this.MarkURL = value.UrlMark;
1292 this.LineBreakMethod = value.LineBreak;
1293 this.LineBreakCharCount = value.LineBreakCharCount;
1294 this.TabChars = value.TabStops;
1300 private void _Document_AutoCompleteChanged(object sender, EventArgs e)
1302 Document doc = (Document)sender;
1303 ((AutoCompleteBox)this._Document.AutoComplete).TargetPopup = this.popup;
1304 this._Document.AutoComplete.GetPostion = (tp, edoc) =>
1306 var p = this.View.GetPostionFromTextPoint(tp);
1307 int height = (int)this.Render.emSize.Height;
1309 return PointToScreen(this.TranslatePoint(p.Scale(Util.GetScale()), this));
1314 /// プロパティーが変更されたときに呼ばれます
1316 /// <param name="e">イベントパラメーター</param>
1317 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
1319 switch (e.Property.Name)
1322 this.SetDocument(this.Document);
1325 this.View.Hilighter = this.Hilighter;
1327 case "TextAntialiasMode":
1328 this.Render.TextAntialiasMode = this.TextAntialiasMode;
1330 case "FoldingStrategy":
1331 this.View.LayoutLines.FoldingStrategy = this.FoldingStrategy;
1333 case "SelectedText":
1334 if (!this.isNotifyChanged)
1335 this._Controller.SelectedText = this.SelectedText;
1338 this._Controller.IndentMode = this.IndentMode;
1341 if(!this.isNotifyChanged)
1342 this.Select(this.Selection.Index, this.Selection.Length);
1344 case "CaretPostion":
1345 if (!this.isNotifyChanged)
1346 this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
1348 case "LineBreakMethod":
1349 this.Document.LineBreak = this.LineBreakMethod;
1351 case "LineBreakCharCount":
1352 this.Document.LineBreakCharCount = this.LineBreakCharCount;
1355 this.View.InsertMode = this.InsertMode;
1358 this.Document.TabStops = this.TabChars;
1360 case "RectSelectMode":
1361 this._Controller.RectSelection = this.RectSelectMode;
1364 this.View.HideCaret = !this.DrawCaret;
1366 case "DrawCaretLine":
1367 this.View.HideLineMarker = !this.DrawCaretLine;
1369 case "DrawLineNumber":
1370 this.Document.DrawLineNumber = this.DrawLineNumber;
1373 this.Render.FontFamily = this.FontFamily;
1376 this.Render.FontSize = this.FontSize;
1379 this.Render.FontStyle = this.FontStyle;
1382 this.Render.FontWeigth = this.FontWeight;
1385 this.Render.Foreground = D2DRender.ToColor4(this.Foreground);
1387 case "HilightForeground":
1388 this.Render.HilightForeground = D2DRender.ToColor4(this.HilightForeground);
1391 this.Render.Background = D2DRender.ToColor4(this.Background);
1394 this.Render.ControlChar =D2DRender.ToColor4( this.ControlChar);
1397 this.Render.Hilight = D2DRender.ToColor4(this.Hilight);
1400 this.Render.Keyword1 = D2DRender.ToColor4(this.Keyword1);
1403 this.Render.Keyword2 = D2DRender.ToColor4(this.Keyword2);
1406 this.Render.Comment = D2DRender.ToColor4(this.Comment);
1409 this.Render.Literal = D2DRender.ToColor4(this.Literal);
1412 this.Render.Url = D2DRender.ToColor4(this.URL);
1415 this.Render.InsertCaret = D2DRender.ToColor4(this.InsertCaret);
1417 case "OverwriteCaret":
1418 this.Render.OverwriteCaret = D2DRender.ToColor4(this.OverwriteCaret);
1421 this.View.Padding = new Padding((int)this.Padding.Left, (int)this.Padding.Top, (int)this.Padding.Right, (int)this.Padding.Bottom);
1424 this.Render.LineMarker = D2DRender.ToColor4(this.LineMarker);
1427 this.Document.UrlMark = this.MarkURL;
1429 case "ShowFullSpace":
1430 this.Document.ShowFullSpace = this.ShowFullSpace;
1432 case "ShowHalfSpace":
1433 this.Document.ShowHalfSpace = this.ShowHalfSpace;
1436 this.Document.ShowTab = this.ShowTab;
1438 case "ShowLineBreak":
1439 this.Document.ShowLineBreak = this.ShowLineBreak;
1441 case "FlowDirection":
1442 this.Document.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;
1443 this.horizontalScrollBar.FlowDirection = this.FlowDirection;
1446 this.Document.HideRuler = !this.DrawRuler;
1447 this._Controller.JumpCaret(this.Document.CaretPostion.row, this.Document.CaretPostion.col);
1450 this.Render.UpdateArea = D2DRender.ToColor4(this.UpdateArea);
1453 this.Render.LineNumber = D2DRender.ToColor4(this.LineNumber);
1456 base.OnPropertyChanged(e);
1461 internal Controller Controller
1465 return this._Controller;
1470 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1472 public TextAntialiasMode TextAntialiasMode
1474 get { return (TextAntialiasMode)GetValue(TextAntialiasModeProperty); }
1475 set { SetValue(TextAntialiasModeProperty, value); }
1479 /// TextAntialiasModeの依存プロパティを表す
1481 public static readonly DependencyProperty TextAntialiasModeProperty =
1482 DependencyProperty.Register("TextAntialiasMode", typeof(TextAntialiasMode), typeof(FooTextBox), new PropertyMetadata(TextAntialiasMode.Default));
1487 public IHilighter Hilighter
1489 get { return (IHilighter)GetValue(HilighterProperty); }
1490 set { SetValue(HilighterProperty, value); }
1494 /// Hilighterの依存プロパティを表す
1496 public static readonly DependencyProperty HilighterProperty =
1497 DependencyProperty.Register("Hilighter", typeof(IHilighter), typeof(FooTextBox), new PropertyMetadata(null));
1500 /// フォールティングを作成するインターフェイスを表す
1502 public IFoldingStrategy FoldingStrategy
1504 get { return (IFoldingStrategy)GetValue(FoldingStrategyProperty); }
1505 set { SetValue(FoldingStrategyProperty, value); }
1509 /// FoldingStrategyの依存プロパティ
1511 public static readonly DependencyProperty FoldingStrategyProperty =
1512 DependencyProperty.Register("FoldingStrategy", typeof(IFoldingStrategy), typeof(FooTextBox), new PropertyMetadata(null));
1518 public MarkerPatternSet MarkerPatternSet
1522 return this.Document.MarkerPatternSet;
1529 public Document Document
1531 get { return (Document)GetValue(DocumentProperty); }
1532 set { SetValue(DocumentProperty, value); }
1538 public static readonly DependencyProperty DocumentProperty =
1539 DependencyProperty.Register("Document", typeof(Document), typeof(FooTextBox), new PropertyMetadata(null));
1545 public LineToIndexTable LayoutLineCollection
1547 get { return this.View.LayoutLines; }
1553 public string SelectedText
1555 get { return (string)GetValue(SelectedTextProperty); }
1556 set { SetValue(SelectedTextProperty, value); }
1560 /// SelectedTextの依存プロパティを表す
1562 public static readonly DependencyProperty SelectedTextProperty =
1563 DependencyProperty.Register("SelectedText", typeof(string), typeof(FooTextBox), new PropertyMetadata(null));
1568 public IndentMode IndentMode
1570 get { return (IndentMode)GetValue(IndentModeProperty); }
1571 set { SetValue(IndentModeProperty, value); }
1575 /// IndentModeの依存プロパティを表す
1577 public static readonly DependencyProperty IndentModeProperty =
1578 DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab));
1584 /// Lengthが0の場合はキャレット位置を表します。
1585 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1587 public TextRange Selection
1589 get { return (TextRange)GetValue(SelectionProperty); }
1590 set { SetValue(SelectionProperty, value); }
1594 /// Selectionの依存プロパティを表す
1596 public static readonly DependencyProperty SelectionProperty =
1597 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null));
1602 public double MagnificationPower
1604 get { return (double)GetValue(MagnificationPowerPropertyKey.DependencyProperty); }
1610 public static readonly DependencyPropertyKey MagnificationPowerPropertyKey =
1611 DependencyProperty.RegisterReadOnly("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0));
1616 public new FlowDirection FlowDirection
1618 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1619 set { SetValue(FlowDirectionProperty, value); }
1623 /// レタリング方向を表す。これは依存プロパティです
1625 public new static readonly DependencyProperty FlowDirectionProperty =
1626 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight));
1629 /// キャレット位置を表す。これは依存プロパティです
1631 public TextPoint CaretPostion
1633 get { return (TextPoint)GetValue(CaretPostionProperty); }
1634 set { SetValue(CaretPostionProperty, value); }
1638 /// CaretPostionの依存プロパティを表す
1640 public static readonly DependencyProperty CaretPostionProperty =
1641 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(TextPoint.Null));
1644 /// デフォルトの文字色を表す。これは依存プロパティです
1646 public new System.Windows.Media.Color Foreground
1648 get { return (System.Windows.Media.Color)GetValue(ForegroundProperty); }
1649 set { SetValue(ForegroundProperty, value); }
1653 /// Foregroundの依存プロパティを表す
1655 public new static readonly DependencyProperty ForegroundProperty =
1656 DependencyProperty.Register("Foreground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1659 /// 背景色を表す。これは依存プロパティです
1661 public new System.Windows.Media.Color Background
1663 get { return (System.Windows.Media.Color)GetValue(BackgroundProperty); }
1664 set { SetValue(BackgroundProperty, value); }
1668 /// Backgroundの依存プロパティを表す
1670 public new static readonly DependencyProperty BackgroundProperty =
1671 DependencyProperty.Register("Background", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowColor));
1674 /// 選択時の文字色を表す。これは依存プロパティです
1676 public System.Windows.Media.Color HilightForeground
1678 get { return (System.Windows.Media.Color)GetValue(HilightForegroundProperty); }
1679 set { SetValue(HilightForegroundProperty, value); }
1683 /// ControlCharの依存プロパティを表す
1685 public static readonly DependencyProperty HilightForegroundProperty =
1686 DependencyProperty.Register("HilightForeground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.White));
1689 /// コントロールコードの文字色を表す。これは依存プロパティです
1691 public System.Windows.Media.Color ControlChar
1693 get { return (System.Windows.Media.Color)GetValue(ControlCharProperty); }
1694 set { SetValue(ControlCharProperty, value); }
1698 /// ControlCharの依存プロパティを表す
1700 public static readonly DependencyProperty ControlCharProperty =
1701 DependencyProperty.Register("ControlChar", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Gray));
1704 /// 選択時の背景色を表す。これは依存プロパティです
1706 public System.Windows.Media.Color Hilight
1708 get { return (System.Windows.Media.Color)GetValue(HilightProperty); }
1709 set { SetValue(HilightProperty, value); }
1713 /// Hilightの依存プロパティを表す
1715 public static readonly DependencyProperty HilightProperty =
1716 DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));
1719 /// キーワード1の文字色を表す。これは依存プロパティです
1721 public System.Windows.Media.Color Keyword1
1723 get { return (System.Windows.Media.Color)GetValue(Keyword1Property); }
1724 set { SetValue(Keyword1Property, value); }
1728 /// Keyword1の依存プロパティを表す
1730 public static readonly DependencyProperty Keyword1Property =
1731 DependencyProperty.Register("Keyword1", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1734 /// キーワード2の文字色を表す。これは依存プロパティです
1736 public System.Windows.Media.Color Keyword2
1738 get { return (System.Windows.Media.Color)GetValue(Keyword2Property); }
1739 set { SetValue(Keyword2Property, value); }
1743 /// Keyword2の依存プロパティを表す
1745 public static readonly DependencyProperty Keyword2Property =
1746 DependencyProperty.Register("Keyword2", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DarkCyan));
1749 /// コメントの文字色を表す。これは依存プロパティです
1751 public System.Windows.Media.Color Comment
1753 get { return (System.Windows.Media.Color)GetValue(CommentProperty); }
1754 set { SetValue(CommentProperty, value); }
1758 /// Commentの依存プロパティを表す
1760 public static readonly DependencyProperty CommentProperty =
1761 DependencyProperty.Register("Comment", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Green));
1764 /// 文字リテラルの文字色を表す。これは依存プロパティです
1766 public System.Windows.Media.Color Literal
1768 get { return (System.Windows.Media.Color)GetValue(LiteralProperty); }
1769 set { SetValue(LiteralProperty, value); }
1773 /// Literalの依存プロパティを表す
1775 public static readonly DependencyProperty LiteralProperty =
1776 DependencyProperty.Register("Literal", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Brown));
1779 /// URLの文字色を表す。これは依存プロパティです
1781 public System.Windows.Media.Color URL
1783 get { return (System.Windows.Media.Color)GetValue(URLProperty); }
1784 set { SetValue(URLProperty, value); }
1790 public static readonly DependencyProperty URLProperty =
1791 DependencyProperty.Register("URL", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1797 public System.Windows.Media.Color LineMarker
1799 get { return (System.Windows.Media.Color)GetValue(LineMarkerProperty); }
1800 set { SetValue(LineMarkerProperty, value); }
1804 /// LineMarkerの依存プロパティを表す
1806 public static readonly DependencyProperty LineMarkerProperty =
1807 DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));
1810 /// 挿入モード時のキャレットの色を表す
1812 public System.Windows.Media.Color InsertCaret
1814 get { return (System.Windows.Media.Color)GetValue(InsertCaretProperty); }
1815 set { SetValue(InsertCaretProperty, value); }
1819 /// InsertCaretの依存プロパティを表す
1821 public static readonly DependencyProperty InsertCaretProperty =
1822 DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1827 public System.Windows.Media.Color UpdateArea
1829 get { return (System.Windows.Media.Color)GetValue(UpdateAreaProperty); }
1830 set { SetValue(UpdateAreaProperty, value); }
1834 /// UpdateAreaの依存プロパティを表す
1836 public static readonly DependencyProperty UpdateAreaProperty =
1837 DependencyProperty.Register("UpdateArea", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));
1840 /// 上書きモード時のキャレット職を表す
1842 public System.Windows.Media.Color OverwriteCaret
1844 get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }
1845 set { SetValue(OverwriteCaretProperty, value); }
1849 /// OverwriteCaretの依存プロパティを表す
1851 public static readonly DependencyProperty OverwriteCaretProperty =
1852 DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1857 public System.Windows.Media.Color LineNumber
1859 get { return (System.Windows.Media.Color)GetValue(LineNumberProperty); }
1860 set { SetValue(LineNumberProperty, value); }
1864 /// Using a DependencyProperty as the backing store for LineNumber. This enables animation, styling, binding, etc...
1866 public static readonly DependencyProperty LineNumberProperty =
1867 DependencyProperty.Register("LineNumber", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray));
1870 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1872 public bool InsertMode
1874 get { return (bool)GetValue(InsertModeProperty); }
1875 set { SetValue(InsertModeProperty, value); }
1879 /// InsertModeの依存プロパティを表す
1881 public static readonly DependencyProperty InsertModeProperty =
1882 DependencyProperty.Register("InsertMode",
1885 new FrameworkPropertyMetadata(true));
1888 /// タブの文字数を表す。これは依存プロパティです
1892 get { return (int)GetValue(TabCharsProperty); }
1893 set { SetValue(TabCharsProperty, value); }
1897 /// TabCharsの依存プロパティを表す
1899 public static readonly DependencyProperty TabCharsProperty =
1900 DependencyProperty.Register("TabChars",
1903 new FrameworkPropertyMetadata(4));
1906 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1908 public bool RectSelectMode
1910 get { return (bool)GetValue(RectSelectModeProperty); }
1911 set { SetValue(RectSelectModeProperty, value); }
1915 /// RectSelectModeの依存プロパティを表す
1917 public static readonly DependencyProperty RectSelectModeProperty =
1918 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1924 /// 変更した場合、レイアウトの再構築を行う必要があります
1926 public LineBreakMethod LineBreakMethod
1928 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1929 set { SetValue(LineBreakProperty, value); }
1933 /// LineBreakMethodの依存プロパティを表す
1935 public static readonly DependencyProperty LineBreakProperty =
1936 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None));
1940 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1943 /// 変更した場合、レイアウトの再構築を行う必要があります
1945 public int LineBreakCharCount
1947 get { return (int)GetValue(LineBreakCharCountProperty); }
1948 set { SetValue(LineBreakCharCountProperty, value); }
1952 /// LineBreakCharCountの依存プロパティを表す
1954 public static readonly DependencyProperty LineBreakCharCountProperty =
1955 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
1958 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1960 public bool DrawCaret
1962 get { return (bool)GetValue(DrawCaretProperty); }
1963 set { SetValue(DrawCaretProperty, value); }
1967 /// DrawCaretの依存プロパティを表す
1969 public static readonly DependencyProperty DrawCaretProperty =
1970 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
1974 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1976 public bool DrawCaretLine
1978 get { return (bool)GetValue(DrawCaretLineProperty); }
1979 set { SetValue(DrawCaretLineProperty, value); }
1983 /// DrawCaretLineの依存プロパティを表す
1985 public static readonly DependencyProperty DrawCaretLineProperty =
1986 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1989 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
1991 public bool DrawLineNumber
1993 get { return (bool)GetValue(DrawLineNumberProperty); }
1994 set { SetValue(DrawLineNumberProperty, value); }
1998 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
2000 public bool DrawRuler
2002 get { return (bool)GetValue(DrawRulerProperty); }
2003 set { SetValue(DrawRulerProperty, value); }
2007 /// DrawRulerの依存プロパティを表す
2009 public static readonly DependencyProperty DrawRulerProperty =
2010 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
2014 /// DrawLineNumberの依存プロパティを表す
2016 public static readonly DependencyProperty DrawLineNumberProperty =
2017 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
2020 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
2024 get { return (bool)GetValue(MarkURLProperty); }
2025 set { SetValue(MarkURLProperty, value); }
2029 /// MarkURLの依存プロパティを表す
2031 public static readonly DependencyProperty MarkURLProperty =
2032 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
2035 /// 全角スペースを表示するなら真。そうでないなら偽
2037 public bool ShowFullSpace
2039 get { return (bool)GetValue(ShowFullSpaceProperty); }
2040 set { SetValue(ShowFullSpaceProperty, value); }
2044 /// ShowFullSpaceの依存プロパティを表す
2046 public static readonly DependencyProperty ShowFullSpaceProperty =
2047 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
2050 /// 半角スペースを表示するなら真。そうでないなら偽
2052 public bool ShowHalfSpace
2054 get { return (bool)GetValue(ShowHalfSpaceProperty); }
2055 set { SetValue(ShowHalfSpaceProperty, value); }
2059 /// ShowHalfSpaceの依存プロパティを表す
2061 public static readonly DependencyProperty ShowHalfSpaceProperty =
2062 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
2065 /// タブを表示するなら真。そうでないなら偽
2069 get { return (bool)GetValue(ShowTabProperty); }
2070 set { SetValue(ShowTabProperty, value); }
2074 /// ShowTabの依存プロパティを表す
2076 public static readonly DependencyProperty ShowTabProperty =
2077 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
2080 /// 改行マークを表示するなら真。そうでないなら偽
2082 public bool ShowLineBreak
2084 get { return (bool)GetValue(ShowLineBreakProperty); }
2085 set { SetValue(ShowLineBreakProperty, value); }
2089 /// ShowLineBreakの依存プロパティを表す
2091 public static readonly DependencyProperty ShowLineBreakProperty =
2092 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
2097 /// マウスボタン関連のイベントクラス
2099 public sealed class FooMouseButtonEventArgs : MouseButtonEventArgs
2102 /// イベントが発生したドキュメントのインデックス
2113 /// <param name="mouse">マウスデバイス</param>
2114 /// <param name="timestamp">タイムスタンプ</param>
2115 /// <param name="button">ボタン</param>
2116 /// <param name="stylusDevice">スタイラスデバイス</param>
2117 /// <param name="index">インデックス</param>
2118 public FooMouseButtonEventArgs(MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice, int index)
2119 : base(mouse, timestamp, button, stylusDevice)
2127 public sealed class FooMouseEventArgs : MouseEventArgs
2130 /// イベントが発生したドキュメントのインデックス
2141 /// <param name="mouse">マウスデバイス</param>
2142 /// <param name="timestamp">タイムスタンプ</param>
2143 /// <param name="stylusDevice">スタイラスデバイス</param>
2144 /// <param name="index">インデックス</param>
2145 public FooMouseEventArgs(MouseDevice mouse,
2147 StylusDevice stylusDevice,
2149 : base(mouse, timestamp, stylusDevice)