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