make window parent a pointer + fix usage
Modified: trunk/reactos/subsys/win32k/include/window.h
Modified: trunk/reactos/subsys/win32k/ntuser/focus.c
Modified: trunk/reactos/subsys/win32k/ntuser/object.c
Modified: trunk/reactos/subsys/win32k/ntuser/painting.c
Modified: trunk/reactos/subsys/win32k/ntuser/window.c
Modified: trunk/reactos/subsys/win32k/ntuser/winpos.c

Modified: trunk/reactos/subsys/win32k/include/window.h
--- trunk/reactos/subsys/win32k/include/window.h	2005-09-06 13:36:04 UTC (rev 17696)
+++ trunk/reactos/subsys/win32k/include/window.h	2005-09-06 14:09:22 UTC (rev 17697)
@@ -72,9 +72,9 @@
   /* Entry in the list of thread windows. */
   LIST_ENTRY ThreadListEntry;
   /* Handle to the parent window. */
-  HANDLE Parent;
+  struct _WINDOW_OBJECT* Parent;
   /* Handle to the owner window. */
-  HANDLE Owner;
+  HWND hOwner;
   /* DC Entries (DCE) */
   PDCE Dce;
   /* Property list head.*/

Modified: trunk/reactos/subsys/win32k/ntuser/focus.c
--- trunk/reactos/subsys/win32k/ntuser/focus.c	2005-09-06 13:36:04 UTC (rev 17696)
+++ trunk/reactos/subsys/win32k/ntuser/focus.c	2005-09-06 14:09:22 UTC (rev 17697)
@@ -129,7 +129,7 @@
 
   for(Child = Root->FirstChild; Child; Child = Child->NextSibling)
   {
-    OwnerWnd = IntGetWindowObject(Child->Owner);
+    OwnerWnd = IntGetWindowObject(Child->hOwner);
     if(!OwnerWnd)
       continue;
 

Modified: trunk/reactos/subsys/win32k/ntuser/object.c
--- trunk/reactos/subsys/win32k/ntuser/object.c	2005-09-06 13:36:04 UTC (rev 17696)
+++ trunk/reactos/subsys/win32k/ntuser/object.c	2005-09-06 14:09:22 UTC (rev 17697)
@@ -52,6 +52,8 @@
     {
       DPRINT1("ObjectHeader 0x%X has invalid reference count (%d)\n",
 	       ObjectHeader, ObjectHeader->RefCount);
+          
+          ASSERT(FALSE);
     }
 
   if (ObjectHeader->HandleCount < 0)

Modified: trunk/reactos/subsys/win32k/ntuser/painting.c
--- trunk/reactos/subsys/win32k/ntuser/painting.c	2005-09-06 13:36:04 UTC (rev 17696)
+++ trunk/reactos/subsys/win32k/ntuser/painting.c	2005-09-06 14:09:22 UTC (rev 17697)
@@ -42,7 +42,7 @@
 VOID FASTCALL
 IntValidateParent(PWINDOW_OBJECT Child, HRGN ValidRegion)
 {
-   PWINDOW_OBJECT ParentWindow = IntGetParentObject(Child), OldWindow;
+   PWINDOW_OBJECT ParentWindow = Child->Parent;
 
    while (ParentWindow)
    {
@@ -65,9 +65,8 @@
             NtGdiOffsetRgn(ValidRegion, -OffsetX, -OffsetY);
          }
       }
-      OldWindow = ParentWindow;
-      ParentWindow = IntGetParentObject(ParentWindow);
-      IntReleaseWindowObject(OldWindow);
+
+      ParentWindow = ParentWindow->Parent;
    }
 }
 

Modified: trunk/reactos/subsys/win32k/ntuser/window.c
--- trunk/reactos/subsys/win32k/ntuser/window.c	2005-09-06 13:36:04 UTC (rev 17696)
+++ trunk/reactos/subsys/win32k/ntuser/window.c	2005-09-06 14:09:22 UTC (rev 17697)
@@ -147,13 +147,17 @@
 
   if (Wnd->Style & WS_POPUP)
   {
-    hWnd = Wnd->Owner;
+    hWnd = Wnd->hOwner;
     return IntGetWindowObject(hWnd);
   }
   else if (Wnd->Style & WS_CHILD)
   {
-    hWnd = Wnd->Parent;
-    return IntGetWindowObject(hWnd);
+    PWINDOW_OBJECT par;
+    
+    par = Wnd->Parent;
+    if (par) IntReferenceWindowObject(par);
+    return par;
+    //return IntGetWindowObject(hWnd);
   }
 
   return NULL;
