[WIN32K]
[reactos.git] / reactos / subsystems / win32 / win32k / ntuser / timer.c
index 1983073..1c34ab7 100644 (file)
@@ -1,21 +1,3 @@
-/*
- *  ReactOS W32 Subsystem
- *  Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
 /*
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
@@ -29,7 +11,7 @@
 
 /* INCLUDES ******************************************************************/
 
-#include <w32k.h>
+#include <win32k.h>
 
 #define NDEBUG
 #include <debug.h>
@@ -67,13 +49,13 @@ CreateTimer(VOID)
 
   if (!FirstpTmr)
   {
-      FirstpTmr = UserCreateObject(gHandleTable, &Handle, otTimer, sizeof(TIMER));
+      FirstpTmr = UserCreateObject(gHandleTable, NULL, &Handle, otTimer, sizeof(TIMER));
       if (FirstpTmr) InitializeListHead(&FirstpTmr->ptmrList);
       Ret = FirstpTmr;
   }
   else
   {
-      Ret = UserCreateObject(gHandleTable, &Handle, otTimer, sizeof(TIMER));
+      Ret = UserCreateObject(gHandleTable, NULL, &Handle, otTimer, sizeof(TIMER));
       if (Ret) InsertTailList(&FirstpTmr->ptmrList, &Ret->ptmrList);
   } 
   return Ret;
@@ -87,7 +69,7 @@ RemoveTimer(PTIMER pTmr)
   if (pTmr)
   {
      RemoveEntryList(&pTmr->ptmrList);
-     UserDeleteObject( USER_BODY_TO_HEADER(pTmr)->hSelf, otTimer);
+     UserDeleteObject( UserHMGetHandle(pTmr), otTimer);
      return TRUE;
   }
   return FALSE;
@@ -100,6 +82,7 @@ FindTimer(PWINDOW_OBJECT Window,
           UINT flags,
           BOOL Distroy)
 {
+  PLIST_ENTRY pLE;
   PTIMER pTmr = FirstpTmr;
   KeEnterCriticalRegion();
   do
@@ -118,7 +101,8 @@ FindTimer(PWINDOW_OBJECT Window,
        break;
     }
 
-    pTmr = (PTIMER)pTmr->ptmrList.Flink;
+    pLE = pTmr->ptmrList.Flink;
+    pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
   } while (pTmr != FirstpTmr);
   KeLeaveCriticalRegion();
 
@@ -129,6 +113,7 @@ PTIMER
 FASTCALL
 FindSystemTimer(PMSG pMsg)
 {
+  PLIST_ENTRY pLE;
   PTIMER pTmr = FirstpTmr;
   KeEnterCriticalRegion();
   do
@@ -139,7 +124,8 @@ FindSystemTimer(PMSG pMsg)
          (pTmr->flags & TMRF_SYSTEM) )
        break;
 
-    pTmr = (PTIMER)pTmr->ptmrList.Flink;
+    pLE = pTmr->ptmrList.Flink;
+    pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);    
   } while (pTmr != FirstpTmr);
   KeLeaveCriticalRegion();
 
