bool isNotifyChanged = false;
Document _Document;
Popup popup;
-
+
+ const int Interval = 96;
+ const int IntervalWhenLostFocuse = 160;
+
static FooTextBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(typeof(FooTextBox)));
this.textStore.CompositionEnded += textStore_CompositionEnded;
this.Render = new D2DRender(this, 200, 200,this.image);
- this.Render.ShowFullSpace = this.ShowFullSpace;
- this.Render.ShowHalfSpace = this.ShowHalfSpace;
- this.Render.ShowTab = this.ShowTab;
this.Document = new Document();
this.Document.HideRuler = !this.DrawRuler;
this.Document.UrlMark = this.MarkURL;
this.Document.TabStops = this.TabChars;
+ this.Document.ShowFullSpace = this.ShowFullSpace;
+ this.Document.ShowHalfSpace = this.ShowHalfSpace;
+ this.Document.ShowTab = this.ShowTab;
this._Controller = new Controller(this.Document, this.View);
this._Document.SelectionChanged += new EventHandler(Controller_SelectionChanged);
this.InputBindings.Add(new InputBinding(FooTextBoxCommands.ToggleCodePoint, new KeyGesture(Key.X, ModifierKeys.Alt)));
this.timer = new DispatcherTimer();
- this.timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
+ this.timer.Interval = new TimeSpan(0, 0, 0, 0, Interval);
this.timer.Tick += new EventHandler(timer_Tick);
this.Loaded += new RoutedEventHandler(FooTextBox_Loaded);
{
this.verticalScrollBar.SmallChange = 1;
this.verticalScrollBar.LargeChange = 10;
- this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
+ this.verticalScrollBar.Maximum = this.Document.LayoutLines.Count - 1;
this.verticalScrollBar.Scroll += new ScrollEventHandler(verticalScrollBar_Scroll);
}
}
TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
if (this.verticalScrollBar != null)
this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
+ this.View.CalculateWhloeViewPort();
this.View.CalculateLineCountOnScreen();
this.IsEnabled = true;
+ this.Refresh(this.View.PageBound);
}
}
base.OnGotKeyboardFocus(e);
this.textStore.SetFocus();
this.View.IsFocused = true;
+ this.timer.Interval = new TimeSpan(0,0,0,0,Interval);
this.Refresh();
}
{
base.OnLostKeyboardFocus(e);
this.View.IsFocused = false;
+ this.timer.Interval = new TimeSpan(0, 0, 0, 0, IntervalWhenLostFocuse);
this.Refresh();
}
#endregion
if (e.LeftButton == MouseButtonState.Pressed)
{
+ if (p.X < this.Render.TextArea.X)
+ this.Document.SelectLine((int)index);
+ else
+ this.Document.SelectWord((int)index);
- this.Document.SelectWord((int)index);
this.textStore.NotifySelectionChanged();
if(this.peer != null)
this.peer.OnNotifyCaretChanged();
TextPointSearchRange searchRange;
if (this.View.HitTextArea(p.X, p.Y))
+ {
searchRange = TextPointSearchRange.TextAreaOnly;
+ }
else if (leftPressed)
+ {
searchRange = TextPointSearchRange.Full;
+ }
else
- searchRange = TextPointSearchRange.TextAreaOnly;
+ {
+ this.Cursor = Cursors.Arrow;
+ base.OnMouseMove(e);
+ return;
+ }
TextPoint tp = this.View.GetTextPointFromPostion(p, searchRange);
if (tp == TextPoint.Null)
{
+ this.Cursor = Cursors.Arrow;
base.OnMouseMove(e);
return;
}
{
this.Cursor = Cursors.Arrow;
}
-
if (leftPressed)
{
- this._Controller.MoveCaretAndSelect(tp);
+ bool controlPressed = (Keyboard.GetKeyStates(Key.LeftCtrl) & KeyStates.Down) == KeyStates.Down;
+ this._Controller.MoveCaretAndSelect(tp, controlPressed);
if (this.peer != null)
this.peer.OnNotifyCaretChanged();
this.Refresh();
return;
if (this.Resize(this.image.ActualWidth, this.image.ActualHeight))
{
- this.Refresh();
+ this.Refresh(this.View.PageBound);
return;
}
bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding() || this.Document.IsRequestRedraw;
if (updateAll)
- this.Refresh();
+ this.Refresh(this.View.PageBound);
else
this.Refresh(this.View.GetCurrentCaretRect());
}
toX = this.horizontalScrollBar.Value;
else
toX = -this.horizontalScrollBar.Value;
- this._Controller.Scroll(toX, this.View.Src.Row, false, false);
+ this.Controller.ScrollByPixel(ScrollDirection.Left, (int)toX, false, false);
this.Refresh();
}
{
if (this.verticalScrollBar == null)
return;
- int newRow = (int)this.verticalScrollBar.Value;
- if (newRow >= this.View.LayoutLines.Count)
- return;
- this._Controller.Scroll(this.View.Src.X,newRow, false, false);
+ this.Controller.Scroll(this.Document.Src.X, (int)this.verticalScrollBar.Value, false, false);
this.Refresh();
}
if (this.horizontalScrollBar == null || this.verticalScrollBar == null)
return;
EditView view = this.View;
- if (view.Src.Row > this.verticalScrollBar.Maximum)
- this.verticalScrollBar.Maximum = view.Src.Row + view.LineCountOnScreen + 1;
+ if (view.Src.Row > this.Document.LayoutLines.Count)
+ this.verticalScrollBar.Maximum = this.Document.LayoutLines.Count - 1;
double absoulteX = Math.Abs(view.Src.X);
if(absoulteX > this.horizontalScrollBar.Maximum)
this.horizontalScrollBar.Maximum = absoulteX + view.PageBound.Width + 1;
{
old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
old_doc.LoadProgress -= Document_LoadProgress;
- old_doc.SelectionChanged += new EventHandler(Controller_SelectionChanged);
+ old_doc.SelectionChanged -= new EventHandler(Controller_SelectionChanged);
+ old_doc.AutoCompleteChanged -= _Document_AutoCompleteChanged;
oldLength = old_doc.Length;
if (this._Document.AutoComplete != null)
{
this._Document.LayoutLines.Render = this.Render;
this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
this._Document.LoadProgress += Document_LoadProgress;
- if (this._Document.AutoComplete != null)
- {
- ((AutoCompleteBox)this._Document.AutoComplete).TargetPopup = this.popup;
- this._Document.AutoComplete.GetPostion = (tp, doc) =>
- {
- var p = this.View.GetPostionFromTextPoint(tp);
- int height = (int)doc.LayoutLines.GetLayout(doc.CaretPostion.row).Height;
- p.Y += height;
- return PointToScreen(this.TranslatePoint(p.Scale(Util.GetScale()), this));
- };
- }
+ this._Document.AutoCompleteChanged += _Document_AutoCompleteChanged;
+ if (this._Document.AutoComplete != null && this.Document.AutoComplete.GetPostion == null)
+ this._Document_AutoCompleteChanged(this.Document, null);
//初期化が終わっていればすべて存在する
if (this.Controller != null && this.View != null && this.textStore != null)
{
this.Refresh();
}
}
+
+ private void _Document_AutoCompleteChanged(object sender, EventArgs e)
+ {
+ Document doc = (Document)sender;
+ ((AutoCompleteBox)this._Document.AutoComplete).TargetPopup = this.popup;
+ this._Document.AutoComplete.GetPostion = (tp, edoc) =>
+ {
+ var p = this.View.GetPostionFromTextPoint(tp);
+ int height = (int)this.Render.emSize.Height;
+ p.Y += height;
+ return PointToScreen(this.TranslatePoint(p.Scale(Util.GetScale()), this));
+ };
+ }
+
/// <summary>
/// プロパティーが変更されたときに呼ばれます
/// </summary>
case "Foreground":
this.Render.Foreground = D2DRender.ToColor4(this.Foreground);
break;
+ case "HilightForeground":
+ this.Render.HilightForeground = D2DRender.ToColor4(this.HilightForeground);
+ break;
case "Background":
this.Render.Background = D2DRender.ToColor4(this.Background);
break;
/// </summary>
public new static readonly DependencyProperty BackgroundProperty =
DependencyProperty.Register("Background", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(SystemColors.WindowColor));
-
+
+ /// <summary>
+ /// 選択時の文字色を表す。これは依存プロパティです
+ /// </summary>
+ public System.Windows.Media.Color HilightForeground
+ {
+ get { return (System.Windows.Media.Color)GetValue(HilightForegroundProperty); }
+ set { SetValue(HilightForegroundProperty, value); }
+ }
+
+ /// <summary>
+ /// ControlCharの依存プロパティを表す
+ /// </summary>
+ public static readonly DependencyProperty HilightForegroundProperty =
+ DependencyProperty.Register("HilightForeground", typeof(System.Windows.Media.Color), typeof(FooTextBox), new FrameworkPropertyMetadata(Colors.White));
+
/// <summary>
/// コントロールコードの文字色を表す。これは依存プロパティです
/// </summary>