this.View.PerformLayouted += View_LineBreakChanged;\r
this.View.PageBoundChanged += View_PageBoundChanged;\r
this.Document.Clear();\r
- this.CaretMoved += new EventHandler((s, e) => { });\r
+ this.SelectionChanged += new EventHandler((s, e) => { });\r
}\r
\r
/// <summary>\r
- /// キャレット移動時に通知される\r
+ /// 選択領域変更時に通知される\r
/// </summary>\r
- public event EventHandler CaretMoved;\r
-\r
+ public event EventHandler SelectionChanged;\r
\r
/// <summary>\r
/// 矩形選択モードなら真を返し、そうでない場合は偽を返す\r
else\r
this.View.InsertPoint = null;\r
}\r
- else\r
+ else if(length != 0)\r
{\r
this.View.Selections.Add(Selection.Create(start, length));\r
this.View.InsertPoint = null;\r
}\r
+ this.SelectionChanged(this, null);\r
}\r
\r
public void Select(TextPoint tp, int width, int height)\r
this.View.InsertPoint = new SelectCollection(this.View.Selections);\r
else\r
this.View.InsertPoint = null;\r
+\r
+ this.SelectionChanged(this, null);\r
}\r
\r
private void SelectByRectangle(TextRectangle rect)\r
this.View.AdjustCaretAndSrc();\r
\r
this.SelectWithMoveCaret(false);\r
-\r
- this.CaretMoved(this, null);\r
}\r
\r
/// <summary>\r
this.View.JumpCaret(0, 0);\r
this.View.AdjustCaretAndSrc();\r
this.SelectWithMoveCaret(isSelected);\r
- this.CaretMoved(this, null);\r
}\r
\r
/// <summary>\r
this.View.JumpCaret(this.View.LayoutLines.Count - 1, 0);\r
this.View.AdjustCaretAndSrc();\r
this.SelectWithMoveCaret(isSelected);\r
- this.CaretMoved(this, null);\r
}\r
\r
/// <summary>\r
this.View.JumpCaret(toRow, 0);\r
this.View.AdjustCaretAndSrc();\r
this.SelectWithMoveCaret(isSelected);\r
- this.CaretMoved(this, null);\r
}\r
else\r
{\r
}\r
this.View.AdjustCaretAndSrc(AdjustFlow.Col);\r
this.SelectWithMoveCaret(isSelected);\r
- this.CaretMoved(this, null);\r
}\r
\r
void AlignNearestWord(bool MoveFlow)\r
this.MoveCaretVertical(deltarow > 0);\r
this.View.AdjustCaretAndSrc(AdjustFlow.Both);\r
this.SelectWithMoveCaret(isSelected);\r
- this.CaretMoved(this, null);\r
}\r
\r
/// <summary>\r
\r
SelectCollection Selections = this.View.Selections;\r
if (isSelected)\r
- this.Select(this.AnchorIndex, CaretPostion - this.AnchorIndex);\r
- else\r
{\r
- this.View.Selections.Clear();\r
+ this.Select(this.AnchorIndex, CaretPostion - this.AnchorIndex);\r
+ }else{\r
+ this.Select(CaretPostion, 0);\r
this.AnchorIndex = CaretPostion;\r
this.View.InsertPoint = null;\r
}\r
GestureRecognizer gestureRecongnizer = new GestureRecognizer();\r
TextStore2 textStore;\r
FooTextBoxAutomationPeer peer;\r
+ bool nowCaretMove = false;\r
\r
/// <summary>\r
/// コンストラクター\r
this.View.TabStops = this.TabChars;\r
\r
this._Controller = new Controller(this.Document, this.View);\r
- this._Controller.CaretMoved += Controller_CaretMoved;\r
+ this._Controller.SelectionChanged += Controller_SelectionChanged;\r
\r
this.FirstGripper = new Gripper(this._Controller, this.View, this.Render, GripperType.First);\r
this.SecondGripper = new Gripper(this._Controller, this.View, this.Render, GripperType.Second);\r
this.Refresh();\r
}\r
\r
- void Controller_CaretMoved(object sender, EventArgs e)\r
+ void Controller_SelectionChanged(object sender, EventArgs e)\r
{\r
+ //こうしないと選択できなくなってしまう\r
+ this.nowCaretMove = true;\r
SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));\r
SetValue(CaretPostionPropertyKey, this.View.CaretPostion);\r
+ this.nowCaretMove = false;\r
if (this.textStore.IsLocked() == false)\r
this.textStore.NotifySelectionChanged();\r
}\r
public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)\r
{\r
FooTextBox source = (FooTextBox)sender;\r
- if (e.Property.Equals(SelectionProperty))\r
+ if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)\r
source._Controller.Select(source.Selection.Index,source.Selection.Length);\r
- if (e.Property.Equals(CaretPostionPropertyKey))\r
+ if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)\r
source.JumpCaret(source.CaretPostion.row, source.CaretPostion.col);\r
if (e.Property.Equals(InsertModeProperty))\r
source.View.InsertMode = source.InsertMode;\r
DispatcherTimer timer;\r
bool disposed = false;\r
FooTextBoxAutomationPeer peer;\r
+ bool nowCaretMove = false;\r
\r
static FooTextBox()\r
{\r
this.View.TabStops = this.TabChars;\r
\r
this._Controller = new Controller(this.Document, this.View);\r
- this._Controller.CaretMoved += new EventHandler(Controller_CaretMoved);\r
+ this._Controller.SelectionChanged += new EventHandler(Controller_SelectionChanged);\r
\r
//Viewを作成した後に追加しないと例外が発生する\r
this.Document.Update += new DocumentUpdateEventHandler(Document_Update);\r
this.horizontalScrollBar.Value = Math.Abs(view.Src.X);\r
}\r
\r
- void Controller_CaretMoved(object sender, EventArgs e)\r
+ void Controller_SelectionChanged(object sender, EventArgs e)\r
{\r
this.View.CaretBlink = this.View.CaretBlink;\r
this.CaretMoved(this, null);\r
+ //こうしないと選択できなくなってしまう\r
+ this.nowCaretMove = true;\r
SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));\r
SetValue(CaretPostionProperty, this.View.CaretPostion);\r
+ this.nowCaretMove = false; \r
if(this.textStore.IsLocked() == false)\r
this.textStore.NotifySelectionChanged();\r
}\r
switch (e.Property.Name)\r
{\r
case "Selection":\r
- this.Select(this.Selection.Index, this.Selection.Length);\r
+ if(!this.nowCaretMove)\r
+ this.Select(this.Selection.Index, this.Selection.Length);\r
break;\r
case "CaretPostion":\r
- this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);\r
+ if (!this.nowCaretMove)\r
+ this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);\r
break;\r
case "LineBreakMethod":\r
this.View.LineBreak = this.LineBreakMethod;\r
/// Selectionの依存プロパティを表す\r
/// </summary>\r
public static readonly DependencyProperty SelectionProperty =\r
- DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(0));\r
+ DependencyProperty.Register("Selection", typeof(TextRange), typeof(FooTextBox), new PropertyMetadata(TextRange.Null));\r
\r
/// <summary>\r
/// 拡大率を表す\r
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">
+ <Window.Resources>
+ <local:TextRangeConveter x:Key="TextRangeConverter"/>
+ </Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="24"/>
</Menu>
<MyNamespace:FooTextBox x:Name="fooTextBox" Grid.Row="1"/>
<StackPanel Grid.Row="2" Orientation="Horizontal">
- <TextBlock Text="{Binding Selection.Index,ElementName=fooTextBox}"/>
- <TextBlock Text="{Binding Selection.Length,ElementName=fooTextBox}" Margin="10,0,0,0"/>
+ <TextBlock Text="{Binding Selection,ElementName=fooTextBox,Converter={StaticResource TextRangeConverter}}" Margin="10,0,0,0"/>
<TextBlock Text="FindPattern" Margin="10,0,0,0"/>
<TextBox Name="FindPattern" Width="100"/>
<TextBlock Text="ReplaceAll" Margin="10,0,0,0"/>
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();
+ }
+ }
}