make window parent a pointer + fix usage
authorGunnar Dalsnes <hardon@online.no>
Tue, 6 Sep 2005 14:09:22 +0000 (14:09 +0000)
committerGunnar Dalsnes <hardon@online.no>
Tue, 6 Sep 2005 14:09:22 +0000 (14:09 +0000)
svn path=/trunk/; revision=17697

reactos/subsys/win32k/include/window.h
reactos/subsys/win32k/ntuser/focus.c
reactos/subsys/win32k/ntuser/object.c
reactos/subsys/win32k/ntuser/painting.c
reactos/subsys/win32k/ntuser/window.c
reactos/subsys/win32k/ntuser/winpos.c

index e931a9c..da37f3c 100644 (file)
@@ -72,9 +72,9 @@ typedef struct _WINDOW_OBJECT
   /* 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.*/
index f99292f..98515c7 100644 (file)
@@ -129,7 +129,7 @@ IntFindChildWindowToOwner(PWINDOW_OBJECT Root, PWINDOW_OBJECT Owner)
 
   for(Child = Root->FirstChild; Child; Child = Child->NextSibling)
   {
-    OwnerWnd = IntGetWindowObject(Child->Owner);
+    OwnerWnd = IntGetWindowObject(Child->hOwner);
     if(!OwnerWnd)
       continue;
 
index 9d5b06f..88e4d51 100644 (file)
@@ -52,6 +52,8 @@ ObmpPerformRetentionChecks(PUSER_OBJECT_HEADER ObjectHeader)
     {
       DPRINT1("ObjectHeader 0x%X has invalid reference count (%d)\n",
               ObjectHeader, ObjectHeader->RefCount);
+          
+          ASSERT(FALSE);
     }
 
   if (ObjectHeader->HandleCount < 0)
index ba4c75c..2c5d0f2 100644 (file)
@@ -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 @@ IntValidateParent(PWINDOW_OBJECT Child, HRGN ValidRegion)
             NtGdiOffsetRgn(ValidRegion, -OffsetX, -OffsetY);
          }
       }
-      OldWindow = ParentWindow;
-      ParentWindow = IntGetParentObject(ParentWindow);
-      IntReleaseWindowObject(OldWindow);
+
+      ParentWindow = ParentWindow->Parent;
    }
 }
 
index 2c22052..a11cef7 100644 (file)
@@ -147,13 +147,17 @@ IntGetParent(PWINDOW_OBJECT Wnd)
 
   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 @@ IntGetOwner(PWINDOW_OBJECT Wnd)
 {
   HWND hWnd;
 
-  hWnd = Wnd->Owner;
+  hWnd = Wnd->hOwner;
 
   return IntGetWindowObject(hWnd);
 }
