From b4472c0848535a2de30dab4f86fc8d603d14dabe Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Tue, 13 Apr 2004 23:12:30 +0000 Subject: [PATCH] fixed implementation of ChildWindowFromPointEx() svn path=/trunk/; revision=9134 --- reactos/subsys/win32k/include/winpos.h | 9 ++ reactos/subsys/win32k/ntuser/window.c | 115 ++++++++++++------------- reactos/subsys/win32k/ntuser/winpos.c | 11 +-- 3 files changed, 65 insertions(+), 70 deletions(-) diff --git a/reactos/subsys/win32k/include/winpos.h b/reactos/subsys/win32k/include/winpos.h index f2428db1b14..2929d8137de 100644 --- a/reactos/subsys/win32k/include/winpos.h +++ b/reactos/subsys/win32k/include/winpos.h @@ -5,6 +5,15 @@ #define SWP_NOCLIENTMOVE 0x0800 #define SWP_NOCLIENTSIZE 0x1000 +#define IntPtInWindow(WndObject,x,y) \ + ((x) >= (WndObject)->WindowRect.left && \ + (x) < (WndObject)->WindowRect.right && \ + (y) >= (WndObject)->WindowRect.top && \ + (y) < (WndObject)->WindowRect.bottom && \ + (!(WndObject)->WindowRegion || ((WndObject)->Style & WS_MINIMIZE) || \ + NtGdiPtInRegion((WndObject)->WindowRegion, (INT)((x) - (WndObject)->WindowRect.left), \ + (INT)((y) - (WndObject)->WindowRect.top)))) + BOOL FASTCALL IntGetClientOrigin(HWND hWnd, LPPOINT Point); LRESULT FASTCALL diff --git a/reactos/subsys/win32k/ntuser/window.c b/reactos/subsys/win32k/ntuser/window.c index ac638b7667e..20d9300f62b 100644 --- a/reactos/subsys/win32k/ntuser/window.c +++ b/reactos/subsys/win32k/ntuser/window.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: window.c,v 1.214 2004/04/13 18:40:00 weiden Exp $ +/* $Id: window.c,v 1.215 2004/04/13 23:12:29 weiden Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -1233,76 +1233,69 @@ NtUserBuildHwndList( /* * @implemented */ - - /* FIXME - NEEDS TO BE FIXED - UNSAFE !!! */ HWND STDCALL NtUserChildWindowFromPointEx(HWND hwndParent, LONG x, LONG y, UINT uiFlags) { - PWINDOW_OBJECT pParent, pCurrent, pLast, pPar; - POINT p = {x,y}; - RECT rc; - BOOL bFirstRun = TRUE; - - if(hwndParent) + PWINDOW_OBJECT Parent; + POINTL Pt; + HWND Ret; + HWND *List, *phWnd; + + if(!(Parent = IntGetWindowObject(hwndParent))) + { + SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); + return NULL; + } + + Ret = NULL; + + Pt.x = Parent->WindowRect.left + x; + Pt.y = Parent->WindowRect.top + y; + + if((List = IntWinListChildren(Parent))) + { + for(phWnd = List; *phWnd; phWnd++) { - pParent = IntGetWindowObject(hwndParent); - if(pParent) + PWINDOW_OBJECT Child; + if((Child = IntGetWindowObject(*phWnd))) + { + if(!(Child->Style & WS_VISIBLE) && (uiFlags & CWP_SKIPINVISIBLE)) { - IntLockRelatives(pParent); - - pLast = IntGetWindowObject(pParent->LastChild->Self); - pCurrent = IntGetWindowObject(pParent->FirstChild->Self); - - do - { - if (!bFirstRun) - { - pCurrent = IntGetWindowObject(pCurrent->NextSibling->Self); - - } - else - bFirstRun = FALSE; - if(!pCurrent) - { - IntUnLockRelatives(pParent); - return (HWND)NULL; - } - if(!(pPar = IntGetWindowObject(pCurrent->Parent))) - { - IntUnLockRelatives(pParent); - return (HWND)NULL; - } - rc.left = pCurrent->WindowRect.left - pPar->ClientRect.left; - rc.top = pCurrent->WindowRect.top - pPar->ClientRect.top; - rc.right = rc.left + (pCurrent->WindowRect.right - pCurrent->WindowRect.left); - rc.bottom = rc.top + (pCurrent->WindowRect.bottom - pCurrent->WindowRect.top); - DbgPrint("Rect: %i,%i,%i,%i\n",rc.left, rc.top, rc.right, rc.bottom); - IntReleaseWindowObject(pPar); - if (POINT_IN_RECT(p,rc)) /* Found a match */ - { - if ( (uiFlags & CWP_SKIPDISABLED) && (pCurrent->Style & WS_DISABLED) ) - continue; - if( (uiFlags & CWP_SKIPTRANSPARENT) && (pCurrent->ExStyle & WS_EX_TRANSPARENT) ) - continue; - if( (uiFlags & CWP_SKIPINVISIBLE) && !(pCurrent->Style & WS_VISIBLE) ) - continue; - - IntUnLockRelatives(pParent); - return pCurrent->Self; - } - } - while(pCurrent != pLast); - - IntUnLockRelatives(pParent); - return (HWND)NULL; + IntReleaseWindowObject(Child); + continue; } - SetLastWin32Error(ERROR_INVALID_PARAMETER); + if((Child->Style & WS_DISABLED) && (uiFlags & CWP_SKIPDISABLED)) + { + IntReleaseWindowObject(Child); + continue; + } + if((Child->ExStyle & WS_EX_TRANSPARENT) && (uiFlags & CWP_SKIPTRANSPARENT)) + { + IntReleaseWindowObject(Child); + continue; + } + if(IntPtInWindow(Child, Pt.x, Pt.y)) + { + Ret = Child->Self; + IntReleaseWindowObject(Child); + break; + } + IntReleaseWindowObject(Child); + } } - - return (HWND)NULL; + ExFreePool(List); + } + + if((Ret == NULL) && IntPtInWindow(Parent, Pt.x, Pt.y)) + { + Ret = Parent->Self; + } + + IntReleaseWindowObject(Parent); + return Ret; } diff --git a/reactos/subsys/win32k/ntuser/winpos.c b/reactos/subsys/win32k/ntuser/winpos.c index dea9fb4025f..298fb67cf92 100644 --- a/reactos/subsys/win32k/ntuser/winpos.c +++ b/reactos/subsys/win32k/ntuser/winpos.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: winpos.c,v 1.109 2004/04/09 20:03:19 navaraf Exp $ +/* $Id: winpos.c,v 1.110 2004/04/13 23:12:30 weiden Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -1385,14 +1385,7 @@ WinPosSearchChildren(PWINDOW_OBJECT ScopeWin, BOOL SendHitTestMessage, POINT *Po if (Current->Style & WS_VISIBLE && (!(Current->Style & WS_DISABLED) || (Current->Style & (WS_CHILD | WS_POPUP)) != WS_CHILD) && - (Point->x >= Current->WindowRect.left && - Point->x < Current->WindowRect.right && - Point->y >= Current->WindowRect.top && - Point->y < Current->WindowRect.bottom) && - (!Current->WindowRegion || (Current->Style & WS_MINIMIZE) || - NtGdiPtInRegion(Current->WindowRegion, (INT)(Point->x - Current->WindowRect.left), - (INT)(Point->y - Current->WindowRect.top))) - ) + IntPtInWindow(Current, Point->x, Point->y)) { if(*Window) {