OSDN Git Service

バックグランドで更新する可能性があるのでタイマーを止めないことにした
authorkonekoneko <test2214@hotmail.co.jp>
Sun, 20 Nov 2016 14:09:32 +0000 (19:39 +0530)
committerkonekoneko <test2214@hotmail.co.jp>
Sun, 20 Nov 2016 14:09:32 +0000 (19:39 +0530)
UWP/FooEditEngine.UWP/FooTextBox.cs
WPF/FooEditEngine/FooTextBox.cs

index 49f03d5..ddbef7c 100644 (file)
@@ -58,6 +58,9 @@ namespace FooEditEngine.UWP
         Document _Document;
         DispatcherTimer timer = new DispatcherTimer();
 
+        const int Interval = 16;
+        const int IntervalWhenLostFocus = 160;
+
         /// <summary>
         /// コンストラクター
         /// </summary>
@@ -104,7 +107,7 @@ namespace FooEditEngine.UWP
             this.gestureRecongnizer.ManipulationUpdated += gestureRecongnizer_ManipulationUpdated;
             this.gestureRecongnizer.ManipulationCompleted += gestureRecongnizer_ManipulationCompleted;
 
-            this.timer.Interval = new TimeSpan(0, 0, 0, 0, 16);
+            this.timer.Interval = new TimeSpan(0, 0, 0, 0, Interval);
             this.timer.Tick += this.timer_Tick;
             this.timer.Start();
 
@@ -433,7 +436,9 @@ namespace FooEditEngine.UWP
         {
             base.OnGotFocus(e);
 
-            if(this.textServiceManager == null)
+            System.Diagnostics.Debug.WriteLine("got focus");
+
+            if (this.textServiceManager == null)
             {
                 await Task.Delay(500);
                 this.textServiceManager = CoreTextServicesManager.GetForCurrentView();
@@ -443,7 +448,7 @@ namespace FooEditEngine.UWP
             this.CreateTextContext();
 
             this.View.IsFocused = true;
-            this.timer.Start();
+            this.timer.Interval = new TimeSpan(0, 0, 0, 0, Interval);
             this.Refresh();
         }
 
@@ -461,9 +466,11 @@ namespace FooEditEngine.UWP
 
             this.RemoveTextContext();
 
+            System.Diagnostics.Debug.WriteLine("lost focus");
+            
             this.View.IsFocused = false;
             this.Refresh(this.View.PageBound);
-            this.timer.Stop();
+            this.timer.Interval = new TimeSpan(0, 0, 0, 0, IntervalWhenLostFocus);
         }
 
         private void CreateTextContext()
@@ -1261,6 +1268,7 @@ namespace FooEditEngine.UWP
 
         void timer_Tick(object sender, object e)
         {
+            System.Diagnostics.Debug.WriteLine("interval {0}", DateTime.Now.Millisecond);
             if (this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding() || this.Document.IsRequestRedraw)
             {
                 this.Refresh(this.View.PageBound);
index 0fa8933..b93cc7d 100644 (file)
@@ -47,7 +47,10 @@ namespace FooEditEngine.WPF
         bool isNotifyChanged = false;
         Document _Document;
         Popup popup;
-        
+
+        const int Interval = 16;
+        const int IntervalWhenLostFocuse = 160;
+
         static FooTextBox()
         {
             DefaultStyleKeyProperty.OverrideMetadata(typeof(FooTextBox), new FrameworkPropertyMetadata(typeof(FooTextBox)));
@@ -125,7 +128,7 @@ namespace FooEditEngine.WPF
             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, 16);
+            this.timer.Interval = new TimeSpan(0, 0, 0, 0, Interval);
             this.timer.Tick += new EventHandler(timer_Tick);
 
             this.Loaded += new RoutedEventHandler(FooTextBox_Loaded);
@@ -648,7 +651,7 @@ namespace FooEditEngine.WPF
             base.OnGotKeyboardFocus(e);
             this.textStore.SetFocus();
             this.View.IsFocused = true;
-            this.timer.Start();
+            this.timer.Interval = new TimeSpan(0,0,0,0,Interval);
             this.Refresh();
         }
 
@@ -660,9 +663,8 @@ namespace FooEditEngine.WPF
         {
             base.OnLostKeyboardFocus(e);
             this.View.IsFocused = false;
-            //タイマーを止めるので強制的に再描写させる
-            this.Refresh(this.View.PageBound);
-            this.timer.Stop();
+            this.timer.Interval = new TimeSpan(0, 0, 0, 0, IntervalWhenLostFocuse);
+            this.Refresh();
         }
         #endregion
         #region Event