OSDN Git Service

リザイズ時にフォーカス系のイベントが呼ばれると落ちることがあった
authortest <test@yahoo.co.jp>
Sun, 23 Aug 2020 07:16:02 +0000 (16:16 +0900)
committertest <test@yahoo.co.jp>
Sun, 23 Aug 2020 07:16:02 +0000 (16:16 +0900)
UWP/FooEditEngine.UWP/FooTextBox.cs

index f9301bc..8a37743 100644 (file)
@@ -55,10 +55,11 @@ namespace FooEditEngine.UWP
 #endif
         bool nowCaretMove = false;
         bool nowCompstion = false;
+        bool requestSizeChange = false;
         Document _Document;
         DispatcherTimer timer = new DispatcherTimer();
 
-        const int Interval = 96;
+        const int Interval = 32;
         const int IntervalWhenLostFocus = 160;
 
         /// <summary>
@@ -313,9 +314,12 @@ namespace FooEditEngine.UWP
         /// <summary>
         /// 再描写する
         /// </summary>
-        public void Refresh()
+        public void Refresh(bool immidately=true)
         {
-            this.Refresh(this.View.PageBound);
+            if(immidately)
+                this.Refresh(this.View.PageBound);
+            else
+                this.Document.RequestRedraw();
         }
 
         /// <summary>
@@ -475,7 +479,7 @@ namespace FooEditEngine.UWP
 
             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)
@@ -491,7 +495,7 @@ namespace FooEditEngine.UWP
             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);
         }
 
@@ -1244,11 +1248,8 @@ namespace FooEditEngine.UWP
 
         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)
@@ -1318,7 +1319,16 @@ namespace FooEditEngine.UWP
         void timer_Tick(object sender, object e)
         {
             this.timer.Stop();
-            if (this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding() || this.Document.IsRequestRedraw)
+            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);
             }