@@ -153,6 +139,7 @@ ValidateTimerCallback(PTHREADINFO pti,
                       WPARAM wParam,
                       LPARAM lParam)
 {
+  PLIST_ENTRY pLE;
   PTIMER pTmr = FirstpTmr;
 
   if (!pTmr) return FALSE;
@@ -162,10 +149,11 @@ ValidateTimerCallback(PTHREADINFO pti,
   {
     if ( (lParam == (LPARAM)pTmr->pfn) &&
          (pTmr->flags & (TMRF_SYSTEM|TMRF_RIT)) &&
-         (pTmr->pti->ThreadInfo->ppi == pti->ThreadInfo->ppi) )
+         (pTmr->pti->ppi == pti->ppi) )
        break;
 
-    pTmr = (PTIMER)pTmr->ptmrList.Flink;
+    pLE = pTmr->ptmrList.Flink;
+    pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
   } while (pTmr != FirstpTmr);
   KeLeaveCriticalRegion();
 
@@ -216,7 +204,7 @@ InternalSetTimer( PWINDOW_OBJECT Window,
      if (!pTmr) return 0;
 
     if (Window && (Type & TMRF_TIFROMWND))
-       pTmr->pti = Window->OwnerThread->Tcb.Win32Thread;
+       pTmr->pti = Window->pti->pEThread->Tcb.Win32Thread;
     else
     {
        if (Type & TMRF_RIT)
@@ -265,12 +253,12 @@ StartTheTimers(VOID)
 
 UINT_PTR
 FASTCALL
-SetSystemTimer( PWINDOW_OBJECT Window,
+SystemTimerSet( PWINDOW_OBJECT Window,
                 UINT_PTR nIDEvent,
                 UINT uElapse,
                 TIMERPROC lpTimerFunc) 
 {
-  if (Window && Window->OwnerThread->ThreadsProcess != PsGetCurrentProcess())
+  if (Window && Window->pti->pEThread->ThreadsProcess != PsGetCurrentProcess())
   {
      SetLastWin32Error(ERROR_ACCESS_DENIED);
      return 0;
@@ -280,21 +268,22 @@ SetSystemTimer( PWINDOW_OBJECT Window,
 
 BOOL
 FASTCALL
-PostTimerMessages(HWND hWnd)
+PostTimerMessages(PWINDOW_OBJECT Window)
 {
+  PLIST_ENTRY pLE;
   PUSER_MESSAGE_QUEUE ThreadQueue;
   MSG Msg;
   PTHREADINFO pti;
-  PWINDOW_OBJECT pWnd = NULL;
   BOOL Hit = FALSE;
   PTIMER pTmr = FirstpTmr;
 
   if (!pTmr) return FALSE;
 
-  if (hWnd)
+  ASSERT(Window);
+
+  if (Window && ((ULONG_PTR)Window != 1))
   {
-     pWnd = UserGetWindowObject(hWnd);
-     if (!pWnd || !pWnd->Wnd) return FALSE;
+     if (!Window->Wnd) return FALSE;
   }
 
   pti = PsGetCurrentThreadWin32Thread();
@@ -305,9 +294,10 @@ PostTimerMessages(HWND hWnd)
   {
      if ( (pTmr->flags & TMRF_READY) &&
           (pTmr->pti == pti) &&
-          (pTmr->pWnd == pWnd))
+          (pTmr->pWnd == Window))
         {
-           Msg.hwnd    = hWnd;
+           ASSERT((ULONG_PTR)Window != 1);
+           Msg.hwnd    = Window->hSelf;
            Msg.message = (pTmr->flags & TMRF_SYSTEM) ? WM_SYSTIMER : WM_TIMER;
            Msg.wParam  = (WPARAM) pTmr->nID;
            Msg.lParam  = (LPARAM) pTmr->pfn;
@@ -318,7 +308,8 @@ PostTimerMessages(HWND hWnd)
            Hit = TRUE;
         }
 
-     pTmr = (PTIMER)pTmr->ptmrList.Flink;
+     pLE = pTmr->ptmrList.Flink;
+     pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
   } while (pTmr != FirstpTmr);
   KeLeaveCriticalRegion();
 
@@ -331,6 +322,7 @@ ProcessTimers(VOID)
 {
   LARGE_INTEGER TickCount, DueTime;
   LONG Time;
+  PLIST_ENTRY pLE;
   PTIMER pTmr = FirstpTmr;
 
   if (!pTmr) return;
@@ -346,7 +338,8 @@ ProcessTimers(VOID)
   {
     if (pTmr->flags & TMRF_WAITING)
     {
-       pTmr = (PTIMER)pTmr->ptmrList.Flink;
+       pLE = pTmr->ptmrList.Flink;
+       pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
        continue;
     }
 
@@ -382,7 +375,8 @@ ProcessTimers(VOID)
        else
           pTmr->cmsCountdown -= Time - TimeLast;
     }
-    pTmr = (PTIMER)pTmr->ptmrList.Flink;
+    pLE = pTmr->ptmrList.Flink;
+    pTmr = CONTAINING_RECORD(pLE, TIMER, ptmrList);
   } while (pTmr != FirstpTmr);
 
   // Restart the timer thread!
@@ -438,7 +432,7 @@ IntSetTimer(HWND Wnd, UINT_PTR IDEvent, UINT Elapse, TIMERPROC TimerFunc, BOOL S
          return 0;
       }
 
-      if (Window->OwnerThread->ThreadsProcess != PsGetCurrentProcess())
+      if (Window->pti->pEThread->ThreadsProcess != PsGetCurrentProcess())
       {
          DPRINT1("Trying to set timer for window in another process (shatter attack?)\n");
          SetLastWin32Error(ERROR_ACCESS_DENIED);
@@ -446,7 +440,7 @@ IntSetTimer(HWND Wnd, UINT_PTR IDEvent, UINT Elapse, TIMERPROC TimerFunc, BOOL S
       }
 
       Ret = IDEvent;
-      MessageQueue = Window->MessageQueue;
+      MessageQueue = Window->pti->MessageQueue;
    }
 
 #if 0
@@ -508,7 +502,7 @@ IntKillTimer(HWND Wnd, UINT_PTR IDEvent, BOOL SystemTimer)
                                 IDEvent, SystemTimer ? WM_SYSTIMER : WM_TIMER))
       {
          // Give it another chance to find the timer.
-         if (Window && !( MsqKillTimer(Window->MessageQueue, Wnd,
+         if (Window && !( MsqKillTimer(Window->pti->MessageQueue, Wnd,
                             IDEvent, SystemTimer ? WM_SYSTIMER : WM_TIMER)))
          {
             DPRINT1("Unable to locate timer in message queue for Window.\n");
@@ -535,6 +529,8 @@ IntKillTimer(HWND Wnd, UINT_PTR IDEvent, BOOL SystemTimer)
       ASSERT(RtlAreBitsSet(&WindowLessTimersBitMap, IDEvent - 1, 1));
       RtlClearBits(&WindowLessTimersBitMap, IDEvent - 1, 1);
 
+      HintIndex = IDEvent - 1;
+
       IntUnlockWindowlessTimerBitmap();
    }