ShowCaret/HideCaret: Don't reset the blinking interval

Michael Kaufmann hallo at michael-kaufmann.ch
Sun Oct 30 09:22:03 CST 2005


Tests on Windows show that ShowCaret and HideCaret don't reset the 
blinking interval of the caret. So the blinking timer has to be started 
in CreateCaret and stopped in DestroyCaret.

Changelog:
  - Don't reset the blinking interval in ShowCaret/HideCaret
  - Reset the blinking interval in SetCaretPos only if the caret 
position changed

-------------- next part --------------
Index: dlls/user/caret.c
===================================================================
RCS file: /home/wine/wine/dlls/user/caret.c,v
retrieving revision 1.6
diff -u -r1.6 caret.c
--- dlls/user/caret.c	12 Sep 2005 15:14:07 -0000	1.6
+++ dlls/user/caret.c	30 Oct 2005 14:03:03 -0000
@@ -185,16 +185,18 @@
     SERVER_END_REQ;
     if (!ret) return FALSE;
 
-    if (prev && !hidden)  /* hide the previous one */
+    if (prev)
     {
-        /* FIXME: won't work if prev belongs to a different process */
         KillSystemTimer( prev, TIMERID );
-        if (old_state) CARET_DisplayCaret( prev, &r );
+    
+        /* hide the previous caret */
+        if (!hidden && old_state) CARET_DisplayCaret( prev, &r );
     }
 
     if (Caret.hBmp) DeleteObject( Caret.hBmp );
     Caret.hBmp = hBmp;
     Caret.timeout = GetProfileIntA( "windows", "CursorBlinkRate", 500 );
+    SetSystemTimer( hwnd, TIMERID, Caret.timeout, CARET_Callback );
     return TRUE;
 }
 
@@ -228,11 +230,10 @@
     }
     SERVER_END_REQ;
 
-    if (ret && prev && !hidden)
+    if (ret && prev)
     {
-        /* FIXME: won't work if prev belongs to a different process */
         KillSystemTimer( prev, TIMERID );
-        if (old_state) CARET_DisplayCaret( prev, &r );
+        if (!hidden && old_state) CARET_DisplayCaret( prev, &r );
     }
     if (Caret.hBmp) DeleteObject( Caret.hBmp );
     Caret.hBmp = 0;
@@ -248,8 +249,15 @@
     BOOL ret;
     HWND hwnd = 0;
     RECT r;
+    POINT old_pos;
     int old_state = 0;
     int hidden = 0;
+    
+    if (GetCaretPos(&old_pos))
+    {
+        if ((x == old_pos.x) && (y == old_pos.y))
+            return TRUE;
+    }
 
     SERVER_START_REQ( set_caret_info )
     {
@@ -271,16 +279,23 @@
         }
     }
     SERVER_END_REQ;
-    if (ret && !hidden)
+    
+    if (ret && hwnd)
     {
-        if (old_state) CARET_DisplayCaret( hwnd, &r );
-        r.right += x - r.left;
-        r.bottom += y - r.top;
-        r.left = x;
-        r.top = y;
-        CARET_DisplayCaret( hwnd, &r );
+        if (!hidden)
+        {
+            if (old_state) CARET_DisplayCaret( hwnd, &r );
+            r.right += x - r.left;
+            r.bottom += y - r.top;
+            r.left = x;
+            r.top = y;
+            CARET_DisplayCaret( hwnd, &r );
+        }
+        
+        /* Restart the blinking interval */
         SetSystemTimer( hwnd, TIMERID, Caret.timeout, CARET_Callback );
     }
+   
     return ret;
 }
 
@@ -297,7 +312,7 @@
 
     SERVER_START_REQ( set_caret_info )
     {
-        req->flags  = SET_CARET_HIDE|SET_CARET_STATE;
+        req->flags  = SET_CARET_HIDE;
         req->handle = hwnd;
         req->x      = 0;
         req->y      = 0;
@@ -316,11 +331,9 @@
     }
     SERVER_END_REQ;
 
-    if (ret && !hidden)
-    {
-        if (old_state) CARET_DisplayCaret( hwnd, &r );
-        KillSystemTimer( hwnd, TIMERID );
-    }
+    if (ret && (hidden == 0) && old_state)  /* hidden was 0 so it's now 1 */
+        CARET_DisplayCaret( hwnd, &r );
+    
     return ret;
 }
 
@@ -337,12 +350,12 @@
 
     SERVER_START_REQ( set_caret_info )
     {
-        req->flags  = SET_CARET_HIDE|SET_CARET_STATE;
+        req->flags  = SET_CARET_HIDE;
         req->handle = hwnd;
         req->x      = 0;
         req->y      = 0;
         req->hide   = -1;
-        req->state  = 1;
+        req->state  = 0;
         if ((ret = !wine_server_call_err( req )))
         {
             hwnd      = reply->full_handle;
@@ -356,11 +369,9 @@
     }
     SERVER_END_REQ;
 
-    if (ret && (hidden == 1))  /* hidden was 1 so it's now 0 */
-    {
+    if (ret && (hidden == 1) && old_state)  /* hidden was 1 so it's now 0 */
         CARET_DisplayCaret( hwnd, &r );
-        SetSystemTimer( hwnd, TIMERID, Caret.timeout, CARET_Callback );
-    }
+    
     return ret;
 }
 
@@ -396,10 +407,19 @@
  */
 BOOL WINAPI SetCaretBlinkTime( UINT msecs )
 {
+    GUITHREADINFO info;
+
     TRACE("msecs=%d\n", msecs);
 
     Caret.timeout = msecs;
-/*    if (Caret.hwnd) CARET_SetTimer(); FIXME */
+    
+    /* Restart the blinking interval */
+    if (GetGUIThreadInfo( GetCurrentThreadId(), &info ) && info.hwndCaret)
+    {
+        SetSystemTimer( info.hwndCaret, TIMERID, Caret.timeout,
+            CARET_Callback );
+    }
+    
     return TRUE;
 }
 


More information about the wine-patches mailing list