Author: weiden
Date: Fri Nov 16 12:03:51 2007
New Revision: 30497
URL:
http://svn.reactos.org/svn/reactos?rev=30497&view=rev
Log:
Optimize IsWindow() and IsWindowUnicode()
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/include/window.h
trunk/reactos/subsystems/win32/win32k/ntuser/message.c
trunk/reactos/subsystems/win32/win32k/ntuser/misc.c
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/u…
==============================================================================
--- trunk/reactos/dll/win32/user32/include/user32.h (original)
+++ trunk/reactos/dll/win32/user32/include/user32.h Fri Nov 16 12:03:51 2007
@@ -89,3 +89,5 @@
PWINDOW FASTCALL ValidateHwnd(HWND hwnd);
PWINDOW FASTCALL ValidateHwndOrDesk(HWND hwnd);
PWINDOW FASTCALL GetThreadDesktopWnd(VOID);
+PVOID FASTCALL ValidateHandleNoErr(HANDLE handle, UINT uType);
+PWINDOW FASTCALL ValidateHwndNoErr(HWND hwnd);
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 12:03:51 2007
@@ -422,6 +422,35 @@
}
//
+// Validate Handle and return the pointer to the object.
+//
+PVOID
+FASTCALL
+ValidateHandleNoErr(HANDLE handle, UINT uType)
+{
+ PVOID ret;
+ PUSER_HANDLE_ENTRY pEntry;
+
+ ASSERT(uType <= VALIDATE_TYPE_MONITOR);
+
+ pEntry = GetUser32Handle(handle);
+
+ if (pEntry && uType == 0)
+ uType = pEntry->type;
+
+// Must have an entry and must be the same type!
+ if ( (!pEntry) || (pEntry->type != uType) || !pEntry->ptr )
+ return NULL;
+
+ if (g_ObjectHeapTypeShared[uType])
+ ret = SharedPtrToUser(pEntry->ptr);
+ else
+ ret = DesktopPtrToUser(pEntry->ptr);
+
+ return ret;
+}
+
+//
// Validate a callproc handle and return the pointer to the object.
//
PCALLPROC
@@ -474,6 +503,45 @@
return NULL;
}
+//
+// Validate a window handle and return the pointer to the object.
+//
+PWINDOW
+FASTCALL
+ValidateHwndNoErr(HWND hwnd)
+{
+ PWINDOW Wnd;
+ PW32CLIENTINFO ClientInfo = GetWin32ClientInfo();
+ ASSERT(ClientInfo != NULL);
+
+ /* See if the window is cached */
+ if (hwnd == ClientInfo->hWND)
+ return ClientInfo->pvWND;
+
+ Wnd = ValidateHandleNoErr((HANDLE)hwnd, VALIDATE_TYPE_WIN);
+ if (Wnd != NULL)
+ {
+ /* FIXME: Check if handle table entry is marked as deleting and
+ return NULL in this case! */
+
+#if 0
+ return Wnd;
+#else
+ /* HACK HACK HACK! This needs to be done until WINDOW_OBJECT is completely
+ superseded by the WINDOW structure. We *ASSUME* a pointer to the WINDOW
+ structure to be at the beginning of the WINDOW_OBJECT structure!!!
+
+ !!! REMOVE AS SOON AS WINDOW_OBJECT NO LONGER EXISTS !!!
+ */
+
+ if (*((PVOID*)Wnd) != NULL)
+ return DesktopPtrToUser(*((PVOID*)Wnd));
+#endif
+ }
+
+ return NULL;
+}
+
PWINDOW
FASTCALL
GetThreadDesktopWnd(VOID)
Modified: trunk/reactos/dll/win32/user32/windows/window.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/user32/windows/w…
==============================================================================
--- trunk/reactos/dll/win32/user32/windows/window.c (original)
+++ trunk/reactos/dll/win32/user32/windows/window.c Fri Nov 16 12:03:51 2007
@@ -1201,8 +1201,14 @@
BOOL STDCALL
IsWindow(HWND hWnd)
{
- DWORD WndProc = NtUserGetWindowLong(hWnd, GWL_WNDPROC, FALSE);
- return (0 != WndProc || ERROR_INVALID_WINDOW_HANDLE != GetLastError());
+ PWINDOW Wnd = ValidateHwndNoErr(hWnd);
+ if (Wnd != NULL)
+ {
+ /* FIXME: If window is being destroyed return FALSE! */
+ return TRUE;
+ }
+
+ return FALSE;
}
@@ -1212,7 +1218,12 @@
BOOL STDCALL
IsWindowUnicode(HWND hWnd)
{
- return NtUserIsWindowUnicode(hWnd);
+ PWINDOW Wnd = ValidateHwnd(hWnd);
+
+ if (Wnd != NULL)
+ return Wnd->Unicode;
+
+ return FALSE;
}
Modified: trunk/reactos/include/reactos/win32k/ntuser.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/win32k/ntu…
==============================================================================
--- trunk/reactos/include/reactos/win32k/ntuser.h (original)
+++ trunk/reactos/include/reactos/win32k/ntuser.h Fri Nov 16 12:03:51 2007
@@ -115,6 +115,8 @@
PWINDOWCLASS Class;
/* Window name. */
UNICODE_STRING WindowName;
+
+ UINT Unicode : 1;
} WINDOW, *PWINDOW;
typedef struct _W32PROCESSINFO
Modified: trunk/reactos/subsystems/win32/win32k/include/window.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/in…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/include/window.h (original)
+++ trunk/reactos/subsystems/win32/win32k/include/window.h Fri Nov 16 12:03:51 2007
@@ -78,7 +78,6 @@
ULONG PropListItems;
/* Scrollbar info */
PWINDOW_SCROLLINFO Scroll;
- BOOL Unicode;
WNDPROC WndProc;
PETHREAD OwnerThread;
HWND hWndLastPopup; /* handle to last active popup window (wine doesn't use
pointer, for unk. reason)*/
Modified: trunk/reactos/subsystems/win32/win32k/ntuser/message.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/nt…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/ntuser/message.c (original)
+++ trunk/reactos/subsystems/win32/win32k/ntuser/message.c Fri Nov 16 12:03:51 2007
@@ -385,7 +385,7 @@
}
else
{
- MsgInfo.Ansi = !Window->Unicode;
+ MsgInfo.Ansi = !Window->Wnd->Unicode;
MsgInfo.Proc = Window->WndProc;
}
}
@@ -1390,7 +1390,7 @@
RETURN( FALSE);
}
- Result = (ULONG_PTR)co_IntCallWindowProc(Window->WndProc, !Window->Unicode,
hWnd, Msg, wParam,
+ Result = (ULONG_PTR)co_IntCallWindowProc(Window->WndProc,
!Window->Wnd->Unicode, hWnd, Msg, wParam,
lParamPacked,lParamBufferSize);
if(uResult)
@@ -1566,7 +1566,7 @@
sizeof(BOOL));
if (! NT_SUCCESS(Status))
{
- Info.Ansi = ! Window->Unicode;
+ Info.Ansi = ! Window->Wnd->Unicode;
}
if (Window->IsSystem)
@@ -1575,7 +1575,7 @@
}
else
{
- Info.Ansi = !Window->Unicode;
+ Info.Ansi = !Window->Wnd->Unicode;
Info.Proc = Window->WndProc;
}
}
Modified: trunk/reactos/subsystems/win32/win32k/ntuser/misc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/nt…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/ntuser/misc.c (original)
+++ trunk/reactos/subsystems/win32/win32k/ntuser/misc.c Fri Nov 16 12:03:51 2007
@@ -283,7 +283,7 @@
{
RETURN( FALSE);
}
- Result = Window->Unicode;
+ Result = Window->Wnd->Unicode;
RETURN( Result);
}
Modified: trunk/reactos/subsystems/win32/win32k/ntuser/window.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/nt…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/ntuser/window.c (original)
+++ trunk/reactos/subsystems/win32/win32k/ntuser/window.c Fri Nov 16 12:03:51 2007
@@ -525,7 +525,7 @@
}
else
{
- if (!Ansi == Window->Unicode)
+ if (!Ansi == Wnd->Unicode)
{
return Window->WndProc;
}
@@ -541,12 +541,12 @@
NewCallProc = UserFindCallProc(Wnd->Class,
Window->WndProc,
- Window->Unicode);
+ Wnd->Unicode);
if (NewCallProc == NULL)
{
NewCallProc = CreateCallProc(Wnd->ti->Desktop,
Window->WndProc,
- Window->Unicode,
+ Wnd->Unicode,
Wnd->ti->kpi);
if (NewCallProc == NULL)
{
@@ -1649,13 +1649,13 @@
if (Wnd->Class->System)
{
/* NOTE: Always create a unicode window for system classes! */
- Window->Unicode = TRUE;
+ Wnd->Unicode = TRUE;
Window->WndProc = Wnd->Class->WndProc;
Window->WndProcExtra = Wnd->Class->WndProcExtra;
}
else
{
- Window->Unicode = Wnd->Class->Unicode;
+ Wnd->Unicode = Wnd->Class->Unicode;
Window->WndProc = Wnd->Class->WndProc;
Window->CallProc = NULL;
}
@@ -3614,7 +3614,7 @@
}
else
{
- if (!Ansi == Window->Unicode)
+ if (!Ansi == Wnd->Unicode)
{
Ret = Window->WndProc;
}
@@ -3622,12 +3622,12 @@
{
CallProc = UserFindCallProc(Wnd->Class,
Window->WndProc,
- Window->Unicode);
+ Wnd->Unicode);
if (CallProc == NULL)
{
CallProc = CreateCallProc(NULL,
Window->WndProc,
- Window->Unicode,
+ Wnd->Unicode,
Wnd->ti->kpi);
if (CallProc == NULL)
{
@@ -3656,7 +3656,7 @@
{
Window->WndProc = Wnd->Class->WndProc;
Window->WndProcExtra = Wnd->Class->WndProcExtra;
- Window->Unicode = !Ansi;
+ Wnd->Unicode = !Ansi;
return Ret;
}
}
@@ -3665,7 +3665,7 @@
/* update the window procedure */
Window->WndProc = NewWndProc;
- Window->Unicode = !Ansi;
+ Wnd->Unicode = !Ansi;
return Ret;
}