2 * Copyright (C) 2013 FooProject
\r
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
\r
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
\r
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
\r
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/>.
\r
13 using System.Threading.Tasks;
\r
14 using System.Runtime.InteropServices;
\r
15 using System.Windows;
\r
16 using System.Windows.Input;
\r
17 using System.Windows.Media;
\r
18 using System.Windows.Controls;
\r
19 using System.Windows.Controls.Primitives;
\r
20 using System.Windows.Documents;
\r
21 using System.Windows.Interop;
\r
22 using System.Windows.Threading;
\r
23 using DotNetTextStore;
\r
24 using DotNetTextStore.UnmanagedAPI.TSF;
\r
25 using DotNetTextStore.UnmanagedAPI.WinDef;
\r
26 using Microsoft.Win32;
\r
28 namespace FooEditEngine.WPF
\r
31 /// オートインデントを行うためのデリゲートを表す
\r
33 /// <param name="sender">イベント発生元のオブジェクト</param>
\r
34 /// <param name="e">イベントデーター</param>
\r
35 public delegate void AutoIndentHookerHandler(object sender,EventArgs e);
\r
38 /// WPFでのFooTextBoxの実装
\r
40 public sealed class FooTextBox : Control, IDisposable
\r
42 const double MaxFontSize = 72.0f;
\r
43 const double MinFontSize = 1;
\r
46 Controller _Controller;
\r
49 ScrollBar verticalScrollBar, horizontalScrollBar;
\r
50 TextStore textStore;
\r
51 DispatcherTimer timer;
\r
52 bool disposed = false;
\r
53 FooTextBoxAutomationPeer peer;
\r
54 bool nowCaretMove = false;
\r
58 DefaultStyleKeyProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(typeof(FooTextBox)));
\r
59 KeyboardNavigation.IsTabStopProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(true));
\r
60 KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(KeyboardNavigationMode.None));
\r
68 this.image = new Image();
\r
69 this.image.Stretch = Stretch.Fill;
\r
70 this.image.HorizontalAlignment = HorizontalAlignment.Left;
\r
71 this.image.VerticalAlignment = VerticalAlignment.Top;
\r
73 this.textStore = new TextStore();
\r
74 this.textStore.IsLoading += textStore_IsLoading;
\r
75 this.textStore.IsReadOnly += textStore_IsReadOnly;
\r
76 this.textStore.GetDpi += textStore_GetDpi;
\r
77 this.textStore.GetStringLength += () => this.Document.Length;
\r
78 this.textStore.GetString += _textStore_GetString;
\r
79 this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;
\r
80 this.textStore.SetSelectionIndex += _textStore_SetSelectionIndex;
\r
81 this.textStore.InsertAtSelection += _textStore_InsertAtSelection;
\r
82 this.textStore.GetHWnd += _textStore_GetHWnd;
\r
83 this.textStore.GetScreenExtent += _textStore_GetScreenExtent;
\r
84 this.textStore.GetStringExtent += _textStore_GetStringExtent;
\r
85 this.textStore.CompositionStarted += textStore_CompositionStarted;
\r
86 this.textStore.CompositionUpdated += textStore_CompositionUpdated;
\r
87 this.textStore.CompositionEnded += textStore_CompositionEnded;
\r
89 this.Render = new D2DRender(this, 200, 200,this.image);
\r
90 this.Render.ShowFullSpace = this.ShowFullSpace;
\r
91 this.Render.ShowHalfSpace = this.ShowHalfSpace;
\r
92 this.Render.ShowTab = this.ShowTab;
\r
94 this.Document = new Document();
\r
95 this.Document.LayoutLines.Render = this.Render;
\r
97 this.View = new EditView(this.Document, this.Render, new Padding(5, 5, 5, 5));
\r
98 this.View.SrcChanged += View_SrcChanged;
\r
99 this.View.InsertMode = this.InsertMode;
\r
100 this.View.DrawLineNumber = this.DrawLineNumber;
\r
101 this.View.HideCaret = !this.DrawCaret;
\r
102 this.View.HideLineMarker = !this.DrawCaretLine;
\r
103 this.View.HideRuler = !this.DrawRuler;
\r
104 this.View.UrlMark = this.MarkURL;
\r
105 this.View.TabStops = this.TabChars;
\r
107 this._Controller = new Controller(this.Document, this.View);
\r
108 this._Controller.SelectionChanged += new EventHandler(Controller_SelectionChanged);
\r
110 //Viewを作成した後に追加しないと例外が発生する
\r
111 this.Document.Update += new DocumentUpdateEventHandler(Document_Update);
\r
113 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, CopyCommand, CanExecute));
\r
114 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, CutCommand, CanExecute));
\r
115 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, PasteCommand, CanExecute));
\r
116 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, DeleteCommand, CanExecute));
\r
117 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, SelectAllCommand, CanExecute));
\r
118 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, UndoCommand, CanExecute));
\r
119 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, RedoCommand, CanExecute));
\r
120 this.CommandBindings.Add(new CommandBinding(EditingCommands.ToggleInsert, ToggleInsertCommand, CanExecute));
\r
121 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleRectSelectMode, ToggleRectSelectCommand, CanExecute));
\r
122 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleFlowDirection, ToggleFlowDirectionCommand, CanExecute));
\r
123 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleCodePoint, ToggleCodePointCommand, CanExecute));
\r
125 this.InputBindings.Add(new InputBinding(ApplicationCommands.Copy, new KeyGesture(Key.C, ModifierKeys.Control)));
\r
126 this.InputBindings.Add(new InputBinding(ApplicationCommands.Cut, new KeyGesture(Key.X, ModifierKeys.Control)));
\r
127 this.InputBindings.Add(new InputBinding(ApplicationCommands.Paste, new KeyGesture(Key.V, ModifierKeys.Control)));
\r
128 this.InputBindings.Add(new InputBinding(ApplicationCommands.Delete, new KeyGesture(Key.Delete, ModifierKeys.None)));
\r
129 this.InputBindings.Add(new InputBinding(ApplicationCommands.SelectAll, new KeyGesture(Key.A, ModifierKeys.Control)));
\r
130 this.InputBindings.Add(new InputBinding(ApplicationCommands.Undo, new KeyGesture(Key.Z, ModifierKeys.Control)));
\r
131 this.InputBindings.Add(new InputBinding(ApplicationCommands.Redo, new KeyGesture(Key.Y, ModifierKeys.Control)));
\r
132 this.InputBindings.Add(new InputBinding(EditingCommands.ToggleInsert, new KeyGesture(Key.Insert, ModifierKeys.None)));
\r
133 this.InputBindings.Add(new InputBinding(FooTextBoxCommands.ToggleCodePoint, new KeyGesture(Key.X, ModifierKeys.Alt)));
\r
135 this.timer = new DispatcherTimer();
\r
136 this.timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
\r
137 this.timer.Tick += new EventHandler(timer_Tick);
\r
139 this.Loaded += new RoutedEventHandler(FooTextBox_Loaded);
\r
141 this.AutoIndentHooker = (s,e)=>{};
\r
143 SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
\r
145 this.SystemEvents_UserPreferenceChanged(null, new UserPreferenceChangedEventArgs(UserPreferenceCategory.Keyboard));
\r
147 this.CaretMoved += (s, e) => { };
\r
155 //Dispose(false)を呼び出すと落ちる
\r
156 this.Dispose(false);
\r
160 /// オートインデントを行うためのイベント
\r
162 public AutoIndentHookerHandler AutoIndentHooker;
\r
167 public override void OnApplyTemplate()
\r
169 base.OnApplyTemplate();
\r
171 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
\r
174 Grid.SetRow(this.image, 0);
\r
175 Grid.SetColumn(this.image, 0);
\r
176 grid.Children.Add(this.image);
\r
179 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
\r
180 if (this.horizontalScrollBar != null)
\r
182 this.horizontalScrollBar.SmallChange = 10;
\r
183 this.horizontalScrollBar.LargeChange = 100;
\r
184 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
\r
185 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
\r
187 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
\r
188 if (this.verticalScrollBar != null)
\r
190 this.verticalScrollBar.SmallChange = 1;
\r
191 this.verticalScrollBar.LargeChange = 10;
\r
192 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
\r
193 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
\r
200 /// <param name="start">開始インデックス</param>
\r
201 /// <param name="length">長さ</param>
\r
202 public void Select(int start, int length)
\r
204 this._Controller.Select(start, length);
\r
205 this.textStore.NotifySelectionChanged();
\r
209 /// キャレットを指定した行に移動させます
\r
211 /// <param name="index">インデックス</param>
\r
212 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
\r
213 public void JumpCaret(int index)
\r
215 this._Controller.JumpCaret(index);
\r
218 /// キャレットを指定した行と桁に移動させます
\r
220 /// <param name="row">行番号</param>
\r
221 /// <param name="col">桁</param>
\r
222 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
\r
223 public void JumpCaret(int row, int col)
\r
225 this._Controller.JumpCaret(row, col);
\r
229 /// 選択中のテキストをクリップボードにコピーします
\r
233 string text = this._Controller.SelectedText;
\r
234 if (text != null && text != string.Empty)
\r
235 Clipboard.SetText(text);
\r
239 /// 選択中のテキストをクリップボードに切り取ります
\r
243 string text = this._Controller.SelectedText;
\r
244 if (text != null && text != string.Empty)
\r
246 Clipboard.SetText(text);
\r
247 this._Controller.SelectedText = "";
\r
252 /// 選択中のテキストを貼り付けます
\r
254 public void Paste()
\r
256 if (Clipboard.ContainsText() == false)
\r
258 string text = Clipboard.GetText();
\r
259 this._Controller.SelectedText = text;
\r
265 public void DeSelectAll()
\r
267 this._Controller.DeSelectAll();
\r
268 this.textStore.NotifySelectionChanged();
\r
274 /// <param name="tp">テキストポイント</param>
\r
275 /// <returns>座標</returns>
\r
276 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
\r
277 public System.Windows.Point GetPostionFromTextPoint(TextPoint tp)
\r
279 if (this.Document.FireUpdateEvent == false)
\r
280 throw new InvalidOperationException("");
\r
281 return this.View.GetPostionFromTextPoint(tp);
\r
285 /// 対応するテキストポイントを返します
\r
287 /// <param name="p">クライアント領域の原点を左上とする座標</param>
\r
288 /// <returns>テキストポイント</returns>
\r
289 public TextPoint GetTextPointFromPostion(System.Windows.Point p)
\r
291 if (this.Document.FireUpdateEvent == false)
\r
292 throw new InvalidOperationException("");
\r
293 return this.View.GetTextPointFromPostion(p);
\r
299 /// <param name="row">レイアウト行</param>
\r
300 /// <returns>行の高さ</returns>
\r
301 public double GetLineHeight(int row)
\r
303 if (this.Document.FireUpdateEvent == false)
\r
304 throw new InvalidOperationException("");
\r
305 return this.View.LayoutLines.GetLayout(row).Height;;
\r
309 /// インデックスに対応する座標を得ます
\r
311 /// <param name="index">インデックス</param>
\r
312 /// <returns>座標を返す</returns>
\r
313 public System.Windows.Point GetPostionFromIndex(int index)
\r
315 if (this.Document.FireUpdateEvent == false)
\r
316 throw new InvalidOperationException("");
\r
317 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
\r
318 return this.View.GetPostionFromTextPoint(tp);
\r
322 /// 座標からインデックスに変換します
\r
324 /// <param name="p">座標</param>
\r
325 /// <returns>インデックスを返す</returns>
\r
326 public int GetIndexFromPostion(System.Windows.Point p)
\r
328 if (this.Document.FireUpdateEvent == false)
\r
329 throw new InvalidOperationException("");
\r
330 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
331 return this.View.GetIndexFromLayoutLine(tp);
\r
337 public void Refresh()
\r
339 this.Refresh(this.View.PageBound);
\r
343 /// レイアウト行をすべて破棄し、再度レイアウトを行う
\r
345 public void PerfomLayouts()
\r
347 this.View.PerfomLayouts();
\r
351 /// ストリームからドキュメントを構築する
\r
353 /// <param name="tr">TextReader</param>
\r
354 /// <param name="token">キャンセル用トークン</param>
\r
355 /// <returns>Taskオブジェクト</returns>
\r
356 public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)
\r
358 WinFileReader fs = new WinFileReader(tr);
\r
359 await this.LoadAsyncImpl(fs, token);
\r
363 /// ファイルからドキュメントを構築する
\r
365 /// <param name="filepath">ファイルパス</param>
\r
366 /// <param name="enc">エンコード</param>
\r
367 /// <param name="token">キャンセル用トークン</param>
\r
368 /// <returns>Taskオブジェクト</returns>
\r
369 public async Task LoadFileAsync(string filepath, Encoding enc,System.Threading.CancellationTokenSource token)
\r
371 WinFileReader fs = new WinFileReader(filepath, enc);
\r
372 await this.LoadAsyncImpl(fs, token);
\r
375 async Task LoadAsyncImpl(WinFileReader fs,System.Threading.CancellationTokenSource token)
\r
377 this.IsEnabled = false;
\r
378 this.View.LayoutLines.IsFrozneDirtyFlag = true;
\r
379 await this.Document.LoadAsync(fs, token);
\r
380 this.View.LayoutLines.IsFrozneDirtyFlag = false;
\r
381 TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
\r
382 if (this.verticalScrollBar != null)
\r
383 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
\r
384 this.View.CalculateLineCountOnScreen();
\r
385 this.IsEnabled = true;
\r
389 /// ドキュメントの内容をファイルに保存する
\r
391 /// <param name="filepath">ファイルパス</param>
\r
392 /// <param name="newLine">改行コード</param>
\r
393 /// <param name="enc">エンコード</param>
\r
394 /// <returns>Taskオブジェクト</returns>
\r
395 public async Task SaveFile(string filepath, Encoding enc,string newLine, System.Threading.CancellationTokenSource token)
\r
397 WinFileWriter fs = new WinFileWriter(filepath, enc);
\r
398 fs.NewLine = newLine;
\r
399 await this.Document.SaveAsync(fs, token);
\r
403 /// アンマネージドリソースを開放する
\r
405 public void Dispose()
\r
409 this.Dispose(true);
\r
410 GC.SuppressFinalize(this);
\r
411 this.disposed = true;
\r
417 /// <param name="disposing">真ならマネージドリソースも開放し、そうでないならアンマネージドリソースのみを開放する</param>
\r
418 void Dispose(bool disposing)
\r
422 this.textStore.Dispose();
\r
424 this.View.Dispose();
\r
425 this.Render.Dispose();
\r
427 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
\r
430 void Refresh(Rectangle updateRect)
\r
437 this.Render.BegineDraw();
\r
438 if (this.IsEnabled)
\r
439 this.View.Draw(updateRect);
\r
441 this.Render.FillBackground(updateRect);
\r
442 this.Render.EndDraw();
\r
444 this.timer.Start();
\r
448 void CanExecute(object sender, CanExecuteRoutedEventArgs e)
\r
450 e.CanExecute = this.IsEnabled;
\r
453 void ToggleCodePointCommand(object sender, RoutedEventArgs e)
\r
455 if (!this._Controller.ConvertToChar())
\r
456 this._Controller.ConvertToCodePoint();
\r
460 void CopyCommand(object sender, RoutedEventArgs e)
\r
465 void CutCommand(object sender, RoutedEventArgs e)
\r
471 void PasteCommand(object sender, RoutedEventArgs e)
\r
477 void DeleteCommand(object sender, RoutedEventArgs e)
\r
479 int oldLength = this.Document.Length;
\r
480 this._Controller.DoDeleteAction();
\r
484 void SelectAllCommand(object sender, RoutedEventArgs e)
\r
486 this.Select(0, this.Document.Length);
\r
490 void UndoCommand(object sender, RoutedEventArgs e)
\r
492 int oldLength = this.Document.Length;
\r
493 this.Document.UndoManager.undo();
\r
497 void RedoCommand(object sender, RoutedEventArgs e)
\r
499 int oldLength = this.Document.Length;
\r
500 this.Document.UndoManager.redo();
\r
504 void ToggleInsertCommand(object sender, RoutedEventArgs e)
\r
506 if (this.InsertMode)
\r
507 this.InsertMode = false;
\r
509 this.InsertMode = true;
\r
513 void ToggleRectSelectCommand(object sender, RoutedEventArgs e)
\r
515 if (this.RectSelectMode)
\r
516 this.RectSelectMode = false;
\r
518 this.RectSelectMode = true;
\r
521 void ToggleFlowDirectionCommand(object sender, RoutedEventArgs e)
\r
523 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
\r
524 this.FlowDirection = System.Windows.FlowDirection.RightToLeft;
\r
526 this.FlowDirection = System.Windows.FlowDirection.LeftToRight;
\r
531 internal TextStore TextStore
\r
533 get { return this.textStore; }
\r
536 double textStore_GetDpi()
\r
539 this.Render.GetDpi(out dpi, out dpi);
\r
543 bool textStore_IsReadOnly()
\r
548 bool textStore_IsLoading()
\r
553 void textStore_CompositionEnded()
\r
555 TextStoreHelper.EndCompostion(this.Document);
\r
559 void textStore_CompositionUpdated(int start, int end)
\r
561 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
\r
564 bool textStore_CompositionStarted()
\r
566 bool result = TextStoreHelper.StartCompstion(this.Document);
\r
568 System.Media.SystemSounds.Beep.Play();
\r
572 string _textStore_GetString(int start, int length)
\r
574 return this.Document.ToString(start, length);
\r
577 IntPtr _textStore_GetHWnd()
\r
579 var hwndSource = HwndSource.FromVisual(this) as HwndSource;
\r
580 if (hwndSource != null)
\r
581 return hwndSource.Handle;
\r
583 return IntPtr.Zero;
\r
586 void _textStore_GetStringExtent(
\r
589 out POINT o_topLeft,
\r
590 out POINT o_bottomRight
\r
593 Point startPos, endPos;
\r
594 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
\r
596 startPos = PointToScreen(this.TranslatePoint(startPos, this));
\r
597 endPos = PointToScreen(this.TranslatePoint(endPos, this));
\r
599 o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);
\r
600 o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);
\r
603 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
\r
605 var pointTopLeft = new Point(0, 0);
\r
606 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
\r
608 pointTopLeft = PointToScreen(pointTopLeft);
\r
609 pointBottomRight = PointToScreen(pointBottomRight);
\r
611 o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
\r
612 o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
\r
615 void _textStore_GetSelectionIndex(out int o_startIndex, out int o_endIndex)
\r
617 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out o_startIndex, out o_endIndex);
\r
620 void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)
\r
622 TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);
\r
626 void _textStore_InsertAtSelection(string i_value)
\r
628 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
\r
633 /// キーボードフォーカスが取得されたときに呼ばれます
\r
635 /// <param name="e">イベントデーター</param>
\r
636 protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
\r
638 base.OnGotKeyboardFocus(e);
\r
639 this.textStore.SetFocus();
\r
640 this.View.IsFocused = true;
\r
645 /// キーボードフォーカスが失われたときに呼ばれます
\r
647 /// <param name="e">イベントデーター</param>
\r
648 protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
\r
650 base.OnLostKeyboardFocus(e);
\r
651 this.View.IsFocused = false;
\r
657 /// キャレットが移動したときに通知されるイベント
\r
659 public event EventHandler CaretMoved;
\r
662 protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
\r
664 this.peer = new FooTextBoxAutomationPeer(this);
\r
670 protected override void OnTextInput(TextCompositionEventArgs e)
\r
672 if (e.Text == "\r")
\r
674 this._Controller.DoEnterAction();
\r
675 this.AutoIndentHooker(this, null);
\r
677 else if (e.Text == "\b")
\r
679 this._Controller.DoBackSpaceAction();
\r
683 if(this.IsInputString(e.Text))
\r
684 this._Controller.DoInputString(e.Text);
\r
687 base.OnTextInput(e);
\r
691 bool IsInputString(string s)
\r
693 foreach (char charCode in s)
\r
695 if ((0x20 <= charCode && charCode <= 0x7e)
\r
696 || 0x7f < charCode)
\r
703 protected override void OnKeyDown(KeyEventArgs e)
\r
705 if (this.textStore.IsLocked())
\r
708 ModifierKeys modiferKeys = e.KeyboardDevice.Modifiers;
\r
709 bool movedCaret = false;
\r
713 this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
719 this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
725 this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
\r
731 this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
\r
737 this._Controller.Scroll(ScrollDirection.Up,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
\r
742 this._Controller.Scroll(ScrollDirection.Down,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
\r
747 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
\r
748 this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
750 this._Controller.JumpToLineHead(this.View.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
755 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
\r
756 this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
758 this._Controller.JumpToLineEnd(this.View.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
763 int oldLength = this.Document.Length;
\r
764 if (this.Selection.Length == 0)
\r
765 this._Controller.DoInputChar('\t');
\r
766 else if(this.IsPressedModifierKey(modiferKeys,ModifierKeys.Shift))
\r
767 this._Controller.DownIndent();
\r
769 this._Controller.UpIndent();
\r
774 if (movedCaret && this.peer != null)
\r
775 this.peer.OnNotifyCaretChanged();
\r
779 bool IsPressedModifierKey(ModifierKeys keys, ModifierKeys pressed)
\r
781 if (keys == pressed)
\r
783 if ((keys & pressed) == pressed)
\r
789 /// ダブルクリックされたときに呼ばれます
\r
791 /// <param name="e">イベントパラメーター</param>
\r
793 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
\r
794 /// e.Handledを真にした場合、単語単位の選択が行われなくなります
\r
796 protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
\r
798 System.Windows.Point p = e.GetPosition(this);
\r
799 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
800 if (tp == TextPoint.Null)
\r
802 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
804 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
\r
809 newEventArgs.RoutedEvent = e.RoutedEvent;
\r
810 base.OnMouseDoubleClick(newEventArgs);
\r
812 if (newEventArgs.Handled)
\r
815 if (e.LeftButton == MouseButtonState.Pressed)
\r
818 this._Controller.SelectWord(index);
\r
819 this.textStore.NotifySelectionChanged();
\r
820 if(this.peer != null)
\r
821 this.peer.OnNotifyCaretChanged();
\r
827 /// マウスボタンが押されたときに呼ばれます
\r
829 /// <param name="e">イベントパラメーター</param>
\r
831 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
\r
832 /// e.Handledを真にした場合、キャレットの移動処理が行われなくなります
\r
834 protected override void OnMouseDown(MouseButtonEventArgs e)
\r
836 System.Windows.Point p = e.GetPosition(this);
\r
837 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
838 if (tp == TextPoint.Null)
\r
840 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
842 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
\r
847 newEventArgs.RoutedEvent = e.RoutedEvent;
\r
848 base.OnMouseDown(newEventArgs);
\r
850 if (newEventArgs.Handled)
\r
853 if (e.LeftButton == MouseButtonState.Pressed)
\r
855 FoldingItem foldingData = this.View.HitFoldingData(p.X,tp.row);
\r
856 if (foldingData != null)
\r
858 if (foldingData.Expand)
\r
859 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
\r
861 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
\r
862 this._Controller.JumpCaret(foldingData.Start,false);
\r
866 this._Controller.JumpCaret(tp.row, tp.col, false);
\r
868 if (this.peer != null)
\r
869 this.peer.OnNotifyCaretChanged();
\r
870 this.View.IsFocused = true;
\r
877 /// マウスが移動したときに呼ばれます
\r
879 /// <param name="e">イベントパラメーター</param>
\r
881 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
\r
882 /// e.Handledを真にした場合、選択処理と状況に応じたカーソルの変化が行われなくなります
\r
884 protected override void OnMouseMove(MouseEventArgs e)
\r
886 System.Windows.Point p = e.GetPosition(this);
\r
887 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
888 if (tp == TextPoint.Null)
\r
890 base.OnMouseMove(e);
\r
893 int index = this.View.GetIndexFromLayoutLine(tp);
\r
895 FooMouseEventArgs newEventArgs = new FooMouseEventArgs(e.MouseDevice, e.Timestamp, e.StylusDevice, index);
\r
896 newEventArgs.RoutedEvent = e.RoutedEvent;
\r
897 base.OnMouseMove(newEventArgs);
\r
899 if (newEventArgs.Handled)
\r
902 if (this.View.HitTextArea(p.X,p.Y))
\r
904 if (this._Controller.IsMarker(tp, HilightType.Url))
\r
905 this.Cursor = Cursors.Hand;
\r
907 this.Cursor = Cursors.IBeam;
\r
909 if (e.LeftButton == MouseButtonState.Pressed)
\r
911 this._Controller.MoveCaretAndSelect(tp);
\r
912 if (this.peer != null)
\r
913 this.peer.OnNotifyCaretChanged();
\r
919 this.Cursor = Cursors.Arrow;
\r
924 protected override void OnMouseWheel(MouseWheelEventArgs e)
\r
926 if(Keyboard.Modifiers == ModifierKeys.None)
\r
929 this._Controller.Scroll(ScrollDirection.Up, SystemParameters.WheelScrollLines, false, false);
\r
931 this._Controller.Scroll(ScrollDirection.Down, SystemParameters.WheelScrollLines, false, false);
\r
933 else if (Keyboard.Modifiers == ModifierKeys.Control)
\r
935 double newFontSize = this.Render.FontSize;
\r
940 if (newFontSize > MaxFontSize)
\r
942 else if (newFontSize < MinFontSize)
\r
944 this.Render.FontSize = newFontSize;
\r
945 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
\r
948 base.OnMouseWheel(e);
\r
951 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
\r
953 if (e.Category == UserPreferenceCategory.Keyboard)
\r
955 int blinkTime = (int)NativeMethods.GetCaretBlinkTime();
\r
956 this.View.CaretBlink = blinkTime >= 0;
\r
957 this.View.CaretBlinkTime = blinkTime * 2;
\r
959 if (e.Category == UserPreferenceCategory.General)
\r
961 this.View.CaretWidthOnInsertMode = SystemParameters.CaretWidth;
\r
965 void Document_Update(object sender, DocumentUpdateEventArgs e)
\r
967 if (this.textStore.IsLocked())
\r
969 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
\r
972 void timer_Tick(object sender, EventArgs e)
\r
974 if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)
\r
976 if (this.Resize(this.image.ActualWidth, this.image.ActualHeight))
\r
982 ITextLayout layout = this.View.LayoutLines.GetLayout(this.View.CaretPostion.row);
\r
983 double width = layout.GetWidthFromIndex(this.View.CaretPostion.col);
\r
985 width = this.View.CaretWidthOnInsertMode;
\r
986 double height = layout.Height;
\r
987 Rectangle updateRect = new Rectangle(
\r
988 this.View.CaretLocation.X,
\r
989 this.View.CaretLocation.Y,
\r
993 this.Refresh(updateRect);
\r
996 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
998 if (this.horizontalScrollBar == null)
\r
1001 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
\r
1002 toX = this.horizontalScrollBar.Value;
\r
1004 toX = -this.horizontalScrollBar.Value;
\r
1005 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
\r
1009 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
1011 if (this.verticalScrollBar == null)
\r
1013 int newRow = (int)this.verticalScrollBar.Value;
\r
1014 if (newRow >= this.View.LayoutLines.Count)
\r
1016 this._Controller.Scroll(this.View.Src.X,newRow, false, false);
\r
1020 void View_SrcChanged(object sender, EventArgs e)
\r
1022 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
\r
1024 EditView view = this.View;
\r
1025 if (view.Src.Row > this.verticalScrollBar.Maximum)
\r
1026 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
\r
1027 double absoulteX = Math.Abs(view.Src.X);
\r
1028 if(absoulteX > this.horizontalScrollBar.Maximum)
\r
1029 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
\r
1030 if(view.Src.Row != this.verticalScrollBar.Value)
\r
1031 this.verticalScrollBar.Value = view.Src.Row;
\r
1032 if (view.Src.X != this.horizontalScrollBar.Value)
\r
1033 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
\r
1036 void Controller_SelectionChanged(object sender, EventArgs e)
\r
1038 this.View.CaretBlink = this.View.CaretBlink;
\r
1039 this.CaretMoved(this, null);
\r
1040 //こうしないと選択できなくなってしまう
\r
1041 this.nowCaretMove = true;
\r
1042 SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
\r
1043 SetValue(CaretPostionProperty, this.View.CaretPostion);
\r
1044 this.nowCaretMove = false;
\r
1045 if(this.textStore.IsLocked() == false)
\r
1046 this.textStore.NotifySelectionChanged();
\r
1049 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
\r
1051 this.Resize(this.image.ActualWidth, this.image.ActualHeight);
\r
1054 bool Resize(double width, double height)
\r
1056 if (width == 0 || height == 0)
\r
1057 throw new ArgumentOutOfRangeException();
\r
1058 if (this.Render.Resize(width, height))
\r
1060 this.View.PageBound = new Rectangle(0, 0, width, height);
\r
1062 if (this.horizontalScrollBar != null)
\r
1064 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
\r
1065 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
\r
1067 if (this.verticalScrollBar != null)
\r
1069 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
\r
1070 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
\r
1078 /// プロパティーが変更されたときに呼ばれます
\r
1080 /// <param name="e">イベントパラメーター</param>
\r
1081 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
\r
1083 switch (e.Property.Name)
\r
1086 if(!this.nowCaretMove)
\r
1087 this.Select(this.Selection.Index, this.Selection.Length);
\r
1089 case "CaretPostion":
\r
1090 if (!this.nowCaretMove)
\r
1091 this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
\r
1093 case "LineBreakMethod":
\r
1094 this.View.LineBreak = this.LineBreakMethod;
\r
1096 case "LineBreakCharCount":
\r
1097 this.View.LineBreakCharCount = this.LineBreakCharCount;
\r
1099 case "InsertMode":
\r
1100 this.View.InsertMode = this.InsertMode;
\r
1103 this.View.TabStops = this.TabChars;
\r
1105 case "RectSelectMode":
\r
1106 this._Controller.RectSelection = this.RectSelectMode;
\r
1109 this.View.HideCaret = !this.DrawCaret;
\r
1111 case "DrawCaretLine":
\r
1112 this.View.HideLineMarker = !this.DrawCaretLine;
\r
1114 case "DrawLineNumber":
\r
1115 this.View.DrawLineNumber = this.DrawLineNumber;
\r
1116 this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);
\r
1118 case "FontFamily":
\r
1119 this.Render.FontFamily = this.FontFamily;
\r
1122 this.Render.FontSize = this.FontSize;
\r
1125 this.Render.FontStyle = this.FontStyle;
\r
1127 case "FontWeight":
\r
1128 this.Render.FontWeigth = this.FontWeight;
\r
1130 case "Foreground":
\r
1131 this.Render.Foreground = D2DRender.ToColor4(this.Foreground);
\r
1133 case "Background":
\r
1134 this.Render.Background = D2DRender.ToColor4(this.Background);
\r
1136 case "ControlChar":
\r
1137 this.Render.ControlChar =D2DRender.ToColor4( this.ControlChar);
\r
1140 this.Render.Hilight = D2DRender.ToColor4(this.Hilight);
\r
1143 this.Render.Keyword1 = D2DRender.ToColor4(this.Keyword1);
\r
1146 this.Render.Keyword2 = D2DRender.ToColor4(this.Keyword2);
\r
1149 this.Render.Comment = D2DRender.ToColor4(this.Comment);
\r
1152 this.Render.Literal = D2DRender.ToColor4(this.Literal);
\r
1155 this.Render.Url = D2DRender.ToColor4(this.URL);
\r
1157 case "InsertCaret":
\r
1158 this.Render.InsertCaret = D2DRender.ToColor4(this.InsertCaret);
\r
1160 case "OverwriteCaret":
\r
1161 this.Render.OverwriteCaret = D2DRender.ToColor4(this.OverwriteCaret);
\r
1164 this.View.Padding = new Padding((int)this.Padding.Left, (int)this.Padding.Top, (int)this.Padding.Right, (int)this.Padding.Bottom);
\r
1166 case "LineMarker":
\r
1167 this.Render.LineMarker = D2DRender.ToColor4(this.LineMarker);
\r
1170 this.View.UrlMark = this.MarkURL;
\r
1172 case "ShowFullSpace":
\r
1173 this.Render.ShowFullSpace = this.ShowFullSpace;
\r
1175 case "ShowHalfSpace":
\r
1176 this.Render.ShowHalfSpace = this.ShowHalfSpace;
\r
1179 this.Render.ShowTab = this.ShowTab;
\r
1181 case "ShowLineBreak":
\r
1182 this.Render.ShowLineBreak = this.ShowLineBreak;
\r
1184 case "FlowDirection":
\r
1185 this.Render.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;
\r
1186 this.horizontalScrollBar.FlowDirection = this.FlowDirection;
\r
1189 this.View.HideRuler = !this.DrawRuler;
\r
1190 this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);
\r
1192 case "UpdateArea":
\r
1193 this.Render.UpdateArea = D2DRender.ToColor4(this.UpdateArea);
\r
1196 base.OnPropertyChanged(e);
\r
1201 internal Controller Controller
\r
1205 return this._Controller;
\r
1210 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
\r
1212 public TextAntialiasMode TextAntialiasMode
\r
1216 return this.Render.TextAntialiasMode;
\r
1220 this.Render.TextAntialiasMode = value;
\r
1225 /// シンタックスハイライターを表す
\r
1227 public IHilighter Hilighter
\r
1231 return this.View.Hilighter;
\r
1235 this.View.Hilighter = value;
\r
1236 this.View.LayoutLines.ClearLayoutCache();
\r
1241 /// フォールティングを作成するインターフェイスを表す
\r
1243 public IFoldingStrategy FoldingStrategy
\r
1247 return this.View.LayoutLines.FoldingStrategy;
\r
1251 this.View.LayoutLines.FoldingStrategy = value;
\r
1252 if (value == null)
\r
1253 this.View.LayoutLines.FoldingCollection.Clear();
\r
1260 public MarkerPatternSet MarkerPatternSet
\r
1264 return this.View.MarkerPatternSet;
\r
1271 public Document Document
\r
1280 public LineToIndexTable LayoutLineCollection
\r
1282 get { return this.View.LayoutLines; }
\r
1288 public string SelectedText
\r
1292 return this._Controller.SelectedText;
\r
1296 int oldLength = this.Document.Length;
\r
1297 this._Controller.SelectedText = value;
\r
1305 /// Lengthが0の場合はキャレット位置を表します。
\r
1306 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
\r
1308 public TextRange Selection
\r
1310 get { return (TextRange)GetValue(SelectionProperty); }
\r
1311 set { SetValue(SelectionProperty, value); }
\r
1315 /// Selectionの依存プロパティを表す
\r
1317 public static readonly DependencyProperty SelectionProperty =
\r
1318 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null));
\r
1323 public double MagnificationPower
\r
1325 get { return (double)GetValue(MagnificationPowerPropertyKey.DependencyProperty); }
\r
1331 public static readonly DependencyPropertyKey MagnificationPowerPropertyKey =
\r
1332 DependencyProperty.RegisterReadOnly("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0));
\r
1337 public new FlowDirection FlowDirection
\r
1339 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
\r
1340 set { SetValue(FlowDirectionProperty, value); }
\r
1344 /// レタリング方向を表す。これは依存プロパティです
\r
1346 public new static readonly DependencyProperty FlowDirectionProperty =
\r
1347 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight));
\r
1350 /// キャレット位置を表す。これは依存プロパティです
\r
1352 public TextPoint CaretPostion
\r
1354 get { return (TextPoint)GetValue(CaretPostionProperty); }
\r
1355 set { SetValue(CaretPostionProperty, value); }
\r
1359 /// CaretPostionの依存プロパティを表す
\r
1361 public static readonly DependencyProperty CaretPostionProperty =
\r
1362 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(TextPoint.Null));
\r
1365 /// デフォルトの文字色を表す。これは依存プロパティです
\r
1367 public new System.Windows.Media.Color Foreground
\r
1369 get { return (System.Windows.Media.Color)GetValue(ForegroundProperty); }
\r
1370 set { SetValue(ForegroundProperty, value); }
\r
1374 /// Foregroundの依存プロパティを表す
\r
1376 public new static readonly DependencyProperty ForegroundProperty =
\r
1377 DependencyProperty.Register("Foreground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
\r
1380 /// 背景色を表す。これは依存プロパティです
\r
1382 public new System.Windows.Media.Color Background
\r
1384 get { return (System.Windows.Media.Color)GetValue(BackgroundProperty); }
\r
1385 set { SetValue(BackgroundProperty, value); }
\r
1389 /// Backgroundの依存プロパティを表す
\r
1391 public new static readonly DependencyProperty BackgroundProperty =
\r
1392 DependencyProperty.Register("Background", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowColor));
\r
1395 /// コントロールコードの文字色を表す。これは依存プロパティです
\r
1397 public System.Windows.Media.Color ControlChar
\r
1399 get { return (System.Windows.Media.Color)GetValue(ControlCharProperty); }
\r
1400 set { SetValue(ControlCharProperty, value); }
\r
1404 /// ControlCharの依存プロパティを表す
\r
1406 public static readonly DependencyProperty ControlCharProperty =
\r
1407 DependencyProperty.Register("ControlChar", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Gray));
\r
1410 /// 選択時の背景色を表す。これは依存プロパティです
\r
1412 public System.Windows.Media.Color Hilight
\r
1414 get { return (System.Windows.Media.Color)GetValue(HilightProperty); }
\r
1415 set { SetValue(HilightProperty, value); }
\r
1419 /// Hilightの依存プロパティを表す
\r
1421 public static readonly DependencyProperty HilightProperty =
\r
1422 DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));
\r
1425 /// キーワード1の文字色を表す。これは依存プロパティです
\r
1427 public System.Windows.Media.Color Keyword1
\r
1429 get { return (System.Windows.Media.Color)GetValue(Keyword1Property); }
\r
1430 set { SetValue(Keyword1Property, value); }
\r
1434 /// Keyword1の依存プロパティを表す
\r
1436 public static readonly DependencyProperty Keyword1Property =
\r
1437 DependencyProperty.Register("Keyword1", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
\r
1440 /// キーワード2の文字色を表す。これは依存プロパティです
\r
1442 public System.Windows.Media.Color Keyword2
\r
1444 get { return (System.Windows.Media.Color)GetValue(Keyword2Property); }
\r
1445 set { SetValue(Keyword2Property, value); }
\r
1449 /// Keyword2の依存プロパティを表す
\r
1451 public static readonly DependencyProperty Keyword2Property =
\r
1452 DependencyProperty.Register("Keyword2", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DarkCyan));
\r
1455 /// コメントの文字色を表す。これは依存プロパティです
\r
1457 public System.Windows.Media.Color Comment
\r
1459 get { return (System.Windows.Media.Color)GetValue(CommentProperty); }
\r
1460 set { SetValue(CommentProperty, value); }
\r
1464 /// Commentの依存プロパティを表す
\r
1466 public static readonly DependencyProperty CommentProperty =
\r
1467 DependencyProperty.Register("Comment", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Green));
\r
1470 /// 文字リテラルの文字色を表す。これは依存プロパティです
\r
1472 public System.Windows.Media.Color Literal
\r
1474 get { return (System.Windows.Media.Color)GetValue(LiteralProperty); }
\r
1475 set { SetValue(LiteralProperty, value); }
\r
1479 /// Literalの依存プロパティを表す
\r
1481 public static readonly DependencyProperty LiteralProperty =
\r
1482 DependencyProperty.Register("Literal", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Brown));
\r
1485 /// URLの文字色を表す。これは依存プロパティです
\r
1487 public System.Windows.Media.Color URL
\r
1489 get { return (System.Windows.Media.Color)GetValue(URLProperty); }
\r
1490 set { SetValue(URLProperty, value); }
\r
1494 /// URLの依存プロパティを表す
\r
1496 public static readonly DependencyProperty URLProperty =
\r
1497 DependencyProperty.Register("URL", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
\r
1503 public System.Windows.Media.Color LineMarker
\r
1505 get { return (System.Windows.Media.Color)GetValue(LineMarkerProperty); }
\r
1506 set { SetValue(LineMarkerProperty, value); }
\r
1510 /// LineMarkerの依存プロパティを表す
\r
1512 public static readonly DependencyProperty LineMarkerProperty =
\r
1513 DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));
\r
1516 /// 挿入モード時のキャレットの色を表す
\r
1518 public System.Windows.Media.Color InsertCaret
\r
1520 get { return (System.Windows.Media.Color)GetValue(InsertCaretProperty); }
\r
1521 set { SetValue(InsertCaretProperty, value); }
\r
1525 /// InsertCaretの依存プロパティを表す
\r
1527 public static readonly DependencyProperty InsertCaretProperty =
\r
1528 DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
\r
1533 public System.Windows.Media.Color UpdateArea
\r
1535 get { return (System.Windows.Media.Color)GetValue(UpdateAreaProperty); }
\r
1536 set { SetValue(UpdateAreaProperty, value); }
\r
1540 /// UpdateAreaの依存プロパティを表す
\r
1542 public static readonly DependencyProperty UpdateAreaProperty =
\r
1543 DependencyProperty.Register("UpdateArea", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));
\r
1546 /// 上書きモード時のキャレット職を表す
\r
1548 public System.Windows.Media.Color OverwriteCaret
\r
1550 get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }
\r
1551 set { SetValue(OverwriteCaretProperty, value); }
\r
1555 /// OverwriteCaretの依存プロパティを表す
\r
1557 public static readonly DependencyProperty OverwriteCaretProperty =
\r
1558 DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
\r
1561 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
\r
1563 public bool InsertMode
\r
1565 get { return (bool)GetValue(InsertModeProperty); }
\r
1566 set { SetValue(InsertModeProperty, value); }
\r
1570 /// InsertModeの依存プロパティを表す
\r
1572 public static readonly DependencyProperty InsertModeProperty =
\r
1573 DependencyProperty.Register("InsertMode",
\r
1575 typeof(FooTextBox),
\r
1576 new FrameworkPropertyMetadata(true));
\r
1579 /// タブの文字数を表す。これは依存プロパティです
\r
1581 public int TabChars
\r
1583 get { return (int)GetValue(TabCharsProperty); }
\r
1584 set { SetValue(TabCharsProperty, value); }
\r
1588 /// TabCharsの依存プロパティを表す
\r
1590 public static readonly DependencyProperty TabCharsProperty =
\r
1591 DependencyProperty.Register("TabChars",
\r
1593 typeof(FooTextBox),
\r
1594 new FrameworkPropertyMetadata(4));
\r
1597 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
\r
1599 public bool RectSelectMode
\r
1601 get { return (bool)GetValue(RectSelectModeProperty); }
\r
1602 set { SetValue(RectSelectModeProperty, value); }
\r
1606 /// RectSelectModeの依存プロパティを表す
\r
1608 public static readonly DependencyProperty RectSelectModeProperty =
\r
1609 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1615 /// 変更した場合、レイアウトの再構築を行う必要があります
\r
1617 public LineBreakMethod LineBreakMethod
\r
1619 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
\r
1620 set { SetValue(LineBreakProperty, value); }
\r
1624 /// LineBreakMethodの依存プロパティを表す
\r
1626 public static readonly DependencyProperty LineBreakProperty =
\r
1627 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None));
\r
1631 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
\r
1634 /// 変更した場合、レイアウトの再構築を行う必要があります
\r
1636 public int LineBreakCharCount
\r
1638 get { return (int)GetValue(LineBreakCharCountProperty); }
\r
1639 set { SetValue(LineBreakCharCountProperty, value); }
\r
1643 /// LineBreakCharCountの依存プロパティを表す
\r
1645 public static readonly DependencyProperty LineBreakCharCountProperty =
\r
1646 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
\r
1649 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
\r
1651 public bool DrawCaret
\r
1653 get { return (bool)GetValue(DrawCaretProperty); }
\r
1654 set { SetValue(DrawCaretProperty, value); }
\r
1658 /// DrawCaretの依存プロパティを表す
\r
1660 public static readonly DependencyProperty DrawCaretProperty =
\r
1661 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
\r
1665 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
\r
1667 public bool DrawCaretLine
\r
1669 get { return (bool)GetValue(DrawCaretLineProperty); }
\r
1670 set { SetValue(DrawCaretLineProperty, value); }
\r
1674 /// DrawCaretLineの依存プロパティを表す
\r
1676 public static readonly DependencyProperty DrawCaretLineProperty =
\r
1677 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1680 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
\r
1682 public bool DrawLineNumber
\r
1684 get { return (bool)GetValue(DrawLineNumberProperty); }
\r
1685 set { SetValue(DrawLineNumberProperty, value); }
\r
1689 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
\r
1691 public bool DrawRuler
\r
1693 get { return (bool)GetValue(DrawRulerProperty); }
\r
1694 set { SetValue(DrawRulerProperty, value); }
\r
1698 /// DrawRulerの依存プロパティを表す
\r
1700 public static readonly DependencyProperty DrawRulerProperty =
\r
1701 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
\r
1705 /// DrawLineNumberの依存プロパティを表す
\r
1707 public static readonly DependencyProperty DrawLineNumberProperty =
\r
1708 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1711 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
\r
1713 public bool MarkURL
\r
1715 get { return (bool)GetValue(MarkURLProperty); }
\r
1716 set { SetValue(MarkURLProperty, value); }
\r
1720 /// MarkURLの依存プロパティを表す
\r
1722 public static readonly DependencyProperty MarkURLProperty =
\r
1723 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1726 /// 全角スペースを表示するなら真。そうでないなら偽
\r
1728 public bool ShowFullSpace
\r
1730 get { return (bool)GetValue(ShowFullSpaceProperty); }
\r
1731 set { SetValue(ShowFullSpaceProperty, value); }
\r
1735 /// ShowFullSpaceの依存プロパティを表す
\r
1737 public static readonly DependencyProperty ShowFullSpaceProperty =
\r
1738 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
\r
1741 /// 半角スペースを表示するなら真。そうでないなら偽
\r
1743 public bool ShowHalfSpace
\r
1745 get { return (bool)GetValue(ShowHalfSpaceProperty); }
\r
1746 set { SetValue(ShowHalfSpaceProperty, value); }
\r
1750 /// ShowHalfSpaceの依存プロパティを表す
\r
1752 public static readonly DependencyProperty ShowHalfSpaceProperty =
\r
1753 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
\r
1756 /// タブを表示するなら真。そうでないなら偽
\r
1758 public bool ShowTab
\r
1760 get { return (bool)GetValue(ShowTabProperty); }
\r
1761 set { SetValue(ShowTabProperty, value); }
\r
1765 /// ShowTabの依存プロパティを表す
\r
1767 public static readonly DependencyProperty ShowTabProperty =
\r
1768 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
\r
1771 /// 改行マークを表示するなら真。そうでないなら偽
\r
1773 public bool ShowLineBreak
\r
1775 get { return (bool)GetValue(ShowLineBreakProperty); }
\r
1776 set { SetValue(ShowLineBreakProperty, value); }
\r
1780 /// ShowLineBreakの依存プロパティを表す
\r
1782 public static readonly DependencyProperty ShowLineBreakProperty =
\r
1783 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
\r
1788 /// マウスボタン関連のイベントクラス
\r
1790 public sealed class FooMouseButtonEventArgs : MouseButtonEventArgs
\r
1793 /// イベントが発生したドキュメントのインデックス
\r
1804 /// <param name="mouse">マウスデバイス</param>
\r
1805 /// <param name="timestamp">タイムスタンプ</param>
\r
1806 /// <param name="button">ボタン</param>
\r
1807 /// <param name="stylusDevice">スタイラスデバイス</param>
\r
1808 /// <param name="index">インデックス</param>
\r
1809 public FooMouseButtonEventArgs(MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice, int index)
\r
1810 : base(mouse, timestamp, button, stylusDevice)
\r
1812 this.Index = index;
\r
1818 public sealed class FooMouseEventArgs : MouseEventArgs
\r
1821 /// イベントが発生したドキュメントのインデックス
\r
1832 /// <param name="mouse">マウスデバイス</param>
\r
1833 /// <param name="timestamp">タイムスタンプ</param>
\r
1834 /// <param name="stylusDevice">スタイラスデバイス</param>
\r
1835 /// <param name="index">インデックス</param>
\r
1836 public FooMouseEventArgs(MouseDevice mouse,
\r
1838 StylusDevice stylusDevice,
\r
1840 : base(mouse, timestamp, stylusDevice)
\r
1842 this.Index = index;
\r