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