@@ -164,7 +168,7 @@
 {
   HWND hWnd;
 
-  hWnd = Wnd->Owner;
+  hWnd = Wnd->hOwner;
 
   return IntGetWindowObject(hWnd);
 }
@@ -172,10 +176,11 @@
 PWINDOW_OBJECT FASTCALL
 IntGetParentObject(PWINDOW_OBJECT Wnd)
 {
-  HWND hParent;
-
-  hParent = Wnd->Parent;
-  return IntGetWindowObject(hParent);
+  PWINDOW_OBJECT par;
+  
+  par = Wnd->Parent;
+  if (par) IntReferenceWindowObject(par);
+  return par;
 }
 
 /*
@@ -759,9 +764,9 @@
 BOOL FASTCALL
 IntIsChildWindow(HWND Parent, HWND Child)
 {
-  PWINDOW_OBJECT BaseWindow, Window, Old;
+  PWINDOW_OBJECT BaseWindow, Window;
 
-  if(!(BaseWindow = IntGetWindowObject(Child)))
+  if(!(BaseWindow = UserGetWindowObjectNoRef(Child)))
   {
     return FALSE;
   }
@@ -771,24 +776,16 @@
   {
     if (Window->hSelf == Parent)
     {
-      if(Window != BaseWindow)
-        IntReleaseWindowObject(Window);
-      IntReleaseWindowObject(BaseWindow);
       return(TRUE);
     }
     if(!(Window->Style & WS_CHILD))
     {
-      if(Window != BaseWindow)
-        IntReleaseWindowObject(Window);
       break;
     }
-    Old = Window;
-    Window = IntGetParentObject(Window);
-    if(Old != BaseWindow)
-      IntReleaseWindowObject(Old);
+
+    Window = Window->Parent;
   }
 
-  IntReleaseWindowObject(BaseWindow);
   return(FALSE);
 }
 
@@ -849,37 +846,34 @@
 {
   PWINDOW_OBJECT Parent;
 
-  Wnd->Parent = WndParent->hSelf;
+  Wnd->Parent = WndParent;
   if ((Wnd->PrevSibling = WndPrevSibling))
   {
     /* link after WndPrevSibling */
     if ((Wnd->NextSibling = WndPrevSibling->NextSibling))
       Wnd->NextSibling->PrevSibling = Wnd;
-    else if ((Parent = IntGetWindowObject(Wnd->Parent)))
+    else if ((Parent = Wnd->Parent))
     {
       if(Parent->LastChild == WndPrevSibling)
         Parent->LastChild = Wnd;
-      IntReleaseWindowObject(Parent);
     }
     Wnd->PrevSibling->NextSibling = Wnd;
   }
   else
   {
     /* link at top */
-    Parent = IntGetWindowObject(Wnd->Parent);
+    Parent = Wnd->Parent;
     if ((Wnd->NextSibling = WndParent->FirstChild))
       Wnd->NextSibling->PrevSibling = Wnd;
     else if (Parent)
     {
       Parent->LastChild = Wnd;
       Parent->FirstChild = Wnd;
-      IntReleaseWindowObject(Parent);
       return;
     }
     if(Parent)
     {
       Parent->FirstChild = Wnd;
-      IntReleaseWindowObject(Parent);
     }
   }
 
@@ -895,7 +889,7 @@
   if(!Wnd)
     return NULL;
 
