X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=Windows%2FFooEditEngine%2FFooTextBox.cs;h=d8680496e3c4fa38227da63c38e8e9422e2b97ed;hb=ab8338d5cdc4d30e697165366f0fe6646bc07737;hp=981244b2f062e04cda38b4be9a2f41df650ff235;hpb=97343955058ead834ea8ec953842434f657dd980;p=fooeditengine%2FFooEditEngine.git diff --git a/Windows/FooEditEngine/FooTextBox.cs b/Windows/FooEditEngine/FooTextBox.cs index 981244b..d868049 100644 --- a/Windows/FooEditEngine/FooTextBox.cs +++ b/Windows/FooEditEngine/FooTextBox.cs @@ -9,7 +9,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ using System; +using System.Text; using System.Threading; +using System.Threading.Tasks; using System.Windows.Forms; using System.Drawing; using System.ComponentModel; @@ -70,7 +72,6 @@ namespace FooEditEngine.Windows this.SetStyle(ControlStyles.Opaque, true); this.Document = new Document(); - DocumentExtend.Progress += Document_Progress; this.render = new D2DTextRender(this); this.View = new EditView(this.Document,this.render,new FooEditEngine.Padding(5,5,5,5)); @@ -99,6 +100,7 @@ namespace FooEditEngine.Windows this.RightToLeftChanged += FooTextBox_RightToLeftChanged; SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged); + } /// @@ -430,6 +432,20 @@ namespace FooEditEngine.Windows set { this.Controller.RectSelection = value; } } + System.Drawing.Color ForegroundColor = SystemColors.ControlText, + BackgroundColor = SystemColors.Control, + HilightColor = System.Drawing.Color.DeepSkyBlue, + Keyword1Color = System.Drawing.Color.Blue, + Keyword2Color = System.Drawing.Color.DarkCyan, + LiteralColor = System.Drawing.Color.Brown, + UrlColor = System.Drawing.Color.Blue, + ControlCharColor = System.Drawing.Color.Gray, + CommentColor = System.Drawing.Color.Green, + InsertCaretColor = System.Drawing.Color.Black, + OverwriteCaretColor = System.Drawing.Color.Black, + LineMarkerColor = System.Drawing.Color.WhiteSmoke, + UpdateAreaColor = System.Drawing.Color.MediumSeaGreen; + /// /// 前景色 /// @@ -437,11 +453,12 @@ namespace FooEditEngine.Windows { get { - return this.render.Foreground; + return this.ForegroundColor; } set { - this.render.Foreground = value; + this.render.Foreground = D2DTextRender.ToColor4(value); + this.ForegroundColor = value; } } @@ -452,11 +469,12 @@ namespace FooEditEngine.Windows { get { - return this.render.Background; + return this.BackgroundColor; } set { - this.render.Background = value; + this.render.Background = D2DTextRender.ToColor4(value); + this.BackgroundColor = value; } } @@ -467,11 +485,12 @@ namespace FooEditEngine.Windows { get { - return this.render.InsertCaret; + return this.InsertCaretColor; } set { - this.render.InsertCaret = value; + this.InsertCaretColor = value; + this.render.InsertCaret = D2DTextRender.ToColor4(value); } } @@ -482,11 +501,12 @@ namespace FooEditEngine.Windows { get { - return this.render.OverwriteCaret; + return this.OverwriteCaretColor; } set { - this.render.OverwriteCaret = value; + this.OverwriteCaretColor = value; + this.render.OverwriteCaret = D2DTextRender.ToColor4(value); } } @@ -497,11 +517,12 @@ namespace FooEditEngine.Windows { get { - return this.render.LineMarker; + return this.LineMarkerColor; } set { - this.render.LineMarker = value; + this.LineMarkerColor = value; + this.render.LineMarker = D2DTextRender.ToColor4(value); } } @@ -512,11 +533,28 @@ namespace FooEditEngine.Windows { get { - return this.render.ControlChar; + return this.ControlCharColor; + } + set + { + this.ControlCharColor = value; + this.render.ControlChar = D2DTextRender.ToColor4(value); + } + } + + /// + /// 編集行フラグの色 + /// + public System.Drawing.Color UpdateArea + { + get + { + return this.UpdateAreaColor; } set { - this.render.ControlChar = value; + this.UpdateAreaColor = value; + this.render.UpdateArea = D2DTextRender.ToColor4(value); } } @@ -527,11 +565,12 @@ namespace FooEditEngine.Windows { get { - return this.render.Url; + return this.UrlColor; } set { - this.render.Url = value; + this.UrlColor = value; + this.render.Url = D2DTextRender.ToColor4(value); } } @@ -542,11 +581,12 @@ namespace FooEditEngine.Windows { get { - return this.render.Hilight; + return this.HilightColor; } set { - this.render.Hilight = value; + this.HilightColor = value; + this.render.Hilight = D2DTextRender.ToColor4(value); } } @@ -557,11 +597,12 @@ namespace FooEditEngine.Windows { get { - return this.render.Comment; + return this.CommentColor; } set { - this.render.Comment = value; + this.CommentColor = value; + this.render.Comment = D2DTextRender.ToColor4(value); } } @@ -572,11 +613,12 @@ namespace FooEditEngine.Windows { get { - return this.render.Literal; + return this.LiteralColor; } set { - this.render.Literal = value; + this.LiteralColor = value; + this.render.Literal = D2DTextRender.ToColor4(value); } } @@ -587,11 +629,12 @@ namespace FooEditEngine.Windows { get { - return this.render.Keyword1; + return this.Keyword1Color; } set { - this.render.Keyword1 = value; + this.Keyword1Color = value; + this.render.Keyword1 = D2DTextRender.ToColor4(value); } } @@ -602,11 +645,12 @@ namespace FooEditEngine.Windows { get { - return this.render.Keyword2; + return this.Keyword2Color; } set { - this.render.Keyword2 = value; + this.Keyword2Color = value; + this.render.Keyword2 = D2DTextRender.ToColor4(value); } } @@ -627,8 +671,6 @@ namespace FooEditEngine.Windows /// 長さ public void Select(int start, int length) { - if (this.Document.State == AsyncState.Loading) - throw new InvalidOperationException(); this.Controller.Select(start, length); this.HScrollBar.Value = (int)this.View.Src.X; this.VScrollBar.Value = this.View.Src.Row; @@ -639,8 +681,6 @@ namespace FooEditEngine.Windows /// public void SelectAll() { - if (this.Document.State == AsyncState.Loading) - throw new InvalidOperationException(); this.Controller.Select(0, this.Document.Length - 1); } @@ -649,8 +689,6 @@ namespace FooEditEngine.Windows /// public void DeSelectAll() { - if (this.Document.State == AsyncState.Loading) - throw new InvalidOperationException(); this.Controller.DeSelectAll(); } @@ -659,8 +697,6 @@ namespace FooEditEngine.Windows /// public void Copy() { - if (this.Document.State == AsyncState.Loading) - throw new InvalidOperationException(); string text = this.SelectedText; if(text != null && text != string.Empty) Clipboard.SetText(text); @@ -671,8 +707,6 @@ namespace FooEditEngine.Windows /// public void Cut() { - if (this.Document.State == AsyncState.Loading) - throw new InvalidOperationException(); string text = this.SelectedText; if (text != null && text != string.Empty) { @@ -686,8 +720,6 @@ namespace FooEditEngine.Windows /// public void Paste() { - if (this.Document.State == AsyncState.Loading) - throw new InvalidOperationException(); if (Clipboard.ContainsText() == false) return; this.Controller.SelectedText = Clipboard.GetText(); @@ -700,8 +732,6 @@ namespace FooEditEngine.Windows /// このメソッドを呼び出すと選択状態は解除されます public void JumpCaret(int index) { - if (this.Document.State == AsyncState.Loading) - throw new InvalidOperationException(); this.Controller.JumpCaret(index); } /// @@ -712,8 +742,6 @@ namespace FooEditEngine.Windows /// このメソッドを呼び出すと選択状態は解除されます public void JumpCaret(int row, int col) { - if (this.Document.State == AsyncState.Loading) - throw new InvalidOperationException(); this.Controller.JumpCaret(row, col); } @@ -722,8 +750,6 @@ namespace FooEditEngine.Windows /// public new void Refresh() { - if (this.Document.State == AsyncState.Loading) - return; if (this.Document.FireUpdateEvent == false) throw new InvalidOperationException(""); if(this.View.CaretBlink) @@ -739,8 +765,6 @@ namespace FooEditEngine.Windows /// 高さ public double GetLineHeight(int row) { - if (this.Document.State == AsyncState.Loading) - throw new InvalidOperationException(); if (this.Document.FireUpdateEvent == false) throw new InvalidOperationException(""); return this.View.LayoutLines.GetLayout(row).Height; @@ -754,8 +778,6 @@ namespace FooEditEngine.Windows /// テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます public System.Drawing.Point GetPostionFromTextPoint(TextPoint tp) { - if (this.Document.State == AsyncState.Loading) - throw new InvalidOperationException(); if (this.Document.FireUpdateEvent == false) throw new InvalidOperationException(""); return this.View.GetPostionFromTextPoint(tp); @@ -768,8 +790,6 @@ namespace FooEditEngine.Windows /// テキストポイント public TextPoint GetTextPointFromPostion(System.Drawing.Point p) { - if (this.Document.State == AsyncState.Loading) - throw new InvalidOperationException(); if (this.Document.FireUpdateEvent == false) throw new InvalidOperationException(""); return this.View.GetTextPointFromPostion(p); @@ -782,8 +802,6 @@ namespace FooEditEngine.Windows /// 座標を返す public System.Drawing.Point GetPostionFromIndex(int index) { - if (this.Document.State == AsyncState.Loading) - throw new InvalidOperationException(); if (this.Document.FireUpdateEvent == false) throw new InvalidOperationException(""); TextPoint tp = this.View.GetLayoutLineFromIndex(index); @@ -797,8 +815,6 @@ namespace FooEditEngine.Windows /// インデックスを返す public int GetIndexFromPostion(System.Drawing.Point p) { - if (this.Document.State == AsyncState.Loading) - throw new InvalidOperationException(); if (this.Document.FireUpdateEvent == false) throw new InvalidOperationException(""); TextPoint tp = this.View.GetTextPointFromPostion(p); @@ -815,6 +831,57 @@ namespace FooEditEngine.Windows } /// + /// ストリームからドキュメントを構築する + /// + /// TextReader + /// キャンセル用トークン + /// Taskオブジェクト + public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token) + { + WinFileReader fs = new WinFileReader(tr); + await this.LoadAsyncImpl(fs, token); + } + + /// + /// ファイルからドキュメントを構築する + /// + /// ファイルパス + /// エンコード + /// キャンセル用トークン + /// Taskオブジェクト + public async Task LoadFileAsync(string filepath, Encoding enc, System.Threading.CancellationTokenSource token) + { + WinFileReader fs = new WinFileReader(filepath, enc); + await this.LoadAsyncImpl(fs, token); + } + + async Task LoadAsyncImpl(WinFileReader fs, System.Threading.CancellationTokenSource token) + { + this.Enabled = false; + this.View.LayoutLines.IsFrozneDirtyFlag = true; + await this.Document.LoadAsync(fs, token); + this.View.LayoutLines.IsFrozneDirtyFlag = false; + this.initScrollBars(); + this.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, MousePosition.X, MousePosition.Y, 0)); + this.View.CalculateLineCountOnScreen(); + this.Enabled = true; + } + + /// + /// ドキュメントの内容をファイルに保存する + /// + /// ファイルパス + /// 改行コード + /// エンコード + /// Taskオブジェクト + public async Task SaveFile(string filepath, Encoding enc, string newLine, System.Threading.CancellationTokenSource token) + { + WinFileWriter fs = new WinFileWriter(filepath, enc); + fs.NewLine = newLine; + await this.Document.SaveAsync(fs, token); + } + + /// /// マウスカーソルを指定します /// public override Cursor Cursor @@ -862,8 +929,6 @@ namespace FooEditEngine.Windows /// 文字がコントロールによって処理された場合は true。それ以外の場合は false。 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { - if (this.Document.State == AsyncState.Loading) - return false; const int WM_KEYDOWN = 0x100; if (msg.Msg != WM_KEYDOWN) return base.ProcessCmdKey(ref msg, keyData); @@ -907,7 +972,6 @@ namespace FooEditEngine.Windows protected override void Dispose(bool disposing) { SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(this.SystemEvents_UserPreferenceChanged); - DocumentExtend.Progress -= this.Document_Progress; this.render.Dispose(); this.Timer.Dispose(); base.Dispose(disposing); @@ -935,6 +999,16 @@ namespace FooEditEngine.Windows } /// + /// PaddingChangedイベントを発生させます + /// + /// インベントデータ + protected override void OnPaddingChanged(EventArgs e) + { + base.OnPaddingChanged(e); + this.View.Padding = new Padding(this.Padding.Left, this.Padding.Top, this.Padding.Right, this.Padding.Bottom); + } + + /// /// GotFocusイベントを発生させます /// /// インベントデータ @@ -974,9 +1048,6 @@ namespace FooEditEngine.Windows /// インベントデータ protected override void OnMouseDown(MouseEventArgs e) { - if (this.Document.State == AsyncState.Loading) - return; - TextPoint tp = this.View.GetTextPointFromPostion(e.Location); if (tp == TextPoint.Null) return; @@ -1016,9 +1087,6 @@ namespace FooEditEngine.Windows /// インベントデータ protected override void OnMouseClick(MouseEventArgs e) { - if (this.Document.State == AsyncState.Loading) - return; - int index = this.GetIndexFromPostion(e.Location); FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta); @@ -1032,9 +1100,6 @@ namespace FooEditEngine.Windows /// インベントデータ protected override void OnMouseDoubleClick(MouseEventArgs e) { - if (this.Document.State == AsyncState.Loading) - return; - TextPoint tp = this.View.GetTextPointFromPostion(e.Location); if (tp == TextPoint.Null) return; @@ -1058,11 +1123,6 @@ namespace FooEditEngine.Windows /// インベントデータ protected override void OnMouseMove(MouseEventArgs e) { - if (this.Document.State == AsyncState.Loading) - { - this.Cursor = Cursors.WaitCursor; - return; - } if (this.Focused == false) return; @@ -1094,9 +1154,6 @@ namespace FooEditEngine.Windows /// インベントデータ protected override void OnMouseWheel(MouseEventArgs e) { - if (this.Document.State == AsyncState.Loading) - return; - base.OnMouseWheel(e); ScrollDirection dir = e.Delta > 0 ? ScrollDirection.Up : ScrollDirection.Down; @@ -1110,13 +1167,13 @@ namespace FooEditEngine.Windows /// インベントデータ protected override void OnPaint(PaintEventArgs e) { - if (DesignMode || this.Document.State == AsyncState.Loading) + if (DesignMode) { SolidBrush brush = new SolidBrush(this.BackColor); e.Graphics.FillRectangle(brush, this.ClientRectangle); brush.Dispose(); }else if (this.Document.FireUpdateEvent){ - this.render.BeginDraw(); + this.render.BegineDraw(); this.View.Draw(e.ClipRectangle); this.render.EndDraw(); } @@ -1156,9 +1213,6 @@ namespace FooEditEngine.Windows /// インベントデータ protected override void OnKeyDown(KeyEventArgs e) { - if (this.Document.State == AsyncState.Loading) - return; - base.OnKeyDown(e); if (e.Handled) @@ -1236,9 +1290,6 @@ namespace FooEditEngine.Windows /// インベントデータ protected override void OnKeyPress(KeyPressEventArgs e) { - if (this.Document.State == AsyncState.Loading) - return; - base.OnKeyPress(e); if (e.Handled) @@ -1301,16 +1352,12 @@ namespace FooEditEngine.Windows void VScrollBar_Scroll(object sender, ScrollEventArgs e) { - if (this.Document.State == AsyncState.Loading) - return; this.View.TryScroll(this.View.Src.X, e.NewValue); this.Refresh(); } void HScrollBar_Scroll(object sender, ScrollEventArgs e) { - if (this.Document.State == AsyncState.Loading) - return; int toX; if (this.RightToLeft == System.Windows.Forms.RightToLeft.Yes) toX = -e.NewValue; @@ -1322,10 +1369,13 @@ namespace FooEditEngine.Windows void Ime_StartCompstion(object sender, StartCompstionEventArgs e) { - if (this.Document.State == AsyncState.Loading) - return; this.Ime.Font = this.Font; - this.Ime.Location = this.GetPostionFromIndex(this.Controller.SelectionStart); + System.Drawing.Point p = this.GetPostionFromIndex(this.Controller.SelectionStart); + float dpi; + this.render.GetDpi(out dpi, out dpi); + p.X = (int)(p.X * dpi / 96); + p.Y = (int)(p.Y * dpi / 96); + this.Ime.Location = p; this.View.HideCaret = true; } @@ -1336,16 +1386,12 @@ namespace FooEditEngine.Windows void Ime_ImeCompstion(object sender, ImeCompstionEventArgs e) { - if (this.Document.State == AsyncState.Loading) - return; this.Controller.DoInputString(e.InputText); this.Refresh(); } void Ime_ImeDocumentFeed(object sender, ImeDocumentFeedEventArgs e) { - if (this.Document.State == AsyncState.Loading) - return; TextPoint tp = this.CaretPostion; e.Pragraph = this.LayoutLines[tp.row]; e.pos = tp.col; @@ -1353,8 +1399,6 @@ namespace FooEditEngine.Windows void Ime_ImeReconvert(object sender, ImeReconvertStringEventArgs e) { - if (this.Document.State == AsyncState.Loading) - return; if (this.RectSelection) return; if (this.Controller.SelectionLength == 0) @@ -1374,9 +1418,6 @@ namespace FooEditEngine.Windows void Ime_ImeQueryReconvert(object sender, ImeQueryRecovertStringEventArgs e) { - if (this.Document.State == AsyncState.Loading) - return; - TextPoint tp = this.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart); tp.col = e.offset; @@ -1390,18 +1431,6 @@ namespace FooEditEngine.Windows this.SelectionChanged(this, null); } - void Document_Progress(object sender, ProgressEventArgs e) - { - if (this.Document.State == AsyncState.Saving) - return; - if (e.state == ProgressState.Complete) - { - this.initScrollBars(); - this.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, MousePosition.X, MousePosition.Y, 0)); - this.View.CalculateLineCountOnScreen(); - } - } - void initScrollBars() { this.VScrollBar.SmallChange = 1; @@ -1414,8 +1443,6 @@ namespace FooEditEngine.Windows void Timer_Tick(object sender,EventArgs e) { - if (this.Document.State == AsyncState.Loading) - return; if (this.View.CaretPostion.row >= this.View.LayoutLines.Count || DesignMode) return; @@ -1442,18 +1469,21 @@ namespace FooEditEngine.Windows if (CaretBlinkTime == -1) { this.View.CaretBlink = false; - this.BeginInvoke(new Action(() => { + if (this.IsHandleCreated) + this.BeginInvoke(new Action(() => + { this.Timer.Stop(); - })); + })); } else { this.View.CaretBlink = true; this.View.CaretBlinkTime = CaretBlinkTime * 2; - this.BeginInvoke(new Action(() => - { - this.Timer.Start(); - })); + if(this.IsHandleCreated) + this.BeginInvoke(new Action(() => + { + this.Timer.Start(); + })); } this.View.CaretWidthOnInsertMode = SystemInformation.CaretWidth; }