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
434 System.Drawing.Color ForegroundColor = SystemColors.ControlText,
\r
435 BackgroundColor = SystemColors.Control,
\r
436 HilightColor = System.Drawing.Color.DeepSkyBlue,
\r
437 Keyword1Color = System.Drawing.Color.Blue,
\r
438 Keyword2Color = System.Drawing.Color.DarkCyan,
\r
439 LiteralColor = System.Drawing.Color.Brown,
\r
440 UrlColor = System.Drawing.Color.Blue,
\r
441 ControlCharColor = System.Drawing.Color.Gray,
\r
442 CommentColor = System.Drawing.Color.Green,
\r
443 InsertCaretColor = System.Drawing.Color.Black,
\r
444 OverwriteCaretColor = System.Drawing.Color.Black,
\r
445 LineMarkerColor = System.Drawing.Color.WhiteSmoke,
\r
446 UpdateAreaColor = System.Drawing.Color.MediumSeaGreen;
\r
451 public System.Drawing.Color Foreground
\r
455 return this.ForegroundColor;
\r
459 this.render.Foreground = D2DTextRender.ToColor4(value);
\r
460 this.ForegroundColor = value;
\r
467 public System.Drawing.Color Background
\r
471 return this.BackgroundColor;
\r
475 this.render.Background = D2DTextRender.ToColor4(value);
\r
476 this.BackgroundColor = value;
\r
483 public System.Drawing.Color InsertCaret
\r
487 return this.InsertCaretColor;
\r
491 this.InsertCaretColor = value;
\r
492 this.render.InsertCaret = D2DTextRender.ToColor4(value);
\r
499 public System.Drawing.Color OverwriteCaret
\r
503 return this.OverwriteCaretColor;
\r
507 this.OverwriteCaretColor = value;
\r
508 this.render.OverwriteCaret = D2DTextRender.ToColor4(value);
\r
515 public System.Drawing.Color LineMarker
\r
519 return this.LineMarkerColor;
\r
523 this.LineMarkerColor = value;
\r
524 this.render.LineMarker = D2DTextRender.ToColor4(value);
\r
531 public System.Drawing.Color ControlChar
\r
535 return this.ControlCharColor;
\r
539 this.ControlCharColor = value;
\r
540 this.render.ControlChar = D2DTextRender.ToColor4(value);
\r
547 public System.Drawing.Color UpdateArea
\r
551 return this.UpdateAreaColor;
\r
555 this.UpdateAreaColor = value;
\r
556 this.render.UpdateArea = D2DTextRender.ToColor4(value);
\r
563 public System.Drawing.Color Url
\r
567 return this.UrlColor;
\r
571 this.UrlColor = value;
\r
572 this.render.Url = D2DTextRender.ToColor4(value);
\r
579 public System.Drawing.Color Hilight
\r
583 return this.HilightColor;
\r
587 this.HilightColor = value;
\r
588 this.render.Hilight = D2DTextRender.ToColor4(value);
\r
595 public System.Drawing.Color Comment
\r
599 return this.CommentColor;
\r
603 this.CommentColor = value;
\r
604 this.render.Comment = D2DTextRender.ToColor4(value);
\r
611 public System.Drawing.Color Literal
\r
615 return this.LiteralColor;
\r
619 this.LiteralColor = value;
\r
620 this.render.Literal = D2DTextRender.ToColor4(value);
\r
627 public System.Drawing.Color Keyword1
\r
631 return this.Keyword1Color;
\r
635 this.Keyword1Color = value;
\r
636 this.render.Keyword1 = D2DTextRender.ToColor4(value);
\r
643 public System.Drawing.Color Keyword2
\r
647 return this.Keyword2Color;
\r
651 this.Keyword2Color = value;
\r
652 this.render.Keyword2 = D2DTextRender.ToColor4(value);
\r
657 /// キャレットに下線を描くかどうか
\r
659 [DefaultValue(false)]
\r
660 public bool DrawCaretLine
\r
662 get { return !this.View.HideLineMarker; }
\r
663 set { this.View.HideLineMarker = !value; }
\r
669 /// <param name="start">開始インデックス</param>
\r
670 /// <param name="length">長さ</param>
\r
671 public void Select(int start, int length)
\r
673 this.Controller.Select(start, length);
\r
674 this.HScrollBar.Value = (int)this.View.Src.X;
\r
675 this.VScrollBar.Value = this.View.Src.Row;
\r
681 public void SelectAll()
\r
683 this.Controller.Select(0, this.Document.Length - 1);
\r
689 public void DeSelectAll()
\r
691 this.Controller.DeSelectAll();
\r
699 string text = this.SelectedText;
\r
700 if(text != null && text != string.Empty)
\r
701 Clipboard.SetText(text);
\r
705 /// クリップボードにコピーし、指定した範囲にある文字列をすべて削除します
\r
709 string text = this.SelectedText;
\r
710 if (text != null && text != string.Empty)
\r
712 Clipboard.SetText(text);
\r
713 this.Controller.SelectedText = "";
\r
718 /// クリップボードの内容をペーストします
\r
720 public void Paste()
\r
722 if (Clipboard.ContainsText() == false)
\r
724 this.Controller.SelectedText = Clipboard.GetText();
\r
728 /// キャレットを指定した行に移動させます
\r
730 /// <param name="index">インデックス</param>
\r
731 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
\r
732 public void JumpCaret(int index)
\r
734 this.Controller.JumpCaret(index);
\r
737 /// キャレットを指定した行と桁に移動させます
\r
739 /// <param name="row">行番号</param>
\r
740 /// <param name="col">桁</param>
\r
741 /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>
\r
742 public void JumpCaret(int row, int col)
\r
744 this.Controller.JumpCaret(row, col);
\r
750 public new void Refresh()
\r
752 if (this.Document.FireUpdateEvent == false)
\r
753 throw new InvalidOperationException("");
\r
754 if(this.View.CaretBlink)
\r
755 this.View.CaretBlink = true;
\r
763 /// <param name="row">行</param>
\r
764 /// <returns>高さ</returns>
\r
765 public double GetLineHeight(int row)
\r
767 if (this.Document.FireUpdateEvent == false)
\r
768 throw new InvalidOperationException("");
\r
769 return this.View.LayoutLines.GetLayout(row).Height;
\r
775 /// <param name="tp">テキストポイント</param>
\r
776 /// <returns>座標</returns>
\r
777 /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>
\r
778 public System.Drawing.Point GetPostionFromTextPoint(TextPoint tp)
\r
780 if (this.Document.FireUpdateEvent == false)
\r
781 throw new InvalidOperationException("");
\r
782 return this.View.GetPostionFromTextPoint(tp);
\r
786 /// 対応するテキストポイントを返す
\r
788 /// <param name="p">クライアント領域の原点を左上とする座標</param>
\r
789 /// <returns>テキストポイント</returns>
\r
790 public TextPoint GetTextPointFromPostion(System.Drawing.Point p)
\r
792 if (this.Document.FireUpdateEvent == false)
\r
793 throw new InvalidOperationException("");
\r
794 return this.View.GetTextPointFromPostion(p);
\r
798 /// インデックスに対応する座標を得ます
\r
800 /// <param name="index">インデックス</param>
\r
801 /// <returns>座標を返す</returns>
\r
802 public System.Drawing.Point GetPostionFromIndex(int index)
\r
804 if (this.Document.FireUpdateEvent == false)
\r
805 throw new InvalidOperationException("");
\r
806 TextPoint tp = this.View.GetLayoutLineFromIndex(index);
\r
807 return this.View.GetPostionFromTextPoint(tp);
\r
811 /// 座標からインデックスに変換します
\r
813 /// <param name="p">座標</param>
\r
814 /// <returns>インデックスを返す</returns>
\r
815 public int GetIndexFromPostion(System.Drawing.Point p)
\r
817 if (this.Document.FireUpdateEvent == false)
\r
818 throw new InvalidOperationException("");
\r
819 TextPoint tp = this.View.GetTextPointFromPostion(p);
\r
820 return this.View.GetIndexFromLayoutLine(tp);
\r
824 /// レイアウト行をすべて破棄し、再度レイアウトを行う
\r
826 public void PerfomLayouts()
\r
828 this.View.PerfomLayouts();
\r
835 public override Cursor Cursor
\r
839 return base.Cursor;
\r
843 base.Cursor = value;
\r
844 this.VScrollBar.Cursor = DefaultCursor;
\r
845 this.HScrollBar.Cursor = DefaultCursor;
\r
849 private const int WS_BORDER = 0x00800000;
\r
850 private const int WS_EX_CLIENTEDGE = 0x00000200;
\r
852 /// コントロールの外観を指定します
\r
854 protected override CreateParams CreateParams
\r
858 CreateParams cp = base.CreateParams;
\r
859 switch (this.BorderStyle)
\r
861 case BorderStyle.Fixed3D:
\r
862 cp.ExStyle |= WS_EX_CLIENTEDGE;
\r
864 case BorderStyle.FixedSingle:
\r
865 cp.Style |= WS_BORDER;
\r
875 /// <param name="msg">メッセージ</param>
\r
876 /// <param name="keyData">キーデータ</param>
\r
877 /// <returns>文字がコントロールによって処理された場合は true。それ以外の場合は false。 </returns>
\r
878 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
\r
880 const int WM_KEYDOWN = 0x100;
\r
881 if (msg.Msg != WM_KEYDOWN)
\r
882 return base.ProcessCmdKey(ref msg, keyData);
\r
885 case Keys.Control | Keys.C:
\r
888 case Keys.Control | Keys.V:
\r
892 case Keys.Control | Keys.X:
\r
896 case Keys.Control | Keys.Z:
\r
897 this.Document.UndoManager.undo();
\r
900 case Keys.Control | Keys.Y:
\r
901 this.Document.UndoManager.redo();
\r
904 case Keys.Control | Keys.B:
\r
905 if (this.Controller.RectSelection)
\r
906 this.Controller.RectSelection = false;
\r
908 this.Controller.RectSelection = true;
\r
911 return base.ProcessCmdKey(ref msg,keyData);
\r
919 /// <param name="disposing">マネージ リソースとアンマネージ リソースの両方を解放する場合は true。アンマネージ リソースだけを解放する場合は false。</param>
\r
920 protected override void Dispose(bool disposing)
\r
922 SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(this.SystemEvents_UserPreferenceChanged);
\r
923 DocumentExtend.Progress -= this.Document_Progress;
\r
924 this.render.Dispose();
\r
925 this.Timer.Dispose();
\r
926 base.Dispose(disposing);
\r
930 /// 入力可能な文字かチェックします
\r
932 /// <param name="charCode">入力しようとした文字</param>
\r
933 /// <returns>可能なら真。そうでなければ偽</returns>
\r
934 protected override bool IsInputChar(char charCode)
\r
936 if ((0x20 <= charCode && charCode <= 0x7e)
\r
937 || charCode == '\r'
\r
938 || charCode == '\n'
\r
940 || charCode == '\t'
\r
942 || 0x7f < charCode)
\r
951 /// PaddingChangedイベントを発生させます
\r
953 /// <param name="e">インベントデータ</param>
\r
954 protected override void OnPaddingChanged(EventArgs e)
\r
956 base.OnPaddingChanged(e);
\r
957 this.View.Padding = new Padding(this.Padding.Left, this.Padding.Top, this.Padding.Right, this.Padding.Bottom);
\r
961 /// GotFocusイベントを発生させます
\r
963 /// <param name="e">インベントデータ</param>
\r
964 protected override void OnGotFocus(EventArgs e)
\r
966 base.OnGotFocus(e);
\r
967 this.View.IsFocused = true;
\r
972 /// LostFocusイベントを発生させます
\r
974 /// <param name="e">インベントデータ</param>
\r
975 protected override void OnLostFocus(EventArgs e)
\r
977 base.OnLostFocus(e);
\r
978 this.View.IsFocused = false;
\r
983 /// FontChangedイベントを発生させます
\r
985 /// <param name="e">インベントデータ</param>
\r
986 protected override void OnFontChanged(EventArgs e)
\r
988 if (this.DesignMode)
\r
990 base.OnFontChanged(e);
\r
995 /// MouseDownイベントを発生させます
\r
997 /// <param name="e">インベントデータ</param>
\r
998 protected override void OnMouseDown(MouseEventArgs e)
\r
1000 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
\r
1001 if (tp == TextPoint.Null)
\r
1003 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
1005 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
\r
1007 base.OnMouseDown(mouseEvent);
\r
1009 if (mouseEvent.Handled)
\r
1012 if (e.Button == MouseButtons.Left)
\r
1014 FoldingItem foldingData = this.View.HitFoldingData(e.Location.X, tp.row);
\r
1015 if (foldingData != null)
\r
1017 if (foldingData.Expand)
\r
1018 this.View.LayoutLines.FoldingCollection.Collapse(foldingData);
\r
1020 this.View.LayoutLines.FoldingCollection.Expand(foldingData);
\r
1021 this.Controller.JumpCaret(foldingData.Start, false);
\r
1025 this.Controller.JumpCaret(tp.row, tp.col, false);
\r
1027 this.View.IsFocused = true;
\r
1034 /// MouseClickイベントを発生させます
\r
1036 /// <param name="e">インベントデータ</param>
\r
1037 protected override void OnMouseClick(MouseEventArgs e)
\r
1039 int index = this.GetIndexFromPostion(e.Location);
\r
1041 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
\r
1043 base.OnMouseClick(mouseEvent);
\r
1047 /// MouseDoubleClickイベントを発生させます
\r
1049 /// <param name="e">インベントデータ</param>
\r
1050 protected override void OnMouseDoubleClick(MouseEventArgs e)
\r
1052 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
\r
1053 if (tp == TextPoint.Null)
\r
1055 int index = this.View.LayoutLines.GetIndexFromTextPoint(tp);
\r
1057 FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);
\r
1059 base.OnMouseDoubleClick(mouseEvent);
\r
1061 if (mouseEvent.Handled)
\r
1064 this.Controller.SelectWord(index);
\r
1070 /// MouseMoveイベントを発生させます
\r
1072 /// <param name="e">インベントデータ</param>
\r
1073 protected override void OnMouseMove(MouseEventArgs e)
\r
1075 if (this.Focused == false)
\r
1078 base.OnMouseMove(e);
\r
1080 if (this.View.HitTextArea(e.Location.X, e.Location.Y))
\r
1082 TextPoint tp = this.View.GetTextPointFromPostion(e.Location);
\r
1083 if (this.Controller.IsMarker(tp, HilightType.Url))
\r
1084 this.Cursor = Cursors.Hand;
\r
1086 this.Cursor = Cursors.IBeam;
\r
1088 if (e.Button == MouseButtons.Left)
\r
1090 this.Controller.MoveCaretAndSelect(tp);
\r
1096 this.Cursor = Cursors.Arrow;
\r
1101 /// MouseWheelイベントを発生させます
\r
1103 /// <param name="e">インベントデータ</param>
\r
1104 protected override void OnMouseWheel(MouseEventArgs e)
\r
1106 base.OnMouseWheel(e);
\r
1108 ScrollDirection dir = e.Delta > 0 ? ScrollDirection.Up : ScrollDirection.Down;
\r
1109 this.Controller.Scroll(dir, SystemInformation.MouseWheelScrollLines, false, false);
\r
1114 /// Paintイベントを発生させます
\r
1116 /// <param name="e">インベントデータ</param>
\r
1117 protected override void OnPaint(PaintEventArgs e)
\r
1121 SolidBrush brush = new SolidBrush(this.BackColor);
\r
1122 e.Graphics.FillRectangle(brush, this.ClientRectangle);
\r
1124 }else if (this.Document.FireUpdateEvent){
\r
1125 this.render.BegineDraw();
\r
1126 this.View.Draw(e.ClipRectangle);
\r
1127 this.render.EndDraw();
\r
1133 /// PaintBackgroundイベントを発生させます
\r
1135 /// <param name="e">インベントデータ</param>
\r
1136 protected override void OnPaintBackground(PaintEventArgs e)
\r
1141 /// PreviewKeyDownイベントを発生させます
\r
1143 /// <param name="e">インベントデータ</param>
\r
1144 protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
\r
1146 base.OnPreviewKeyDown(e);
\r
1147 switch (e.KeyCode)
\r
1154 e.IsInputKey = true;
\r
1160 /// KeyDownイベントを発生させます
\r
1162 /// <param name="e">インベントデータ</param>
\r
1163 protected override void OnKeyDown(KeyEventArgs e)
\r
1165 base.OnKeyDown(e);
\r
1170 switch (e.KeyCode)
\r
1173 this.Controller.MoveCaretVertical(-1, e.Shift);
\r
1177 this.Controller.MoveCaretVertical(+1, e.Shift);
\r
1181 this.Controller.MoveCaretHorizontical(-1, e.Shift, e.Control);
\r
1185 this.Controller.MoveCaretHorizontical(1, e.Shift, e.Control);
\r
1189 this.Controller.Scroll(ScrollDirection.Up, this.VScrollBar.LargeChange,e.Shift,true);
\r
1192 case Keys.PageDown:
\r
1193 this.Controller.Scroll(ScrollDirection.Down, this.VScrollBar.LargeChange,e.Shift,true);
\r
1197 if (this.InsertMode)
\r
1198 this.InsertMode = false;
\r
1200 this.InsertMode = true;
\r
1203 this.Controller.DoDeleteAction();
\r
1207 this.Controller.DoBackSpaceAction();
\r
1212 this.Controller.JumpToHead(e.Shift);
\r
1214 this.Controller.JumpToLineHead(this.View.CaretPostion.row, e.Shift);
\r
1219 this.Controller.JumpToEnd(e.Shift);
\r
1221 this.Controller.JumpToLineEnd(this.View.CaretPostion.row, e.Shift);
\r
1225 if (this.Controller.SelectionLength == 0)
\r
1226 this.Controller.DoInputChar('\t');
\r
1228 this.Controller.DownIndent();
\r
1230 this.Controller.UpIndent();
\r
1237 /// KeyPressイベントを発生させます
\r
1239 /// <param name="e">インベントデータ</param>
\r
1240 protected override void OnKeyPress(KeyPressEventArgs e)
\r
1242 base.OnKeyPress(e);
\r
1247 switch (e.KeyChar)
\r
1250 this.Controller.DoEnterAction();
\r
1254 break; //OnKeyDownで処理しているので不要
\r
1256 if (IsInputChar(e.KeyChar) == false)
\r
1258 this.Controller.DoInputChar(e.KeyChar);
\r
1265 /// ClientSizeChangedイベントを発生させます
\r
1267 /// <param name="e">インベントデータ</param>
\r
1268 protected override void OnClientSizeChanged(EventArgs e)
\r
1270 if (this.DesignMode)
\r
1272 base.OnClientSizeChanged(e);
\r
1274 this.View.PageBound = new Rectangle(0,
\r
1276 Math.Max(this.ClientRectangle.Width - this.VScrollBar.Width,0),
\r
1277 Math.Max(this.ClientRectangle.Height - this.HScrollBar.Height, 0));
\r
1283 void View_SrcChanged(object sender, EventArgs e)
\r
1285 if (this.View.Src.Row > this.VScrollBar.Maximum)
\r
1286 this.VScrollBar.Maximum = this.View.Src.Row + this.View.LineCountOnScreen + 1;
\r
1288 int srcX = (int)Math.Abs(this.View.Src.X);
\r
1289 if (srcX > this.HScrollBar.Maximum)
\r
1290 this.HScrollBar.Maximum = srcX + (int)this.View.PageBound.Width + 1;
\r
1292 this.HScrollBar.Value = srcX;
\r
1294 this.VScrollBar.Value = this.View.Src.Row;
\r
1297 void FooTextBox_RightToLeftChanged(object sender, EventArgs e)
\r
1299 this.render.RightToLeft = this.RightToLeft == System.Windows.Forms.RightToLeft.Yes;
\r
1302 void VScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
1304 this.View.TryScroll(this.View.Src.X, e.NewValue);
\r
1308 void HScrollBar_Scroll(object sender, ScrollEventArgs e)
\r
1311 if (this.RightToLeft == System.Windows.Forms.RightToLeft.Yes)
\r
1312 toX = -e.NewValue;
\r
1315 this.View.TryScroll(toX, this.View.Src.Row);
\r
1319 void Ime_StartCompstion(object sender, StartCompstionEventArgs e)
\r
1321 this.Ime.Font = this.Font;
\r
1322 System.Drawing.Point p = this.GetPostionFromIndex(this.Controller.SelectionStart);
\r
1324 this.render.GetDpi(out dpi, out dpi);
\r
1325 p.X = (int)(p.X * dpi / 96);
\r
1326 p.Y = (int)(p.Y * dpi / 96);
\r
1327 this.Ime.Location = p;
\r
1328 this.View.HideCaret = true;
\r
1331 void Ime_EndCompstion(object sender, EndCompstionEventArgs e)
\r
1333 this.View.HideCaret = false;
\r
1336 void Ime_ImeCompstion(object sender, ImeCompstionEventArgs e)
\r
1338 this.Controller.DoInputString(e.InputText);
\r
1342 void Ime_ImeDocumentFeed(object sender, ImeDocumentFeedEventArgs e)
\r
1344 TextPoint tp = this.CaretPostion;
\r
1345 e.Pragraph = this.LayoutLines[tp.row];
\r
1349 void Ime_ImeReconvert(object sender, ImeReconvertStringEventArgs e)
\r
1351 if (this.RectSelection)
\r
1353 if (this.Controller.SelectionLength == 0)
\r
1355 TextPoint tp = this.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart);
\r
1356 e.TargetString = this.LayoutLines[tp.row];
\r
1357 e.AutoAdjust = true;
\r
1361 e.TargetString = this.SelectedText;
\r
1362 if (e.TargetString.Length > 40)
\r
1363 e.TargetString.Remove(40);
\r
1365 e.CaretPostion = this.View.CaretLocation;
\r
1368 void Ime_ImeQueryReconvert(object sender, ImeQueryRecovertStringEventArgs e)
\r
1370 TextPoint tp = this.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart);
\r
1371 tp.col = e.offset;
\r
1373 int index = this.View.GetIndexFromLayoutLine(tp);
\r
1375 this.Select(index, index + e.length);
\r
1378 void Controller_CaretMoved(object sender, EventArgs e)
\r
1380 this.SelectionChanged(this, null);
\r
1383 void Document_Progress(object sender, ProgressEventArgs e)
\r
1385 if (e.state == ProgressState.Start)
\r
1386 this.LayoutLines.IsFrozneDirtyFlag = true;
\r
1387 if (e.state == ProgressState.Complete)
\r
1389 this.LayoutLines.IsFrozneDirtyFlag = false;
\r
1390 this.BeginInvoke(new Action(() => {
\r
1391 this.initScrollBars();
\r
1392 this.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, MousePosition.X, MousePosition.Y, 0));
\r
1394 this.View.CalculateLineCountOnScreen();
\r
1398 void initScrollBars()
\r
1400 this.VScrollBar.SmallChange = 1;
\r
1401 this.VScrollBar.LargeChange = this.View.LineCountOnScreen;
\r
1402 this.VScrollBar.Maximum = this.View.LayoutLines.Count + this.View.LineCountOnScreen + 1;
\r
1403 this.HScrollBar.SmallChange = 10;
\r
1404 this.HScrollBar.LargeChange = (int)this.View.PageBound.Width;
\r
1405 this.HScrollBar.Maximum = this.HScrollBar.LargeChange + 1;
\r
1408 void Timer_Tick(object sender,EventArgs e)
\r
1410 if (this.View.CaretPostion.row >= this.View.LayoutLines.Count || DesignMode)
\r
1413 ITextLayout layout = this.View.LayoutLines.GetLayout(this.View.CaretPostion.row);
\r
1415 Size redrawSize = new Size();
\r
1416 redrawSize.Width = layout.GetWidthFromIndex(this.View.CaretPostion.col);
\r
1417 if (redrawSize.Width == 0.0)
\r
1418 redrawSize.Width = this.View.CaretWidthOnInsertMode;
\r
1419 redrawSize.Height = layout.Height;
\r
1421 this.Invalidate(new System.Drawing.Rectangle(this.View.CaretLocation, redrawSize));
\r
1424 void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
\r
1426 this.SetSystemParamaters();
\r
1430 void SetSystemParamaters()
\r
1432 int CaretBlinkTime = SystemInformation.CaretBlinkTime;
\r
1433 if (CaretBlinkTime == -1)
\r
1435 this.View.CaretBlink = false;
\r
1436 if (this.IsHandleCreated)
\r
1437 this.BeginInvoke(new Action(() =>
\r
1439 this.Timer.Stop();
\r
1444 this.View.CaretBlink = true;
\r
1445 this.View.CaretBlinkTime = CaretBlinkTime * 2;
\r
1446 if(this.IsHandleCreated)
\r
1447 this.BeginInvoke(new Action(() =>
\r
1449 this.Timer.Start();
\r
1452 this.View.CaretWidthOnInsertMode = SystemInformation.CaretWidth;
\r
1458 /// FooEditEngineで使用するマウスイベント
\r
1460 public class FooMouseEventArgs : MouseEventArgs
\r
1463 /// イベントが発生したインデックス
\r
1467 /// 既定の処理を省略するなら真。そうでなければ偽
\r
1469 public bool Handled;
\r
1473 /// <param name="index">インデックス</param>
\r
1474 /// <param name="button">押されているボタン</param>
\r
1475 /// <param name="clicks">ボタンが押された回数</param>
\r
1476 /// <param name="x">マウスカーソルがあるX座標</param>
\r
1477 /// <param name="y">マウスカーソルがあるY座標</param>
\r
1478 /// <param name="delta">ホイールの回転方向</param>
\r
1479 public FooMouseEventArgs(int index, MouseButtons button, int clicks, int x, int y, int delta)
\r
1480 : base(button, clicks, x, y, delta)
\r
1482 this.index = index;
\r