[WIN32SS][NTUSER] Fix PostTimeMessage message time
[reactos.git] / win32ss / user / ntuser / timer.c
index f113be3..fc348ee 100644 (file)
@@ -2,7 +2,7 @@
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
  * PURPOSE:          Window timers messages
- * FILE:             subsystems/win32/win32k/ntuser/timer.c
+ * FILE:             win32ss/user/ntuser/timer.c
  * PROGRAMER:        Gunnar
  *                   Thomas Weidenmueller (w3seek@users.sourceforge.net)
  *                   Michael Martin (michael.martin@reactos.org)
@@ -16,8 +16,6 @@ DBG_DEFAULT_CHANNEL(UserTimer);
 static LIST_ENTRY TimersListHead;
 static LONG TimeLast = 0;
 
-#define MAX_ELAPSE_TIME 0x7FFFFFFF
-
 /* Windows 2000 has room for 32768 window-less timers */
 #define NUM_WINDOW_LESS_TIMERS   32768
 
@@ -189,25 +187,25 @@ IntSetTimer( PWND Window,
 
 #if 0
   /* Windows NT/2k/XP behaviour */
-  if (Elapse > MAX_ELAPSE_TIME)
+  if (Elapse > USER_TIMER_MAXIMUM)
   {
      TRACE("Adjusting uElapse\n");
      Elapse = 1;
   }
 #else
   /* Windows XP SP2 and Windows Server 2003 behaviour */
-  if (Elapse > MAX_ELAPSE_TIME)
+  if (Elapse > USER_TIMER_MAXIMUM)
   {
      TRACE("Adjusting uElapse\n");
-     Elapse = MAX_ELAPSE_TIME;
+     Elapse = USER_TIMER_MAXIMUM;
   }
 #endif
 
   /* Windows 2k/XP and Windows Server 2003 SP1 behaviour */
-  if (Elapse < 10)
+  if (Elapse < USER_TIMER_MINIMUM)
   {
      TRACE("Adjusting uElapse\n");
-     Elapse = 10; // 1024hz .9765625 ms, set to 10.0 ms (+/-)1 ms
+     Elapse = USER_TIMER_MINIMUM; // 1024hz .9765625 ms, set to 10.0 ms (+/-)1 ms
   }
 
   /* Passing an IDEvent of 0 and the SetTimer returns 1.
@@ -281,8 +279,8 @@ VOID
 CALLBACK
 SystemTimerProc(HWND hwnd,
                 UINT uMsg,
-         UINT_PTR idEvent,
-             DWORD dwTime)
+                UINT_PTR idEvent,
+                DWORD dwTime)
 {
   PDESKTOP pDesk;
   PWND pWnd = NULL;
@@ -292,7 +290,7 @@ SystemTimerProc(HWND hwnd,
      pWnd = UserGetWindowObject(hwnd);
      if (!pWnd)
      {
-        ERR( "System Timer Proc has invalid window handle! 0x%x Id: %d\n", hwnd, idEvent);
+        ERR("System Timer Proc has invalid window handle! %p Id: %u\n", hwnd, idEvent);
         return;
      }
   }
@@ -317,12 +315,12 @@ SystemTimerProc(HWND hwnd,
           if ( pDesk->dwDTFlags & DF_TME_HOVER &&
                pWnd == pDesk->spwndTrack )
           {
-             Point = pWnd->head.pti->MessageQueue->MouseMoveMsg.pt;
+             Point = gpsi->ptCursor;
              if ( RECTL_bPointInRect(&pDesk->rcMouseHover, Point.x, Point.y) )
              {
                 if (pDesk->htEx == HTCLIENT) // In a client area.
                 {
-                   wParam = UserGetMouseButtonsState();
+                   wParam = MsqGetDownKeyState(pWnd->head.pti->MessageQueue);
                    Msg = WM_MOUSEHOVER;
 
                    if (pWnd->ExStyle & WS_EX_LAYOUTRTL)
@@ -347,8 +345,19 @@ SystemTimerProc(HWND hwnd,
        }
        return; // Not this window so just return.
 
+     case ID_EVENT_SYSTIMER_FLASHWIN:
+       {
+          FLASHWINFO fwi =
+            {sizeof(FLASHWINFO),
+             UserHMGetHandle(pWnd),
+             FLASHW_SYSTIMER,0,0};
+
+          IntFlashWindowEx(pWnd, &fwi);
+       }
+       return;
+
      default:
-       ERR( "System Timer Proc invalid id %d!\n", idEvent );
+       ERR("System Timer Proc invalid id %u!\n", idEvent);
        break;
   }
   IntKillTimer(pWnd, idEvent, TRUE);
@@ -386,14 +395,13 @@ FASTCALL
 PostTimerMessages(PWND Window)
 {
   PLIST_ENTRY pLE;
-  PUSER_MESSAGE_QUEUE ThreadQueue;
   MSG Msg;
   PTHREADINFO pti;
   BOOL Hit = FALSE;
   PTIMER pTmr;
+  LARGE_INTEGER TickCount;
 
   pti = PsGetCurrentThreadWin32Thread();
-  ThreadQueue = pti->MessageQueue;
 
   TimerEnterExclusive();
   pLE = TimersListHead.Flink;
@@ -404,14 +412,19 @@ PostTimerMessages(PWND Window)
           (pTmr->pti == pti) &&
           ((pTmr->pWnd == Window) || (Window == NULL)) )
         {
+           KeQueryTickCount(&TickCount);
+
            Msg.hwnd    = (pTmr->pWnd) ? pTmr->pWnd->head.h : 0;
            Msg.message = (pTmr->flags & TMRF_SYSTEM) ? WM_SYSTIMER : WM_TIMER;
            Msg.wParam  = (WPARAM) pTmr->nID;
            Msg.lParam  = (LPARAM) pTmr->pfn;
+           Msg.time    = MsqCalculateMessageTime(&TickCount);
+           // Fix all wine win:test_GetMessagePos WM_TIMER tests. See CORE-10867.
+           Msg.pt      = gpsi->ptCursor;
 
-           MsqPostMessage(ThreadQueue, &Msg, FALSE, QS_TIMER, 0);
+           MsqPostMessage(pti, &Msg, FALSE, (QS_POSTMESSAGE|QS_ALLPOSTMESSAGE), 0, 0);
            pTmr->flags &= ~TMRF_READY;
-           pti->cTimersReady++;
+           ClearMsgBitsMask(pti, QS_TIMER);
            Hit = TRUE;
            // Now move this entry to the end of the list so it will not be
            // called again in the next msg loop.
@@ -482,10 +495,11 @@ ProcessTimers(VOID)
              {
                 pTmr->flags |= TMRF_READY; // Set timer ready to be ran.
                 // Set thread message queue for this timer.
-                if (pTmr->pti->MessageQueue)
+                if (pTmr->pti)
                 {  // Wakeup thread
-                   ASSERT(pTmr->pti->MessageQueue->NewMessages != NULL);
-                   KeSetEvent(pTmr->pti->MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE);
+                   pTmr->pti->cTimersReady++;
+                   ASSERT(pTmr->pti->pEventQueueServer != NULL);
+                   MsqWakeQueue(pTmr->pti, QS_TIMER, TRUE);
                 }
              }
           }
@@ -515,7 +529,7 @@ DestroyTimersForWindow(PTHREADINFO pti, PWND Window)
    PTIMER pTmr;
    BOOL TimersRemoved = FALSE;
 
-   if ((Window == NULL))
+   if (Window == NULL)
       return FALSE;
 
    TimerEnterExclusive();
@@ -563,8 +577,8 @@ BOOL FASTCALL
 IntKillTimer(PWND Window, UINT_PTR IDEvent, BOOL SystemTimer)
 {
    PTIMER pTmr = NULL;
-   TRACE("IntKillTimer Window %x id %p systemtimer %s\n",
-          Window, IDEvent, SystemTimer ? "TRUE" : "FALSE");
+   TRACE("IntKillTimer Window %p id %uI systemtimer %s\n",
+         Window, IDEvent, SystemTimer ? "TRUE" : "FALSE");
 
    TimerEnterExclusive();
    pTmr = FindTimer(Window, IDEvent, SystemTimer ? TMRF_SYSTEM : 0);
@@ -594,7 +608,7 @@ InitTimerImpl(VOID)
 
    ExInitializeFastMutex(Mutex);
 
-   BitmapBytes = ROUND_UP(NUM_WINDOW_LESS_TIMERS, sizeof(ULONG) * 8) / 8;
+   BitmapBytes = ALIGN_UP_BY(NUM_WINDOW_LESS_TIMERS, sizeof(ULONG) * 8) / 8;
    WindowLessTimersBitMapBuffer = ExAllocatePoolWithTag(NonPagedPool, BitmapBytes, TAG_TIMERBMP);
    if (WindowLessTimersBitMapBuffer == NULL)
    {
@@ -635,7 +649,7 @@ NtUserSetTimer
    RETURN(IntSetTimer(Window, nIDEvent, uElapse, lpTimerFunc, TMRF_TIFROMWND));
 
 CLEANUP:
-   TRACE("Leave NtUserSetTimer, ret=%i\n", _ret_);
+   TRACE("Leave NtUserSetTimer, ret=%u\n", _ret_);
 
    END_CLEANUP;
 }
@@ -681,15 +695,13 @@ NtUserSetSystemTimer(
    RETURN(IntSetTimer(UserGetWindowObject(hWnd), nIDEvent, uElapse, NULL, TMRF_SYSTEM));
 
 CLEANUP:
-   TRACE("Leave NtUserSetSystemTimer, ret=%i\n", _ret_);
+   TRACE("Leave NtUserSetSystemTimer, ret=%u\n", _ret_);
    END_CLEANUP;
 }
 
 BOOL
 APIENTRY
 NtUserValidateTimerCallback(
-    HWND hWnd,
-    WPARAM wParam,
     LPARAM lParam)
 {
   BOOL Ret = FALSE;