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.Document.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.Document.DrawLineNumber;
234 this.Document.DrawLineNumber = value;
241 [DefaultValue(false)]
242 public bool DrawRuler
246 return !this.Document.HideRuler;
250 this.Document.HideRuler = !value;
251 this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
259 /// 反映させるためにはレイアウト行の再構築を行う必要があります
261 [DefaultValue(LineBreakMethod.None)]
262 public LineBreakMethod LineBreakMethod
266 return this.Document.LineBreak;
270 this.Document.LineBreak = value;
278 /// 反映させるためにはレイアウト行の再構築を行う必要があります
281 public int LineBreakCharCount
285 return this.Document.LineBreakCharCount;
289 this.Document.LineBreakCharCount = value;
296 [DefaultValue(false)]
301 return this.Document.UrlMark;
305 this.Document.UrlMark = value;
315 get { return this.Document.TabStops; }
317 this.Document.TabStops = value;
318 this.View.AdjustCaretAndSrc();
319 this.TabStopChange(this, null);
324 /// 全角スペースを表示するなら真。そうでないなら偽
326 [DefaultValue(false)]
327 public bool ShowFullSpace
331 return this.Document.ShowFullSpace;
335 this.Document.ShowFullSpace = value;
340 /// 半角スペースを表示するなら真。そうでないなら偽
342 [DefaultValue(false)]
343 public bool ShowHalfSpace
347 return this.Document.ShowHalfSpace;
351 this.Document.ShowHalfSpace = value;
356 /// タブを表示するなら真。そうでないなら偽
358 [DefaultValue(false)]
363 return this.Document.ShowTab;
367 this.Document.ShowTab = value;
372 /// 改行マークを表示するなら真。そうでないなら偽
374 [DefaultValue(false)]
375 public bool ShowLineBreak
379 return this.Document.ShowLineBreak;
383 this.Document.ShowLineBreak = value;
391 /// 未選択状態で文字列を代入した場合、キャレット位置に挿入され、そうでないときは置き換えられます。
393 [BrowsableAttribute(false)]
394 public string SelectedText
396 get { return this.Controller.SelectedText; }
397 set { this.Controller.SelectedText = value; }
403 [BrowsableAttribute(false)]
404 public TextPoint CaretPostion
406 get { return this.Document.CaretPostion; }
413 /// Lengthが0の場合はキャレット位置を表します
414 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
416 [BrowsableAttribute(false)]
417 public TextRange Selection
419 get { return new TextRange(this.Controller.SelectionStart,this.Controller.SelectionLength); }
422 this.Controller.Select(value.Index, value.Length);
430 public bool InsertMode
432 get { return this.View.InsertMode; }
435 this.View.InsertMode = value;
436 this.InsetModeChange(this, null);
443 [DefaultValue(false)]
444 public bool RectSelection
446 get { return this.Controller.RectSelection; }
447 set { this.Controller.RectSelection = value; }
450 System.Drawing.Color ForegroundColor = SystemColors.ControlText,
451 BackgroundColor = SystemColors.Control,
452 HilightColor = System.Drawing.Color.DeepSkyBlue,
453 Keyword1Color = System.Drawing.Color.Blue,
454 Keyword2Color = System.Drawing.Color.DarkCyan,
455 LiteralColor = System.Drawing.Color.Brown,
456 UrlColor = System.Drawing.Color.Blue,
457 ControlCharColor = System.Drawing.Color.Gray,
458 CommentColor = System.Drawing.Color.Green,
459 InsertCaretColor = System.Drawing.Color.Black,
460 OverwriteCaretColor = System.Drawing.Color.Black,
461 LineMarkerColor = System.Drawing.Color.WhiteSmoke,
462 UpdateAreaColor = System.Drawing.Color.MediumSeaGreen,
463 LineNumberColor = System.Drawing.Color.DimGray;
468 public System.Drawing.Color Foreground
472 return this.ForegroundColor;
476 this.render.Foreground = D2DTextRender.ToColor4(value);
477 this.ForegroundColor = value;
484 public System.Drawing.Color Background
488 return this.BackgroundColor;
492 this.render.Background = D2DTextRender.ToColor4(value);
493 this.BackgroundColor = value;
500 public System.Drawing.Color InsertCaret
504 return this.InsertCaretColor;
508 this.InsertCaretColor = value;
509 this.render.InsertCaret = D2DTextRender.ToColor4(value);
516 public System.Drawing.Color OverwriteCaret
520 return this.OverwriteCaretColor;
524 this.OverwriteCaretColor = value;
525 this.render.OverwriteCaret = D2DTextRender.ToColor4(value);
532 public System.Drawing.Color LineMarker
536 return this.LineMarkerColor;
540 this.LineMarkerColor = value;
541 this.render.LineMarker = D2DTextRender.ToColor4(value);
548 public System.Drawing.Color ControlChar
552 return this.ControlCharColor;
556 this.ControlCharColor = value;
557 this.render.ControlChar = D2DTextRender.ToColor4(value);
564 public System.Drawing.Color UpdateArea
568 return this.UpdateAreaColor;
572 this.UpdateAreaColor = value;
573 this.render.UpdateArea = D2DTextRender.ToColor4(value);
580 public System.Drawing.Color LineNumber
584 return this.LineNumber;
588 this.LineNumber = value;
589 this.render.LineNumber = D2DTextRender.ToColor4(value);
596 public System.Drawing.Color Url
600 return this.UrlColor;
604 this.UrlColor = value;
605 this.render.Url = D2DTextRender.ToColor4(value);
612 public System.Drawing.Color Hilight
616 return this.HilightColor;
620 this.HilightColor = value;
621 this.render.Hilight = D2DTextRender.ToColor4(value);
628 public System.Drawing.Color Comment
632 return this.CommentColor;
636 this.CommentColor = value;
637 this.render.Comment = D2DTextRender.ToColor4(value);
644 public System.Drawing.Color Literal
648 return this.LiteralColor;
652 this.LiteralColor = value;
653 this.render.Literal = D2DTextRender.ToColor4(value);
660 public System.Drawing.Color Keyword1
664 return this.Keyword1Color;
668 this.Keyword1Color = value;
669 this.render.Keyword1 = D2DTextRender.ToColor4(value);
676 public System.Drawing.Color Keyword2
680 return this.Keyword2Color;
684 this.Keyword2Color = value;
685 this.render.Keyword2 = D2DTextRender.ToColor4(value);
692 [DefaultValue(false)]
693 public bool DrawCaretLine
695 get { return !this.View.HideLineMarker; }
696 set { this.View.HideLineMarker = !value; }
702 /// <param name="start">開始インデックス</param>
703 /// <param name="length">長さ</param>
704 public void Select(int start, int length)
706 this.Controller.Select(start, length);
707 this.HScrollBar.Value = (int)this.View.Src.X;
708 this.VScrollBar.Value = this.View.Src.Row;
714 public void SelectAll()
716 this.Controller.Select(0, this.Document.Length - 1);
722 public void DeSelectAll()
724 this.Controller.DeSelectAll();
732 string text = this.SelectedText;
733 if(text != null && text != string.Empty)
734 Clipboard.SetText(text);
738 /// クリップボードにコピーし、指定した範囲にある文字列をすべて削除します
742 string text = this.SelectedText;
743 if (text != null && text != string.Empty)
745 Clipboard.SetText(text);
746 this.Controller.SelectedText = "";
751 /// クリップボードの内容をペーストします
755 if (Clipboard.ContainsText() == false)
757 this.Controller.SelectedText = Clipboard.GetText();
761 /// キャレットを指定した行に移動させます
763 /// <param name="index">インデックス</param>
764 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
765 public void JumpCaret(int index)
767 this.Controller.JumpCaret(index);
770 /// キャレットを指定した行と桁に移動させます
772 /// <param name="row">行番号</param>
773 /// <param name="col">桁</param>
774 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
775 public void JumpCaret(int row, int col)
777 this.Controller.JumpCaret(row, col);
783 public new void Refresh()
785 if (this.Document.FireUpdateEvent == false)
786 throw new InvalidOperationException("");
787 if(this.View.CaretBlink)
788 this.View.CaretBlink = true;
796 /// <param name="row">行</param>
797 /// <returns>高さ</returns>
798 public double GetLineHeight(int row)
800 if (this.Document.FireUpdateEvent == false)
801 throw new InvalidOperationException("");
802 return this.View.LayoutLines.GetLayout(row).Height;
808 /// <param name="tp">テキストポイント</param>
809 /// <returns>座標</returns>
810 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
811 public System.Drawing.Point GetPostionFromTextPoint(TextPoint tp)
813 if (this.Document.FireUpdateEvent == false)
814 throw new InvalidOperationException("");
815 return this.View.GetPostionFromTextPoint(tp);
821 /// <param name="p">クライアント領域の原点を左上とする座標</param>
822 /// <returns>テキストポイント</returns>
823 public TextPoint GetTextPointFromPostion(System.Drawing.Point p)
825 if (this.Document.FireUpdateEvent == false)
826 throw new InvalidOperationException("");
827 return this.View.GetTextPointFromPostion(p);
831 /// インデックスに対応する座標を得ます
833 /// <param name="index">インデックス</param>
834 /// <returns>座標を返す</returns>
835 public System.Drawing.Point GetPostionFromIndex(int index)
837 if (this.Document.FireUpdateEvent == false)
838 throw new InvalidOperationException("");
839 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
840 return this.View.GetPostionFromTextPoint(tp);
846 /// <param name="p">座標</param>
847 /// <returns>インデックスを返す</returns>
848 public int GetIndexFromPostion(System.Drawing.Point p)
850 if (this.Document.FireUpdateEvent == false)
851 throw new InvalidOperationException("");
852 TextPoint tp = this.View.GetTextPointFromPostion(p);
853 return this.View.GetIndexFromLayoutLine(tp);
857 /// レイアウト行をすべて破棄し、再度レイアウトを行う
859 public void PerfomLayouts()
861 this.View.PerfomLayouts();
866 /// ストリームからドキュメントを構築する
868 /// <param name="tr">TextReader</param>
869 /// <param name="token">キャンセル用トークン</param>
870 /// <returns>Taskオブジェクト</returns>
871 public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)
873 WinFileReader fs = new WinFileReader(tr);
874 await this.LoadAsyncImpl(fs, token);
878 /// ファイルからドキュメントを構築する
880 /// <param name="filepath">ファイルパス</param>
881 /// <param name="enc">エンコード</param>
882 /// <param name="token">キャンセル用トークン</param>
883 /// <returns>Taskオブジェクト</returns>
884 public async Task LoadFileAsync(string filepath, Encoding enc, System.Threading.CancellationTokenSource token)
886 WinFileReader fs = new WinFileReader(filepath, enc);
887 await this.LoadAsyncImpl(fs, token);
891 async Task LoadAsyncImpl(WinFileReader fs, System.Threading.CancellationTokenSource token)
893 this.Enabled = false;
894 this.View.LayoutLines.IsFrozneDirtyFlag = true;
895 await this.Document.LoadAsync(fs, token);
896 this.View.LayoutLines.IsFrozneDirtyFlag = false;
897 this.initScrollBars();
898 this.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, MousePosition.X, MousePosition.Y, 0));
899 this.View.CalculateLineCountOnScreen();
904 /// ドキュメントの内容をファイルに保存する
906 /// <param name="filepath">ファイルパス</param>
907 /// <param name="newLine">改行コード</param>
908 /// <param name="enc">エンコード</param>
909 /// <returns>Taskオブジェクト</returns>
910 public async Task SaveFile(string filepath, Encoding enc, string newLine, System.Threading.CancellationTokenSource token)
912 WinFileWriter fs = new WinFileWriter(filepath, enc);
913 fs.NewLine = newLine;
914 await this.Document.SaveAsync(fs, token);
921 public override Cursor Cursor
930 this.VScrollBar.Cursor = DefaultCursor;
931 this.HScrollBar.Cursor = DefaultCursor;
935 private const int WS_BORDER = 0x00800000;
936 private const int WS_EX_CLIENTEDGE = 0x00000200;
940 protected override CreateParams CreateParams
944 CreateParams cp = base.CreateParams;
945 switch (this.BorderStyle)
947 case BorderStyle.Fixed3D:
948 cp.ExStyle |= WS_EX_CLIENTEDGE;
950 case BorderStyle.FixedSingle:
951 cp.Style |= WS_BORDER;
961 /// <param name="msg">メッセージ</param>
962 /// <param name="keyData">キーデータ</param>
963 /// <returns>文字がコントロールによって処理された場合は true。それ以外の場合は false。 </returns>
964 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
966 const int WM_KEYDOWN = 0x100;
967 if (msg.Msg != WM_KEYDOWN)
968 return base.ProcessCmdKey(ref msg, keyData);
971 case Keys.Control | Keys.C:
974 case Keys.Control | Keys.V:
978 case Keys.Control | Keys.X:
982 case Keys.Control | Keys.Z:
983 this.Document.UndoManager.undo();
986 case Keys.Control | Keys.Y:
987 this.Document.UndoManager.redo();
990 case Keys.Control | Keys.B:
991 if (this.Controller.RectSelection)
992 this.Controller.RectSelection = false;
994 this.Controller.RectSelection = true;
997 return base.ProcessCmdKey(ref msg,keyData);
1005 /// <param name="disposing">マネージ リソースとアンマネージ リソースの両方を解放する場合は true。アンマネージ リソースだけを解放する場合は false。</param>
1006 protected override void Dispose(bool disposing)
1008 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(this.SystemEvents_UserPreferenceChanged);
1009 this.render.Dispose();
1010 this.Timer.Dispose();
1011 base.Dispose(disposing);
1017 /// <param name="charCode">入力しようとした文字</param>
1018 /// <returns>可能なら真。そうでなければ偽</returns>
1019 protected override bool IsInputChar(char charCode)
1021 if ((0x20 <= charCode && charCode <= 0x7e)
1036 /// PaddingChangedイベントを発生させます
1038 /// <param name="e">インベントデータ</param>
1039 protected override void OnPaddingChanged(EventArgs e)
1041 base.OnPaddingChanged(e);
1042 this.View.Padding = new Padding(this.Padding.Left, this.Padding.Top, this.Padding.Right, this.Padding.Bottom);
1046 /// GotFocusイベントを発生させます
1048 /// <param name="e">インベントデータ</param>
1049 protected override void OnGotFocus(EventArgs e)
1052 this.View.IsFocused = true;
1057 /// LostFocusイベントを発生させます
1059 /// <param name="e">インベントデータ</param>
1060 protected override void OnLostFocus(EventArgs e)
1062 base.OnLostFocus(e);
1063 this.View.IsFocused = false;
1068 /// FontChangedイベントを発生させます
1070 /// <param name="e">インベントデータ</param>
1071 protected override void OnFontChanged(EventArgs e)
1073 if (this.DesignMode)
1075 base.OnFontChanged(e);
1080 /// MouseDownイベントを発生させます
1082 /// <param name="e">インベントデータ</param>
1083 protected override void OnMouseDown(MouseEventArgs e)
1085 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
1086 if (tp == TextPoint.Null)
1088 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
1090 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
1092 base.OnMouseDown(mouseEvent);
1094 if (mouseEvent.Handled)
1097 if (e.Button == MouseButtons.Left)
1099 FoldingItem foldingData = this.View.HitFoldingData(e.Location.X, tp.row);
1100 if (foldingData != null)
1102 if (foldingData.Expand)
1103 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
1105 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
1106 this.Controller.JumpCaret(foldingData.Start, false);
1110 this.Controller.JumpCaret(tp.row, tp.col, false);
1112 this.View.IsFocused = true;
1119 /// MouseClickイベントを発生させます
1121 /// <param name="e">インベントデータ</param>
1122 protected override void OnMouseClick(MouseEventArgs e)
1124 int index = this.GetIndexFromPostion(e.Location);
1126 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
1128 base.OnMouseClick(mouseEvent);
1132 /// MouseDoubleClickイベントを発生させます
1134 /// <param name="e">インベントデータ</param>
1135 protected override void OnMouseDoubleClick(MouseEventArgs e)
1137 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
1138 if (tp == TextPoint.Null)
1140 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
1142 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
1144 base.OnMouseDoubleClick(mouseEvent);
1146 if (mouseEvent.Handled)
1149 this.Controller.SelectWord(index);
1155 /// MouseMoveイベントを発生させます
1157 /// <param name="e">インベントデータ</param>
1158 protected override void OnMouseMove(MouseEventArgs e)
1160 if (this.Focused == false)
1163 base.OnMouseMove(e);
1165 if (this.View.HitTextArea(e.Location.X, e.Location.Y))
1167 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
1168 if (this.Controller.IsMarker(tp, HilightType.Url))
1169 this.Cursor = Cursors.Hand;
1171 this.Cursor = Cursors.IBeam;
1173 if (e.Button == MouseButtons.Left)
1175 this.Controller.MoveCaretAndSelect(tp);
1181 this.Cursor = Cursors.Arrow;
1186 /// MouseWheelイベントを発生させます
1188 /// <param name="e">インベントデータ</param>
1189 protected override void OnMouseWheel(MouseEventArgs e)
1191 base.OnMouseWheel(e);
1193 ScrollDirection dir = e.Delta > 0 ? ScrollDirection.Up : ScrollDirection.Down;
1194 this.Controller.Scroll(dir, SystemInformation.MouseWheelScrollLines, false, false);
1199 /// Paintイベントを発生させます
1201 /// <param name="e">インベントデータ</param>
1202 protected override void OnPaint(PaintEventArgs e)
1206 SolidBrush brush = new SolidBrush(this.BackColor);
1207 e.Graphics.FillRectangle(brush, this.ClientRectangle);
1209 }else if (this.Document.FireUpdateEvent){
1210 this.render.BegineDraw();
1211 this.View.Draw(e.ClipRectangle);
1212 this.render.EndDraw();
1218 /// PaintBackgroundイベントを発生させます
1220 /// <param name="e">インベントデータ</param>
1221 protected override void OnPaintBackground(PaintEventArgs e)
1226 /// PreviewKeyDownイベントを発生させます
1228 /// <param name="e">インベントデータ</param>
1229 protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
1231 base.OnPreviewKeyDown(e);
1239 e.IsInputKey = true;
1245 /// KeyDownイベントを発生させます
1247 /// <param name="e">インベントデータ</param>
1248 protected override void OnKeyDown(KeyEventArgs e)
1258 this.Controller.MoveCaretVertical(-1, e.Shift);
1262 this.Controller.MoveCaretVertical(+1, e.Shift);
1266 this.Controller.MoveCaretHorizontical(-1, e.Shift, e.Control);
1270 this.Controller.MoveCaretHorizontical(1, e.Shift, e.Control);
1274 this.Controller.Scroll(ScrollDirection.Up, this.VScrollBar.LargeChange,e.Shift,true);
1278 this.Controller.Scroll(ScrollDirection.Down, this.VScrollBar.LargeChange,e.Shift,true);
1282 if (this.InsertMode)
1283 this.InsertMode = false;
1285 this.InsertMode = true;
1288 this.Controller.DoDeleteAction();
1292 this.Controller.DoBackSpaceAction();
1297 this.Controller.JumpToHead(e.Shift);
1299 this.Controller.JumpToLineHead(this.Document.CaretPostion.row, e.Shift);
1304 this.Controller.JumpToEnd(e.Shift);
1306 this.Controller.JumpToLineEnd(this.Document.CaretPostion.row, e.Shift);
1310 if (this.Controller.SelectionLength == 0)
1311 this.Controller.DoInputChar('\t');
1313 this.Controller.DownIndent();
1315 this.Controller.UpIndent();
1322 /// KeyPressイベントを発生させます
1324 /// <param name="e">インベントデータ</param>
1325 protected override void OnKeyPress(KeyPressEventArgs e)
1335 this.Controller.DoEnterAction();
1339 break; //OnKeyDownで処理しているので不要
1341 if (IsInputChar(e.KeyChar) == false)
1343 this.Controller.DoInputChar(e.KeyChar);
1350 /// ClientSizeChangedイベントを発生させます
1352 /// <param name="e">インベントデータ</param>
1353 protected override void OnClientSizeChanged(EventArgs e)
1355 if (this.DesignMode)
1357 base.OnClientSizeChanged(e);
1359 this.View.PageBound = new Rectangle(0,
1361 Math.Max(this.ClientRectangle.Width - this.VScrollBar.Width,0),
1362 Math.Max(this.ClientRectangle.Height - this.HScrollBar.Height, 0));
1368 void View_SrcChanged(object sender, EventArgs e)
1370 if (this.View.Src.Row > this.VScrollBar.Maximum)
1371 this.VScrollBar.Maximum = this.View.Src.Row + this.View.LineCountOnScreen + 1;
1373 int srcX = (int)Math.Abs(this.View.Src.X);
1374 if (srcX > this.HScrollBar.Maximum)
1375 this.HScrollBar.Maximum = srcX + (int)this.View.PageBound.Width + 1;
1377 this.HScrollBar.Value = srcX;
1379 this.VScrollBar.Value = this.View.Src.Row;
1382 void FooTextBox_RightToLeftChanged(object sender, EventArgs e)
1384 this.Document.RightToLeft = this.RightToLeft == System.Windows.Forms.RightToLeft.Yes;
1387 void VScrollBar_Scroll(object sender, ScrollEventArgs e)
1389 this.View.TryScroll(this.View.Src.X, e.NewValue);
1393 void HScrollBar_Scroll(object sender, ScrollEventArgs e)
1396 if (this.RightToLeft == System.Windows.Forms.RightToLeft.Yes)
1400 this.View.TryScroll(toX, this.View.Src.Row);
1404 void Ime_StartCompstion(object sender, StartCompstionEventArgs e)
1406 this.Ime.Font = this.Font;
1407 System.Drawing.Point p = this.GetPostionFromIndex(this.Controller.SelectionStart);
1409 this.render.GetDpi(out dpi, out dpi);
1410 p.X = (int)(p.X * dpi / 96);
1411 p.Y = (int)(p.Y * dpi / 96);
1412 this.Ime.Location = p;
1413 this.View.HideCaret = true;
1416 void Ime_EndCompstion(object sender, EndCompstionEventArgs e)
1418 this.View.HideCaret = false;
1421 void Ime_ImeCompstion(object sender, ImeCompstionEventArgs e)
1423 this.Controller.DoInputString(e.InputText);
1427 void Ime_ImeDocumentFeed(object sender, ImeDocumentFeedEventArgs e)
1429 TextPoint tp = this.CaretPostion;
1430 e.Pragraph = this.LayoutLines[tp.row];
1434 void Ime_ImeReconvert(object sender, ImeReconvertStringEventArgs e)
1436 if (this.RectSelection)
1438 if (this.Controller.SelectionLength == 0)
1440 TextPoint tp = this.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart);
1441 e.TargetString = this.LayoutLines[tp.row];
1442 e.AutoAdjust = true;
1446 e.TargetString = this.SelectedText;
1447 if (e.TargetString.Length > 40)
1448 e.TargetString.Remove(40);
1450 e.CaretPostion = this.View.CaretLocation;
1453 void Ime_ImeQueryReconvert(object sender, ImeQueryRecovertStringEventArgs e)
1455 TextPoint tp = this.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart);
1458 int index = this.View.GetIndexFromLayoutLine(tp);
1460 this.Select(index, index + e.length);
1463 void Controller_CaretMoved(object sender, EventArgs e)
1465 this.SelectionChanged(this, null);
1468 void initScrollBars()
1470 this.VScrollBar.SmallChange = 1;
1471 this.VScrollBar.LargeChange = this.View.LineCountOnScreen;
1472 this.VScrollBar.Maximum = this.View.LayoutLines.Count + this.View.LineCountOnScreen + 1;
1473 this.HScrollBar.SmallChange = 10;
1474 this.HScrollBar.LargeChange = (int)this.View.PageBound.Width;
1475 this.HScrollBar.Maximum = this.HScrollBar.LargeChange + 1;
1478 void Timer_Tick(object sender,EventArgs e)
1480 if (this.Document.CaretPostion.row >= this.View.LayoutLines.Count || DesignMode)
1483 ITextLayout layout = this.View.LayoutLines.GetLayout(this.Document.CaretPostion.row);
1485 Size redrawSize = new Size();
1486 redrawSize.Width = layout.GetWidthFromIndex(this.Document.CaretPostion.col);
1487 if (redrawSize.Width == 0.0)
1488 redrawSize.Width = this.View.CaretWidthOnInsertMode;
1489 redrawSize.Height = layout.Height;
1491 bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding();
1496 this.Invalidate(new System.Drawing.Rectangle(this.View.CaretLocation, redrawSize));
1499 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
1501 this.SetSystemParamaters();
1505 void SetSystemParamaters()
1507 int CaretBlinkTime = SystemInformation.CaretBlinkTime;
1508 if (CaretBlinkTime == -1)
1510 this.View.CaretBlink = false;
1511 if (this.IsHandleCreated)
1512 this.BeginInvoke(new Action(() =>
1519 this.View.CaretBlink = true;
1520 this.View.CaretBlinkTime = CaretBlinkTime * 2;
1521 if(this.IsHandleCreated)
1522 this.BeginInvoke(new Action(() =>
1527 this.View.CaretWidthOnInsertMode = SystemInformation.CaretWidth;
1533 /// FooEditEngineで使用するマウスイベント
1535 public class FooMouseEventArgs : MouseEventArgs
1542 /// 既定の処理を省略するなら真。そうでなければ偽
1544 public bool Handled;
1548 /// <param name="index">インデックス</param>
1549 /// <param name="button">押されているボタン</param>
1550 /// <param name="clicks">ボタンが押された回数</param>
1551 /// <param name="x">マウスカーソルがあるX座標</param>
1552 /// <param name="y">マウスカーソルがあるY座標</param>
1553 /// <param name="delta">ホイールの回転方向</param>
1554 public FooMouseEventArgs(int index, MouseButtons button, int clicks, int x, int y, int delta)
1555 : base(button, clicks, x, y, delta)