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.Document.AutoComplete = new AutoCompleteBox(this);
78 this.Document.AutoComplete.GetPostion = (tp, doc) => {
79 var p = this.GetPostionFromTextPoint(tp);
80 p.Y += (int)this.render.emSize.Height;
83 this.View = new EditView(this.Document, this.render, new FooEditEngine.Padding(5, 5, 5, 5));
84 this.View.SrcChanged += View_SrcChanged;
86 this.Controller = new Controller(this.Document, this.View);
87 this.Document.SelectionChanged += new EventHandler(Controller_CaretMoved);
89 this.Ime = new WinIME(this);
90 this.Ime.ImeCompstion += new ImeCompstionEventHandeler(Ime_ImeCompstion);
91 this.Ime.StartCompstion += new StartCompstionEventHandeler(Ime_StartCompstion);
92 this.Ime.EndCompstion += new EndCompstionEventHandeler(Ime_EndCompstion);
93 this.Ime.ImeDocumentFeed += new ImeDocumentFeedEventHandler(Ime_ImeDocumentFeed);
94 this.Ime.ImeReconvert += new ImeReconvertStringEventHandler(Ime_ImeReconvert);
95 this.Ime.ImeQueryReconvert += new ImeQueryReconvertStringEventHandler(Ime_ImeQueryReconvert);
97 this.Timer = new System.Windows.Forms.Timer();
98 this.Timer.Tick += new EventHandler(this.Timer_Tick);
99 this.Timer.Interval = Interval;
100 this.SetSystemParamaters();
102 this.TabStopChange += new TabStopChangeEventHandler((s, e) => { });
103 this.InsetModeChange += new InsertModeChangeEventHandler((s, e) => { });
104 this.SelectionChanged +=new EventHandler((s,e)=>{});
106 this.RightToLeftChanged += FooTextBox_RightToLeftChanged;
108 SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
113 /// キャレットが移動したときに通知されるイベント
115 public event EventHandler SelectionChanged;
118 /// タブの幅が変更された時に発生するイベント
120 public event TabStopChangeEventHandler TabStopChange;
123 /// InsertModeが変更されたときに呼び出されるイベント
125 public event InsertModeChangeEventHandler InsetModeChange;
130 [DefaultValue(IndentMode.Tab)]
131 public IndentMode IndentMode
135 return this.Controller.IndentMode;
139 this.Controller.IndentMode = value;
144 /// テキスト描写に使用するアンチエイリアシングモードを表す
146 [BrowsableAttribute(false)]
147 public TextAntialiasMode TextAntialiasMode
151 return this.render.TextAntialiasMode;
155 this.render.TextAntialiasMode = value;
162 [BrowsableAttribute(false)]
163 public MarkerPatternSet MarkerPatternSet
167 return this.Document.MarkerPatternSet;
174 [BrowsableAttribute(false)]
175 public Document Document
184 [BrowsableAttribute(false)]
185 public LineToIndexTable LayoutLines
187 get { return this.View.LayoutLines; }
193 [BrowsableAttribute(false)]
194 public IHilighter Hilighter
196 get { return this.View.Hilighter; }
197 set { this.View.Hilighter = value; this.View.LayoutLines.ClearLayoutCache(); }
201 /// フォールティングを作成するインターフェイスを表す
203 [BrowsableAttribute(false)]
204 public IFoldingStrategy FoldingStrategy
208 return this.View.LayoutLines.FoldingStrategy;
212 this.View.LayoutLines.FoldingStrategy = value;
214 this.View.LayoutLines.FoldingCollection.Clear();
221 public BorderStyle BorderStyle
223 get { return this._BoderStyle; }
224 set { this._BoderStyle = value; this.UpdateStyles(); }
231 [DefaultValue(false)]
232 public bool DrawLineNumber
236 return this.Document.DrawLineNumber;
240 this.Document.DrawLineNumber = value;
247 [DefaultValue(false)]
248 public bool DrawRuler
252 return !this.Document.HideRuler;
256 this.Document.HideRuler = !value;
257 this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
265 /// 反映させるためにはレイアウト行の再構築を行う必要があります
267 [DefaultValue(LineBreakMethod.None)]
268 public LineBreakMethod LineBreakMethod
272 return this.Document.LineBreak;
276 this.Document.LineBreak = value;
284 /// 反映させるためにはレイアウト行の再構築を行う必要があります
287 public int LineBreakCharCount
291 return this.Document.LineBreakCharCount;
295 this.Document.LineBreakCharCount = value;
302 [DefaultValue(false)]
307 return this.Document.UrlMark;
311 this.Document.UrlMark = value;
321 get { return this.Document.TabStops; }
323 this.Document.TabStops = value;
324 this.View.AdjustCaretAndSrc();
325 this.TabStopChange(this, null);
330 /// 全角スペースを表示するなら真。そうでないなら偽
332 [DefaultValue(false)]
333 public bool ShowFullSpace
337 return this.Document.ShowFullSpace;
341 this.Document.ShowFullSpace = value;
346 /// 半角スペースを表示するなら真。そうでないなら偽
348 [DefaultValue(false)]
349 public bool ShowHalfSpace
353 return this.Document.ShowHalfSpace;
357 this.Document.ShowHalfSpace = value;
362 /// タブを表示するなら真。そうでないなら偽
364 [DefaultValue(false)]
369 return this.Document.ShowTab;
373 this.Document.ShowTab = value;
378 /// 改行マークを表示するなら真。そうでないなら偽
380 [DefaultValue(false)]
381 public bool ShowLineBreak
385 return this.Document.ShowLineBreak;
389 this.Document.ShowLineBreak = value;
397 /// 未選択状態で文字列を代入した場合、キャレット位置に挿入され、そうでないときは置き換えられます。
399 [BrowsableAttribute(false)]
400 public string SelectedText
402 get { return this.Controller.SelectedText; }
403 set { this.Controller.SelectedText = value; }
409 [BrowsableAttribute(false)]
410 public TextPoint CaretPostion
412 get { return this.Document.CaretPostion; }
419 /// Lengthが0の場合はキャレット位置を表します
420 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
422 [BrowsableAttribute(false)]
423 public TextRange Selection
425 get { return new TextRange(this.Controller.SelectionStart,this.Controller.SelectionLength); }
428 this.Document.Select(value.Index, value.Length);
436 public bool InsertMode
438 get { return this.View.InsertMode; }
441 this.View.InsertMode = value;
442 this.InsetModeChange(this, null);
449 [DefaultValue(false)]
450 public bool RectSelection
452 get { return this.Controller.RectSelection; }
453 set { this.Controller.RectSelection = value; }
456 System.Drawing.Color ForegroundColor = SystemColors.ControlText,
457 HilightForegroundColor = SystemColors.HighlightText,
458 BackgroundColor = SystemColors.Control,
459 HilightColor = System.Drawing.Color.DeepSkyBlue,
460 Keyword1Color = System.Drawing.Color.Blue,
461 Keyword2Color = System.Drawing.Color.DarkCyan,
462 LiteralColor = System.Drawing.Color.Brown,
463 UrlColor = System.Drawing.Color.Blue,
464 ControlCharColor = System.Drawing.Color.Gray,
465 CommentColor = System.Drawing.Color.Green,
466 InsertCaretColor = System.Drawing.Color.Black,
467 OverwriteCaretColor = System.Drawing.Color.Black,
468 LineMarkerColor = System.Drawing.Color.WhiteSmoke,
469 UpdateAreaColor = System.Drawing.Color.MediumSeaGreen,
470 LineNumberColor = System.Drawing.Color.DimGray;
475 public System.Drawing.Color Foreground
479 return this.ForegroundColor;
483 this.render.Foreground = D2DTextRender.ToColor4(value);
484 this.ForegroundColor = value;
491 public System.Drawing.Color HilightForeground
495 return this.HilightForegroundColor;
499 this.render.HilightForeground = D2DTextRender.ToColor4(value);
500 this.HilightForegroundColor = value;
507 public System.Drawing.Color Background
511 return this.BackgroundColor;
515 this.render.Background = D2DTextRender.ToColor4(value);
516 this.BackgroundColor = value;
523 public System.Drawing.Color InsertCaret
527 return this.InsertCaretColor;
531 this.InsertCaretColor = value;
532 this.render.InsertCaret = D2DTextRender.ToColor4(value);
539 public System.Drawing.Color OverwriteCaret
543 return this.OverwriteCaretColor;
547 this.OverwriteCaretColor = value;
548 this.render.OverwriteCaret = D2DTextRender.ToColor4(value);
555 public System.Drawing.Color LineMarker
559 return this.LineMarkerColor;
563 this.LineMarkerColor = value;
564 this.render.LineMarker = D2DTextRender.ToColor4(value);
571 public System.Drawing.Color ControlChar
575 return this.ControlCharColor;
579 this.ControlCharColor = value;
580 this.render.ControlChar = D2DTextRender.ToColor4(value);
587 public System.Drawing.Color UpdateArea
591 return this.UpdateAreaColor;
595 this.UpdateAreaColor = value;
596 this.render.UpdateArea = D2DTextRender.ToColor4(value);
603 public System.Drawing.Color LineNumber
607 return this.LineNumberColor;
611 this.LineNumberColor = value;
612 this.render.LineNumber = D2DTextRender.ToColor4(value);
619 public System.Drawing.Color Url
623 return this.UrlColor;
627 this.UrlColor = value;
628 this.render.Url = D2DTextRender.ToColor4(value);
635 public System.Drawing.Color Hilight
639 return this.HilightColor;
643 this.HilightColor = value;
644 this.render.Hilight = D2DTextRender.ToColor4(value);
651 public System.Drawing.Color Comment
655 return this.CommentColor;
659 this.CommentColor = value;
660 this.render.Comment = D2DTextRender.ToColor4(value);
667 public System.Drawing.Color Literal
671 return this.LiteralColor;
675 this.LiteralColor = value;
676 this.render.Literal = D2DTextRender.ToColor4(value);
683 public System.Drawing.Color Keyword1
687 return this.Keyword1Color;
691 this.Keyword1Color = value;
692 this.render.Keyword1 = D2DTextRender.ToColor4(value);
699 public System.Drawing.Color Keyword2
703 return this.Keyword2Color;
707 this.Keyword2Color = value;
708 this.render.Keyword2 = D2DTextRender.ToColor4(value);
715 [DefaultValue(false)]
716 public bool DrawCaretLine
718 get { return !this.View.HideLineMarker; }
719 set { this.View.HideLineMarker = !value; }
725 /// <param name="start">開始インデックス</param>
726 /// <param name="length">長さ</param>
727 public void Select(int start, int length)
729 this.Document.Select(start, length);
730 this.HScrollBar.Value = (int)this.View.Src.X;
731 this.VScrollBar.Value = this.View.Src.Row;
737 public void SelectAll()
739 this.Document.Select(0, this.Document.Length - 1);
745 public void DeSelectAll()
747 this.Controller.DeSelectAll();
755 string text = this.SelectedText;
756 if(text != null && text != string.Empty)
757 Clipboard.SetText(text);
761 /// クリップボードにコピーし、指定した範囲にある文字列をすべて削除します
765 string text = this.SelectedText;
766 if (text != null && text != string.Empty)
768 Clipboard.SetText(text);
769 this.Controller.SelectedText = "";
774 /// クリップボードの内容をペーストします
778 if (Clipboard.ContainsText() == false)
780 this.Controller.SelectedText = Clipboard.GetText();
784 /// キャレットを指定した行に移動させます
786 /// <param name="index">インデックス</param>
787 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
788 public void JumpCaret(int index)
790 this.Controller.JumpCaret(index);
793 /// キャレットを指定した行と桁に移動させます
795 /// <param name="row">行番号</param>
796 /// <param name="col">桁</param>
797 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
798 public void JumpCaret(int row, int col)
800 this.Controller.JumpCaret(row, col);
806 public new void Refresh()
808 if (this.Document.FireUpdateEvent == false)
809 throw new InvalidOperationException("");
810 if(this.View.CaretBlink)
811 this.View.CaretBlink = true;
819 /// <param name="row">行</param>
820 /// <returns>高さ</returns>
821 public double GetLineHeight(int row)
823 if (this.Document.FireUpdateEvent == false)
824 throw new InvalidOperationException("");
825 return this.View.LayoutLines.GetLayout(row).Height;
831 /// <param name="tp">テキストポイント</param>
832 /// <returns>座標</returns>
833 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
834 public System.Drawing.Point GetPostionFromTextPoint(TextPoint tp)
836 if (this.Document.FireUpdateEvent == false)
837 throw new InvalidOperationException("");
838 return this.View.GetPostionFromTextPoint(tp);
844 /// <param name="p">クライアント領域の原点を左上とする座標</param>
845 /// <returns>テキストポイント</returns>
846 public TextPoint GetTextPointFromPostion(System.Drawing.Point p)
848 if (this.Document.FireUpdateEvent == false)
849 throw new InvalidOperationException("");
850 return this.View.GetTextPointFromPostion(p);
854 /// インデックスに対応する座標を得ます
856 /// <param name="index">インデックス</param>
857 /// <returns>座標を返す</returns>
858 public System.Drawing.Point GetPostionFromIndex(int index)
860 if (this.Document.FireUpdateEvent == false)
861 throw new InvalidOperationException("");
862 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
863 return this.View.GetPostionFromTextPoint(tp);
869 /// <param name="p">座標</param>
870 /// <returns>インデックスを返す</returns>
871 public int GetIndexFromPostion(System.Drawing.Point p)
873 if (this.Document.FireUpdateEvent == false)
874 throw new InvalidOperationException("");
875 TextPoint tp = this.View.GetTextPointFromPostion(p);
876 return this.View.GetIndexFromLayoutLine(tp);
880 /// レイアウト行をすべて破棄し、再度レイアウトを行う
882 public void PerfomLayouts()
884 this.Document.PerformLayout();
889 /// ストリームからドキュメントを構築する
891 /// <param name="tr">TextReader</param>
892 /// <param name="token">キャンセル用トークン</param>
893 /// <returns>Taskオブジェクト</returns>
894 public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)
896 await this.Document.LoadAsync(tr, token);
900 /// ファイルからドキュメントを構築する
902 /// <param name="filepath">ファイルパス</param>
903 /// <param name="enc">エンコード</param>
904 /// <param name="token">キャンセル用トークン</param>
905 /// <returns>Taskオブジェクト</returns>
906 public async Task LoadFileAsync(string filepath, Encoding enc, System.Threading.CancellationTokenSource token)
908 var fs = new System.IO.StreamReader(filepath, enc);
909 await this.Document.LoadAsync(fs, token);
913 private void Document_LoadProgress(object sender, ProgressEventArgs e)
915 if (e.state == ProgressState.Start)
917 this.Enabled = false;
919 else if (e.state == ProgressState.Complete)
921 this.initScrollBars();
922 this.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, MousePosition.X, MousePosition.Y, 0));
923 this.View.CalculateLineCountOnScreen();
929 /// ドキュメントの内容をファイルに保存する
931 /// <param name="filepath">ファイルパス</param>
932 /// <param name="newLine">改行コード</param>
933 /// <param name="enc">エンコード</param>
934 /// <param name="token">キャンセル用トークン</param>
935 /// <returns>Taskオブジェクト</returns>
936 public async Task SaveFile(string filepath, Encoding enc, string newLine, System.Threading.CancellationTokenSource token)
938 var fs = new System.IO.StreamWriter(filepath, false, enc);
939 fs.NewLine = newLine;
940 await this.Document.SaveAsync(fs, token);
947 public override Cursor Cursor
956 this.VScrollBar.Cursor = DefaultCursor;
957 this.HScrollBar.Cursor = DefaultCursor;
961 private const int WS_BORDER = 0x00800000;
962 private const int WS_EX_CLIENTEDGE = 0x00000200;
966 protected override CreateParams CreateParams
970 CreateParams cp = base.CreateParams;
971 switch (this.BorderStyle)
973 case BorderStyle.Fixed3D:
974 cp.ExStyle |= WS_EX_CLIENTEDGE;
976 case BorderStyle.FixedSingle:
977 cp.Style |= WS_BORDER;
987 /// <param name="msg">メッセージ</param>
988 /// <param name="keyData">キーデータ</param>
989 /// <returns>文字がコントロールによって処理された場合は true。それ以外の場合は false。 </returns>
990 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
992 const int WM_KEYDOWN = 0x100;
993 if (msg.Msg != WM_KEYDOWN)
994 return base.ProcessCmdKey(ref msg, keyData);
997 case Keys.Control | Keys.C:
1000 case Keys.Control | Keys.V:
1004 case Keys.Control | Keys.X:
1008 case Keys.Control | Keys.Z:
1009 this.Document.UndoManager.undo();
1012 case Keys.Control | Keys.Y:
1013 this.Document.UndoManager.redo();
1016 case Keys.Control | Keys.B:
1017 if (this.Controller.RectSelection)
1018 this.Controller.RectSelection = false;
1020 this.Controller.RectSelection = true;
1023 return base.ProcessCmdKey(ref msg,keyData);
1031 /// <param name="disposing">マネージ リソースとアンマネージ リソースの両方を解放する場合は true。アンマネージ リソースだけを解放する場合は false。</param>
1032 protected override void Dispose(bool disposing)
1034 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(this.SystemEvents_UserPreferenceChanged);
1035 this.render.Dispose();
1036 this.Timer.Dispose();
1037 base.Dispose(disposing);
1043 /// <param name="charCode">入力しようとした文字</param>
1044 /// <returns>可能なら真。そうでなければ偽</returns>
1045 protected override bool IsInputChar(char charCode)
1047 if ((0x20 <= charCode && charCode <= 0x7e)
1062 /// PaddingChangedイベントを発生させます
1064 /// <param name="e">インベントデータ</param>
1065 protected override void OnPaddingChanged(EventArgs e)
1067 base.OnPaddingChanged(e);
1068 this.View.Padding = new Padding(this.Padding.Left, this.Padding.Top, this.Padding.Right, this.Padding.Bottom);
1072 /// GotFocusイベントを発生させます
1074 /// <param name="e">インベントデータ</param>
1075 protected override void OnGotFocus(EventArgs e)
1078 this.View.IsFocused = true;
1084 /// LostFocusイベントを発生させます
1086 /// <param name="e">インベントデータ</param>
1087 protected override void OnLostFocus(EventArgs e)
1089 base.OnLostFocus(e);
1090 this.View.IsFocused = false;
1096 /// FontChangedイベントを発生させます
1098 /// <param name="e">インベントデータ</param>
1099 protected override void OnFontChanged(EventArgs e)
1101 if (this.DesignMode)
1103 base.OnFontChanged(e);
1108 /// MouseDownイベントを発生させます
1110 /// <param name="e">インベントデータ</param>
1111 protected override void OnMouseDown(MouseEventArgs e)
1113 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
1114 if (tp == TextPoint.Null)
1116 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
1118 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
1120 base.OnMouseDown(mouseEvent);
1122 if (mouseEvent.Handled)
1125 if (e.Button == MouseButtons.Left)
1127 FoldingItem foldingData = this.View.HitFoldingData(e.Location.X, tp.row);
1128 if (foldingData != null)
1130 if (foldingData.Expand)
1131 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
1133 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
1134 this.Controller.JumpCaret(foldingData.Start, false);
1138 this.Controller.JumpCaret(tp.row, tp.col, false);
1140 this.View.IsFocused = true;
1147 /// MouseClickイベントを発生させます
1149 /// <param name="e">インベントデータ</param>
1150 protected override void OnMouseClick(MouseEventArgs e)
1152 int index = this.GetIndexFromPostion(e.Location);
1154 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
1156 base.OnMouseClick(mouseEvent);
1160 /// MouseDoubleClickイベントを発生させます
1162 /// <param name="e">インベントデータ</param>
1163 protected override void OnMouseDoubleClick(MouseEventArgs e)
1165 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
1166 if (tp == TextPoint.Null)
1168 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
1170 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
1172 base.OnMouseDoubleClick(mouseEvent);
1174 if (mouseEvent.Handled)
1177 if (e.X < this.render.TextArea.X)
1178 this.Document.SelectLine(index);
1180 this.Document.SelectWord(index);
1186 /// MouseMoveイベントを発生させます
1188 /// <param name="e">インベントデータ</param>
1189 protected override void OnMouseMove(MouseEventArgs e)
1191 if (this.Focused == false)
1194 base.OnMouseMove(e);
1196 if (this.View.HitTextArea(e.Location.X, e.Location.Y))
1198 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
1199 if (this.Controller.IsMarker(tp, HilightType.Url))
1200 this.Cursor = Cursors.Hand;
1202 this.Cursor = Cursors.IBeam;
1204 if (e.Button == MouseButtons.Left)
1206 this.Controller.MoveCaretAndSelect(tp, ModifierKeys.HasFlag(Keys.Control));
1212 this.Cursor = Cursors.Arrow;
1217 /// MouseWheelイベントを発生させます
1219 /// <param name="e">インベントデータ</param>
1220 protected override void OnMouseWheel(MouseEventArgs e)
1222 base.OnMouseWheel(e);
1224 ScrollDirection dir = e.Delta > 0 ? ScrollDirection.Up : ScrollDirection.Down;
1225 this.Controller.Scroll(dir, SystemInformation.MouseWheelScrollLines, false, false);
1230 /// Paintイベントを発生させます
1232 /// <param name="e">インベントデータ</param>
1233 protected override void OnPaint(PaintEventArgs e)
1237 SolidBrush brush = new SolidBrush(this.BackColor);
1238 e.Graphics.FillRectangle(brush, this.ClientRectangle);
1240 }else if (this.Document.FireUpdateEvent){
1241 this.render.DrawContent(this.View, e.ClipRectangle);
1242 this.Document.IsRequestRedraw = false;
1248 /// PaintBackgroundイベントを発生させます
1250 /// <param name="e">インベントデータ</param>
1251 protected override void OnPaintBackground(PaintEventArgs e)
1256 /// PreviewKeyDownイベントを発生させます
1258 /// <param name="e">インベントデータ</param>
1259 protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
1261 base.OnPreviewKeyDown(e);
1270 e.IsInputKey = true;
1276 /// KeyDownイベントを発生させます
1278 /// <param name="e">インベントデータ</param>
1279 protected override void OnKeyDown(KeyEventArgs e)
1283 var completeBox = (AutoCompleteBox)this.Document.AutoComplete;
1284 if (completeBox.ProcessKeyDown(this, e, e.Control, e.Shift))
1296 this.Controller.MoveCaretVertical(-1, e.Shift);
1300 this.Controller.MoveCaretVertical(+1, e.Shift);
1304 this.Controller.MoveCaretHorizontical(-1, e.Shift, e.Control);
1308 this.Controller.MoveCaretHorizontical(1, e.Shift, e.Control);
1312 this.Controller.Scroll(ScrollDirection.Up, this.VScrollBar.LargeChange,e.Shift,true);
1316 this.Controller.Scroll(ScrollDirection.Down, this.VScrollBar.LargeChange,e.Shift,true);
1320 if (this.InsertMode)
1321 this.InsertMode = false;
1323 this.InsertMode = true;
1326 this.Controller.DoDeleteAction();
1330 this.Controller.DoBackSpaceAction();
1335 this.Controller.JumpToHead(e.Shift);
1337 this.Controller.JumpToLineHead(this.Document.CaretPostion.row, e.Shift);
1342 this.Controller.JumpToEnd(e.Shift);
1344 this.Controller.JumpToLineEnd(this.Document.CaretPostion.row, e.Shift);
1348 if (this.Controller.SelectionLength == 0)
1349 this.Controller.DoInputChar('\t');
1351 this.Controller.DownIndent();
1353 this.Controller.UpIndent();
1360 /// KeyPressイベントを発生させます
1362 /// <param name="e">インベントデータ</param>
1363 protected override void OnKeyPress(KeyPressEventArgs e)
1370 var completeBox = (AutoCompleteBox)this.Document.AutoComplete;
1371 if (completeBox.ProcessKeyPress(this, e))
1377 this.Controller.DoEnterAction();
1381 break; //OnKeyDownで処理しているので不要
1383 if (IsInputChar(e.KeyChar) == false)
1385 this.Controller.DoInputChar(e.KeyChar);
1392 /// ClientSizeChangedイベントを発生させます
1394 /// <param name="e">インベントデータ</param>
1395 protected override void OnClientSizeChanged(EventArgs e)
1397 if (this.DesignMode)
1399 base.OnClientSizeChanged(e);
1401 this.View.PageBound = new Rectangle(0,
1403 Math.Max(this.ClientRectangle.Width - this.VScrollBar.Width,0),
1404 Math.Max(this.ClientRectangle.Height - this.HScrollBar.Height, 0));
1410 void View_SrcChanged(object sender, EventArgs e)
1412 if (this.View.Src.Row > this.VScrollBar.Maximum)
1413 this.VScrollBar.Maximum = this.View.Src.Row + this.View.LineCountOnScreen + 1;
1415 int srcX = (int)Math.Abs(this.View.Src.X);
1416 if (srcX > this.HScrollBar.Maximum)
1417 this.HScrollBar.Maximum = srcX + (int)this.View.PageBound.Width + 1;
1419 this.HScrollBar.Value = srcX;
1421 this.VScrollBar.Value = this.View.Src.Row;
1424 void FooTextBox_RightToLeftChanged(object sender, EventArgs e)
1426 this.Document.RightToLeft = this.RightToLeft == System.Windows.Forms.RightToLeft.Yes;
1429 void VScrollBar_Scroll(object sender, ScrollEventArgs e)
1431 this.View.TryScroll(this.View.Src.X, e.NewValue);
1435 void HScrollBar_Scroll(object sender, ScrollEventArgs e)
1438 if (this.RightToLeft == System.Windows.Forms.RightToLeft.Yes)
1442 this.View.TryScroll(toX, this.View.Src.Row);
1446 void Ime_StartCompstion(object sender, StartCompstionEventArgs e)
1448 this.Ime.Font = this.Font;
1449 System.Drawing.Point p = this.GetPostionFromIndex(this.Controller.SelectionStart);
1451 this.render.GetDpi(out dpi, out dpi);
1452 p.X = (int)(p.X * dpi / 96);
1453 p.Y = (int)(p.Y * dpi / 96);
1454 this.Ime.Location = p;
1455 this.View.HideCaret = true;
1458 void Ime_EndCompstion(object sender, EndCompstionEventArgs e)
1460 this.View.HideCaret = false;
1463 void Ime_ImeCompstion(object sender, ImeCompstionEventArgs e)
1465 this.Controller.DoInputString(e.InputText);
1469 void Ime_ImeDocumentFeed(object sender, ImeDocumentFeedEventArgs e)
1471 TextPoint tp = this.CaretPostion;
1472 e.Pragraph = this.LayoutLines[tp.row];
1476 void Ime_ImeReconvert(object sender, ImeReconvertStringEventArgs e)
1478 if (this.RectSelection)
1480 if (this.Controller.SelectionLength == 0)
1482 TextPoint tp = this.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart);
1483 e.TargetString = this.LayoutLines[tp.row];
1484 e.AutoAdjust = true;
1488 e.TargetString = this.SelectedText;
1489 if (e.TargetString.Length > 40)
1490 e.TargetString.Remove(40);
1492 e.CaretPostion = this.View.CaretLocation;
1495 void Ime_ImeQueryReconvert(object sender, ImeQueryRecovertStringEventArgs e)
1497 TextPoint tp = this.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart);
1500 int index = this.View.GetIndexFromLayoutLine(tp);
1502 this.Select(index, index + e.length);
1505 void Controller_CaretMoved(object sender, EventArgs e)
1507 this.SelectionChanged(this, null);
1510 void initScrollBars()
1512 this.VScrollBar.SmallChange = 1;
1513 this.VScrollBar.LargeChange = this.View.LineCountOnScreen;
1514 this.VScrollBar.Maximum = this.View.LayoutLines.Count + this.View.LineCountOnScreen + 1;
1515 this.HScrollBar.SmallChange = 10;
1516 this.HScrollBar.LargeChange = (int)this.View.PageBound.Width;
1517 this.HScrollBar.Maximum = this.HScrollBar.LargeChange + 1;
1520 void Timer_Tick(object sender,EventArgs e)
1522 if (this.Document.CaretPostion.row >= this.View.LayoutLines.Count || DesignMode)
1525 bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding() || this.Document.IsRequestRedraw;
1530 this.Invalidate(new System.Drawing.Rectangle(this.View.CaretLocation, this.View.GetCurrentCaretRect().Size));
1533 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
1535 this.SetSystemParamaters();
1539 void SetSystemParamaters()
1541 int CaretBlinkTime = SystemInformation.CaretBlinkTime;
1542 if (CaretBlinkTime == -1)
1544 this.View.CaretBlink = false;
1548 this.View.CaretBlink = true;
1549 this.View.CaretBlinkTime = CaretBlinkTime * 2;
1551 this.View.CaretWidthOnInsertMode = SystemInformation.CaretWidth;
1557 /// FooEditEngineで使用するマウスイベント
1559 public class FooMouseEventArgs : MouseEventArgs
1566 /// 既定の処理を省略するなら真。そうでなければ偽
1568 public bool Handled;
1572 /// <param name="index">インデックス</param>
1573 /// <param name="button">押されているボタン</param>
1574 /// <param name="clicks">ボタンが押された回数</param>
1575 /// <param name="x">マウスカーソルがあるX座標</param>
1576 /// <param name="y">マウスカーソルがあるY座標</param>
1577 /// <param name="delta">ホイールの回転方向</param>
1578 public FooMouseEventArgs(int index, MouseButtons button, int clicks, int x, int y, int delta)
1579 : base(button, clicks, x, y, delta)