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 DocumentExtend.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.GetLayout(row).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
375 this.Dispose(true);
\r
376 GC.SuppressFinalize(this);
\r
377 this.disposed = true;
\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.View.IsFocused = 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.View.IsFocused = 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 this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
667 this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
673 this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
\r
679 this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
\r
685 this._Controller.Scroll(ScrollDirection.Up,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
\r
690 this._Controller.Scroll(ScrollDirection.Down,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
\r
695 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
\r
696 this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
698 this._Controller.JumpCaret(this.View.CaretPostion.row, 0);
\r
703 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
\r
704 this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
706 this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.LayoutLines[this.View.CaretPostion.row].Length - 1);
\r
711 int oldLength = this.Document.Length;
\r
712 if (this.SelectionLength == 0)
\r
713 this._Controller.DoInputChar('\t');
\r
714 else if(this.IsPressedModifierKey(modiferKeys,ModifierKeys.Shift))
\r
715 this._Controller.DownIndent();
\r
717 this._Controller.UpIndent();
\r
722 if (movedCaret && this.peer != null)
\r
723 this.peer.OnNotifyCaretChanged();
\r
727 bool IsPressedModifierKey(ModifierKeys keys, ModifierKeys pressed)
\r
729 if (keys == pressed)
\r
731 if ((keys & pressed) == pressed)
\r
737 /// ダブルクリックされたときに呼ばれます
\r
739 /// <param name="e">イベントパラメーター</param>
\r
741 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
\r
742 /// e.Handledを真にした場合、単語単位の選択が行われなくなります
\r
744 protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
\r
746 if (this.Document.State == AsyncState.Loading)
\r
748 System.Windows.Point p = e.GetPosition(this);
\r
749 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
750 if (tp == TextPoint.Null)
\r
752 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
754 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
\r
759 newEventArgs.RoutedEvent = e.RoutedEvent;
\r
760 base.OnMouseDoubleClick(newEventArgs);
\r
762 if (newEventArgs.Handled)
\r
765 if (e.LeftButton == MouseButtonState.Pressed)
\r
768 this._Controller.SelectWord(index);
\r
769 this.textStore.NotifySelectionChanged();
\r
770 if(this.peer != null)
\r
771 this.peer.OnNotifyCaretChanged();
\r
777 /// マウスボタンが押されたときに呼ばれます
\r
779 /// <param name="e">イベントパラメーター</param>
\r
781 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
\r
782 /// e.Handledを真にした場合、キャレットの移動処理が行われなくなります
\r
784 protected override void OnMouseDown(MouseButtonEventArgs e)
\r
786 if (this.Document.State == AsyncState.Loading)
\r
789 System.Windows.Point p = e.GetPosition(this);
\r
790 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
791 if (tp == TextPoint.Null)
\r
793 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
795 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
\r
800 newEventArgs.RoutedEvent = e.RoutedEvent;
\r
801 base.OnMouseDown(newEventArgs);
\r
803 if (newEventArgs.Handled)
\r
806 if (e.LeftButton == MouseButtonState.Pressed)
\r
808 FoldingItem foldingData = this.View.HitFoldingData(p.X,tp.row);
\r
809 if (foldingData != null)
\r
811 if (foldingData.Expand)
\r
812 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
\r
814 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
\r
815 this._Controller.JumpCaret(foldingData.Start,false);
\r
819 this._Controller.JumpCaret(tp.row, tp.col, false);
\r
821 if (this.peer != null)
\r
822 this.peer.OnNotifyCaretChanged();
\r
829 /// マウスが移動したときに呼ばれます
\r
831 /// <param name="e">イベントパラメーター</param>
\r
833 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
\r
834 /// e.Handledを真にした場合、選択処理と状況に応じたカーソルの変化が行われなくなります
\r
836 protected override void OnMouseMove(MouseEventArgs e)
\r
838 if (this.Document.State == AsyncState.Loading)
\r
840 this.Cursor = Cursors.Wait;
\r
841 base.OnMouseMove(e);
\r
844 System.Windows.Point p = e.GetPosition(this);
\r
845 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
846 if (tp == TextPoint.Null)
\r
848 base.OnMouseMove(e);
\r
851 int index = this.View.GetIndexFromLayoutLine(tp);
\r
853 FooMouseEventArgs newEventArgs = new FooMouseEventArgs(e.MouseDevice, e.Timestamp, e.StylusDevice, index);
\r
854 newEventArgs.RoutedEvent = e.RoutedEvent;
\r
855 base.OnMouseMove(newEventArgs);
\r
857 if (newEventArgs.Handled)
\r
860 if (this.View.HitTextArea(p.X,p.Y))
\r
862 if (this._Controller.IsMarker(tp, HilightType.Url))
\r
863 this.Cursor = Cursors.Hand;
\r
865 this.Cursor = Cursors.IBeam;
\r
867 if (e.LeftButton == MouseButtonState.Pressed)
\r
869 this._Controller.MoveCaretAndSelect(tp);
\r
870 if (this.peer != null)
\r
871 this.peer.OnNotifyCaretChanged();
\r
877 this.Cursor = Cursors.Arrow;
\r
882 protected override void OnMouseWheel(MouseWheelEventArgs e)
\r
884 if (this.Document.State == AsyncState.Loading)
\r
886 if(Keyboard.Modifiers == ModifierKeys.None)
\r
889 this._Controller.Scroll(ScrollDirection.Up, SystemParameters.WheelScrollLines, false, false);
\r
891 this._Controller.Scroll(ScrollDirection.Down, SystemParameters.WheelScrollLines, false, false);
\r
893 else if (Keyboard.Modifiers == ModifierKeys.Control)
\r
895 double newFontSize = this.Render.FontSize;
\r
900 if (newFontSize > MaxFontSize)
\r
902 else if (newFontSize < MinFontSize)
\r
904 this.Render.FontSize = newFontSize;
\r
905 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
\r
908 base.OnMouseWheel(e);
\r
911 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
\r
913 if (e.Category == UserPreferenceCategory.Keyboard)
\r
915 int blinkTime = (int)NativeMethods.GetCaretBlinkTime();
\r
916 this.View.CaretBlink = blinkTime >= 0;
\r
917 this.View.CaretBlinkTime = blinkTime * 2;
\r
919 if (e.Category == UserPreferenceCategory.General)
\r
921 this.View.CaretWidthOnInsertMode = SystemParameters.CaretWidth;
\r
925 void Document_Update(object sender, DocumentUpdateEventArgs e)
\r
927 if (this.textStore.IsLocked() || e.type == UpdateType.Clear)
\r
929 if(e.removeLength == 0)
\r
930 this.textStore.NotifyTextChanged(e.startIndex,e.startIndex,e.startIndex + e.insertLength);
\r
932 this.textStore.NotifyTextChanged(e.startIndex,e.startIndex + 1,e.startIndex + e.insertLength - e.removeLength);
\r
935 void Document_Progress(object sender, ProgressEventArgs e)
\r
937 if (this.Document.State == AsyncState.Loading)
\r
941 case ProgressState.Start:
\r
942 this.textStore.NotifyTextChanged(0, this.Document.Length, 0);
\r
944 case ProgressState.Complete:
\r
945 this.textStore.NotifyTextChanged(0, 0, this.Document.Length);
\r
946 this.OnMouseMove(new MouseEventArgs(Mouse.PrimaryDevice, new TimeSpan(DateTime.Now.Ticks).Milliseconds));
\r
947 if(this.verticalScrollBar != null)
\r
948 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
\r
949 this.View.CalculateLineCountOnScreen();
\r
954 void timer_Tick(object sender, EventArgs e)
\r
956 if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)
\r
958 if (this.Document.State == AsyncState.Loading || this.Resize(this.image.ActualWidth, this.image.ActualHeight))
\r
964 ITextLayout layout = this.View.LayoutLines.GetLayout(this.View.CaretPostion.row);
\r
965 double width = layout.GetWidthFromIndex(this.View.CaretPostion.col);
\r
967 width = this.View.CaretWidthOnInsertMode;
\r
968 double height = layout.Height;
\r
969 Rectangle updateRect = new Rectangle(
\r
970 this.View.CaretLocation.X,
\r
971 this.View.CaretLocation.Y,
\r
975 this.Refresh(updateRect);
\r
978 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
980 if (this.Document.State == AsyncState.Loading)
\r
982 if (this.horizontalScrollBar == null)
\r
985 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
\r
986 toX = this.horizontalScrollBar.Value;
\r
988 toX = -this.horizontalScrollBar.Value;
\r
989 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
\r
993 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
995 if (this.Document.State == AsyncState.Loading)
\r
997 if (this.verticalScrollBar == null)
\r
999 int newRow = (int)this.verticalScrollBar.Value;
\r
1000 if (newRow >= this.View.LayoutLines.Count)
\r
1002 this._Controller.Scroll(this.View.Src.X,newRow, false, false);
\r
1006 void View_SrcChanged(object sender, EventArgs e)
\r
1008 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
\r
1010 EditView view = this.View;
\r
1011 if (view.Src.Row > this.verticalScrollBar.Maximum)
\r
1012 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
\r
1013 double absoulteX = Math.Abs(view.Src.X);
\r
1014 if(absoulteX > this.horizontalScrollBar.Maximum)
\r
1015 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
\r
1016 if(view.Src.Row != this.verticalScrollBar.Value)
\r
1017 this.verticalScrollBar.Value = view.Src.Row;
\r
1018 if (view.Src.X != this.horizontalScrollBar.Value)
\r
1019 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
\r
1022 void Controller_CaretMoved(object sender, EventArgs e)
\r
1024 this.View.CaretBlink = this.View.CaretBlink;
\r
1025 SetValue(CaretPostionPropertyKey, this.View.CaretPostion);
\r
1026 if(this.textStore.IsLocked() == false)
\r
1027 this.textStore.NotifySelectionChanged();
\r
1030 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
\r
1032 this.Resize(this.image.ActualWidth, this.image.ActualHeight);
\r
1035 bool Resize(double width, double height)
\r
1037 if (width == 0 || height == 0)
\r
1038 throw new ArgumentOutOfRangeException();
\r
1039 if (this.Render.Resize(width, height) && this.Document.State != AsyncState.Loading)
\r
1041 this.View.PageBound = new Rectangle(0, 0, width, height);
\r
1043 if (this.horizontalScrollBar != null)
\r
1045 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
\r
1046 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
\r
1048 if (this.verticalScrollBar != null)
\r
1050 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
\r
1051 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
\r
1059 /// プロパティーが変更されたときに呼ばれます
\r
1061 /// <param name="e">イベントパラメーター</param>
\r
1062 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
\r
1064 switch (e.Property.Name)
\r
1066 case "LineBreakMethod":
\r
1067 this.View.LineBreak = this.LineBreakMethod;
\r
1069 case "LineBreakCharCount":
\r
1070 this.View.LineBreakCharCount = this.LineBreakCharCount;
\r
1072 case "InsertMode":
\r
1073 this.View.InsertMode = this.InsertMode;
\r
1076 this.View.TabStops = this.TabChars;
\r
1078 case "RectSelectMode":
\r
1079 this._Controller.RectSelection = this.RectSelectMode;
\r
1082 this.View.HideCaret = !this.DrawCaret;
\r
1084 case "DrawCaretLine":
\r
1085 this.View.HideLineMarker = !this.DrawCaretLine;
\r
1087 case "DrawLineNumber":
\r
1088 this.View.DrawLineNumber = this.DrawLineNumber;
\r
1089 this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);
\r
1091 case "FontFamily":
\r
1092 this.Render.FontFamily = this.FontFamily;
\r
1095 this.Render.FontSize = this.FontSize;
\r
1098 this.Render.FontStyle = this.FontStyle;
\r
1100 case "FontWeight":
\r
1101 this.Render.FontWeigth = this.FontWeight;
\r
1103 case "Foreground":
\r
1104 this.Render.Foreground = this.Foreground;
\r
1106 case "Background":
\r
1107 this.Render.Background = this.Background;
\r
1109 case "ControlChar":
\r
1110 this.Render.ControlChar = this.ControlChar;
\r
1113 this.Render.Hilight = this.Hilight;
\r
1116 this.Render.Keyword1 = this.Keyword1;
\r
1119 this.Render.Keyword2 = this.Keyword2;
\r
1122 this.Render.Comment = this.Comment;
\r
1125 this.Render.Literal = this.Literal;
\r
1128 this.Render.Url = this.URL;
\r
1130 case "InsertCaret":
\r
1131 this.Render.InsertCaret = this.InsertCaret;
\r
1133 case "OverwriteCaret":
\r
1134 this.Render.OverwriteCaret = this.OverwriteCaret;
\r
1136 case "LineMarker":
\r
1137 this.Render.LineMarker = this.LineMarker;
\r
1140 this.View.UrlMark = this.MarkURL;
\r
1142 case "ShowFullSpace":
\r
1143 this.Render.ShowFullSpace = this.ShowFullSpace;
\r
1145 case "ShowHalfSpace":
\r
1146 this.Render.ShowHalfSpace = this.ShowHalfSpace;
\r
1149 this.Render.ShowTab = this.ShowTab;
\r
1151 case "ShowLineBreak":
\r
1152 this.Render.ShowLineBreak = this.ShowLineBreak;
\r
1154 case "FlowDirection":
\r
1155 this.Render.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;
\r
1156 this.horizontalScrollBar.FlowDirection = this.FlowDirection;
\r
1159 this.View.HideRuler = !this.DrawRuler;
\r
1160 this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);
\r
1163 base.OnPropertyChanged(e);
\r
1168 internal Controller Controller
\r
1172 return this._Controller;
\r
1177 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
\r
1179 public TextAntialiasMode TextAntialiasMode
\r
1183 return this.Render.TextAntialiasMode;
\r
1187 this.Render.TextAntialiasMode = value;
\r
1192 /// シンタックスハイライターを表す
\r
1194 public IHilighter Hilighter
\r
1198 return this.View.Hilighter;
\r
1202 this.View.Hilighter = value;
\r
1203 this.View.LayoutLines.ClearLayoutCache();
\r
1208 /// フォールティングを作成するインターフェイスを表す
\r
1210 public IFoldingStrategy FoldingStrategy
\r
1214 return this.View.LayoutLines.FoldingStrategy;
\r
1218 this.View.LayoutLines.FoldingStrategy = value;
\r
1219 if (value == null)
\r
1220 this.View.LayoutLines.FoldingCollection.Clear();
\r
1227 public Document Document
\r
1236 public LineToIndexTable LayoutLineCollection
\r
1238 get { return this.View.LayoutLines; }
\r
1244 public string SelectedText
\r
1248 return this._Controller.SelectedText;
\r
1252 int oldLength = this.Document.Length;
\r
1253 this._Controller.SelectedText = value;
\r
1260 /// <remarks>SelectionLengthが0の場合はキャレット位置を表します</remarks>
\r
1261 public int SelectionStart
\r
1263 get { return this._Controller.SelectionStart; }
\r
1269 /// <remarks>矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります</remarks>
\r
1270 public int SelectionLength
\r
1272 get { return this._Controller.SelectionLength; }
\r
1278 public double MagnificationPower
\r
1280 get { return (double)GetValue(MagnificationPowerPropertyKey.DependencyProperty); }
\r
1286 public static readonly DependencyPropertyKey MagnificationPowerPropertyKey =
\r
1287 DependencyProperty.RegisterReadOnly("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0));
\r
1292 public new FlowDirection FlowDirection
\r
1294 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
\r
1295 set { SetValue(FlowDirectionProperty, value); }
\r
1299 /// レタリング方向を表す。これは依存プロパティです
\r
1301 public new static readonly DependencyProperty FlowDirectionProperty =
\r
1302 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight));
\r
1305 /// キャレット位置を表す。これは依存プロパティです
\r
1307 public TextPoint CaretPostion
\r
1309 get { return (TextPoint)GetValue(CaretPostionPropertyKey.DependencyProperty); }
\r
1312 static readonly DependencyPropertyKey CaretPostionPropertyKey =
\r
1313 DependencyProperty.RegisterReadOnly("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new FrameworkPropertyMetadata(new TextPoint()));
\r
1316 /// デフォルトの文字色を表す。これは依存プロパティです
\r
1318 public new System.Windows.Media.Color Foreground
\r
1320 get { return (System.Windows.Media.Color)GetValue(ForegroundProperty); }
\r
1321 set { SetValue(ForegroundProperty, value); }
\r
1325 /// Foregroundの依存プロパティを表す
\r
1327 public new static readonly DependencyProperty ForegroundProperty =
\r
1328 DependencyProperty.Register("Foreground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
\r
1331 /// 背景色を表す。これは依存プロパティです
\r
1333 public new System.Windows.Media.Color Background
\r
1335 get { return (System.Windows.Media.Color)GetValue(BackgroundProperty); }
\r
1336 set { SetValue(BackgroundProperty, value); }
\r
1340 /// Backgroundの依存プロパティを表す
\r
1342 public new static readonly DependencyProperty BackgroundProperty =
\r
1343 DependencyProperty.Register("Background", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowColor));
\r
1346 /// コントロールコードの文字色を表す。これは依存プロパティです
\r
1348 public System.Windows.Media.Color ControlChar
\r
1350 get { return (System.Windows.Media.Color)GetValue(ControlCharProperty); }
\r
1351 set { SetValue(ControlCharProperty, value); }
\r
1355 /// ControlCharの依存プロパティを表す
\r
1357 public static readonly DependencyProperty ControlCharProperty =
\r
1358 DependencyProperty.Register("ControlChar", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Gray));
\r
1361 /// 選択時の背景色を表す。これは依存プロパティです
\r
1363 public System.Windows.Media.Color Hilight
\r
1365 get { return (System.Windows.Media.Color)GetValue(HilightProperty); }
\r
1366 set { SetValue(HilightProperty, value); }
\r
1370 /// Hilightの依存プロパティを表す
\r
1372 public static readonly DependencyProperty HilightProperty =
\r
1373 DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));
\r
1376 /// キーワード1の文字色を表す。これは依存プロパティです
\r
1378 public System.Windows.Media.Color Keyword1
\r
1380 get { return (System.Windows.Media.Color)GetValue(Keyword1Property); }
\r
1381 set { SetValue(Keyword1Property, value); }
\r
1385 /// Keyword1の依存プロパティを表す
\r
1387 public static readonly DependencyProperty Keyword1Property =
\r
1388 DependencyProperty.Register("Keyword1", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
\r
1391 /// キーワード2の文字色を表す。これは依存プロパティです
\r
1393 public System.Windows.Media.Color Keyword2
\r
1395 get { return (System.Windows.Media.Color)GetValue(Keyword2Property); }
\r
1396 set { SetValue(Keyword2Property, value); }
\r
1400 /// Keyword2の依存プロパティを表す
\r
1402 public static readonly DependencyProperty Keyword2Property =
\r
1403 DependencyProperty.Register("Keyword2", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DarkCyan));
\r
1406 /// コメントの文字色を表す。これは依存プロパティです
\r
1408 public System.Windows.Media.Color Comment
\r
1410 get { return (System.Windows.Media.Color)GetValue(CommentProperty); }
\r
1411 set { SetValue(CommentProperty, value); }
\r
1415 /// Commentの依存プロパティを表す
\r
1417 public static readonly DependencyProperty CommentProperty =
\r
1418 DependencyProperty.Register("Comment", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Green));
\r
1421 /// 文字リテラルの文字色を表す。これは依存プロパティです
\r
1423 public System.Windows.Media.Color Literal
\r
1425 get { return (System.Windows.Media.Color)GetValue(LiteralProperty); }
\r
1426 set { SetValue(LiteralProperty, value); }
\r
1430 /// Literalの依存プロパティを表す
\r
1432 public static readonly DependencyProperty LiteralProperty =
\r
1433 DependencyProperty.Register("Literal", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Brown));
\r
1436 /// URLの文字色を表す。これは依存プロパティです
\r
1438 public System.Windows.Media.Color URL
\r
1440 get { return (System.Windows.Media.Color)GetValue(URLProperty); }
\r
1441 set { SetValue(URLProperty, value); }
\r
1445 /// URLの依存プロパティを表す
\r
1447 public static readonly DependencyProperty URLProperty =
\r
1448 DependencyProperty.Register("URL", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
\r
1454 public System.Windows.Media.Color LineMarker
\r
1456 get { return (System.Windows.Media.Color)GetValue(LineMarkerProperty); }
\r
1457 set { SetValue(LineMarkerProperty, value); }
\r
1461 /// LineMarkerの依存プロパティを表す
\r
1463 public static readonly DependencyProperty LineMarkerProperty =
\r
1464 DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));
\r
1467 /// 挿入モード時のキャレットの色を表す
\r
1469 public System.Windows.Media.Color InsertCaret
\r
1471 get { return (System.Windows.Media.Color)GetValue(InsertCaretProperty); }
\r
1472 set { SetValue(InsertCaretProperty, value); }
\r
1476 /// InsertCaretの依存プロパティを表す
\r
1478 public static readonly DependencyProperty InsertCaretProperty =
\r
1479 DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
\r
1482 /// 上書きモード時のキャレット職を表す
\r
1484 public System.Windows.Media.Color OverwriteCaret
\r
1486 get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }
\r
1487 set { SetValue(OverwriteCaretProperty, value); }
\r
1491 /// OverwriteCaretの依存プロパティを表す
\r
1493 public static readonly DependencyProperty OverwriteCaretProperty =
\r
1494 DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
\r
1497 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
\r
1499 public bool InsertMode
\r
1501 get { return (bool)GetValue(InsertModeProperty); }
\r
1502 set { SetValue(InsertModeProperty, value); }
\r
1506 /// InsertModeの依存プロパティを表す
\r
1508 public static readonly DependencyProperty InsertModeProperty =
\r
1509 DependencyProperty.Register("InsertMode",
\r
1511 typeof(FooTextBox),
\r
1512 new FrameworkPropertyMetadata(true));
\r
1515 /// タブの文字数を表す。これは依存プロパティです
\r
1517 public int TabChars
\r
1519 get { return (int)GetValue(TabCharsProperty); }
\r
1520 set { SetValue(TabCharsProperty, value); }
\r
1524 /// TabCharsの依存プロパティを表す
\r
1526 public static readonly DependencyProperty TabCharsProperty =
\r
1527 DependencyProperty.Register("TabChars",
\r
1529 typeof(FooTextBox),
\r
1530 new FrameworkPropertyMetadata(4));
\r
1533 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
\r
1535 public bool RectSelectMode
\r
1537 get { return (bool)GetValue(RectSelectModeProperty); }
\r
1538 set { SetValue(RectSelectModeProperty, value); }
\r
1542 /// RectSelectModeの依存プロパティを表す
\r
1544 public static readonly DependencyProperty RectSelectModeProperty =
\r
1545 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1551 /// 変更した場合、レイアウトの再構築を行う必要があります
\r
1553 public LineBreakMethod LineBreakMethod
\r
1555 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
\r
1556 set { SetValue(LineBreakProperty, value); }
\r
1560 /// LineBreakMethodの依存プロパティを表す
\r
1562 public static readonly DependencyProperty LineBreakProperty =
\r
1563 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None));
\r
1567 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
\r
1570 /// 変更した場合、レイアウトの再構築を行う必要があります
\r
1572 public int LineBreakCharCount
\r
1574 get { return (int)GetValue(LineBreakCharCountProperty); }
\r
1575 set { SetValue(LineBreakCharCountProperty, value); }
\r
1579 /// LineBreakCharCountの依存プロパティを表す
\r
1581 public static readonly DependencyProperty LineBreakCharCountProperty =
\r
1582 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
\r
1585 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
\r
1587 public bool DrawCaret
\r
1589 get { return (bool)GetValue(DrawCaretProperty); }
\r
1590 set { SetValue(DrawCaretProperty, value); }
\r
1594 /// DrawCaretの依存プロパティを表す
\r
1596 public static readonly DependencyProperty DrawCaretProperty =
\r
1597 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
\r
1601 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
\r
1603 public bool DrawCaretLine
\r
1605 get { return (bool)GetValue(DrawCaretLineProperty); }
\r
1606 set { SetValue(DrawCaretLineProperty, value); }
\r
1610 /// DrawCaretLineの依存プロパティを表す
\r
1612 public static readonly DependencyProperty DrawCaretLineProperty =
\r
1613 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
\r
1616 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
\r
1618 public bool DrawLineNumber
\r
1620 get { return (bool)GetValue(DrawLineNumberProperty); }
\r
1621 set { SetValue(DrawLineNumberProperty, value); }
\r
1625 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
\r
1627 public bool DrawRuler
\r
1629 get { return (bool)GetValue(DrawRulerProperty); }
\r
1630 set { SetValue(DrawRulerProperty, value); }
\r
1634 /// DrawRulerの依存プロパティを表す
\r
1636 public static readonly DependencyProperty DrawRulerProperty =
\r
1637 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
\r
1641 /// DrawLineNumberの依存プロパティを表す
\r
1643 public static readonly DependencyProperty DrawLineNumberProperty =
\r
1644 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1647 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
\r
1649 public bool MarkURL
\r
1651 get { return (bool)GetValue(MarkURLProperty); }
\r
1652 set { SetValue(MarkURLProperty, value); }
\r
1656 /// MarkURLの依存プロパティを表す
\r
1658 public static readonly DependencyProperty MarkURLProperty =
\r
1659 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1662 /// 全角スペースを表示するなら真。そうでないなら偽
\r
1664 public bool ShowFullSpace
\r
1666 get { return (bool)GetValue(ShowFullSpaceProperty); }
\r
1667 set { SetValue(ShowFullSpaceProperty, value); }
\r
1671 /// ShowFullSpaceの依存プロパティを表す
\r
1673 public static readonly DependencyProperty ShowFullSpaceProperty =
\r
1674 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
\r
1677 /// 半角スペースを表示するなら真。そうでないなら偽
\r
1679 public bool ShowHalfSpace
\r
1681 get { return (bool)GetValue(ShowHalfSpaceProperty); }
\r
1682 set { SetValue(ShowHalfSpaceProperty, value); }
\r
1686 /// ShowHalfSpaceの依存プロパティを表す
\r
1688 public static readonly DependencyProperty ShowHalfSpaceProperty =
\r
1689 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
\r
1692 /// タブを表示するなら真。そうでないなら偽
\r
1694 public bool ShowTab
\r
1696 get { return (bool)GetValue(ShowTabProperty); }
\r
1697 set { SetValue(ShowTabProperty, value); }
\r
1701 /// ShowTabの依存プロパティを表す
\r
1703 public static readonly DependencyProperty ShowTabProperty =
\r
1704 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
\r
1707 /// 改行マークを表示するなら真。そうでないなら偽
\r
1709 public bool ShowLineBreak
\r
1711 get { return (bool)GetValue(ShowLineBreakProperty); }
\r
1712 set { SetValue(ShowLineBreakProperty, value); }
\r
1716 /// ShowLineBreakの依存プロパティを表す
\r
1718 public static readonly DependencyProperty ShowLineBreakProperty =
\r
1719 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
\r
1724 /// マウスボタン関連のイベントクラス
\r
1726 public sealed class FooMouseButtonEventArgs : MouseButtonEventArgs
\r
1729 /// イベントが発生したドキュメントのインデックス
\r
1740 /// <param name="mouse">マウスデバイス</param>
\r
1741 /// <param name="timestamp">タイムスタンプ</param>
\r
1742 /// <param name="button">ボタン</param>
\r
1743 /// <param name="stylusDevice">スタイラスデバイス</param>
\r
1744 /// <param name="index">インデックス</param>
\r
1745 public FooMouseButtonEventArgs(MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice, int index)
\r
1746 : base(mouse, timestamp, button, stylusDevice)
\r
1748 this.Index = index;
\r
1754 public sealed class FooMouseEventArgs : MouseEventArgs
\r
1757 /// イベントが発生したドキュメントのインデックス
\r
1768 /// <param name="mouse">マウスデバイス</param>
\r
1769 /// <param name="timestamp">タイムスタンプ</param>
\r
1770 /// <param name="stylusDevice">スタイラスデバイス</param>
\r
1771 /// <param name="index">インデックス</param>
\r
1772 public FooMouseEventArgs(MouseDevice mouse,
\r
1774 StylusDevice stylusDevice,
\r
1776 : base(mouse, timestamp, stylusDevice)
\r
1778 this.Index = index;
\r