make window parent a pointer + fix usage

svn path=/trunk/; revision=17697
This commit is contained in:
Gunnar Dalsnes 2005-09-06 14:09:22 +00:00
parent e51f10ab47
commit a1c7e10fc8
6 changed files with 50 additions and 79 deletions

View file

@ -72,9 +72,9 @@ typedef struct _WINDOW_OBJECT
/* Entry in the list of thread windows. */ /* Entry in the list of thread windows. */
LIST_ENTRY ThreadListEntry; LIST_ENTRY ThreadListEntry;
/* Handle to the parent window. */ /* Handle to the parent window. */
HANDLE Parent; struct _WINDOW_OBJECT* Parent;
/* Handle to the owner window. */ /* Handle to the owner window. */
HANDLE Owner; HWND hOwner;
/* DC Entries (DCE) */ /* DC Entries (DCE) */
PDCE Dce; PDCE Dce;
/* Property list head.*/ /* Property list head.*/

View file

@ -129,7 +129,7 @@ IntFindChildWindowToOwner(PWINDOW_OBJECT Root, PWINDOW_OBJECT Owner)
for(Child = Root->FirstChild; Child; Child = Child->NextSibling) for(Child = Root->FirstChild; Child; Child = Child->NextSibling)
{ {
OwnerWnd = IntGetWindowObject(Child->Owner); OwnerWnd = IntGetWindowObject(Child->hOwner);
if(!OwnerWnd) if(!OwnerWnd)
continue; continue;

View file

@ -52,6 +52,8 @@ ObmpPerformRetentionChecks(PUSER_OBJECT_HEADER ObjectHeader)
{ {
DPRINT1("ObjectHeader 0x%X has invalid reference count (%d)\n", DPRINT1("ObjectHeader 0x%X has invalid reference count (%d)\n",
ObjectHeader, ObjectHeader->RefCount); ObjectHeader, ObjectHeader->RefCount);
ASSERT(FALSE);
} }
if (ObjectHeader->HandleCount < 0) if (ObjectHeader->HandleCount < 0)

View file

@ -42,7 +42,7 @@
VOID FASTCALL VOID FASTCALL
IntValidateParent(PWINDOW_OBJECT Child, HRGN ValidRegion) IntValidateParent(PWINDOW_OBJECT Child, HRGN ValidRegion)
{ {
PWINDOW_OBJECT ParentWindow = IntGetParentObject(Child), OldWindow; PWINDOW_OBJECT ParentWindow = Child->Parent;
while (ParentWindow) while (ParentWindow)
{ {
@ -65,9 +65,8 @@ IntValidateParent(PWINDOW_OBJECT Child, HRGN ValidRegion)
NtGdiOffsetRgn(ValidRegion, -OffsetX, -OffsetY); NtGdiOffsetRgn(ValidRegion, -OffsetX, -OffsetY);
} }
} }
OldWindow = ParentWindow;
ParentWindow = IntGetParentObject(ParentWindow); ParentWindow = ParentWindow->Parent;
IntReleaseWindowObject(OldWindow);
} }
} }

View file

