From 823118e08a2fb64882ac30912217f31c35e2b0e0 Mon Sep 17 00:00:00 2001 From: James Tabor Date: Mon, 28 Feb 2011 06:31:44 +0000 Subject: [PATCH] [Win32k|User32] - Clarify the meaning and the use of 0, 1 and 2 for user window regions, wine never did. Noticing patches not corresponding in correctness and understanding, leaving potential crashes in the DCE code, which depend on these types. - Patch based on Rafal Harabien patch, fixes wine msg SetWindowRgn test, see also bug 5959. svn path=/trunk/; revision=50933 --- reactos/dll/win32/user32/windows/defwnd.c | 6 ++--- reactos/dll/win32/user32/windows/nonclient.c | 5 ++-- reactos/dll/win32/user32/windows/window.c | 4 +-- reactos/include/reactos/win32k/ntuser.h | 4 +++ .../subsystems/win32/win32k/ntuser/painting.c | 10 ++++---- .../subsystems/win32/win32k/ntuser/windc.c | 2 +- .../subsystems/win32/win32k/ntuser/window.c | 25 +++++++++++-------- .../subsystems/win32/win32k/ntuser/winpos.c | 2 +- 8 files changed, 33 insertions(+), 25 deletions(-) diff --git a/reactos/dll/win32/user32/windows/defwnd.c b/reactos/dll/win32/user32/windows/defwnd.c index 774b74552ca..edee49dac73 100644 --- a/reactos/dll/win32/user32/windows/defwnd.c +++ b/reactos/dll/win32/user32/windows/defwnd.c @@ -1189,7 +1189,7 @@ User32DefWindowProc(HWND hWnd, case WM_SYSCOLORCHANGE: { /* force to redraw non-client area */ - DefWndNCPaint(hWnd, (HRGN)1, -1); + DefWndNCPaint(hWnd, HRGN_WINDOW, -1); /* Use InvalidateRect to redraw client area, enable * erase to redraw all subcontrols otherwise send the * WM_SYSCOLORCHANGE to child windows/controls is required @@ -1966,7 +1966,7 @@ RealDefWindowProcA(HWND hWnd, if ((GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION) { - DefWndNCPaint(hWnd, (HRGN)1, -1); + DefWndNCPaint(hWnd, HRGN_WINDOW, -1); } Result = 1; break; @@ -2112,7 +2112,7 @@ RealDefWindowProcW(HWND hWnd, if ((GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION) { - DefWndNCPaint(hWnd, (HRGN)1, -1); + DefWndNCPaint(hWnd, HRGN_WINDOW, -1); } Result = 1; break; diff --git a/reactos/dll/win32/user32/windows/nonclient.c b/reactos/dll/win32/user32/windows/nonclient.c index b9df4425149..1d825b978df 100644 --- a/reactos/dll/win32/user32/windows/nonclient.c +++ b/reactos/dll/win32/user32/windows/nonclient.c @@ -489,7 +489,8 @@ DefWndNCPaint(HWND hWnd, HRGN hRgn, BOOL Active) } ReleaseDC(hWnd, hDC); - DeleteObject(hRgn); // We use DCX_KEEPCLIPRGN + if (hRgn != HRGN_WINDOW) + DeleteObject(hRgn); // We use DCX_KEEPCLIPRGN return 0; } @@ -650,7 +651,7 @@ DefWndNCCalcSize(HWND hWnd, BOOL CalcSizeStruct, RECT *Rect) LRESULT DefWndNCActivate(HWND hWnd, WPARAM wParam) { - DefWndNCPaint(hWnd, (HRGN)1, wParam); + DefWndNCPaint(hWnd, HRGN_WINDOW, wParam); return TRUE; } diff --git a/reactos/dll/win32/user32/windows/window.c b/reactos/dll/win32/user32/windows/window.c index d2a7bb9ee97..2025d815617 100644 --- a/reactos/dll/win32/user32/windows/window.c +++ b/reactos/dll/win32/user32/windows/window.c @@ -1727,7 +1727,7 @@ SetWindowTextA(HWND hWnd, if ((GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION) { - DefWndNCPaint(hWnd, (HRGN)1, -1); + DefWndNCPaint(hWnd, HRGN_WINDOW, -1); } return TRUE; } @@ -1757,7 +1757,7 @@ SetWindowTextW(HWND hWnd, if ((GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION) { - DefWndNCPaint(hWnd, (HRGN)1, -1); + DefWndNCPaint(hWnd, HRGN_WINDOW, -1); } return TRUE; } diff --git a/reactos/include/reactos/win32k/ntuser.h b/reactos/include/reactos/win32k/ntuser.h index a334a04ff30..0b4f587a34a 100644 --- a/reactos/include/reactos/win32k/ntuser.h +++ b/reactos/include/reactos/win32k/ntuser.h @@ -231,6 +231,10 @@ C_ASSERT(sizeof(CLIENTINFO) <= sizeof(((PTEB)0)->Win32ClientInfo)); #define GetWin32ClientInfo() ((PCLIENTINFO)(NtCurrentTeb()->Win32ClientInfo)) +#define HRGN_NULL ( (HRGN) 0) // NULL empty region +#define HRGN_WINDOW ( (HRGN) 1) // region from window rcWindow +#define HRGN_MONITOR ( (HRGN) 2) // region from monitor region. + /* Menu Item fType. */ #define MFT_RTOL 0x6000 diff --git a/reactos/subsystems/win32/win32k/ntuser/painting.c b/reactos/subsystems/win32/win32k/ntuser/painting.c index e74639180ce..beedd93cfb8 100644 --- a/reactos/subsystems/win32/win32k/ntuser/painting.c +++ b/reactos/subsystems/win32/win32k/ntuser/painting.c @@ -141,7 +141,7 @@ IntGetNCUpdateRgn(PWND Window, BOOL Validate) UINT RgnType; if (Window->hrgnUpdate != NULL && - Window->hrgnUpdate != (HRGN)1) + Window->hrgnUpdate != HRGN_WINDOW) { hRgnNonClient = IntCalcWindowRgn(Window, FALSE); @@ -151,14 +151,14 @@ IntGetNCUpdateRgn(PWND Window, BOOL Validate) */ if (hRgnNonClient == NULL) { - return (HRGN)1; + return HRGN_WINDOW; } hRgnWindow = IntCalcWindowRgn(Window, TRUE); if (hRgnWindow == NULL) { REGION_FreeRgnByHandle(hRgnNonClient); - return (HRGN)1; + return HRGN_WINDOW; } RgnType = NtGdiCombineRgn(hRgnNonClient, hRgnNonClient, @@ -167,7 +167,7 @@ IntGetNCUpdateRgn(PWND Window, BOOL Validate) { REGION_FreeRgnByHandle(hRgnWindow); REGION_FreeRgnByHandle(hRgnNonClient); - return (HRGN)1; + return HRGN_WINDOW; } else if (RgnType == NULLREGION) { @@ -1049,7 +1049,7 @@ NtUserGetUpdateRect(HWND hWnd, LPRECT UnsafeRect, BOOL bErase) else { /* Get the update region bounding box. */ - if (Window->hrgnUpdate == (HRGN)1) + if (Window->hrgnUpdate == HRGN_WINDOW) { Rect = Window->rcClient; } diff --git a/reactos/subsystems/win32/win32k/ntuser/windc.c b/reactos/subsystems/win32/win32k/ntuser/windc.c index 89f44f76fe0..619f94b430a 100644 --- a/reactos/subsystems/win32/win32k/ntuser/windc.c +++ b/reactos/subsystems/win32/win32k/ntuser/windc.c @@ -551,7 +551,7 @@ UserGetDCEx(PWND Wnd OPTIONAL, HANDLE ClipRegion, ULONG Flags) ClipRegion = Wnd->hrgnUpdate; } - if (ClipRegion == (HRGN) 1) + if (ClipRegion == HRGN_WINDOW) { if (!(Flags & DCX_WINDOW)) { diff --git a/reactos/subsystems/win32/win32k/ntuser/window.c b/reactos/subsystems/win32/win32k/ntuser/window.c index 892ef7ac979..cb431f21000 100644 --- a/reactos/subsystems/win32/win32k/ntuser/window.c +++ b/reactos/subsystems/win32/win32k/ntuser/window.c @@ -4017,6 +4017,7 @@ CLEANUP: } +// This should be in user32! INT FASTCALL IntGetWindowRgn(PWND Window, HRGN hRgn) { @@ -4055,6 +4056,7 @@ IntGetWindowRgn(PWND Window, HRGN hRgn) return Ret; } +// This should be in user32! INT FASTCALL IntGetWindowRgnBox(PWND Window, RECTL *Rect) { @@ -4104,6 +4106,8 @@ NtUserSetWindowRgn( { HRGN hrgnCopy; PWND Window; + INT flags = (SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE); + BOOLEAN Ret = FALSE; DECLARE_RETURN(INT); DPRINT("Enter NtUserSetWindowRgn\n"); @@ -4119,32 +4123,31 @@ NtUserSetWindowRgn( if (GDIOBJ_ValidateHandle(hRgn, GDI_OBJECT_TYPE_REGION)) { hrgnCopy = IntSysCreateRectRgn(0, 0, 0, 0); + + /* Set public ownership */ + IntGdiSetRegionOwner(hrgnCopy, GDI_OBJ_HMGR_PUBLIC); + NtGdiCombineRgn(hrgnCopy, hRgn, 0, RGN_COPY); } else RETURN( 0); } else - hrgnCopy = (HRGN) 1; + { + hrgnCopy = IntSysCreateRectRgnIndirect(&Window->rcWindow); //HRGN_WINDOW; + } if (Window->hrgnClip) { /* Delete no longer needed region handle */ GreDeleteObject(Window->hrgnClip); } - Window->hrgnClip = hrgnCopy; - /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */ + Window->hrgnClip = hrgnCopy; - if(bRedraw) - { - USER_REFERENCE_ENTRY Ref; - UserRefObjectCo(Window, &Ref); - co_UserRedrawWindow(Window, NULL, NULL, RDW_INVALIDATE); - UserDerefObjectCo(Window); - } + Ret = co_WinPosSetWindowPos(Window, HWND_TOP, 0, 0, 0, 0, bRedraw ? flags : (flags|SWP_NOREDRAW) ); - RETURN( (INT)hRgn); + RETURN( (INT)Ret); CLEANUP: DPRINT("Leave NtUserSetWindowRgn, ret=%i\n",_ret_); diff --git a/reactos/subsystems/win32/win32k/ntuser/winpos.c b/reactos/subsystems/win32/win32k/ntuser/winpos.c index 3099bee17ef..6a9dfd2b169 100644 --- a/reactos/subsystems/win32/win32k/ntuser/winpos.c +++ b/reactos/subsystems/win32/win32k/ntuser/winpos.c @@ -1120,7 +1120,7 @@ co_WinPosSetWindowPos( Window->style |= WS_VISIBLE; } - if (Window->hrgnUpdate != NULL && Window->hrgnUpdate != (HRGN)1) + if (Window->hrgnUpdate != NULL && Window->hrgnUpdate != HRGN_WINDOW) { NtGdiOffsetRgn(Window->hrgnUpdate, NewWindowRect.left - OldWindowRect.left, -- 2.17.1