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
13 using System.Threading;
\r
14 using System.Threading.Tasks;
\r
15 using System.Windows.Forms;
\r
16 using System.Drawing;
\r
17 using System.ComponentModel;
\r
18 using Microsoft.Win32;
\r
20 namespace FooEditEngine.Windows
\r
23 /// タブの幅が変更されたときに呼びされるデリゲート
\r
25 /// <param name="sender">送り主が属するクラス</param>
\r
26 /// <param name="e">イベントデータ</param>
\r
27 public delegate void TabStopChangeEventHandler(object sender, EventArgs e);
\r
30 /// InsetModeが変更されたときに呼び出されるデリゲート
\r
32 /// <param name="sender">送り主が属するクラス</param>
\r
33 /// <param name="e">イベントデータ</param>
\r
34 public delegate void InsertModeChangeEventHandler(object sender, EventArgs e);
\r
37 /// FooEditEngineを表します
\r
39 public class FooTextBox : Control
\r
42 Controller Controller;
\r
43 D2DTextRender render;
\r
44 BorderStyle _BoderStyle;
\r
45 HScrollBar HScrollBar;
\r
46 VScrollBar VScrollBar;
\r
48 System.Windows.Forms.Timer Timer;
\r
50 const int Interval = 100;
\r
57 this.VScrollBar = new VScrollBar();
\r
58 this.VScrollBar.Scroll += new ScrollEventHandler(VScrollBar_Scroll);
\r
59 this.VScrollBar.Dock = DockStyle.Right;
\r
60 this.VScrollBar.Visible = true;
\r
61 this.Controls.Add(this.VScrollBar);
\r
63 this.HScrollBar = new HScrollBar();
\r
64 this.HScrollBar.Scroll += new ScrollEventHandler(HScrollBar_Scroll);
\r
65 this.HScrollBar.Dock = DockStyle.Bottom;
\r
66 this.HScrollBar.Visible = true;
\r
67 this.Controls.Add(this.HScrollBar);
\r
69 this.SetStyle(ControlStyles.ResizeRedraw, true);
\r
70 this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
\r
71 this.SetStyle(ControlStyles.UserPaint, true);
\r
72 this.SetStyle(ControlStyles.Opaque, true);
\r
74 this.render = new D2DTextRender(this);
\r
75 this.Document = new Document();
\r
76 this.Document.LayoutLines.Render = this.render;
\r
77 this.View = new EditView(this.Document, this.render, new FooEditEngine.Padding(5, 5, 5, 5));
\r
78 this.View.SrcChanged += View_SrcChanged;
\r
80 this.Controller = new Controller(this.Document, this.View);
\r
81 this.Controller.SelectionChanged += new EventHandler(Controller_CaretMoved);
\r
83 this.Ime = new WinIME(this);
\r
84 this.Ime.ImeCompstion += new ImeCompstionEventHandeler(Ime_ImeCompstion);
\r
85 this.Ime.StartCompstion += new StartCompstionEventHandeler(Ime_StartCompstion);
\r
86 this.Ime.EndCompstion += new EndCompstionEventHandeler(Ime_EndCompstion);
\r
87 this.Ime.ImeDocumentFeed += new ImeDocumentFeedEventHandler(Ime_ImeDocumentFeed);
\r
88 this.Ime.ImeReconvert += new ImeReconvertStringEventHandler(Ime_ImeReconvert);
\r
89 this.Ime.ImeQueryReconvert += new ImeQueryReconvertStringEventHandler(Ime_ImeQueryReconvert);
\r
91 this.Timer = new System.Windows.Forms.Timer();
\r
92 this.Timer.Tick += new EventHandler(this.Timer_Tick);
\r
93 this.Timer.Interval = Interval;
\r
94 this.SetSystemParamaters();
\r
96 this.TabStopChange += new TabStopChangeEventHandler((s, e) => { });
\r
97 this.InsetModeChange += new InsertModeChangeEventHandler((s, e) => { });
\r
98 this.SelectionChanged +=new EventHandler((s,e)=>{});
\r
100 this.RightToLeftChanged += FooTextBox_RightToLeftChanged;
\r
102 SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
\r
107 /// キャレットが移動したときに通知されるイベント
\r
109 public event EventHandler SelectionChanged;
\r
112 /// タブの幅が変更された時に発生するイベント
\r
114 public event TabStopChangeEventHandler TabStopChange;
\r
117 /// InsertModeが変更されたときに呼び出されるイベント
\r
119 public event InsertModeChangeEventHandler InsetModeChange;
\r
124 [DefaultValue(IndentMode.Tab)]
\r
125 public IndentMode IndentMode
\r
129 return this.Controller.IndentMode;
\r
133 this.Controller.IndentMode = value;
\r
138 /// テキスト描写に使用するアンチエイリアシングモードを表す
\r
140 [BrowsableAttribute(false)]
\r
141 public TextAntialiasMode TextAntialiasMode
\r
145 return this.render.TextAntialiasMode;
\r
149 this.render.TextAntialiasMode = value;
\r
156 [BrowsableAttribute(false)]
\r
157 public MarkerPatternSet MarkerPatternSet
\r
161 return this.View.MarkerPatternSet;
\r
168 [BrowsableAttribute(false)]
\r
169 public Document Document
\r
178 [BrowsableAttribute(false)]
\r
179 public LineToIndexTable LayoutLines
\r
181 get { return this.View.LayoutLines; }
\r
187 [BrowsableAttribute(false)]
\r
188 public IHilighter Hilighter
\r
190 get { return this.View.Hilighter; }
\r
191 set { this.View.Hilighter = value; this.View.LayoutLines.ClearLayoutCache(); }
\r
195 /// フォールティングを作成するインターフェイスを表す
\r
197 [BrowsableAttribute(false)]
\r
198 public IFoldingStrategy FoldingStrategy
\r
202 return this.View.LayoutLines.FoldingStrategy;
\r
206 this.View.LayoutLines.FoldingStrategy = value;
\r
208 this.View.LayoutLines.FoldingCollection.Clear();
\r
215 public BorderStyle BorderStyle
\r
217 get { return this._BoderStyle; }
\r
218 set { this._BoderStyle = value; this.UpdateStyles(); }
\r
225 [DefaultValue(false)]
\r
226 public bool DrawLineNumber
\r
230 return this.View.DrawLineNumber;
\r
234 this.View.DrawLineNumber = value;
\r
235 this.JumpCaret(this.CaretPostion.row,this.CaretPostion.col);
\r
242 [DefaultValue(false)]
\r
243 public bool DrawRuler
\r
247 return !this.View.HideRuler;
\r
251 this.View.HideRuler = !value;
\r
252 this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
\r
260 /// 反映させるためにはレイアウト行の再構築を行う必要があります
\r
262 [DefaultValue(LineBreakMethod.None)]
\r
263 public LineBreakMethod LineBreakMethod
\r
267 return this.View.LineBreak;
\r
271 this.View.LineBreak = value;
\r
279 /// 反映させるためにはレイアウト行の再構築を行う必要があります
\r
282 public int LineBreakCharCount
\r
286 return this.View.LineBreakCharCount;
\r
290 this.View.LineBreakCharCount = value;
\r
297 [DefaultValue(false)]
\r
298 public bool UrlMark
\r
302 return this.View.UrlMark;
\r
306 this.View.UrlMark = value;
\r
314 public int TabStops
\r
316 get { return this.View.TabStops; }
\r
318 this.View.TabStops = value;
\r
319 this.View.AdjustCaretAndSrc();
\r
320 this.TabStopChange(this, null);
\r
325 /// 全角スペースを表示するなら真。そうでないなら偽
\r
327 [DefaultValue(false)]
\r
328 public bool ShowFullSpace
\r
332 return this.render.ShowFullSpace;
\r
336 this.render.ShowFullSpace = value;
\r
341 /// 半角スペースを表示するなら真。そうでないなら偽
\r
343 [DefaultValue(false)]
\r
344 public bool ShowHalfSpace
\r
348 return this.render.ShowHalfSpace;
\r
352 this.render.ShowHalfSpace = value;
\r
357 /// タブを表示するなら真。そうでないなら偽
\r
359 [DefaultValue(false)]
\r
360 public bool ShowTab
\r
364 return this.render.ShowTab;
\r
368 this.render.ShowTab = value;
\r
373 /// 改行マークを表示するなら真。そうでないなら偽
\r
375 [DefaultValue(false)]
\r
376 public bool ShowLineBreak
\r
380 return this.render.ShowLineBreak;
\r
384 this.render.ShowLineBreak = value;
\r
392 /// 未選択状態で文字列を代入した場合、キャレット位置に挿入され、そうでないときは置き換えられます。
\r
394 [BrowsableAttribute(false)]
\r
395 public string SelectedText
\r
397 get { return this.Controller.SelectedText; }
\r
398 set { this.Controller.SelectedText = value; }
\r
404 [BrowsableAttribute(false)]
\r
405 public TextPoint CaretPostion
\r
407 get { return this.View.CaretPostion; }
\r
414 /// Lengthが0の場合はキャレット位置を表します
\r
415 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
\r
417 [BrowsableAttribute(false)]
\r
418 public TextRange Selection
\r
420 get { return new TextRange(this.Controller.SelectionStart,this.Controller.SelectionLength); }
\r
423 this.Controller.Select(value.Index, value.Length);
\r
430 [DefaultValue(true)]
\r
431 public bool InsertMode
\r
433 get { return this.View.InsertMode; }
\r
436 this.View.InsertMode = value;
\r
437 this.InsetModeChange(this, null);
\r
444 [DefaultValue(false)]
\r
445 public bool RectSelection
\r
447 get { return this.Controller.RectSelection; }
\r
448 set { this.Controller.RectSelection = value; }
\r
451 System.Drawing.Color ForegroundColor = SystemColors.ControlText,
\r
452 BackgroundColor = SystemColors.Control,
\r
453 HilightColor = System.Drawing.Color.DeepSkyBlue,
\r
454 Keyword1Color = System.Drawing.Color.Blue,
\r
455 Keyword2Color = System.Drawing.Color.DarkCyan,
\r
456 LiteralColor = System.Drawing.Color.Brown,
\r
457 UrlColor = System.Drawing.Color.Blue,
\r
458 ControlCharColor = System.Drawing.Color.Gray,
\r
459 CommentColor = System.Drawing.Color.Green,
\r
460 InsertCaretColor = System.Drawing.Color.Black,
\r
461 OverwriteCaretColor = System.Drawing.Color.Black,
\r
462 LineMarkerColor = System.Drawing.Color.WhiteSmoke,
\r
463 UpdateAreaColor = System.Drawing.Color.MediumSeaGreen,
\r
464 LineNumberColor = System.Drawing.Color.DimGray;
\r
469 public System.Drawing.Color Foreground
\r
473 return this.ForegroundColor;
\r
477 this.render.Foreground = D2DTextRender.ToColor4(value);
\r
478 this.ForegroundColor = value;
\r
485 public System.Drawing.Color Background
\r
489 return this.BackgroundColor;
\r
493 this.render.Background = D2DTextRender.ToColor4(value);
\r
494 this.BackgroundColor = value;
\r
501 public System.Drawing.Color InsertCaret
\r
505 return this.InsertCaretColor;
\r
509 this.InsertCaretColor = value;
\r
510 this.render.InsertCaret = D2DTextRender.ToColor4(value);
\r
517 public System.Drawing.Color OverwriteCaret
\r
521 return this.OverwriteCaretColor;
\r
525 this.OverwriteCaretColor = value;
\r
526 this.render.OverwriteCaret = D2DTextRender.ToColor4(value);
\r
533 public System.Drawing.Color LineMarker
\r
537 return this.LineMarkerColor;
\r
541 this.LineMarkerColor = value;
\r
542 this.render.LineMarker = D2DTextRender.ToColor4(value);
\r
549 public System.Drawing.Color ControlChar
\r
553 return this.ControlCharColor;
\r
557 this.ControlCharColor = value;
\r
558 this.render.ControlChar = D2DTextRender.ToColor4(value);
\r
565 public System.Drawing.Color UpdateArea
\r
569 return this.UpdateAreaColor;
\r
573 this.UpdateAreaColor = value;
\r
574 this.render.UpdateArea = D2DTextRender.ToColor4(value);
\r
581 public System.Drawing.Color LineNumber
\r
585 return this.LineNumber;
\r
589 this.LineNumber = value;
\r
590 this.render.LineNumber = D2DTextRender.ToColor4(value);
\r
597 public System.Drawing.Color Url
\r
601 return this.UrlColor;
\r
605 this.UrlColor = value;
\r
606 this.render.Url = D2DTextRender.ToColor4(value);
\r
613 public System.Drawing.Color Hilight
\r
617 return this.HilightColor;
\r
621 this.HilightColor = value;
\r
622 this.render.Hilight = D2DTextRender.ToColor4(value);
\r
629 public System.Drawing.Color Comment
\r
633 return this.CommentColor;
\r
637 this.CommentColor = value;
\r
638 this.render.Comment = D2DTextRender.ToColor4(value);
\r
645 public System.Drawing.Color Literal
\r
649 return this.LiteralColor;
\r
653 this.LiteralColor = value;
\r
654 this.render.Literal = D2DTextRender.ToColor4(value);
\r
661 public System.Drawing.Color Keyword1
\r
665 return this.Keyword1Color;
\r
669 this.Keyword1Color = value;
\r
670 this.render.Keyword1 = D2DTextRender.ToColor4(value);
\r
677 public System.Drawing.Color Keyword2
\r
681 return this.Keyword2Color;
\r
685 this.Keyword2Color = value;
\r
686 this.render.Keyword2 = D2DTextRender.ToColor4(value);
\r
691 /// キャレットに下線を描くかどうか
\r
693 [DefaultValue(false)]
\r
694 public bool DrawCaretLine
\r
696 get { return !this.View.HideLineMarker; }
\r
697 set { this.View.HideLineMarker = !value; }
\r
703 /// <param name="start">開始インデックス</param>
\r
704 /// <param name="length">長さ</param>
\r
705 public void Select(int start, int length)
\r
707 this.Controller.Select(start, length);
\r
708 this.HScrollBar.Value = (int)this.View.Src.X;
\r
709 this.VScrollBar.Value = this.View.Src.Row;
\r
715 public void SelectAll()
\r
717 this.Controller.Select(0, this.Document.Length - 1);
\r
723 public void DeSelectAll()
\r
725 this.Controller.DeSelectAll();
\r
733 string text = this.SelectedText;
\r
734 if(text != null && text != string.Empty)
\r
735 Clipboard.SetText(text);
\r
739 /// クリップボードにコピーし、指定した範囲にある文字列をすべて削除します
\r
743 string text = this.SelectedText;
\r
744 if (text != null && text != string.Empty)
\r
746 Clipboard.SetText(text);
\r
747 this.Controller.SelectedText = "";
\r
752 /// クリップボードの内容をペーストします
\r
754 public void Paste()
\r
756 if (Clipboard.ContainsText() == false)
\r
758 this.Controller.SelectedText = Clipboard.GetText();
\r
762 /// キャレットを指定した行に移動させます
\r
764 /// <param name="index">インデックス</param>
\r
765 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
\r
766 public void JumpCaret(int index)
\r
768 this.Controller.JumpCaret(index);
\r
771 /// キャレットを指定した行と桁に移動させます
\r
773 /// <param name="row">行番号</param>
\r
774 /// <param name="col">桁</param>
\r
775 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
\r
776 public void JumpCaret(int row, int col)
\r
778 this.Controller.JumpCaret(row, col);
\r
784 public new void Refresh()
\r
786 if (this.Document.FireUpdateEvent == false)
\r
787 throw new InvalidOperationException("");
\r
788 if(this.View.CaretBlink)
\r
789 this.View.CaretBlink = true;
\r
797 /// <param name="row">行</param>
\r
798 /// <returns>高さ</returns>
\r
799 public double GetLineHeight(int row)
\r
801 if (this.Document.FireUpdateEvent == false)
\r
802 throw new InvalidOperationException("");
\r
803 return this.View.LayoutLines.GetLayout(row).Height;
\r
809 /// <param name="tp">テキストポイント</param>
\r
810 /// <returns>座標</returns>
\r
811 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
\r
812 public System.Drawing.Point GetPostionFromTextPoint(TextPoint tp)
\r
814 if (this.Document.FireUpdateEvent == false)
\r
815 throw new InvalidOperationException("");
\r
816 return this.View.GetPostionFromTextPoint(tp);
\r
820 /// 対応するテキストポイントを返す
\r
822 /// <param name="p">クライアント領域の原点を左上とする座標</param>
\r
823 /// <returns>テキストポイント</returns>
\r
824 public TextPoint GetTextPointFromPostion(System.Drawing.Point p)
\r
826 if (this.Document.FireUpdateEvent == false)
\r
827 throw new InvalidOperationException("");
\r
828 return this.View.GetTextPointFromPostion(p);
\r
832 /// インデックスに対応する座標を得ます
\r
834 /// <param name="index">インデックス</param>
\r
835 /// <returns>座標を返す</returns>
\r
836 public System.Drawing.Point GetPostionFromIndex(int index)
\r
838 if (this.Document.FireUpdateEvent == false)
\r
839 throw new InvalidOperationException("");
\r
840 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
\r
841 return this.View.GetPostionFromTextPoint(tp);
\r
845 /// 座標からインデックスに変換します
\r
847 /// <param name="p">座標</param>
\r
848 /// <returns>インデックスを返す</returns>
\r
849 public int GetIndexFromPostion(System.Drawing.Point p)
\r
851 if (this.Document.FireUpdateEvent == false)
\r
852 throw new InvalidOperationException("");
\r
853 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
854 return this.View.GetIndexFromLayoutLine(tp);
\r
858 /// レイアウト行をすべて破棄し、再度レイアウトを行う
\r
860 public void PerfomLayouts()
\r
862 this.View.PerfomLayouts();
\r
867 /// ストリームからドキュメントを構築する
\r
869 /// <param name="tr">TextReader</param>
\r
870 /// <param name="token">キャンセル用トークン</param>
\r
871 /// <returns>Taskオブジェクト</returns>
\r
872 public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)
\r
874 WinFileReader fs = new WinFileReader(tr);
\r
875 await this.LoadAsyncImpl(fs, token);
\r
879 /// ファイルからドキュメントを構築する
\r
881 /// <param name="filepath">ファイルパス</param>
\r
882 /// <param name="enc">エンコード</param>
\r
883 /// <param name="token">キャンセル用トークン</param>
\r
884 /// <returns>Taskオブジェクト</returns>
\r
885 public async Task LoadFileAsync(string filepath, Encoding enc, System.Threading.CancellationTokenSource token)
\r
887 WinFileReader fs = new WinFileReader(filepath, enc);
\r
888 await this.LoadAsyncImpl(fs, token);
\r
892 async Task LoadAsyncImpl(WinFileReader fs, System.Threading.CancellationTokenSource token)
\r
894 this.Enabled = false;
\r
895 this.View.LayoutLines.IsFrozneDirtyFlag = true;
\r
896 await this.Document.LoadAsync(fs, token);
\r
897 this.View.LayoutLines.IsFrozneDirtyFlag = false;
\r
898 this.initScrollBars();
\r
899 this.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, MousePosition.X, MousePosition.Y, 0));
\r
900 this.View.CalculateLineCountOnScreen();
\r
901 this.Enabled = true;
\r
905 /// ドキュメントの内容をファイルに保存する
\r
907 /// <param name="filepath">ファイルパス</param>
\r
908 /// <param name="newLine">改行コード</param>
\r
909 /// <param name="enc">エンコード</param>
\r
910 /// <returns>Taskオブジェクト</returns>
\r
911 public async Task SaveFile(string filepath, Encoding enc, string newLine, System.Threading.CancellationTokenSource token)
\r
913 WinFileWriter fs = new WinFileWriter(filepath, enc);
\r
914 fs.NewLine = newLine;
\r
915 await this.Document.SaveAsync(fs, token);
\r
922 public override Cursor Cursor
\r
926 return base.Cursor;
\r
930 base.Cursor = value;
\r
931 this.VScrollBar.Cursor = DefaultCursor;
\r
932 this.HScrollBar.Cursor = DefaultCursor;
\r
936 private const int WS_BORDER = 0x00800000;
\r
937 private const int WS_EX_CLIENTEDGE = 0x00000200;
\r
939 /// コントロールの外観を指定します
\r
941 protected override CreateParams CreateParams
\r
945 CreateParams cp = base.CreateParams;
\r
946 switch (this.BorderStyle)
\r
948 case BorderStyle.Fixed3D:
\r
949 cp.ExStyle |= WS_EX_CLIENTEDGE;
\r
951 case BorderStyle.FixedSingle:
\r
952 cp.Style |= WS_BORDER;
\r
962 /// <param name="msg">メッセージ</param>
\r
963 /// <param name="keyData">キーデータ</param>
\r
964 /// <returns>文字がコントロールによって処理された場合は true。それ以外の場合は false。 </returns>
\r
965 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
\r
967 const int WM_KEYDOWN = 0x100;
\r
968 if (msg.Msg != WM_KEYDOWN)
\r
969 return base.ProcessCmdKey(ref msg, keyData);
\r
972 case Keys.Control | Keys.C:
\r
975 case Keys.Control | Keys.V:
\r
979 case Keys.Control | Keys.X:
\r
983 case Keys.Control | Keys.Z:
\r
984 this.Document.UndoManager.undo();
\r
987 case Keys.Control | Keys.Y:
\r
988 this.Document.UndoManager.redo();
\r
991 case Keys.Control | Keys.B:
\r
992 if (this.Controller.RectSelection)
\r
993 this.Controller.RectSelection = false;
\r
995 this.Controller.RectSelection = true;
\r
998 return base.ProcessCmdKey(ref msg,keyData);
\r
1006 /// <param name="disposing">マネージ リソースとアンマネージ リソースの両方を解放する場合は true。アンマネージ リソースだけを解放する場合は false。</param>
\r
1007 protected override void Dispose(bool disposing)
\r
1009 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(this.SystemEvents_UserPreferenceChanged);
\r
1010 this.render.Dispose();
\r
1011 this.Timer.Dispose();
\r
1012 base.Dispose(disposing);
\r
1016 /// 入力可能な文字かチェックします
\r
1018 /// <param name="charCode">入力しようとした文字</param>
\r
1019 /// <returns>可能なら真。そうでなければ偽</returns>
\r
1020 protected override bool IsInputChar(char charCode)
\r
1022 if ((0x20 <= charCode && charCode <= 0x7e)
\r
1023 || charCode == '\r'
\r
1024 || charCode == '\n'
\r
1025 || charCode == ' '
\r
1026 || charCode == '\t'
\r
1027 || charCode == ' '
\r
1028 || 0x7f < charCode)
\r
1037 /// PaddingChangedイベントを発生させます
\r
1039 /// <param name="e">インベントデータ</param>
\r
1040 protected override void OnPaddingChanged(EventArgs e)
\r
1042 base.OnPaddingChanged(e);
\r
1043 this.View.Padding = new Padding(this.Padding.Left, this.Padding.Top, this.Padding.Right, this.Padding.Bottom);
\r
1047 /// GotFocusイベントを発生させます
\r
1049 /// <param name="e">インベントデータ</param>
\r
1050 protected override void OnGotFocus(EventArgs e)
\r
1052 base.OnGotFocus(e);
\r
1053 this.View.IsFocused = true;
\r
1058 /// LostFocusイベントを発生させます
\r
1060 /// <param name="e">インベントデータ</param>
\r
1061 protected override void OnLostFocus(EventArgs e)
\r
1063 base.OnLostFocus(e);
\r
1064 this.View.IsFocused = false;
\r
1069 /// FontChangedイベントを発生させます
\r
1071 /// <param name="e">インベントデータ</param>
\r
1072 protected override void OnFontChanged(EventArgs e)
\r
1074 if (this.DesignMode)
\r
1076 base.OnFontChanged(e);
\r
1081 /// MouseDownイベントを発生させます
\r
1083 /// <param name="e">インベントデータ</param>
\r
1084 protected override void OnMouseDown(MouseEventArgs e)
\r
1086 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
\r
1087 if (tp == TextPoint.Null)
\r
1089 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
1091 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
\r
1093 base.OnMouseDown(mouseEvent);
\r
1095 if (mouseEvent.Handled)
\r
1098 if (e.Button == MouseButtons.Left)
\r
1100 FoldingItem foldingData = this.View.HitFoldingData(e.Location.X, tp.row);
\r
1101 if (foldingData != null)
\r
1103 if (foldingData.Expand)
\r
1104 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
\r
1106 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
\r
1107 this.Controller.JumpCaret(foldingData.Start, false);
\r
1111 this.Controller.JumpCaret(tp.row, tp.col, false);
\r
1113 this.View.IsFocused = true;
\r
1120 /// MouseClickイベントを発生させます
\r
1122 /// <param name="e">インベントデータ</param>
\r
1123 protected override void OnMouseClick(MouseEventArgs e)
\r
1125 int index = this.GetIndexFromPostion(e.Location);
\r
1127 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
\r
1129 base.OnMouseClick(mouseEvent);
\r
1133 /// MouseDoubleClickイベントを発生させます
\r
1135 /// <param name="e">インベントデータ</param>
\r
1136 protected override void OnMouseDoubleClick(MouseEventArgs e)
\r
1138 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
\r
1139 if (tp == TextPoint.Null)
\r
1141 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
1143 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
\r
1145 base.OnMouseDoubleClick(mouseEvent);
\r
1147 if (mouseEvent.Handled)
\r
1150 this.Controller.SelectWord(index);
\r
1156 /// MouseMoveイベントを発生させます
\r
1158 /// <param name="e">インベントデータ</param>
\r
1159 protected override void OnMouseMove(MouseEventArgs e)
\r
1161 if (this.Focused == false)
\r
1164 base.OnMouseMove(e);
\r
1166 if (this.View.HitTextArea(e.Location.X, e.Location.Y))
\r
1168 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
\r
1169 if (this.Controller.IsMarker(tp, HilightType.Url))
\r
1170 this.Cursor = Cursors.Hand;
\r
1172 this.Cursor = Cursors.IBeam;
\r
1174 if (e.Button == MouseButtons.Left)
\r
1176 this.Controller.MoveCaretAndSelect(tp);
\r
1182 this.Cursor = Cursors.Arrow;
\r
1187 /// MouseWheelイベントを発生させます
\r
1189 /// <param name="e">インベントデータ</param>
\r
1190 protected override void OnMouseWheel(MouseEventArgs e)
\r
1192 base.OnMouseWheel(e);
\r
1194 ScrollDirection dir = e.Delta > 0 ? ScrollDirection.Up : ScrollDirection.Down;
\r
1195 this.Controller.Scroll(dir, SystemInformation.MouseWheelScrollLines, false, false);
\r
1200 /// Paintイベントを発生させます
\r
1202 /// <param name="e">インベントデータ</param>
\r
1203 protected override void OnPaint(PaintEventArgs e)
\r
1207 SolidBrush brush = new SolidBrush(this.BackColor);
\r
1208 e.Graphics.FillRectangle(brush, this.ClientRectangle);
\r
1210 }else if (this.Document.FireUpdateEvent){
\r
1211 this.render.BegineDraw();
\r
1212 this.View.Draw(e.ClipRectangle);
\r
1213 this.render.EndDraw();
\r
1219 /// PaintBackgroundイベントを発生させます
\r
1221 /// <param name="e">インベントデータ</param>
\r
1222 protected override void OnPaintBackground(PaintEventArgs e)
\r
1227 /// PreviewKeyDownイベントを発生させます
\r
1229 /// <param name="e">インベントデータ</param>
\r
1230 protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
\r
1232 base.OnPreviewKeyDown(e);
\r
1233 switch (e.KeyCode)
\r
1240 e.IsInputKey = true;
\r
1246 /// KeyDownイベントを発生させます
\r
1248 /// <param name="e">インベントデータ</param>
\r
1249 protected override void OnKeyDown(KeyEventArgs e)
\r
1251 base.OnKeyDown(e);
\r
1256 switch (e.KeyCode)
\r
1259 this.Controller.MoveCaretVertical(-1, e.Shift);
\r
1263 this.Controller.MoveCaretVertical(+1, e.Shift);
\r
1267 this.Controller.MoveCaretHorizontical(-1, e.Shift, e.Control);
\r
1271 this.Controller.MoveCaretHorizontical(1, e.Shift, e.Control);
\r
1275 this.Controller.Scroll(ScrollDirection.Up, this.VScrollBar.LargeChange,e.Shift,true);
\r
1278 case Keys.PageDown:
\r
1279 this.Controller.Scroll(ScrollDirection.Down, this.VScrollBar.LargeChange,e.Shift,true);
\r
1283 if (this.InsertMode)
\r
1284 this.InsertMode = false;
\r
1286 this.InsertMode = true;
\r
1289 this.Controller.DoDeleteAction();
\r
1293 this.Controller.DoBackSpaceAction();
\r
1298 this.Controller.JumpToHead(e.Shift);
\r
1300 this.Controller.JumpToLineHead(this.View.CaretPostion.row, e.Shift);
\r
1305 this.Controller.JumpToEnd(e.Shift);
\r
1307 this.Controller.JumpToLineEnd(this.View.CaretPostion.row, e.Shift);
\r
1311 if (this.Controller.SelectionLength == 0)
\r
1312 this.Controller.DoInputChar('\t');
\r
1314 this.Controller.DownIndent();
\r
1316 this.Controller.UpIndent();
\r
1323 /// KeyPressイベントを発生させます
\r
1325 /// <param name="e">インベントデータ</param>
\r
1326 protected override void OnKeyPress(KeyPressEventArgs e)
\r
1328 base.OnKeyPress(e);
\r
1333 switch (e.KeyChar)
\r
1336 this.Controller.DoEnterAction();
\r
1340 break; //OnKeyDownで処理しているので不要
\r
1342 if (IsInputChar(e.KeyChar) == false)
\r
1344 this.Controller.DoInputChar(e.KeyChar);
\r
1351 /// ClientSizeChangedイベントを発生させます
\r
1353 /// <param name="e">インベントデータ</param>
\r
1354 protected override void OnClientSizeChanged(EventArgs e)
\r
1356 if (this.DesignMode)
\r
1358 base.OnClientSizeChanged(e);
\r
1360 this.View.PageBound = new Rectangle(0,
\r
1362 Math.Max(this.ClientRectangle.Width - this.VScrollBar.Width,0),
\r
1363 Math.Max(this.ClientRectangle.Height - this.HScrollBar.Height, 0));
\r
1369 void View_SrcChanged(object sender, EventArgs e)
\r
1371 if (this.View.Src.Row > this.VScrollBar.Maximum)
\r
1372 this.VScrollBar.Maximum = this.View.Src.Row + this.View.LineCountOnScreen + 1;
\r
1374 int srcX = (int)Math.Abs(this.View.Src.X);
\r
1375 if (srcX > this.HScrollBar.Maximum)
\r
1376 this.HScrollBar.Maximum = srcX + (int)this.View.PageBound.Width + 1;
\r
1378 this.HScrollBar.Value = srcX;
\r
1380 this.VScrollBar.Value = this.View.Src.Row;
\r
1383 void FooTextBox_RightToLeftChanged(object sender, EventArgs e)
\r
1385 this.render.RightToLeft = this.RightToLeft == System.Windows.Forms.RightToLeft.Yes;
\r
1388 void VScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
1390 this.View.TryScroll(this.View.Src.X, e.NewValue);
\r
1394 void HScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
1397 if (this.RightToLeft == System.Windows.Forms.RightToLeft.Yes)
\r
1398 toX = -e.NewValue;
\r
1401 this.View.TryScroll(toX, this.View.Src.Row);
\r
1405 void Ime_StartCompstion(object sender, StartCompstionEventArgs e)
\r
1407 this.Ime.Font = this.Font;
\r
1408 System.Drawing.Point p = this.GetPostionFromIndex(this.Controller.SelectionStart);
\r
1410 this.render.GetDpi(out dpi, out dpi);
\r
1411 p.X = (int)(p.X * dpi / 96);
\r
1412 p.Y = (int)(p.Y * dpi / 96);
\r
1413 this.Ime.Location = p;
\r
1414 this.View.HideCaret = true;
\r
1417 void Ime_EndCompstion(object sender, EndCompstionEventArgs e)
\r
1419 this.View.HideCaret = false;
\r
1422 void Ime_ImeCompstion(object sender, ImeCompstionEventArgs e)
\r
1424 this.Controller.DoInputString(e.InputText);
\r
1428 void Ime_ImeDocumentFeed(object sender, ImeDocumentFeedEventArgs e)
\r
1430 TextPoint tp = this.CaretPostion;
\r
1431 e.Pragraph = this.LayoutLines[tp.row];
\r
1435 void Ime_ImeReconvert(object sender, ImeReconvertStringEventArgs e)
\r
1437 if (this.RectSelection)
\r
1439 if (this.Controller.SelectionLength == 0)
\r
1441 TextPoint tp = this.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart);
\r
1442 e.TargetString = this.LayoutLines[tp.row];
\r
1443 e.AutoAdjust = true;
\r
1447 e.TargetString = this.SelectedText;
\r
1448 if (e.TargetString.Length > 40)
\r
1449 e.TargetString.Remove(40);
\r
1451 e.CaretPostion = this.View.CaretLocation;
\r
1454 void Ime_ImeQueryReconvert(object sender, ImeQueryRecovertStringEventArgs e)
\r
1456 TextPoint tp = this.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart);
\r
1457 tp.col = e.offset;
\r
1459 int index = this.View.GetIndexFromLayoutLine(tp);
\r
1461 this.Select(index, index + e.length);
\r
1464 void Controller_CaretMoved(object sender, EventArgs e)
\r
1466 this.SelectionChanged(this, null);
\r
1469 void initScrollBars()
\r
1471 this.VScrollBar.SmallChange = 1;
\r
1472 this.VScrollBar.LargeChange = this.View.LineCountOnScreen;
\r
1473 this.VScrollBar.Maximum = this.View.LayoutLines.Count + this.View.LineCountOnScreen + 1;
\r
1474 this.HScrollBar.SmallChange = 10;
\r
1475 this.HScrollBar.LargeChange = (int)this.View.PageBound.Width;
\r
1476 this.HScrollBar.Maximum = this.HScrollBar.LargeChange + 1;
\r
1479 void Timer_Tick(object sender,EventArgs e)
\r
1481 if (this.View.CaretPostion.row >= this.View.LayoutLines.Count || DesignMode)
\r
1484 ITextLayout layout = this.View.LayoutLines.GetLayout(this.View.CaretPostion.row);
\r
1486 Size redrawSize = new Size();
\r
1487 redrawSize.Width = layout.GetWidthFromIndex(this.View.CaretPostion.col);
\r
1488 if (redrawSize.Width == 0.0)
\r
1489 redrawSize.Width = this.View.CaretWidthOnInsertMode;
\r
1490 redrawSize.Height = layout.Height;
\r
1492 bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding();
\r
1495 this.Invalidate();
\r
1497 this.Invalidate(new System.Drawing.Rectangle(this.View.CaretLocation, redrawSize));
\r
1500 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
\r
1502 this.SetSystemParamaters();
\r
1506 void SetSystemParamaters()
\r
1508 int CaretBlinkTime = SystemInformation.CaretBlinkTime;
\r
1509 if (CaretBlinkTime == -1)
\r
1511 this.View.CaretBlink = false;
\r
1512 if (this.IsHandleCreated)
\r
1513 this.BeginInvoke(new Action(() =>
\r
1515 this.Timer.Stop();
\r
1520 this.View.CaretBlink = true;
\r
1521 this.View.CaretBlinkTime = CaretBlinkTime * 2;
\r
1522 if(this.IsHandleCreated)
\r
1523 this.BeginInvoke(new Action(() =>
\r
1525 this.Timer.Start();
\r
1528 this.View.CaretWidthOnInsertMode = SystemInformation.CaretWidth;
\r
1534 /// FooEditEngineで使用するマウスイベント
\r
1536 public class FooMouseEventArgs : MouseEventArgs
\r
1539 /// イベントが発生したインデックス
\r
1543 /// 既定の処理を省略するなら真。そうでなければ偽
\r
1545 public bool Handled;
\r
1549 /// <param name="index">インデックス</param>
\r
1550 /// <param name="button">押されているボタン</param>
\r
1551 /// <param name="clicks">ボタンが押された回数</param>
\r
1552 /// <param name="x">マウスカーソルがあるX座標</param>
\r
1553 /// <param name="y">マウスカーソルがあるY座標</param>
\r
1554 /// <param name="delta">ホイールの回転方向</param>
\r
1555 public FooMouseEventArgs(int index, MouseButtons button, int clicks, int x, int y, int delta)
\r
1556 : base(button, clicks, x, y, delta)
\r
1558 this.index = index;
\r