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 += new EventHandler<ProgressEventArgs>(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
143 this.CaretMoved += (s, e) => { };
\r
151 //Dispose(false)を呼び出すと落ちる
\r
152 this.Dispose(false);
\r
156 /// オートインデントを行うためのイベント
\r
158 public AutoIndentHookerHandler AutoIndentHooker;
\r
163 public override void OnApplyTemplate()
\r
165 base.OnApplyTemplate();
\r
167 Grid grid = this.GetTemplateChild("PART_Grid") as Grid;
\r
170 Grid.SetRow(this.image, 0);
\r
171 Grid.SetColumn(this.image, 0);
\r
172 grid.Children.Add(this.image);
\r
175 this.horizontalScrollBar = this.GetTemplateChild("PART_HorizontalScrollBar") as ScrollBar;
\r
176 if (this.horizontalScrollBar != null)
\r
178 this.horizontalScrollBar.SmallChange = 10;
\r
179 this.horizontalScrollBar.LargeChange = 100;
\r
180 this.horizontalScrollBar.Maximum = this.horizontalScrollBar.LargeChange + 1;
\r
181 this.horizontalScrollBar.Scroll += new ScrollEventHandler(horizontalScrollBar_Scroll);
\r
183 this.verticalScrollBar = this.GetTemplateChild("PART_VerticalScrollBar") as ScrollBar;
\r
184 if (this.verticalScrollBar != null)
\r
186 this.verticalScrollBar.SmallChange = 1;
\r
187 this.verticalScrollBar.LargeChange = 10;
\r
188 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
\r
189 this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
\r
196 /// <param name="start">開始インデックス</param>
\r
197 /// <param name="length">長さ</param>
\r
198 public void Select(int start, int length)
\r
200 if (this.Document.State == AsyncState.Loading)
\r
201 throw new InvalidOperationException();
\r
202 this._Controller.Select(start, length);
\r
203 this.textStore.NotifySelectionChanged();
\r
207 /// キャレットを指定した行に移動させます
\r
209 /// <param name="index">インデックス</param>
\r
210 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
\r
211 public void JumpCaret(int index)
\r
213 if (this.Document.State == AsyncState.Loading)
\r
214 throw new InvalidOperationException();
\r
215 this._Controller.JumpCaret(index);
\r
218 /// キャレットを指定した行と桁に移動させます
\r
220 /// <param name="row">行番号</param>
\r
221 /// <param name="col">桁</param>
\r
222 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
\r
223 public void JumpCaret(int row, int col)
\r
225 if (this.Document.State == AsyncState.Loading)
\r
226 throw new InvalidOperationException();
\r
227 this._Controller.JumpCaret(row, col);
\r
231 /// 選択中のテキストをクリップボードにコピーします
\r
235 if (this.Document.State == AsyncState.Loading)
\r
236 throw new InvalidOperationException();
\r
237 string text = this._Controller.SelectedText;
\r
238 if (text != null && text != string.Empty)
\r
239 Clipboard.SetText(text);
\r
243 /// 選択中のテキストをクリップボードに切り取ります
\r
247 if (this.Document.State == AsyncState.Loading)
\r
248 throw new InvalidOperationException();
\r
249 string text = this._Controller.SelectedText;
\r
250 if (text != null && text != string.Empty)
\r
252 Clipboard.SetText(text);
\r
253 this._Controller.SelectedText = "";
\r
258 /// 選択中のテキストを貼り付けます
\r
260 public void Paste()
\r
262 if (this.Document.State == AsyncState.Loading)
\r
263 throw new InvalidOperationException();
\r
264 if (Clipboard.ContainsText() == false)
\r
266 string text = Clipboard.GetText();
\r
267 this._Controller.SelectedText = text;
\r
273 public void DeSelectAll()
\r
275 if (this.Document.State == AsyncState.Loading)
\r
276 throw new InvalidOperationException();
\r
277 this._Controller.DeSelectAll();
\r
278 this.textStore.NotifySelectionChanged();
\r
284 /// <param name="tp">テキストポイント</param>
\r
285 /// <returns>座標</returns>
\r
286 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
\r
287 public System.Windows.Point GetPostionFromTextPoint(TextPoint tp)
\r
289 if (this.Document.State == AsyncState.Loading)
\r
290 throw new InvalidOperationException();
\r
291 if (this.Document.FireUpdateEvent == false)
\r
292 throw new InvalidOperationException("");
\r
293 return this.View.GetPostionFromTextPoint(tp);
\r
297 /// 対応するテキストポイントを返します
\r
299 /// <param name="p">クライアント領域の原点を左上とする座標</param>
\r
300 /// <returns>テキストポイント</returns>
\r
301 public TextPoint GetTextPointFromPostion(System.Windows.Point p)
\r
303 if (this.Document.State == AsyncState.Loading)
\r
304 throw new InvalidOperationException();
\r
305 if (this.Document.FireUpdateEvent == false)
\r
306 throw new InvalidOperationException("");
\r
307 return this.View.GetTextPointFromPostion(p);
\r
313 /// <param name="row">レイアウト行</param>
\r
314 /// <returns>行の高さ</returns>
\r
315 public double GetLineHeight(int row)
\r
317 if (this.Document.State == AsyncState.Loading)
\r
318 throw new InvalidOperationException();
\r
319 if (this.Document.FireUpdateEvent == false)
\r
320 throw new InvalidOperationException("");
\r
321 return this.View.LayoutLines.GetLayout(row).Height;;
\r
325 /// インデックスに対応する座標を得ます
\r
327 /// <param name="index">インデックス</param>
\r
328 /// <returns>座標を返す</returns>
\r
329 public System.Windows.Point GetPostionFromIndex(int index)
\r
331 if (this.Document.State == AsyncState.Loading)
\r
332 throw new InvalidOperationException();
\r
333 if (this.Document.FireUpdateEvent == false)
\r
334 throw new InvalidOperationException("");
\r
335 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
\r
336 return this.View.GetPostionFromTextPoint(tp);
\r
340 /// 座標からインデックスに変換します
\r
342 /// <param name="p">座標</param>
\r
343 /// <returns>インデックスを返す</returns>
\r
344 public int GetIndexFromPostion(System.Windows.Point p)
\r
346 if (this.Document.State == AsyncState.Loading)
\r
347 throw new InvalidOperationException();
\r
348 if (this.Document.FireUpdateEvent == false)
\r
349 throw new InvalidOperationException("");
\r
350 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
351 return this.View.GetIndexFromLayoutLine(tp);
\r
357 public void Refresh()
\r
359 this.Refresh(this.View.PageBound);
\r
363 /// レイアウト行をすべて破棄し、再度レイアウトを行う
\r
365 public void PerfomLayouts()
\r
367 this.View.PerfomLayouts();
\r
371 /// アンマネージドリソースを開放する
\r
373 public void Dispose()
\r
377 this.Dispose(true);
\r
378 GC.SuppressFinalize(this);
\r
379 this.disposed = true;
\r
385 /// <param name="disposing">真ならマネージドリソースも開放し、そうでないならアンマネージドリソースのみを開放する</param>
\r
386 void Dispose(bool disposing)
\r
390 this.textStore.Dispose();
\r
392 this.View.Dispose();
\r
393 this.Render.Dispose();
\r
395 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
\r
396 DocumentExtend.Progress -= this.Document_Progress;
\r
399 void Refresh(Rectangle updateRect)
\r
406 this.Render.BegineDraw();
\r
407 if (this.Document.State != AsyncState.Loading)
\r
408 this.View.Draw(updateRect);
\r
410 this.Render.FillBackground(updateRect);
\r
411 this.Render.EndDraw();
\r
413 this.timer.Start();
\r
417 void CanExecute(object sender, CanExecuteRoutedEventArgs e)
\r
419 e.CanExecute = this.Document.State != FooEditEngine.AsyncState.Loading;
\r
422 void ToggleCodePointCommand(object sender, RoutedEventArgs e)
\r
424 if (!this._Controller.ConvertToChar())
\r
425 this._Controller.ConvertToCodePoint();
\r
429 void CopyCommand(object sender, RoutedEventArgs e)
\r
434 void CutCommand(object sender, RoutedEventArgs e)
\r
440 void PasteCommand(object sender, RoutedEventArgs e)
\r
446 void DeleteCommand(object sender, RoutedEventArgs e)
\r
448 int oldLength = this.Document.Length;
\r
449 this._Controller.DoDeleteAction();
\r
453 void SelectAllCommand(object sender, RoutedEventArgs e)
\r
455 this.Select(0, this.Document.Length);
\r
459 void UndoCommand(object sender, RoutedEventArgs e)
\r
461 int oldLength = this.Document.Length;
\r
462 this.Document.UndoManager.undo();
\r
466 void RedoCommand(object sender, RoutedEventArgs e)
\r
468 int oldLength = this.Document.Length;
\r
469 this.Document.UndoManager.redo();
\r
473 void ToggleInsertCommand(object sender, RoutedEventArgs e)
\r
475 if (this.InsertMode)
\r
476 this.InsertMode = false;
\r
478 this.InsertMode = true;
\r
482 void ToggleRectSelectCommand(object sender, RoutedEventArgs e)
\r
484 if (this.RectSelectMode)
\r
485 this.RectSelectMode = false;
\r
487 this.RectSelectMode = true;
\r
490 void ToggleFlowDirectionCommand(object sender, RoutedEventArgs e)
\r
492 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
\r
493 this.FlowDirection = System.Windows.FlowDirection.RightToLeft;
\r
495 this.FlowDirection = System.Windows.FlowDirection.LeftToRight;
\r
500 internal TextStore TextStore
\r
502 get { return this.textStore; }
\r
505 bool textStore_IsReadOnly()
\r
510 bool textStore_IsLoading()
\r
512 return this.Document.State == AsyncState.Loading;
\r
515 void textStore_CompositionEnded()
\r
517 TextStoreHelper.EndCompostion(this.Document);
\r
521 void textStore_CompositionUpdated(int start, int end)
\r
523 if (TextStoreHelper.ScrollToCompstionUpdated(this.textStore, this.View, start, end))
\r
526 bool textStore_CompositionStarted()
\r
528 bool result = TextStoreHelper.StartCompstion(this.Document);
\r
530 System.Media.SystemSounds.Beep.Play();
\r
534 string _textStore_GetString(int start, int length)
\r
536 return this.Document.ToString(start, length);
\r
539 IntPtr _textStore_GetHWnd()
\r
541 var hwndSource = HwndSource.FromVisual(this) as HwndSource;
\r
542 if (hwndSource != null)
\r
543 return hwndSource.Handle;
\r
545 return IntPtr.Zero;
\r
548 void _textStore_GetStringExtent(
\r
551 out POINT o_topLeft,
\r
552 out POINT o_bottomRight
\r
555 Point startPos, endPos;
\r
556 TextStoreHelper.GetStringExtent(this.Document, this.View, i_startIndex, i_endIndex, out startPos, out endPos);
\r
558 startPos = PointToScreen(this.TranslatePoint(startPos, this));
\r
559 endPos = PointToScreen(this.TranslatePoint(endPos, this));
\r
561 o_topLeft = new POINT((int)startPos.X, (int)startPos.Y);
\r
562 o_bottomRight = new POINT((int)endPos.X, (int)endPos.Y);
\r
565 void _textStore_GetScreenExtent(out POINT o_topLeft, out POINT o_bottomRight)
\r
567 var pointTopLeft = new Point(0, 0);
\r
568 var pointBottomRight = new Point(this.RenderSize.Width, this.RenderSize.Height);
\r
570 pointTopLeft = PointToScreen(pointTopLeft);
\r
571 pointBottomRight = PointToScreen(pointBottomRight);
\r
573 o_topLeft = new POINT((int)pointTopLeft.X, (int)pointTopLeft.Y);
\r
574 o_bottomRight = new POINT((int)pointBottomRight.X, (int)pointBottomRight.Y);
\r
577 void _textStore_GetSelectionIndex(out int o_startIndex, out int o_endIndex)
\r
579 TextStoreHelper.GetSelection(this._Controller, this.View.Selections, out o_startIndex, out o_endIndex);
\r
582 void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)
\r
584 if (this.Document.State == AsyncState.Loading)
\r
586 TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);
\r
590 void _textStore_InsertAtSelection(string i_value)
\r
592 TextStoreHelper.InsertTextAtSelection(this._Controller, i_value);
\r
597 /// キーボードフォーカスが取得されたときに呼ばれます
\r
599 /// <param name="e">イベントデーター</param>
\r
600 protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
\r
602 base.OnGotKeyboardFocus(e);
\r
603 this.textStore.SetFocus();
\r
604 this.View.IsFocused = true;
\r
609 /// キーボードフォーカスが失われたときに呼ばれます
\r
611 /// <param name="e">イベントデーター</param>
\r
612 protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
\r
614 base.OnLostKeyboardFocus(e);
\r
615 this.View.IsFocused = false;
\r
621 /// キャレットが移動したときに通知されるイベント
\r
623 public event EventHandler CaretMoved;
\r
626 protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
\r
628 this.peer = new FooTextBoxAutomationPeer(this);
\r
634 protected override void OnTextInput(TextCompositionEventArgs e)
\r
636 if (this.Document.State == AsyncState.Loading)
\r
638 if (e.Text == "\r")
\r
640 this._Controller.DoEnterAction();
\r
641 this.AutoIndentHooker(this, null);
\r
643 else if (e.Text == "\b")
\r
645 this._Controller.DoBackSpaceAction();
\r
649 this._Controller.DoInputString(e.Text);
\r
652 base.OnTextInput(e);
\r
657 protected override void OnKeyDown(KeyEventArgs e)
\r
659 if (this.Document.State == AsyncState.Loading)
\r
661 if (this.textStore.IsLocked())
\r
664 ModifierKeys modiferKeys = e.KeyboardDevice.Modifiers;
\r
665 bool movedCaret = false;
\r
669 this._Controller.MoveCaretVertical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
675 this._Controller.MoveCaretVertical(+1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
681 this._Controller.MoveCaretHorizontical(-1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
\r
687 this._Controller.MoveCaretHorizontical(1, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift), this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control));
\r
693 this._Controller.Scroll(ScrollDirection.Up,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
\r
698 this._Controller.Scroll(ScrollDirection.Down,this.View.LineCountOnScreen, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift),true);
\r
703 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
\r
704 this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
706 this._Controller.JumpCaret(this.View.CaretPostion.row, 0);
\r
711 if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
\r
712 this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
\r
714 this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.LayoutLines[this.View.CaretPostion.row].Length - 1);
\r
719 int oldLength = this.Document.Length;
\r
720 if (this.SelectionLength == 0)
\r
721 this._Controller.DoInputChar('\t');
\r
722 else if(this.IsPressedModifierKey(modiferKeys,ModifierKeys.Shift))
\r
723 this._Controller.DownIndent();
\r
725 this._Controller.UpIndent();
\r
730 if (movedCaret && this.peer != null)
\r
731 this.peer.OnNotifyCaretChanged();
\r
735 bool IsPressedModifierKey(ModifierKeys keys, ModifierKeys pressed)
\r
737 if (keys == pressed)
\r
739 if ((keys & pressed) == pressed)
\r
745 /// ダブルクリックされたときに呼ばれます
\r
747 /// <param name="e">イベントパラメーター</param>
\r
749 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
\r
750 /// e.Handledを真にした場合、単語単位の選択が行われなくなります
\r
752 protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
\r
754 if (this.Document.State == AsyncState.Loading)
\r
756 System.Windows.Point p = e.GetPosition(this);
\r
757 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
758 if (tp == TextPoint.Null)
\r
760 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
762 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
\r
767 newEventArgs.RoutedEvent = e.RoutedEvent;
\r
768 base.OnMouseDoubleClick(newEventArgs);
\r
770 if (newEventArgs.Handled)
\r
773 if (e.LeftButton == MouseButtonState.Pressed)
\r
776 this._Controller.SelectWord(index);
\r
777 this.textStore.NotifySelectionChanged();
\r
778 if(this.peer != null)
\r
779 this.peer.OnNotifyCaretChanged();
\r
785 /// マウスボタンが押されたときに呼ばれます
\r
787 /// <param name="e">イベントパラメーター</param>
\r
789 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
\r
790 /// e.Handledを真にした場合、キャレットの移動処理が行われなくなります
\r
792 protected override void OnMouseDown(MouseButtonEventArgs e)
\r
794 if (this.Document.State == AsyncState.Loading)
\r
797 System.Windows.Point p = e.GetPosition(this);
\r
798 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
799 if (tp == TextPoint.Null)
\r
801 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
803 FooMouseButtonEventArgs newEventArgs = new FooMouseButtonEventArgs(e.MouseDevice,
\r
808 newEventArgs.RoutedEvent = e.RoutedEvent;
\r
809 base.OnMouseDown(newEventArgs);
\r
811 if (newEventArgs.Handled)
\r
814 if (e.LeftButton == MouseButtonState.Pressed)
\r
816 FoldingItem foldingData = this.View.HitFoldingData(p.X,tp.row);
\r
817 if (foldingData != null)
\r
819 if (foldingData.Expand)
\r
820 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
\r
822 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
\r
823 this._Controller.JumpCaret(foldingData.Start,false);
\r
827 this._Controller.JumpCaret(tp.row, tp.col, false);
\r
829 if (this.peer != null)
\r
830 this.peer.OnNotifyCaretChanged();
\r
837 /// マウスが移動したときに呼ばれます
\r
839 /// <param name="e">イベントパラメーター</param>
\r
841 /// イベントパラメーターはFooMouseEventArgsにキャスト可能です。
\r
842 /// e.Handledを真にした場合、選択処理と状況に応じたカーソルの変化が行われなくなります
\r
844 protected override void OnMouseMove(MouseEventArgs e)
\r
846 if (this.Document.State == AsyncState.Loading)
\r
848 this.Cursor = Cursors.Wait;
\r
849 base.OnMouseMove(e);
\r
852 System.Windows.Point p = e.GetPosition(this);
\r
853 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
854 if (tp == TextPoint.Null)
\r
856 base.OnMouseMove(e);
\r
859 int index = this.View.GetIndexFromLayoutLine(tp);
\r
861 FooMouseEventArgs newEventArgs = new FooMouseEventArgs(e.MouseDevice, e.Timestamp, e.StylusDevice, index);
\r
862 newEventArgs.RoutedEvent = e.RoutedEvent;
\r
863 base.OnMouseMove(newEventArgs);
\r
865 if (newEventArgs.Handled)
\r
868 if (this.View.HitTextArea(p.X,p.Y))
\r
870 if (this._Controller.IsMarker(tp, HilightType.Url))
\r
871 this.Cursor = Cursors.Hand;
\r
873 this.Cursor = Cursors.IBeam;
\r
875 if (e.LeftButton == MouseButtonState.Pressed)
\r
877 this._Controller.MoveCaretAndSelect(tp);
\r
878 if (this.peer != null)
\r
879 this.peer.OnNotifyCaretChanged();
\r
885 this.Cursor = Cursors.Arrow;
\r
890 protected override void OnMouseWheel(MouseWheelEventArgs e)
\r
892 if (this.Document.State == AsyncState.Loading)
\r
894 if(Keyboard.Modifiers == ModifierKeys.None)
\r
897 this._Controller.Scroll(ScrollDirection.Up, SystemParameters.WheelScrollLines, false, false);
\r
899 this._Controller.Scroll(ScrollDirection.Down, SystemParameters.WheelScrollLines, false, false);
\r
901 else if (Keyboard.Modifiers == ModifierKeys.Control)
\r
903 double newFontSize = this.Render.FontSize;
\r
908 if (newFontSize > MaxFontSize)
\r
910 else if (newFontSize < MinFontSize)
\r
912 this.Render.FontSize = newFontSize;
\r
913 SetValue(MagnificationPowerPropertyKey, this.Render.FontSize / this.FontSize);
\r
916 base.OnMouseWheel(e);
\r
919 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
\r
921 if (e.Category == UserPreferenceCategory.Keyboard)
\r
923 int blinkTime = (int)NativeMethods.GetCaretBlinkTime();
\r
924 this.View.CaretBlink = blinkTime >= 0;
\r
925 this.View.CaretBlinkTime = blinkTime * 2;
\r
927 if (e.Category == UserPreferenceCategory.General)
\r
929 this.View.CaretWidthOnInsertMode = SystemParameters.CaretWidth;
\r
933 void Document_Update(object sender, DocumentUpdateEventArgs e)
\r
935 if (this.textStore.IsLocked() || e.type == UpdateType.Clear)
\r
937 if(e.removeLength == 0)
\r
938 this.textStore.NotifyTextChanged(e.startIndex,e.startIndex,e.startIndex + e.insertLength);
\r
940 this.textStore.NotifyTextChanged(e.startIndex,e.startIndex + 1,e.startIndex + e.insertLength - e.removeLength);
\r
943 void Document_Progress(object sender, ProgressEventArgs e)
\r
945 if (this.Document.State == AsyncState.Loading)
\r
949 case ProgressState.Start:
\r
950 this.textStore.NotifyTextChanged(0, this.Document.Length, 0);
\r
952 case ProgressState.Complete:
\r
953 this.textStore.NotifyTextChanged(0, 0, this.Document.Length);
\r
954 this.OnMouseMove(new MouseEventArgs(Mouse.PrimaryDevice, new TimeSpan(DateTime.Now.Ticks).Milliseconds));
\r
955 if(this.verticalScrollBar != null)
\r
956 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
\r
957 this.View.CalculateLineCountOnScreen();
\r
962 void timer_Tick(object sender, EventArgs e)
\r
964 if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)
\r
966 if (this.Document.State == AsyncState.Loading || this.Resize(this.image.ActualWidth, this.image.ActualHeight))
\r
972 ITextLayout layout = this.View.LayoutLines.GetLayout(this.View.CaretPostion.row);
\r
973 double width = layout.GetWidthFromIndex(this.View.CaretPostion.col);
\r
975 width = this.View.CaretWidthOnInsertMode;
\r
976 double height = layout.Height;
\r
977 Rectangle updateRect = new Rectangle(
\r
978 this.View.CaretLocation.X,
\r
979 this.View.CaretLocation.Y,
\r
983 this.Refresh(updateRect);
\r
986 void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
988 if (this.Document.State == AsyncState.Loading)
\r
990 if (this.horizontalScrollBar == null)
\r
993 if (this.FlowDirection == System.Windows.FlowDirection.LeftToRight)
\r
994 toX = this.horizontalScrollBar.Value;
\r
996 toX = -this.horizontalScrollBar.Value;
\r
997 this._Controller.Scroll(toX, this.View.Src.Row, false, false);
\r
1001 void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
1003 if (this.Document.State == AsyncState.Loading)
\r
1005 if (this.verticalScrollBar == null)
\r
1007 int newRow = (int)this.verticalScrollBar.Value;
\r
1008 if (newRow >= this.View.LayoutLines.Count)
\r
1010 this._Controller.Scroll(this.View.Src.X,newRow, false, false);
\r
1014 void View_SrcChanged(object sender, EventArgs e)
\r
1016 if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
\r
1018 EditView view = this.View;
\r
1019 if (view.Src.Row > this.verticalScrollBar.Maximum)
\r
1020 this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
\r
1021 double absoulteX = Math.Abs(view.Src.X);
\r
1022 if(absoulteX > this.horizontalScrollBar.Maximum)
\r
1023 this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
\r
1024 if(view.Src.Row != this.verticalScrollBar.Value)
\r
1025 this.verticalScrollBar.Value = view.Src.Row;
\r
1026 if (view.Src.X != this.horizontalScrollBar.Value)
\r
1027 this.horizontalScrollBar.Value = Math.Abs(view.Src.X);
\r
1030 void Controller_CaretMoved(object sender, EventArgs e)
\r
1032 this.View.CaretBlink = this.View.CaretBlink;
\r
1033 this.CaretMoved(this, null);
\r
1034 SetValue(CaretPostionPropertyKey, this.View.CaretPostion);
\r
1035 if(this.textStore.IsLocked() == false)
\r
1036 this.textStore.NotifySelectionChanged();
\r
1039 void FooTextBox_Loaded(object sender, RoutedEventArgs e)
\r
1041 this.Resize(this.image.ActualWidth, this.image.ActualHeight);
\r
1044 bool Resize(double width, double height)
\r
1046 if (width == 0 || height == 0)
\r
1047 throw new ArgumentOutOfRangeException();
\r
1048 if (this.Render.Resize(width, height) && this.Document.State != AsyncState.Loading)
\r
1050 this.View.PageBound = new Rectangle(0, 0, width, height);
\r
1052 if (this.horizontalScrollBar != null)
\r
1054 this.horizontalScrollBar.LargeChange = this.View.PageBound.Width;
\r
1055 this.horizontalScrollBar.Maximum = this.View.LongestWidth + this.horizontalScrollBar.LargeChange + 1;
\r
1057 if (this.verticalScrollBar != null)
\r
1059 this.verticalScrollBar.LargeChange = this.View.LineCountOnScreen;
\r
1060 this.verticalScrollBar.Maximum = this.View.LayoutLines.Count + this.verticalScrollBar.LargeChange + 1;
\r
1068 /// プロパティーが変更されたときに呼ばれます
\r
1070 /// <param name="e">イベントパラメーター</param>
\r
1071 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
\r
1073 switch (e.Property.Name)
\r
1075 case "LineBreakMethod":
\r
1076 this.View.LineBreak = this.LineBreakMethod;
\r
1078 case "LineBreakCharCount":
\r
1079 this.View.LineBreakCharCount = this.LineBreakCharCount;
\r
1081 case "InsertMode":
\r
1082 this.View.InsertMode = this.InsertMode;
\r
1085 this.View.TabStops = this.TabChars;
\r
1087 case "RectSelectMode":
\r
1088 this._Controller.RectSelection = this.RectSelectMode;
\r
1091 this.View.HideCaret = !this.DrawCaret;
\r
1093 case "DrawCaretLine":
\r
1094 this.View.HideLineMarker = !this.DrawCaretLine;
\r
1096 case "DrawLineNumber":
\r
1097 this.View.DrawLineNumber = this.DrawLineNumber;
\r
1098 this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);
\r
1100 case "FontFamily":
\r
1101 this.Render.FontFamily = this.FontFamily;
\r
1104 this.Render.FontSize = this.FontSize;
\r
1107 this.Render.FontStyle = this.FontStyle;
\r
1109 case "FontWeight":
\r
1110 this.Render.FontWeigth = this.FontWeight;
\r
1112 case "Foreground":
\r
1113 this.Render.Foreground = this.Foreground;
\r
1115 case "Background":
\r
1116 this.Render.Background = this.Background;
\r
1118 case "ControlChar":
\r
1119 this.Render.ControlChar = this.ControlChar;
\r
1122 this.Render.Hilight = this.Hilight;
\r
1125 this.Render.Keyword1 = this.Keyword1;
\r
1128 this.Render.Keyword2 = this.Keyword2;
\r
1131 this.Render.Comment = this.Comment;
\r
1134 this.Render.Literal = this.Literal;
\r
1137 this.Render.Url = this.URL;
\r
1139 case "InsertCaret":
\r
1140 this.Render.InsertCaret = this.InsertCaret;
\r
1142 case "OverwriteCaret":
\r
1143 this.Render.OverwriteCaret = this.OverwriteCaret;
\r
1145 case "LineMarker":
\r
1146 this.Render.LineMarker = this.LineMarker;
\r
1149 this.View.UrlMark = this.MarkURL;
\r
1151 case "ShowFullSpace":
\r
1152 this.Render.ShowFullSpace = this.ShowFullSpace;
\r
1154 case "ShowHalfSpace":
\r
1155 this.Render.ShowHalfSpace = this.ShowHalfSpace;
\r
1158 this.Render.ShowTab = this.ShowTab;
\r
1160 case "ShowLineBreak":
\r
1161 this.Render.ShowLineBreak = this.ShowLineBreak;
\r
1163 case "FlowDirection":
\r
1164 this.Render.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;
\r
1165 this.horizontalScrollBar.FlowDirection = this.FlowDirection;
\r
1168 this.View.HideRuler = !this.DrawRuler;
\r
1169 this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);
\r
1172 base.OnPropertyChanged(e);
\r
1177 internal Controller Controller
\r
1181 return this._Controller;
\r
1186 /// 文字列の描写に使用されるアンチエイリアシング モードを表します
\r
1188 public TextAntialiasMode TextAntialiasMode
\r
1192 return this.Render.TextAntialiasMode;
\r
1196 this.Render.TextAntialiasMode = value;
\r
1201 /// シンタックスハイライターを表す
\r
1203 public IHilighter Hilighter
\r
1207 return this.View.Hilighter;
\r
1211 this.View.Hilighter = value;
\r
1212 this.View.LayoutLines.ClearLayoutCache();
\r
1217 /// フォールティングを作成するインターフェイスを表す
\r
1219 public IFoldingStrategy FoldingStrategy
\r
1223 return this.View.LayoutLines.FoldingStrategy;
\r
1227 this.View.LayoutLines.FoldingStrategy = value;
\r
1228 if (value == null)
\r
1229 this.View.LayoutLines.FoldingCollection.Clear();
\r
1236 public Document Document
\r
1245 public LineToIndexTable LayoutLineCollection
\r
1247 get { return this.View.LayoutLines; }
\r
1253 public string SelectedText
\r
1257 return this._Controller.SelectedText;
\r
1261 int oldLength = this.Document.Length;
\r
1262 this._Controller.SelectedText = value;
\r
1269 /// <remarks>SelectionLengthが0の場合はキャレット位置を表します</remarks>
\r
1270 public int SelectionStart
\r
1272 get { return this._Controller.SelectionStart; }
\r
1278 /// <remarks>矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります</remarks>
\r
1279 public int SelectionLength
\r
1281 get { return this._Controller.SelectionLength; }
\r
1287 public double MagnificationPower
\r
1289 get { return (double)GetValue(MagnificationPowerPropertyKey.DependencyProperty); }
\r
1295 public static readonly DependencyPropertyKey MagnificationPowerPropertyKey =
\r
1296 DependencyProperty.RegisterReadOnly("MagnificationPower", typeof(double), typeof(FooTextBox), new PropertyMetadata(1.0));
\r
1301 public new FlowDirection FlowDirection
\r
1303 get { return (FlowDirection)GetValue(FlowDirectionProperty); }
\r
1304 set { SetValue(FlowDirectionProperty, value); }
\r
1308 /// レタリング方向を表す。これは依存プロパティです
\r
1310 public new static readonly DependencyProperty FlowDirectionProperty =
\r
1311 DependencyProperty.Register("FlowDirection", typeof(FlowDirection), typeof(FooTextBox), new PropertyMetadata(FlowDirection.LeftToRight));
\r
1314 /// キャレット位置を表す。これは依存プロパティです
\r
1316 public TextPoint CaretPostion
\r
1318 get { return (TextPoint)GetValue(CaretPostionPropertyKey.DependencyProperty); }
\r
1321 static readonly DependencyPropertyKey CaretPostionPropertyKey =
\r
1322 DependencyProperty.RegisterReadOnly("CaretPostion", typeof(TextPoint), typeof(FooTextBox), new FrameworkPropertyMetadata(new TextPoint()));
\r
1325 /// デフォルトの文字色を表す。これは依存プロパティです
\r
1327 public new System.Windows.Media.Color Foreground
\r
1329 get { return (System.Windows.Media.Color)GetValue(ForegroundProperty); }
\r
1330 set { SetValue(ForegroundProperty, value); }
\r
1334 /// Foregroundの依存プロパティを表す
\r
1336 public new static readonly DependencyProperty ForegroundProperty =
\r
1337 DependencyProperty.Register("Foreground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
\r
1340 /// 背景色を表す。これは依存プロパティです
\r
1342 public new System.Windows.Media.Color Background
\r
1344 get { return (System.Windows.Media.Color)GetValue(BackgroundProperty); }
\r
1345 set { SetValue(BackgroundProperty, value); }
\r
1349 /// Backgroundの依存プロパティを表す
\r
1351 public new static readonly DependencyProperty BackgroundProperty =
\r
1352 DependencyProperty.Register("Background", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowColor));
\r
1355 /// コントロールコードの文字色を表す。これは依存プロパティです
\r
1357 public System.Windows.Media.Color ControlChar
\r
1359 get { return (System.Windows.Media.Color)GetValue(ControlCharProperty); }
\r
1360 set { SetValue(ControlCharProperty, value); }
\r
1364 /// ControlCharの依存プロパティを表す
\r
1366 public static readonly DependencyProperty ControlCharProperty =
\r
1367 DependencyProperty.Register("ControlChar", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Gray));
\r
1370 /// 選択時の背景色を表す。これは依存プロパティです
\r
1372 public System.Windows.Media.Color Hilight
\r
1374 get { return (System.Windows.Media.Color)GetValue(HilightProperty); }
\r
1375 set { SetValue(HilightProperty, value); }
\r
1379 /// Hilightの依存プロパティを表す
\r
1381 public static readonly DependencyProperty HilightProperty =
\r
1382 DependencyProperty.Register("Hilight", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DeepSkyBlue));
\r
1385 /// キーワード1の文字色を表す。これは依存プロパティです
\r
1387 public System.Windows.Media.Color Keyword1
\r
1389 get { return (System.Windows.Media.Color)GetValue(Keyword1Property); }
\r
1390 set { SetValue(Keyword1Property, value); }
\r
1394 /// Keyword1の依存プロパティを表す
\r
1396 public static readonly DependencyProperty Keyword1Property =
\r
1397 DependencyProperty.Register("Keyword1", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
\r
1400 /// キーワード2の文字色を表す。これは依存プロパティです
\r
1402 public System.Windows.Media.Color Keyword2
\r
1404 get { return (System.Windows.Media.Color)GetValue(Keyword2Property); }
\r
1405 set { SetValue(Keyword2Property, value); }
\r
1409 /// Keyword2の依存プロパティを表す
\r
1411 public static readonly DependencyProperty Keyword2Property =
\r
1412 DependencyProperty.Register("Keyword2", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.DarkCyan));
\r
1415 /// コメントの文字色を表す。これは依存プロパティです
\r
1417 public System.Windows.Media.Color Comment
\r
1419 get { return (System.Windows.Media.Color)GetValue(CommentProperty); }
\r
1420 set { SetValue(CommentProperty, value); }
\r
1424 /// Commentの依存プロパティを表す
\r
1426 public static readonly DependencyProperty CommentProperty =
\r
1427 DependencyProperty.Register("Comment", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Green));
\r
1430 /// 文字リテラルの文字色を表す。これは依存プロパティです
\r
1432 public System.Windows.Media.Color Literal
\r
1434 get { return (System.Windows.Media.Color)GetValue(LiteralProperty); }
\r
1435 set { SetValue(LiteralProperty, value); }
\r
1439 /// Literalの依存プロパティを表す
\r
1441 public static readonly DependencyProperty LiteralProperty =
\r
1442 DependencyProperty.Register("Literal", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Brown));
\r
1445 /// URLの文字色を表す。これは依存プロパティです
\r
1447 public System.Windows.Media.Color URL
\r
1449 get { return (System.Windows.Media.Color)GetValue(URLProperty); }
\r
1450 set { SetValue(URLProperty, value); }
\r
1454 /// URLの依存プロパティを表す
\r
1456 public static readonly DependencyProperty URLProperty =
\r
1457 DependencyProperty.Register("URL", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Blue));
\r
1463 public System.Windows.Media.Color LineMarker
\r
1465 get { return (System.Windows.Media.Color)GetValue(LineMarkerProperty); }
\r
1466 set { SetValue(LineMarkerProperty, value); }
\r
1470 /// LineMarkerの依存プロパティを表す
\r
1472 public static readonly DependencyProperty LineMarkerProperty =
\r
1473 DependencyProperty.Register("LineMarker", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.Silver));
\r
1476 /// 挿入モード時のキャレットの色を表す
\r
1478 public System.Windows.Media.Color InsertCaret
\r
1480 get { return (System.Windows.Media.Color)GetValue(InsertCaretProperty); }
\r
1481 set { SetValue(InsertCaretProperty, value); }
\r
1485 /// InsertCaretの依存プロパティを表す
\r
1487 public static readonly DependencyProperty InsertCaretProperty =
\r
1488 DependencyProperty.Register("InsertCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
\r
1491 /// 上書きモード時のキャレット職を表す
\r
1493 public System.Windows.Media.Color OverwriteCaret
\r
1495 get { return (System.Windows.Media.Color)GetValue(OverwriteCaretProperty); }
\r
1496 set { SetValue(OverwriteCaretProperty, value); }
\r
1500 /// OverwriteCaretの依存プロパティを表す
\r
1502 public static readonly DependencyProperty OverwriteCaretProperty =
\r
1503 DependencyProperty.Register("OverwriteCaret", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowTextColor));
\r
1506 /// 挿入モードなら真を返し、そうでないなら、偽を返す。これは依存プロパティです
\r
1508 public bool InsertMode
\r
1510 get { return (bool)GetValue(InsertModeProperty); }
\r
1511 set { SetValue(InsertModeProperty, value); }
\r
1515 /// InsertModeの依存プロパティを表す
\r
1517 public static readonly DependencyProperty InsertModeProperty =
\r
1518 DependencyProperty.Register("InsertMode",
\r
1520 typeof(FooTextBox),
\r
1521 new FrameworkPropertyMetadata(true));
\r
1524 /// タブの文字数を表す。これは依存プロパティです
\r
1526 public int TabChars
\r
1528 get { return (int)GetValue(TabCharsProperty); }
\r
1529 set { SetValue(TabCharsProperty, value); }
\r
1533 /// TabCharsの依存プロパティを表す
\r
1535 public static readonly DependencyProperty TabCharsProperty =
\r
1536 DependencyProperty.Register("TabChars",
\r
1538 typeof(FooTextBox),
\r
1539 new FrameworkPropertyMetadata(4));
\r
1542 /// 矩形選択モードなら真を返し、そうでないなら偽を返す。これは依存プロパティです
\r
1544 public bool RectSelectMode
\r
1546 get { return (bool)GetValue(RectSelectModeProperty); }
\r
1547 set { SetValue(RectSelectModeProperty, value); }
\r
1551 /// RectSelectModeの依存プロパティを表す
\r
1553 public static readonly DependencyProperty RectSelectModeProperty =
\r
1554 DependencyProperty.Register("RectSelectMode", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1560 /// 変更した場合、レイアウトの再構築を行う必要があります
\r
1562 public LineBreakMethod LineBreakMethod
\r
1564 get { return (LineBreakMethod)GetValue(LineBreakProperty); }
\r
1565 set { SetValue(LineBreakProperty, value); }
\r
1569 /// LineBreakMethodの依存プロパティを表す
\r
1571 public static readonly DependencyProperty LineBreakProperty =
\r
1572 DependencyProperty.Register("LineBreakMethod", typeof(LineBreakMethod), typeof(FooTextBox), new PropertyMetadata(LineBreakMethod.None));
\r
1576 /// 折り返しの幅を指定する。LineBreakMethod.CharUnit以外の時は無視されます
\r
1579 /// 変更した場合、レイアウトの再構築を行う必要があります
\r
1581 public int LineBreakCharCount
\r
1583 get { return (int)GetValue(LineBreakCharCountProperty); }
\r
1584 set { SetValue(LineBreakCharCountProperty, value); }
\r
1588 /// LineBreakCharCountの依存プロパティを表す
\r
1590 public static readonly DependencyProperty LineBreakCharCountProperty =
\r
1591 DependencyProperty.Register("LineBreakCharCount", typeof(int), typeof(FooTextBox), new PropertyMetadata(80));
\r
1594 /// キャレットを描くなら真。そうでないなら偽を返す。これは依存プロパティです
\r
1596 public bool DrawCaret
\r
1598 get { return (bool)GetValue(DrawCaretProperty); }
\r
1599 set { SetValue(DrawCaretProperty, value); }
\r
1603 /// DrawCaretの依存プロパティを表す
\r
1605 public static readonly DependencyProperty DrawCaretProperty =
\r
1606 DependencyProperty.Register("DrawCaret", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(true));
\r
1610 /// キャレットラインを描くなら真。そうでないなら偽を返す。これは依存プロパティです
\r
1612 public bool DrawCaretLine
\r
1614 get { return (bool)GetValue(DrawCaretLineProperty); }
\r
1615 set { SetValue(DrawCaretLineProperty, value); }
\r
1619 /// DrawCaretLineの依存プロパティを表す
\r
1621 public static readonly DependencyProperty DrawCaretLineProperty =
\r
1622 DependencyProperty.Register("DrawCaretLine", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1625 /// 行番号を描くなら真。そうでなければ偽。これは依存プロパティです
\r
1627 public bool DrawLineNumber
\r
1629 get { return (bool)GetValue(DrawLineNumberProperty); }
\r
1630 set { SetValue(DrawLineNumberProperty, value); }
\r
1634 /// ルーラーを描くなら真。そうでなければ偽。これは依存プロパティです
\r
1636 public bool DrawRuler
\r
1638 get { return (bool)GetValue(DrawRulerProperty); }
\r
1639 set { SetValue(DrawRulerProperty, value); }
\r
1643 /// DrawRulerの依存プロパティを表す
\r
1645 public static readonly DependencyProperty DrawRulerProperty =
\r
1646 DependencyProperty.Register("DrawRuler", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
\r
1650 /// DrawLineNumberの依存プロパティを表す
\r
1652 public static readonly DependencyProperty DrawLineNumberProperty =
\r
1653 DependencyProperty.Register("DrawLineNumber", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1656 /// URLに下線を引くなら真。そうでないなら偽を表す。これは依存プロパティです
\r
1658 public bool MarkURL
\r
1660 get { return (bool)GetValue(MarkURLProperty); }
\r
1661 set { SetValue(MarkURLProperty, value); }
\r
1665 /// MarkURLの依存プロパティを表す
\r
1667 public static readonly DependencyProperty MarkURLProperty =
\r
1668 DependencyProperty.Register("MarkURL", typeof(bool), typeof(FooTextBox), new FrameworkPropertyMetadata(false));
\r
1671 /// 全角スペースを表示するなら真。そうでないなら偽
\r
1673 public bool ShowFullSpace
\r
1675 get { return (bool)GetValue(ShowFullSpaceProperty); }
\r
1676 set { SetValue(ShowFullSpaceProperty, value); }
\r
1680 /// ShowFullSpaceの依存プロパティを表す
\r
1682 public static readonly DependencyProperty ShowFullSpaceProperty =
\r
1683 DependencyProperty.Register("ShowFullSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
\r
1686 /// 半角スペースを表示するなら真。そうでないなら偽
\r
1688 public bool ShowHalfSpace
\r
1690 get { return (bool)GetValue(ShowHalfSpaceProperty); }
\r
1691 set { SetValue(ShowHalfSpaceProperty, value); }
\r
1695 /// ShowHalfSpaceの依存プロパティを表す
\r
1697 public static readonly DependencyProperty ShowHalfSpaceProperty =
\r
1698 DependencyProperty.Register("ShowHalfSpace", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
\r
1701 /// タブを表示するなら真。そうでないなら偽
\r
1703 public bool ShowTab
\r
1705 get { return (bool)GetValue(ShowTabProperty); }
\r
1706 set { SetValue(ShowTabProperty, value); }
\r
1710 /// ShowTabの依存プロパティを表す
\r
1712 public static readonly DependencyProperty ShowTabProperty =
\r
1713 DependencyProperty.Register("ShowTab", typeof(bool), typeof(FooTextBox), new UIPropertyMetadata(false));
\r
1716 /// 改行マークを表示するなら真。そうでないなら偽
\r
1718 public bool ShowLineBreak
\r
1720 get { return (bool)GetValue(ShowLineBreakProperty); }
\r
1721 set { SetValue(ShowLineBreakProperty, value); }
\r
1725 /// ShowLineBreakの依存プロパティを表す
\r
1727 public static readonly DependencyProperty ShowLineBreakProperty =
\r
1728 DependencyProperty.Register("ShowLineBreak", typeof(bool), typeof(FooTextBox), new PropertyMetadata(false));
\r
1733 /// マウスボタン関連のイベントクラス
\r
1735 public sealed class FooMouseButtonEventArgs : MouseButtonEventArgs
\r
1738 /// イベントが発生したドキュメントのインデックス
\r
1749 /// <param name="mouse">マウスデバイス</param>
\r
1750 /// <param name="timestamp">タイムスタンプ</param>
\r
1751 /// <param name="button">ボタン</param>
\r
1752 /// <param name="stylusDevice">スタイラスデバイス</param>
\r
1753 /// <param name="index">インデックス</param>
\r
1754 public FooMouseButtonEventArgs(MouseDevice mouse, int timestamp, MouseButton button, StylusDevice stylusDevice, int index)
\r
1755 : base(mouse, timestamp, button, stylusDevice)
\r
1757 this.Index = index;
\r
1763 public sealed class FooMouseEventArgs : MouseEventArgs
\r
1766 /// イベントが発生したドキュメントのインデックス
\r
1777 /// <param name="mouse">マウスデバイス</param>
\r
1778 /// <param name="timestamp">タイムスタンプ</param>
\r
1779 /// <param name="stylusDevice">スタイラスデバイス</param>
\r
1780 /// <param name="index">インデックス</param>
\r
1781 public FooMouseEventArgs(MouseDevice mouse,
\r
1783 StylusDevice stylusDevice,
\r
1785 : base(mouse, timestamp, stylusDevice)
\r
1787 this.Index = index;
\r