@ -147,13 +147,17 @@ IntGetParent(PWINDOW_OBJECT Wnd)
if (Wnd->Style & WS_POPUP) if (Wnd->Style & WS_POPUP)
{ {
hWnd = Wnd->Owner; hWnd = Wnd->hOwner;
return IntGetWindowObject(hWnd); return IntGetWindowObject(hWnd);
} }
else if (Wnd->Style & WS_CHILD) else if (Wnd->Style & WS_CHILD)
{ {
hWnd = Wnd->Parent; PWINDOW_OBJECT par;
return IntGetWindowObject(hWnd);
par = Wnd->Parent;
if (par) IntReferenceWindowObject(par);
return par;
//return IntGetWindowObject(hWnd);
} }
return NULL; return NULL;
@ -164,7 +168,7 @@ IntGetOwner(PWINDOW_OBJECT Wnd)
{ {
HWND hWnd; HWND hWnd;
hWnd = Wnd->Owner; hWnd = Wnd->hOwner;
return IntGetWindowObject(hWnd); return IntGetWindowObject(hWnd);
} }
@ -172,10 +176,11 @@ IntGetOwner(PWINDOW_OBJECT Wnd)
PWINDOW_OBJECT FASTCALL PWINDOW_OBJECT FASTCALL
IntGetParentObject(PWINDOW_OBJECT Wnd) IntGetParentObject(PWINDOW_OBJECT Wnd)
{ {
HWND hParent; PWINDOW_OBJECT par;
hParent = Wnd->Parent; par = Wnd->Parent;
return IntGetWindowObject(hParent); if (par) IntReferenceWindowObject(par);
return par;
} }
/* /*
@ -759,9 +764,9 @@ IntGetSystemMenu(PWINDOW_OBJECT Window, BOOL bRevert, BOOL RetMenu)
BOOL FASTCALL BOOL FASTCALL
IntIsChildWindow(HWND Parent, HWND Child) IntIsChildWindow(HWND Parent, HWND Child)
{ {
PWINDOW_OBJECT BaseWindow, Window, Old; PWINDOW_OBJECT BaseWindow, Window;
if(!(BaseWindow = IntGetWindowObject(Child))) if(!(BaseWindow = UserGetWindowObjectNoRef(Child)))
{ {
return FALSE; return FALSE;
} }
@ -771,24 +776,16 @@ IntIsChildWindow(HWND Parent, HWND Child)
{ {
if (Window->hSelf == Parent) if (Window->hSelf == Parent)
{ {
if(Window != BaseWindow)
IntReleaseWindowObject(Window);
IntReleaseWindowObject(BaseWindow);
return(TRUE); return(TRUE);
} }
if(!(Window->Style & WS_CHILD)) if(!(Window->Style & WS_CHILD))
{ {
if(Window != BaseWindow)
IntReleaseWindowObject(Window);
break; break;
} }
Old = Window;
Window = IntGetParentObject(Window); Window = Window->Parent;
if(Old != BaseWindow)
IntReleaseWindowObject(Old);
} }
IntReleaseWindowObject(BaseWindow);
return(FALSE); return(FALSE);
} }
@ -849,37 +846,34 @@ IntLinkWindow(
{ {
PWINDOW_OBJECT Parent; PWINDOW_OBJECT Parent;
Wnd->Parent = WndParent->hSelf; Wnd->Parent = WndParent;
if ((Wnd->PrevSibling = WndPrevSibling)) if ((Wnd->PrevSibling = WndPrevSibling))
{ {
/* link after WndPrevSibling */ /* link after WndPrevSibling */
if ((Wnd->NextSibling = WndPrevSibling->NextSibling)) if ((Wnd->NextSibling = WndPrevSibling->NextSibling))
Wnd->NextSibling->PrevSibling = Wnd; Wnd->NextSibling->PrevSibling = Wnd;
else if ((Parent = IntGetWindowObject(Wnd->Parent))) else if ((Parent = Wnd->Parent))
{ {
if(Parent->LastChild == WndPrevSibling) if(Parent->LastChild == WndPrevSibling)
Parent->LastChild = Wnd; Parent->LastChild = Wnd;
IntReleaseWindowObject(Parent);
} }
Wnd->PrevSibling->NextSibling = Wnd; Wnd->PrevSibling->NextSibling = Wnd;
} }
else else
{ {
/* link at top */ /* link at top */
Parent = IntGetWindowObject(Wnd->Parent); Parent = Wnd->Parent;
if ((Wnd->NextSibling = WndParent->FirstChild)) if ((Wnd->NextSibling = WndParent->FirstChild))
Wnd->NextSibling->PrevSibling = Wnd; Wnd->NextSibling->PrevSibling = Wnd;
else if (Parent) else if (Parent)
{ {
Parent->LastChild = Wnd; Parent->LastChild = Wnd;
Parent->FirstChild = Wnd; Parent->FirstChild = Wnd;
IntReleaseWindowObject(Parent);
return; return;
} }
if(Parent) if(Parent)
{ {
Parent->FirstChild = Wnd; Parent->FirstChild = Wnd;
IntReleaseWindowObject(Parent);
} }
} }
@ -895,7 +889,7 @@ IntSetOwner(HWND hWnd, HWND hWndNewOwner)
if(!Wnd) if(!Wnd)
return NULL; return NULL;
WndOldOwner = IntGetWindowObject(Wnd->Owner); WndOldOwner = IntGetWindowObject(Wnd->hOwner);
if (WndOldOwner) if (WndOldOwner)
{ {
ret = WndOldOwner->hSelf; ret = WndOldOwner->hSelf;
@ -908,11 +902,11 @@ IntSetOwner(HWND hWnd, HWND hWndNewOwner)
if((WndNewOwner = IntGetWindowObject(hWndNewOwner))) if((WndNewOwner = IntGetWindowObject(hWndNewOwner)))
{ {
Wnd->Owner = hWndNewOwner; Wnd->hOwner = hWndNewOwner;
IntReleaseWindowObject(WndNewOwner); IntReleaseWindowObject(WndNewOwner);
} }
else else
Wnd->Owner = NULL; Wnd->hOwner = NULL;
IntReleaseWindowObject(Wnd); IntReleaseWindowObject(Wnd);
return ret; return ret;
@ -1048,12 +1042,7 @@ IntSetSystemMenu(PWINDOW_OBJECT Window, PMENU_OBJECT Menu)
VOID FASTCALL VOID FASTCALL
IntUnlinkWindow(PWINDOW_OBJECT Wnd) 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; if (Wnd->NextSibling) Wnd->NextSibling->PrevSibling = Wnd->PrevSibling;
else if (WndParent && WndParent->LastChild == Wnd) WndParent->LastChild = 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; if (Wnd->PrevSibling) Wnd->PrevSibling->NextSibling = Wnd->NextSibling;
else if (WndParent && WndParent->FirstChild == Wnd) WndParent->FirstChild = Wnd->NextSibling; else if (WndParent && WndParent->FirstChild == Wnd) WndParent->FirstChild = Wnd->NextSibling;
if(WndParent)
{
IntReleaseWindowObject(WndParent);
}
Wnd->PrevSibling = Wnd->NextSibling = Wnd->Parent = NULL; Wnd->PrevSibling = Wnd->NextSibling = Wnd->Parent = NULL;
} }
@ -1081,7 +1066,7 @@ IntAnyPopup(VOID)
for(Child = Window->FirstChild; Child; Child = Child->NextSibling) 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 * The desktop has a popup window if one of them has
@ -1548,14 +1533,14 @@ co_IntCreateWindowEx(DWORD dwExStyle,
} }
Window->MessageQueue = PsGetWin32Thread()->MessageQueue; Window->MessageQueue = PsGetWin32Thread()->MessageQueue;
IntReferenceMessageQueue(Window->MessageQueue); IntReferenceMessageQueue(Window->MessageQueue);
Window->Parent = (ParentWindow ? ParentWindow->hSelf : NULL); Window->Parent = ParentWindow;
if((OwnerWindow = IntGetWindowObject(OwnerWindowHandle))) if((OwnerWindow = IntGetWindowObject(OwnerWindowHandle)))
{ {
Window->Owner = OwnerWindowHandle; Window->hOwner = OwnerWindowHandle;
IntReleaseWindowObject(OwnerWindow); IntReleaseWindowObject(OwnerWindow);
HasOwner = TRUE; HasOwner = TRUE;
} else { } else {
Window->Owner = NULL; Window->hOwner = NULL;
HasOwner = FALSE; HasOwner = FALSE;
} }
Window->UserData = 0; Window->UserData = 0;
@ -2192,7 +2177,7 @@ BOOLEAN FASTCALL co_UserDestroyWindow(PWINDOW_OBJECT Window)
Child = IntGetWindowObject(*ChildHandle); Child = IntGetWindowObject(*ChildHandle);
if (Child == NULL) if (Child == NULL)
continue; continue;
if (Child->Owner != Window->hSelf) if (Child->hOwner != Window->hSelf)
{ {
IntReleaseWindowObject(Child); IntReleaseWindowObject(Child);
continue; continue;
@ -2206,9 +2191,9 @@ BOOLEAN FASTCALL co_UserDestroyWindow(PWINDOW_OBJECT Window)
continue; continue;
} }
if (Child->Owner != NULL) if (Child->hOwner != NULL)
{ {
Child->Owner = NULL; Child->hOwner = NULL;
} }
IntReleaseWindowObject(Child); IntReleaseWindowObject(Child);
@ -3214,27 +3199,23 @@ UserGetWindow(HWND hWnd, UINT Relationship)
PWINDOW_OBJECT Parent, Window; PWINDOW_OBJECT Parent, Window;
HWND hWndResult = NULL; HWND hWndResult = NULL;
if (!(Window = IntGetWindowObject(hWnd))) return NULL; if (!(Window = UserGetWindowObjectNoRef(hWnd))) return NULL;
switch (Relationship) switch (Relationship)
{ {
case GW_HWNDFIRST: case GW_HWNDFIRST:
if((Parent = IntGetParentObject(Window))) if((Parent = Window->Parent))
{ {
if (Parent->FirstChild) if (Parent->FirstChild)
hWndResult = Parent->FirstChild->hSelf; hWndResult = Parent->FirstChild->hSelf;
IntReleaseWindowObject(Parent);
} }
break; break;
case GW_HWNDLAST: case GW_HWNDLAST:
if((Parent = IntGetParentObject(Window))) if((Parent = Window->Parent))
{ {
if (Parent->LastChild) if (Parent->LastChild)
hWndResult = Parent->LastChild->hSelf; hWndResult = Parent->LastChild->hSelf;
IntReleaseWindowObject(Parent);
} }
break; break;
@ -3249,7 +3230,7 @@ UserGetWindow(HWND hWnd, UINT Relationship)
break; break;
case GW_OWNER: case GW_OWNER:
if((Parent = IntGetWindowObject(Window->Owner))) if((Parent = IntGetWindowObject(Window->hOwner)))
{ {
hWndResult = Parent->hSelf; hWndResult = Parent->hSelf;
IntReleaseWindowObject(Parent); IntReleaseWindowObject(Parent);
@ -3261,8 +3242,6 @@ UserGetWindow(HWND hWnd, UINT Relationship)
break; break;
} }
IntReleaseWindowObject(Window);
return hWndResult; return hWndResult;
} }
@ -3365,14 +3344,13 @@ UserGetWindowLong(HWND hWnd, DWORD Index, BOOL Ansi)
break; break;
case GWL_HWNDPARENT: case GWL_HWNDPARENT:
Parent = IntGetWindowObject(Window->Parent); Parent = Window->Parent;
if(Parent) if(Parent)
{ {
if (Parent && Parent->hSelf == IntGetDesktopWindow()) if (Parent && Parent->hSelf == IntGetDesktopWindow())
Result = (LONG) UserGetWindow(Window->hSelf, GW_OWNER); Result = (LONG) UserGetWindow(Window->hSelf, GW_OWNER);
else else
Result = (LONG) Parent->hSelf; Result = (LONG) Parent->hSelf;
IntReleaseWindowObject(Parent);
} }
break; break;

