From fdafc67fbe4acafdef6f40cf2d7551a486f47979 Mon Sep 17 00:00:00 2001 From: Gunnar Dalsnes Date: Sun, 11 Sep 2005 14:48:32 +0000 Subject: [PATCH] -refcount reworking (simplification & improvement) -make functions deal with pointers, not handles -misc formatting svn path=/trunk/; revision=17802 --- reactos/subsys/win32k/eng/window.c | 3 +- reactos/subsys/win32k/include/userfuncs.h | 57 ++- reactos/subsys/win32k/include/window.h | 4 +- reactos/subsys/win32k/ntuser/class.c | 18 +- reactos/subsys/win32k/ntuser/desktop.c | 16 +- reactos/subsys/win32k/ntuser/focus.c | 64 +-- reactos/subsys/win32k/ntuser/message.c | 202 +++++---- reactos/subsys/win32k/ntuser/misc.c | 112 ++--- reactos/subsys/win32k/ntuser/msgqueue.c | 68 ++- reactos/subsys/win32k/ntuser/object.c | 2 + reactos/subsys/win32k/ntuser/painting.c | 55 ++- reactos/subsys/win32k/ntuser/timer.c | 11 +- reactos/subsys/win32k/ntuser/windc.c | 35 +- reactos/subsys/win32k/ntuser/window.c | 513 ++++++++-------------- reactos/subsys/win32k/ntuser/winpos.c | 156 ++++--- reactos/subsys/win32k/objects/color.c | 6 +- 16 files changed, 603 insertions(+), 719 deletions(-) diff --git a/reactos/subsys/win32k/eng/window.c b/reactos/subsys/win32k/eng/window.c index 18088258072..48686218156 100644 --- a/reactos/subsys/win32k/eng/window.c +++ b/reactos/subsys/win32k/eng/window.c @@ -287,7 +287,7 @@ EngDeleteWnd( } /* Get window object */ - Window = IntGetWindowObject(WndObjInt->Hwnd); + Window = UserGetWindowObject(WndObjInt->Hwnd); if (Window == NULL) { DPRINT1("Warning: Couldnt get window object for WndObjInt->Hwnd!!!\n"); @@ -297,7 +297,6 @@ EngDeleteWnd( { /* Remove object from window */ RemoveEntryList(&WndObjInt->ListEntry); - IntReleaseWindowObject(Window); } if (!calledFromUser){ diff --git a/reactos/subsys/win32k/include/userfuncs.h b/reactos/subsys/win32k/include/userfuncs.h index 9dad7cc3bbe..66e813a7e22 100644 --- a/reactos/subsys/win32k/include/userfuncs.h +++ b/reactos/subsys/win32k/include/userfuncs.h @@ -2,15 +2,57 @@ #define _WIN32K_USERFUNCS_H -#define ASSERT_REFS_CO(obj) \ + + + +PMENU_OBJECT FASTCALL UserGetMenuObject(HMENU hMenu); + + +#if 0 +#define ObmDereferenceObject(_obj_) \ { \ - LONG ref = USER_BODY_TO_HEADER(obj)->RefCount;\ + DPRINT1("obj 0x%x dereffed to %i refs\n",_obj_, USER_BODY_TO_HEADER(_obj_)->RefCount-1); \ + ObmDereferenceObject2(_obj_); \ +} +#endif + + + + + + + +#define ASSERT_REFS_CO(_obj_) \ +{ \ + LONG ref = USER_BODY_TO_HEADER(_obj_)->RefCount;\ if (!(ref >= 1)){ \ - DPRINT1("obj 0x%x, refs %i\n", obj, ref); \ + DPRINT1("ASSERT: obj 0x%x, refs %i\n", _obj_, ref); \ ASSERT(FALSE); \ } \ } +#if 0 +#define ASSERT_REFS_CO(_obj_) \ +{ \ + PSINGLE_LIST_ENTRY e; \ + BOOL gotit=FALSE; \ + LONG ref = USER_BODY_TO_HEADER(_obj_)->RefCount;\ + if (!(ref >= 1)){ \ + DPRINT1("obj 0x%x, refs %i\n", _obj_, ref); \ + ASSERT(FALSE); \ + } \ + \ + e = PsGetWin32Thread()->ReferencesList.Next; \ + while (e) \ + { \ + PUSER_REFERENCE_ENTRY ref = CONTAINING_RECORD(e, USER_REFERENCE_ENTRY, Entry); \ + if (ref->obj == _obj_){ gotit=TRUE; break; } \ + e = e->Next; \ + } \ + ASSERT(gotit); \ +} +#endif + #define DUMP_REFS(obj) DPRINT1("obj 0x%x, refs %i\n",obj, USER_BODY_TO_HEADER(obj)->RefCount) @@ -19,11 +61,6 @@ VOID FASTCALL ObmReferenceObject(PVOID obj); BOOL FASTCALL ObmDereferenceObject(PVOID obj); -#define IntReferenceWindowObject(o) ObmReferenceObject(o) - -#define UserDerefObject(o) ObmReferenceObject(o) - -VOID FASTCALL IntReleaseWindowObject(PWINDOW_OBJECT Window); PWINDOW_OBJECT FASTCALL IntGetWindowObject(HWND hWnd); PVOID FASTCALL ObmCreateObject(PUSER_HANDLE_TABLE ht, HANDLE* h,USER_OBJECT_TYPE type , ULONG size); @@ -31,8 +68,8 @@ ObmCreateObject(PUSER_HANDLE_TABLE ht, HANDLE* h,USER_OBJECT_TYPE type , ULONG s BOOL FASTCALL ObmDeleteObject(HANDLE h, USER_OBJECT_TYPE type ); -//#define UserRefObjectCo(o) ObmReferenceObject(o) -//#define UserDerefObjectCo(o) ObmDereferenceObject(o) +#define UserRefObject(o) ObmReferenceObject(o) +#define UserDerefObject(o) ObmDereferenceObject(o) BOOL FASTCALL ObmCreateHandleTable(); diff --git a/reactos/subsys/win32k/include/window.h b/reactos/subsys/win32k/include/window.h index 64a8647b2b7..162dc1186cb 100644 --- a/reactos/subsys/win32k/include/window.h +++ b/reactos/subsys/win32k/include/window.h @@ -157,7 +157,7 @@ BOOL FASTCALL IntIsWindowVisible (PWINDOW_OBJECT Window); BOOL FASTCALL -IntIsChildWindow (HWND Parent, HWND Child); +IntIsChildWindow (PWINDOW_OBJECT Parent, PWINDOW_OBJECT Child); VOID FASTCALL IntUnlinkWindow(PWINDOW_OBJECT Wnd); @@ -174,8 +174,6 @@ IntGetParent(PWINDOW_OBJECT Wnd); PWINDOW_OBJECT FASTCALL IntGetOwner(PWINDOW_OBJECT Wnd); -PWINDOW_OBJECT FASTCALL -IntGetParentObject(PWINDOW_OBJECT Wnd); INT FASTCALL IntGetWindowRgn(PWINDOW_OBJECT Window, HRGN hRgn); diff --git a/reactos/subsys/win32k/ntuser/class.c b/reactos/subsys/win32k/ntuser/class.c index 115ecb70721..76850f3600e 100644 --- a/reactos/subsys/win32k/ntuser/class.c +++ b/reactos/subsys/win32k/ntuser/class.c @@ -559,8 +559,6 @@ CLEANUP: void FASTCALL co_IntSetClassLong(PWINDOW_OBJECT Window, ULONG Offset, LONG dwNewLong, BOOL Ansi) { - PWINDOW_OBJECT Parent, Owner; - ASSERT_REFS_CO(Window); if ((int)Offset >= 0) @@ -591,25 +589,11 @@ co_IntSetClassLong(PWINDOW_OBJECT Window, ULONG Offset, LONG dwNewLong, BOOL Ans break; case GCL_HICON: Window->Class->hIcon = (HICON)dwNewLong; - Owner = IntGetOwner(Window); - Parent = IntGetParent(Window); - if ((!Owner) && (!Parent)) + if (!IntGetOwner(Window) && !IntGetParent(Window)) { co_IntShellHookNotify(HSHELL_REDRAW, (LPARAM) Window->hSelf); } - - if (Parent) - { - IntReleaseWindowObject(Parent); - } - - if (Owner) - { - IntReleaseWindowObject(Owner); - } - - break; case GCL_HICONSM: Window->Class->hIconSm = (HICON)dwNewLong; diff --git a/reactos/subsys/win32k/ntuser/desktop.c b/reactos/subsys/win32k/ntuser/desktop.c index a1b4438ed31..9b6e098c198 100644 --- a/reactos/subsys/win32k/ntuser/desktop.c +++ b/reactos/subsys/win32k/ntuser/desktop.c @@ -463,7 +463,6 @@ HWND FASTCALL IntGetDesktopWindow(VOID) PWINDOW_OBJECT FASTCALL UserGetDesktopWindow(VOID) { PDESKTOP_OBJECT pdo = IntGetActiveDesktop(); - PWINDOW_OBJECT DeskWnd; if (!pdo) { @@ -471,11 +470,7 @@ PWINDOW_OBJECT FASTCALL UserGetDesktopWindow(VOID) return NULL; } - //temp hack - DeskWnd = IntGetWindowObject(pdo->DesktopWindow); - if (DeskWnd) - IntReleaseWindowObject(DeskWnd); - return DeskWnd; + return UserGetWindowObject(pdo->DesktopWindow); } @@ -1190,14 +1185,11 @@ NtUserPaintDesktop(HDC hDC) IntGdiGetClipBox(hDC, &Rect); hWndDesktop = IntGetDesktopWindow(); - if (!(WndDesktop = IntGetWindowObject(hWndDesktop))) + if (!(WndDesktop = UserGetWindowObject(hWndDesktop))) return FALSE; DesktopBrush = (HBRUSH)IntGetClassLong(WndDesktop, GCL_HBRBACKGROUND, FALSE); //fixme: verify retval - //temp hack - IntReleaseWindowObject(WndDesktop); - /* * Paint desktop background @@ -1207,7 +1199,7 @@ NtUserPaintDesktop(HDC hDC) { PWINDOW_OBJECT DeskWin; - if((DeskWin = IntGetWindowObject(hWndDesktop))) + if((DeskWin = UserGetWindowObject(hWndDesktop))) { SIZE sz; int x, y; @@ -1215,7 +1207,7 @@ NtUserPaintDesktop(HDC hDC) sz.cx = DeskWin->WindowRect.right - DeskWin->WindowRect.left; sz.cy = DeskWin->WindowRect.bottom - DeskWin->WindowRect.top; - IntReleaseWindowObject(DeskWin); + x = (sz.cx / 2) - (WinSta->cxWallpaper / 2); y = (sz.cy / 2) - (WinSta->cyWallpaper / 2); diff --git a/reactos/subsys/win32k/ntuser/focus.c b/reactos/subsys/win32k/ntuser/focus.c index ba26fbacc97..4d5a1efdd01 100644 --- a/reactos/subsys/win32k/ntuser/focus.c +++ b/reactos/subsys/win32k/ntuser/focus.c @@ -61,10 +61,13 @@ co_IntSendDeactivateMessages(HWND hWndPrev, HWND hWnd) VOID FASTCALL co_IntSendActivateMessages(HWND hWndPrev, HWND hWnd, BOOL MouseActivate) { - PWINDOW_OBJECT Window, Owner, Parent; - - if (hWnd && (Window = IntGetWindowObject(hWnd))) + PWINDOW_OBJECT Window; + + if ((Window = UserGetWindowObject(hWnd))) { + + UserRefObjectCo(Window); + /* Send palette messages */ if (co_IntPostOrSendMessage(hWnd, WM_QUERYNEWPALETTE, 0, 0)) { @@ -76,22 +79,12 @@ co_IntSendActivateMessages(HWND hWndPrev, HWND hWnd, BOOL MouseActivate) co_WinPosSetWindowPos(Window, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOSENDCHANGING); - - Owner = IntGetOwner(Window); - if (!Owner) + if (!IntGetOwner(Window) && !IntGetParent(Window)) { - Parent = IntGetParent(Window); - if (!Parent) - co_IntShellHookNotify(HSHELL_WINDOWACTIVATED, (LPARAM) hWnd); - else - IntReleaseWindowObject(Parent); - } - else - { - IntReleaseWindowObject(Owner); + co_IntShellHookNotify(HSHELL_WINDOWACTIVATED, (LPARAM) hWnd); } - IntReleaseWindowObject(Window); + UserDerefObjectCo(Window); /* FIXME: IntIsWindow */ @@ -130,17 +123,15 @@ IntFindChildWindowToOwner(PWINDOW_OBJECT Root, PWINDOW_OBJECT Owner) for(Child = Root->FirstChild; Child; Child = Child->NextSibling) { - OwnerWnd = IntGetWindowObject(Child->hOwner); + OwnerWnd = UserGetWindowObject(Child->hOwner); if(!OwnerWnd) continue; if(OwnerWnd == Owner) { Ret = Child->hSelf; - IntReleaseWindowObject(OwnerWnd); return Ret; } - IntReleaseWindowObject(OwnerWnd); } return NULL; @@ -215,9 +206,9 @@ co_IntSetForegroundAndFocusWindow(PWINDOW_OBJECT Window, PWINDOW_OBJECT FocusWin } BOOL FASTCALL -co_IntSetForegroundWindow(PWINDOW_OBJECT Window) +co_IntSetForegroundWindow(PWINDOW_OBJECT Window)//FIXME: can Window be NULL?? { - ASSERT_REFS_CO(Window); + /*if (Window)*/ ASSERT_REFS_CO(Window); return co_IntSetForegroundAndFocusWindow(Window, Window, FALSE); } @@ -234,18 +225,18 @@ co_IntMouseActivateWindow(PWINDOW_OBJECT Window) { BOOL Ret; PWINDOW_OBJECT TopWnd; - PWINDOW_OBJECT DesktopWindow = IntGetWindowObject(IntGetDesktopWindow()); + PWINDOW_OBJECT DesktopWindow = UserGetWindowObject(IntGetDesktopWindow()); if(DesktopWindow) { Top = IntFindChildWindowToOwner(DesktopWindow, Window); - if((TopWnd = IntGetWindowObject(Top))) + if((TopWnd = UserGetWindowObject(Top))) { + UserRefObjectCo(TopWnd); Ret = co_IntMouseActivateWindow(TopWnd); - IntReleaseWindowObject(TopWnd); - IntReleaseWindowObject(DesktopWindow); + UserDerefObjectCo(TopWnd); + return Ret; } - IntReleaseWindowObject(DesktopWindow); } return FALSE; } @@ -253,23 +244,6 @@ co_IntMouseActivateWindow(PWINDOW_OBJECT Window) TopWindow = UserGetAncestor(Window, GA_ROOT); if (!TopWindow) return FALSE; -// if (TopWindow != Window) -// { - -// Top = UserGetAncestor(Window, GA_ROOT); -// if (Top != Window->hSelf) -// { -// TopWindow = IntGetWindowObject(Top); -// if (TopWindow == NULL) -// { -// SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); -// return FALSE; -// } -// } -// else -// { -// TopWindow = Window; -// } /* TMN: Check return valud from this function? */ UserRefObjectCo(TopWindow); @@ -278,10 +252,6 @@ co_IntMouseActivateWindow(PWINDOW_OBJECT Window) UserDerefObjectCo(TopWindow); -// if (TopWindow != Window) -// { -// IntReleaseWindowObject(TopWindow); -// } return TRUE; } diff --git a/reactos/subsys/win32k/ntuser/message.c b/reactos/subsys/win32k/ntuser/message.c index 7f770237530..18da8095253 100644 --- a/reactos/subsys/win32k/ntuser/message.c +++ b/reactos/subsys/win32k/ntuser/message.c @@ -318,7 +318,6 @@ NtUserDispatchMessage(PNTUSERDISPATCHMESSAGEINFO UnsafeMsgInfo) { NTSTATUS Status; NTUSERDISPATCHMESSAGEINFO MsgInfo; - PWINDOW_OBJECT WindowObject; LRESULT Result = TRUE; DECLARE_RETURN(LRESULT); @@ -352,19 +351,19 @@ NtUserDispatchMessage(PNTUSERDISPATCHMESSAGEINFO UnsafeMsgInfo) } else { + PWINDOW_OBJECT Window; + /* Get the window object. */ - WindowObject = IntGetWindowObject(MsgInfo.Msg.hwnd); - if (NULL == WindowObject) + Window = UserGetWindowObject(MsgInfo.Msg.hwnd); + if (NULL == Window) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); MsgInfo.HandledByKernel = TRUE; Result = 0; } else { - if (WindowObject->OwnerThread != PsGetCurrentThread()) + if (Window->OwnerThread != PsGetCurrentThread()) { - IntReleaseWindowObject(WindowObject); DPRINT1("Window doesn't belong to the calling thread!\n"); MsgInfo.HandledByKernel = TRUE; Result = 0; @@ -375,30 +374,29 @@ NtUserDispatchMessage(PNTUSERDISPATCHMESSAGEINFO UnsafeMsgInfo) MsgInfo.HandledByKernel = FALSE; Result = 0; - if (0xFFFF0000 != ((DWORD) WindowObject->WndProcW & 0xFFFF0000)) + if (0xFFFF0000 != ((DWORD) Window->WndProcW & 0xFFFF0000)) { - if (0xFFFF0000 != ((DWORD) WindowObject->WndProcA & 0xFFFF0000)) + if (0xFFFF0000 != ((DWORD) Window->WndProcA & 0xFFFF0000)) { /* Both Unicode and Ansi winprocs are real, use whatever usermode prefers */ - MsgInfo.Proc = (MsgInfo.Ansi ? WindowObject->WndProcA - : WindowObject->WndProcW); + MsgInfo.Proc = (MsgInfo.Ansi ? Window->WndProcA + : Window->WndProcW); } else { /* Real Unicode winproc */ MsgInfo.Ansi = FALSE; - MsgInfo.Proc = WindowObject->WndProcW; + MsgInfo.Proc = Window->WndProcW; } } else { /* Must have real Ansi winproc */ MsgInfo.Ansi = TRUE; - MsgInfo.Proc = WindowObject->WndProcA; + MsgInfo.Proc = Window->WndProcA; } } - IntReleaseWindowObject(WindowObject); } } Status = MmCopyToCaller(UnsafeMsgInfo, &MsgInfo, sizeof(NTUSERDISPATCHMESSAGEINFO)); @@ -511,13 +509,15 @@ co_IntActivateWindowMouse(PUSER_MESSAGE_QUEUE ThreadQueue, LPMSG Msg, PWINDOW_OB ULONG Result; PWINDOW_OBJECT Parent; + ASSERT_REFS_CO(MsgWindow); + if(*HitTest == (USHORT)HTTRANSPARENT) { /* eat the message, search again! */ return TRUE; } - Parent = IntGetParent(MsgWindow); + Parent = IntGetParent(MsgWindow);//fixme: deref retval? /* fixme: abort if no parent ? */ Result = co_IntSendMessage(MsgWindow->hSelf, WM_MOUSEACTIVATE, @@ -548,12 +548,14 @@ co_IntTranslateMouseMessage(PUSER_MESSAGE_QUEUE ThreadQueue, LPMSG Msg, USHORT * { PWINDOW_OBJECT Window; - if(!(Window = IntGetWindowObject(Msg->hwnd))) + if(!(Window = UserGetWindowObject(Msg->hwnd))) { /* let's just eat the message?! */ return TRUE; } + UserRefObjectCo(Window); + if(ThreadQueue == Window->MessageQueue && ThreadQueue->CaptureWindow != Window->hSelf) { @@ -566,10 +568,12 @@ co_IntTranslateMouseMessage(PUSER_MESSAGE_QUEUE ThreadQueue, LPMSG Msg, USHORT * PWINDOW_OBJECT DesktopWindow; HWND hDesktop = IntGetDesktopWindow(); - if((DesktopWindow = IntGetWindowObject(hDesktop))) + if((DesktopWindow = UserGetWindowObject(hDesktop))) { PWINDOW_OBJECT Wnd; - + + UserRefObjectCo(DesktopWindow); + co_WinPosWindowFromPoint(DesktopWindow, Window->MessageQueue, &Msg->pt, &Wnd); if(Wnd) { @@ -585,15 +589,15 @@ co_IntTranslateMouseMessage(PUSER_MESSAGE_QUEUE ThreadQueue, LPMSG Msg, USHORT * } /* eat the message */ - IntReleaseWindowObject(Wnd); - IntReleaseWindowObject(Window); - IntReleaseWindowObject(DesktopWindow); + UserDerefObject(Wnd); + UserDerefObjectCo(DesktopWindow); + UserDerefObjectCo(Window); return TRUE; } - IntReleaseWindowObject(Wnd); + UserDerefObject(Wnd); } - IntReleaseWindowObject(DesktopWindow); + UserDerefObjectCo(DesktopWindow); } } } @@ -641,7 +645,7 @@ co_IntTranslateMouseMessage(PUSER_MESSAGE_QUEUE ThreadQueue, LPMSG Msg, USHORT * } } - IntReleaseWindowObject(Window); + UserDerefObjectCo(Window); return FALSE; } @@ -651,7 +655,7 @@ co_IntTranslateMouseMessage(PUSER_MESSAGE_QUEUE ThreadQueue, LPMSG Msg, USHORT * */ BOOL FASTCALL co_IntPeekMessage(PUSER_MESSAGE Msg, - HWND Wnd, + HWND hWnd, UINT MsgFilterMin, UINT MsgFilterMax, UINT RemoveMsg) @@ -703,7 +707,7 @@ CheckMessages: Present = co_MsqFindMessage(ThreadQueue, FALSE, RemoveMessages, - Wnd, + hWnd, MsgFilterMin, MsgFilterMax, &Message); @@ -721,7 +725,7 @@ CheckMessages: Present = co_MsqFindMessage(ThreadQueue, TRUE, RemoveMessages, - Wnd, + hWnd, MsgFilterMin, MsgFilterMax, &Message); @@ -740,14 +744,14 @@ CheckMessages: ; /* Check for paint messages. */ - if (IntGetPaintMessage(Wnd, MsgFilterMin, MsgFilterMax, PsGetWin32Thread(), &Msg->Msg, RemoveMessages)) + if (IntGetPaintMessage(hWnd, MsgFilterMin, MsgFilterMax, PsGetWin32Thread(), &Msg->Msg, RemoveMessages)) { Msg->FreeLParam = FALSE; return TRUE; } /* Check for WM_(SYS)TIMER messages */ - Present = MsqGetTimerMessage(ThreadQueue, Wnd, MsgFilterMin, MsgFilterMax, + Present = MsqGetTimerMessage(ThreadQueue, hWnd, MsgFilterMin, MsgFilterMax, &Msg->Msg, RemoveMessages); if (Present) { @@ -763,19 +767,22 @@ MessageFound: { PWINDOW_OBJECT MsgWindow = NULL; - if(Msg->Msg.hwnd && (MsgWindow = IntGetWindowObject(Msg->Msg.hwnd)) && + if(Msg->Msg.hwnd && (MsgWindow = UserGetWindowObject(Msg->Msg.hwnd)) && Msg->Msg.message >= WM_MOUSEFIRST && Msg->Msg.message <= WM_MOUSELAST) { USHORT HitTest; + UserRefObjectCo(MsgWindow); + if(co_IntTranslateMouseMessage(ThreadQueue, &Msg->Msg, &HitTest, TRUE)) /* FIXME - check message filter again, if the message doesn't match anymore, search again */ { - IntReleaseWindowObject(MsgWindow); + UserDerefObjectCo(MsgWindow); /* eat the message, search again */ goto CheckMessages; } + if(ThreadQueue->CaptureWindow == NULL) { co_IntSendHitTestMessages(ThreadQueue, &Msg->Msg); @@ -783,21 +790,23 @@ MessageFound: IS_BTN_MESSAGE(Msg->Msg.message, DOWN) && co_IntActivateWindowMouse(ThreadQueue, &Msg->Msg, MsgWindow, &HitTest)) { - IntReleaseWindowObject(MsgWindow); + UserDerefObjectCo(MsgWindow); /* eat the message, search again */ goto CheckMessages; } } + + UserDerefObjectCo(MsgWindow); } else { co_IntSendHitTestMessages(ThreadQueue, &Msg->Msg); } - if(MsgWindow) - { - IntReleaseWindowObject(MsgWindow); - } +// if(MsgWindow) +// { +// UserDerefObject(MsgWindow); +// } return TRUE; } @@ -820,7 +829,7 @@ MessageFound: BOOL STDCALL NtUserPeekMessage(PNTUSERGETMESSAGEINFO UnsafeInfo, - HWND Wnd, + HWND hWnd, UINT MsgFilterMin, UINT MsgFilterMax, UINT RemoveMsg) @@ -839,16 +848,11 @@ NtUserPeekMessage(PNTUSERGETMESSAGEINFO UnsafeInfo, UserEnterExclusive(); /* Validate input */ - if (NULL != Wnd) + if (hWnd && hWnd != INVALID_HANDLE_VALUE) { - Window = IntGetWindowObject(Wnd); - if (NULL == Window) + if (!(Window = UserGetWindowObject(hWnd))) { - Wnd = NULL; - } - else - { - IntReleaseWindowObject(Window); + RETURN(-1); } } @@ -858,7 +862,7 @@ NtUserPeekMessage(PNTUSERGETMESSAGEINFO UnsafeInfo, MsgFilterMax = 0; } - Present = co_IntPeekMessage(&Msg, Wnd, MsgFilterMin, MsgFilterMax, RemoveMsg); + Present = co_IntPeekMessage(&Msg, hWnd, MsgFilterMin, MsgFilterMax, RemoveMsg); if (Present) { Info.Msg = Msg.Msg; @@ -945,7 +949,7 @@ co_IntWaitMessage(HWND Wnd, BOOL STDCALL NtUserGetMessage(PNTUSERGETMESSAGEINFO UnsafeInfo, - HWND Wnd, + HWND hWnd, UINT MsgFilterMin, UINT MsgFilterMax) /* @@ -962,7 +966,7 @@ NtUserGetMessage(PNTUSERGETMESSAGEINFO UnsafeInfo, BOOL GotMessage; NTUSERGETMESSAGEINFO Info; NTSTATUS Status; - PWINDOW_OBJECT Window; + PWINDOW_OBJECT Window = NULL; PMSGMEMORY MsgMemoryEntry; PVOID UserMem; UINT Size; @@ -973,14 +977,13 @@ NtUserGetMessage(PNTUSERGETMESSAGEINFO UnsafeInfo, UserEnterExclusive(); /* Validate input */ - if (NULL != Wnd) + if (hWnd && !(Window = UserGetWindowObject(hWnd))) { - Window = IntGetWindowObject(Wnd); - if(!Window) - Wnd = NULL; - else - IntReleaseWindowObject(Window); + RETURN(-1); } + +// if (Window) UserRefObjectCo(Window); + if (MsgFilterMax < MsgFilterMin) { MsgFilterMin = 0; @@ -989,7 +992,7 @@ NtUserGetMessage(PNTUSERGETMESSAGEINFO UnsafeInfo, do { - GotMessage = co_IntPeekMessage(&Msg, Wnd, MsgFilterMin, MsgFilterMax, PM_REMOVE); + GotMessage = co_IntPeekMessage(&Msg, hWnd, MsgFilterMin, MsgFilterMax, PM_REMOVE); if (GotMessage) { Info.Msg = Msg.Msg; @@ -1038,7 +1041,7 @@ NtUserGetMessage(PNTUSERGETMESSAGEINFO UnsafeInfo, RETURN( (BOOL) -1); } } - else if (! co_IntWaitMessage(Wnd, MsgFilterMin, MsgFilterMax)) + else if (! co_IntWaitMessage(hWnd, MsgFilterMin, MsgFilterMax)) { RETURN( (BOOL) -1); } @@ -1048,6 +1051,8 @@ NtUserGetMessage(PNTUSERGETMESSAGEINFO UnsafeInfo, RETURN( WM_QUIT != Info.Msg.message); CLEANUP: +// if (Window) UserDerefObjectCo(Window); + DPRINT("Leave NtUserGetMessage\n"); UserLeave(); END_CLEANUP; @@ -1169,7 +1174,6 @@ UserPostMessage(HWND Wnd, WPARAM wParam, LPARAM lParam) { - PWINDOW_OBJECT Window; MSG UserModeMsg, KernelModeMsg; LARGE_INTEGER LargeTickCount; NTSTATUS Status; @@ -1185,9 +1189,9 @@ UserPostMessage(HWND Wnd, PWINDOW_OBJECT DesktopWindow; ULONG i; - DesktopWindow = IntGetWindowObject(IntGetDesktopWindow()); + DesktopWindow = UserGetWindowObject(IntGetDesktopWindow()); List = IntWinListChildren(DesktopWindow); - IntReleaseWindowObject(DesktopWindow); + if (List != NULL) { for (i = 0; List[i]; i++) @@ -1197,15 +1201,15 @@ UserPostMessage(HWND Wnd, } else { - Window = IntGetWindowObject(Wnd); + PWINDOW_OBJECT Window; + + Window = UserGetWindowObject(Wnd); if (NULL == Window) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); return FALSE; } if(Window->Status & WINDOWSTATUS_DESTROYING) { - IntReleaseWindowObject(Window); DPRINT1("Attempted to post message to window 0x%x that is being destroyed!\n", Wnd); /* FIXME - last error code? */ return FALSE; @@ -1229,7 +1233,6 @@ UserPostMessage(HWND Wnd, MsqPostMessage(Window->MessageQueue, &KernelModeMsg, NULL != MsgMemoryEntry && 0 != KernelModeMsg.lParam, QS_POSTMESSAGE); - IntReleaseWindowObject(Window); } return TRUE; @@ -1336,7 +1339,8 @@ co_IntSendMessage(HWND hWnd, return 0; } -static LRESULT FASTCALL +static +LRESULT FASTCALL co_IntSendMessageTimeoutSingle(HWND hWnd, UINT Msg, WPARAM wParam, @@ -1347,19 +1351,20 @@ co_IntSendMessageTimeoutSingle(HWND hWnd, { ULONG_PTR Result; NTSTATUS Status; - PWINDOW_OBJECT Window; + PWINDOW_OBJECT Window = NULL; PMSGMEMORY MsgMemoryEntry; INT lParamBufferSize; LPARAM lParamPacked; PW32THREAD Win32Thread; + DECLARE_RETURN(LRESULT); /* FIXME: Call hooks. */ - Window = IntGetWindowObject(hWnd); - if (!Window) + if (!(Window = UserGetWindowObject(hWnd))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); - return FALSE; + RETURN( FALSE); } + + UserRefObjectCo(Window); Win32Thread = PsGetWin32Thread(); @@ -1369,8 +1374,7 @@ co_IntSendMessageTimeoutSingle(HWND hWnd, if (Win32Thread->IsExiting) { /* Never send messages to exiting threads */ - IntReleaseWindowObject(Window); - return FALSE; + RETURN( FALSE); } /* See if this message type is present in the table */ @@ -1386,9 +1390,8 @@ co_IntSendMessageTimeoutSingle(HWND hWnd, if (! NT_SUCCESS(PackParam(&lParamPacked, Msg, wParam, lParam))) { - IntReleaseWindowObject(Window); DPRINT1("Failed to pack message parameters\n"); - return FALSE; + RETURN( FALSE); } if (0xFFFF0000 != ((DWORD) Window->WndProcW & 0xFFFF0000)) { @@ -1408,46 +1411,47 @@ co_IntSendMessageTimeoutSingle(HWND hWnd, if (! NT_SUCCESS(UnpackParam(lParamPacked, Msg, wParam, lParam))) { - IntReleaseWindowObject(Window); DPRINT1("Failed to unpack message parameters\n"); - return TRUE; + RETURN( TRUE); } - IntReleaseWindowObject(Window); - return TRUE; + RETURN( TRUE); } if(uFlags & SMTO_ABORTIFHUNG && MsqIsHung(Window->MessageQueue)) { - IntReleaseWindowObject(Window); /* FIXME - Set a LastError? */ - return FALSE; + RETURN( FALSE); } if(Window->Status & WINDOWSTATUS_DESTROYING) { - IntReleaseWindowObject(Window); /* FIXME - last error? */ DPRINT1("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd); - return FALSE; + RETURN( FALSE); } Status = co_MsqSendMessage(Window->MessageQueue, hWnd, Msg, wParam, lParam, uTimeout, (uFlags & SMTO_BLOCK), FALSE, uResult); - IntReleaseWindowObject(Window); + + if (STATUS_TIMEOUT == Status) { /* MSDN says GetLastError() should return 0 after timeout */ SetLastWin32Error(0); - return FALSE; + RETURN( FALSE); } else if (! NT_SUCCESS(Status)) { SetLastNtError(Status); - return FALSE; + RETURN( FALSE); } - return TRUE; + RETURN( TRUE); + +CLEANUP: + if (Window) UserDerefObjectCo(Window); + END_CLEANUP; } LRESULT FASTCALL @@ -1468,14 +1472,14 @@ co_IntSendMessageTimeout(HWND hWnd, return co_IntSendMessageTimeoutSingle(hWnd, Msg, wParam, lParam, uFlags, uTimeout, uResult); } - DesktopWindow = IntGetWindowObject(IntGetDesktopWindow()); + DesktopWindow = UserGetWindowObject(IntGetDesktopWindow()); if (NULL == DesktopWindow) { SetLastWin32Error(ERROR_INTERNAL_ERROR); return 0; } + Children = IntWinListChildren(DesktopWindow); - IntReleaseWindowObject(DesktopWindow); if (NULL == Children) { return 0; @@ -1509,10 +1513,8 @@ co_IntPostOrSendMessage(HWND hWnd, return 0; } - Window = IntGetWindowObject(hWnd); - if(!Window) + if(!(Window = UserGetWindowObject(hWnd))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); return 0; } @@ -1528,13 +1530,11 @@ co_IntPostOrSendMessage(HWND hWnd, } } - IntReleaseWindowObject(Window); - return (LRESULT)Result; } LRESULT FASTCALL -co_IntDoSendMessage(HWND Wnd, +co_IntDoSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, @@ -1552,15 +1552,14 @@ co_IntDoSendMessage(HWND Wnd, RtlZeroMemory(&Info, sizeof(NTUSERSENDMESSAGEINFO)); /* FIXME: Call hooks. */ - if (HWND_BROADCAST != Wnd) + if (HWND_BROADCAST != hWnd) { - Window = IntGetWindowObject(Wnd); + Window = UserGetWindowObject(hWnd); if (NULL == Window) { /* Tell usermode to not touch this one */ Info.HandledByKernel = TRUE; MmCopyToCaller(UnsafeInfo, &Info, sizeof(NTUSERSENDMESSAGEINFO)); - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); return 0; } } @@ -1568,7 +1567,7 @@ co_IntDoSendMessage(HWND Wnd, /* FIXME: Check for an exiting window. */ /* See if the current thread can handle the message */ - if (HWND_BROADCAST != Wnd && NULL != PsGetWin32Thread() && + if (HWND_BROADCAST != hWnd && NULL != PsGetWin32Thread() && Window->MessageQueue == PsGetWin32Thread()->MessageQueue) { /* Gather the information usermode needs to call the window proc directly */ @@ -1599,17 +1598,16 @@ co_IntDoSendMessage(HWND Wnd, Info.Ansi = TRUE; Info.Proc = Window->WndProcA; } - IntReleaseWindowObject(Window); } else { /* Must be handled by other thread */ - if (HWND_BROADCAST != Wnd) - { - IntReleaseWindowObject(Window); - } +// if (HWND_BROADCAST != hWnd) +// { +// UserDerefObject(Window); +// } Info.HandledByKernel = TRUE; - UserModeMsg.hwnd = Wnd; + UserModeMsg.hwnd = hWnd; UserModeMsg.message = Msg; UserModeMsg.wParam = wParam; UserModeMsg.lParam = lParam; diff --git a/reactos/subsys/win32k/ntuser/misc.c b/reactos/subsys/win32k/ntuser/misc.c index 07607e4a111..3e0e1c510bd 100644 --- a/reactos/subsys/win32k/ntuser/misc.c +++ b/reactos/subsys/win32k/ntuser/misc.c @@ -182,35 +182,30 @@ NtUserCallOneParam( { case ONEPARAM_ROUTINE_GETMENU: { - PWINDOW_OBJECT WindowObject; + PWINDOW_OBJECT Window; DWORD Result; - WindowObject = IntGetWindowObject((HWND)Param); - if(!WindowObject) + if(!(Window = UserGetWindowObject((HWND)Param))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); RETURN( FALSE); } - Result = (DWORD)WindowObject->IDMenu; + Result = (DWORD)Window->IDMenu; - IntReleaseWindowObject(WindowObject); RETURN( Result); } case ONEPARAM_ROUTINE_ISWINDOWUNICODE: { - PWINDOW_OBJECT WindowObject; + PWINDOW_OBJECT Window; DWORD Result; - WindowObject = IntGetWindowObject((HWND)Param); - if(!WindowObject) + Window = UserGetWindowObject((HWND)Param); + if(!Window) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); RETURN( FALSE); } - Result = WindowObject->Unicode; - IntReleaseWindowObject(WindowObject); + Result = Window->Unicode; RETURN( Result); } @@ -219,32 +214,30 @@ NtUserCallOneParam( case ONEPARAM_ROUTINE_GETWNDCONTEXTHLPID: { - PWINDOW_OBJECT WindowObject; + PWINDOW_OBJECT Window; DWORD Result; - WindowObject = IntGetWindowObject((HWND)Param); - if(!WindowObject) + Window = UserGetWindowObject((HWND)Param); + if(!Window) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); RETURN( FALSE); } - Result = WindowObject->ContextHelpId; + Result = Window->ContextHelpId; - IntReleaseWindowObject(WindowObject); RETURN( Result); } case ONEPARAM_ROUTINE_SWAPMOUSEBUTTON: { - PWINSTATION_OBJECT WinStaObject; + PWINSTATION_OBJECT WinSta; NTSTATUS Status; DWORD Result; Status = IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation, KernelMode, 0, - &WinStaObject); + &WinSta); if (!NT_SUCCESS(Status)) RETURN( (DWORD)FALSE); @@ -252,7 +245,7 @@ NtUserCallOneParam( Result = (DWORD)IntSwapMouseButton(WinStaObject, (BOOL)Param); */ Result = 0; - ObDereferenceObject(WinStaObject); + ObDereferenceObject(WinSta); RETURN( Result); } @@ -267,17 +260,15 @@ NtUserCallOneParam( case ONEPARAM_ROUTINE_GETWINDOWINSTANCE: { - PWINDOW_OBJECT WindowObject; + PWINDOW_OBJECT Window; DWORD Result; - if(!(WindowObject = IntGetWindowObject((HWND)Param))) + if(!(Window = UserGetWindowObject((HWND)Param))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); RETURN( FALSE); } - Result = (DWORD)WindowObject->Instance; - IntReleaseWindowObject(WindowObject); + Result = (DWORD)Window->Instance; RETURN( Result); } @@ -286,7 +277,7 @@ NtUserCallOneParam( case ONEPARAM_ROUTINE_GETCURSORPOSITION: { - PWINSTATION_OBJECT WinStaObject; + PWINSTATION_OBJECT WinSta; NTSTATUS Status; POINT Pos; @@ -295,41 +286,38 @@ NtUserCallOneParam( Status = IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation, KernelMode, 0, - &WinStaObject); + &WinSta); if (!NT_SUCCESS(Status)) RETURN( (DWORD)FALSE); /* FIXME - check if process has WINSTA_READATTRIBUTES */ - IntGetCursorLocation(WinStaObject, &Pos); + IntGetCursorLocation(WinSta, &Pos); Status = MmCopyToCaller((PPOINT)Param, &Pos, sizeof(POINT)); if(!NT_SUCCESS(Status)) { - ObDereferenceObject(WinStaObject); + ObDereferenceObject(WinSta); SetLastNtError(Status); RETURN( FALSE); } - ObDereferenceObject(WinStaObject); + ObDereferenceObject(WinSta); RETURN( (DWORD)TRUE); } case ONEPARAM_ROUTINE_ISWINDOWINDESTROY: { - PWINDOW_OBJECT WindowObject; + PWINDOW_OBJECT Window; DWORD Result; - WindowObject = IntGetWindowObject((HWND)Param); - if(!WindowObject) + if(!(Window = UserGetWindowObject((HWND)Param))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); RETURN( FALSE); } - Result = (DWORD)IntIsWindowInDestroy(WindowObject); + Result = (DWORD)IntIsWindowInDestroy(Window); - IntReleaseWindowObject(WindowObject); RETURN( Result); } @@ -389,7 +377,7 @@ NtUserCallTwoParam( DWORD Routine) { NTSTATUS Status; - PWINDOW_OBJECT WindowObject; + PWINDOW_OBJECT Window; DECLARE_RETURN(DWORD); DPRINT("Enter NtUserCallTwoParam\n"); @@ -496,26 +484,26 @@ NtUserCallTwoParam( case TWOPARAM_ROUTINE_ROS_SHOWWINDOW: { #define WIN_NEEDS_SHOW_OWNEDPOPUP (0x00000040) - PWINDOW_OBJECT Window = IntGetWindowObject((HWND)Param1); + PWINDOW_OBJECT Window; DPRINT1("ROS_SHOWWINDOW\n"); - if (Window == 0) + + if (!(Window = UserGetWindowObject((HWND)Param1))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); RETURN( FALSE); } + if (Param2) { if (!(Window->Flags & WIN_NEEDS_SHOW_OWNEDPOPUP)) { - IntReleaseWindowObject(Window); RETURN( TRUE); } Window->Flags &= ~WIN_NEEDS_SHOW_OWNEDPOPUP; } else Window->Flags |= WIN_NEEDS_SHOW_OWNEDPOPUP; + DPRINT1("ROS_SHOWWINDOW ---> 0x%x\n",Window->Flags); - IntReleaseWindowObject(Window); RETURN( TRUE); } case TWOPARAM_ROUTINE_SWITCHTOTHISWINDOW: @@ -538,16 +526,14 @@ NtUserCallTwoParam( } case TWOPARAM_ROUTINE_SETWNDCONTEXTHLPID: - WindowObject = IntGetWindowObject((HWND)Param1); - if(!WindowObject) + + if(!(Window = UserGetWindowObject((HWND)Param1))) { - SetLastWin32Error(ERROR_INVALID_HANDLE); RETURN( (DWORD)FALSE); } - WindowObject->ContextHelpId = Param2; + Window->ContextHelpId = Param2; - IntReleaseWindowObject(WindowObject); RETURN( (DWORD)TRUE); case TWOPARAM_ROUTINE_SETCARETPOS: @@ -558,9 +544,8 @@ NtUserCallTwoParam( WINDOWINFO wi; DWORD Ret; - if(!(WindowObject = IntGetWindowObject((HWND)Param1))) + if(!(Window = UserGetWindowObject((HWND)Param1))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); RETURN( FALSE); } @@ -572,31 +557,27 @@ NtUserCallTwoParam( Status = MmCopyFromCaller(&wi.cbSize, (PVOID)Param2, sizeof(wi.cbSize)); if(!NT_SUCCESS(Status)) { - IntReleaseWindowObject(WindowObject); SetLastNtError(Status); RETURN( FALSE); } if(wi.cbSize != sizeof(WINDOWINFO)) { - IntReleaseWindowObject(WindowObject); SetLastWin32Error(ERROR_INVALID_PARAMETER); RETURN( FALSE); } #endif - if((Ret = (DWORD)IntGetWindowInfo(WindowObject, &wi))) + if((Ret = (DWORD)IntGetWindowInfo(Window, &wi))) { Status = MmCopyToCaller((PVOID)Param2, &wi, sizeof(WINDOWINFO)); if(!NT_SUCCESS(Status)) { - IntReleaseWindowObject(WindowObject); SetLastNtError(Status); RETURN( FALSE); } } - IntReleaseWindowObject(WindowObject); RETURN( Ret); } @@ -728,12 +709,11 @@ NtUserCallHwndLock( DPRINT("Enter NtUserCallHwndLock\n"); UserEnterExclusive(); - Window = IntGetWindowObject(hWnd); - if (Window == 0) + if (!(Window = UserGetWindowObject(hWnd))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); RETURN( FALSE); } + UserRefObjectCo(Window); /* FIXME: Routine can be 0x53 - 0x5E */ switch (Routine) @@ -744,19 +724,21 @@ NtUserCallHwndLock( case HWNDLOCK_ROUTINE_DRAWMENUBAR: { - PMENU_OBJECT MenuObject; + PMENU_OBJECT Menu; DPRINT("HWNDLOCK_ROUTINE_DRAWMENUBAR\n"); Ret = FALSE; if (!((Window->Style & (WS_CHILD | WS_POPUP)) != WS_CHILD)) break; - MenuObject = IntGetMenuObject((HMENU) Window->IDMenu); - if(MenuObject == NULL) + + if(!(Menu = UserGetMenuObject((HMENU) Window->IDMenu))) break; - MenuObject->MenuInfo.WndOwner = hWnd; - MenuObject->MenuInfo.Height = 0; - IntReleaseMenuObject(MenuObject); + + Menu->MenuInfo.WndOwner = hWnd; + Menu->MenuInfo.Height = 0; + co_WinPosSetWindowPos(Window, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED ); + Ret = TRUE; break; } @@ -774,7 +756,7 @@ NtUserCallHwndLock( break; } - IntReleaseWindowObject(Window); + UserDerefObjectCo(Window); RETURN( Ret); diff --git a/reactos/subsys/win32k/ntuser/msgqueue.c b/reactos/subsys/win32k/ntuser/msgqueue.c index e05c18a21e3..f362cb130f3 100644 --- a/reactos/subsys/win32k/ntuser/msgqueue.c +++ b/reactos/subsys/win32k/ntuser/msgqueue.c @@ -254,14 +254,23 @@ co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT Fi { USHORT Msg = Message->Msg.message; PWINDOW_OBJECT Window = NULL; - HWND CaptureWin; + HWND hCaptureWin; + + ASSERT_REFS_CO(ScopeWin); - CaptureWin = IntGetCaptureWindow(); - if (CaptureWin == NULL) + /* + co_WinPosWindowFromPoint can return a Window, and in that case + that window has a ref that we need to deref. Thats why we add "dummy" + refs in all other cases. + */ + + hCaptureWin = IntGetCaptureWindow(); + if (hCaptureWin == NULL) { if(Msg == WM_MOUSEWHEEL) { - Window = IntGetWindowObject(IntGetFocusWindow()); + Window = UserGetWindowObject(IntGetFocusWindow()); + if (Window) UserRefObject(Window); } else { @@ -269,7 +278,12 @@ co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT Fi if(Window == NULL) { Window = ScopeWin; - IntReferenceWindowObject(Window); + if (Window) UserRefObject(Window); + } + else + { + /* this is the one case where we dont add a ref, since the returned + window is already referenced */ } } } @@ -277,9 +291,12 @@ co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT Fi { /* FIXME - window messages should go to the right window if no buttons are pressed */ - Window = IntGetWindowObject(CaptureWin); + Window = UserGetWindowObject(hCaptureWin); + if (Window) UserRefObject(Window); } + + if (Window == NULL) { if(!FromGlobalQueue) @@ -348,7 +365,7 @@ co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT Fi IntUnLockHardwareMessageQueue(Window->MessageQueue); *Freed = FALSE; - IntReleaseWindowObject(Window); + UserDerefObject(Window); return(FALSE); } @@ -391,7 +408,7 @@ co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT Fi IntUnLockHardwareMessageQueue(Window->MessageQueue); } - IntReleaseWindowObject(Window); + UserDerefObject(Window); *Freed = FALSE; return(FALSE); } @@ -430,7 +447,7 @@ co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT Fi } } - IntReleaseWindowObject(Window); + UserDerefObject(Window); *Freed = FALSE; return(TRUE); } @@ -444,14 +461,15 @@ co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, POINT ScreenPoint; BOOL Accept, Freed; PLIST_ENTRY CurrentEntry; - PWINDOW_OBJECT DesktopWindow; + PWINDOW_OBJECT DesktopWindow = NULL; PVOID WaitObjects[2]; NTSTATUS WaitStatus; - + DECLARE_RETURN(BOOL); + if( !IntGetScreenDC() || PsGetWin32Thread()->MessageQueue == W32kGetPrimitiveMessageQueue() ) { - return FALSE; + RETURN(FALSE); } WaitObjects[1] = MessageQueue->NewMessages; @@ -472,8 +490,10 @@ co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, } while (NT_SUCCESS(WaitStatus) && STATUS_WAIT_0 != WaitStatus); - DesktopWindow = IntGetWindowObject(IntGetDesktopWindow()); - + DesktopWindow = UserGetWindowObject(IntGetDesktopWindow()); + + if (DesktopWindow) UserRefObjectCo(DesktopWindow);//can DesktopWindow be NULL? + /* Process messages in the message queue itself. */ IntLockHardwareMessageQueue(MessageQueue); CurrentEntry = MessageQueue->HardwareMessagesListHead.Flink; @@ -485,6 +505,9 @@ co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, if (Current->Msg.message >= WM_MOUSEFIRST && Current->Msg.message <= WM_MOUSELAST) { + + + Accept = co_MsqTranslateMouseMessage(MessageQueue, hWnd, FilterLow, FilterHigh, Current, Remove, &Freed, DesktopWindow, &ScreenPoint, FALSE); @@ -497,8 +520,8 @@ co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, IntUnLockHardwareMessageQueue(MessageQueue); IntUnLockSystemHardwareMessageQueueLock(FALSE); *Message = Current; - IntReleaseWindowObject(DesktopWindow); - return(TRUE); + + RETURN(TRUE); } } @@ -623,8 +646,8 @@ co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, } IntUnLockSystemHardwareMessageQueueLock(FALSE); *Message = Current; - IntReleaseWindowObject(DesktopWindow); - return(TRUE); + + RETURN(TRUE); } /* If the contents of the queue changed then restart processing. */ if (HardwareMessageQueueStamp != ActiveStamp) @@ -634,7 +657,7 @@ co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, } } } - IntReleaseWindowObject(DesktopWindow); + /* Check if the system message queue is now empty. */ IntLockSystemMessageQueue(OldIrql); if (SystemMessageQueueCount == 0 && IsListEmpty(&HardwareMessageQueueHead)) @@ -644,7 +667,12 @@ co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, IntUnLockSystemMessageQueue(OldIrql); IntUnLockSystemHardwareMessageQueueLock(FALSE); - return(FALSE); + RETURN(FALSE); + +CLEANUP: + if (DesktopWindow) UserDerefObjectCo(DesktopWindow); + + END_CLEANUP; } VOID FASTCALL diff --git a/reactos/subsys/win32k/ntuser/object.c b/reactos/subsys/win32k/ntuser/object.c index 2af6302a6d6..47aebc6b1e0 100644 --- a/reactos/subsys/win32k/ntuser/object.c +++ b/reactos/subsys/win32k/ntuser/object.c @@ -55,6 +55,8 @@ inline static PUSER_HANDLE_ENTRY alloc_user_entry(PUSER_HANDLE_TABLE ht) { PUSER_HANDLE_ENTRY entry; +// DPRINT1("handles used %i\n",usedHandles); + if (ht->freelist) { entry = ht->freelist; diff --git a/reactos/subsys/win32k/ntuser/painting.c b/reactos/subsys/win32k/ntuser/painting.c index 1513ce1c8cd..b489bdd42fc 100644 --- a/reactos/subsys/win32k/ntuser/painting.c +++ b/reactos/subsys/win32k/ntuser/painting.c @@ -164,11 +164,13 @@ co_IntPaintWindows(PWINDOW_OBJECT Window, ULONG Flags) { for (phWnd = List; *phWnd; ++phWnd) { - Window = IntGetWindowObject(*phWnd); + Window = UserGetWindowObject(*phWnd); if (Window && (Window->Style & WS_VISIBLE)) { + UserRefObjectCo(Window); co_IntPaintWindows(Window, Flags); - IntReleaseWindowObject(Window); + UserDerefObjectCo(Window); + } } ExFreePool(List); @@ -344,11 +346,11 @@ IntInvalidateWindows(PWINDOW_OBJECT Window, HRGN hRgn, ULONG Flags) { for (phWnd = List; *phWnd; ++phWnd) { - Child = IntGetWindowObject(*phWnd); - if(!Child) + if(!(Child = UserGetWindowObject(*phWnd))) { continue; } + if (Child->Style & WS_VISIBLE) { /* @@ -362,7 +364,7 @@ IntInvalidateWindows(PWINDOW_OBJECT Window, HRGN hRgn, ULONG Flags) IntInvalidateWindows(Child, hRgnTemp, Flags); NtGdiDeleteObject(hRgnTemp); } - IntReleaseWindowObject(Child); + } ExFreePool(List); } @@ -539,14 +541,12 @@ IntFindWindowToRepaint(HWND hWnd, PW32THREAD Thread) PWINDOW_OBJECT Child; HWND hFoundWnd = NULL; - Window = IntGetWindowObject(hWnd); - if (Window == NULL) + if (!(Window = UserGetWindowObject(hWnd))) return NULL; if (IntIsWindowDirty(Window) && IntWndBelongsToThread(Window, Thread)) { - IntReleaseWindowObject(Window); return hWnd; } @@ -578,8 +578,6 @@ IntFindWindowToRepaint(HWND hWnd, PW32THREAD Thread) } } - IntReleaseWindowObject(Window); - return hFoundWnd; } @@ -613,17 +611,13 @@ IntGetPaintMessage(HWND hWnd, UINT MsgFilterMin, UINT MsgFilterMax, return FALSE; } - Window = IntGetWindowObject(Message->hwnd); - if (Window != NULL) - { - Message->message = WM_PAINT; - Message->wParam = Message->lParam = 0; - IntReleaseWindowObject(Window); + if (!(Window = UserGetWindowObject(Message->hwnd))) + return FALSE; - return TRUE; - } + Message->message = WM_PAINT; + Message->wParam = Message->lParam = 0; - return FALSE; + return TRUE; } static @@ -643,8 +637,9 @@ co_IntFixCaret(PWINDOW_OBJECT Window, LPRECT lprc, UINT flags) WndCaret = UserGetWindowObject(hWndCaret); + //fix: check for WndCaret can be null if (WndCaret == Window || - ((flags & SW_SCROLLCHILDREN) && IntIsChildWindow(Window->hSelf, hWndCaret))) + ((flags & SW_SCROLLCHILDREN) && IntIsChildWindow(Window, WndCaret))) { POINT pt, FromOffset, ToOffset, Offset; RECT rcCaret; @@ -683,7 +678,7 @@ co_IntFixCaret(PWINDOW_OBJECT Window, LPRECT lprc, UINT flags) HDC STDCALL NtUserBeginPaint(HWND hWnd, PAINTSTRUCT* UnsafePs) { - PWINDOW_OBJECT Window; + PWINDOW_OBJECT Window = NULL; PAINTSTRUCT Ps; PROSRGNDATA Rgn; NTSTATUS Status; @@ -692,12 +687,13 @@ NtUserBeginPaint(HWND hWnd, PAINTSTRUCT* UnsafePs) DPRINT("Enter NtUserBeginPaint\n"); UserEnterExclusive(); - if (!(Window = IntGetWindowObject(hWnd))) + if (!(Window = UserGetWindowObject(hWnd))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); RETURN( NULL); } + UserRefObjectCo(Window); + co_UserHideCaret(Window); if (Window->Flags & WINDOWOBJECT_NEED_NCPAINT) @@ -728,7 +724,6 @@ NtUserBeginPaint(HWND hWnd, PAINTSTRUCT* UnsafePs) if (!Ps.hdc) { - IntReleaseWindowObject(Window); RETURN( NULL); } @@ -757,6 +752,7 @@ NtUserBeginPaint(HWND hWnd, PAINTSTRUCT* UnsafePs) { if (Window->Flags & WINDOWOBJECT_NEED_INTERNALPAINT) MsqDecPaintCountQueue(Window->MessageQueue); + IntGetClientRect(Window, &Ps.rcPaint); } Window->Flags &= ~WINDOWOBJECT_NEED_INTERNALPAINT; @@ -771,8 +767,6 @@ NtUserBeginPaint(HWND hWnd, PAINTSTRUCT* UnsafePs) Ps.fErase = FALSE; } - IntReleaseWindowObject(Window); - Status = MmCopyToCaller(UnsafePs, &Ps, sizeof(PAINTSTRUCT)); if (! NT_SUCCESS(Status)) { @@ -783,6 +777,8 @@ NtUserBeginPaint(HWND hWnd, PAINTSTRUCT* UnsafePs) RETURN( Ps.hdc); CLEANUP: + if (Window) UserDerefObjectCo(Window); + DPRINT("Leave NtUserBeginPaint, ret=%i\n",_ret_); UserLeave(); END_CLEANUP; @@ -805,15 +801,16 @@ NtUserEndPaint(HWND hWnd, CONST PAINTSTRUCT* lPs) DPRINT("Enter NtUserEndPaint\n"); UserEnterExclusive(); - if (!(Window = IntGetWindowObject(hWnd))) + if (!(Window = UserGetWindowObject(hWnd))) { RETURN(FALSE); } UserReleaseDC(Window, lPs->hdc); - co_UserShowCaret(Window); - IntReleaseWindowObject(Window); //temp hack + UserRefObjectCo(Window); + co_UserShowCaret(Window); + UserDerefObjectCo(Window); RETURN(TRUE); diff --git a/reactos/subsys/win32k/ntuser/timer.c b/reactos/subsys/win32k/ntuser/timer.c index 70b36f78cf3..df540a274c1 100644 --- a/reactos/subsys/win32k/ntuser/timer.c +++ b/reactos/subsys/win32k/ntuser/timer.c @@ -58,7 +58,7 @@ static ULONG HintIndex = 0; UINT_PTR FASTCALL IntSetTimer(HWND Wnd, UINT_PTR IDEvent, UINT Elapse, TIMERPROC TimerFunc, BOOL SystemTimer) { - PWINDOW_OBJECT WindowObject; + PWINDOW_OBJECT Window; UINT_PTR Ret = 0; DPRINT("IntSetTimer wnd %x id %p elapse %u timerproc %p systemtimer %s\n", @@ -85,22 +85,19 @@ IntSetTimer(HWND Wnd, UINT_PTR IDEvent, UINT Elapse, TIMERPROC TimerFunc, BOOL S } else { - WindowObject = IntGetWindowObject(Wnd); - if (! WindowObject) + if (!(Window = UserGetWindowObject(Wnd))) { DPRINT1("Invalid window handle\n"); - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); return 0; } - if (WindowObject->OwnerThread->ThreadsProcess != PsGetCurrentProcess()) + if (Window->OwnerThread->ThreadsProcess != PsGetCurrentProcess()) { - IntReleaseWindowObject(WindowObject); DPRINT1("Trying to set timer for window in another process (shatter attack?)\n"); SetLastWin32Error(ERROR_ACCESS_DENIED); return 0; } - IntReleaseWindowObject(WindowObject); + Ret = IDEvent; } diff --git a/reactos/subsys/win32k/ntuser/windc.c b/reactos/subsys/win32k/ntuser/windc.c index 7f913ec52ff..14ff2b84d40 100644 --- a/reactos/subsys/win32k/ntuser/windc.c +++ b/reactos/subsys/win32k/ntuser/windc.c @@ -293,11 +293,10 @@ DceUpdateVisRgn(DCE *Dce, PWINDOW_OBJECT Window, ULONG Flags) } else if (Window == NULL) { - DesktopWindow = IntGetWindowObject(IntGetDesktopWindow()); + DesktopWindow = UserGetWindowObject(IntGetDesktopWindow()); if (NULL != DesktopWindow) { hRgnVisible = UnsafeIntCreateRectRgnIndirect(&DesktopWindow->WindowRect); - IntReleaseWindowObject(DesktopWindow); } else { @@ -571,30 +570,20 @@ UserGetDCEx(PWINDOW_OBJECT Window OPTIONAL, HANDLE ClipRegion, ULONG Flags) HDC STDCALL -NtUserGetDCEx(HWND hWnd, HANDLE ClipRegion, ULONG Flags) +NtUserGetDCEx(HWND hWnd OPTIONAL, HANDLE ClipRegion, ULONG Flags) { PWINDOW_OBJECT Wnd=NULL; DECLARE_RETURN(HDC); - HDC ret; DPRINT("Enter NtUserGetDCEx\n"); UserEnterExclusive(); - if (hWnd) + if (hWnd && !(Wnd = UserGetWindowObject(hWnd))) { - if (!(Wnd = IntGetWindowObject(hWnd))) - { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); - RETURN(NULL); - } + RETURN(NULL); } - ret = UserGetDCEx(Wnd, ClipRegion, Flags); - - if (Wnd) - IntReleaseWindowObject(Wnd); - - RETURN(ret); + RETURN( UserGetDCEx(Wnd, ClipRegion, Flags)); CLEANUP: DPRINT("Leave NtUserGetDCEx, ret=%i\n",_ret_); @@ -815,7 +804,7 @@ DceResetActiveDCEs(PWINDOW_OBJECT Window) } else { - CurrentWindow = IntGetWindowObject(pDCE->hwndCurrent); + CurrentWindow = UserGetWindowObject(pDCE->hwndCurrent); if (NULL == CurrentWindow) { pDCE = pDCE->next; @@ -826,14 +815,14 @@ DceResetActiveDCEs(PWINDOW_OBJECT Window) dc = DC_LockDc(pDCE->hDC); if (dc == NULL) { - if (Window->hSelf != pDCE->hwndCurrent) - { - IntReleaseWindowObject(CurrentWindow); - } +// if (Window->hSelf != pDCE->hwndCurrent) +// { +// UserDerefObject(CurrentWindow); +// } pDCE = pDCE->next; continue; } - if (Window == CurrentWindow || IntIsChildWindow(Window->hSelf, CurrentWindow->hSelf)) + if (Window == CurrentWindow || IntIsChildWindow(Window, CurrentWindow)) { if (pDCE->DCXFlags & DCX_WINDOW) { @@ -865,7 +854,7 @@ DceResetActiveDCEs(PWINDOW_OBJECT Window) if (Window->hSelf != pDCE->hwndCurrent) { // IntEngWindowChanged(CurrentWindow, WOC_RGN_CLIENT); - IntReleaseWindowObject(CurrentWindow); +// UserDerefObject(CurrentWindow); } } diff --git a/reactos/subsys/win32k/ntuser/window.c b/reactos/subsys/win32k/ntuser/window.c index 65e9e53f0ff..608669b6140 100644 --- a/reactos/subsys/win32k/ntuser/window.c +++ b/reactos/subsys/win32k/ntuser/window.c @@ -75,23 +75,6 @@ CleanupWindowImpl(VOID) /* HELPER FUNCTIONS ***********************************************************/ -VOID FASTCALL IntReleaseWindowObject(PWINDOW_OBJECT Window) -{ - /* - ASSERT(Window); - - ASSERT(USER_BODY_TO_HEADER(Window)->RefCount >= 1); - - USER_BODY_TO_HEADER(Window)->RefCount--; - - if (USER_BODY_TO_HEADER(Window)->RefCount == 0 && USER_BODY_TO_HEADER(Window)->destroyed) - { - } - */ - - ObmDereferenceObject(Window); -} - PWINDOW_OBJECT FASTCALL IntGetWindowObject(HWND hWnd) { @@ -149,60 +132,49 @@ IntIsWindow(HWND hWnd) { PWINDOW_OBJECT Window; - if (!(Window = IntGetWindowObject(hWnd))) + if (!(Window = UserGetWindowObject(hWnd))) return FALSE; - IntReleaseWindowObject(Window); return TRUE; } - +/* + Caller must NOT dereference retval! + But if caller want the returned value to persist spanning a co_ call, + it must reference the value (because the owner is not garanteed to + exist just because the owned window exist)! +*/ PWINDOW_OBJECT FASTCALL IntGetParent(PWINDOW_OBJECT Wnd) { - HWND hWnd; - if (Wnd->Style & WS_POPUP) { - hWnd = Wnd->hOwner; - return IntGetWindowObject(hWnd); + return UserGetWindowObject(Wnd->hOwner); } else if (Wnd->Style & WS_CHILD) { - PWINDOW_OBJECT par; - - par = Wnd->Parent; - if (par) - IntReferenceWindowObject(par); - return par; - //return IntGetWindowObject(hWnd); + return Wnd->Parent; } return NULL; } + +/* + Caller must NOT dereference retval! + But if caller want the returned value to persist spanning a co_ call, + it must reference the value (because the owner is not garanteed to + exist just because the owned window exist)! +*/ PWINDOW_OBJECT FASTCALL IntGetOwner(PWINDOW_OBJECT Wnd) { - HWND hWnd; - - hWnd = Wnd->hOwner; - - return IntGetWindowObject(hWnd); + return UserGetWindowObject(Wnd->hOwner); } -PWINDOW_OBJECT FASTCALL -IntGetParentObject(PWINDOW_OBJECT Wnd) -{ - PWINDOW_OBJECT par; - par = Wnd->Parent; - if (par) - IntReferenceWindowObject(par); - return par; -} /* * IntWinListChildren @@ -243,41 +215,34 @@ IntWinListChildren(PWINDOW_OBJECT Window) /*********************************************************************** * IntSendDestroyMsg */ -static void IntSendDestroyMsg(HWND Wnd) +static void IntSendDestroyMsg(HWND hWnd) { - PWINDOW_OBJECT Window, Owner, Parent; + PWINDOW_OBJECT Window; #if 0 /* FIXME */ GUITHREADINFO info; if (GetGUIThreadInfo(GetCurrentThreadId(), &info)) { - if (Wnd == info.hwndCaret) + if (hWnd == info.hwndCaret) { DestroyCaret(); } } #endif - Window = IntGetWindowObject(Wnd); + Window = UserGetWindowObject(hWnd); if (Window) { - Owner = IntGetOwner(Window); - if (!Owner) +// UserRefObjectCo(Window); + + if (!IntGetOwner(Window) && !IntGetParent(Window)) { - Parent = IntGetParent(Window); - if (!Parent) - co_IntShellHookNotify(HSHELL_WINDOWDESTROYED, (LPARAM) Wnd); - else - IntReleaseWindowObject(Parent); - } - else - { - IntReleaseWindowObject(Owner); + co_IntShellHookNotify(HSHELL_WINDOWDESTROYED, (LPARAM) hWnd); } - IntReleaseWindowObject(Window); +// UserDerefObjectCo(Window); } /* The window could already be destroyed here */ @@ -286,7 +251,7 @@ static void IntSendDestroyMsg(HWND Wnd) * Send the WM_DESTROY to the window. */ - co_IntSendMessage(Wnd, WM_DESTROY, 0, 0); + co_IntSendMessage(hWnd, WM_DESTROY, 0, 0); /* * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow @@ -375,7 +340,8 @@ static LRESULT co_IntDestroyWindow(PWINDOW_OBJECT Window, } else co_IntDestroyWindow(Child, ProcessData, ThreadData, SendMessages); - IntReleaseWindowObject(Child); + + UserDerefObject(Child); } } ExFreePool(Children); @@ -430,19 +396,17 @@ static LRESULT co_IntDestroyWindow(PWINDOW_OBJECT Window, #endif if (!(Window->Style & WS_CHILD) && Window->IDMenu - && (Menu = IntGetMenuObject((HMENU)Window->IDMenu))) + && (Menu = UserGetMenuObject((HMENU)Window->IDMenu))) { IntDestroyMenuObject(Menu, TRUE, TRUE); Window->IDMenu = 0; - IntReleaseMenuObject(Menu); } if(Window->SystemMenu - && (Menu = IntGetMenuObject(Window->SystemMenu))) + && (Menu = UserGetMenuObject(Window->SystemMenu))) { IntDestroyMenuObject(Menu, TRUE, TRUE); Window->SystemMenu = (HMENU)0; - IntReleaseMenuObject(Menu); } DceFreeWindowDCE(Window); /* Always do this to catch orphaned DCs */ @@ -454,7 +418,7 @@ static LRESULT co_IntDestroyWindow(PWINDOW_OBJECT Window, IntUnlinkWindow(Window); - IntReferenceWindowObject(Window); + UserRefObject(Window); ObmDeleteObject(Window->hSelf, otWindow); IntDestroyScrollBars(Window); @@ -473,7 +437,7 @@ static LRESULT co_IntDestroyWindow(PWINDOW_OBJECT Window, RtlFreeUnicodeString(&Window->WindowName); - IntReleaseWindowObject(Window); + UserDerefObject(Window); return 0; } @@ -597,53 +561,39 @@ IntSetMenu( VOID FASTCALL co_DestroyThreadWindows(struct _ETHREAD *Thread) { + PW32THREAD WThread; PLIST_ENTRY Current; - PW32PROCESS Win32Process; - PW32THREAD Win32Thread; - PWINDOW_OBJECT *List, *pWnd; - ULONG Cnt = 0; + PWINDOW_OBJECT Wnd; - Win32Thread = Thread->Tcb.Win32Thread; - Win32Process = (PW32PROCESS)Thread->ThreadsProcess->Win32Process; - - Current = Win32Thread->WindowListHead.Flink; - while (Current != &(Win32Thread->WindowListHead)) + WThread = Thread->Tcb.Win32Thread; + + while (!IsListEmpty(&WThread->WindowListHead)) { - Cnt++; - Current = Current->Flink; + Current = WThread->WindowListHead.Flink; + Wnd = CONTAINING_RECORD(Current, WINDOW_OBJECT, ThreadListEntry); + + DPRINT1("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd); + + /* window removes itself from the list */ + + /* + fixme: it is critical that the window removes itself! if now, we will loop + here forever... + */ + + //ASSERT(co_UserDestroyWindow(Wnd)); + + UserRefObjectCo(Wnd);//faxme: temp hack?? + if (!co_UserDestroyWindow(Wnd)) + { + DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd); + } + UserDerefObjectCo(Wnd);//faxme: temp hack?? } - - if(Cnt > 0) - { - List = ExAllocatePool(PagedPool, (Cnt + 1) * sizeof(PWINDOW_OBJECT)); - if(!List) - { - DPRINT("Not enough memory to allocate window handle list\n"); - return; - } - pWnd = List; - Current = Win32Thread->WindowListHead.Flink; - while (Current != &(Win32Thread->WindowListHead)) - { - *pWnd = CONTAINING_RECORD(Current, WINDOW_OBJECT, ThreadListEntry); - IntReferenceWindowObject(*pWnd); - pWnd++; - Current = Current->Flink; - } - *pWnd = NULL; - - for(pWnd = List; *pWnd; pWnd++) - { - co_UserDestroyWindow(*pWnd); - IntReleaseWindowObject(*pWnd); - } - ExFreePool(List); - return; - } - } + /*! * Internal function. * Returns client window rectangle relative to the upper-left corner of client area. @@ -698,19 +648,18 @@ IntGetSystemMenu(PWINDOW_OBJECT Window, BOOL bRevert, BOOL RetMenu) if(Window->SystemMenu) { - Menu = IntGetMenuObject(Window->SystemMenu); + Menu = UserGetMenuObject(Window->SystemMenu); if(Menu) { IntDestroyMenuObject(Menu, FALSE, TRUE); Window->SystemMenu = (HMENU)0; - IntReleaseMenuObject(Menu); } } if(W32Thread->Desktop->WindowStation->SystemMenuTemplate) { /* clone system menu */ - Menu = IntGetMenuObject(W32Thread->Desktop->WindowStation->SystemMenuTemplate); + Menu = UserGetMenuObject(W32Thread->Desktop->WindowStation->SystemMenuTemplate); if(!Menu) return NULL; @@ -721,9 +670,8 @@ IntGetSystemMenu(PWINDOW_OBJECT Window, BOOL bRevert, BOOL RetMenu) NewMenu->MenuInfo.Flags |= MF_SYSMENU; NewMenu->MenuInfo.Wnd = Window->hSelf; ret = NewMenu; - //IntReleaseMenuObject(NewMenuObject); + //IntReleaseMenuObject(NewMenu); } - IntReleaseMenuObject(Menu); } else { @@ -794,19 +742,14 @@ IntGetSystemMenu(PWINDOW_OBJECT Window, BOOL bRevert, BOOL RetMenu) BOOL FASTCALL -IntIsChildWindow(HWND Parent, HWND Child) +IntIsChildWindow(PWINDOW_OBJECT Parent, PWINDOW_OBJECT BaseWindow) { - PWINDOW_OBJECT BaseWindow, Window; - - if(!(BaseWindow = UserGetWindowObject(Child))) - { - return FALSE; - } + PWINDOW_OBJECT Window; Window = BaseWindow; while (Window) { - if (Window->hSelf == Parent) + if (Window == Parent) { return(TRUE); } @@ -907,22 +850,21 @@ IntSetOwner(HWND hWnd, HWND hWndNewOwner) if (WndOldOwner) { ret = WndOldOwner->hSelf; - IntReleaseWindowObject(WndOldOwner); + UserDerefObject(WndOldOwner); } else { ret = 0; } - if((WndNewOwner = IntGetWindowObject(hWndNewOwner))) + if((WndNewOwner = UserGetWindowObject(hWndNewOwner))) { Wnd->hOwner = hWndNewOwner; - IntReleaseWindowObject(WndNewOwner); } else Wnd->hOwner = NULL; - IntReleaseWindowObject(Wnd); + UserDerefObject(Wnd); return ret; } @@ -930,7 +872,7 @@ PWINDOW_OBJECT FASTCALL co_IntSetParent(PWINDOW_OBJECT Wnd, PWINDOW_OBJECT WndNewParent) { PWINDOW_OBJECT WndOldParent, Sibling, InsertAfter; - HWND hWnd, hWndNewParent, hWndOldParent; +// HWND hWnd, hWndNewParent; BOOL WasVisible; BOOL MenuChanged; @@ -939,8 +881,8 @@ co_IntSetParent(PWINDOW_OBJECT Wnd, PWINDOW_OBJECT WndNewParent) ASSERT_REFS_CO(Wnd); ASSERT_REFS_CO(WndNewParent); - hWnd = Wnd->hSelf; - hWndNewParent = WndNewParent->hSelf; +// hWnd = Wnd->hSelf; +// hWndNewParent = WndNewParent->hSelf; /* * Windows hides the window first, then shows it again @@ -948,17 +890,18 @@ co_IntSetParent(PWINDOW_OBJECT Wnd, PWINDOW_OBJECT WndNewParent) */ WasVisible = co_WinPosShowWindow(Wnd, SW_HIDE); - /* Validate that window and parent still exist */ - if (!IntIsWindow(hWnd) || !IntIsWindow(hWndNewParent)) - return NULL; +// /* Validate that window and parent still exist */ +// if (!IntIsWindow(hWnd) || !IntIsWindow(hWndNewParent)) +// return NULL; /* Window must belong to current process */ if (Wnd->OwnerThread->ThreadsProcess != PsGetCurrentProcess()) return NULL; - WndOldParent = IntGetParentObject(Wnd); - hWndOldParent = (WndOldParent ? WndOldParent->hSelf : NULL); - + WndOldParent = Wnd->Parent; + + if (WndOldParent) UserRefObject(WndOldParent); /* caller must deref */ + if (WndNewParent != WndOldParent) { IntUnlinkWindow(Wnd); @@ -979,9 +922,9 @@ co_IntSetParent(PWINDOW_OBJECT Wnd, PWINDOW_OBJECT WndNewParent) } else { - IntReferenceWindowObject(InsertAfter); +// UserRefObject(InsertAfter); IntLinkWindow(Wnd, WndNewParent, InsertAfter /*prev sibling*/); - IntReleaseWindowObject(InsertAfter); +// UserDerefObject(InsertAfter); } if (WndNewParent->hSelf != IntGetDesktopWindow()) /* a child window */ @@ -1012,19 +955,20 @@ co_IntSetParent(PWINDOW_OBJECT Wnd, PWINDOW_OBJECT WndNewParent) * Validate that the old parent still exist, since it migth have been * destroyed during the last callbacks to user-mode */ - if(WndOldParent) - { - if(!IntIsWindow(WndOldParent->hSelf)) - { - IntReleaseWindowObject(WndOldParent); - return NULL; - } +// if(WndOldParent) +// { +// if(!IntIsWindow(WndOldParent->hSelf)) +// { +// UserDerefObject(WndOldParent); +// return NULL; +// } /* don't dereference the window object here, it must be done by the caller of IntSetParent() */ - return WndOldParent; - } - return NULL; +// return WndOldParent; +// } + + return WndOldParent;//NULL; } BOOL FASTCALL @@ -1078,9 +1022,8 @@ IntAnyPopup(VOID) { PWINDOW_OBJECT Window, Child; - if(!(Window = IntGetWindowObject(IntGetDesktopWindow()))) + if(!(Window = UserGetWindowObject(IntGetDesktopWindow()))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); return FALSE; } @@ -1092,12 +1035,10 @@ IntAnyPopup(VOID) * The desktop has a popup window if one of them has * an owner window and is visible */ - IntReleaseWindowObject(Window); return TRUE; } } - IntReleaseWindowObject(Window); return FALSE; } @@ -1153,9 +1094,8 @@ NtUserBuildHwndList( if(hwndParent) { PWINDOW_OBJECT Window, Child; - if(!(Window = IntGetWindowObject(hwndParent))) + if(!(Window = UserGetWindowObject(hwndParent))) { - SetLastWin32Error(ERROR_INVALID_HANDLE); return 0; } @@ -1171,8 +1111,6 @@ NtUserBuildHwndList( } } } - - IntReleaseWindowObject(Window); } else if(dwThreadId) { @@ -1239,11 +1177,9 @@ NtUserBuildHwndList( return 0; } } - if(!(Window = IntGetWindowObject(Desktop->DesktopWindow))) + if(!(Window = UserGetWindowObject(Desktop->DesktopWindow))) { - if(hDesktop) - ObDereferenceObject(Desktop); - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); + if(hDesktop) ObDereferenceObject(Desktop); return 0; } @@ -1260,9 +1196,7 @@ NtUserBuildHwndList( } } - IntReleaseWindowObject(Window); - if(hDesktop) - ObDereferenceObject(Desktop); + if(hDesktop) ObDereferenceObject(Desktop); } return dwCount; @@ -1283,9 +1217,8 @@ NtUserChildWindowFromPointEx(HWND hwndParent, HWND Ret; HWND *List, *phWnd; - if(!(Parent = IntGetWindowObject(hwndParent))) + if(!(Parent = UserGetWindowObject(hwndParent))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); return NULL; } @@ -1300,7 +1233,6 @@ NtUserChildWindowFromPointEx(HWND hwndParent, if(!IntPtInWindow(Parent, Pt.x, Pt.y)) { - IntReleaseWindowObject(Parent); return NULL; } @@ -1310,36 +1242,30 @@ NtUserChildWindowFromPointEx(HWND hwndParent, for(phWnd = List; *phWnd; phWnd++) { PWINDOW_OBJECT Child; - if((Child = IntGetWindowObject(*phWnd))) + if((Child = UserGetWindowObject(*phWnd))) { if(!(Child->Style & WS_VISIBLE) && (uiFlags & CWP_SKIPINVISIBLE)) { - IntReleaseWindowObject(Child); continue; } 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->hSelf; - IntReleaseWindowObject(Child); break; } - IntReleaseWindowObject(Child); } } ExFreePool(List); } - IntReleaseWindowObject(Parent); return Ret; } @@ -1464,17 +1390,16 @@ co_IntCreateWindowEx(DWORD dwExStyle, RETURN( (HWND)0); /* WS_CHILD needs a parent, but WS_POPUP doesn't */ } - if (NULL != ParentWindowHandle) - { - ParentWindow = UserGetWindowObject(ParentWindowHandle); +// if (NULL != ParentWindowHandle) +// { + ParentWindow = UserGetWindowObject(ParentWindowHandle); - if (ParentWindow) - UserRefObjectCo(ParentWindow); - } - else - { - ParentWindow = NULL; - } + if (ParentWindow) UserRefObjectCo(ParentWindow); +// } +// else +// { +// ParentWindow = NULL; +// } /* FIXME: parent must belong to the current process */ @@ -1556,13 +1481,14 @@ co_IntCreateWindowEx(DWORD dwExStyle, { IntSetMenu(Window, hMenu, &MenuChanged); } + Window->MessageQueue = PsGetWin32Thread()->MessageQueue; IntReferenceMessageQueue(Window->MessageQueue); Window->Parent = ParentWindow; - if((OwnerWindow = IntGetWindowObject(OwnerWindowHandle))) + + if((OwnerWindow = UserGetWindowObject(OwnerWindowHandle))) { Window->hOwner = OwnerWindowHandle; - IntReleaseWindowObject(OwnerWindow); HasOwner = TRUE; } else @@ -1570,7 +1496,9 @@ co_IntCreateWindowEx(DWORD dwExStyle, Window->hOwner = NULL; HasOwner = FALSE; } + Window->UserData = 0; + if ((((DWORD)Class->lpfnWndProcA & 0xFFFF0000) != 0xFFFF0000) && (((DWORD)Class->lpfnWndProcW & 0xFFFF0000) != 0xFFFF0000)) { @@ -1856,6 +1784,8 @@ co_IntCreateWindowEx(DWORD dwExStyle, Result = co_WinPosGetNonClientSize(Window, &Window->WindowRect, &Window->ClientRect); + + IntGdiOffsetRect(&Window->WindowRect, MaxPos.x - Window->WindowRect.left, MaxPos.y - Window->WindowRect.top); @@ -1866,22 +1796,21 @@ co_IntCreateWindowEx(DWORD dwExStyle, if ((dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) { PWINDOW_OBJECT PrevSibling; - if((PrevSibling = ParentWindow->LastChild)) - IntReferenceWindowObject(PrevSibling); + + PrevSibling = ParentWindow->LastChild; + /* link window as bottom sibling */ IntLinkWindow(Window, ParentWindow, PrevSibling /*prev sibling*/); - if(PrevSibling) - IntReleaseWindowObject(PrevSibling); } else { /* link window as top sibling (but after topmost siblings) */ PWINDOW_OBJECT InsertAfter, Sibling; - if (0 == (dwExStyle & WS_EX_TOPMOST)) + if (!(dwExStyle & WS_EX_TOPMOST)) { InsertAfter = NULL; Sibling = ParentWindow->FirstChild; - while (NULL != Sibling && 0 != (Sibling->ExStyle & WS_EX_TOPMOST)) + while (Sibling && (Sibling->ExStyle & WS_EX_TOPMOST)) { InsertAfter = Sibling; Sibling = Sibling->NextSibling; @@ -1891,21 +1820,17 @@ co_IntCreateWindowEx(DWORD dwExStyle, { InsertAfter = NULL; } - if (NULL != InsertAfter) - { - IntReferenceWindowObject(InsertAfter); - } + IntLinkWindow(Window, ParentWindow, InsertAfter /* prev sibling */); - if (NULL != InsertAfter) - { - IntReleaseWindowObject(InsertAfter); - } + } } /* Send the WM_CREATE message. */ DPRINT("IntCreateWindowEx(): about to send CREATE message.\n"); Result = co_IntSendMessage(Window->hSelf, WM_CREATE, 0, (LPARAM) &Cs); + + if (Result == (LRESULT)-1) { /* FIXME: Cleanup. */ @@ -1914,6 +1839,7 @@ co_IntCreateWindowEx(DWORD dwExStyle, RETURN((HWND)0); } + /* Send move and size messages. */ if (!(Window->Flags & WINDOWOBJECT_NEED_SIZE)) { @@ -1927,6 +1853,7 @@ co_IntCreateWindowEx(DWORD dwExStyle, DPRINT("Sending bogus WM_SIZE\n"); } + lParam = MAKE_LONG(Window->ClientRect.right - Window->ClientRect.left, Window->ClientRect.bottom - @@ -1934,6 +1861,7 @@ co_IntCreateWindowEx(DWORD dwExStyle, co_IntSendMessage(Window->hSelf, WM_SIZE, SIZE_RESTORED, lParam); + DPRINT("IntCreateWindow(): About to send WM_MOVE\n"); if (0 != (Window->Style & WS_CHILD) && ParentWindow) @@ -1946,10 +1874,15 @@ co_IntCreateWindowEx(DWORD dwExStyle, lParam = MAKE_LONG(Window->ClientRect.left, Window->ClientRect.top); } + + co_IntSendMessage(Window->hSelf, WM_MOVE, 0, lParam); + /* Call WNDOBJ change procs */ IntEngWindowChanged(Window, WOC_RGN_CLIENT); + + } /* Show or maybe minimize or maximize the window. */ @@ -2013,10 +1946,8 @@ co_IntCreateWindowEx(DWORD dwExStyle, RETURN((HWND)Handle); CLEANUP: - if (Window) - UserDerefObjectCo(Window); - if (ParentWindow) - UserDerefObjectCo(ParentWindow); + if (Window) UserDerefObjectCo(Window); + if (ParentWindow) UserDerefObjectCo(ParentWindow); END_CLEANUP; } @@ -2122,12 +2053,7 @@ BOOLEAN FASTCALL co_UserDestroyWindow(PWINDOW_OBJECT Window) { BOOLEAN isChild; - ASSERT_REFS_CO(Window); - - if (Window == NULL) - { - return FALSE; - } + ASSERT_REFS_CO(Window); //fixme: temp hack? /* Check for owner thread and desktop window */ if ((Window->OwnerThread != PsGetCurrentThread()) || IntIsDesktopWindow(Window)) @@ -2198,26 +2124,28 @@ BOOLEAN FASTCALL co_UserDestroyWindow(PWINDOW_OBJECT Window) HWND *ChildHandle; PWINDOW_OBJECT Child, Desktop; - Desktop = IntGetWindowObject(IntGetDesktopWindow()); + Desktop = UserGetWindowObject(IntGetDesktopWindow()); Children = IntWinListChildren(Desktop); - IntReleaseWindowObject(Desktop); + if (Children) { for (ChildHandle = Children; *ChildHandle; ++ChildHandle) { - Child = IntGetWindowObject(*ChildHandle); + Child = UserGetWindowObject(*ChildHandle); if (Child == NULL) continue; if (Child->hOwner != Window->hSelf) { - IntReleaseWindowObject(Child); continue; } if (IntWndBelongsToThread(Child, PsGetWin32Thread())) { + + UserRefObjectCo(Child);//temp hack? co_UserDestroyWindow(Child); - IntReleaseWindowObject(Child); + UserDerefObjectCo(Child);//temp hack? + GotOne = TRUE; continue; } @@ -2227,7 +2155,6 @@ BOOLEAN FASTCALL co_UserDestroyWindow(PWINDOW_OBJECT Window) Child->hOwner = NULL; } - IntReleaseWindowObject(Child); } ExFreePool(Children); } @@ -2260,18 +2187,22 @@ NtUserDestroyWindow(HWND Wnd) { PWINDOW_OBJECT Window; DECLARE_RETURN(BOOLEAN); + BOOLEAN ret; DPRINT("Enter NtUserDestroyWindow\n"); UserEnterExclusive(); - Window = IntGetWindowObject(Wnd); - if (Window == NULL) + if (!(Window = UserGetWindowObject(Wnd))) { RETURN(FALSE); } - RETURN(co_UserDestroyWindow(Window)); + UserRefObjectCo(Window);//faxme: dunno if win should be reffed during destroy.. + ret = co_UserDestroyWindow(Window); + UserDerefObjectCo(Window);//faxme: dunno if win should be reffed during destroy.. + RETURN(ret); + CLEANUP: DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_); UserLeave(); @@ -2354,7 +2285,7 @@ IntFindWindow(PWINDOW_OBJECT Parent, while(*phWnd) { PWINDOW_OBJECT Child; - if(!(Child = IntGetWindowObject(*(phWnd++)))) + if(!(Child = UserGetWindowObject(*(phWnd++)))) { continue; } @@ -2366,11 +2297,9 @@ IntFindWindow(PWINDOW_OBJECT Parent, (!ClassAtom || Child->Class->Atom == ClassAtom)) { Ret = Child->hSelf; - IntReleaseWindowObject(Child); break; } - IntReleaseWindowObject(Child); } ExFreePool(List); } @@ -2429,17 +2358,14 @@ NtUserFindWindowEx(HWND hwndParent, } */ - if(!(Parent = IntGetWindowObject(hwndParent))) + if(!(Parent = UserGetWindowObject(hwndParent))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); RETURN( NULL); } ChildAfter = NULL; - if(hwndChildAfter && !(ChildAfter = IntGetWindowObject(hwndChildAfter))) + if(hwndChildAfter && !(ChildAfter = UserGetWindowObject(hwndChildAfter))) { - IntReleaseWindowObject(Parent); - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); RETURN( NULL); } @@ -2537,7 +2463,7 @@ NtUserFindWindowEx(HWND hwndParent, /* search children */ while(*phWnd) { - if(!(TopLevelWindow = IntGetWindowObject(*(phWnd++)))) + if(!(TopLevelWindow = UserGetWindowObject(*(phWnd++)))) { continue; } @@ -2553,7 +2479,6 @@ NtUserFindWindowEx(HWND hwndParent, if (WindowMatches && ClassMatches) { Ret = TopLevelWindow->hSelf; - IntReleaseWindowObject(TopLevelWindow); break; } @@ -2562,11 +2487,9 @@ NtUserFindWindowEx(HWND hwndParent, /* window returns the handle of the top-level window, in case it found the child window */ Ret = TopLevelWindow->hSelf; - IntReleaseWindowObject(TopLevelWindow); break; } - IntReleaseWindowObject(TopLevelWindow); } ExFreePool(List); } @@ -2583,10 +2506,9 @@ NtUserFindWindowEx(HWND hwndParent, Parent is the desktop window??? */ PWINDOW_OBJECT MsgWindows; - if((MsgWindows = IntGetWindowObject(IntGetMessageWindow()))) + if((MsgWindows = UserGetWindowObject(IntGetMessageWindow()))) { Ret = IntFindWindow(MsgWindows, ChildAfter, ClassAtom, &WindowName); - IntReleaseWindowObject(MsgWindows); } } #endif @@ -2599,9 +2521,6 @@ Cleanup2: RtlFreeUnicodeString(&WindowName); Cleanup3: - if(ChildAfter) - IntReleaseWindowObject(ChildAfter); - IntReleaseWindowObject(Parent); RETURN( Ret); @@ -2673,7 +2592,8 @@ PWINDOW_OBJECT FASTCALL UserGetAncestor(PWINDOW_OBJECT Wnd, UINT Type) for (;;) { - PWINDOW_OBJECT Old; + PWINDOW_OBJECT Parent, Old; + Old = WndAncestor; Parent = IntGetParent(WndAncestor); @@ -2683,7 +2603,7 @@ PWINDOW_OBJECT FASTCALL UserGetAncestor(PWINDOW_OBJECT Wnd, UINT Type) } //temp hack - UserDerefObject(Parent); +// UserDerefObject(Parent); WndAncestor = Parent; } @@ -2749,14 +2669,12 @@ NtUserGetClientRect(HWND hWnd, LPRECT Rect) DPRINT("Enter NtUserGetClientRect\n"); UserEnterShared(); - if(!(Window = IntGetWindowObject(hWnd))) + if(!(Window = UserGetWindowObject(hWnd))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); RETURN( FALSE); } IntGetClientRect(Window, &SafeRect); - IntReleaseWindowObject(Window); if(!NT_SUCCESS(MmCopyToCaller(Rect, &SafeRect, sizeof(RECT)))) { @@ -2820,19 +2738,13 @@ NtUserGetLastActivePopup(HWND hWnd) PWINDOW_OBJECT Wnd; HWND hWndLastPopup; - IntAcquireWinLockShared(); - - if (!(Wnd = IntGetWindowObject(hWnd))) + if (!(Wnd = UserGetWindowObject(hWnd))) { - IntReleaseWinLock(); - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); return NULL; } hWndLastPopup = Wnd->hWndLastPopup; - IntReleaseWinLock(); - return hWndLastPopup; #else @@ -2864,9 +2776,8 @@ NtUserGetParent(HWND hWnd) DPRINT("Enter NtUserGetParent\n"); UserEnterExclusive(); - if (!(Wnd = IntGetWindowObject(hWnd))) + if (!(Wnd = UserGetWindowObject(hWnd))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); RETURN( NULL); } @@ -2874,11 +2785,8 @@ NtUserGetParent(HWND hWnd) if (WndParent) { hWndParent = WndParent->hSelf; - IntReleaseWindowObject(WndParent); } - IntReleaseWindowObject(Wnd); - RETURN( hWndParent); CLEANUP: @@ -2910,39 +2818,38 @@ co_UserSetParent(HWND hWndChild, HWND hWndNewParent) if (hWndNewParent) { - if (!(WndParent = IntGetWindowObject(hWndNewParent))) + if (!(WndParent = UserGetWindowObject(hWndNewParent))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); return( NULL); } } else { - if (!(WndParent = IntGetWindowObject(IntGetDesktopWindow()))) + if (!(WndParent = UserGetWindowObject(IntGetDesktopWindow()))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); return( NULL); } } - if (!(Wnd = IntGetWindowObject(hWndChild))) + if (!(Wnd = UserGetWindowObject(hWndChild))) { - IntReleaseWindowObject(WndParent); - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); return( NULL); } + UserRefObjectCo(Wnd); + UserRefObjectCo(WndParent); + WndOldParent = co_IntSetParent(Wnd, WndParent); + + UserDerefObjectCo(WndParent); + UserDerefObjectCo(Wnd); if (WndOldParent) { hWndOldParent = WndOldParent->hSelf; - IntReleaseWindowObject(WndOldParent); + UserDerefObject(WndOldParent); } - IntReleaseWindowObject(Wnd); - IntReleaseWindowObject(WndParent); - return( hWndOldParent); } @@ -3193,9 +3100,8 @@ NtUserSetSystemMenu(HWND hWnd, HMENU hMenu) DPRINT("Enter NtUserSetSystemMenu\n"); UserEnterExclusive(); - if (!(Window = IntGetWindowObject(hWnd))) + if (!(Window = UserGetWindowObject(hWnd))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); RETURN( FALSE); } @@ -3204,21 +3110,14 @@ NtUserSetSystemMenu(HWND hWnd, HMENU hMenu) /* * Assign new menu handle. */ - Menu = IntGetMenuObject(hMenu); - if (!Menu) + if (!(Menu = UserGetMenuObject(hMenu))) { - IntReleaseWindowObject(Window); - SetLastWin32Error(ERROR_INVALID_MENU_HANDLE); RETURN( FALSE); } Result = IntSetSystemMenu(Window, Menu); - - IntReleaseMenuObject(Menu); } - IntReleaseWindowObject(Window); - RETURN( Result); CLEANUP: @@ -3268,10 +3167,9 @@ UserGetWindow(HWND hWnd, UINT Relationship) break; case GW_OWNER: - if((Parent = IntGetWindowObject(Window->hOwner))) + if((Parent = UserGetWindowObject(Window->hOwner))) { hWndResult = Parent->hSelf; - IntReleaseWindowObject(Parent); } break; case GW_CHILD: @@ -3333,9 +3231,8 @@ UserGetWindowLong(HWND hWnd, DWORD Index, BOOL Ansi) DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd, (INT)Index, Ansi); - if (!(Window = IntGetWindowObject(hWnd))) + if (!(Window = UserGetWindowObject(hWnd))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); return 0; } @@ -3408,8 +3305,6 @@ UserGetWindowLong(HWND hWnd, DWORD Index, BOOL Ansi) } } - IntReleaseWindowObject(Window); - return Result; } @@ -3460,9 +3355,8 @@ co_UserSetWindowLong(HWND hWnd, DWORD Index, LONG NewValue, BOOL Ansi) return( 0); } - if (!(Window = IntGetWindowObject(hWnd))) + if (!(Window = UserGetWindowObject(hWnd))) { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); return( 0); } @@ -3471,7 +3365,6 @@ co_UserSetWindowLong(HWND hWnd, DWORD Index, LONG NewValue, BOOL Ansi) if ((Index + sizeof(LONG)) > Window->ExtraDataSize) { SetLastWin32Error(ERROR_INVALID_PARAMETER); - IntReleaseWindowObject(Window); return( 0); } OldValue = *((LONG *)(Window->ExtraData + Index)); @@ -3534,13 +3427,11 @@ co_UserSetWindowLong(HWND hWnd, DWORD Index, LONG NewValue, BOOL Ansi) break; case GWL_HWNDPARENT: - Parent = IntGetParentObject(Window); + Parent = Window->Parent; if (Parent && (Parent->hSelf == IntGetDesktopWindow())) OldValue = (LONG) IntSetOwner(Window->hSelf, (HWND) NewValue); else OldValue = (LONG) co_UserSetParent(Window->hSelf, (HWND) NewValue); - if(Parent) - IntReleaseWindowObject(Parent); break; case GWL_ID: @@ -3561,8 +3452,6 @@ co_UserSetWindowLong(HWND hWnd, DWORD Index, LONG NewValue, BOOL Ansi) } } - IntReleaseWindowObject(Window); - return( OldValue); } @@ -3614,12 +3503,17 @@ NtUserSetWindowWord(HWND hWnd, INT Index, WORD NewValue) DPRINT("Enter NtUserSetWindowWord\n"); UserEnterExclusive(); + if (!(Window = UserGetWindowObject(hWnd))) + { + RETURN( 0); + } + switch (Index) { case GWL_ID: case GWL_HINSTANCE: case GWL_HWNDPARENT: - RETURN( co_UserSetWindowLong(hWnd, Index, (UINT)NewValue, TRUE)); + RETURN( co_UserSetWindowLong(Window->hSelf, Index, (UINT)NewValue, TRUE)); default: if (Index < 0) { @@ -3628,24 +3522,15 @@ NtUserSetWindowWord(HWND hWnd, INT Index, WORD NewValue) } } - if (!(Window = IntGetWindowObject(hWnd))) - { - SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); - RETURN( 0); - } - if (Index > Window->ExtraDataSize - sizeof(WORD)) { SetLastWin32Error(ERROR_INVALID_PARAMETER); - IntReleaseWindowObject(Window); RETURN( 0); } OldValue = *((WORD *)(Window->ExtraData + Index)); *((WORD *)(Window->ExtraData + Index)) = NewValue; - IntReleaseWindowObject(Window); - RETURN( OldValue); CLEANUP: @@ -4350,35 +4235,39 @@ NtUserWindowFromPoint(LONG X, LONG Y) { POINT pt; HWND Ret; - PWINDOW_OBJECT DesktopWindow, Window = NULL; + PWINDOW_OBJECT DesktopWindow = NULL, Window = NULL; DECLARE_RETURN(HWND); DPRINT("Enter NtUserWindowFromPoint\n"); UserEnterExclusive(); - if ((DesktopWindow = IntGetWindowObject(IntGetDesktopWindow()))) + if ((DesktopWindow = UserGetWindowObject(IntGetDesktopWindow()))) { USHORT Hit; pt.x = X; pt.y = Y; + //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window + //its possible this referencing is useless, thou it shouldnt hurt... + UserRefObjectCo(DesktopWindow); + Hit = co_WinPosWindowFromPoint(DesktopWindow, PsGetWin32Thread()->MessageQueue, &pt, &Window); - + if(Window) { Ret = Window->hSelf; - IntReleaseWindowObject(Window); - IntReleaseWindowObject(DesktopWindow); + RETURN( Ret); } - - IntReleaseWindowObject(DesktopWindow); } RETURN( NULL); CLEANUP: + if (Window) UserDerefObject(Window); + if (DesktopWindow) UserDerefObjectCo(DesktopWindow); + DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_); UserLeave(); END_CLEANUP; @@ -4399,7 +4288,7 @@ CLEANUP: BOOL STDCALL NtUserDefSetText(HWND hWnd, PUNICODE_STRING WindowText) { - PWINDOW_OBJECT Window, Parent, Owner; + PWINDOW_OBJECT Window; UNICODE_STRING SafeText; NTSTATUS Status; DECLARE_RETURN(INT); @@ -4432,25 +4321,11 @@ NtUserDefSetText(HWND hWnd, PUNICODE_STRING WindowText) Window->WindowName = SafeText; /* Send shell notifications */ - - Owner = IntGetOwner(Window); - Parent = IntGetParent(Window); - - if ((!Owner) && (!Parent)) + if (!IntGetOwner(Window) && !IntGetParent(Window)) { co_IntShellHookNotify(HSHELL_REDRAW, (LPARAM) hWnd); } - if (Owner) - { - IntReleaseWindowObject(Owner); - } - - if (Parent) - { - IntReleaseWindowObject(Parent); - } - RETURN( TRUE); CLEANUP: diff --git a/reactos/subsys/win32k/ntuser/winpos.c b/reactos/subsys/win32k/ntuser/winpos.c index 58c9b33dc78..b56fb1dd9b3 100644 --- a/reactos/subsys/win32k/ntuser/winpos.c +++ b/reactos/subsys/win32k/ntuser/winpos.c @@ -126,7 +126,8 @@ CLEANUP: * * Check if we can activate the specified window. */ -static BOOL FASTCALL can_activate_window( PWINDOW_OBJECT Wnd ) +static +BOOL FASTCALL can_activate_window( PWINDOW_OBJECT Wnd OPTIONAL) { LONG style; @@ -144,65 +145,54 @@ static BOOL FASTCALL can_activate_window( PWINDOW_OBJECT Wnd ) * Activates window other than pWnd. */ VOID FASTCALL -co_WinPosActivateOtherWindow(PWINDOW_OBJECT Window OPTIONAL) +co_WinPosActivateOtherWindow(PWINDOW_OBJECT Window) { - PWINDOW_OBJECT Wnd; + PWINDOW_OBJECT WndTo = NULL; HWND Fg; - if (Window) - ASSERT_REFS_CO(Window); + ASSERT_REFS_CO(Window); - if (!Window || IntIsDesktopWindow(Window)) + if (IntIsDesktopWindow(Window)) { IntSetFocusMessageQueue(NULL); return; } /* If this is popup window, try to activate the owner first. */ - if ((Window->Style & WS_POPUP) && (Wnd = IntGetOwner(Window))) + if ((Window->Style & WS_POPUP) && (WndTo = IntGetOwner(Window))) { - Wnd = UserGetAncestor( Wnd, GA_ROOT ); - if (can_activate_window(Wnd)) goto done; + WndTo = UserGetAncestor( WndTo, GA_ROOT ); + if (can_activate_window(WndTo)) goto done; } /* Pick a next top-level window. */ /* FIXME: Search for non-tooltip windows first. */ - Wnd = Window; - while (Wnd != NULL) + WndTo = Window; + for (;;) { - if (Wnd->NextSibling == NULL) - { - Wnd = NULL; - break; - } - - Wnd = Wnd->NextSibling; - - if ((Wnd->Style & (WS_DISABLED | WS_VISIBLE)) == WS_VISIBLE && - (Wnd->Style & (WS_POPUP | WS_CHILD)) != WS_CHILD) - break; + if (!(WndTo = WndTo->NextSibling)) break; + if (can_activate_window( WndTo )) break; } done: - if (Wnd) - UserRefObjectCo(Wnd); + if (WndTo) UserRefObjectCo(WndTo); Fg = UserGetForegroundWindow(); - if (Wnd && (!Fg || Window->hSelf == Fg)) + if ((!Fg || Window->hSelf == Fg) && WndTo)//fixme: ok if WndTo is NULL?? { - if (co_IntSetForegroundWindow(Wnd)) + /* fixme: wine can pass WndTo=NULL to co_IntSetForegroundWindow. hmm */ + if (co_IntSetForegroundWindow(WndTo)) { - UserDerefObjectCo(Wnd); + UserDerefObjectCo(WndTo); return; } } - if (!co_IntSetActiveWindow(Wnd)) + if (!co_IntSetActiveWindow(WndTo)) /* ok for WndTo to be NULL here */ co_IntSetActiveWindow(0); - if (Wnd) - UserDerefObjectCo(Wnd); + if (WndTo) UserDerefObjectCo(WndTo); } @@ -419,6 +409,7 @@ co_WinPosMinMaximize(PWINDOW_OBJECT Window, UINT ShowFlag, RECT* NewPos) return(SwpFlags); } +static VOID FASTCALL WinPosFillMinMaxInfoStruct(PWINDOW_OBJECT Window, MINMAXINFO *Info) { @@ -480,7 +471,8 @@ co_WinPosGetMinMaxInfo(PWINDOW_OBJECT Window, POINT* MaxSize, POINT* MaxPos, return 0; //FIXME: what does it return? } -STATIC VOID FASTCALL +static +VOID FASTCALL FixClientRect(PRECT ClientRect, PRECT WindowRect) { if (ClientRect->left < WindowRect->left) @@ -517,7 +509,8 @@ FixClientRect(PRECT ClientRect, PRECT WindowRect) } } -LONG STATIC FASTCALL +static +LONG FASTCALL co_WinPosDoNCCALCSize(PWINDOW_OBJECT Window, PWINDOWPOS WinPos, RECT* WindowRect, RECT* ClientRect) { @@ -592,6 +585,7 @@ co_WinPosDoNCCALCSize(PWINDOW_OBJECT Window, PWINDOWPOS WinPos, return wvrFlags; } +static BOOL FASTCALL co_WinPosDoWinPosChanging(PWINDOW_OBJECT Window, PWINDOWPOS WinPos, @@ -646,6 +640,7 @@ co_WinPosDoWinPosChanging(PWINDOW_OBJECT Window, * Fix Z order taking into account owned popups - * basically we need to maintain them above the window that owns them */ +static HWND FASTCALL WinPosDoOwnedPopups(HWND hWnd, HWND hWndInsertAfter) { @@ -662,9 +657,9 @@ WinPosDoOwnedPopups(HWND hWnd, HWND hWndInsertAfter) if (hWndInsertAfter != HWND_TOPMOST) { - DesktopWindow = IntGetWindowObject(IntGetDesktopWindow()); + DesktopWindow = UserGetWindowObject(IntGetDesktopWindow()); List = IntWinListChildren(DesktopWindow); - IntReleaseWindowObject(DesktopWindow); + if (List != NULL) { for (i = 0; List[i]; i++) @@ -673,15 +668,13 @@ WinPosDoOwnedPopups(HWND hWnd, HWND hWndInsertAfter) break; if (HWND_TOP == hWndInsertAfter) { - ChildObject = IntGetWindowObject(List[i]); + ChildObject = UserGetWindowObject(List[i]); if (NULL != ChildObject) { if (0 == (ChildObject->ExStyle & WS_EX_TOPMOST)) { - IntReleaseWindowObject(ChildObject); break; } - IntReleaseWindowObject(ChildObject); } } if (List[i] != hWnd) @@ -700,9 +693,8 @@ WinPosDoOwnedPopups(HWND hWnd, HWND hWndInsertAfter) if (!List) { - DesktopWindow = IntGetWindowObject(IntGetDesktopWindow()); + DesktopWindow = UserGetWindowObject(IntGetDesktopWindow()); List = IntWinListChildren(DesktopWindow); - IntReleaseWindowObject(DesktopWindow); } if (List != NULL) { @@ -741,7 +733,8 @@ WinPosDoOwnedPopups(HWND hWnd, HWND hWndInsertAfter) * Update WindowRect and ClientRect of Window and all of its children * We keep both WindowRect and ClientRect in screen coordinates internally */ -VOID STATIC FASTCALL +static +VOID FASTCALL WinPosInternalMoveWindow(PWINDOW_OBJECT Window, INT MoveX, INT MoveY) { PWINDOW_OBJECT Child; @@ -767,7 +760,7 @@ WinPosInternalMoveWindow(PWINDOW_OBJECT Window, INT MoveX, INT MoveY) * * Fix redundant flags and values in the WINDOWPOS structure. */ - +static BOOL FASTCALL WinPosFixupFlags(WINDOWPOS *WinPos, PWINDOW_OBJECT Window) { @@ -999,14 +992,14 @@ co_WinPosSetWindowPos( } if (NULL != InsertAfterWindow) { - IntReferenceWindowObject(InsertAfterWindow); + UserRefObject(InsertAfterWindow); } } else if (WinPos.hwndInsertAfter == HWND_BOTTOM) { if(ParentWindow->LastChild) { - IntReferenceWindowObject(ParentWindow->LastChild); + UserRefObject(ParentWindow->LastChild); InsertAfterWindow = ParentWindow->LastChild; } else @@ -1022,7 +1015,7 @@ co_WinPosSetWindowPos( IntLinkWindow(Window, ParentWindow, InsertAfterWindow); } if (InsertAfterWindow != NULL) - IntReleaseWindowObject(InsertAfterWindow); + UserDerefObject(InsertAfterWindow); if ((HWND_TOPMOST == WinPos.hwndInsertAfter) || (0 != (Window->ExStyle & WS_EX_TOPMOST) && NULL != Window->PrevSibling @@ -1395,6 +1388,8 @@ co_WinPosShowWindow(PWINDOW_OBJECT Window, INT Cmd) if (Cmd == SW_HIDE) { + PWINDOW_OBJECT ThreadFocusWindow; + /* FIXME: This will cause the window to be activated irrespective * of whether it is owned by the same thread. Has to be done * asynchronously. @@ -1405,9 +1400,13 @@ co_WinPosShowWindow(PWINDOW_OBJECT Window, INT Cmd) co_WinPosActivateOtherWindow(Window); } + + //temphack + ThreadFocusWindow = UserGetWindowObject(IntGetThreadFocusWindow()); + /* Revert focus to parent */ - if (Window->hSelf == IntGetThreadFocusWindow() || - IntIsChildWindow(Window->hSelf, IntGetThreadFocusWindow())) + if (ThreadFocusWindow && (Window == ThreadFocusWindow || + IntIsChildWindow(Window, ThreadFocusWindow))) { //faxme: as long as we have ref on Window, we also, indirectly, have ref on parent... co_UserSetFocus(Window->Parent); @@ -1457,10 +1456,43 @@ co_WinPosShowWindow(PWINDOW_OBJECT Window, INT Cmd) return(WasVisible); } -STATIC VOID FASTCALL + +#if 0 + +/* find child of 'parent' that contains the given point (in parent-relative coords) */ +PWINDOW_OBJECT child_window_from_point(PWINDOW_OBJECT parent, int x, int y ) +{ + PWINDOW_OBJECT Wnd;// = parent->FirstChild; + +// LIST_FOR_EACH_ENTRY( Wnd, &parent->children, struct window, entry ) + for (Wnd = parent->FirstChild; Wnd; Wnd = Wnd->NextSibling) + { + if (!IntPtInWindow( Wnd, x, y )) continue; /* skip it */ + + /* if window is minimized or disabled, return at once */ + if (Wnd->Style & (WS_MINIMIZE|WS_DISABLED)) return Wnd; + + /* if point is not in client area, return at once */ + if (x < Wnd->ClientRect.left || x >= Wnd->ClientRect.right || + y < Wnd->ClientRect.top || y >= Wnd->ClientRect.bottom) + return Wnd; + + return child_window_from_point( Wnd, x - Wnd->ClientRect.left, y - Wnd->ClientRect.top ); + } + return parent; /* not found any child */ +} +#endif + + +static +VOID FASTCALL co_WinPosSearchChildren( - PWINDOW_OBJECT ScopeWin, PUSER_MESSAGE_QUEUE OnlyHitTests, POINT *Point, - PWINDOW_OBJECT* Window, USHORT *HitTest) + PWINDOW_OBJECT ScopeWin, + PUSER_MESSAGE_QUEUE OnlyHitTests, + POINT *Point, + PWINDOW_OBJECT* Window, + USHORT *HitTest + ) { PWINDOW_OBJECT Current; HWND *List, *phWnd; @@ -1471,50 +1503,52 @@ co_WinPosSearchChildren( { for (phWnd = List; *phWnd; ++phWnd) { - if (!(Current = IntGetWindowObject(*phWnd))) + if (!(Current = UserGetWindowObject(*phWnd))) continue; if (!(Current->Style & WS_VISIBLE)) { - IntReleaseWindowObject(Current); continue; } if ((Current->Style & (WS_POPUP | WS_CHILD | WS_DISABLED)) == (WS_CHILD | WS_DISABLED)) { - IntReleaseWindowObject(Current); continue; } if (!IntPtInWindow(Current, Point->x, Point->y)) { - IntReleaseWindowObject(Current); continue; } - if (*Window) - IntReleaseWindowObject(*Window); *Window = Current; - + if (Current->Style & WS_MINIMIZE) { *HitTest = HTCAPTION; + UserRefObject(Current); break; } if (Current->Style & WS_DISABLED) { *HitTest = HTERROR; + UserRefObject(Current); break; } + UserRefObjectCo(Current); + if (OnlyHitTests && (Current->MessageQueue == OnlyHitTests)) { *HitTest = co_IntSendMessage(Current->hSelf, WM_NCHITTEST, 0, MAKELONG(Point->x, Point->y)); if ((*HitTest) == (USHORT)HTTRANSPARENT) + { + UserDerefObjectCo(Current); continue; + } } else *HitTest = HTCLIENT; @@ -1526,6 +1560,9 @@ co_WinPosSearchChildren( { co_WinPosSearchChildren(Current, OnlyHitTests, Point, Window, HitTest); } + + UserRefObject(Current); + UserDerefObjectCo(Current); break; } @@ -1533,6 +1570,7 @@ co_WinPosSearchChildren( } } +/* wine: WINPOS_WindowFromPoint */ USHORT FASTCALL co_WinPosWindowFromPoint(PWINDOW_OBJECT ScopeWin, PUSER_MESSAGE_QUEUE OnlyHitTests, POINT *WinPoint, PWINDOW_OBJECT* Window) @@ -1560,11 +1598,10 @@ co_WinPosWindowFromPoint(PWINDOW_OBJECT ScopeWin, PUSER_MESSAGE_QUEUE OnlyHitTes /* Translate the point to the space of the scope window. */ DesktopWindowHandle = IntGetDesktopWindow(); if((DesktopWindowHandle != ScopeWin->hSelf) && - (DesktopWindow = IntGetWindowObject(DesktopWindowHandle))) + (DesktopWindow = UserGetWindowObject(DesktopWindowHandle))) { Point.x += ScopeWin->ClientRect.left - DesktopWindow->ClientRect.left; Point.y += ScopeWin->ClientRect.top - DesktopWindow->ClientRect.top; - IntReleaseWindowObject(DesktopWindow); } HitTest = HTNOWHERE; @@ -1626,8 +1663,7 @@ NtUserGetMinMaxInfo( RETURN( FALSE); CLEANUP: - if (Window) - UserDerefObjectCo(Window); + if (Window) UserDerefObjectCo(Window); DPRINT("Leave NtUserGetMinMaxInfo, ret=%i\n",_ret_); UserLeave(); diff --git a/reactos/subsys/win32k/objects/color.c b/reactos/subsys/win32k/objects/color.c index 6c4c2754f8b..001727b41f0 100644 --- a/reactos/subsys/win32k/objects/color.c +++ b/reactos/subsys/win32k/objects/color.c @@ -645,7 +645,7 @@ NtGdiUpdateColors(HDC hDC) UserEnterExclusive(); } - Wnd = IntGetWindowObject(IntWindowFromDC(hDC)); + Wnd = UserGetWindowObject(IntWindowFromDC(hDC)); if (Wnd == NULL) { SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); @@ -657,9 +657,9 @@ NtGdiUpdateColors(HDC hDC) return FALSE; } + UserRefObjectCo(Wnd); ret = co_UserRedrawWindow(Wnd, NULL, 0, RDW_INVALIDATE); - - IntReleaseWindowObject(Wnd); //temp hack + UserDerefObjectCo(Wnd); if (!calledFromUser){ UserLeave();