-  WndOldOwner = IntGetWindowObject(Wnd->Owner);
+  WndOldOwner = IntGetWindowObject(Wnd->hOwner);
   if (WndOldOwner)
   {
      ret = WndOldOwner->hSelf;
@@ -908,11 +902,11 @@
 
   if((WndNewOwner = IntGetWindowObject(hWndNewOwner)))
   {
-    Wnd->Owner = hWndNewOwner;
+    Wnd->hOwner = hWndNewOwner;
     IntReleaseWindowObject(WndNewOwner);
   }
   else
-    Wnd->Owner = NULL;
+    Wnd->hOwner = NULL;
 
   IntReleaseWindowObject(Wnd);
   return ret;
@@ -1048,23 +1042,14 @@
 VOID FASTCALL
 IntUnlinkWindow(PWINDOW_OBJECT Wnd)
 {
-  PWINDOW_OBJECT WndParent;
+  PWINDOW_OBJECT WndParent = Wnd->Parent;
 
-  if((WndParent = IntGetWindowObject(Wnd->Parent)))
-  {
-
-  }
-
   if (Wnd->NextSibling) Wnd->NextSibling->PrevSibling = Wnd->PrevSibling;
   else if (WndParent && WndParent->LastChild == Wnd) WndParent->LastChild = Wnd->PrevSibling;
 
   if (Wnd->PrevSibling) Wnd->PrevSibling->NextSibling = Wnd->NextSibling;
   else if (WndParent && WndParent->FirstChild == Wnd) WndParent->FirstChild = Wnd->NextSibling;
 
-  if(WndParent)
-  {
-    IntReleaseWindowObject(WndParent);
-  }
   Wnd->PrevSibling = Wnd->NextSibling = Wnd->Parent = NULL;
 }
 
@@ -1081,7 +1066,7 @@
 
   for(Child = Window->FirstChild; Child; Child = Child->NextSibling)
   {
-    if(Child->Owner && Child->Style & WS_VISIBLE)
+    if(Child->hOwner && Child->Style & WS_VISIBLE)
     {
       /*
        * The desktop has a popup window if one of them has
@@ -1548,14 +1533,14 @@
     }
   Window->MessageQueue = PsGetWin32Thread()->MessageQueue;
   IntReferenceMessageQueue(Window->MessageQueue);
-  Window->Parent = (ParentWindow ? ParentWindow->hSelf : NULL);
+  Window->Parent = ParentWindow;
   if((OwnerWindow = IntGetWindowObject(OwnerWindowHandle)))
   {
-    Window->Owner = OwnerWindowHandle;
+    Window->hOwner = OwnerWindowHandle;
     IntReleaseWindowObject(OwnerWindow);
     HasOwner = TRUE;
   } else {
-    Window->Owner = NULL;
+    Window->hOwner = NULL;
     HasOwner = FALSE;
   }
   Window->UserData = 0;
@@ -2192,7 +2177,7 @@
 		  Child = IntGetWindowObject(*ChildHandle);
 		  if (Child == NULL)
 		    continue;
-		  if (Child->Owner != Window->hSelf)
+		  if (Child->hOwner != Window->hSelf)
 		    {
 		      IntReleaseWindowObject(Child);
 		      continue;
@@ -2206,9 +2191,9 @@
 		      continue;
 		    }
 
-		  if (Child->Owner != NULL)
+		  if (Child->hOwner != NULL)
 		    {
-		      Child->Owner = NULL;
+		      Child->hOwner = NULL;
 		    }
 
 		  IntReleaseWindowObject(Child);
@@ -3214,27 +3199,23 @@
    PWINDOW_OBJECT Parent, Window;
    HWND hWndResult = NULL;
 
-   if (!(Window = IntGetWindowObject(hWnd))) return NULL;
+   if (!(Window = UserGetWindowObjectNoRef(hWnd))) return NULL;
 
    switch (Relationship)
    {
       case GW_HWNDFIRST:
-         if((Parent = IntGetParentObject(Window)))
+         if((Parent = Window->Parent))
          {
            if (Parent->FirstChild)
               hWndResult = Parent->FirstChild->hSelf;
-
-           IntReleaseWindowObject(Parent);
          }
          break;
 
       case GW_HWNDLAST:
-         if((Parent = IntGetParentObject(Window)))
+         if((Parent = Window->Parent))
          {
            if (Parent->LastChild)
               hWndResult = Parent->LastChild->hSelf;
-
-           IntReleaseWindowObject(Parent);
          }
          break;
 
@@ -3249,7 +3230,7 @@
          break;
 
       case GW_OWNER:
-         if((Parent = IntGetWindowObject(Window->Owner)))
+         if((Parent = IntGetWindowObject(Window->hOwner)))
          {
            hWndResult = Parent->hSelf;
            IntReleaseWindowObject(Parent);
@@ -3261,8 +3242,6 @@
          break;
    }
 
-   IntReleaseWindowObject(Window);
-
    return hWndResult;
 }
 
@@ -3365,14 +3344,13 @@
             break;
 
          case GWL_HWNDPARENT:
-            Parent = IntGetWindowObject(Window->Parent);
+            Parent = Window->Parent;
             if(Parent)
             {
               if (Parent && Parent->hSelf == IntGetDesktopWindow())
                  Result = (LONG) UserGetWindow(Window->hSelf, GW_OWNER);
               else
                  Result = (LONG) Parent->hSelf;
-              IntReleaseWindowObject(Parent);
             }
             break;
 

Modified: trunk/reactos/subsys/win32k/ntuser/winpos.c
--- trunk/reactos/subsys/win32k/ntuser/winpos.c	2005-09-06 13:36:04 UTC (rev 17696)
+++ trunk/reactos/subsys/win32k/ntuser/winpos.c	2005-09-06 14:09:22 UTC (rev 17697)
@@ -254,14 +254,13 @@
       RECT WorkArea;
       PDESKTOP_OBJECT Desktop = PsGetWin32Thread()->Desktop; /* Or rather get it from the window? */
 
-      Parent = IntGetParentObject(Window);
+      Parent = Window->Parent;
       if(Parent)
       {
         if(IntIsDesktopWindow(Parent))
           IntGetDesktopWorkArea(Desktop, &WorkArea);
         else
           WorkArea = Parent->ClientRect;
-        IntReleaseWindowObject(Parent);
       }
       else
         IntGetDesktopWorkArea(Desktop, &WorkArea);
@@ -507,7 +506,7 @@
       params.rgrc[0] = *WindowRect;
       params.rgrc[1] = Window->WindowRect;
       params.rgrc[2] = Window->ClientRect;
-      Parent = IntGetParentObject(Window);
+      Parent = Window->Parent;
       if (0 != (Window->Style & WS_CHILD) && Parent)
 	{
 	  IntGdiOffsetRect(&(params.rgrc[0]), - Parent->ClientRect.left,
@@ -550,8 +549,6 @@
 	{
           WinPos->flags &= ~SWP_NOCLIENTSIZE;
 	}
-	  if(Parent)
-	    IntReleaseWindowObject(Parent);
     }
   else
     {
@@ -593,14 +590,13 @@
       PWINDOW_OBJECT Parent;
       X = WinPos->x;
       Y = WinPos->y;
-      Parent = IntGetParentObject(Window);
+      Parent = Window->Parent;
       if ((0 != (Window->Style & WS_CHILD)) && Parent)
 	{
 	  X += Parent->ClientRect.left;
 	  Y += Parent->ClientRect.top;
 	}
-	  if(Parent)
-	    IntReleaseWindowObject(Parent);
+
       WindowRect->left = X;
       WindowRect->top = Y;
       WindowRect->right += X - Window->WindowRect.left;
@@ -805,18 +801,14 @@
           && HWND_NOTOPMOST != WinPos->hwndInsertAfter
           && HWND_BOTTOM != WinPos->hwndInsertAfter)
       {
-         PWINDOW_OBJECT Parent = IntGetParentObject(Window);
+         PWINDOW_OBJECT Parent = Window->Parent;
          if (UserGetAncestor(WinPos->hwndInsertAfter, GA_PARENT) !=
              (Parent ? Parent->hSelf : NULL))
          {
-            if(Parent)
-              IntReleaseWindowObject(Parent);
             return FALSE;
          }
          else
          {
-            if(Parent)
-              IntReleaseWindowObject(Parent);
             /*
              * We don't need to change the Z order of hwnd if it's already
              * inserted after hwndInsertAfter or when inserting hwnd after
@@ -1382,7 +1374,7 @@
       if (Wnd == IntGetThreadFocusWindow() ||
           IntIsChildWindow(Wnd, IntGetThreadFocusWindow()))
         {
-          UserSetFocus(Window->Parent);
+          UserSetFocus(Window->Parent->hSelf);
         }
 
       if (!(Window->Parent))