View file

@ -254,14 +254,13 @@ WinPosInitInternalPos(PWINDOW_OBJECT Window, POINT *pt, PRECT RestoreRect)
RECT WorkArea; RECT WorkArea;
PDESKTOP_OBJECT Desktop = PsGetWin32Thread()->Desktop; /* Or rather get it from the window? */ PDESKTOP_OBJECT Desktop = PsGetWin32Thread()->Desktop; /* Or rather get it from the window? */
Parent = IntGetParentObject(Window); Parent = Window->Parent;
if(Parent) if(Parent)
{ {
if(IntIsDesktopWindow(Parent)) if(IntIsDesktopWindow(Parent))
IntGetDesktopWorkArea(Desktop, &WorkArea); IntGetDesktopWorkArea(Desktop, &WorkArea);
else else
WorkArea = Parent->ClientRect; WorkArea = Parent->ClientRect;
IntReleaseWindowObject(Parent);
} }
else else
IntGetDesktopWorkArea(Desktop, &WorkArea); IntGetDesktopWorkArea(Desktop, &WorkArea);
@ -507,7 +506,7 @@ co_WinPosDoNCCALCSize(PWINDOW_OBJECT Window, PWINDOWPOS WinPos,
params.rgrc[0] = *WindowRect; params.rgrc[0] = *WindowRect;
params.rgrc[1] = Window->WindowRect; params.rgrc[1] = Window->WindowRect;
params.rgrc[2] = Window->ClientRect; params.rgrc[2] = Window->ClientRect;
Parent = IntGetParentObject(Window); Parent = Window->Parent;
if (0 != (Window->Style & WS_CHILD) && Parent) if (0 != (Window->Style & WS_CHILD) && Parent)
{ {
IntGdiOffsetRect(&(params.rgrc[0]), - Parent->ClientRect.left, IntGdiOffsetRect(&(params.rgrc[0]), - Parent->ClientRect.left,
@ -550,8 +549,6 @@ co_WinPosDoNCCALCSize(PWINDOW_OBJECT Window, PWINDOWPOS WinPos,
{ {
WinPos->flags &= ~SWP_NOCLIENTSIZE; WinPos->flags &= ~SWP_NOCLIENTSIZE;
} }
if(Parent)
IntReleaseWindowObject(Parent);
} }
else else
{ {
@ -593,14 +590,13 @@ co_WinPosDoWinPosChanging(PWINDOW_OBJECT Window,
PWINDOW_OBJECT Parent; PWINDOW_OBJECT Parent;
X = WinPos->x; X = WinPos->x;
Y = WinPos->y; Y = WinPos->y;
Parent = IntGetParentObject(Window); Parent = Window->Parent;
if ((0 != (Window->Style & WS_CHILD)) && Parent) if ((0 != (Window->Style & WS_CHILD)) && Parent)
{ {
X += Parent->ClientRect.left; X += Parent->ClientRect.left;
Y += Parent->ClientRect.top; Y += Parent->ClientRect.top;
} }
if(Parent)
IntReleaseWindowObject(Parent);
WindowRect->left = X; WindowRect->left = X;
WindowRect->top = Y; WindowRect->top = Y;
WindowRect->right += X - Window->WindowRect.left; WindowRect->right += X - Window->WindowRect.left;
@ -805,18 +801,14 @@ WinPosFixupFlags(WINDOWPOS *WinPos, PWINDOW_OBJECT Window)
&& HWND_NOTOPMOST != WinPos->hwndInsertAfter && HWND_NOTOPMOST != WinPos->hwndInsertAfter
&& HWND_BOTTOM != WinPos->hwndInsertAfter) && HWND_BOTTOM != WinPos->hwndInsertAfter)
{ {
PWINDOW_OBJECT Parent = IntGetParentObject(Window); PWINDOW_OBJECT Parent = Window->Parent;
if (UserGetAncestor(WinPos->hwndInsertAfter, GA_PARENT) != if (UserGetAncestor(WinPos->hwndInsertAfter, GA_PARENT) !=
(Parent ? Parent->hSelf : NULL)) (Parent ? Parent->hSelf : NULL))
{ {
if(Parent)
IntReleaseWindowObject(Parent);
return FALSE; return FALSE;
} }
else else
{ {
if(Parent)
IntReleaseWindowObject(Parent);
/* /*
* We don't need to change the Z order of hwnd if it's already * We don't need to change the Z order of hwnd if it's already
* inserted after hwndInsertAfter or when inserting hwnd after * inserted after hwndInsertAfter or when inserting hwnd after
@ -1382,7 +1374,7 @@ co_WinPosShowWindow(HWND Wnd, INT Cmd)
if (Wnd == IntGetThreadFocusWindow() || if (Wnd == IntGetThreadFocusWindow() ||
IntIsChildWindow(Wnd, IntGetThreadFocusWindow())) IntIsChildWindow(Wnd, IntGetThreadFocusWindow()))
{ {
UserSetFocus(Window->Parent); UserSetFocus(Window->Parent->hSelf);
} }
if (!(Window->Parent)) if (!(Window->Parent))