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.Document = new Document();
\r
76 this.render = new D2DTextRender(this);
\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
122 /// テキスト描写に使用するアンチエイリアシングモードを表す
\r
124 [BrowsableAttribute(false)]
\r
125 public TextAntialiasMode TextAntialiasMode
\r
129 return this.render.TextAntialiasMode;
\r
133 this.render.TextAntialiasMode = value;
\r
140 [BrowsableAttribute(false)]
\r
141 public MarkerPatternSet MarkerPatternSet
\r
145 return this.View.MarkerPatternSet;
\r
152 [BrowsableAttribute(false)]
\r
153 public Document Document
\r
162 [BrowsableAttribute(false)]
\r
163 public LineToIndexTable LayoutLines
\r
165 get { return this.View.LayoutLines; }
\r
171 [BrowsableAttribute(false)]
\r
172 public IHilighter Hilighter
\r
174 get { return this.View.Hilighter; }
\r
175 set { this.View.Hilighter = value; this.View.LayoutLines.ClearLayoutCache(); }
\r
179 /// フォールティングを作成するインターフェイスを表す
\r
181 [BrowsableAttribute(false)]
\r
182 public IFoldingStrategy FoldingStrategy
\r
186 return this.View.LayoutLines.FoldingStrategy;
\r
190 this.View.LayoutLines.FoldingStrategy = value;
\r
192 this.View.LayoutLines.FoldingCollection.Clear();
\r
199 public BorderStyle BorderStyle
\r
201 get { return this._BoderStyle; }
\r
202 set { this._BoderStyle = value; this.UpdateStyles(); }
\r
209 [DefaultValue(false)]
\r
210 public bool DrawLineNumber
\r
214 return this.View.DrawLineNumber;
\r
218 this.View.DrawLineNumber = value;
\r
219 this.JumpCaret(this.CaretPostion.row,this.CaretPostion.col);
\r
226 [DefaultValue(false)]
\r
227 public bool DrawRuler
\r
231 return !this.View.HideRuler;
\r
235 this.View.HideRuler = !value;
\r
236 this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
\r
244 /// 反映させるためにはレイアウト行の再構築を行う必要があります
\r
246 [DefaultValue(LineBreakMethod.None)]
\r
247 public LineBreakMethod LineBreakMethod
\r
251 return this.View.LineBreak;
\r
255 this.View.LineBreak = value;
\r
263 /// 反映させるためにはレイアウト行の再構築を行う必要があります
\r
266 public int LineBreakCharCount
\r
270 return this.View.LineBreakCharCount;
\r
274 this.View.LineBreakCharCount = value;
\r
281 [DefaultValue(false)]
\r
282 public bool UrlMark
\r
286 return this.View.UrlMark;
\r
290 this.View.UrlMark = value;
\r
298 public int TabStops
\r
300 get { return this.View.TabStops; }
\r
302 this.View.TabStops = value;
\r
303 this.View.AdjustCaretAndSrc();
\r
304 this.TabStopChange(this, null);
\r
309 /// 全角スペースを表示するなら真。そうでないなら偽
\r
311 [DefaultValue(false)]
\r
312 public bool ShowFullSpace
\r
316 return this.render.ShowFullSpace;
\r
320 this.render.ShowFullSpace = value;
\r
325 /// 半角スペースを表示するなら真。そうでないなら偽
\r
327 [DefaultValue(false)]
\r
328 public bool ShowHalfSpace
\r
332 return this.render.ShowHalfSpace;
\r
336 this.render.ShowHalfSpace = value;
\r
341 /// タブを表示するなら真。そうでないなら偽
\r
343 [DefaultValue(false)]
\r
344 public bool ShowTab
\r
348 return this.render.ShowTab;
\r
352 this.render.ShowTab = value;
\r
357 /// 改行マークを表示するなら真。そうでないなら偽
\r
359 [DefaultValue(false)]
\r
360 public bool ShowLineBreak
\r
364 return this.render.ShowLineBreak;
\r
368 this.render.ShowLineBreak = value;
\r
376 /// 未選択状態で文字列を代入した場合、キャレット位置に挿入され、そうでないときは置き換えられます。
\r
378 [BrowsableAttribute(false)]
\r
379 public string SelectedText
\r
381 get { return this.Controller.SelectedText; }
\r
382 set { this.Controller.SelectedText = value; }
\r
388 [BrowsableAttribute(false)]
\r
389 public TextPoint CaretPostion
\r
391 get { return this.View.CaretPostion; }
\r
398 /// Lengthが0の場合はキャレット位置を表します
\r
399 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
\r
401 [BrowsableAttribute(false)]
\r
402 public TextRange Selection
\r
404 get { return new TextRange(this.Controller.SelectionStart,this.Controller.SelectionLength); }
\r
407 this.Controller.Select(value.Index, value.Length);
\r
414 [DefaultValue(true)]
\r
415 public bool InsertMode
\r
417 get { return this.View.InsertMode; }
\r
420 this.View.InsertMode = value;
\r
421 this.InsetModeChange(this, null);
\r
428 [DefaultValue(false)]
\r
429 public bool RectSelection
\r
431 get { return this.Controller.RectSelection; }
\r
432 set { this.Controller.RectSelection = value; }
\r
435 System.Drawing.Color ForegroundColor = SystemColors.ControlText,
\r
436 BackgroundColor = SystemColors.Control,
\r
437 HilightColor = System.Drawing.Color.DeepSkyBlue,
\r
438 Keyword1Color = System.Drawing.Color.Blue,
\r
439 Keyword2Color = System.Drawing.Color.DarkCyan,
\r
440 LiteralColor = System.Drawing.Color.Brown,
\r
441 UrlColor = System.Drawing.Color.Blue,
\r
442 ControlCharColor = System.Drawing.Color.Gray,
\r
443 CommentColor = System.Drawing.Color.Green,
\r
444 InsertCaretColor = System.Drawing.Color.Black,
\r
445 OverwriteCaretColor = System.Drawing.Color.Black,
\r
446 LineMarkerColor = System.Drawing.Color.WhiteSmoke,
\r
447 UpdateAreaColor = System.Drawing.Color.MediumSeaGreen;
\r
452 public System.Drawing.Color Foreground
\r
456 return this.ForegroundColor;
\r
460 this.render.Foreground = D2DTextRender.ToColor4(value);
\r
461 this.ForegroundColor = value;
\r
468 public System.Drawing.Color Background
\r
472 return this.BackgroundColor;
\r
476 this.render.Background = D2DTextRender.ToColor4(value);
\r
477 this.BackgroundColor = value;
\r
484 public System.Drawing.Color InsertCaret
\r
488 return this.InsertCaretColor;
\r
492 this.InsertCaretColor = value;
\r
493 this.render.InsertCaret = D2DTextRender.ToColor4(value);
\r
500 public System.Drawing.Color OverwriteCaret
\r
504 return this.OverwriteCaretColor;
\r
508 this.OverwriteCaretColor = value;
\r
509 this.render.OverwriteCaret = D2DTextRender.ToColor4(value);
\r
516 public System.Drawing.Color LineMarker
\r
520 return this.LineMarkerColor;
\r
524 this.LineMarkerColor = value;
\r
525 this.render.LineMarker = D2DTextRender.ToColor4(value);
\r
532 public System.Drawing.Color ControlChar
\r
536 return this.ControlCharColor;
\r
540 this.ControlCharColor = value;
\r
541 this.render.ControlChar = D2DTextRender.ToColor4(value);
\r
548 public System.Drawing.Color UpdateArea
\r
552 return this.UpdateAreaColor;
\r
556 this.UpdateAreaColor = value;
\r
557 this.render.UpdateArea = D2DTextRender.ToColor4(value);
\r
564 public System.Drawing.Color Url
\r
568 return this.UrlColor;
\r
572 this.UrlColor = value;
\r
573 this.render.Url = D2DTextRender.ToColor4(value);
\r
580 public System.Drawing.Color Hilight
\r
584 return this.HilightColor;
\r
588 this.HilightColor = value;
\r
589 this.render.Hilight = D2DTextRender.ToColor4(value);
\r
596 public System.Drawing.Color Comment
\r
600 return this.CommentColor;
\r
604 this.CommentColor = value;
\r
605 this.render.Comment = D2DTextRender.ToColor4(value);
\r
612 public System.Drawing.Color Literal
\r
616 return this.LiteralColor;
\r
620 this.LiteralColor = value;
\r
621 this.render.Literal = D2DTextRender.ToColor4(value);
\r
628 public System.Drawing.Color Keyword1
\r
632 return this.Keyword1Color;
\r
636 this.Keyword1Color = value;
\r
637 this.render.Keyword1 = D2DTextRender.ToColor4(value);
\r
644 public System.Drawing.Color Keyword2
\r
648 return this.Keyword2Color;
\r
652 this.Keyword2Color = value;
\r
653 this.render.Keyword2 = D2DTextRender.ToColor4(value);
\r
658 /// キャレットに下線を描くかどうか
\r
660 [DefaultValue(false)]
\r
661 public bool DrawCaretLine
\r
663 get { return !this.View.HideLineMarker; }
\r
664 set { this.View.HideLineMarker = !value; }
\r
670 /// <param name="start">開始インデックス</param>
\r
671 /// <param name="length">長さ</param>
\r
672 public void Select(int start, int length)
\r
674 this.Controller.Select(start, length);
\r
675 this.HScrollBar.Value = (int)this.View.Src.X;
\r
676 this.VScrollBar.Value = this.View.Src.Row;
\r
682 public void SelectAll()
\r
684 this.Controller.Select(0, this.Document.Length - 1);
\r
690 public void DeSelectAll()
\r
692 this.Controller.DeSelectAll();
\r
700 string text = this.SelectedText;
\r
701 if(text != null && text != string.Empty)
\r
702 Clipboard.SetText(text);
\r
706 /// クリップボードにコピーし、指定した範囲にある文字列をすべて削除します
\r
710 string text = this.SelectedText;
\r
711 if (text != null && text != string.Empty)
\r
713 Clipboard.SetText(text);
\r
714 this.Controller.SelectedText = "";
\r
719 /// クリップボードの内容をペーストします
\r
721 public void Paste()
\r
723 if (Clipboard.ContainsText() == false)
\r
725 this.Controller.SelectedText = Clipboard.GetText();
\r
729 /// キャレットを指定した行に移動させます
\r
731 /// <param name="index">インデックス</param>
\r
732 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
\r
733 public void JumpCaret(int index)
\r
735 this.Controller.JumpCaret(index);
\r
738 /// キャレットを指定した行と桁に移動させます
\r
740 /// <param name="row">行番号</param>
\r
741 /// <param name="col">桁</param>
\r
742 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
\r
743 public void JumpCaret(int row, int col)
\r
745 this.Controller.JumpCaret(row, col);
\r
751 public new void Refresh()
\r
753 if (this.Document.FireUpdateEvent == false)
\r
754 throw new InvalidOperationException("");
\r
755 if(this.View.CaretBlink)
\r
756 this.View.CaretBlink = true;
\r
764 /// <param name="row">行</param>
\r
765 /// <returns>高さ</returns>
\r
766 public double GetLineHeight(int row)
\r
768 if (this.Document.FireUpdateEvent == false)
\r
769 throw new InvalidOperationException("");
\r
770 return this.View.LayoutLines.GetLayout(row).Height;
\r
776 /// <param name="tp">テキストポイント</param>
\r
777 /// <returns>座標</returns>
\r
778 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
\r
779 public System.Drawing.Point GetPostionFromTextPoint(TextPoint tp)
\r
781 if (this.Document.FireUpdateEvent == false)
\r
782 throw new InvalidOperationException("");
\r
783 return this.View.GetPostionFromTextPoint(tp);
\r
787 /// 対応するテキストポイントを返す
\r
789 /// <param name="p">クライアント領域の原点を左上とする座標</param>
\r
790 /// <returns>テキストポイント</returns>
\r
791 public TextPoint GetTextPointFromPostion(System.Drawing.Point p)
\r
793 if (this.Document.FireUpdateEvent == false)
\r
794 throw new InvalidOperationException("");
\r
795 return this.View.GetTextPointFromPostion(p);
\r
799 /// インデックスに対応する座標を得ます
\r
801 /// <param name="index">インデックス</param>
\r
802 /// <returns>座標を返す</returns>
\r
803 public System.Drawing.Point GetPostionFromIndex(int index)
\r
805 if (this.Document.FireUpdateEvent == false)
\r
806 throw new InvalidOperationException("");
\r
807 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
\r
808 return this.View.GetPostionFromTextPoint(tp);
\r
812 /// 座標からインデックスに変換します
\r
814 /// <param name="p">座標</param>
\r
815 /// <returns>インデックスを返す</returns>
\r
816 public int GetIndexFromPostion(System.Drawing.Point p)
\r
818 if (this.Document.FireUpdateEvent == false)
\r
819 throw new InvalidOperationException("");
\r
820 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
821 return this.View.GetIndexFromLayoutLine(tp);
\r
825 /// レイアウト行をすべて破棄し、再度レイアウトを行う
\r
827 public void PerfomLayouts()
\r
829 this.View.PerfomLayouts();
\r
834 /// ストリームからドキュメントを構築する
\r
836 /// <param name="tr">TextReader</param>
\r
837 /// <param name="token">キャンセル用トークン</param>
\r
838 /// <returns>Taskオブジェクト</returns>
\r
839 public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)
\r
841 WinFileReader fs = new WinFileReader(tr);
\r
842 await this.LoadAsyncImpl(fs, token);
\r
846 /// ファイルからドキュメントを構築する
\r
848 /// <param name="filepath">ファイルパス</param>
\r
849 /// <param name="enc">エンコード</param>
\r
850 /// <param name="token">キャンセル用トークン</param>
\r
851 /// <returns>Taskオブジェクト</returns>
\r
852 public async Task LoadFileAsync(string filepath, Encoding enc, System.Threading.CancellationTokenSource token)
\r
854 WinFileReader fs = new WinFileReader(filepath, enc);
\r
855 await this.LoadAsyncImpl(fs, token);
\r
858 async Task LoadAsyncImpl(WinFileReader fs, System.Threading.CancellationTokenSource token)
\r
860 this.Enabled = false;
\r
861 this.View.LayoutLines.IsFrozneDirtyFlag = true;
\r
862 await this.Document.LoadAsync(fs, token);
\r
863 this.View.LayoutLines.IsFrozneDirtyFlag = false;
\r
864 this.initScrollBars();
\r
865 this.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, MousePosition.X, MousePosition.Y, 0));
\r
866 this.View.CalculateLineCountOnScreen();
\r
867 this.Enabled = true;
\r
871 /// ドキュメントの内容をファイルに保存する
\r
873 /// <param name="filepath">ファイルパス</param>
\r
874 /// <param name="newLine">改行コード</param>
\r
875 /// <param name="enc">エンコード</param>
\r
876 /// <returns>Taskオブジェクト</returns>
\r
877 public async Task SaveFile(string filepath, Encoding enc, string newLine, System.Threading.CancellationTokenSource token)
\r
879 WinFileWriter fs = new WinFileWriter(filepath, enc);
\r
880 fs.NewLine = newLine;
\r
881 await this.Document.SaveAsync(fs, token);
\r
887 public override Cursor Cursor
\r
891 return base.Cursor;
\r
895 base.Cursor = value;
\r
896 this.VScrollBar.Cursor = DefaultCursor;
\r
897 this.HScrollBar.Cursor = DefaultCursor;
\r
901 private const int WS_BORDER = 0x00800000;
\r
902 private const int WS_EX_CLIENTEDGE = 0x00000200;
\r
904 /// コントロールの外観を指定します
\r
906 protected override CreateParams CreateParams
\r
910 CreateParams cp = base.CreateParams;
\r
911 switch (this.BorderStyle)
\r
913 case BorderStyle.Fixed3D:
\r
914 cp.ExStyle |= WS_EX_CLIENTEDGE;
\r
916 case BorderStyle.FixedSingle:
\r
917 cp.Style |= WS_BORDER;
\r
927 /// <param name="msg">メッセージ</param>
\r
928 /// <param name="keyData">キーデータ</param>
\r
929 /// <returns>文字がコントロールによって処理された場合は true。それ以外の場合は false。 </returns>
\r
930 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
\r
932 const int WM_KEYDOWN = 0x100;
\r
933 if (msg.Msg != WM_KEYDOWN)
\r
934 return base.ProcessCmdKey(ref msg, keyData);
\r
937 case Keys.Control | Keys.C:
\r
940 case Keys.Control | Keys.V:
\r
944 case Keys.Control | Keys.X:
\r
948 case Keys.Control | Keys.Z:
\r
949 this.Document.UndoManager.undo();
\r
952 case Keys.Control | Keys.Y:
\r
953 this.Document.UndoManager.redo();
\r
956 case Keys.Control | Keys.B:
\r
957 if (this.Controller.RectSelection)
\r
958 this.Controller.RectSelection = false;
\r
960 this.Controller.RectSelection = true;
\r
963 return base.ProcessCmdKey(ref msg,keyData);
\r
971 /// <param name="disposing">マネージ リソースとアンマネージ リソースの両方を解放する場合は true。アンマネージ リソースだけを解放する場合は false。</param>
\r
972 protected override void Dispose(bool disposing)
\r
974 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(this.SystemEvents_UserPreferenceChanged);
\r
975 this.render.Dispose();
\r
976 this.Timer.Dispose();
\r
977 base.Dispose(disposing);
\r
981 /// 入力可能な文字かチェックします
\r
983 /// <param name="charCode">入力しようとした文字</param>
\r
984 /// <returns>可能なら真。そうでなければ偽</returns>
\r
985 protected override bool IsInputChar(char charCode)
\r
987 if ((0x20 <= charCode && charCode <= 0x7e)
\r
988 || charCode == '\r'
\r
989 || charCode == '\n'
\r
991 || charCode == '\t'
\r
993 || 0x7f < charCode)
\r
1002 /// PaddingChangedイベントを発生させます
\r
1004 /// <param name="e">インベントデータ</param>
\r
1005 protected override void OnPaddingChanged(EventArgs e)
\r
1007 base.OnPaddingChanged(e);
\r
1008 this.View.Padding = new Padding(this.Padding.Left, this.Padding.Top, this.Padding.Right, this.Padding.Bottom);
\r
1012 /// GotFocusイベントを発生させます
\r
1014 /// <param name="e">インベントデータ</param>
\r
1015 protected override void OnGotFocus(EventArgs e)
\r
1017 base.OnGotFocus(e);
\r
1018 this.View.IsFocused = true;
\r
1023 /// LostFocusイベントを発生させます
\r
1025 /// <param name="e">インベントデータ</param>
\r
1026 protected override void OnLostFocus(EventArgs e)
\r
1028 base.OnLostFocus(e);
\r
1029 this.View.IsFocused = false;
\r
1034 /// FontChangedイベントを発生させます
\r
1036 /// <param name="e">インベントデータ</param>
\r
1037 protected override void OnFontChanged(EventArgs e)
\r
1039 if (this.DesignMode)
\r
1041 base.OnFontChanged(e);
\r
1046 /// MouseDownイベントを発生させます
\r
1048 /// <param name="e">インベントデータ</param>
\r
1049 protected override void OnMouseDown(MouseEventArgs e)
\r
1051 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
\r
1052 if (tp == TextPoint.Null)
\r
1054 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
1056 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
\r
1058 base.OnMouseDown(mouseEvent);
\r
1060 if (mouseEvent.Handled)
\r
1063 if (e.Button == MouseButtons.Left)
\r
1065 FoldingItem foldingData = this.View.HitFoldingData(e.Location.X, tp.row);
\r
1066 if (foldingData != null)
\r
1068 if (foldingData.Expand)
\r
1069 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
\r
1071 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
\r
1072 this.Controller.JumpCaret(foldingData.Start, false);
\r
1076 this.Controller.JumpCaret(tp.row, tp.col, false);
\r
1078 this.View.IsFocused = true;
\r
1085 /// MouseClickイベントを発生させます
\r
1087 /// <param name="e">インベントデータ</param>
\r
1088 protected override void OnMouseClick(MouseEventArgs e)
\r
1090 int index = this.GetIndexFromPostion(e.Location);
\r
1092 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
\r
1094 base.OnMouseClick(mouseEvent);
\r
1098 /// MouseDoubleClickイベントを発生させます
\r
1100 /// <param name="e">インベントデータ</param>
\r
1101 protected override void OnMouseDoubleClick(MouseEventArgs e)
\r
1103 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
\r
1104 if (tp == TextPoint.Null)
\r
1106 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
1108 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
\r
1110 base.OnMouseDoubleClick(mouseEvent);
\r
1112 if (mouseEvent.Handled)
\r
1115 this.Controller.SelectWord(index);
\r
1121 /// MouseMoveイベントを発生させます
\r
1123 /// <param name="e">インベントデータ</param>
\r
1124 protected override void OnMouseMove(MouseEventArgs e)
\r
1126 if (this.Focused == false)
\r
1129 base.OnMouseMove(e);
\r
1131 if (this.View.HitTextArea(e.Location.X, e.Location.Y))
\r
1133 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
\r
1134 if (this.Controller.IsMarker(tp, HilightType.Url))
\r
1135 this.Cursor = Cursors.Hand;
\r
1137 this.Cursor = Cursors.IBeam;
\r
1139 if (e.Button == MouseButtons.Left)
\r
1141 this.Controller.MoveCaretAndSelect(tp);
\r
1147 this.Cursor = Cursors.Arrow;
\r
1152 /// MouseWheelイベントを発生させます
\r
1154 /// <param name="e">インベントデータ</param>
\r
1155 protected override void OnMouseWheel(MouseEventArgs e)
\r
1157 base.OnMouseWheel(e);
\r
1159 ScrollDirection dir = e.Delta > 0 ? ScrollDirection.Up : ScrollDirection.Down;
\r
1160 this.Controller.Scroll(dir, SystemInformation.MouseWheelScrollLines, false, false);
\r
1165 /// Paintイベントを発生させます
\r
1167 /// <param name="e">インベントデータ</param>
\r
1168 protected override void OnPaint(PaintEventArgs e)
\r
1172 SolidBrush brush = new SolidBrush(this.BackColor);
\r
1173 e.Graphics.FillRectangle(brush, this.ClientRectangle);
\r
1175 }else if (this.Document.FireUpdateEvent){
\r
1176 this.render.BegineDraw();
\r
1177 this.View.Draw(e.ClipRectangle);
\r
1178 this.render.EndDraw();
\r
1184 /// PaintBackgroundイベントを発生させます
\r
1186 /// <param name="e">インベントデータ</param>
\r
1187 protected override void OnPaintBackground(PaintEventArgs e)
\r
1192 /// PreviewKeyDownイベントを発生させます
\r
1194 /// <param name="e">インベントデータ</param>
\r
1195 protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
\r
1197 base.OnPreviewKeyDown(e);
\r
1198 switch (e.KeyCode)
\r
1205 e.IsInputKey = true;
\r
1211 /// KeyDownイベントを発生させます
\r
1213 /// <param name="e">インベントデータ</param>
\r
1214 protected override void OnKeyDown(KeyEventArgs e)
\r
1216 base.OnKeyDown(e);
\r
1221 switch (e.KeyCode)
\r
1224 this.Controller.MoveCaretVertical(-1, e.Shift);
\r
1228 this.Controller.MoveCaretVertical(+1, e.Shift);
\r
1232 this.Controller.MoveCaretHorizontical(-1, e.Shift, e.Control);
\r
1236 this.Controller.MoveCaretHorizontical(1, e.Shift, e.Control);
\r
1240 this.Controller.Scroll(ScrollDirection.Up, this.VScrollBar.LargeChange,e.Shift,true);
\r
1243 case Keys.PageDown:
\r
1244 this.Controller.Scroll(ScrollDirection.Down, this.VScrollBar.LargeChange,e.Shift,true);
\r
1248 if (this.InsertMode)
\r
1249 this.InsertMode = false;
\r
1251 this.InsertMode = true;
\r
1254 this.Controller.DoDeleteAction();
\r
1258 this.Controller.DoBackSpaceAction();
\r
1263 this.Controller.JumpToHead(e.Shift);
\r
1265 this.Controller.JumpToLineHead(this.View.CaretPostion.row, e.Shift);
\r
1270 this.Controller.JumpToEnd(e.Shift);
\r
1272 this.Controller.JumpToLineEnd(this.View.CaretPostion.row, e.Shift);
\r
1276 if (this.Controller.SelectionLength == 0)
\r
1277 this.Controller.DoInputChar('\t');
\r
1279 this.Controller.DownIndent();
\r
1281 this.Controller.UpIndent();
\r
1288 /// KeyPressイベントを発生させます
\r
1290 /// <param name="e">インベントデータ</param>
\r
1291 protected override void OnKeyPress(KeyPressEventArgs e)
\r
1293 base.OnKeyPress(e);
\r
1298 switch (e.KeyChar)
\r
1301 this.Controller.DoEnterAction();
\r
1305 break; //OnKeyDownで処理しているので不要
\r
1307 if (IsInputChar(e.KeyChar) == false)
\r
1309 this.Controller.DoInputChar(e.KeyChar);
\r
1316 /// ClientSizeChangedイベントを発生させます
\r
1318 /// <param name="e">インベントデータ</param>
\r
1319 protected override void OnClientSizeChanged(EventArgs e)
\r
1321 if (this.DesignMode)
\r
1323 base.OnClientSizeChanged(e);
\r
1325 this.View.PageBound = new Rectangle(0,
\r
1327 Math.Max(this.ClientRectangle.Width - this.VScrollBar.Width,0),
\r
1328 Math.Max(this.ClientRectangle.Height - this.HScrollBar.Height, 0));
\r
1334 void View_SrcChanged(object sender, EventArgs e)
\r
1336 if (this.View.Src.Row > this.VScrollBar.Maximum)
\r
1337 this.VScrollBar.Maximum = this.View.Src.Row + this.View.LineCountOnScreen + 1;
\r
1339 int srcX = (int)Math.Abs(this.View.Src.X);
\r
1340 if (srcX > this.HScrollBar.Maximum)
\r
1341 this.HScrollBar.Maximum = srcX + (int)this.View.PageBound.Width + 1;
\r
1343 this.HScrollBar.Value = srcX;
\r
1345 this.VScrollBar.Value = this.View.Src.Row;
\r
1348 void FooTextBox_RightToLeftChanged(object sender, EventArgs e)
\r
1350 this.render.RightToLeft = this.RightToLeft == System.Windows.Forms.RightToLeft.Yes;
\r
1353 void VScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
1355 this.View.TryScroll(this.View.Src.X, e.NewValue);
\r
1359 void HScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
1362 if (this.RightToLeft == System.Windows.Forms.RightToLeft.Yes)
\r
1363 toX = -e.NewValue;
\r
1366 this.View.TryScroll(toX, this.View.Src.Row);
\r
1370 void Ime_StartCompstion(object sender, StartCompstionEventArgs e)
\r
1372 this.Ime.Font = this.Font;
\r
1373 System.Drawing.Point p = this.GetPostionFromIndex(this.Controller.SelectionStart);
\r
1375 this.render.GetDpi(out dpi, out dpi);
\r
1376 p.X = (int)(p.X * dpi / 96);
\r
1377 p.Y = (int)(p.Y * dpi / 96);
\r
1378 this.Ime.Location = p;
\r
1379 this.View.HideCaret = true;
\r
1382 void Ime_EndCompstion(object sender, EndCompstionEventArgs e)
\r
1384 this.View.HideCaret = false;
\r
1387 void Ime_ImeCompstion(object sender, ImeCompstionEventArgs e)
\r
1389 this.Controller.DoInputString(e.InputText);
\r
1393 void Ime_ImeDocumentFeed(object sender, ImeDocumentFeedEventArgs e)
\r
1395 TextPoint tp = this.CaretPostion;
\r
1396 e.Pragraph = this.LayoutLines[tp.row];
\r
1400 void Ime_ImeReconvert(object sender, ImeReconvertStringEventArgs e)
\r
1402 if (this.RectSelection)
\r
1404 if (this.Controller.SelectionLength == 0)
\r
1406 TextPoint tp = this.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart);
\r
1407 e.TargetString = this.LayoutLines[tp.row];
\r
1408 e.AutoAdjust = true;
\r
1412 e.TargetString = this.SelectedText;
\r
1413 if (e.TargetString.Length > 40)
\r
1414 e.TargetString.Remove(40);
\r
1416 e.CaretPostion = this.View.CaretLocation;
\r
1419 void Ime_ImeQueryReconvert(object sender, ImeQueryRecovertStringEventArgs e)
\r
1421 TextPoint tp = this.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart);
\r
1422 tp.col = e.offset;
\r
1424 int index = this.View.GetIndexFromLayoutLine(tp);
\r
1426 this.Select(index, index + e.length);
\r
1429 void Controller_CaretMoved(object sender, EventArgs e)
\r
1431 this.SelectionChanged(this, null);
\r
1434 void initScrollBars()
\r
1436 this.VScrollBar.SmallChange = 1;
\r
1437 this.VScrollBar.LargeChange = this.View.LineCountOnScreen;
\r
1438 this.VScrollBar.Maximum = this.View.LayoutLines.Count + this.View.LineCountOnScreen + 1;
\r
1439 this.HScrollBar.SmallChange = 10;
\r
1440 this.HScrollBar.LargeChange = (int)this.View.PageBound.Width;
\r
1441 this.HScrollBar.Maximum = this.HScrollBar.LargeChange + 1;
\r
1444 void Timer_Tick(object sender,EventArgs e)
\r
1446 if (this.View.CaretPostion.row >= this.View.LayoutLines.Count || DesignMode)
\r
1449 ITextLayout layout = this.View.LayoutLines.GetLayout(this.View.CaretPostion.row);
\r
1451 Size redrawSize = new Size();
\r
1452 redrawSize.Width = layout.GetWidthFromIndex(this.View.CaretPostion.col);
\r
1453 if (redrawSize.Width == 0.0)
\r
1454 redrawSize.Width = this.View.CaretWidthOnInsertMode;
\r
1455 redrawSize.Height = layout.Height;
\r
1457 this.Invalidate(new System.Drawing.Rectangle(this.View.CaretLocation, redrawSize));
\r
1460 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
\r
1462 this.SetSystemParamaters();
\r
1466 void SetSystemParamaters()
\r
1468 int CaretBlinkTime = SystemInformation.CaretBlinkTime;
\r
1469 if (CaretBlinkTime == -1)
\r
1471 this.View.CaretBlink = false;
\r
1472 if (this.IsHandleCreated)
\r
1473 this.BeginInvoke(new Action(() =>
\r
1475 this.Timer.Stop();
\r
1480 this.View.CaretBlink = true;
\r
1481 this.View.CaretBlinkTime = CaretBlinkTime * 2;
\r
1482 if(this.IsHandleCreated)
\r
1483 this.BeginInvoke(new Action(() =>
\r
1485 this.Timer.Start();
\r
1488 this.View.CaretWidthOnInsertMode = SystemInformation.CaretWidth;
\r
1494 /// FooEditEngineで使用するマウスイベント
\r
1496 public class FooMouseEventArgs : MouseEventArgs
\r
1499 /// イベントが発生したインデックス
\r
1503 /// 既定の処理を省略するなら真。そうでなければ偽
\r
1505 public bool Handled;
\r
1509 /// <param name="index">インデックス</param>
\r
1510 /// <param name="button">押されているボタン</param>
\r
1511 /// <param name="clicks">ボタンが押された回数</param>
\r
1512 /// <param name="x">マウスカーソルがあるX座標</param>
\r
1513 /// <param name="y">マウスカーソルがあるY座標</param>
\r
1514 /// <param name="delta">ホイールの回転方向</param>
\r
1515 public FooMouseEventArgs(int index, MouseButtons button, int clicks, int x, int y, int delta)
\r
1516 : base(button, clicks, x, y, delta)
\r
1518 this.index = index;
\r