2 * Copyright (C) 2013 FooProject
\r
3 * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
\r
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
\r
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
\r
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
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
26 namespace FooEditEngine.WPF
\r
29 /// オートインデントを行うためのデリゲートを表す
\r
31 /// <param name="sender">イベント発生元のオブジェクト</param>
\r
32 /// <param name="e">イベントデーター</param>
\r
33 public delegate void AutoIndentHookerHandler(object sender,EventArgs e);
\r
36 /// WPFでのFooTextBoxの実装
\r
38 public sealed class FooTextBox : Control, IDisposable
\r
40 const double MaxFontSize = 72.0f;
\r
41 const double MinFontSize = 1;
\r
44 Controller _Controller;
\r
47 ScrollBar verticalScrollBar, horizontalScrollBar;
\r
48 TextStore textStore;
\r
49 DispatcherTimer timer;
\r
50 bool disposed = false;
\r
51 FooTextBoxAutomationPeer peer;
\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
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
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
85 this.Document = new Document();
\r
86 this.Document.Progress += Document_Progress;
\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
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
103 this._Controller = new Controller(this.Document, this.View);
\r
104 this._Controller.CaretMoved += new EventHandler(Controller_CaretMoved);
\r
106 //Viewを作成した後に追加しないと例外が発生する
\r
107 this.Document.Update += new DocumentUpdateEventHandler(Document_Update);
\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
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
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
135 this.Loaded += new RoutedEventHandler(FooTextBox_Loaded);
\r
137 this.AutoIndentHooker = (s,e)=>{};
\r
139 SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
\r
141 this.SystemEvents_UserPreferenceChanged(null, new UserPreferenceChangedEventArgs(UserPreferenceCategory.Keyboard));
\r
149 //Dispose(false)を呼び出すと落ちる
\r
150 this.Dispose(false);
\r
154 /// オートインデントを行うためのイベント
\r
156 public AutoIndentHookerHandler AutoIndentHooker;
\r
161 public override void OnApplyTemplate()
\r
163 base.OnApplyTemplate();
\r
165 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
\r
168 Grid.SetRow(this.image, 0);
\r
169 Grid.SetColumn(this.image, 0);
\r
170 grid.Children.Add(this.image);
\r
173 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
\r
174 if (this.horizontalScrollBar != null)
\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
181 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
\r
182 if (this.verticalScrollBar != null)
\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
194 /// <param name="start">開始インデックス</param>
\r
195 /// <param name="length">長さ</param>
\r
196 public void Select(int start, int length)
\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
205 /// キャレットを指定した行に移動させます
\r
207 /// <param name="index">インデックス</param>
\r
208 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
\r
209 public void JumpCaret(int index)
\r
211 if (this.Document.State == AsyncState.Loading)
\r
212 throw new InvalidOperationException();
\r
213 this._Controller.JumpCaret(index);
\r
216 /// キャレットを指定した行と桁に移動させます
\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
223 if (this.Document.State == AsyncState.Loading)
\r
224 throw new InvalidOperationException();
\r
225 this._Controller.JumpCaret(row, col);
\r
229 /// 選択中のテキストをクリップボードにコピーします
\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
241 /// 選択中のテキストをクリップボードに切り取ります
\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
250 Clipboard.SetText(text);
\r
251 this._Controller.SelectedText = "";
\r
256 /// 選択中のテキストを貼り付けます
\r
258 public void Paste()
\r
260 if (this.Document.State == AsyncState.Loading)
\r
261 throw new InvalidOperationException();
\r
262 if (Clipboard.ContainsText() == false)
\r
264 string text = Clipboard.GetText();
\r
265 this._Controller.SelectedText = text;
\r
271 public void DeSelectAll()
\r
273 if (this.Document.State == AsyncState.Loading)
\r
274 throw new InvalidOperationException();
\r
275 this._Controller.DeSelectAll();
\r
276 this.textStore.NotifySelectionChanged();
\r
282 /// <param name="tp">テキストポイント</param>
\r
283 /// <returns>座標</returns>
\r
284 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
\r
285 public System.Windows.Point GetPostionFromTextPoint(TextPoint tp)
\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
295 /// 対応するテキストポイントを返します
\r
297 /// <param name="p">クライアント領域の原点を左上とする座標</param>
\r
298 /// <returns>テキストポイント</returns>
\r
299 public TextPoint GetTextPointFromPostion(System.Windows.Point p)
\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
311 /// <param name="row">レイアウト行</param>
\r
312 /// <returns>行の高さ</returns>
\r
313 public double GetLineHeight(int row)
\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
323 /// インデックスに対応する座標を得ます
\r
325 /// <param name="index">インデックス</param>
\r
326 /// <returns>座標を返す</returns>
\r
327 public System.Windows.Point GetPostionFromIndex(int index)
\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
338 /// 座標からインデックスに変換します
\r
340 /// <param name="p">座標</param>
\r
341 /// <returns>インデックスを返す</returns>
\r
342 public int GetIndexFromPostion(System.Windows.Point p)
\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
355 public void Refresh()
\r
357 this.Refresh(this.View.PageBound);
\r
361 /// レイアウト行をすべて破棄し、再度レイアウトを行う
\r
363 public void PerfomLayouts()
\r
365 this.View.PerfomLayouts();
\r
369 /// アンマネージドリソースを開放する
\r
371 public void Dispose()
\r
373 this.disposed = true;
\r
376 this.Dispose(true);
\r
377 GC.SuppressFinalize(this);
\r
383 /// <param name="disposing">真ならマネージドリソースも開放し、そうでないならアンマネージドリソースのみを開放する</param>
\r
384 void Dispose(bool disposing)
\r
388 this.textStore.Dispose();
\r
390 this.View.Dispose();
\r
391 this.Render.Dispose();
\r
393 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
\r
396 void Refresh(Rectangle updateRect)
\r
403 this.Render.BegineDraw();
\r
404 if (this.Document.State != AsyncState.Loading)
\r
405 this.View.Draw(updateRect);
\r
407 this.Render.FillBackground(updateRect);
\r
408 this.Render.EndDraw();
\r
410 this.timer.Start();
\r
414 void CanExecute(object sender, CanExecuteRoutedEventArgs e)
\r
416 e.CanExecute = this.Document.State != FooEditEngine.AsyncState.Loading;
\r
419 void ToggleCodePointCommand(object sender, RoutedEventArgs e)
\r
421 if (!this._Controller.ConvertToChar())
\r
422 this._Controller.ConvertToCodePoint();
\r
426 void CopyCommand(object sender, RoutedEventArgs e)
\r
431 void CutCommand(object sender, RoutedEventArgs e)
\r
437 void PasteCommand(object sender, RoutedEventArgs e)
\r
443 void DeleteCommand(object sender, RoutedEventArgs e)
\r
445 int oldLength = this.Document.Length;
\r
446 this._Controller.DoDeleteAction();
\r
450 void SelectAllCommand(object sender, RoutedEventArgs e)
\r
452 this.Select(0, this.Document.Length);
\r
456 void UndoCommand(object sender, RoutedEventArgs e)
\r
458 int oldLength = this.Document.Length;
\r
459 this.Document.UndoManager.undo();
\r
463 void RedoCommand(object sender, RoutedEventArgs e)
\r
465 int oldLength = this.Document.Length;
\r
466 this.Document.UndoManager.redo();
\r
470 void ToggleInsertCommand(object sender, RoutedEventArgs e)
\r
472 if (this.InsertMode)
\r
473 this.InsertMode = false;
\r
475 this.InsertMode = true;
\r
479 void ToggleRectSelectCommand(object sender, RoutedEventArgs e)
\r
481 if (this.RectSelectMode)
\r
482 this.RectSelectMode = false;
\r
484 this.RectSelectMode = true;
\r
487 void ToggleFlowDirectionCommand(object sender, RoutedEventArgs e)
\r
489 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
\r
490 this.FlowDirection = System.Windows.FlowDirection.RightToLeft;
\r
492 this.FlowDirection = System.Windows.FlowDirection.LeftToRight;
\r
497 internal TextStore TextStore
\r
499 get { return this.textStore; }
\r
502 bool textStore_IsReadOnly()
\r
507 bool textStore_IsLoading()
\r
509 return this.Document.State == AsyncState.Loading;
\r
512 void textStore_CompositionEnded()
\r
514 TextStoreHelper.EndCompostion(this.Document);
\r
518 void textStore_CompositionUpdated(int start, int end)
\r
520 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
\r
523 bool textStore_CompositionStarted()
\r
525 bool result = TextStoreHelper.StartCompstion(this.Document);
\r
527 System.Media.SystemSounds.Beep.Play();
\r
531 string _textStore_GetString(int start, int length)
\r
533 return this.Document.ToString(start, length);
\r
536 IntPtr _textStore_GetHWnd()
\r
538 var hwndSource = HwndSource.FromVisual(this) as HwndSource;
\r
539 if (hwndSource != null)
\r
540 return hwndSource.Handle;
\r
542 return IntPtr.Zero;
\r
545 void _textStore_GetStringExtent(
\r
548 out POINT o_topLeft,
\r
549 out POINT o_bottomRight
\r
552 Point startPos, endPos;
\r
553 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
\r
555 startPos = PointToScreen(this.TranslatePoint(startPos, this));
\r
556 endPos = PointToScreen(this.TranslatePoint(endPos, this));
\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
562 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
\r
564 var pointTopLeft = new Point(0, 0);
\r
565 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
\r
567 pointTopLeft = PointToScreen(pointTopLeft);
\r
568 pointBottomRight = PointToScreen(pointBottomRight);
\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
574 void _textStore_GetSelectionIndex(out int o_startIndex, out int o_endIndex)
\r
576 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out o_startIndex, out o_endIndex);
\r
579 void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)
\r
581 if (this.Document.State == AsyncState.Loading)
\r
583 TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);
\r
587 void _textStore_InsertAtSelection(string i_value)
\r
589 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
\r
594 /// キーボードフォーカスが取得されたときに呼ばれます
\r
596 /// <param name="e">イベントデーター</param>
\r
597 protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
\r
599 base.OnGotKeyboardFocus(e);
\r
600 this.textStore.SetFocus();
\r
601 this.DrawCaret = true;
\r
606 /// キーボードフォーカスが失われたときに呼ばれます
\r
608 /// <param name="e">イベントデーター</param>
\r
609 protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
\r
611 base.OnLostKeyboardFocus(e);
\r
612 this.DrawCaret = false;
\r
618 protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
\r
620 this.peer = new FooTextBoxAutomationPeer(this);
\r
626 protected override void OnTextInput(TextCompositionEventArgs e)
\r
628 if (this.Document.State == AsyncState.Loading)
\r
630 if (e.Text == "\r")
\r
632 this._Controller.DoEnterAction();
\r
633 this.AutoIndentHooker(this, null);
\r
635 else if (e.Text == "\b")
\r
637 this._Controller.DoBackSpaceAction();
\r
641 this._Controller.DoInputString(e.Text);
\r
644 base.OnTextInput(e);
\r
649 protected override void OnKeyDown(KeyEventArgs e)
\r
651 if (this.Document.State == AsyncState.Loading)
\r
653 if (this.textStore.IsLocked())
\r
656 ModifierKeys modiferKeys = e.KeyboardDevice.Modifiers;
\r
657 bool movedCaret = false;
\r
661 if (!this._Controller.IsCanMoveCaret(-1,MoveFlow.Vertical))
\r
662 System.Media.SystemSounds.Beep.Play();
\r
664 this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
670 if (!this._Controller.IsCanMoveCaret(+1, MoveFlow.Vertical))
\r
671 System.Media.SystemSounds.Beep.Play();
\r
673 this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
679 if (!this._Controller.IsCanMoveCaret(-1, MoveFlow.Horizontical))
\r
680 System.Media.SystemSounds.Beep.Play();
\r
682 this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
\r
688 if (!this._Controller.IsCanMoveCaret(1, MoveFlow.Horizontical))
\r
689 System.Media.SystemSounds.Beep.Play();
\r
691 this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
\r
697 this._Controller.Scroll(ScrollDirection.Up,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
\r
702 this._Controller.Scroll(ScrollDirection.Down,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
\r
707 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
\r
708 this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
710 this._Controller.JumpCaret(this.View.CaretPostion.row, 0);
\r
715 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
\r
716 this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
718 this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.LayoutLines[this.View.CaretPostion.row].Length - 1);
\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
729 this._Controller.UpIndent();
\r
734 if (movedCaret && this.peer != null)
\r
735 this.peer.OnNotifyCaretChanged();
\r
739 bool IsPressedModifierKey(ModifierKeys keys, ModifierKeys pressed)
\r
741 if (keys == pressed)
\r
743 if ((keys & pressed) == pressed)
\r
749 /// ダブルクリックされたときに呼ばれます
\r
751 /// <param name="e">イベントパラメーター</param>
\r
753 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
\r
754 /// e.Handledを真にした場合、単語単位の選択が行われなくなります
\r
756 protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
\r
758 if (this.Document.State == AsyncState.Loading)
\r
760 System.Windows.Point p = e.GetPosition(this);
\r
761 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
762 if (tp == TextPoint.Null)
\r
764 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
766 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
\r
771 newEventArgs.RoutedEvent = e.RoutedEvent;
\r
772 base.OnMouseDoubleClick(newEventArgs);
\r
774 if (newEventArgs.Handled)
\r
777 if (e.LeftButton == MouseButtonState.Pressed)
\r
780 this._Controller.SelectWord(index);
\r
781 this.textStore.NotifySelectionChanged();
\r
782 if(this.peer != null)
\r
783 this.peer.OnNotifyCaretChanged();
\r
789 /// マウスボタンが押されたときに呼ばれます
\r
791 /// <param name="e">イベントパラメーター</param>
\r
793 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
\r
794 /// e.Handledを真にした場合、キャレットの移動処理が行われなくなります
\r
796 protected override void OnMouseDown(MouseButtonEventArgs e)
\r
798 if (this.Document.State == AsyncState.Loading)
\r
801 System.Windows.Point p = e.GetPosition(this);
\r
802 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
803 if (tp == TextPoint.Null)
\r
805 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
807 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
\r
812 newEventArgs.RoutedEvent = e.RoutedEvent;
\r
813 base.OnMouseDown(newEventArgs);
\r
815 if (newEventArgs.Handled)
\r
818 if (e.LeftButton == MouseButtonState.Pressed)
\r
820 FoldingItem foldingData = this.View.HitFoldingData(p.X,tp.row);
\r
821 if (foldingData != null)
\r
823 if (foldingData.Expand)
\r
824 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
\r
826 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
\r
827 this._Controller.JumpCaret(foldingData.Start,false);
\r
831 this._Controller.JumpCaret(tp.row, tp.col, false);
\r
833 if (this.peer != null)
\r
834 this.peer.OnNotifyCaretChanged();
\r
841 /// マウスが移動したときに呼ばれます
\r
843 /// <param name="e">イベントパラメーター</param>
\r
845 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
\r
846 /// e.Handledを真にした場合、選択処理と状況に応じたカーソルの変化が行われなくなります
\r
848 protected override void OnMouseMove(MouseEventArgs e)
\r
850 if (this.Document.State == AsyncState.Loading)
\r
852 this.Cursor = Cursors.Wait;
\r
853 base.OnMouseMove(e);
\r
856 System.Windows.Point p = e.GetPosition(this);
\r
857 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
858 if (tp == TextPoint.Null)
\r
860 base.OnMouseMove(e);
\r
863 int index = this.View.GetIndexFromLayoutLine(tp);
\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
869 if (newEventArgs.Handled)
\r
872 if (this.View.HitTextArea(p.X,p.Y))
\r
874 if (this._Controller.IsMarker(tp, HilightType.Url))
\r
875 this.Cursor = Cursors.Hand;
\r
877 this.Cursor = Cursors.IBeam;
\r
879 if (e.LeftButton == MouseButtonState.Pressed)
\r
881 this._Controller.MoveCaretAndSelect(tp);
\r
882 if (this.peer != null)
\r
883 this.peer.OnNotifyCaretChanged();
\r
889 this.Cursor = Cursors.Arrow;
\r
894 protected override void OnMouseWheel(MouseWheelEventArgs e)
\r
896 if (this.Document.State == AsyncState.Loading)
\r
898 if(Keyboard.Modifiers == ModifierKeys.None)
\r
901 this._Controller.Scroll(ScrollDirection.Up, SystemParameters.WheelScrollLines, false, false);
\r
903 this._Controller.Scroll(ScrollDirection.Down, SystemParameters.WheelScrollLines, false, false);
\r
905 else if (Keyboard.Modifiers == ModifierKeys.Control)
\r
907 double newFontSize = this.Render.FontSize;
\r
912 if (newFontSize > MaxFontSize)
\r
914 else if (newFontSize < MinFontSize)
\r
916 this.Render.FontSize = newFontSize;
\r
917 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
\r
920 base.OnMouseWheel(e);
\r
923 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
\r
925 if (e.Category == UserPreferenceCategory.Keyboard)
\r
927 int blinkTime = (int)NativeMethods.GetCaretBlinkTime();
\r
928 this.View.CaretBlink = blinkTime >= 0;
\r
929 this.View.CaretBlinkTime = blinkTime * 2;
\r
931 if (e.Category == UserPreferenceCategory.General)
\r
933 this.View.CaretWidthOnInsertMode = SystemParameters.CaretWidth;
\r
937 void Document_Update(object sender, DocumentUpdateEventArgs e)
\r
939 if (this.textStore.IsLocked() || e.type == UpdateType.Clear)
\r
941 if(e.removeLength == 0)
\r
942 this.textStore.NotifyTextChanged(e.startIndex,e.startIndex,e.startIndex + e.insertLength);
\r
944 this.textStore.NotifyTextChanged(e.startIndex,e.startIndex + 1,e.startIndex + e.insertLength - e.removeLength);
\r
947 void Document_Progress(object sender, ProgressEventArgs e)
\r
949 if (this.Document.State == AsyncState.Loading)
\r
953 case ProgressState.Start:
\r
954 this.textStore.NotifyTextChanged(0, this.Document.Length, 0);
\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
965 void timer_Tick(object sender, EventArgs e)
\r
967 if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)
\r
969 if (this.Document.State == AsyncState.Loading || this.Resize(this.image.ActualWidth, this.image.ActualHeight))
\r
975 ITextLayout layout = this.View.LayoutLines.GetData(this.View.CaretPostion.row).Layout;
\r
976 double width = layout.GetWidthFromIndex(this.View.CaretPostion.col);
\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
986 this.Refresh(updateRect);
\r
989 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
991 if (this.Document.State == AsyncState.Loading)
\r
993 if (this.horizontalScrollBar == null)
\r
996 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
\r
997 toX = this.horizontalScrollBar.Value;
\r
999 toX = -this.horizontalScrollBar.Value;
\r
1000 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
\r
1004 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
1006 if (this.Document.State == AsyncState.Loading)
\r
1008 if (this.verticalScrollBar == null)
\r
1010 int newRow = (int)this.verticalScrollBar.Value;
\r
1011 if (newRow >= this.View.LayoutLines.Count)
\r
1013 this._Controller.Scroll(this.View.Src.X,newRow, false, false);
\r
1017 void View_SrcChanged(object sender, EventArgs e)
\r
1019 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
\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
1033 void Controller_CaretMoved(object sender, EventArgs e)
\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
1041 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
\r
1043 this.Resize(this.image.ActualWidth, this.image.ActualHeight);
\r
1046 bool Resize(double width, double height)
\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
1052 this.View.PageBound = new Rectangle(0, 0, width, height);
\r
1054 if (this.horizontalScrollBar != null)
\r
1056 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
\r
1057 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
\r
1059 if (this.verticalScrollBar != null)
\r
1061 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
\r
1062 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
\r
1070 /// プロパティーが変更されたときに呼ばれます
\r
1072 /// <param name="e">イベントパラメーター</param>
\r
1073 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
\r
1075 switch (e.Property.Name)
\r
1077 case "LineBreakMethod":
\r
1078 this.View.LineBreak = this.LineBreakMethod;
\r
1080 case "LineBreakCharCount":
\r
1081 this.View.LineBreakCharCount = this.LineBreakCharCount;
\r
1083 case "InsertMode":
\r
1084 this.View.InsertMode = this.InsertMode;
\r
1087 this.View.TabStops = this.TabChars;
\r
1089 case "RectSelectMode":
\r
1090 this._Controller.RectSelection = this.RectSelectMode;
\r
1093 this.View.HideCaret = !this.DrawCaret;
\r
1095 case "DrawCaretLine":
\r
1096 this.View.HideLineMarker = !this.DrawCaretLine;
\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
1102 case "FontFamily":
\r
1103 this.Render.FontFamily = this.FontFamily;
\r
1106 this.Render.FontSize = this.FontSize;
\r
1109 this.Render.FontStyle = this.FontStyle;
\r
1111 case "FontWeight":
\r
1112 this.Render.FontWeigth = this.FontWeight;
\r
1114 case "Foreground":
\r
1115 this.Render.Foreground = this.Foreground;
\r
1117 case "Background":
\r
1118 this.Render.Background = this.Background;
\r
1120 case "ControlChar":
\r
1121 this.Render.ControlChar = this.ControlChar;
\r
1124 this.Render.Hilight = this.Hilight;
\r
1127 this.Render.Keyword1 = this.Keyword1;
\r
1130 this.Render.Keyword2 = this.Keyword2;
\r
1133 this.Render.Comment = this.Comment;
\r
1136 this.Render.Literal = this.Literal;
\r
1139 this.Render.Url = this.URL;
\r
1141 case "InsertCaret":
\r
1142 this.Render.InsertCaret = this.InsertCaret;
\r
1144 case "OverwriteCaret":
\r
1145 this.Render.OverwriteCaret = this.OverwriteCaret;
\r
1147 case "LineMarker":
\r
1148 this.Render.LineMarker = this.LineMarker;
\r
1151 this.View.UrlMark = this.MarkURL;
\r
1153 case "ShowFullSpace":
\r
1154 this.Render.ShowFullSpace = this.ShowFullSpace;
\r
1156 case "ShowHalfSpace":
\r
1157 this.Render.ShowHalfSpace = this.ShowHalfSpace;
\r
1160 this.Render.ShowTab = this.ShowTab;
\r
1162 case "FlowDirection":
\r
1163 this.Render.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;
\r
1164 this.horizontalScrollBar.FlowDirection = this.FlowDirection;
\r
1167 this.View.HideRuler = !this.DrawRuler;
\r
1168 this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);
\r
1171 base.OnPropertyChanged(e);
\r
1176 internal Controller Controller
\r
1180 return this._Controller;
\r
1185 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
\r
1187 public TextAntialiasMode TextAntialiasMode
\r
1191 return this.Render.TextAntialiasMode;
\r
1195 this.Render.TextAntialiasMode = value;
\r
1200 /// シンタックスハイライターを表す
\r
1202 public IHilighter Hilighter
\r
1206 return this.View.Hilighter;
\r
1210 this.View.Hilighter = value;
\r
1211 this.View.LayoutLines.ClearLayoutCache();
\r
1216 /// フォールティングを作成するインターフェイスを表す
\r
1218 public IFoldingStrategy FoldingStrategy
\r
1222 return this.View.LayoutLines.FoldingStrategy;
\r
1226 this.View.LayoutLines.FoldingStrategy = value;
\r
1227 if (value == null)
\r
1228 this.View.LayoutLines.FoldingCollection.Clear();
\r
1235 public Document Document
\r
1244 public LineToIndexTable LayoutLineCollection
\r
1246 get { return this.View.LayoutLines; }
\r
1252 public string SelectedText
\r
1256 return this._Controller.SelectedText;
\r
1260 int oldLength = this.Document.Length;
\r
1261 this._Controller.SelectedText = value;
\r
1268 /// <remarks>SelectionLengthが0の場合はキャレット位置を表します</remarks>
\r
1269 public int SelectionStart
\r
1271 get { return this._Controller.SelectionStart; }
\r
1277 /// <remarks>矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります</remarks>
\r
1278 public int SelectionLength
\r
1280 get { return this._Controller.SelectionLength; }
\r
1286 public double MagnificationPower
\r
1288 get { return (double)GetValue(MagnificationPowerPropertyKey.DependencyProperty); }
\r
1294 public static readonly DependencyPropertyKey MagnificationPowerPropertyKey =
\r
1295 DependencyProperty.RegisterReadOnly("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0));
\r
1300 public new FlowDirection FlowDirection
\r
1302 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
\r
1303 set { SetValue(FlowDirectionProperty, value); }
\r
1307 /// レタリング方向を表す。これは依存プロパティです
\r
1309 public new static readonly DependencyProperty FlowDirectionProperty =
\r
1310 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight));
\r
1313 /// キャレット位置を表す。これは依存プロパティです
\r
1315 public TextPoint CaretPostion
\r
1317 get { return (TextPoint)GetValue(CaretPostionPropertyKey.DependencyProperty); }
\r
1320 static readonly DependencyPropertyKey CaretPostionPropertyKey =
\r
1321 DependencyProperty.RegisterReadOnly("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new FrameworkPropertyMetadata(new TextPoint()));
\r
1324 /// デフォルトの文字色を表す。これは依存プロパティです
\r
1326 public new System.Windows.Media.Color Foreground
\r
1328 get { return (System.Windows.Media.Color)GetValue(ForegroundProperty); }
\r
1329 set { SetValue(ForegroundProperty, value); }
\r
1333 /// Foregroundの依存プロパティを表す
\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
1339 /// 背景色を表す。これは依存プロパティです
\r
1341 public new System.Windows.Media.Color Background
\r
1343 get { return (System.Windows.Media.Color)GetValue(BackgroundProperty); }
\r
1344 set { SetValue(BackgroundProperty, value); }
\r
1348 /// Backgroundの依存プロパティを表す
\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
1354 /// コントロールコードの文字色を表す。これは依存プロパティです
\r
1356 public System.Windows.Media.Color ControlChar
\r
1358 get { return (System.Windows.Media.Color)GetValue(ControlCharProperty); }
\r
1359 set { SetValue(ControlCharProperty, value); }
\r
1363 /// ControlCharの依存プロパティを表す
\r
1365 public static readonly DependencyProperty ControlCharProperty =
\r
1366 DependencyProperty.Register("ControlChar", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Gray));
\r
1369 /// 選択時の背景色を表す。これは依存プロパティです
\r
1371 public System.Windows.Media.Color Hilight
\r
1373 get { return (System.Windows.Media.Color)GetValue(HilightProperty); }
\r
1374 set { SetValue(HilightProperty, value); }
\r
1378 /// Hilightの依存プロパティを表す
\r
1380 public static readonly DependencyProperty HilightProperty =
\r
1381 DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));
\r
1384 /// キーワード1の文字色を表す。これは依存プロパティです
\r
1386 public System.Windows.Media.Color Keyword1
\r
1388 get { return (System.Windows.Media.Color)GetValue(Keyword1Property); }
\r
1389 set { SetValue(Keyword1Property, value); }
\r
1393 /// Keyword1の依存プロパティを表す
\r
1395 public static readonly DependencyProperty Keyword1Property =
\r
1396 DependencyProperty.Register("Keyword1", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
\r
1399 /// キーワード2の文字色を表す。これは依存プロパティです
\r
1401 public System.Windows.Media.Color Keyword2
\r
1403 get { return (System.Windows.Media.Color)GetValue(Keyword2Property); }
\r
1404 set { SetValue(Keyword2Property, value); }
\r
1408 /// Keyword2の依存プロパティを表す
\r
1410 public static readonly DependencyProperty Keyword2Property =
\r
1411 DependencyProperty.Register("Keyword2", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DarkCyan));
\r
1414 /// コメントの文字色を表す。これは依存プロパティです
\r
1416 public System.Windows.Media.Color Comment
\r
1418 get { return (System.Windows.Media.Color)GetValue(CommentProperty); }
\r
1419 set { SetValue(CommentProperty, value); }
\r
1423 /// Commentの依存プロパティを表す
\r
1425 public static readonly DependencyProperty CommentProperty =
\r
1426 DependencyProperty.Register("Comment", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Green));
\r
1429 /// 文字リテラルの文字色を表す。これは依存プロパティです
\r
1431 public System.Windows.Media.Color Literal
\r
1433 get { return (System.Windows.Media.Color)GetValue(LiteralProperty); }
\r
1434 set { SetValue(LiteralProperty, value); }
\r
1438 /// Literalの依存プロパティを表す
\r
1440 public static readonly DependencyProperty LiteralProperty =
\r
1441 DependencyProperty.Register("Literal", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Brown));
\r
1444 /// URLの文字色を表す。これは依存プロパティです
\r
1446 public System.Windows.Media.Color URL
\r
1448 get { return (System.Windows.Media.Color)GetValue(URLProperty); }
\r
1449 set { SetValue(URLProperty, value); }
\r
1453 /// URLの依存プロパティを表す
\r
1455 public static readonly DependencyProperty URLProperty =
\r
1456 DependencyProperty.Register("URL", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
\r
1462 public System.Windows.Media.Color LineMarker
\r
1464 get { return (System.Windows.Media.Color)GetValue(LineMarkerProperty); }
\r
1465 set { SetValue(LineMarkerProperty, value); }
\r
1469 /// LineMarkerの依存プロパティを表す
\r
1471 public static readonly DependencyProperty LineMarkerProperty =
\r
1472 DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));
\r
1475 /// 挿入モード時のキャレットの色を表す
\r
1477 public System.Windows.Media.Color InsertCaret
\r
1479 get { return (System.Windows.Media.Color)GetValue(InsertCaretProperty); }
\r
1480 set { SetValue(InsertCaretProperty, value); }
\r
1484 /// InsertCaretの依存プロパティを表す
\r
1486 public static readonly DependencyProperty InsertCaretProperty =
\r
1487 DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
\r
1490 /// 上書きモード時のキャレット職を表す
\r
1492 public System.Windows.Media.Color OverwriteCaret
\r
1494 get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }
\r
1495 set { SetValue(OverwriteCaretProperty, value); }
\r
1499 /// OverwriteCaretの依存プロパティを表す
\r
1501 public static readonly DependencyProperty OverwriteCaretProperty =
\r
1502 DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
\r
1505 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
\r
1507 public bool InsertMode
\r
1509 get { return (bool)GetValue(InsertModeProperty); }
\r
1510 set { SetValue(InsertModeProperty, value); }
\r
1514 /// InsertModeの依存プロパティを表す
\r
1516 public static readonly DependencyProperty InsertModeProperty =
\r
1517 DependencyProperty.Register("InsertMode",
\r
1519 typeof(FooTextBox),
\r
1520 new FrameworkPropertyMetadata(true));
\r
1523 /// タブの文字数を表す。これは依存プロパティです
\r
1525 public int TabChars
\r
1527 get { return (int)GetValue(TabCharsProperty); }
\r
1528 set { SetValue(TabCharsProperty, value); }
\r
1532 /// TabCharsの依存プロパティを表す
\r
1534 public static readonly DependencyProperty TabCharsProperty =
\r
1535 DependencyProperty.Register("TabChars",
\r
1537 typeof(FooTextBox),
\r
1538 new FrameworkPropertyMetadata(4));
\r
1541 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
\r
1543 public bool RectSelectMode
\r
1545 get { return (bool)GetValue(RectSelectModeProperty); }
\r
1546 set { SetValue(RectSelectModeProperty, value); }
\r
1550 /// RectSelectModeの依存プロパティを表す
\r
1552 public static readonly DependencyProperty RectSelectModeProperty =
\r
1553 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1559 /// 変更した場合、レイアウトの再構築を行う必要があります
\r
1561 public LineBreakMethod LineBreakMethod
\r
1563 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
\r
1564 set { SetValue(LineBreakProperty, value); }
\r
1568 /// LineBreakMethodの依存プロパティを表す
\r
1570 public static readonly DependencyProperty LineBreakProperty =
\r
1571 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None));
\r
1575 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
\r
1578 /// 変更した場合、レイアウトの再構築を行う必要があります
\r
1580 public int LineBreakCharCount
\r
1582 get { return (int)GetValue(LineBreakCharCountProperty); }
\r
1583 set { SetValue(LineBreakCharCountProperty, value); }
\r
1587 /// LineBreakCharCountの依存プロパティを表す
\r
1589 public static readonly DependencyProperty LineBreakCharCountProperty =
\r
1590 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
\r
1593 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
\r
1595 public bool DrawCaret
\r
1597 get { return (bool)GetValue(DrawCaretProperty); }
\r
1598 set { SetValue(DrawCaretProperty, value); }
\r
1602 /// DrawCaretの依存プロパティを表す
\r
1604 public static readonly DependencyProperty DrawCaretProperty =
\r
1605 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
\r
1609 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
\r
1611 public bool DrawCaretLine
\r
1613 get { return (bool)GetValue(DrawCaretLineProperty); }
\r
1614 set { SetValue(DrawCaretLineProperty, value); }
\r
1618 /// DrawCaretLineの依存プロパティを表す
\r
1620 public static readonly DependencyProperty DrawCaretLineProperty =
\r
1621 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
\r
1624 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
\r
1626 public bool DrawLineNumber
\r
1628 get { return (bool)GetValue(DrawLineNumberProperty); }
\r
1629 set { SetValue(DrawLineNumberProperty, value); }
\r
1633 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
\r
1635 public bool DrawRuler
\r
1637 get { return (bool)GetValue(DrawRulerProperty); }
\r
1638 set { SetValue(DrawRulerProperty, value); }
\r
1642 /// DrawRulerの依存プロパティを表す
\r
1644 public static readonly DependencyProperty DrawRulerProperty =
\r
1645 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
\r
1649 /// DrawLineNumberの依存プロパティを表す
\r
1651 public static readonly DependencyProperty DrawLineNumberProperty =
\r
1652 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1655 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
\r
1657 public bool MarkURL
\r
1659 get { return (bool)GetValue(MarkURLProperty); }
\r
1660 set { SetValue(MarkURLProperty, value); }
\r
1664 /// MarkURLの依存プロパティを表す
\r
1666 public static readonly DependencyProperty MarkURLProperty =
\r
1667 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
\r
1670 /// 全角スペースを表示するなら真。そうでないなら偽
\r
1672 public bool ShowFullSpace
\r
1674 get { return (bool)GetValue(ShowFullSpaceProperty); }
\r
1675 set { SetValue(ShowFullSpaceProperty, value); }
\r
1679 /// ShowFullSpaceの依存プロパティを表す
\r
1681 public static readonly DependencyProperty ShowFullSpaceProperty =
\r
1682 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
\r
1685 /// 半角スペースを表示するなら真。そうでないなら偽
\r
1687 public bool ShowHalfSpace
\r
1689 get { return (bool)GetValue(ShowHalfSpaceProperty); }
\r
1690 set { SetValue(ShowHalfSpaceProperty, value); }
\r
1694 /// ShowHalfSpaceの依存プロパティを表す
\r
1696 public static readonly DependencyProperty ShowHalfSpaceProperty =
\r
1697 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
\r
1700 /// タブを表示するなら真。そうでないなら偽
\r
1702 public bool ShowTab
\r
1704 get { return (bool)GetValue(ShowTabProperty); }
\r
1705 set { SetValue(ShowTabProperty, value); }
\r
1709 /// ShowTabの依存プロパティを表す
\r
1711 public static readonly DependencyProperty ShowTabProperty =
\r
1712 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
\r
1717 /// マウスボタン関連のイベントクラス
\r
1719 public sealed class FooMouseButtonEventArgs : MouseButtonEventArgs
\r
1722 /// イベントが発生したドキュメントのインデックス
\r
1733 /// <param name="mouse">マウスデバイス</param>
\r
1734 /// <param name="timestamp">タイムスタンプ</param>
\r
1735 /// <param name="button">ボタン</param>
\r
1736 /// <param name="stylusDevice">スタイラスデバイス</param>
\r
1737 /// <param name="index">インデックス</param>
\r
1738 public FooMouseButtonEventArgs(MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice, int index)
\r
1739 : base(mouse, timestamp, button, stylusDevice)
\r
1741 this.Index = index;
\r
1747 public sealed class FooMouseEventArgs : MouseEventArgs
\r
1750 /// イベントが発生したドキュメントのインデックス
\r
1761 /// <param name="mouse">マウスデバイス</param>
\r
1762 /// <param name="timestamp">タイムスタンプ</param>
\r
1763 /// <param name="stylusDevice">スタイラスデバイス</param>
\r
1764 /// <param name="index">インデックス</param>
\r
1765 public FooMouseEventArgs(MouseDevice mouse,
\r
1767 StylusDevice stylusDevice,
\r
1769 : base(mouse, timestamp, stylusDevice)
\r
1771 this.Index = index;
\r