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
52 bool nowCaretMove = false;
\r
56 DefaultStyleKeyProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(typeof(FooTextBox)));
\r
57 KeyboardNavigation.IsTabStopProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(true));
\r
58 KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(KeyboardNavigationMode.None));
\r
66 this.image = new Image();
\r
67 this.image.Stretch = Stretch.Fill;
\r
68 this.image.HorizontalAlignment = HorizontalAlignment.Left;
\r
69 this.image.VerticalAlignment = VerticalAlignment.Top;
\r
71 this.textStore = new TextStore();
\r
72 this.textStore.IsLoading += textStore_IsLoading;
\r
73 this.textStore.IsReadOnly += textStore_IsReadOnly;
\r
74 this.textStore.GetStringLength += () => this.Document.Length;
\r
75 this.textStore.GetString += _textStore_GetString;
\r
76 this.textStore.GetSelectionIndex += _textStore_GetSelectionIndex;
\r
77 this.textStore.SetSelectionIndex += _textStore_SetSelectionIndex;
\r
78 this.textStore.InsertAtSelection += _textStore_InsertAtSelection;
\r
79 this.textStore.GetHWnd += _textStore_GetHWnd;
\r
80 this.textStore.GetScreenExtent += _textStore_GetScreenExtent;
\r
81 this.textStore.GetStringExtent += _textStore_GetStringExtent;
\r
82 this.textStore.CompositionStarted += textStore_CompositionStarted;
\r
83 this.textStore.CompositionUpdated += textStore_CompositionUpdated;
\r
84 this.textStore.CompositionEnded += textStore_CompositionEnded;
\r
86 this.Document = new Document();
\r
87 DocumentExtend.Progress += new EventHandler<ProgressEventArgs>(Document_Progress);
\r
89 this.Render = new D2DRender(this, 200, 200,this.image);
\r
90 this.Render.ShowFullSpace = this.ShowFullSpace;
\r
91 this.Render.ShowHalfSpace = this.ShowHalfSpace;
\r
92 this.Render.ShowTab = this.ShowTab;
\r
94 this.View = new EditView(this.Document, this.Render,new Margin(5,5,5,5));
\r
95 this.View.SrcChanged += View_SrcChanged;
\r
96 this.View.InsertMode = this.InsertMode;
\r
97 this.View.DrawLineNumber = this.DrawLineNumber;
\r
98 this.View.HideCaret = !this.DrawCaret;
\r
99 this.View.HideLineMarker = !this.DrawCaretLine;
\r
100 this.View.HideRuler = !this.DrawRuler;
\r
101 this.View.UrlMark = this.MarkURL;
\r
102 this.View.TabStops = this.TabChars;
\r
104 this._Controller = new Controller(this.Document, this.View);
\r
105 this._Controller.SelectionChanged += new EventHandler(Controller_SelectionChanged);
\r
107 //Viewを作成した後に追加しないと例外が発生する
\r
108 this.Document.Update += new DocumentUpdateEventHandler(Document_Update);
\r
110 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, CopyCommand, CanExecute));
\r
111 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, CutCommand, CanExecute));
\r
112 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, PasteCommand, CanExecute));
\r
113 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, DeleteCommand, CanExecute));
\r
114 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, SelectAllCommand, CanExecute));
\r
115 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, UndoCommand, CanExecute));
\r
116 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, RedoCommand, CanExecute));
\r
117 this.CommandBindings.Add(new CommandBinding(EditingCommands.ToggleInsert, ToggleInsertCommand, CanExecute));
\r
118 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleRectSelectMode, ToggleRectSelectCommand, CanExecute));
\r
119 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleFlowDirection, ToggleFlowDirectionCommand, CanExecute));
\r
120 this.CommandBindings.Add(new CommandBinding(FooTextBoxCommands.ToggleCodePoint, ToggleCodePointCommand, CanExecute));
\r
122 this.InputBindings.Add(new InputBinding(ApplicationCommands.Copy, new KeyGesture(Key.C, ModifierKeys.Control)));
\r
123 this.InputBindings.Add(new InputBinding(ApplicationCommands.Cut, new KeyGesture(Key.X, ModifierKeys.Control)));
\r
124 this.InputBindings.Add(new InputBinding(ApplicationCommands.Paste, new KeyGesture(Key.V, ModifierKeys.Control)));
\r
125 this.InputBindings.Add(new InputBinding(ApplicationCommands.Delete, new KeyGesture(Key.Delete, ModifierKeys.None)));
\r
126 this.InputBindings.Add(new InputBinding(ApplicationCommands.SelectAll, new KeyGesture(Key.A, ModifierKeys.Control)));
\r
127 this.InputBindings.Add(new InputBinding(ApplicationCommands.Undo, new KeyGesture(Key.Z, ModifierKeys.Control)));
\r
128 this.InputBindings.Add(new InputBinding(ApplicationCommands.Redo, new KeyGesture(Key.Y, ModifierKeys.Control)));
\r
129 this.InputBindings.Add(new InputBinding(EditingCommands.ToggleInsert, new KeyGesture(Key.Insert, ModifierKeys.None)));
\r
130 this.InputBindings.Add(new InputBinding(FooTextBoxCommands.ToggleCodePoint, new KeyGesture(Key.X, ModifierKeys.Alt)));
\r
132 this.timer = new DispatcherTimer();
\r
133 this.timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
\r
134 this.timer.Tick += new EventHandler(timer_Tick);
\r
136 this.Loaded += new RoutedEventHandler(FooTextBox_Loaded);
\r
138 this.AutoIndentHooker = (s,e)=>{};
\r
140 SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
\r
142 this.SystemEvents_UserPreferenceChanged(null, new UserPreferenceChangedEventArgs(UserPreferenceCategory.Keyboard));
\r
144 this.CaretMoved += (s, e) => { };
\r
152 //Dispose(false)を呼び出すと落ちる
\r
153 this.Dispose(false);
\r
157 /// オートインデントを行うためのイベント
\r
159 public AutoIndentHookerHandler AutoIndentHooker;
\r
164 public override void OnApplyTemplate()
\r
166 base.OnApplyTemplate();
\r
168 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
\r
171 Grid.SetRow(this.image, 0);
\r
172 Grid.SetColumn(this.image, 0);
\r
173 grid.Children.Add(this.image);
\r
176 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
\r
177 if (this.horizontalScrollBar != null)
\r
179 this.horizontalScrollBar.SmallChange = 10;
\r
180 this.horizontalScrollBar.LargeChange = 100;
\r
181 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
\r
182 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
\r
184 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
\r
185 if (this.verticalScrollBar != null)
\r
187 this.verticalScrollBar.SmallChange = 1;
\r
188 this.verticalScrollBar.LargeChange = 10;
\r
189 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
\r
190 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
\r
197 /// <param name="start">開始インデックス</param>
\r
198 /// <param name="length">長さ</param>
\r
199 public void Select(int start, int length)
\r
201 if (this.Document.State == AsyncState.Loading)
\r
202 throw new InvalidOperationException();
\r
203 this._Controller.Select(start, length);
\r
204 this.textStore.NotifySelectionChanged();
\r
208 /// キャレットを指定した行に移動させます
\r
210 /// <param name="index">インデックス</param>
\r
211 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
\r
212 public void JumpCaret(int index)
\r
214 if (this.Document.State == AsyncState.Loading)
\r
215 throw new InvalidOperationException();
\r
216 this._Controller.JumpCaret(index);
\r
219 /// キャレットを指定した行と桁に移動させます
\r
221 /// <param name="row">行番号</param>
\r
222 /// <param name="col">桁</param>
\r
223 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
\r
224 public void JumpCaret(int row, int col)
\r
226 if (this.Document.State == AsyncState.Loading)
\r
227 throw new InvalidOperationException();
\r
228 this._Controller.JumpCaret(row, col);
\r
232 /// 選択中のテキストをクリップボードにコピーします
\r
236 if (this.Document.State == AsyncState.Loading)
\r
237 throw new InvalidOperationException();
\r
238 string text = this._Controller.SelectedText;
\r
239 if (text != null && text != string.Empty)
\r
240 Clipboard.SetText(text);
\r
244 /// 選択中のテキストをクリップボードに切り取ります
\r
248 if (this.Document.State == AsyncState.Loading)
\r
249 throw new InvalidOperationException();
\r
250 string text = this._Controller.SelectedText;
\r
251 if (text != null && text != string.Empty)
\r
253 Clipboard.SetText(text);
\r
254 this._Controller.SelectedText = "";
\r
259 /// 選択中のテキストを貼り付けます
\r
261 public void Paste()
\r
263 if (this.Document.State == AsyncState.Loading)
\r
264 throw new InvalidOperationException();
\r
265 if (Clipboard.ContainsText() == false)
\r
267 string text = Clipboard.GetText();
\r
268 this._Controller.SelectedText = text;
\r
274 public void DeSelectAll()
\r
276 if (this.Document.State == AsyncState.Loading)
\r
277 throw new InvalidOperationException();
\r
278 this._Controller.DeSelectAll();
\r
279 this.textStore.NotifySelectionChanged();
\r
285 /// <param name="tp">テキストポイント</param>
\r
286 /// <returns>座標</returns>
\r
287 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
\r
288 public System.Windows.Point GetPostionFromTextPoint(TextPoint tp)
\r
290 if (this.Document.State == AsyncState.Loading)
\r
291 throw new InvalidOperationException();
\r
292 if (this.Document.FireUpdateEvent == false)
\r
293 throw new InvalidOperationException("");
\r
294 return this.View.GetPostionFromTextPoint(tp);
\r
298 /// 対応するテキストポイントを返します
\r
300 /// <param name="p">クライアント領域の原点を左上とする座標</param>
\r
301 /// <returns>テキストポイント</returns>
\r
302 public TextPoint GetTextPointFromPostion(System.Windows.Point p)
\r
304 if (this.Document.State == AsyncState.Loading)
\r
305 throw new InvalidOperationException();
\r
306 if (this.Document.FireUpdateEvent == false)
\r
307 throw new InvalidOperationException("");
\r
308 return this.View.GetTextPointFromPostion(p);
\r
314 /// <param name="row">レイアウト行</param>
\r
315 /// <returns>行の高さ</returns>
\r
316 public double GetLineHeight(int row)
\r
318 if (this.Document.State == AsyncState.Loading)
\r
319 throw new InvalidOperationException();
\r
320 if (this.Document.FireUpdateEvent == false)
\r
321 throw new InvalidOperationException("");
\r
322 return this.View.LayoutLines.GetLayout(row).Height;;
\r
326 /// インデックスに対応する座標を得ます
\r
328 /// <param name="index">インデックス</param>
\r
329 /// <returns>座標を返す</returns>
\r
330 public System.Windows.Point GetPostionFromIndex(int index)
\r
332 if (this.Document.State == AsyncState.Loading)
\r
333 throw new InvalidOperationException();
\r
334 if (this.Document.FireUpdateEvent == false)
\r
335 throw new InvalidOperationException("");
\r
336 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
\r
337 return this.View.GetPostionFromTextPoint(tp);
\r
341 /// 座標からインデックスに変換します
\r
343 /// <param name="p">座標</param>
\r
344 /// <returns>インデックスを返す</returns>
\r
345 public int GetIndexFromPostion(System.Windows.Point p)
\r
347 if (this.Document.State == AsyncState.Loading)
\r
348 throw new InvalidOperationException();
\r
349 if (this.Document.FireUpdateEvent == false)
\r
350 throw new InvalidOperationException("");
\r
351 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
352 return this.View.GetIndexFromLayoutLine(tp);
\r
358 public void Refresh()
\r
360 this.Refresh(this.View.PageBound);
\r
364 /// レイアウト行をすべて破棄し、再度レイアウトを行う
\r
366 public void PerfomLayouts()
\r
368 this.View.PerfomLayouts();
\r
372 /// アンマネージドリソースを開放する
\r
374 public void Dispose()
\r
378 this.Dispose(true);
\r
379 GC.SuppressFinalize(this);
\r
380 this.disposed = true;
\r
386 /// <param name="disposing">真ならマネージドリソースも開放し、そうでないならアンマネージドリソースのみを開放する</param>
\r
387 void Dispose(bool disposing)
\r
391 this.textStore.Dispose();
\r
393 this.View.Dispose();
\r
394 this.Render.Dispose();
\r
396 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
\r
397 DocumentExtend.Progress -= this.Document_Progress;
\r
400 void Refresh(Rectangle updateRect)
\r
407 this.Render.BegineDraw();
\r
408 if (this.Document.State != AsyncState.Loading)
\r
409 this.View.Draw(updateRect);
\r
411 this.Render.FillBackground(updateRect);
\r
412 this.Render.EndDraw();
\r
414 this.timer.Start();
\r
418 void CanExecute(object sender, CanExecuteRoutedEventArgs e)
\r
420 e.CanExecute = this.Document.State != FooEditEngine.AsyncState.Loading;
\r
423 void ToggleCodePointCommand(object sender, RoutedEventArgs e)
\r
425 if (!this._Controller.ConvertToChar())
\r
426 this._Controller.ConvertToCodePoint();
\r
430 void CopyCommand(object sender, RoutedEventArgs e)
\r
435 void CutCommand(object sender, RoutedEventArgs e)
\r
441 void PasteCommand(object sender, RoutedEventArgs e)
\r
447 void DeleteCommand(object sender, RoutedEventArgs e)
\r
449 int oldLength = this.Document.Length;
\r
450 this._Controller.DoDeleteAction();
\r
454 void SelectAllCommand(object sender, RoutedEventArgs e)
\r
456 this.Select(0, this.Document.Length);
\r
460 void UndoCommand(object sender, RoutedEventArgs e)
\r
462 int oldLength = this.Document.Length;
\r
463 this.Document.UndoManager.undo();
\r
467 void RedoCommand(object sender, RoutedEventArgs e)
\r
469 int oldLength = this.Document.Length;
\r
470 this.Document.UndoManager.redo();
\r
474 void ToggleInsertCommand(object sender, RoutedEventArgs e)
\r
476 if (this.InsertMode)
\r
477 this.InsertMode = false;
\r
479 this.InsertMode = true;
\r
483 void ToggleRectSelectCommand(object sender, RoutedEventArgs e)
\r
485 if (this.RectSelectMode)
\r
486 this.RectSelectMode = false;
\r
488 this.RectSelectMode = true;
\r
491 void ToggleFlowDirectionCommand(object sender, RoutedEventArgs e)
\r
493 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
\r
494 this.FlowDirection = System.Windows.FlowDirection.RightToLeft;
\r
496 this.FlowDirection = System.Windows.FlowDirection.LeftToRight;
\r
501 internal TextStore TextStore
\r
503 get { return this.textStore; }
\r
506 bool textStore_IsReadOnly()
\r
511 bool textStore_IsLoading()
\r
513 return this.Document.State == AsyncState.Loading;
\r
516 void textStore_CompositionEnded()
\r
518 TextStoreHelper.EndCompostion(this.Document);
\r
522 void textStore_CompositionUpdated(int start, int end)
\r
524 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
\r
527 bool textStore_CompositionStarted()
\r
529 bool result = TextStoreHelper.StartCompstion(this.Document);
\r
531 System.Media.SystemSounds.Beep.Play();
\r
535 string _textStore_GetString(int start, int length)
\r
537 return this.Document.ToString(start, length);
\r
540 IntPtr _textStore_GetHWnd()
\r
542 var hwndSource = HwndSource.FromVisual(this) as HwndSource;
\r
543 if (hwndSource != null)
\r
544 return hwndSource.Handle;
\r
546 return IntPtr.Zero;
\r
549 void _textStore_GetStringExtent(
\r
552 out POINT o_topLeft,
\r
553 out POINT o_bottomRight
\r
556 Point startPos, endPos;
\r
557 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
\r
559 startPos = PointToScreen(this.TranslatePoint(startPos, this));
\r
560 endPos = PointToScreen(this.TranslatePoint(endPos, this));
\r
562 o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);
\r
563 o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);
\r
566 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
\r
568 var pointTopLeft = new Point(0, 0);
\r
569 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
\r
571 pointTopLeft = PointToScreen(pointTopLeft);
\r
572 pointBottomRight = PointToScreen(pointBottomRight);
\r
574 o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
\r
575 o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
\r
578 void _textStore_GetSelectionIndex(out int o_startIndex, out int o_endIndex)
\r
580 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out o_startIndex, out o_endIndex);
\r
583 void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)
\r
585 if (this.Document.State == AsyncState.Loading)
\r
587 TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);
\r
591 void _textStore_InsertAtSelection(string i_value)
\r
593 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
\r
598 /// キーボードフォーカスが取得されたときに呼ばれます
\r
600 /// <param name="e">イベントデーター</param>
\r
601 protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
\r
603 base.OnGotKeyboardFocus(e);
\r
604 this.textStore.SetFocus();
\r
605 this.View.IsFocused = true;
\r
610 /// キーボードフォーカスが失われたときに呼ばれます
\r
612 /// <param name="e">イベントデーター</param>
\r
613 protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
\r
615 base.OnLostKeyboardFocus(e);
\r
616 this.View.IsFocused = false;
\r
622 /// キャレットが移動したときに通知されるイベント
\r
624 public event EventHandler CaretMoved;
\r
627 protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
\r
629 this.peer = new FooTextBoxAutomationPeer(this);
\r
635 protected override void OnTextInput(TextCompositionEventArgs e)
\r
637 if (this.Document.State == AsyncState.Loading)
\r
639 if (e.Text == "\r")
\r
641 this._Controller.DoEnterAction();
\r
642 this.AutoIndentHooker(this, null);
\r
644 else if (e.Text == "\b")
\r
646 this._Controller.DoBackSpaceAction();
\r
650 this._Controller.DoInputString(e.Text);
\r
653 base.OnTextInput(e);
\r
658 protected override void OnKeyDown(KeyEventArgs e)
\r
660 if (this.Document.State == AsyncState.Loading)
\r
662 if (this.textStore.IsLocked())
\r
665 ModifierKeys modiferKeys = e.KeyboardDevice.Modifiers;
\r
666 bool movedCaret = false;
\r
670 this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
676 this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
682 this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
\r
688 this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
\r
694 this._Controller.Scroll(ScrollDirection.Up,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
\r
699 this._Controller.Scroll(ScrollDirection.Down,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
\r
704 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
\r
705 this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
707 this._Controller.JumpCaret(this.View.CaretPostion.row, 0);
\r
712 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
\r
713 this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
715 this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.LayoutLines[this.View.CaretPostion.row].Length - 1);
\r
720 int oldLength = this.Document.Length;
\r
721 if (this.Selection.Length == 0)
\r
722 this._Controller.DoInputChar('\t');
\r
723 else if(this.IsPressedModifierKey(modiferKeys,ModifierKeys.Shift))
\r
724 this._Controller.DownIndent();
\r
726 this._Controller.UpIndent();
\r
731 if (movedCaret && this.peer != null)
\r
732 this.peer.OnNotifyCaretChanged();
\r
736 bool IsPressedModifierKey(ModifierKeys keys, ModifierKeys pressed)
\r
738 if (keys == pressed)
\r
740 if ((keys & pressed) == pressed)
\r
746 /// ダブルクリックされたときに呼ばれます
\r
748 /// <param name="e">イベントパラメーター</param>
\r
750 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
\r
751 /// e.Handledを真にした場合、単語単位の選択が行われなくなります
\r
753 protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
\r
755 if (this.Document.State == AsyncState.Loading)
\r
757 System.Windows.Point p = e.GetPosition(this);
\r
758 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
759 if (tp == TextPoint.Null)
\r
761 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
763 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
\r
768 newEventArgs.RoutedEvent = e.RoutedEvent;
\r
769 base.OnMouseDoubleClick(newEventArgs);
\r
771 if (newEventArgs.Handled)
\r
774 if (e.LeftButton == MouseButtonState.Pressed)
\r
777 this._Controller.SelectWord(index);
\r
778 this.textStore.NotifySelectionChanged();
\r
779 if(this.peer != null)
\r
780 this.peer.OnNotifyCaretChanged();
\r
786 /// マウスボタンが押されたときに呼ばれます
\r
788 /// <param name="e">イベントパラメーター</param>
\r
790 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
\r
791 /// e.Handledを真にした場合、キャレットの移動処理が行われなくなります
\r
793 protected override void OnMouseDown(MouseButtonEventArgs e)
\r
795 if (this.Document.State == AsyncState.Loading)
\r
798 System.Windows.Point p = e.GetPosition(this);
\r
799 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
800 if (tp == TextPoint.Null)
\r
802 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
804 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
\r
809 newEventArgs.RoutedEvent = e.RoutedEvent;
\r
810 base.OnMouseDown(newEventArgs);
\r
812 if (newEventArgs.Handled)
\r
815 if (e.LeftButton == MouseButtonState.Pressed)
\r
817 FoldingItem foldingData = this.View.HitFoldingData(p.X,tp.row);
\r
818 if (foldingData != null)
\r
820 if (foldingData.Expand)
\r
821 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
\r
823 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
\r
824 this._Controller.JumpCaret(foldingData.Start,false);
\r
828 this._Controller.JumpCaret(tp.row, tp.col, false);
\r
830 if (this.peer != null)
\r
831 this.peer.OnNotifyCaretChanged();
\r
838 /// マウスが移動したときに呼ばれます
\r
840 /// <param name="e">イベントパラメーター</param>
\r
842 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
\r
843 /// e.Handledを真にした場合、選択処理と状況に応じたカーソルの変化が行われなくなります
\r
845 protected override void OnMouseMove(MouseEventArgs e)
\r
847 if (this.Document.State == AsyncState.Loading)
\r
849 this.Cursor = Cursors.Wait;
\r
850 base.OnMouseMove(e);
\r
853 System.Windows.Point p = e.GetPosition(this);
\r
854 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
855 if (tp == TextPoint.Null)
\r
857 base.OnMouseMove(e);
\r
860 int index = this.View.GetIndexFromLayoutLine(tp);
\r
862 FooMouseEventArgs newEventArgs = new FooMouseEventArgs(e.MouseDevice, e.Timestamp, e.StylusDevice, index);
\r
863 newEventArgs.RoutedEvent = e.RoutedEvent;
\r
864 base.OnMouseMove(newEventArgs);
\r
866 if (newEventArgs.Handled)
\r
869 if (this.View.HitTextArea(p.X,p.Y))
\r
871 if (this._Controller.IsMarker(tp, HilightType.Url))
\r
872 this.Cursor = Cursors.Hand;
\r
874 this.Cursor = Cursors.IBeam;
\r
876 if (e.LeftButton == MouseButtonState.Pressed)
\r
878 this._Controller.MoveCaretAndSelect(tp);
\r
879 if (this.peer != null)
\r
880 this.peer.OnNotifyCaretChanged();
\r
886 this.Cursor = Cursors.Arrow;
\r
891 protected override void OnMouseWheel(MouseWheelEventArgs e)
\r
893 if (this.Document.State == AsyncState.Loading)
\r
895 if(Keyboard.Modifiers == ModifierKeys.None)
\r
898 this._Controller.Scroll(ScrollDirection.Up, SystemParameters.WheelScrollLines, false, false);
\r
900 this._Controller.Scroll(ScrollDirection.Down, SystemParameters.WheelScrollLines, false, false);
\r
902 else if (Keyboard.Modifiers == ModifierKeys.Control)
\r
904 double newFontSize = this.Render.FontSize;
\r
909 if (newFontSize > MaxFontSize)
\r
911 else if (newFontSize < MinFontSize)
\r
913 this.Render.FontSize = newFontSize;
\r
914 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
\r
917 base.OnMouseWheel(e);
\r
920 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
\r
922 if (e.Category == UserPreferenceCategory.Keyboard)
\r
924 int blinkTime = (int)NativeMethods.GetCaretBlinkTime();
\r
925 this.View.CaretBlink = blinkTime >= 0;
\r
926 this.View.CaretBlinkTime = blinkTime * 2;
\r
928 if (e.Category == UserPreferenceCategory.General)
\r
930 this.View.CaretWidthOnInsertMode = SystemParameters.CaretWidth;
\r
934 void Document_Update(object sender, DocumentUpdateEventArgs e)
\r
936 if (this.textStore.IsLocked() || e.type == UpdateType.Clear)
\r
938 if(e.removeLength == 0)
\r
939 this.textStore.NotifyTextChanged(e.startIndex,e.startIndex,e.startIndex + e.insertLength);
\r
941 this.textStore.NotifyTextChanged(e.startIndex,e.startIndex + 1,e.startIndex + e.insertLength - e.removeLength);
\r
944 void Document_Progress(object sender, ProgressEventArgs e)
\r
946 if (this.Document.State == AsyncState.Loading)
\r
950 case ProgressState.Start:
\r
951 this.textStore.NotifyTextChanged(0, this.Document.Length, 0);
\r
953 case ProgressState.Complete:
\r
954 this.textStore.NotifyTextChanged(0, 0, this.Document.Length);
\r
955 this.OnMouseMove(new MouseEventArgs(Mouse.PrimaryDevice, new TimeSpan(DateTime.Now.Ticks).Milliseconds));
\r
956 if(this.verticalScrollBar != null)
\r
957 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
\r
958 this.View.CalculateLineCountOnScreen();
\r
963 void timer_Tick(object sender, EventArgs e)
\r
965 if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)
\r
967 if (this.Document.State == AsyncState.Loading || this.Resize(this.image.ActualWidth, this.image.ActualHeight))
\r
973 ITextLayout layout = this.View.LayoutLines.GetLayout(this.View.CaretPostion.row);
\r
974 double width = layout.GetWidthFromIndex(this.View.CaretPostion.col);
\r
976 width = this.View.CaretWidthOnInsertMode;
\r
977 double height = layout.Height;
\r
978 Rectangle updateRect = new Rectangle(
\r
979 this.View.CaretLocation.X,
\r
980 this.View.CaretLocation.Y,
\r
984 this.Refresh(updateRect);
\r
987 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
989 if (this.Document.State == AsyncState.Loading)
\r
991 if (this.horizontalScrollBar == null)
\r
994 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
\r
995 toX = this.horizontalScrollBar.Value;
\r
997 toX = -this.horizontalScrollBar.Value;
\r
998 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
\r
1002 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
1004 if (this.Document.State == AsyncState.Loading)
\r
1006 if (this.verticalScrollBar == null)
\r
1008 int newRow = (int)this.verticalScrollBar.Value;
\r
1009 if (newRow >= this.View.LayoutLines.Count)
\r
1011 this._Controller.Scroll(this.View.Src.X,newRow, false, false);
\r
1015 void View_SrcChanged(object sender, EventArgs e)
\r
1017 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
\r
1019 EditView view = this.View;
\r
1020 if (view.Src.Row > this.verticalScrollBar.Maximum)
\r
1021 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
\r
1022 double absoulteX = Math.Abs(view.Src.X);
\r
1023 if(absoulteX > this.horizontalScrollBar.Maximum)
\r
1024 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
\r
1025 if(view.Src.Row != this.verticalScrollBar.Value)
\r
1026 this.verticalScrollBar.Value = view.Src.Row;
\r
1027 if (view.Src.X != this.horizontalScrollBar.Value)
\r
1028 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
\r
1031 void Controller_SelectionChanged(object sender, EventArgs e)
\r
1033 this.View.CaretBlink = this.View.CaretBlink;
\r
1034 this.CaretMoved(this, null);
\r
1035 //こうしないと選択できなくなってしまう
\r
1036 this.nowCaretMove = true;
\r
1037 SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
\r
1038 SetValue(CaretPostionProperty, this.View.CaretPostion);
\r
1039 this.nowCaretMove = false;
\r
1040 if(this.textStore.IsLocked() == false)
\r
1041 this.textStore.NotifySelectionChanged();
\r
1044 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
\r
1046 this.Resize(this.image.ActualWidth, this.image.ActualHeight);
\r
1049 bool Resize(double width, double height)
\r
1051 if (width == 0 || height == 0)
\r
1052 throw new ArgumentOutOfRangeException();
\r
1053 if (this.Render.Resize(width, height) && this.Document.State != AsyncState.Loading)
\r
1055 this.View.PageBound = new Rectangle(0, 0, width, height);
\r
1057 if (this.horizontalScrollBar != null)
\r
1059 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
\r
1060 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
\r
1062 if (this.verticalScrollBar != null)
\r
1064 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
\r
1065 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
\r
1073 /// プロパティーが変更されたときに呼ばれます
\r
1075 /// <param name="e">イベントパラメーター</param>
\r
1076 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
\r
1078 switch (e.Property.Name)
\r
1081 if(!this.nowCaretMove)
\r
1082 this.Select(this.Selection.Index, this.Selection.Length);
\r
1084 case "CaretPostion":
\r
1085 if (!this.nowCaretMove)
\r
1086 this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
\r
1088 case "LineBreakMethod":
\r
1089 this.View.LineBreak = this.LineBreakMethod;
\r
1091 case "LineBreakCharCount":
\r
1092 this.View.LineBreakCharCount = this.LineBreakCharCount;
\r
1094 case "InsertMode":
\r
1095 this.View.InsertMode = this.InsertMode;
\r
1098 this.View.TabStops = this.TabChars;
\r
1100 case "RectSelectMode":
\r
1101 this._Controller.RectSelection = this.RectSelectMode;
\r
1104 this.View.HideCaret = !this.DrawCaret;
\r
1106 case "DrawCaretLine":
\r
1107 this.View.HideLineMarker = !this.DrawCaretLine;
\r
1109 case "DrawLineNumber":
\r
1110 this.View.DrawLineNumber = this.DrawLineNumber;
\r
1111 this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);
\r
1113 case "FontFamily":
\r
1114 this.Render.FontFamily = this.FontFamily;
\r
1117 this.Render.FontSize = this.FontSize;
\r
1120 this.Render.FontStyle = this.FontStyle;
\r
1122 case "FontWeight":
\r
1123 this.Render.FontWeigth = this.FontWeight;
\r
1125 case "Foreground":
\r
1126 this.Render.Foreground = this.Foreground;
\r
1128 case "Background":
\r
1129 this.Render.Background = this.Background;
\r
1131 case "ControlChar":
\r
1132 this.Render.ControlChar = this.ControlChar;
\r
1135 this.Render.Hilight = this.Hilight;
\r
1138 this.Render.Keyword1 = this.Keyword1;
\r
1141 this.Render.Keyword2 = this.Keyword2;
\r
1144 this.Render.Comment = this.Comment;
\r
1147 this.Render.Literal = this.Literal;
\r
1150 this.Render.Url = this.URL;
\r
1152 case "InsertCaret":
\r
1153 this.Render.InsertCaret = this.InsertCaret;
\r
1155 case "OverwriteCaret":
\r
1156 this.Render.OverwriteCaret = this.OverwriteCaret;
\r
1158 case "LineMarker":
\r
1159 this.Render.LineMarker = this.LineMarker;
\r
1162 this.View.UrlMark = this.MarkURL;
\r
1164 case "ShowFullSpace":
\r
1165 this.Render.ShowFullSpace = this.ShowFullSpace;
\r
1167 case "ShowHalfSpace":
\r
1168 this.Render.ShowHalfSpace = this.ShowHalfSpace;
\r
1171 this.Render.ShowTab = this.ShowTab;
\r
1173 case "ShowLineBreak":
\r
1174 this.Render.ShowLineBreak = this.ShowLineBreak;
\r
1176 case "FlowDirection":
\r
1177 this.Render.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;
\r
1178 this.horizontalScrollBar.FlowDirection = this.FlowDirection;
\r
1181 this.View.HideRuler = !this.DrawRuler;
\r
1182 this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);
\r
1185 base.OnPropertyChanged(e);
\r
1190 internal Controller Controller
\r
1194 return this._Controller;
\r
1199 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
\r
1201 public TextAntialiasMode TextAntialiasMode
\r
1205 return this.Render.TextAntialiasMode;
\r
1209 this.Render.TextAntialiasMode = value;
\r
1214 /// シンタックスハイライターを表す
\r
1216 public IHilighter Hilighter
\r
1220 return this.View.Hilighter;
\r
1224 this.View.Hilighter = value;
\r
1225 this.View.LayoutLines.ClearLayoutCache();
\r
1230 /// フォールティングを作成するインターフェイスを表す
\r
1232 public IFoldingStrategy FoldingStrategy
\r
1236 return this.View.LayoutLines.FoldingStrategy;
\r
1240 this.View.LayoutLines.FoldingStrategy = value;
\r
1241 if (value == null)
\r
1242 this.View.LayoutLines.FoldingCollection.Clear();
\r
1249 public Document Document
\r
1258 public LineToIndexTable LayoutLineCollection
\r
1260 get { return this.View.LayoutLines; }
\r
1266 public string SelectedText
\r
1270 return this._Controller.SelectedText;
\r
1274 int oldLength = this.Document.Length;
\r
1275 this._Controller.SelectedText = value;
\r
1283 /// Lengthが0の場合はキャレット位置を表します。
\r
1284 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
\r
1286 public TextRange Selection
\r
1288 get { return (TextRange)GetValue(SelectionProperty); }
\r
1289 set { SetValue(SelectionProperty, value); }
\r
1293 /// Selectionの依存プロパティを表す
\r
1295 public static readonly DependencyProperty SelectionProperty =
\r
1296 DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null));
\r
1301 public double MagnificationPower
\r
1303 get { return (double)GetValue(MagnificationPowerPropertyKey.DependencyProperty); }
\r
1309 public static readonly DependencyPropertyKey MagnificationPowerPropertyKey =
\r
1310 DependencyProperty.RegisterReadOnly("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0));
\r
1315 public new FlowDirection FlowDirection
\r
1317 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
\r
1318 set { SetValue(FlowDirectionProperty, value); }
\r
1322 /// レタリング方向を表す。これは依存プロパティです
\r
1324 public new static readonly DependencyProperty FlowDirectionProperty =
\r
1325 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight));
\r
1328 /// キャレット位置を表す。これは依存プロパティです
\r
1330 public TextPoint CaretPostion
\r
1332 get { return (TextPoint)GetValue(CaretPostionProperty); }
\r
1333 set { SetValue(CaretPostionProperty, value); }
\r
1336 // Using a DependencyProperty as the backing store for CaretPostion. This enables animation, styling, binding, etc...
\r
1337 public static readonly DependencyProperty CaretPostionProperty =
\r
1338 DependencyProperty.Register("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new PropertyMetadata(TextPoint.Null));
\r
1341 /// デフォルトの文字色を表す。これは依存プロパティです
\r
1343 public new System.Windows.Media.Color Foreground
\r
1345 get { return (System.Windows.Media.Color)GetValue(ForegroundProperty); }
\r
1346 set { SetValue(ForegroundProperty, value); }
\r
1350 /// Foregroundの依存プロパティを表す
\r
1352 public new static readonly DependencyProperty ForegroundProperty =
\r
1353 DependencyProperty.Register("Foreground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
\r
1356 /// 背景色を表す。これは依存プロパティです
\r
1358 public new System.Windows.Media.Color Background
\r
1360 get { return (System.Windows.Media.Color)GetValue(BackgroundProperty); }
\r
1361 set { SetValue(BackgroundProperty, value); }
\r
1365 /// Backgroundの依存プロパティを表す
\r
1367 public new static readonly DependencyProperty BackgroundProperty =
\r
1368 DependencyProperty.Register("Background", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowColor));
\r
1371 /// コントロールコードの文字色を表す。これは依存プロパティです
\r
1373 public System.Windows.Media.Color ControlChar
\r
1375 get { return (System.Windows.Media.Color)GetValue(ControlCharProperty); }
\r
1376 set { SetValue(ControlCharProperty, value); }
\r
1380 /// ControlCharの依存プロパティを表す
\r
1382 public static readonly DependencyProperty ControlCharProperty =
\r
1383 DependencyProperty.Register("ControlChar", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Gray));
\r
1386 /// 選択時の背景色を表す。これは依存プロパティです
\r
1388 public System.Windows.Media.Color Hilight
\r
1390 get { return (System.Windows.Media.Color)GetValue(HilightProperty); }
\r
1391 set { SetValue(HilightProperty, value); }
\r
1395 /// Hilightの依存プロパティを表す
\r
1397 public static readonly DependencyProperty HilightProperty =
\r
1398 DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));
\r
1401 /// キーワード1の文字色を表す。これは依存プロパティです
\r
1403 public System.Windows.Media.Color Keyword1
\r
1405 get { return (System.Windows.Media.Color)GetValue(Keyword1Property); }
\r
1406 set { SetValue(Keyword1Property, value); }
\r
1410 /// Keyword1の依存プロパティを表す
\r
1412 public static readonly DependencyProperty Keyword1Property =
\r
1413 DependencyProperty.Register("Keyword1", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
\r
1416 /// キーワード2の文字色を表す。これは依存プロパティです
\r
1418 public System.Windows.Media.Color Keyword2
\r
1420 get { return (System.Windows.Media.Color)GetValue(Keyword2Property); }
\r
1421 set { SetValue(Keyword2Property, value); }
\r
1425 /// Keyword2の依存プロパティを表す
\r
1427 public static readonly DependencyProperty Keyword2Property =
\r
1428 DependencyProperty.Register("Keyword2", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DarkCyan));
\r
1431 /// コメントの文字色を表す。これは依存プロパティです
\r
1433 public System.Windows.Media.Color Comment
\r
1435 get { return (System.Windows.Media.Color)GetValue(CommentProperty); }
\r
1436 set { SetValue(CommentProperty, value); }
\r
1440 /// Commentの依存プロパティを表す
\r
1442 public static readonly DependencyProperty CommentProperty =
\r
1443 DependencyProperty.Register("Comment", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Green));
\r
1446 /// 文字リテラルの文字色を表す。これは依存プロパティです
\r
1448 public System.Windows.Media.Color Literal
\r
1450 get { return (System.Windows.Media.Color)GetValue(LiteralProperty); }
\r
1451 set { SetValue(LiteralProperty, value); }
\r
1455 /// Literalの依存プロパティを表す
\r
1457 public static readonly DependencyProperty LiteralProperty =
\r
1458 DependencyProperty.Register("Literal", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Brown));
\r
1461 /// URLの文字色を表す。これは依存プロパティです
\r
1463 public System.Windows.Media.Color URL
\r
1465 get { return (System.Windows.Media.Color)GetValue(URLProperty); }
\r
1466 set { SetValue(URLProperty, value); }
\r
1470 /// URLの依存プロパティを表す
\r
1472 public static readonly DependencyProperty URLProperty =
\r
1473 DependencyProperty.Register("URL", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
\r
1479 public System.Windows.Media.Color LineMarker
\r
1481 get { return (System.Windows.Media.Color)GetValue(LineMarkerProperty); }
\r
1482 set { SetValue(LineMarkerProperty, value); }
\r
1486 /// LineMarkerの依存プロパティを表す
\r
1488 public static readonly DependencyProperty LineMarkerProperty =
\r
1489 DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));
\r
1492 /// 挿入モード時のキャレットの色を表す
\r
1494 public System.Windows.Media.Color InsertCaret
\r
1496 get { return (System.Windows.Media.Color)GetValue(InsertCaretProperty); }
\r
1497 set { SetValue(InsertCaretProperty, value); }
\r
1501 /// InsertCaretの依存プロパティを表す
\r
1503 public static readonly DependencyProperty InsertCaretProperty =
\r
1504 DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
\r
1507 /// 上書きモード時のキャレット職を表す
\r
1509 public System.Windows.Media.Color OverwriteCaret
\r
1511 get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }
\r
1512 set { SetValue(OverwriteCaretProperty, value); }
\r
1516 /// OverwriteCaretの依存プロパティを表す
\r
1518 public static readonly DependencyProperty OverwriteCaretProperty =
\r
1519 DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
\r
1522 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
\r
1524 public bool InsertMode
\r
1526 get { return (bool)GetValue(InsertModeProperty); }
\r
1527 set { SetValue(InsertModeProperty, value); }
\r
1531 /// InsertModeの依存プロパティを表す
\r
1533 public static readonly DependencyProperty InsertModeProperty =
\r
1534 DependencyProperty.Register("InsertMode",
\r
1536 typeof(FooTextBox),
\r
1537 new FrameworkPropertyMetadata(true));
\r
1540 /// タブの文字数を表す。これは依存プロパティです
\r
1542 public int TabChars
\r
1544 get { return (int)GetValue(TabCharsProperty); }
\r
1545 set { SetValue(TabCharsProperty, value); }
\r
1549 /// TabCharsの依存プロパティを表す
\r
1551 public static readonly DependencyProperty TabCharsProperty =
\r
1552 DependencyProperty.Register("TabChars",
\r
1554 typeof(FooTextBox),
\r
1555 new FrameworkPropertyMetadata(4));
\r
1558 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
\r
1560 public bool RectSelectMode
\r
1562 get { return (bool)GetValue(RectSelectModeProperty); }
\r
1563 set { SetValue(RectSelectModeProperty, value); }
\r
1567 /// RectSelectModeの依存プロパティを表す
\r
1569 public static readonly DependencyProperty RectSelectModeProperty =
\r
1570 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1576 /// 変更した場合、レイアウトの再構築を行う必要があります
\r
1578 public LineBreakMethod LineBreakMethod
\r
1580 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
\r
1581 set { SetValue(LineBreakProperty, value); }
\r
1585 /// LineBreakMethodの依存プロパティを表す
\r
1587 public static readonly DependencyProperty LineBreakProperty =
\r
1588 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None));
\r
1592 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
\r
1595 /// 変更した場合、レイアウトの再構築を行う必要があります
\r
1597 public int LineBreakCharCount
\r
1599 get { return (int)GetValue(LineBreakCharCountProperty); }
\r
1600 set { SetValue(LineBreakCharCountProperty, value); }
\r
1604 /// LineBreakCharCountの依存プロパティを表す
\r
1606 public static readonly DependencyProperty LineBreakCharCountProperty =
\r
1607 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
\r
1610 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
\r
1612 public bool DrawCaret
\r
1614 get { return (bool)GetValue(DrawCaretProperty); }
\r
1615 set { SetValue(DrawCaretProperty, value); }
\r
1619 /// DrawCaretの依存プロパティを表す
\r
1621 public static readonly DependencyProperty DrawCaretProperty =
\r
1622 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
\r
1626 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
\r
1628 public bool DrawCaretLine
\r
1630 get { return (bool)GetValue(DrawCaretLineProperty); }
\r
1631 set { SetValue(DrawCaretLineProperty, value); }
\r
1635 /// DrawCaretLineの依存プロパティを表す
\r
1637 public static readonly DependencyProperty DrawCaretLineProperty =
\r
1638 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1641 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
\r
1643 public bool DrawLineNumber
\r
1645 get { return (bool)GetValue(DrawLineNumberProperty); }
\r
1646 set { SetValue(DrawLineNumberProperty, value); }
\r
1650 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
\r
1652 public bool DrawRuler
\r
1654 get { return (bool)GetValue(DrawRulerProperty); }
\r
1655 set { SetValue(DrawRulerProperty, value); }
\r
1659 /// DrawRulerの依存プロパティを表す
\r
1661 public static readonly DependencyProperty DrawRulerProperty =
\r
1662 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
\r
1666 /// DrawLineNumberの依存プロパティを表す
\r
1668 public static readonly DependencyProperty DrawLineNumberProperty =
\r
1669 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1672 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
\r
1674 public bool MarkURL
\r
1676 get { return (bool)GetValue(MarkURLProperty); }
\r
1677 set { SetValue(MarkURLProperty, value); }
\r
1681 /// MarkURLの依存プロパティを表す
\r
1683 public static readonly DependencyProperty MarkURLProperty =
\r
1684 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1687 /// 全角スペースを表示するなら真。そうでないなら偽
\r
1689 public bool ShowFullSpace
\r
1691 get { return (bool)GetValue(ShowFullSpaceProperty); }
\r
1692 set { SetValue(ShowFullSpaceProperty, value); }
\r
1696 /// ShowFullSpaceの依存プロパティを表す
\r
1698 public static readonly DependencyProperty ShowFullSpaceProperty =
\r
1699 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
\r
1702 /// 半角スペースを表示するなら真。そうでないなら偽
\r
1704 public bool ShowHalfSpace
\r
1706 get { return (bool)GetValue(ShowHalfSpaceProperty); }
\r
1707 set { SetValue(ShowHalfSpaceProperty, value); }
\r
1711 /// ShowHalfSpaceの依存プロパティを表す
\r
1713 public static readonly DependencyProperty ShowHalfSpaceProperty =
\r
1714 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
\r
1717 /// タブを表示するなら真。そうでないなら偽
\r
1719 public bool ShowTab
\r
1721 get { return (bool)GetValue(ShowTabProperty); }
\r
1722 set { SetValue(ShowTabProperty, value); }
\r
1726 /// ShowTabの依存プロパティを表す
\r
1728 public static readonly DependencyProperty ShowTabProperty =
\r
1729 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
\r
1732 /// 改行マークを表示するなら真。そうでないなら偽
\r
1734 public bool ShowLineBreak
\r
1736 get { return (bool)GetValue(ShowLineBreakProperty); }
\r
1737 set { SetValue(ShowLineBreakProperty, value); }
\r
1741 /// ShowLineBreakの依存プロパティを表す
\r
1743 public static readonly DependencyProperty ShowLineBreakProperty =
\r
1744 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
\r
1749 /// マウスボタン関連のイベントクラス
\r
1751 public sealed class FooMouseButtonEventArgs : MouseButtonEventArgs
\r
1754 /// イベントが発生したドキュメントのインデックス
\r
1765 /// <param name="mouse">マウスデバイス</param>
\r
1766 /// <param name="timestamp">タイムスタンプ</param>
\r
1767 /// <param name="button">ボタン</param>
\r
1768 /// <param name="stylusDevice">スタイラスデバイス</param>
\r
1769 /// <param name="index">インデックス</param>
\r
1770 public FooMouseButtonEventArgs(MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice, int index)
\r
1771 : base(mouse, timestamp, button, stylusDevice)
\r
1773 this.Index = index;
\r
1779 public sealed class FooMouseEventArgs : MouseEventArgs
\r
1782 /// イベントが発生したドキュメントのインデックス
\r
1793 /// <param name="mouse">マウスデバイス</param>
\r
1794 /// <param name="timestamp">タイムスタンプ</param>
\r
1795 /// <param name="stylusDevice">スタイラスデバイス</param>
\r
1796 /// <param name="index">インデックス</param>
\r
1797 public FooMouseEventArgs(MouseDevice mouse,
\r
1799 StylusDevice stylusDevice,
\r
1801 : base(mouse, timestamp, stylusDevice)
\r
1803 this.Index = index;
\r