@@ -172,10 +176,11 @@ IntGetOwner(PWINDOW_OBJECT Wnd)
 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 @@ IntGetSystemMenu(PWINDOW_OBJECT Window, BOOL bRevert, BOOL RetMenu)
 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 @@ IntIsChildWindow(HWND Parent, HWND Child)
   {
     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 @@ IntLinkWindow(
 {
   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 @@ IntSetOwner(HWND hWnd, HWND hWndNewOwner)
   if(!Wnd)
     return NULL;
 
-  WndOldOwner = IntGetWindowObject(Wnd->Owner);
+  WndOldOwner = IntGetWindowObject(Wnd->hOwner);
   if (WndOldOwner)
   {
      ret = WndOldOwner->hSelf;
@@ -908,11 +902,11 @@ IntSetOwner(HWND hWnd, HWND hWndNewOwner)
 
   if((WndNewOwner = IntGetWindowObject(hWndNewOwner)))
   {
-    Wnd->Owner = hWndNewOwner;
+    Wnd->hOwner = hWndNewOwner;
     IntReleaseWindowObject(WndNewOwner);
   }
   else
-    Wnd->Owner = NULL;
+    Wnd->hOwner = NULL;
 
   IntReleaseWindowObject(Wnd);
   return ret;
@@ -1048,12 +1042,7 @@ IntSetSystemMenu(PWINDOW_OBJECT Window, PMENU_OBJECT Menu)
 VOID FASTCALL
 IntUnlinkWindow(PWINDOW_OBJECT Wnd)
 {
-  PWINDOW_OBJECT WndParent;
-
-  if((WndParent = IntGetWindowObject(Wnd->Parent)))
-  {
-
-  }
+  PWINDOW_OBJECT WndParent = Wnd->Parent;
 
   if (Wnd->NextSibling) Wnd->NextSibling->PrevSibling = Wnd->PrevSibling;
   else if (WndParent && WndParent->LastChild == Wnd) WndParent->LastChild = Wnd->PrevSibling;
@@ -1061,10 +1050,6 @@ IntUnlinkWindow(PWINDOW_OBJECT Wnd)
   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 @@ IntAnyPopup(VOID)
 
   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 @@ co_IntCreateWindowEx(DWORD dwExStyle,
     }
   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 @@ BOOLEAN FASTCALL co_UserDestroyWindow(PWINDOW_OBJECT Window)
                  Child = IntGetWindowObject(*ChildHandle);
                  if (Child == NULL)
                    continue;
-                 if (Child->Owner != Window->hSelf)
+                 if (Child->hOwner != Window->hSelf)
                    {
                      IntReleaseWindowObject(Child);
                      continue;
@@ -2206,9 +2191,9 @@ BOOLEAN FASTCALL co_UserDestroyWindow(PWINDOW_OBJECT Window)
                      continue;
                    }
 
-                 if (Child->Owner != NULL)
+                 if (Child->hOwner != NULL)
                    {
-                     Child->Owner = NULL;
+                     Child->hOwner = NULL;
                    }
 
                  IntReleaseWindowObject(Child);
@@ -3214,27 +3199,23 @@ UserGetWindow(HWND hWnd, UINT Relationship)
    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 @@ UserGetWindow(HWND hWnd, UINT Relationship)
          break;
 
       case GW_OWNER:
-         if((Parent = IntGetWindowObject(Window->Owner)))
+         if((Parent = IntGetWindowObject(Window->hOwner)))
          {
            hWndResult = Parent->hSelf;
            IntReleaseWindowObject(Parent);
@@ -3261,8 +3242,6 @@ UserGetWindow(HWND hWnd, UINT Relationship)
          break;
    }
 
-   IntReleaseWindowObject(Window);
-
    return hWndResult;
 }
 
@@ -3365,14 +3344,13 @@ UserGetWindowLong(HWND hWnd, DWORD Index, BOOL Ansi)
             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;
 
index 175ae5d..2cb2fac 100644 (file)
@@ -254,14 +254,13 @@ WinPosInitInternalPos(PWINDOW_OBJECT Window, POINT *pt, PRECT RestoreRect)
       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 @@ co_WinPosDoNCCALCSize(PWINDOW_OBJECT Window, PWINDOWPOS WinPos,
       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 @@ co_WinPosDoNCCALCSize(PWINDOW_OBJECT Window, PWINDOWPOS WinPos,
        {
           WinPos->flags &= ~SWP_NOCLIENTSIZE;
        }
-         if(Parent)
-           IntReleaseWindowObject(Parent);
     }
   else
     {
@@ -593,14 +590,13 @@ co_WinPosDoWinPosChanging(PWINDOW_OBJECT Window,
       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 @@ WinPosFixupFlags(WINDOWPOS *WinPos, PWINDOW_OBJECT Window)
           && 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 @@ co_WinPosShowWindow(HWND Wnd, INT Cmd)
       if (Wnd == IntGetThreadFocusWindow() ||
           IntIsChildWindow(Wnd, IntGetThreadFocusWindow()))
         {
-          UserSetFocus(Window->Parent);
+          UserSetFocus(Window->Parent->hSelf);
         }
 
       if (!(Window->Parent))