OSDN Git Service

MVVM対応に備えてシンボル系列のプロパティもDocumentに移行した
[fooeditengine/FooEditEngine.git] / WPF / FooEditEngine / FooTextBox.cs
1 /*
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.
5
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.
8
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/>.
10  */
11 using System;
12 using System.Text;
13 using System.Threading.Tasks;
14 using System.Runtime.InteropServices;
15 using System.Windows;
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;
27
28 namespace FooEditEngine.WPF
29 {
30     /// <summary>
31     /// オートインデントを行うためのデリゲートを表す
32     /// </summary>
33     /// <param name="sender">イベント発生元のオブジェクト</param>
34     /// <param name="e">イベントデーター</param>
35     public delegate void AutoIndentHookerHandler(object sender,EventArgs e);
36
37     /// <summary>
38     /// WPFでのFooTextBoxの実装
39     /// </summary>
40     public sealed class FooTextBox : Control, IDisposable
41     {
42         const double MaxFontSize = 72.0f;
43         const double MinFontSize = 1;
44
45         EditView View;
46         Controller _Controller;
47         D2DRender Render;
48         Image image;
49         ScrollBar verticalScrollBar, horizontalScrollBar;
50         TextStore textStore;
51         DispatcherTimer timer;
52         bool disposed = false;
53         FooTextBoxAutomationPeer peer;
54         bool nowCaretMove = false;
55         
56         static FooTextBox()
57         {
58             DefaultStyleKeyProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(typeof(FooTextBox)));
59             KeyboardNavigation.IsTabStopProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(true));
60             KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(KeyboardNavigationMode.None));
61         }
62
63         /// <summary>
64         /// コンストラクター
65         /// </summary>
66         public FooTextBox()
67         {
68             this.image = new Image();
69             this.image.Stretch = Stretch.Fill;
70             this.image.HorizontalAlignment = HorizontalAlignment.Left;
71             this.image.VerticalAlignment = VerticalAlignment.Top;
72
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;
87
88             this.Render = new D2DRender(this, 200, 200,this.image);
89             this.Render.ShowFullSpace = this.ShowFullSpace;
90             this.Render.ShowHalfSpace = this.ShowHalfSpace;
91             this.Render.ShowTab = this.ShowTab;
92
93             this.Document = new Document();
94             this.Document.LayoutLines.Render = this.Render;
95
96             this.View = new EditView(this.Document, this.Render, new Padding(5, 5, 5, 5));
97             this.View.SrcChanged += View_SrcChanged;
98             this.View.InsertMode = this.InsertMode;
99             this.Document.DrawLineNumber = this.DrawLineNumber;
100             this.View.HideCaret = !this.DrawCaret;
101             this.View.HideLineMarker = !this.DrawCaretLine;
102             this.Document.HideRuler = !this.DrawRuler;
103             this.Document.UrlMark = this.MarkURL;
104             this.Document.TabStops = this.TabChars;
105
106             this._Controller = new Controller(this.Document, this.View);
107             this._Controller.SelectionChanged += new EventHandler(Controller_SelectionChanged);
108
109             //Viewを作成した後に追加しないと例外が発生する
110             this.Document.Update += new DocumentUpdateEventHandler(Document_Update);
111
112             this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, CopyCommand, CanExecute));
113             this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, CutCommand, CanExecute));
114             this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, PasteCommand, CanExecute));
115             this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, DeleteCommand, CanExecute));
116             this.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, SelectAllCommand, CanExecute));
117             this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, UndoCommand, CanExecute));
118             this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, RedoCommand, CanExecute));
119             this.CommandBindings.Add(new CommandBinding(EditingCommands.ToggleInsert, ToggleInsertCommand, CanExecute));
120             this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleRectSelectMode, ToggleRectSelectCommand, CanExecute));
121             this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleFlowDirection, ToggleFlowDirectionCommand, CanExecute));
122             this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleCodePoint, ToggleCodePointCommand, CanExecute));
123
124             this.InputBindings.Add(new InputBinding(ApplicationCommands.Copy, new KeyGesture(Key.C, ModifierKeys.Control)));
125             this.InputBindings.Add(new InputBinding(ApplicationCommands.Cut, new KeyGesture(Key.X, ModifierKeys.Control)));
126             this.InputBindings.Add(new InputBinding(ApplicationCommands.Paste, new KeyGesture(Key.V, ModifierKeys.Control)));
127             this.InputBindings.Add(new InputBinding(ApplicationCommands.Delete, new KeyGesture(Key.Delete, ModifierKeys.None)));
128             this.InputBindings.Add(new InputBinding(ApplicationCommands.SelectAll, new KeyGesture(Key.A, ModifierKeys.Control)));
129             this.InputBindings.Add(new InputBinding(ApplicationCommands.Undo, new KeyGesture(Key.Z, ModifierKeys.Control)));
130             this.InputBindings.Add(new InputBinding(ApplicationCommands.Redo, new KeyGesture(Key.Y, ModifierKeys.Control)));
131             this.InputBindings.Add(new InputBinding(EditingCommands.ToggleInsert, new KeyGesture(Key.Insert, ModifierKeys.None)));
132             this.InputBindings.Add(new InputBinding(FooTextBoxCommands.ToggleCodePoint, new KeyGesture(Key.X, ModifierKeys.Alt)));
133
134             this.timer = new DispatcherTimer();
135             this.timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
136             this.timer.Tick += new EventHandler(timer_Tick);
137
138             this.Loaded += new RoutedEventHandler(FooTextBox_Loaded);
139
140             this.AutoIndentHooker = (s,e)=>{};
141
142             SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
143
144             this.SystemEvents_UserPreferenceChanged(null, new UserPreferenceChangedEventArgs(UserPreferenceCategory.Keyboard));
145
146             this.CaretMoved += (s, e) => { };
147         }
148
149         /// <summary>
150         /// ファイナライザー
151         /// </summary>
152         ~FooTextBox()
153         {
154             //Dispose(false)を呼び出すと落ちる
155             this.Dispose(false);
156         }
157
158         /// <summary>
159         /// オートインデントを行うためのイベント
160         /// </summary>
161         public AutoIndentHookerHandler AutoIndentHooker;
162
163         /// <summary>
164         /// テンプレートを適用します
165         /// </summary>
166         public override void OnApplyTemplate()
167         {
168             base.OnApplyTemplate();
169
170             Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
171             if (grid != null)
172             {
173                 Grid.SetRow(this.image, 0);
174                 Grid.SetColumn(this.image, 0);
175                 grid.Children.Add(this.image);
176             }
177
178             this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
179             if (this.horizontalScrollBar != null)
180             {
181                 this.horizontalScrollBar.SmallChange = 10;
182                 this.horizontalScrollBar.LargeChange = 100;
183                 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
184                 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
185             }
186             this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
187             if (this.verticalScrollBar != null)
188             {
189                 this.verticalScrollBar.SmallChange = 1;
190                 this.verticalScrollBar.LargeChange = 10;
191                 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
192                 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
193             }
194         }
195
196         /// <summary>
197         /// ドキュメントを選択する
198         /// </summary>
199         /// <param name="start">開始インデックス</param>
200         /// <param name="length">長さ</param>
201         public void Select(int start, int length)
202         {
203             this._Controller.Select(start, length);
204             this.textStore.NotifySelectionChanged();
205         }
206
207         /// <summary>
208         /// キャレットを指定した行に移動させます
209         /// </summary>
210         /// <param name="index">インデックス</param>
211         /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
212         public void JumpCaret(int index)
213         {
214             this._Controller.JumpCaret(index);
215         }
216         /// <summary>
217         /// キャレットを指定した行と桁に移動させます
218         /// </summary>
219         /// <param name="row">行番号</param>
220         /// <param name="col">桁</param>
221         /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
222         public void JumpCaret(int row, int col)
223         {
224             this._Controller.JumpCaret(row, col);
225         }
226
227         /// <summary>
228         /// 選択中のテキストをクリップボードにコピーします
229         /// </summary>
230         public void Copy()
231         {
232             string text = this._Controller.SelectedText;
233             if (text != null && text != string.Empty)
234                 Clipboard.SetText(text);
235         }
236
237         /// <summary>
238         /// 選択中のテキストをクリップボードに切り取ります
239         /// </summary>
240         public void Cut()
241         {
242             string text = this._Controller.SelectedText;
243             if (text != null && text != string.Empty)
244             {
245                 Clipboard.SetText(text);
246                 this._Controller.SelectedText = "";
247             }
248         }
249
250         /// <summary>
251         /// 選択中のテキストを貼り付けます
252         /// </summary>
253         public void Paste()
254         {
255             if (Clipboard.ContainsText() == false)
256                 return;
257             string text = Clipboard.GetText();
258             this._Controller.SelectedText = text;
259         }
260
261         /// <summary>
262         /// 選択を解除する
263         /// </summary>
264         public void DeSelectAll()
265         {
266             this._Controller.DeSelectAll();
267             this.textStore.NotifySelectionChanged();
268         }
269
270         /// <summary>
271         /// 対応する座標を返します
272         /// </summary>
273         /// <param name="tp">テキストポイント</param>
274         /// <returns>座標</returns>
275         /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
276         public System.Windows.Point GetPostionFromTextPoint(TextPoint tp)
277         {
278             if (this.Document.FireUpdateEvent == false)
279                 throw new InvalidOperationException("");
280             return this.View.GetPostionFromTextPoint(tp);
281         }
282
283         /// <summary>
284         /// 対応するテキストポイントを返します
285         /// </summary>
286         /// <param name="p">クライアント領域の原点を左上とする座標</param>
287         /// <returns>テキストポイント</returns>
288         public TextPoint GetTextPointFromPostion(System.Windows.Point p)
289         {
290             if (this.Document.FireUpdateEvent == false)
291                 throw new InvalidOperationException("");
292             return this.View.GetTextPointFromPostion(p);
293         }
294
295         /// <summary>
296         /// 行の高さを取得します
297         /// </summary>
298         /// <param name="row">レイアウト行</param>
299         /// <returns>行の高さ</returns>
300         public double GetLineHeight(int row)
301         {
302             if (this.Document.FireUpdateEvent == false)
303                 throw new InvalidOperationException("");
304             return this.View.LayoutLines.GetLayout(row).Height;;
305         }
306
307         /// <summary>
308         /// インデックスに対応する座標を得ます
309         /// </summary>
310         /// <param name="index">インデックス</param>
311         /// <returns>座標を返す</returns>
312         public System.Windows.Point GetPostionFromIndex(int index)
313         {
314             if (this.Document.FireUpdateEvent == false)
315                 throw new InvalidOperationException("");
316             TextPoint tp = this.View.GetLayoutLineFromIndex(index);
317             return this.View.GetPostionFromTextPoint(tp);
318         }
319
320         /// <summary>
321         /// 座標からインデックスに変換します
322         /// </summary>
323         /// <param name="p">座標</param>
324         /// <returns>インデックスを返す</returns>
325         public int GetIndexFromPostion(System.Windows.Point p)
326         {
327             if (this.Document.FireUpdateEvent == false)
328                 throw new InvalidOperationException("");
329             TextPoint tp = this.View.GetTextPointFromPostion(p);
330             return this.View.GetIndexFromLayoutLine(tp);
331         }
332
333         /// <summary>
334         /// 再描写する
335         /// </summary>
336         public void Refresh()
337         {
338             this.Refresh(this.View.PageBound);
339         }
340
341         /// <summary>
342         /// レイアウト行をすべて破棄し、再度レイアウトを行う
343         /// </summary>
344         public void PerfomLayouts()
345         {
346             this.View.PerfomLayouts();
347         }
348
349         /// <summary>
350         /// 指定行までスクロールする
351         /// </summary>
352         /// <param name="row">行</param>
353         /// <param name="alignTop">指定行を画面上に置くなら真。そうでないなら偽</param>
354         public void ScrollIntoView(int row, bool alignTop)
355         {
356             this.View.ScrollIntoView(row, alignTop);
357         }
358
359         /// <summary>
360         /// ストリームからドキュメントを構築する
361         /// </summary>
362         /// <param name="tr">TextReader</param>
363         /// <param name="token">キャンセル用トークン</param>
364         /// <returns>Taskオブジェクト</returns>
365         public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)
366         {
367             WinFileReader fs = new WinFileReader(tr);
368             await this.LoadAsyncImpl(fs, token);
369         }
370
371         /// <summary>
372         /// ファイルからドキュメントを構築する
373         /// </summary>
374         /// <param name="filepath">ファイルパス</param>
375         /// <param name="enc">エンコード</param>
376         /// <param name="token">キャンセル用トークン</param>
377         /// <returns>Taskオブジェクト</returns>
378         public async Task LoadFileAsync(string filepath, Encoding enc,System.Threading.CancellationTokenSource token)
379         {
380             WinFileReader fs = new WinFileReader(filepath, enc);
381             await this.LoadAsyncImpl(fs, token);
382             fs.Close();
383         }
384
385         async Task LoadAsyncImpl(WinFileReader fs,System.Threading.CancellationTokenSource token)
386         {
387             this.IsEnabled = false;
388             this.View.LayoutLines.IsFrozneDirtyFlag = true;
389             await this.Document.LoadAsync(fs, token);
390             this.View.LayoutLines.IsFrozneDirtyFlag = false;
391             TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
392             if (this.verticalScrollBar != null)
393                 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
394             this.View.CalculateLineCountOnScreen();
395             this.IsEnabled = true;
396         }
397
398         /// <summary>
399         /// ドキュメントの内容をファイルに保存する
400         /// </summary>
401         /// <param name="filepath">ファイルパス</param>
402         /// <param name="newLine">改行コード</param>
403         /// <param name="enc">エンコード</param>
404         /// <returns>Taskオブジェクト</returns>
405         public async Task SaveFile(string filepath, Encoding enc,string newLine, System.Threading.CancellationTokenSource token)
406         {
407             WinFileWriter fs = new WinFileWriter(filepath, enc);
408             fs.NewLine = newLine;
409             await this.Document.SaveAsync(fs, token);
410             fs.Close();
411         }
412
413         /// <summary>
414         /// アンマネージドリソースを開放する
415         /// </summary>
416         public void Dispose()
417         {
418             if (this.disposed)
419                 return;
420             this.Dispose(true);
421             GC.SuppressFinalize(this);
422             this.disposed = true;
423         }
424
425         /// <summary>
426         /// リソースを開放する
427         /// </summary>
428         /// <param name="disposing">真ならマネージドリソースも開放し、そうでないならアンマネージドリソースのみを開放する</param>
429         void Dispose(bool disposing)
430         {
431             if (disposing)
432             {
433                 this.textStore.Dispose();
434                 this.timer.Stop();
435                 this.View.Dispose();
436                 this.Render.Dispose();
437             }
438             SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
439         }
440         
441         void Refresh(Rectangle updateRect)
442         {
443             if (this.disposed || this.Visibility == Visibility.Collapsed)
444                 return;
445
446             this.Render.BegineDraw();
447             if (this.IsEnabled)
448                 this.View.Draw(updateRect);
449             else
450                 this.Render.FillBackground(updateRect);
451             this.Render.EndDraw();
452         }
453
454         #region Commands
455         void CanExecute(object sender, CanExecuteRoutedEventArgs e)
456         {
457             e.CanExecute = this.IsEnabled;
458         }
459
460         void ToggleCodePointCommand(object sender, RoutedEventArgs e)
461         {
462             if (!this._Controller.ConvertToChar())
463                 this._Controller.ConvertToCodePoint();
464             this.Refresh();
465         }
466
467         void CopyCommand(object sender, RoutedEventArgs e)
468         {
469             this.Copy();
470         }
471
472         void CutCommand(object sender, RoutedEventArgs e)
473         {
474             this.Cut();
475             this.Refresh();
476         }
477
478         void PasteCommand(object sender, RoutedEventArgs e)
479         {
480             this.Paste();
481             this.Refresh();
482         }
483
484         void DeleteCommand(object sender, RoutedEventArgs e)
485         {
486             int oldLength = this.Document.Length;
487             this._Controller.DoDeleteAction();
488             this.Refresh();
489         }
490
491         void SelectAllCommand(object sender, RoutedEventArgs e)
492         {
493             this.Select(0, this.Document.Length);
494             this.Refresh();
495         }
496
497         void UndoCommand(object sender, RoutedEventArgs e)
498         {
499             int oldLength = this.Document.Length;
500             this.Document.UndoManager.undo();
501             this.Refresh();
502         }
503
504         void RedoCommand(object sender, RoutedEventArgs e)
505         {
506             int oldLength = this.Document.Length;
507             this.Document.UndoManager.redo();
508             this.Refresh();
509         }
510
511         void ToggleInsertCommand(object sender, RoutedEventArgs e)
512         {
513             if (this.InsertMode)
514                 this.InsertMode = false;
515             else
516                 this.InsertMode = true;
517             this.Refresh();
518         }
519
520         void ToggleRectSelectCommand(object sender, RoutedEventArgs e)
521         {
522             if (this.RectSelectMode)
523                 this.RectSelectMode = false;
524             else
525                 this.RectSelectMode = true;
526             this.Refresh();
527         }
528         void ToggleFlowDirectionCommand(object sender, RoutedEventArgs e)
529         {
530             if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
531                 this.FlowDirection = System.Windows.FlowDirection.RightToLeft;
532             else
533                 this.FlowDirection = System.Windows.FlowDirection.LeftToRight;
534             this.Refresh();
535         }
536         #endregion
537         #region TSF
538         internal TextStore TextStore
539         {
540             get { return this.textStore; }
541         }
542
543         bool textStore_IsReadOnly()
544         {
545             return false;
546         }
547
548         bool textStore_IsLoading()
549         {
550             return false;
551         }
552
553         void textStore_CompositionEnded()
554         {
555             TextStoreHelper.EndCompostion(this.Document);
556             this.Refresh();
557         }
558
559         void textStore_CompositionUpdated(int start, int end)
560         {
561             if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
562                 this.Refresh();
563         }
564         bool textStore_CompositionStarted()
565         {
566             bool result = TextStoreHelper.StartCompstion(this.Document);
567             if (!result)
568                 System.Media.SystemSounds.Beep.Play();
569             return result;
570         }
571
572         string _textStore_GetString(int start, int length)
573         {
574             return this.Document.ToString(start, length);
575         }
576
577         IntPtr _textStore_GetHWnd()
578         {
579             var hwndSource = HwndSource.FromVisual(this) as HwndSource;
580             if (hwndSource != null)
581                 return hwndSource.Handle;
582             else
583                 return IntPtr.Zero;
584         }
585
586         void _textStore_GetStringExtent(
587             int i_startIndex,
588             int i_endIndex,
589             out POINT o_topLeft,
590             out POINT o_bottomRight
591         )
592         {
593             Point startPos, endPos;
594             TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
595
596             double scale = this.Render.GetScale();
597             
598             startPos = PointToScreen(this.TranslatePoint(startPos.Scale(scale), this));
599             endPos = PointToScreen(this.TranslatePoint(endPos.Scale(scale), this));
600             
601             o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);
602             o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);
603         }
604
605         void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
606         {
607             var pointTopLeft = new Point(0, 0);
608             var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
609
610             pointTopLeft = PointToScreen(pointTopLeft);
611             pointBottomRight = PointToScreen(pointBottomRight);
612
613             o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
614             o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
615         }
616
617         void _textStore_GetSelectionIndex(out int o_startIndex, out int o_endIndex)
618         {
619             TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out o_startIndex, out o_endIndex);
620         }
621
622         void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)
623         {
624             TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);
625             this.Refresh();
626         }
627
628         void _textStore_InsertAtSelection(string i_value, ref int o_startIndex, ref int o_endIndex)
629         {
630             TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
631             this.Refresh();
632         }
633
634         /// <summary>
635         /// キーボードフォーカスが取得されたときに呼ばれます
636         /// </summary>
637         /// <param name="e">イベントデーター</param>
638         protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
639         {
640             base.OnGotKeyboardFocus(e);
641             this.textStore.SetFocus();
642             this.View.IsFocused = true;
643             this.Refresh();
644         }
645
646         /// <summary>
647         /// キーボードフォーカスが失われたときに呼ばれます
648         /// </summary>
649         /// <param name="e">イベントデーター</param>
650         protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
651         {
652             base.OnLostKeyboardFocus(e);
653             this.View.IsFocused = false;
654             this.Refresh();
655         }
656         #endregion
657         #region Event
658         /// <summary>
659         /// キャレットが移動したときに通知されるイベント
660         /// </summary>
661         public event EventHandler CaretMoved;
662
663         /// <inheritdoc/>
664         protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
665         {
666             this.peer = new FooTextBoxAutomationPeer(this);
667             return this.peer;
668         }
669
670
671         /// <inheritdoc/>
672         protected override void OnTextInput(TextCompositionEventArgs e)
673         {
674             if (e.Text == "\r")
675             {
676                 this._Controller.DoEnterAction();
677                 this.AutoIndentHooker(this, null);
678             }
679             else if (e.Text == "\b")
680             {
681                 this._Controller.DoBackSpaceAction();
682             }
683             else
684             {
685                 if(this.IsInputString(e.Text))
686                     this._Controller.DoInputString(e.Text);
687             }
688             this.Refresh();
689             base.OnTextInput(e);
690             e.Handled = true;
691         }
692
693         bool IsInputString(string s)
694         {
695             foreach (char charCode in s)
696             {
697                 if ((0x20 <= charCode && charCode <= 0x7e)
698                     || 0x7f < charCode)
699                     return true;
700             }
701             return false;
702         }
703
704         /// <inheritdoc/>
705         protected override void OnKeyDown(KeyEventArgs e)
706         {
707             if (this.textStore.IsLocked())
708                 return;
709
710             ModifierKeys modiferKeys = e.KeyboardDevice.Modifiers;
711             bool movedCaret = false;
712             switch (e.Key)
713             {
714                 case Key.Up:
715                     this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
716                     this.Refresh();
717                     e.Handled = true;
718                     movedCaret = true;
719                     break;
720                 case Key.Down:
721                     this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
722                     this.Refresh();
723                     e.Handled = true;
724                     movedCaret = true;
725                     break;
726                 case Key.Left:
727                     this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
728                     this.Refresh();
729                     e.Handled = true;
730                     movedCaret = true;
731                     break;
732                 case Key.Right:
733                     this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
734                     this.Refresh();
735                     e.Handled = true;
736                     movedCaret = true;
737                     break;
738                 case Key.PageUp:
739                     this._Controller.Scroll(ScrollDirection.Up,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
740                     this.Refresh();
741                     movedCaret = true;
742                     break;
743                 case Key.PageDown:
744                     this._Controller.Scroll(ScrollDirection.Down,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
745                     this.Refresh();
746                     movedCaret = true;
747                     break;
748                 case Key.Home:
749                     if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
750                         this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
751                     else
752                         this._Controller.JumpToLineHead(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
753                     this.Refresh();
754                     movedCaret = true;
755                     break;
756                 case Key.End:
757                     if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
758                         this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
759                     else
760                         this._Controller.JumpToLineEnd(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
761                     this.Refresh();
762                     movedCaret = true;
763                     break;
764                 case Key.Tab:
765                     int oldLength = this.Document.Length;
766                     if (this.Selection.Length == 0)
767                         this._Controller.DoInputChar('\t');
768                     else if(this.IsPressedModifierKey(modiferKeys,ModifierKeys.Shift))
769                         this._Controller.DownIndent();
770                     else
771                         this._Controller.UpIndent();
772                     this.Refresh();
773                     e.Handled = true;
774                     break;
775             }
776             if (movedCaret && this.peer != null)
777                 this.peer.OnNotifyCaretChanged();
778             base.OnKeyDown(e);
779         }
780
781         bool IsPressedModifierKey(ModifierKeys keys, ModifierKeys pressed)
782         {
783             if (keys == pressed)
784                 return true;
785             if ((keys & pressed) == pressed)
786                 return true;
787             return false;
788         }
789
790         /// <summary>
791         /// ダブルクリックされたときに呼ばれます
792         /// </summary>
793         /// <param name="e">イベントパラメーター</param>
794         /// <remarks>
795         /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
796         /// e.Handledを真にした場合、単語単位の選択が行われなくなります
797         /// </remarks>
798         protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
799         {
800             var p = this.GetDipFromPoint(e.GetPosition(this));
801             TextPoint tp = this.View.GetTextPointFromPostion(p);
802             if (tp == TextPoint.Null)
803                 return;
804             int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
805
806             FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
807                 e.Timestamp,
808                 e.ChangedButton,
809                 e.StylusDevice,
810                 index);
811             newEventArgs.RoutedEvent = e.RoutedEvent;
812             base.OnMouseDoubleClick(newEventArgs);
813
814             if (newEventArgs.Handled)
815                 return;
816
817             if (e.LeftButton == MouseButtonState.Pressed)
818             {
819
820                 this._Controller.SelectWord(index);
821                 this.textStore.NotifySelectionChanged();
822                 if(this.peer != null)
823                     this.peer.OnNotifyCaretChanged();
824                 this.Refresh();
825             }
826         }
827
828         /// <summary>
829         /// マウスボタンが押されたときに呼ばれます
830         /// </summary>
831         /// <param name="e">イベントパラメーター</param>
832         /// <remarks>
833         /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
834         /// e.Handledを真にした場合、キャレットの移動処理が行われなくなります
835         /// </remarks>
836         protected override void OnMouseDown(MouseButtonEventArgs e)
837         {
838             var p = this.GetDipFromPoint(e.GetPosition(this));
839             TextPoint tp = this.View.GetTextPointFromPostion(p);
840             if (tp == TextPoint.Null)
841                 return;
842             int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
843
844             FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
845                 e.Timestamp,
846                 e.ChangedButton,
847                 e.StylusDevice,
848                 index);
849             newEventArgs.RoutedEvent = e.RoutedEvent;
850             base.OnMouseDown(newEventArgs);
851
852             if (newEventArgs.Handled)
853                 return;
854
855             if (e.LeftButton == MouseButtonState.Pressed)
856             {
857                 FoldingItem foldingData = this.View.HitFoldingData(p.X,tp.row);
858                 if (foldingData != null)
859                 {
860                     if (foldingData.Expand)
861                         this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
862                     else
863                         this.View.LayoutLines.FoldingCollection.Expand(foldingData);
864                     this._Controller.JumpCaret(foldingData.Start,false);
865                 }
866                 else
867                 {
868                     this._Controller.JumpCaret(tp.row, tp.col, false);
869                 }
870                 if (this.peer != null)
871                     this.peer.OnNotifyCaretChanged();
872                 this.View.IsFocused = true;
873                 this.Focus();
874                 this.Refresh();
875             }
876         }
877
878         /// <summary>
879         /// マウスが移動したときに呼ばれます
880         /// </summary>
881         /// <param name="e">イベントパラメーター</param>
882         /// <remarks>
883         /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
884         /// e.Handledを真にした場合、選択処理と状況に応じたカーソルの変化が行われなくなります
885         /// </remarks>
886         protected override void  OnMouseMove(MouseEventArgs e)
887         {
888             var p = this.GetDipFromPoint(e.GetPosition(this));
889             TextPoint tp = this.View.GetTextPointFromPostion(p);
890             if (tp == TextPoint.Null)
891             {
892                 base.OnMouseMove(e);
893                 return;
894             }
895             int index = this.View.GetIndexFromLayoutLine(tp);
896
897             FooMouseEventArgs newEventArgs = new FooMouseEventArgs(e.MouseDevice, e.Timestamp, e.StylusDevice, index);
898             newEventArgs.RoutedEvent = e.RoutedEvent;
899             base.OnMouseMove(newEventArgs);
900
901             if (newEventArgs.Handled)
902                 return;
903
904             if (this.View.HitTextArea(p.X,p.Y))
905             {
906                 if (this._Controller.IsMarker(tp, HilightType.Url))
907                     this.Cursor = Cursors.Hand;
908                 else
909                     this.Cursor = Cursors.IBeam;
910
911                 if (e.LeftButton == MouseButtonState.Pressed)
912                 {
913                     this._Controller.MoveCaretAndSelect(tp);
914                     if (this.peer != null)
915                         this.peer.OnNotifyCaretChanged();
916                     this.Refresh();
917                 }
918             }
919             else
920             {
921                 this.Cursor = Cursors.Arrow;
922             }
923         }
924
925         private Point GetDipFromPoint(Point p)
926         {
927             float dpi;
928             this.Render.GetDpi(out dpi,out dpi);
929             double scale = dpi / 96.0;
930             return p.Scale(1 / scale);
931         }
932
933         /// <inheritdoc/>
934         protected override void OnMouseWheel(MouseWheelEventArgs e)
935         {
936             if(Keyboard.Modifiers == ModifierKeys.None)
937             {
938                 if (e.Delta > 0)
939                     this._Controller.Scroll(ScrollDirection.Up, SystemParameters.WheelScrollLines, false, false);
940                 else
941                     this._Controller.Scroll(ScrollDirection.Down, SystemParameters.WheelScrollLines, false, false);
942             }
943             else if (Keyboard.Modifiers == ModifierKeys.Control)
944             {
945                 double newFontSize = this.Render.FontSize;
946                 if (e.Delta > 0)
947                     newFontSize++;
948                 else
949                     newFontSize--;
950                 if (newFontSize > MaxFontSize)
951                     newFontSize = 72;
952                 else if (newFontSize < MinFontSize)
953                     newFontSize = 1;
954                 this.Render.FontSize = newFontSize;
955                 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
956             }
957             this.Refresh();
958             base.OnMouseWheel(e);
959         }
960
961         void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
962         {
963             if (e.Category == UserPreferenceCategory.Keyboard)
964             {
965                 int blinkTime = (int)NativeMethods.GetCaretBlinkTime();
966                 this.View.CaretBlink = blinkTime >= 0;
967                 this.View.CaretBlinkTime = blinkTime * 2;
968             }
969             if (e.Category == UserPreferenceCategory.General)
970             {
971                 this.View.CaretWidthOnInsertMode = SystemParameters.CaretWidth;
972             }
973         }
974
975         void Document_Update(object sender, DocumentUpdateEventArgs e)
976         {
977             if (this.textStore.IsLocked())
978                 return;
979             if(e.type == UpdateType.Replace)
980                 TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
981         }
982
983         void timer_Tick(object sender, EventArgs e)
984         {
985             if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)
986                 return;
987             if (this.Resize(this.image.ActualWidth, this.image.ActualHeight))
988             {
989                 this.Refresh();
990                 return;
991             }
992
993             bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding();
994
995             ITextLayout layout = this.View.LayoutLines.GetLayout(this.Document.CaretPostion.row);
996             double width = layout.GetWidthFromIndex(this.Document.CaretPostion.col);
997             if (width == 0.0)
998                 width = this.View.CaretWidthOnInsertMode;
999             double height = layout.Height;
1000             Rectangle updateRect = new Rectangle(
1001                 this.View.CaretLocation.X,
1002                 this.View.CaretLocation.Y,
1003                 width,
1004                 height);
1005
1006             if (updateAll)
1007                 this.Refresh();
1008             else
1009                 this.Refresh(updateRect);
1010         }
1011
1012         void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
1013         {
1014             if (this.horizontalScrollBar == null)
1015                 return;
1016             double toX;
1017             if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
1018                 toX = this.horizontalScrollBar.Value;
1019             else
1020                 toX = -this.horizontalScrollBar.Value;
1021             this._Controller.Scroll(toX, this.View.Src.Row, false, false);
1022             this.Refresh();
1023         }
1024
1025         void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
1026         {
1027             if (this.verticalScrollBar == null)
1028                 return;
1029             int newRow = (int)this.verticalScrollBar.Value;
1030             if (newRow >= this.View.LayoutLines.Count)
1031                 return;
1032             this._Controller.Scroll(this.View.Src.X,newRow, false, false);
1033             this.Refresh();
1034         }
1035
1036         void View_SrcChanged(object sender, EventArgs e)
1037         {
1038             if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
1039                 return;
1040             EditView view = this.View;
1041             if (view.Src.Row > this.verticalScrollBar.Maximum)
1042                 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
1043             double absoulteX = Math.Abs(view.Src.X);
1044             if(absoulteX > this.horizontalScrollBar.Maximum)
1045                 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
1046             if(view.Src.Row != this.verticalScrollBar.Value)
1047                 this.verticalScrollBar.Value = view.Src.Row;
1048             if (view.Src.X != this.horizontalScrollBar.Value)
1049                 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
1050         }
1051
1052         void Controller_SelectionChanged(object sender, EventArgs e)
1053         {
1054             this.View.CaretBlink = this.View.CaretBlink;
1055             this.CaretMoved(this, null);
1056             //こうしないと選択できなくなってしまう
1057             this.nowCaretMove = true;
1058             SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
1059             SetValue(CaretPostionProperty, this.Document.CaretPostion);
1060             this.nowCaretMove = false;            
1061             if(this.textStore.IsLocked() == false)
1062                 this.textStore.NotifySelectionChanged();
1063         }
1064
1065         void FooTextBox_Loaded(object sender, RoutedEventArgs e)
1066         {
1067             this.Resize(this.image.ActualWidth, this.image.ActualHeight);
1068             this.Focus();
1069             this.timer.Start();
1070         }
1071
1072         bool Resize(double width, double height)
1073         {
1074             if (width == 0 || height == 0)
1075                 throw new ArgumentOutOfRangeException();
1076             if (this.Render.Resize(width, height))
1077             {
1078                 double scale = this.Render.GetScale();
1079                 // RenderはレタリングはDIPだが、widthとheightの値はDPI依存なのでDIPに変換する
1080                 this.View.PageBound = new Rectangle(0, 0, width / scale, height / scale);
1081
1082                 if (this.horizontalScrollBar != null)
1083                 {
1084                     this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
1085                     this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
1086                 }
1087                 if (this.verticalScrollBar != null)
1088                 {
1089                     this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
1090                     this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
1091                 }
1092                 return true;
1093             }
1094             return false;
1095         }
1096
1097         /// <summary>
1098         /// プロパティーが変更されたときに呼ばれます
1099         /// </summary>
1100         /// <param name="e">イベントパラメーター</param>
1101         protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
1102         {
1103             switch (e.Property.Name)
1104             {
1105                 case "IndentMode":
1106                     this._Controller.IndentMode = this.IndentMode;
1107                     break;
1108                 case "Selection":
1109                     if(!this.nowCaretMove)
1110                         this.Select(this.Selection.Index, this.Selection.Length);
1111                     break;
1112                 case "CaretPostion":
1113                     if (!this.nowCaretMove)
1114                         this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
1115                     break;
1116                 case "LineBreakMethod":
1117                     this.Document.LineBreak = this.LineBreakMethod;
1118                     break;
1119                 case "LineBreakCharCount":
1120                     this.Document.LineBreakCharCount = this.LineBreakCharCount;
1121                     break;
1122                 case "InsertMode":
1123                     this.View.InsertMode = this.InsertMode;
1124                     break;
1125                 case "TabChars":
1126                     this.Document.TabStops = this.TabChars;
1127                     break;
1128                 case "RectSelectMode":
1129                     this._Controller.RectSelection = this.RectSelectMode;
1130                     break;
1131                 case "DrawCaret":
1132                     this.View.HideCaret = !this.DrawCaret;
1133                     break;
1134                 case "DrawCaretLine":
1135                     this.View.HideLineMarker = !this.DrawCaretLine;
1136                     break;
1137                 case "DrawLineNumber":
1138                     this.Document.DrawLineNumber = this.DrawLineNumber;
1139                     this._Controller.JumpCaret(this.Document.CaretPostion.row, this.Document.CaretPostion.col);
1140                     break;
1141                 case "FontFamily":
1142                     this.Render.FontFamily = this.FontFamily;
1143                     break;
1144                 case "FontSize":
1145                     this.Render.FontSize = this.FontSize;
1146                     break;
1147                 case "FontStyle":
1148                     this.Render.FontStyle = this.FontStyle;
1149                     break;
1150                 case "FontWeight":
1151                     this.Render.FontWeigth = this.FontWeight;
1152                     break;
1153                 case "Foreground":
1154                     this.Render.Foreground = D2DRender.ToColor4(this.Foreground);
1155                     break;
1156                 case "Background":
1157                     this.Render.Background = D2DRender.ToColor4(this.Background);
1158                     break;
1159                 case "ControlChar":
1160                     this.Render.ControlChar =D2DRender.ToColor4( this.ControlChar);
1161                     break;
1162                 case "Hilight":
1163                     this.Render.Hilight = D2DRender.ToColor4(this.Hilight);
1164                     break;
1165                 case "Keyword1":
1166                     this.Render.Keyword1 = D2DRender.ToColor4(this.Keyword1);
1167                     break;
1168                 case "Keyword2":
1169                     this.Render.Keyword2 = D2DRender.ToColor4(this.Keyword2);
1170                     break;
1171                 case "Comment":
1172                     this.Render.Comment = D2DRender.ToColor4(this.Comment);
1173                     break;
1174                 case "Literal":
1175                     this.Render.Literal = D2DRender.ToColor4(this.Literal);
1176                     break;
1177                 case "URL":
1178                     this.Render.Url = D2DRender.ToColor4(this.URL);
1179                     break;
1180                 case "InsertCaret":
1181                     this.Render.InsertCaret = D2DRender.ToColor4(this.InsertCaret);
1182                     break;
1183                 case "OverwriteCaret":
1184                     this.Render.OverwriteCaret = D2DRender.ToColor4(this.OverwriteCaret);
1185                     break;
1186                 case "Padding":
1187                     this.View.Padding = new Padding((int)this.Padding.Left, (int)this.Padding.Top, (int)this.Padding.Right, (int)this.Padding.Bottom);
1188                     break;
1189                 case "LineMarker":
1190                     this.Render.LineMarker = D2DRender.ToColor4(this.LineMarker);
1191                     break;
1192                 case "MarkURL":
1193                     this.Document.UrlMark = this.MarkURL;
1194                     break;
1195                 case "ShowFullSpace":
1196                     this.Document.ShowFullSpace = this.ShowFullSpace;
1197                     break;
1198                 case "ShowHalfSpace":
1199                     this.Document.ShowHalfSpace = this.ShowHalfSpace;
1200                     break;
1201                 case "ShowTab":
1202                     this.Document.ShowTab = this.ShowTab;
1203                     break;
1204                 case "ShowLineBreak":
1205                     this.Document.ShowLineBreak = this.ShowLineBreak;
1206                     break;
1207                 case "FlowDirection":
1208                     this.Document.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;
1209                     this.horizontalScrollBar.FlowDirection = this.FlowDirection;
1210                     break;
1211                 case "DrawRuler":
1212                     this.Document.HideRuler = !this.DrawRuler;
1213                     this._Controller.JumpCaret(this.Document.CaretPostion.row, this.Document.CaretPostion.col);
1214                     break;
1215                 case "UpdateArea":
1216                     this.Render.UpdateArea = D2DRender.ToColor4(this.UpdateArea);
1217                     break;
1218                 case "LineNumber":
1219                     this.Render.LineNumber = D2DRender.ToColor4(this.LineNumber);
1220                     break;
1221             }
1222             base.OnPropertyChanged(e);
1223         }
1224         #endregion
1225         #region property
1226
1227         internal Controller Controller
1228         {
1229             get
1230             {
1231                 return this._Controller;
1232             }
1233         }
1234
1235         /// <summary>
1236         /// 文字列の描写に使用されるアンチエイリアシング モードを表します
1237         /// </summary>
1238         public TextAntialiasMode TextAntialiasMode
1239         {
1240             get
1241             {
1242                 return this.Render.TextAntialiasMode;
1243             }
1244             set
1245             {
1246                 this.Render.TextAntialiasMode = value;
1247             }
1248         }
1249
1250         /// <summary>
1251         /// シンタックスハイライターを表す
1252         /// </summary>
1253         public IHilighter Hilighter
1254         {
1255             get
1256             {
1257                 return this.View.Hilighter;
1258             }
1259             set
1260             {
1261                 this.View.Hilighter = value;
1262                 this.View.LayoutLines.ClearLayoutCache();
1263             }
1264         }
1265
1266         /// <summary>
1267         /// フォールティングを作成するインターフェイスを表す
1268         /// </summary>
1269         public IFoldingStrategy FoldingStrategy
1270         {
1271             get
1272             {
1273                 return this.View.LayoutLines.FoldingStrategy;
1274             }
1275             set
1276             {
1277                 this.View.LayoutLines.FoldingStrategy = value;
1278                 if (value == null)
1279                     this.View.LayoutLines.FoldingCollection.Clear();
1280             }
1281         }
1282
1283         /// <summary>
1284         /// マーカーパターンセット
1285         /// </summary>
1286         public MarkerPatternSet MarkerPatternSet
1287         {
1288             get
1289             {
1290                 return this.Document.MarkerPatternSet;
1291             }
1292         }
1293
1294         /// <summary>
1295         /// ドキュメントを表す
1296         /// </summary>
1297         public Document Document
1298         {
1299             get;
1300             private set;
1301         }
1302
1303         /// <summary>
1304         /// レイアウト行を表す
1305         /// </summary>
1306         public LineToIndexTable LayoutLineCollection
1307         {
1308             get { return this.View.LayoutLines; }
1309         }
1310
1311         /// <summary>
1312         /// 選択中の文字列を表す
1313         /// </summary>
1314         public string SelectedText
1315         {
1316             get
1317             {
1318                 return this._Controller.SelectedText;
1319             }
1320             set
1321             {
1322                 int oldLength = this.Document.Length;
1323                 this._Controller.SelectedText = value;
1324             }
1325         }
1326
1327         /// <summary>
1328         /// インデントの方法を表す
1329         /// </summary>
1330         public IndentMode IndentMode
1331         {
1332             get { return (IndentMode)GetValue(IndentModeProperty); }
1333             set { SetValue(IndentModeProperty, value); }
1334         }
1335
1336         /// <summary>
1337         /// IndentModeの依存プロパティを表す
1338         /// </summary>
1339         public static readonly DependencyProperty IndentModeProperty =
1340             DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab));
1341
1342         /// <summary>
1343         /// 選択範囲を表す
1344         /// </summary>
1345         /// <remarks>
1346         /// Lengthが0の場合はキャレット位置を表します。
1347         /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
1348         /// </remarks>
1349         public TextRange Selection
1350         {
1351             get { return (TextRange)GetValue(SelectionProperty); }
1352             set { SetValue(SelectionProperty, value); }
1353         }
1354
1355         /// <summary>
1356         /// Selectionの依存プロパティを表す
1357         /// </summary>
1358         public static readonly DependencyProperty SelectionProperty =
1359             DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null));
1360
1361         /// <summary>
1362         /// 拡大率を表す
1363         /// </summary>
1364         public double MagnificationPower
1365         {
1366             get { return (double)GetValue(MagnificationPowerPropertyKey.DependencyProperty); }
1367         }
1368
1369         /// <summary>
1370         /// 拡大率を表す依存プロパティ
1371         /// </summary>
1372         public static readonly DependencyPropertyKey MagnificationPowerPropertyKey =
1373             DependencyProperty.RegisterReadOnly("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0));
1374
1375         /// <summary>
1376         /// レタリング方向を表す
1377         /// </summary>
1378         public new FlowDirection FlowDirection
1379         {
1380             get { return (FlowDirection)GetValue(FlowDirectionProperty); }
1381             set { SetValue(FlowDirectionProperty, value); }
1382         }
1383
1384         /// <summary>
1385         /// レタリング方向を表す。これは依存プロパティです
1386         /// </summary>
1387         public new static readonly DependencyProperty FlowDirectionProperty =
1388             DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight));        
1389
1390         /// <summary>
1391         /// キャレット位置を表す。これは依存プロパティです
1392         /// </summary>
1393         public TextPoint CaretPostion
1394         {
1395             get { return (TextPoint)GetValue(CaretPostionProperty); }
1396             set { SetValue(CaretPostionProperty, value); }
1397         }
1398
1399         /// <summary>
1400         /// CaretPostionの依存プロパティを表す
1401         /// </summary>
1402         public static readonly DependencyProperty CaretPostionProperty =
1403             DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(TextPoint.Null));
1404         
1405         /// <summary>
1406         /// デフォルトの文字色を表す。これは依存プロパティです
1407         /// </summary>
1408         public new System.Windows.Media.Color Foreground
1409         {
1410             get { return (System.Windows.Media.Color)GetValue(ForegroundProperty); }
1411             set { SetValue(ForegroundProperty, value); }
1412         }
1413
1414         /// <summary>
1415         /// Foregroundの依存プロパティを表す
1416         /// </summary>
1417         public new static readonly DependencyProperty ForegroundProperty =
1418             DependencyProperty.Register("Foreground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1419
1420         /// <summary>
1421         /// 背景色を表す。これは依存プロパティです
1422         /// </summary>
1423         public new System.Windows.Media.Color Background
1424         {
1425             get { return (System.Windows.Media.Color)GetValue(BackgroundProperty); }
1426             set { SetValue(BackgroundProperty, value); }
1427         }
1428
1429         /// <summary>
1430         /// Backgroundの依存プロパティを表す
1431         /// </summary>
1432         public new static readonly DependencyProperty BackgroundProperty =
1433             DependencyProperty.Register("Background", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowColor));
1434         
1435         /// <summary>
1436         /// コントロールコードの文字色を表す。これは依存プロパティです
1437         /// </summary>
1438         public System.Windows.Media.Color ControlChar
1439         {
1440             get { return (System.Windows.Media.Color)GetValue(ControlCharProperty); }
1441             set { SetValue(ControlCharProperty, value); }
1442         }
1443
1444         /// <summary>
1445         /// ControlCharの依存プロパティを表す
1446         /// </summary>
1447         public static readonly DependencyProperty ControlCharProperty =
1448             DependencyProperty.Register("ControlChar", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Gray));
1449         
1450         /// <summary>
1451         /// 選択時の背景色を表す。これは依存プロパティです
1452         /// </summary>
1453         public System.Windows.Media.Color Hilight
1454         {
1455             get { return (System.Windows.Media.Color)GetValue(HilightProperty); }
1456             set { SetValue(HilightProperty, value); }
1457         }
1458
1459         /// <summary>
1460         /// Hilightの依存プロパティを表す
1461         /// </summary>
1462         public static readonly DependencyProperty HilightProperty =
1463             DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));
1464         
1465         /// <summary>
1466         /// キーワード1の文字色を表す。これは依存プロパティです
1467         /// </summary>
1468         public System.Windows.Media.Color Keyword1
1469         {
1470             get { return (System.Windows.Media.Color)GetValue(Keyword1Property); }
1471             set { SetValue(Keyword1Property, value); }
1472         }
1473
1474         /// <summary>
1475         /// Keyword1の依存プロパティを表す
1476         /// </summary>
1477         public static readonly DependencyProperty Keyword1Property =
1478             DependencyProperty.Register("Keyword1", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1479
1480         /// <summary>
1481         /// キーワード2の文字色を表す。これは依存プロパティです
1482         /// </summary>
1483         public System.Windows.Media.Color Keyword2
1484         {
1485             get { return (System.Windows.Media.Color)GetValue(Keyword2Property); }
1486             set { SetValue(Keyword2Property, value); }
1487         }
1488
1489         /// <summary>
1490         /// Keyword2の依存プロパティを表す
1491         /// </summary>
1492         public static readonly DependencyProperty Keyword2Property =
1493             DependencyProperty.Register("Keyword2", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DarkCyan));
1494
1495         /// <summary>
1496         /// コメントの文字色を表す。これは依存プロパティです
1497         /// </summary>
1498         public System.Windows.Media.Color Comment
1499         {
1500             get { return (System.Windows.Media.Color)GetValue(CommentProperty); }
1501             set { SetValue(CommentProperty, value); }
1502         }
1503
1504         /// <summary>
1505         /// Commentの依存プロパティを表す
1506         /// </summary>
1507         public static readonly DependencyProperty CommentProperty =
1508             DependencyProperty.Register("Comment", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Green));
1509
1510         /// <summary>
1511         /// 文字リテラルの文字色を表す。これは依存プロパティです
1512         /// </summary>
1513         public System.Windows.Media.Color Literal
1514         {
1515             get { return (System.Windows.Media.Color)GetValue(LiteralProperty); }
1516             set { SetValue(LiteralProperty, value); }
1517         }
1518
1519         /// <summary>
1520         /// Literalの依存プロパティを表す
1521         /// </summary>
1522         public static readonly DependencyProperty LiteralProperty =
1523             DependencyProperty.Register("Literal", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Brown));
1524
1525         /// <summary>
1526         /// URLの文字色を表す。これは依存プロパティです
1527         /// </summary>
1528         public System.Windows.Media.Color URL
1529         {
1530             get { return (System.Windows.Media.Color)GetValue(URLProperty); }
1531             set { SetValue(URLProperty, value); }
1532         }
1533
1534         /// <summary>
1535         /// URLの依存プロパティを表す
1536         /// </summary>
1537         public static readonly DependencyProperty URLProperty =
1538             DependencyProperty.Register("URL", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
1539
1540
1541         /// <summary>
1542         /// ラインマーカーの色を表す
1543         /// </summary>
1544         public System.Windows.Media.Color LineMarker
1545         {
1546             get { return (System.Windows.Media.Color)GetValue(LineMarkerProperty); }
1547             set { SetValue(LineMarkerProperty, value); }
1548         }
1549
1550         /// <summary>
1551         /// LineMarkerの依存プロパティを表す
1552         /// </summary>
1553         public static readonly DependencyProperty LineMarkerProperty =
1554             DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));
1555
1556         /// <summary>
1557         /// 挿入モード時のキャレットの色を表す
1558         /// </summary>
1559         public System.Windows.Media.Color InsertCaret
1560         {
1561             get { return (System.Windows.Media.Color)GetValue(InsertCaretProperty); }
1562             set { SetValue(InsertCaretProperty, value); }
1563         }
1564
1565         /// <summary>
1566         /// InsertCaretの依存プロパティを表す
1567         /// </summary>
1568         public static readonly DependencyProperty InsertCaretProperty =
1569             DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1570
1571         /// <summary>
1572         /// 行更新フラグの色を表す
1573         /// </summary>
1574         public System.Windows.Media.Color UpdateArea
1575         {
1576             get { return (System.Windows.Media.Color)GetValue(UpdateAreaProperty); }
1577             set { SetValue(UpdateAreaProperty, value); }
1578         }
1579
1580         /// <summary>
1581         /// UpdateAreaの依存プロパティを表す
1582         /// </summary>
1583         public static readonly DependencyProperty UpdateAreaProperty =
1584             DependencyProperty.Register("UpdateArea", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.MediumSeaGreen));        
1585
1586         /// <summary>
1587         /// 上書きモード時のキャレット職を表す
1588         /// </summary>
1589         public System.Windows.Media.Color OverwriteCaret
1590         {
1591             get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }
1592             set { SetValue(OverwriteCaretProperty, value); }
1593         }
1594         
1595         /// <summary>
1596         /// OverwriteCaretの依存プロパティを表す
1597         /// </summary>
1598         public static readonly DependencyProperty OverwriteCaretProperty =
1599             DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
1600
1601         /// <summary>
1602         /// 行番号の色を表す
1603         /// </summary>
1604         public System.Windows.Media.Color LineNumber
1605         {
1606             get { return (System.Windows.Media.Color)GetValue(LineNumberProperty); }
1607             set { SetValue(LineNumberProperty, value); }
1608         }
1609
1610         /// <summary>
1611         /// Using a DependencyProperty as the backing store for LineNumber.  This enables animation, styling, binding, etc...
1612         /// </summary>
1613         public static readonly DependencyProperty LineNumberProperty =
1614             DependencyProperty.Register("LineNumber", typeof(System.Windows.Media.Color), typeof(FooTextBox), new PropertyMetadata(Colors.DimGray));
1615
1616         /// <summary>
1617         /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
1618         /// </summary>
1619         public bool InsertMode
1620         {
1621             get { return (bool)GetValue(InsertModeProperty); }
1622             set { SetValue(InsertModeProperty, value); }
1623         }
1624
1625         /// <summary>
1626         /// InsertModeの依存プロパティを表す
1627         /// </summary>
1628         public static readonly DependencyProperty InsertModeProperty =
1629             DependencyProperty.Register("InsertMode",
1630             typeof(bool),
1631             typeof(FooTextBox),
1632             new FrameworkPropertyMetadata(true));
1633
1634         /// <summary>
1635         /// タブの文字数を表す。これは依存プロパティです
1636         /// </summary>
1637         public int TabChars
1638         {
1639             get { return (int)GetValue(TabCharsProperty); }
1640             set { SetValue(TabCharsProperty, value); }
1641         }
1642
1643         /// <summary>
1644         /// TabCharsの依存プロパティを表す
1645         /// </summary>
1646         public static readonly DependencyProperty TabCharsProperty =
1647             DependencyProperty.Register("TabChars",
1648             typeof(int),
1649             typeof(FooTextBox),
1650             new FrameworkPropertyMetadata(4));
1651
1652         /// <summary>
1653         /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
1654         /// </summary>
1655         public bool RectSelectMode
1656         {
1657             get { return (bool)GetValue(RectSelectModeProperty); }
1658             set { SetValue(RectSelectModeProperty, value); }
1659         }
1660
1661         /// <summary>
1662         /// RectSelectModeの依存プロパティを表す
1663         /// </summary>
1664         public static readonly DependencyProperty RectSelectModeProperty =
1665             DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1666
1667         /// <summary>
1668         /// 折り返しの方法を指定する
1669         /// </summary>
1670         /// <remarks>
1671         /// 変更した場合、レイアウトの再構築を行う必要があります
1672         /// </remarks>
1673         public LineBreakMethod LineBreakMethod
1674         {
1675             get { return (LineBreakMethod)GetValue(LineBreakProperty); }
1676             set { SetValue(LineBreakProperty, value); }
1677         }
1678
1679         /// <summary>
1680         /// LineBreakMethodの依存プロパティを表す
1681         /// </summary>
1682         public static readonly DependencyProperty LineBreakProperty =
1683             DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None));
1684
1685
1686         /// <summary>
1687         /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
1688         /// </summary>
1689         /// <remarks>
1690         /// 変更した場合、レイアウトの再構築を行う必要があります
1691         /// </remarks>
1692         public int LineBreakCharCount
1693         {
1694             get { return (int)GetValue(LineBreakCharCountProperty); }
1695             set { SetValue(LineBreakCharCountProperty, value); }
1696         }
1697
1698         /// <summary>
1699         /// LineBreakCharCountの依存プロパティを表す
1700         /// </summary>
1701         public static readonly DependencyProperty LineBreakCharCountProperty =
1702             DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
1703
1704         /// <summary>
1705         /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1706         /// </summary>
1707         public bool DrawCaret
1708         {
1709             get { return (bool)GetValue(DrawCaretProperty); }
1710             set { SetValue(DrawCaretProperty, value); }
1711         }
1712
1713         /// <summary>
1714         /// DrawCaretの依存プロパティを表す
1715         /// </summary>
1716         public static readonly DependencyProperty DrawCaretProperty =
1717             DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
1718
1719         
1720         /// <summary>
1721         /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
1722         /// </summary>
1723         public bool DrawCaretLine
1724         {
1725             get { return (bool)GetValue(DrawCaretLineProperty); }
1726             set { SetValue(DrawCaretLineProperty, value); }
1727         }
1728
1729         /// <summary>
1730         /// DrawCaretLineの依存プロパティを表す
1731         /// </summary>
1732         public static readonly DependencyProperty DrawCaretLineProperty =
1733             DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1734
1735         /// <summary>
1736         /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
1737         /// </summary>
1738         public bool DrawLineNumber
1739         {
1740             get { return (bool)GetValue(DrawLineNumberProperty); }
1741             set { SetValue(DrawLineNumberProperty, value); }
1742         }
1743
1744         /// <summary>
1745         /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
1746         /// </summary>
1747         public bool DrawRuler
1748         {
1749             get { return (bool)GetValue(DrawRulerProperty); }
1750             set { SetValue(DrawRulerProperty, value); }
1751         }
1752
1753         /// <summary>
1754         /// DrawRulerの依存プロパティを表す
1755         /// </summary>
1756         public static readonly DependencyProperty DrawRulerProperty =
1757             DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
1758
1759         
1760         /// <summary>
1761         /// DrawLineNumberの依存プロパティを表す
1762         /// </summary>
1763         public static readonly DependencyProperty DrawLineNumberProperty =
1764             DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1765
1766         /// <summary>
1767         /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
1768         /// </summary>
1769         public bool MarkURL
1770         {
1771             get { return (bool)GetValue(MarkURLProperty); }
1772             set { SetValue(MarkURLProperty, value); }
1773         }
1774
1775         /// <summary>
1776         /// MarkURLの依存プロパティを表す
1777         /// </summary>
1778         public static readonly DependencyProperty MarkURLProperty =
1779             DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
1780
1781         /// <summary>
1782         /// 全角スペースを表示するなら真。そうでないなら偽
1783         /// </summary>
1784         public bool ShowFullSpace
1785         {
1786             get { return (bool)GetValue(ShowFullSpaceProperty); }
1787             set { SetValue(ShowFullSpaceProperty, value); }
1788         }
1789
1790         /// <summary>
1791         /// ShowFullSpaceの依存プロパティを表す
1792         /// </summary>
1793         public static readonly DependencyProperty ShowFullSpaceProperty =
1794             DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
1795
1796         /// <summary>
1797         /// 半角スペースを表示するなら真。そうでないなら偽
1798         /// </summary>
1799         public bool ShowHalfSpace
1800         {
1801             get { return (bool)GetValue(ShowHalfSpaceProperty); }
1802             set { SetValue(ShowHalfSpaceProperty, value); }
1803         }
1804
1805         /// <summary>
1806         /// ShowHalfSpaceの依存プロパティを表す
1807         /// </summary>
1808         public static readonly DependencyProperty ShowHalfSpaceProperty =
1809             DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
1810
1811         /// <summary>
1812         /// タブを表示するなら真。そうでないなら偽
1813         /// </summary>
1814         public bool ShowTab
1815         {
1816             get { return (bool)GetValue(ShowTabProperty); }
1817             set { SetValue(ShowTabProperty, value); }
1818         }
1819
1820         /// <summary>
1821         /// ShowTabの依存プロパティを表す
1822         /// </summary>
1823         public static readonly DependencyProperty ShowTabProperty =
1824             DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
1825
1826         /// <summary>
1827         /// 改行マークを表示するなら真。そうでないなら偽
1828         /// </summary>
1829         public bool ShowLineBreak
1830         {
1831             get { return (bool)GetValue(ShowLineBreakProperty); }
1832             set { SetValue(ShowLineBreakProperty, value); }
1833         }
1834
1835         /// <summary>
1836         /// ShowLineBreakの依存プロパティを表す
1837         /// </summary>
1838         public static readonly DependencyProperty ShowLineBreakProperty =
1839             DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
1840         
1841         #endregion
1842     }
1843     /// <summary>
1844     /// マウスボタン関連のイベントクラス
1845     /// </summary>
1846     public sealed class FooMouseButtonEventArgs : MouseButtonEventArgs
1847     {
1848         /// <summary>
1849         /// イベントが発生したドキュメントのインデックス
1850         /// </summary>
1851         public int Index
1852         {
1853             get;
1854             private set;
1855         }
1856
1857         /// <summary>
1858         /// コンストラクター
1859         /// </summary>
1860         /// <param name="mouse">マウスデバイス</param>
1861         /// <param name="timestamp">タイムスタンプ</param>
1862         /// <param name="button">ボタン</param>
1863         /// <param name="stylusDevice">スタイラスデバイス</param>
1864         /// <param name="index">インデックス</param>
1865         public FooMouseButtonEventArgs(MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice, int index)
1866             : base(mouse, timestamp, button, stylusDevice)
1867         {
1868             this.Index = index;
1869         }
1870     }
1871     /// <summary>
1872     /// マウス関連のイベントクラス
1873     /// </summary>
1874     public sealed class FooMouseEventArgs : MouseEventArgs
1875     {
1876         /// <summary>
1877         /// イベントが発生したドキュメントのインデックス
1878         /// </summary>
1879         public int Index
1880         {
1881             get;
1882             private set;
1883         }
1884
1885         /// <summary>
1886         /// コンストラクター
1887         /// </summary>
1888         /// <param name="mouse">マウスデバイス</param>
1889         /// <param name="timestamp">タイムスタンプ</param>
1890         /// <param name="stylusDevice">スタイラスデバイス</param>
1891         /// <param name="index">インデックス</param>
1892         public FooMouseEventArgs(MouseDevice mouse,
1893             int timestamp,
1894             StylusDevice stylusDevice,
1895             int index)
1896             : base(mouse, timestamp, stylusDevice)
1897         {
1898             this.Index = index;
1899         }
1900     }
1901 }