From b4581ff92c447ac242e7ddea5816f087b51c1b0a Mon Sep 17 00:00:00 2001 From: gdkhd812 Date: Mon, 7 Oct 2013 00:54:45 +0900 Subject: [PATCH] =?utf8?q?=E6=AD=A3=E5=B8=B8=E3=81=AB=E9=81=B8=E6=8A=9E?= =?utf8?q?=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=84=E3=83=90=E3=82=B0=E3=82=92?= =?utf8?q?=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Common/Controller.cs | 25 ++++++++++--------------- Metro/FooEditEngnine/FooTextBox.cs | 12 ++++++++---- WPF/FooEditEngine/FooTextBox.cs | 16 +++++++++++----- WPF/Test/MainWindow.xaml | 7 +++++-- WPF/Test/MainWindow.xaml.cs | 13 +++++++++++++ 5 files changed, 47 insertions(+), 26 deletions(-) diff --git a/Common/Controller.cs b/Common/Controller.cs index edb6a32..14d0fea 100644 --- a/Common/Controller.cs +++ b/Common/Controller.cs @@ -51,14 +51,13 @@ namespace FooEditEngine this.View.PerformLayouted += View_LineBreakChanged; this.View.PageBoundChanged += View_PageBoundChanged; this.Document.Clear(); - this.CaretMoved += new EventHandler((s, e) => { }); + this.SelectionChanged += new EventHandler((s, e) => { }); } /// - /// キャレット移動時に通知される + /// 選択領域変更時に通知される /// - public event EventHandler CaretMoved; - + public event EventHandler SelectionChanged; /// /// 矩形選択モードなら真を返し、そうでない場合は偽を返す @@ -166,11 +165,12 @@ namespace FooEditEngine else this.View.InsertPoint = null; } - else + else if(length != 0) { this.View.Selections.Add(Selection.Create(start, length)); this.View.InsertPoint = null; } + this.SelectionChanged(this, null); } public void Select(TextPoint tp, int width, int height) @@ -193,6 +193,8 @@ namespace FooEditEngine this.View.InsertPoint = new SelectCollection(this.View.Selections); else this.View.InsertPoint = null; + + this.SelectionChanged(this, null); } private void SelectByRectangle(TextRectangle rect) @@ -386,8 +388,6 @@ namespace FooEditEngine this.View.AdjustCaretAndSrc(); this.SelectWithMoveCaret(false); - - this.CaretMoved(this, null); } /// @@ -401,7 +401,6 @@ namespace FooEditEngine this.View.JumpCaret(0, 0); this.View.AdjustCaretAndSrc(); this.SelectWithMoveCaret(isSelected); - this.CaretMoved(this, null); } /// @@ -418,7 +417,6 @@ namespace FooEditEngine this.View.JumpCaret(this.View.LayoutLines.Count - 1, 0); this.View.AdjustCaretAndSrc(); this.SelectWithMoveCaret(isSelected); - this.CaretMoved(this, null); } /// @@ -471,7 +469,6 @@ namespace FooEditEngine this.View.JumpCaret(toRow, 0); this.View.AdjustCaretAndSrc(); this.SelectWithMoveCaret(isSelected); - this.CaretMoved(this, null); } else { @@ -501,7 +498,6 @@ namespace FooEditEngine } this.View.AdjustCaretAndSrc(AdjustFlow.Col); this.SelectWithMoveCaret(isSelected); - this.CaretMoved(this, null); } void AlignNearestWord(bool MoveFlow) @@ -536,7 +532,6 @@ namespace FooEditEngine this.MoveCaretVertical(deltarow > 0); this.View.AdjustCaretAndSrc(AdjustFlow.Both); this.SelectWithMoveCaret(isSelected); - this.CaretMoved(this, null); } /// @@ -689,10 +684,10 @@ namespace FooEditEngine SelectCollection Selections = this.View.Selections; if (isSelected) - this.Select(this.AnchorIndex, CaretPostion - this.AnchorIndex); - else { - this.View.Selections.Clear(); + this.Select(this.AnchorIndex, CaretPostion - this.AnchorIndex); + }else{ + this.Select(CaretPostion, 0); this.AnchorIndex = CaretPostion; this.View.InsertPoint = null; } diff --git a/Metro/FooEditEngnine/FooTextBox.cs b/Metro/FooEditEngnine/FooTextBox.cs index 846849e..72ee373 100644 --- a/Metro/FooEditEngnine/FooTextBox.cs +++ b/Metro/FooEditEngnine/FooTextBox.cs @@ -47,6 +47,7 @@ namespace FooEditEngine.Metro GestureRecognizer gestureRecongnizer = new GestureRecognizer(); TextStore2 textStore; FooTextBoxAutomationPeer peer; + bool nowCaretMove = false; /// /// コンストラクター @@ -87,7 +88,7 @@ namespace FooEditEngine.Metro this.View.TabStops = this.TabChars; this._Controller = new Controller(this.Document, this.View); - this._Controller.CaretMoved += Controller_CaretMoved; + this._Controller.SelectionChanged += Controller_SelectionChanged; this.FirstGripper = new Gripper(this._Controller, this.View, this.Render, GripperType.First); this.SecondGripper = new Gripper(this._Controller, this.View, this.Render, GripperType.Second); @@ -736,10 +737,13 @@ namespace FooEditEngine.Metro this.Refresh(); } - void Controller_CaretMoved(object sender, EventArgs e) + void Controller_SelectionChanged(object sender, EventArgs e) { + //こうしないと選択できなくなってしまう + this.nowCaretMove = true; SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength)); SetValue(CaretPostionPropertyKey, this.View.CaretPostion); + this.nowCaretMove = false; if (this.textStore.IsLocked() == false) this.textStore.NotifySelectionChanged(); } @@ -1091,9 +1095,9 @@ namespace FooEditEngine.Metro public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e) { FooTextBox source = (FooTextBox)sender; - if (e.Property.Equals(SelectionProperty)) + if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove) source._Controller.Select(source.Selection.Index,source.Selection.Length); - if (e.Property.Equals(CaretPostionPropertyKey)) + if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove) source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col); if (e.Property.Equals(InsertModeProperty)) source.View.InsertMode = source.InsertMode; diff --git a/WPF/FooEditEngine/FooTextBox.cs b/WPF/FooEditEngine/FooTextBox.cs index 71d050f..37b5713 100644 --- a/WPF/FooEditEngine/FooTextBox.cs +++ b/WPF/FooEditEngine/FooTextBox.cs @@ -49,6 +49,7 @@ namespace FooEditEngine.WPF DispatcherTimer timer; bool disposed = false; FooTextBoxAutomationPeer peer; + bool nowCaretMove = false; static FooTextBox() { @@ -101,7 +102,7 @@ namespace FooEditEngine.WPF this.View.TabStops = this.TabChars; this._Controller = new Controller(this.Document, this.View); - this._Controller.CaretMoved += new EventHandler(Controller_CaretMoved); + this._Controller.SelectionChanged += new EventHandler(Controller_SelectionChanged); //Viewを作成した後に追加しないと例外が発生する this.Document.Update += new DocumentUpdateEventHandler(Document_Update); @@ -1027,12 +1028,15 @@ namespace FooEditEngine.WPF this.horizontalScrollBar.Value = Math.Abs(view.Src.X); } - void Controller_CaretMoved(object sender, EventArgs e) + void Controller_SelectionChanged(object sender, EventArgs e) { this.View.CaretBlink = this.View.CaretBlink; this.CaretMoved(this, null); + //こうしないと選択できなくなってしまう + this.nowCaretMove = true; SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength)); SetValue(CaretPostionProperty, this.View.CaretPostion); + this.nowCaretMove = false; if(this.textStore.IsLocked() == false) this.textStore.NotifySelectionChanged(); } @@ -1074,10 +1078,12 @@ namespace FooEditEngine.WPF switch (e.Property.Name) { case "Selection": - this.Select(this.Selection.Index, this.Selection.Length); + if(!this.nowCaretMove) + this.Select(this.Selection.Index, this.Selection.Length); break; case "CaretPostion": - this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col); + if (!this.nowCaretMove) + this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col); break; case "LineBreakMethod": this.View.LineBreak = this.LineBreakMethod; @@ -1287,7 +1293,7 @@ namespace FooEditEngine.WPF /// Selectionの依存プロパティを表す /// public static readonly DependencyProperty SelectionProperty = - DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(0)); + DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null)); /// /// 拡大率を表す diff --git a/WPF/Test/MainWindow.xaml b/WPF/Test/MainWindow.xaml index 6a00578..24d52e3 100644 --- a/WPF/Test/MainWindow.xaml +++ b/WPF/Test/MainWindow.xaml @@ -2,7 +2,11 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:MyNamespace="clr-namespace:FooEditEngine.WPF;assembly=FooEditEngine.WPF" + xmlns:local="clr-namespace:Test" Title="MainWindow" Height="350" Width="525"> + + + @@ -28,8 +32,7 @@ - - + diff --git a/WPF/Test/MainWindow.xaml.cs b/WPF/Test/MainWindow.xaml.cs index b744416..58464a7 100644 --- a/WPF/Test/MainWindow.xaml.cs +++ b/WPF/Test/MainWindow.xaml.cs @@ -243,4 +243,17 @@ namespace Test this.fooTextBox.Refresh(); } } + public class TextRangeConveter : System.Windows.Data.IValueConverter + { + public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + FooEditEngine.TextRange range = (FooEditEngine.TextRange)value; + return string.Format("Index:{0} Length:{1}", range.Index, range.Length); + } + + public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new System.NotImplementedException(); + } + } } -- 2.11.0