OSDN Git Service

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