OSDN Git Service

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