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
12 using System.Threading;
\r
13 using System.Windows.Forms;
\r
14 using System.Drawing;
\r
15 using System.ComponentModel;
\r
16 using Microsoft.Win32;
\r
18 namespace FooEditEngine.Windows
\r
21 /// タブの幅が変更されたときに呼びされるデリゲート
\r
23 /// <param name="sender">送り主が属するクラス</param>
\r
24 /// <param name="e">イベントデータ</param>
\r
25 public delegate void TabStopChangeEventHandler(object sender, EventArgs e);
\r
28 /// InsetModeが変更されたときに呼び出されるデリゲート
\r
30 /// <param name="sender">送り主が属するクラス</param>
\r
31 /// <param name="e">イベントデータ</param>
\r
32 public delegate void InsertModeChangeEventHandler(object sender, EventArgs e);
\r
35 /// FooEditEngineを表します
\r
37 public class FooTextBox : Control
\r
40 Controller Controller;
\r
41 D2DTextRender render;
\r
42 BorderStyle _BoderStyle;
\r
43 HScrollBar HScrollBar;
\r
44 VScrollBar VScrollBar;
\r
46 System.Windows.Forms.Timer Timer;
\r
48 const int Interval = 100;
\r
55 this.VScrollBar = new VScrollBar();
\r
56 this.VScrollBar.Scroll += new ScrollEventHandler(VScrollBar_Scroll);
\r
57 this.VScrollBar.Dock = DockStyle.Right;
\r
58 this.VScrollBar.Visible = true;
\r
59 this.Controls.Add(this.VScrollBar);
\r
61 this.HScrollBar = new HScrollBar();
\r
62 this.HScrollBar.Scroll += new ScrollEventHandler(HScrollBar_Scroll);
\r
63 this.HScrollBar.Dock = DockStyle.Bottom;
\r
64 this.HScrollBar.Visible = true;
\r
65 this.Controls.Add(this.HScrollBar);
\r
67 this.SetStyle(ControlStyles.ResizeRedraw, true);
\r
68 this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
\r
69 this.SetStyle(ControlStyles.UserPaint, true);
\r
70 this.SetStyle(ControlStyles.Opaque, true);
\r
72 this.Document = new Document();
\r
73 DocumentExtend.Progress += Document_Progress;
\r
75 this.render = new D2DTextRender(this);
\r
76 this.View = new EditView(this.Document,this.render,new FooEditEngine.Padding(5,5,5,5));
\r
77 this.View.SrcChanged += View_SrcChanged;
\r
79 this.Controller = new Controller(this.Document, this.View);
\r
80 this.Controller.SelectionChanged += new EventHandler(Controller_CaretMoved);
\r
82 this.Ime = new WinIME(this);
\r
83 this.Ime.ImeCompstion += new ImeCompstionEventHandeler(Ime_ImeCompstion);
\r
84 this.Ime.StartCompstion += new StartCompstionEventHandeler(Ime_StartCompstion);
\r
85 this.Ime.EndCompstion += new EndCompstionEventHandeler(Ime_EndCompstion);
\r
86 this.Ime.ImeDocumentFeed += new ImeDocumentFeedEventHandler(Ime_ImeDocumentFeed);
\r
87 this.Ime.ImeReconvert += new ImeReconvertStringEventHandler(Ime_ImeReconvert);
\r
88 this.Ime.ImeQueryReconvert += new ImeQueryReconvertStringEventHandler(Ime_ImeQueryReconvert);
\r
90 this.Timer = new System.Windows.Forms.Timer();
\r
91 this.Timer.Tick += new EventHandler(this.Timer_Tick);
\r
92 this.Timer.Interval = Interval;
\r
93 this.SetSystemParamaters();
\r
95 this.TabStopChange += new TabStopChangeEventHandler((s, e) => { });
\r
96 this.InsetModeChange += new InsertModeChangeEventHandler((s, e) => { });
\r
97 this.SelectionChanged +=new EventHandler((s,e)=>{});
\r
99 this.RightToLeftChanged += FooTextBox_RightToLeftChanged;
\r
101 SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
\r
106 /// キャレットが移動したときに通知されるイベント
\r
108 public event EventHandler SelectionChanged;
\r
111 /// タブの幅が変更された時に発生するイベント
\r
113 public event TabStopChangeEventHandler TabStopChange;
\r
116 /// InsertModeが変更されたときに呼び出されるイベント
\r
118 public event InsertModeChangeEventHandler InsetModeChange;
\r
121 /// テキスト描写に使用するアンチエイリアシングモードを表す
\r
123 [BrowsableAttribute(false)]
\r
124 public TextAntialiasMode TextAntialiasMode
\r
128 return this.render.TextAntialiasMode;
\r
132 this.render.TextAntialiasMode = value;
\r
139 [BrowsableAttribute(false)]
\r
140 public MarkerPatternSet MarkerPatternSet
\r
144 return this.View.MarkerPatternSet;
\r
151 [BrowsableAttribute(false)]
\r
152 public Document Document
\r
161 [BrowsableAttribute(false)]
\r
162 public LineToIndexTable LayoutLines
\r
164 get { return this.View.LayoutLines; }
\r
170 [BrowsableAttribute(false)]
\r
171 public IHilighter Hilighter
\r
173 get { return this.View.Hilighter; }
\r
174 set { this.View.Hilighter = value; this.View.LayoutLines.ClearLayoutCache(); }
\r
178 /// フォールティングを作成するインターフェイスを表す
\r
180 [BrowsableAttribute(false)]
\r
181 public IFoldingStrategy FoldingStrategy
\r
185 return this.View.LayoutLines.FoldingStrategy;
\r
189 this.View.LayoutLines.FoldingStrategy = value;
\r
191 this.View.LayoutLines.FoldingCollection.Clear();
\r
198 public BorderStyle BorderStyle
\r
200 get { return this._BoderStyle; }
\r
201 set { this._BoderStyle = value; this.UpdateStyles(); }
\r
208 [DefaultValue(false)]
\r
209 public bool DrawLineNumber
\r
213 return this.View.DrawLineNumber;
\r
217 this.View.DrawLineNumber = value;
\r
218 this.JumpCaret(this.CaretPostion.row,this.CaretPostion.col);
\r
225 [DefaultValue(false)]
\r
226 public bool DrawRuler
\r
230 return !this.View.HideRuler;
\r
234 this.View.HideRuler = !value;
\r
235 this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
\r
243 /// 反映させるためにはレイアウト行の再構築を行う必要があります
\r
245 [DefaultValue(LineBreakMethod.None)]
\r
246 public LineBreakMethod LineBreakMethod
\r
250 return this.View.LineBreak;
\r
254 this.View.LineBreak = value;
\r
262 /// 反映させるためにはレイアウト行の再構築を行う必要があります
\r
265 public int LineBreakCharCount
\r
269 return this.View.LineBreakCharCount;
\r
273 this.View.LineBreakCharCount = value;
\r
280 [DefaultValue(false)]
\r
281 public bool UrlMark
\r
285 return this.View.UrlMark;
\r
289 this.View.UrlMark = value;
\r
297 public int TabStops
\r
299 get { return this.View.TabStops; }
\r
301 this.View.TabStops = value;
\r
302 this.View.AdjustCaretAndSrc();
\r
303 this.TabStopChange(this, null);
\r
308 /// 全角スペースを表示するなら真。そうでないなら偽
\r
310 [DefaultValue(false)]
\r
311 public bool ShowFullSpace
\r
315 return this.render.ShowFullSpace;
\r
319 this.render.ShowFullSpace = value;
\r
324 /// 半角スペースを表示するなら真。そうでないなら偽
\r
326 [DefaultValue(false)]
\r
327 public bool ShowHalfSpace
\r
331 return this.render.ShowHalfSpace;
\r
335 this.render.ShowHalfSpace = value;
\r
340 /// タブを表示するなら真。そうでないなら偽
\r
342 [DefaultValue(false)]
\r
343 public bool ShowTab
\r
347 return this.render.ShowTab;
\r
351 this.render.ShowTab = value;
\r
356 /// 改行マークを表示するなら真。そうでないなら偽
\r
358 [DefaultValue(false)]
\r
359 public bool ShowLineBreak
\r
363 return this.render.ShowLineBreak;
\r
367 this.render.ShowLineBreak = value;
\r
375 /// 未選択状態で文字列を代入した場合、キャレット位置に挿入され、そうでないときは置き換えられます。
\r
377 [BrowsableAttribute(false)]
\r
378 public string SelectedText
\r
380 get { return this.Controller.SelectedText; }
\r
381 set { this.Controller.SelectedText = value; }
\r
387 [BrowsableAttribute(false)]
\r
388 public TextPoint CaretPostion
\r
390 get { return this.View.CaretPostion; }
\r
397 /// Lengthが0の場合はキャレット位置を表します
\r
398 /// 矩形選択モードの場合、選択範囲の文字数ではなく、開始位置から終了位置までの長さとなります
\r
400 [BrowsableAttribute(false)]
\r
401 public TextRange Selection
\r
403 get { return new TextRange(this.Controller.SelectionStart,this.Controller.SelectionLength); }
\r
406 this.Controller.Select(value.Index, value.Length);
\r
413 [DefaultValue(true)]
\r
414 public bool InsertMode
\r
416 get { return this.View.InsertMode; }
\r
419 this.View.InsertMode = value;
\r
420 this.InsetModeChange(this, null);
\r
427 [DefaultValue(false)]
\r
428 public bool RectSelection
\r
430 get { return this.Controller.RectSelection; }
\r
431 set { this.Controller.RectSelection = value; }
\r
437 public System.Drawing.Color Foreground
\r
441 return this.render.Foreground;
\r
445 this.render.Foreground = value;
\r
452 public System.Drawing.Color Background
\r
456 return this.render.Background;
\r
460 this.render.Background = value;
\r
467 public System.Drawing.Color InsertCaret
\r
471 return this.render.InsertCaret;
\r
475 this.render.InsertCaret = value;
\r
482 public System.Drawing.Color OverwriteCaret
\r
486 return this.render.OverwriteCaret;
\r
490 this.render.OverwriteCaret = value;
\r
497 public System.Drawing.Color LineMarker
\r
501 return this.render.LineMarker;
\r
505 this.render.LineMarker = value;
\r
512 public System.Drawing.Color ControlChar
\r
516 return this.render.ControlChar;
\r
520 this.render.ControlChar = value;
\r
527 public System.Drawing.Color Url
\r
531 return this.render.Url;
\r
535 this.render.Url = value;
\r
542 public System.Drawing.Color Hilight
\r
546 return this.render.Hilight;
\r
550 this.render.Hilight = value;
\r
557 public System.Drawing.Color Comment
\r
561 return this.render.Comment;
\r
565 this.render.Comment = value;
\r
572 public System.Drawing.Color Literal
\r
576 return this.render.Literal;
\r
580 this.render.Literal = value;
\r
587 public System.Drawing.Color Keyword1
\r
591 return this.render.Keyword1;
\r
595 this.render.Keyword1 = value;
\r
602 public System.Drawing.Color Keyword2
\r
606 return this.render.Keyword2;
\r
610 this.render.Keyword2 = value;
\r
615 /// キャレットに下線を描くかどうか
\r
617 [DefaultValue(false)]
\r
618 public bool DrawCaretLine
\r
620 get { return !this.View.HideLineMarker; }
\r
621 set { this.View.HideLineMarker = !value; }
\r
627 /// <param name="start">開始インデックス</param>
\r
628 /// <param name="length">長さ</param>
\r
629 public void Select(int start, int length)
\r
631 this.Controller.Select(start, length);
\r
632 this.HScrollBar.Value = (int)this.View.Src.X;
\r
633 this.VScrollBar.Value = this.View.Src.Row;
\r
639 public void SelectAll()
\r
641 this.Controller.Select(0, this.Document.Length - 1);
\r
647 public void DeSelectAll()
\r
649 this.Controller.DeSelectAll();
\r
657 string text = this.SelectedText;
\r
658 if(text != null && text != string.Empty)
\r
659 Clipboard.SetText(text);
\r
663 /// クリップボードにコピーし、指定した範囲にある文字列をすべて削除します
\r
667 string text = this.SelectedText;
\r
668 if (text != null && text != string.Empty)
\r
670 Clipboard.SetText(text);
\r
671 this.Controller.SelectedText = "";
\r
676 /// クリップボードの内容をペーストします
\r
678 public void Paste()
\r
680 if (Clipboard.ContainsText() == false)
\r
682 this.Controller.SelectedText = Clipboard.GetText();
\r
686 /// キャレットを指定した行に移動させます
\r
688 /// <param name="index">インデックス</param>
\r
689 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
\r
690 public void JumpCaret(int index)
\r
692 this.Controller.JumpCaret(index);
\r
695 /// キャレットを指定した行と桁に移動させます
\r
697 /// <param name="row">行番号</param>
\r
698 /// <param name="col">桁</param>
\r
699 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
\r
700 public void JumpCaret(int row, int col)
\r
702 this.Controller.JumpCaret(row, col);
\r
708 public new void Refresh()
\r
710 if (this.Document.FireUpdateEvent == false)
\r
711 throw new InvalidOperationException("");
\r
712 if(this.View.CaretBlink)
\r
713 this.View.CaretBlink = true;
\r
721 /// <param name="row">行</param>
\r
722 /// <returns>高さ</returns>
\r
723 public double GetLineHeight(int row)
\r
725 if (this.Document.FireUpdateEvent == false)
\r
726 throw new InvalidOperationException("");
\r
727 return this.View.LayoutLines.GetLayout(row).Height;
\r
733 /// <param name="tp">テキストポイント</param>
\r
734 /// <returns>座標</returns>
\r
735 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
\r
736 public System.Drawing.Point GetPostionFromTextPoint(TextPoint tp)
\r
738 if (this.Document.FireUpdateEvent == false)
\r
739 throw new InvalidOperationException("");
\r
740 return this.View.GetPostionFromTextPoint(tp);
\r
744 /// 対応するテキストポイントを返す
\r
746 /// <param name="p">クライアント領域の原点を左上とする座標</param>
\r
747 /// <returns>テキストポイント</returns>
\r
748 public TextPoint GetTextPointFromPostion(System.Drawing.Point p)
\r
750 if (this.Document.FireUpdateEvent == false)
\r
751 throw new InvalidOperationException("");
\r
752 return this.View.GetTextPointFromPostion(p);
\r
756 /// インデックスに対応する座標を得ます
\r
758 /// <param name="index">インデックス</param>
\r
759 /// <returns>座標を返す</returns>
\r
760 public System.Drawing.Point GetPostionFromIndex(int index)
\r
762 if (this.Document.FireUpdateEvent == false)
\r
763 throw new InvalidOperationException("");
\r
764 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
\r
765 return this.View.GetPostionFromTextPoint(tp);
\r
769 /// 座標からインデックスに変換します
\r
771 /// <param name="p">座標</param>
\r
772 /// <returns>インデックスを返す</returns>
\r
773 public int GetIndexFromPostion(System.Drawing.Point p)
\r
775 if (this.Document.FireUpdateEvent == false)
\r
776 throw new InvalidOperationException("");
\r
777 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
778 return this.View.GetIndexFromLayoutLine(tp);
\r
782 /// レイアウト行をすべて破棄し、再度レイアウトを行う
\r
784 public void PerfomLayouts()
\r
786 this.View.PerfomLayouts();
\r
793 public override Cursor Cursor
\r
797 return base.Cursor;
\r
801 base.Cursor = value;
\r
802 this.VScrollBar.Cursor = DefaultCursor;
\r
803 this.HScrollBar.Cursor = DefaultCursor;
\r
807 private const int WS_BORDER = 0x00800000;
\r
808 private const int WS_EX_CLIENTEDGE = 0x00000200;
\r
810 /// コントロールの外観を指定します
\r
812 protected override CreateParams CreateParams
\r
816 CreateParams cp = base.CreateParams;
\r
817 switch (this.BorderStyle)
\r
819 case BorderStyle.Fixed3D:
\r
820 cp.ExStyle |= WS_EX_CLIENTEDGE;
\r
822 case BorderStyle.FixedSingle:
\r
823 cp.Style |= WS_BORDER;
\r
833 /// <param name="msg">メッセージ</param>
\r
834 /// <param name="keyData">キーデータ</param>
\r
835 /// <returns>文字がコントロールによって処理された場合は true。それ以外の場合は false。 </returns>
\r
836 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
\r
838 const int WM_KEYDOWN = 0x100;
\r
839 if (msg.Msg != WM_KEYDOWN)
\r
840 return base.ProcessCmdKey(ref msg, keyData);
\r
843 case Keys.Control | Keys.C:
\r
846 case Keys.Control | Keys.V:
\r
850 case Keys.Control | Keys.X:
\r
854 case Keys.Control | Keys.Z:
\r
855 this.Document.UndoManager.undo();
\r
858 case Keys.Control | Keys.Y:
\r
859 this.Document.UndoManager.redo();
\r
862 case Keys.Control | Keys.B:
\r
863 if (this.Controller.RectSelection)
\r
864 this.Controller.RectSelection = false;
\r
866 this.Controller.RectSelection = true;
\r
869 return base.ProcessCmdKey(ref msg,keyData);
\r
877 /// <param name="disposing">マネージ リソースとアンマネージ リソースの両方を解放する場合は true。アンマネージ リソースだけを解放する場合は false。</param>
\r
878 protected override void Dispose(bool disposing)
\r
880 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(this.SystemEvents_UserPreferenceChanged);
\r
881 DocumentExtend.Progress -= this.Document_Progress;
\r
882 this.render.Dispose();
\r
883 this.Timer.Dispose();
\r
884 base.Dispose(disposing);
\r
888 /// 入力可能な文字かチェックします
\r
890 /// <param name="charCode">入力しようとした文字</param>
\r
891 /// <returns>可能なら真。そうでなければ偽</returns>
\r
892 protected override bool IsInputChar(char charCode)
\r
894 if ((0x20 <= charCode && charCode <= 0x7e)
\r
895 || charCode == '\r'
\r
896 || charCode == '\n'
\r
898 || charCode == '\t'
\r
900 || 0x7f < charCode)
\r
909 /// PaddingChangedイベントを発生させます
\r
911 /// <param name="e">インベントデータ</param>
\r
912 protected override void OnPaddingChanged(EventArgs e)
\r
914 base.OnPaddingChanged(e);
\r
915 this.View.Padding = new Padding(this.Padding.Left, this.Padding.Top, this.Padding.Right, this.Padding.Bottom);
\r
919 /// GotFocusイベントを発生させます
\r
921 /// <param name="e">インベントデータ</param>
\r
922 protected override void OnGotFocus(EventArgs e)
\r
924 base.OnGotFocus(e);
\r
925 this.View.IsFocused = true;
\r
930 /// LostFocusイベントを発生させます
\r
932 /// <param name="e">インベントデータ</param>
\r
933 protected override void OnLostFocus(EventArgs e)
\r
935 base.OnLostFocus(e);
\r
936 this.View.IsFocused = false;
\r
941 /// FontChangedイベントを発生させます
\r
943 /// <param name="e">インベントデータ</param>
\r
944 protected override void OnFontChanged(EventArgs e)
\r
946 if (this.DesignMode)
\r
948 base.OnFontChanged(e);
\r
953 /// MouseDownイベントを発生させます
\r
955 /// <param name="e">インベントデータ</param>
\r
956 protected override void OnMouseDown(MouseEventArgs e)
\r
958 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
\r
959 if (tp == TextPoint.Null)
\r
961 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
963 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
\r
965 base.OnMouseDown(mouseEvent);
\r
967 if (mouseEvent.Handled)
\r
970 if (e.Button == MouseButtons.Left)
\r
972 FoldingItem foldingData = this.View.HitFoldingData(e.Location.X, tp.row);
\r
973 if (foldingData != null)
\r
975 if (foldingData.Expand)
\r
976 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
\r
978 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
\r
979 this.Controller.JumpCaret(foldingData.Start, false);
\r
983 this.Controller.JumpCaret(tp.row, tp.col, false);
\r
985 this.View.IsFocused = true;
\r
992 /// MouseClickイベントを発生させます
\r
994 /// <param name="e">インベントデータ</param>
\r
995 protected override void OnMouseClick(MouseEventArgs e)
\r
997 int index = this.GetIndexFromPostion(e.Location);
\r
999 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
\r
1001 base.OnMouseClick(mouseEvent);
\r
1005 /// MouseDoubleClickイベントを発生させます
\r
1007 /// <param name="e">インベントデータ</param>
\r
1008 protected override void OnMouseDoubleClick(MouseEventArgs e)
\r
1010 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
\r
1011 if (tp == TextPoint.Null)
\r
1013 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
1015 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
\r
1017 base.OnMouseDoubleClick(mouseEvent);
\r
1019 if (mouseEvent.Handled)
\r
1022 this.Controller.SelectWord(index);
\r
1028 /// MouseMoveイベントを発生させます
\r
1030 /// <param name="e">インベントデータ</param>
\r
1031 protected override void OnMouseMove(MouseEventArgs e)
\r
1033 if (this.Focused == false)
\r
1036 base.OnMouseMove(e);
\r
1038 if (this.View.HitTextArea(e.Location.X, e.Location.Y))
\r
1040 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
\r
1041 if (this.Controller.IsMarker(tp, HilightType.Url))
\r
1042 this.Cursor = Cursors.Hand;
\r
1044 this.Cursor = Cursors.IBeam;
\r
1046 if (e.Button == MouseButtons.Left)
\r
1048 this.Controller.MoveCaretAndSelect(tp);
\r
1054 this.Cursor = Cursors.Arrow;
\r
1059 /// MouseWheelイベントを発生させます
\r
1061 /// <param name="e">インベントデータ</param>
\r
1062 protected override void OnMouseWheel(MouseEventArgs e)
\r
1064 base.OnMouseWheel(e);
\r
1066 ScrollDirection dir = e.Delta > 0 ? ScrollDirection.Up : ScrollDirection.Down;
\r
1067 this.Controller.Scroll(dir, SystemInformation.MouseWheelScrollLines, false, false);
\r
1072 /// Paintイベントを発生させます
\r
1074 /// <param name="e">インベントデータ</param>
\r
1075 protected override void OnPaint(PaintEventArgs e)
\r
1079 SolidBrush brush = new SolidBrush(this.BackColor);
\r
1080 e.Graphics.FillRectangle(brush, this.ClientRectangle);
\r
1082 }else if (this.Document.FireUpdateEvent){
\r
1083 this.render.BeginDraw();
\r
1084 this.View.Draw(e.ClipRectangle);
\r
1085 this.render.EndDraw();
\r
1091 /// PaintBackgroundイベントを発生させます
\r
1093 /// <param name="e">インベントデータ</param>
\r
1094 protected override void OnPaintBackground(PaintEventArgs e)
\r
1099 /// PreviewKeyDownイベントを発生させます
\r
1101 /// <param name="e">インベントデータ</param>
\r
1102 protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
\r
1104 base.OnPreviewKeyDown(e);
\r
1105 switch (e.KeyCode)
\r
1112 e.IsInputKey = true;
\r
1118 /// KeyDownイベントを発生させます
\r
1120 /// <param name="e">インベントデータ</param>
\r
1121 protected override void OnKeyDown(KeyEventArgs e)
\r
1123 base.OnKeyDown(e);
\r
1128 switch (e.KeyCode)
\r
1131 this.Controller.MoveCaretVertical(-1, e.Shift);
\r
1135 this.Controller.MoveCaretVertical(+1, e.Shift);
\r
1139 this.Controller.MoveCaretHorizontical(-1, e.Shift, e.Control);
\r
1143 this.Controller.MoveCaretHorizontical(1, e.Shift, e.Control);
\r
1147 this.Controller.Scroll(ScrollDirection.Up, this.VScrollBar.LargeChange,e.Shift,true);
\r
1150 case Keys.PageDown:
\r
1151 this.Controller.Scroll(ScrollDirection.Down, this.VScrollBar.LargeChange,e.Shift,true);
\r
1155 if (this.InsertMode)
\r
1156 this.InsertMode = false;
\r
1158 this.InsertMode = true;
\r
1161 this.Controller.DoDeleteAction();
\r
1165 this.Controller.DoBackSpaceAction();
\r
1170 this.Controller.JumpToHead(e.Shift);
\r
1172 this.Controller.JumpToLineHead(this.View.CaretPostion.row, e.Shift);
\r
1177 this.Controller.JumpToEnd(e.Shift);
\r
1179 this.Controller.JumpToLineEnd(this.View.CaretPostion.row, e.Shift);
\r
1183 if (this.Controller.SelectionLength == 0)
\r
1184 this.Controller.DoInputChar('\t');
\r
1186 this.Controller.DownIndent();
\r
1188 this.Controller.UpIndent();
\r
1195 /// KeyPressイベントを発生させます
\r
1197 /// <param name="e">インベントデータ</param>
\r
1198 protected override void OnKeyPress(KeyPressEventArgs e)
\r
1200 base.OnKeyPress(e);
\r
1205 switch (e.KeyChar)
\r
1208 this.Controller.DoEnterAction();
\r
1212 break; //OnKeyDownで処理しているので不要
\r
1214 if (IsInputChar(e.KeyChar) == false)
\r
1216 this.Controller.DoInputChar(e.KeyChar);
\r
1223 /// ClientSizeChangedイベントを発生させます
\r
1225 /// <param name="e">インベントデータ</param>
\r
1226 protected override void OnClientSizeChanged(EventArgs e)
\r
1228 if (this.DesignMode)
\r
1230 base.OnClientSizeChanged(e);
\r
1232 this.View.PageBound = new Rectangle(0,
\r
1234 Math.Max(this.ClientRectangle.Width - this.VScrollBar.Width,0),
\r
1235 Math.Max(this.ClientRectangle.Height - this.HScrollBar.Height, 0));
\r
1241 void View_SrcChanged(object sender, EventArgs e)
\r
1243 if (this.View.Src.Row > this.VScrollBar.Maximum)
\r
1244 this.VScrollBar.Maximum = this.View.Src.Row + this.View.LineCountOnScreen + 1;
\r
1246 int srcX = (int)Math.Abs(this.View.Src.X);
\r
1247 if (srcX > this.HScrollBar.Maximum)
\r
1248 this.HScrollBar.Maximum = srcX + (int)this.View.PageBound.Width + 1;
\r
1250 this.HScrollBar.Value = srcX;
\r
1252 this.VScrollBar.Value = this.View.Src.Row;
\r
1255 void FooTextBox_RightToLeftChanged(object sender, EventArgs e)
\r
1257 this.render.RightToLeft = this.RightToLeft == System.Windows.Forms.RightToLeft.Yes;
\r
1260 void VScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
1262 this.View.TryScroll(this.View.Src.X, e.NewValue);
\r
1266 void HScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
1269 if (this.RightToLeft == System.Windows.Forms.RightToLeft.Yes)
\r
1270 toX = -e.NewValue;
\r
1273 this.View.TryScroll(toX, this.View.Src.Row);
\r
1277 void Ime_StartCompstion(object sender, StartCompstionEventArgs e)
\r
1279 this.Ime.Font = this.Font;
\r
1280 System.Drawing.Point p = this.GetPostionFromIndex(this.Controller.SelectionStart);
\r
1282 this.render.GetDpiHandler(out dpi, out dpi);
\r
1283 p.X = (int)(p.X * dpi / 96);
\r
1284 p.Y = (int)(p.X * dpi / 96);
\r
1285 this.Ime.Location = p;
\r
1286 this.View.HideCaret = true;
\r
1289 void Ime_EndCompstion(object sender, EndCompstionEventArgs e)
\r
1291 this.View.HideCaret = false;
\r
1294 void Ime_ImeCompstion(object sender, ImeCompstionEventArgs e)
\r
1296 this.Controller.DoInputString(e.InputText);
\r
1300 void Ime_ImeDocumentFeed(object sender, ImeDocumentFeedEventArgs e)
\r
1302 TextPoint tp = this.CaretPostion;
\r
1303 e.Pragraph = this.LayoutLines[tp.row];
\r
1307 void Ime_ImeReconvert(object sender, ImeReconvertStringEventArgs e)
\r
1309 if (this.RectSelection)
\r
1311 if (this.Controller.SelectionLength == 0)
\r
1313 TextPoint tp = this.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart);
\r
1314 e.TargetString = this.LayoutLines[tp.row];
\r
1315 e.AutoAdjust = true;
\r
1319 e.TargetString = this.SelectedText;
\r
1320 if (e.TargetString.Length > 40)
\r
1321 e.TargetString.Remove(40);
\r
1323 e.CaretPostion = this.View.CaretLocation;
\r
1326 void Ime_ImeQueryReconvert(object sender, ImeQueryRecovertStringEventArgs e)
\r
1328 TextPoint tp = this.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart);
\r
1329 tp.col = e.offset;
\r
1331 int index = this.View.GetIndexFromLayoutLine(tp);
\r
1333 this.Select(index, index + e.length);
\r
1336 void Controller_CaretMoved(object sender, EventArgs e)
\r
1338 this.SelectionChanged(this, null);
\r
1341 void Document_Progress(object sender, ProgressEventArgs e)
\r
1343 if (e.state == ProgressState.Complete)
\r
1345 this.initScrollBars();
\r
1346 this.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, MousePosition.X, MousePosition.Y, 0));
\r
1347 this.View.CalculateLineCountOnScreen();
\r
1351 void initScrollBars()
\r
1353 this.VScrollBar.SmallChange = 1;
\r
1354 this.VScrollBar.LargeChange = this.View.LineCountOnScreen;
\r
1355 this.VScrollBar.Maximum = this.View.LayoutLines.Count + this.View.LineCountOnScreen + 1;
\r
1356 this.HScrollBar.SmallChange = 10;
\r
1357 this.HScrollBar.LargeChange = (int)this.View.PageBound.Width;
\r
1358 this.HScrollBar.Maximum = this.HScrollBar.LargeChange + 1;
\r
1361 void Timer_Tick(object sender,EventArgs e)
\r
1363 if (this.View.CaretPostion.row >= this.View.LayoutLines.Count || DesignMode)
\r
1366 ITextLayout layout = this.View.LayoutLines.GetLayout(this.View.CaretPostion.row);
\r
1368 Size redrawSize = new Size();
\r
1369 redrawSize.Width = layout.GetWidthFromIndex(this.View.CaretPostion.col);
\r
1370 if (redrawSize.Width == 0.0)
\r
1371 redrawSize.Width = this.View.CaretWidthOnInsertMode;
\r
1372 redrawSize.Height = layout.Height;
\r
1374 this.Invalidate(new System.Drawing.Rectangle(this.View.CaretLocation, redrawSize));
\r
1377 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
\r
1379 this.SetSystemParamaters();
\r
1383 void SetSystemParamaters()
\r
1385 int CaretBlinkTime = SystemInformation.CaretBlinkTime;
\r
1386 if (CaretBlinkTime == -1)
\r
1388 this.View.CaretBlink = false;
\r
1389 this.BeginInvoke(new Action(() => {
\r
1390 this.Timer.Stop();
\r
1395 this.View.CaretBlink = true;
\r
1396 this.View.CaretBlinkTime = CaretBlinkTime * 2;
\r
1397 this.BeginInvoke(new Action(() =>
\r
1399 this.Timer.Start();
\r
1402 this.View.CaretWidthOnInsertMode = SystemInformation.CaretWidth;
\r
1408 /// FooEditEngineで使用するマウスイベント
\r
1410 public class FooMouseEventArgs : MouseEventArgs
\r
1413 /// イベントが発生したインデックス
\r
1417 /// 既定の処理を省略するなら真。そうでなければ偽
\r
1419 public bool Handled;
\r
1423 /// <param name="index">インデックス</param>
\r
1424 /// <param name="button">押されているボタン</param>
\r
1425 /// <param name="clicks">ボタンが押された回数</param>
\r
1426 /// <param name="x">マウスカーソルがあるX座標</param>
\r
1427 /// <param name="y">マウスカーソルがあるY座標</param>
\r
1428 /// <param name="delta">ホイールの回転方向</param>
\r
1429 public FooMouseEventArgs(int index, MouseButtons button, int clicks, int x, int y, int delta)
\r
1430 : base(button, clicks, x, y, delta)
\r
1432 this.index = index;
\r