Author: weiden Date: Fri Nov 16 11:03:04 2007 New Revision: 30495
URL: http://svn.reactos.org/svn/reactos?rev=30495&view=rev Log: Optimize ClientToScreen(), ScreenToClient() and MapWindowPoints()
Modified: trunk/reactos/dll/win32/user32/include/user32.h trunk/reactos/dll/win32/user32/misc/misc.c trunk/reactos/dll/win32/user32/windows/window.c trunk/reactos/include/reactos/win32k/ntuser.h trunk/reactos/subsystems/win32/win32k/ntuser/window.c
Modified: trunk/reactos/dll/win32/user32/include/user32.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/include/us... ============================================================================== --- trunk/reactos/dll/win32/user32/include/user32.h (original) +++ trunk/reactos/dll/win32/user32/include/user32.h Fri Nov 16 11:03:04 2007 @@ -87,3 +87,5 @@
PCALLPROC FASTCALL ValidateCallProc(HANDLE hCallProc); PWINDOW FASTCALL ValidateHwnd(HWND hwnd); +PWINDOW FASTCALL ValidateHwndOrDesk(HWND hwnd); +PWINDOW FASTCALL GetThreadDesktopWnd(VOID);
Modified: trunk/reactos/dll/win32/user32/misc/misc.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/misc/misc.... ============================================================================== --- trunk/reactos/dll/win32/user32/misc/misc.c (original) +++ trunk/reactos/dll/win32/user32/misc/misc.c Fri Nov 16 11:03:04 2007 @@ -146,6 +146,19 @@ }
return pi; +} + +static PDESKTOP +GetThreadDesktopInfo(VOID) +{ + PW32THREADINFO ti; + PDESKTOP di = NULL; + + ti = GetW32ThreadInfo(); + if (ti != NULL) + di = DesktopPtrToUser(ti->Desktop); + + return di; }
@@ -429,6 +442,7 @@ FASTCALL ValidateHwnd(HWND hwnd) { + PWINDOW Wnd; PW32CLIENTINFO ClientInfo = GetWin32ClientInfo(); ASSERT(ClientInfo != NULL);
@@ -436,7 +450,7 @@ if (hwnd == ClientInfo->hWND) return ClientInfo->pvWND;
- PWINDOW Wnd = ValidateHandle((HANDLE)hwnd, VALIDATE_TYPE_WIN); + Wnd = ValidateHandle((HANDLE)hwnd, VALIDATE_TYPE_WIN); if (Wnd != NULL) { /* FIXME: Check if handle table entry is marked as deleting and @@ -459,3 +473,26 @@
return NULL; } + +PWINDOW +FASTCALL +GetThreadDesktopWnd(VOID) +{ + PWINDOW Wnd = GetThreadDesktopInfo()->Wnd; + if (Wnd != NULL) + Wnd = DesktopPtrToUser(Wnd); + return Wnd; +} + +// +// Validate a window handle and return the pointer to the object. +// +PWINDOW +FASTCALL +ValidateHwndOrDesk(HWND hwnd) +{ + if (hwnd == HWND_DESKTOP) + return GetThreadDesktopWnd(); + + return ValidateHwnd(hwnd); +}
Modified: trunk/reactos/dll/win32/user32/windows/window.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/windows/wi... ============================================================================== --- trunk/reactos/dll/win32/user32/windows/window.c (original) +++ trunk/reactos/dll/win32/user32/windows/window.c Fri Nov 16 11:03:04 2007 @@ -1577,36 +1577,28 @@ int STDCALL MapWindowPoints(HWND hWndFrom, HWND hWndTo, LPPOINT lpPoints, UINT cPoints) { - POINT FromOffset, ToOffset; - LONG XMove, YMove; - ULONG i; - - if (hWndFrom == NULL) - { - FromOffset.x = FromOffset.y = 0; - } else - if(!NtUserGetClientOrigin(hWndFrom, &FromOffset)) - { - return 0; - } - - if (hWndTo == NULL) - { - ToOffset.x = ToOffset.y = 0; - } else - if(!NtUserGetClientOrigin(hWndTo, &ToOffset)) - { - return 0; - } - XMove = FromOffset.x - ToOffset.x; - YMove = FromOffset.y - ToOffset.y; - - for (i = 0; i < cPoints; i++) - { - lpPoints[i].x += XMove; - lpPoints[i].y += YMove; - } - return(MAKELONG(LOWORD(XMove), LOWORD(YMove))); + PWINDOW FromWnd, ToWnd; + POINT Delta; + UINT i; + + FromWnd = ValidateHwndOrDesk(hWndFrom); + if (!FromWnd) + return 0; + + ToWnd = ValidateHwndOrDesk(hWndTo); + if (!ToWnd) + return 0; + + Delta.x = FromWnd->ClientRect.left - ToWnd->ClientRect.left; + Delta.y = FromWnd->ClientRect.top - ToWnd->ClientRect.top; + + for (i = 0; i != cPoints; i++) + { + lpPoints[i].x += Delta.x; + lpPoints[i].y += Delta.y; + } + + return MAKELONG(LOWORD(Delta.x), LOWORD(Delta.y)); }
@@ -1616,7 +1608,18 @@ BOOL STDCALL ScreenToClient(HWND hWnd, LPPOINT lpPoint) { - return(MapWindowPoints(NULL, hWnd, lpPoint, 1) != 0); + PWINDOW Wnd, DesktopWnd; + + Wnd = ValidateHwnd(hWnd); + if (!Wnd) + return FALSE; + + DesktopWnd = GetThreadDesktopWnd(); + + lpPoint->x += DesktopWnd->ClientRect.left - Wnd->ClientRect.left; + lpPoint->y += DesktopWnd->ClientRect.top - Wnd->ClientRect.top; + + return TRUE; }
@@ -1626,7 +1629,18 @@ BOOL STDCALL ClientToScreen(HWND hWnd, LPPOINT lpPoint) { - return (MapWindowPoints( hWnd, NULL, lpPoint, 1 ) != 0); + PWINDOW Wnd, DesktopWnd; + + Wnd = ValidateHwnd(hWnd); + if (!Wnd) + return FALSE; + + DesktopWnd = GetThreadDesktopWnd(); + + lpPoint->x += Wnd->ClientRect.left - DesktopWnd->ClientRect.left; + lpPoint->y += Wnd->ClientRect.top - DesktopWnd->ClientRect.top; + + return TRUE; }
Modified: trunk/reactos/include/reactos/win32k/ntuser.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/win32k/ntus... ============================================================================== --- trunk/reactos/include/reactos/win32k/ntuser.h (original) +++ trunk/reactos/include/reactos/win32k/ntuser.h Fri Nov 16 11:03:04 2007 @@ -3,6 +3,7 @@
struct _W32PROCESSINFO; struct _W32THREADINFO; +struct _WINDOW;
typedef struct _REGISTER_SYSCLASS { @@ -22,9 +23,11 @@ { HANDLE hKernelHeap; ULONG_PTR HeapLimit; - WCHAR szDesktopName[1]; HWND hTaskManWindow; HWND hProgmanWindow; + struct _WINDOW *Wnd; + + WCHAR szDesktopName[1]; } DESKTOP, *PDESKTOP;
typedef struct _CALLPROC
Modified: trunk/reactos/subsystems/win32/win32k/ntuser/window.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ntu... ============================================================================== --- trunk/reactos/subsystems/win32/win32k/ntuser/window.c (original) +++ trunk/reactos/subsystems/win32/win32k/ntuser/window.c Fri Nov 16 11:03:04 2007 @@ -1600,6 +1600,7 @@ { /* If there is no desktop window yet, we must be creating it */ PsGetCurrentThreadWin32Thread()->Desktop->DesktopWindow = hWnd; + PsGetCurrentThreadWin32Thread()->Desktop->DesktopInfo->Wnd = Wnd; }
/*