#endif
bool nowCaretMove = false;
bool nowCompstion = false;
+ bool requestSizeChange = false;
Document _Document;
DispatcherTimer timer = new DispatcherTimer();
- const int Interval = 16;
+ const int Interval = 32;
const int IntervalWhenLostFocus = 160;
/// <summary>
this.timer.Tick += this.timer_Tick;
this.timer.Start();
+ this.GettingFocus += FooTextBox_GettingFocus;
+ this.LosingFocus += FooTextBox_LosingFocus;
+
this.SizeChanged += FooTextBox_SizeChanged;
this.Loaded += FooTextBox_Loaded;
var dataPackageView = Clipboard.GetContent();
if (dataPackageView.Contains(StandardDataFormats.Text))
{
- this._Controller.SelectedText = await dataPackageView.GetTextAsync();
+ try
+ {
+ this._Controller.SelectedText = await dataPackageView.GetTextAsync();
+ }catch(Exception e)
+ {
+ System.Diagnostics.Debug.WriteLine("past error:" + e.Message);
+ }
}
}
/// <summary>
/// 再描写する
/// </summary>
- public void Refresh()
+ public void Refresh(bool immidately=true)
{
- this.Document.RequestRedraw();
+ if(immidately)
+ this.Refresh(this.View.PageBound);
+ else
+ this.Document.RequestRedraw();
}
/// <summary>
if (this.verticalScrollBar != null)
this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
this.IsEnabled = true;
- this.Refresh(this.View.PageBound);
+ this.Refresh(false);
}
}
}
}
- /// <inheritdoc/>
- protected override async void OnGotFocus(RoutedEventArgs e)
+ private void FooTextBox_LosingFocus(UIElement sender, LosingFocusEventArgs args)
{
- base.OnGotFocus(e);
+ this.RemoveTextContext();
+
+ if (this.textServiceManager != null)
+ {
+ this.textServiceManager.InputLanguageChanged -= TextServiceManager_InputLanguageChanged;
+ this.textServiceManager = null;
+ }
- System.Diagnostics.Debug.WriteLine("got focus");
+ System.Diagnostics.Debug.WriteLine("losing focus");
+ }
+ private async void FooTextBox_GettingFocus(UIElement sender, GettingFocusEventArgs args)
+ {
+ System.Diagnostics.Debug.WriteLine("getting focus");
if (this.textServiceManager == null)
{
await Task.Delay(500);
}
this.CreateTextContext();
+ }
+
+ /// <inheritdoc/>
+ protected override void OnGotFocus(RoutedEventArgs e)
+ {
+ base.OnGotFocus(e);
+
+ System.Diagnostics.Debug.WriteLine("got focus");
this.View.IsFocused = true;
this.timer.Interval = new TimeSpan(0, 0, 0, 0, Interval);
- this.Refresh();
+ this.Refresh(false);
}
private void TextServiceManager_InputLanguageChanged(CoreTextServicesManager sender, object args)
{
System.Diagnostics.Debug.WriteLine("input language changed input script:"+ this.textServiceManager.InputLanguage.Script);
- this.RemoveTextContext();
- this.CreateTextContext();
}
- /// <inheritdoc/>
+ /// <inheritdoc/>
protected override void OnLostFocus(RoutedEventArgs e)
{
base.OnLostFocus(e);
- this.RemoveTextContext();
-
System.Diagnostics.Debug.WriteLine("lost focus");
this.View.IsFocused = false;
- this.Refresh(this.View.PageBound);
+ this.Refresh(false);
this.timer.Interval = new TimeSpan(0, 0, 0, 0, IntervalWhenLostFocus);
}
if(this.textServiceManager != null)
{
this.textEditContext = this.textServiceManager.CreateEditContext();
+ this.textEditContext.InputScope = CoreTextInputScope.Text;
this.textEditContext.CompositionStarted += TextEditContext_CompositionStarted;
this.textEditContext.CompositionCompleted += TextEditContext_CompositionCompleted;
this.textEditContext.LayoutRequested += TextEditContext_LayoutRequested;
{
if(this.textEditContext != null)
{
+ this.textEditContext.NotifyFocusLeave();
this.textEditContext.CompositionStarted -= TextEditContext_CompositionStarted;
this.textEditContext.CompositionCompleted -= TextEditContext_CompositionCompleted;
this.textEditContext.LayoutRequested -= TextEditContext_LayoutRequested;
this.textEditContext.FormatUpdating -= TextEditContext_FormatUpdating;
this.textEditContext.FocusRemoved -= TextEditContext_FocusRemoved;
this.textEditContext.NotifyFocusLeaveCompleted -= TextEditContext_NotifyFocusLeaveCompleted;
- this.textEditContext.NotifyFocusLeave();
this.textEditContext = null;
}
}
//タッチスクリーンで行選択した場合、アンカーインデックスを単語の先頭にしないとバグる
this.Document.SelectGrippers.BottomLeft.Enabled = touched;
this.Document.SelectLine(this.Controller.SelectionStart, touched);
+ this.Refresh();
}
else if(e.TapCount == 2) //ダブルタップ
{
void FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)
{
- if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))
- {
- //普通に再描写するとちらつく
- this.Refresh(this.View.PageBound);
- }
+ //LostFocusやGotFocusなどと競合するとDirect2Dでエラーが起きるので、timer_tickイベントでサイズ変更を行うことにした
+ this.requestSizeChange = true;
}
void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)
void timer_Tick(object sender, object e)
{
- if (this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding() || this.Document.IsRequestRedraw)
+ this.timer.Stop();
+ if(this.requestSizeChange)
+ {
+ if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))
+ {
+ //普通に再描写するとちらつく
+ this.Refresh(this.View.PageBound);
+ }
+ this.requestSizeChange = false;
+ }
+ else if (this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding() || this.Document.IsRequestRedraw)
{
this.Refresh(this.View.PageBound);
}
+ this.timer.Start();
}
private void SetDocument(Document value)