-cursoricon: naming changes, cleanup

-fix: hide/show caret to accept NULL hWnds
-some handle to pointer converions
-double handle table size
-fix: co_WinPosActivateOtherWindow was trying to access desktop parent

svn path=/trunk/; revision=17756
This commit is contained in:
Gunnar Dalsnes 2005-09-09 00:25:52 +00:00
parent 6b27e47c88
commit 16addb9060
8 changed files with 620 additions and 621 deletions

View file

@ -42,7 +42,7 @@ typedef enum _USER_OBJECT_TYPE
otWindow, otWindow,
otMenu, otMenu,
otAccel, otAccel,
otCursor, otCursorIcon,
otHook, otHook,
otMonitor, otMonitor,
otClass //fixme: remove otClass //fixme: remove

View file

@ -21,6 +21,8 @@ BOOL FASTCALL ObmDereferenceObject(PVOID obj);
#define IntReferenceWindowObject(o) ObmReferenceObject(o) #define IntReferenceWindowObject(o) ObmReferenceObject(o)
#define UserDerefObject(o) ObmReferenceObject(o)
VOID FASTCALL IntReleaseWindowObject(PWINDOW_OBJECT Window); VOID FASTCALL IntReleaseWindowObject(PWINDOW_OBJECT Window);
PWINDOW_OBJECT FASTCALL IntGetWindowObject(HWND hWnd); PWINDOW_OBJECT FASTCALL IntGetWindowObject(HWND hWnd);
PVOID FASTCALL PVOID FASTCALL
@ -136,7 +138,7 @@ BOOLEAN FASTCALL co_UserDestroyWindow(PWINDOW_OBJECT Wnd);
LONG FASTCALL UserGetWindowLong(HWND hWnd, DWORD Index, BOOL Ansi); LONG FASTCALL UserGetWindowLong(HWND hWnd, DWORD Index, BOOL Ansi);
HWND FASTCALL UserGetAncestor(HWND hWnd, UINT Type); PWINDOW_OBJECT FASTCALL UserGetAncestor(PWINDOW_OBJECT Wnd, UINT Type);
/*************** MENU.C ***************/ /*************** MENU.C ***************/

View file

@ -317,11 +317,13 @@ CLEANUP:
} }
BOOL FASTCALL co_UserHideCaret(PWINDOW_OBJECT Window) BOOL FASTCALL co_UserHideCaret(PWINDOW_OBJECT Window OPTIONAL)
{ {
PUSER_MESSAGE_QUEUE ThreadQueue; PUSER_MESSAGE_QUEUE ThreadQueue;
if(Window->OwnerThread != PsGetCurrentThread()) if (Window) ASSERT_REFS_CO(Window);
if(Window && Window->OwnerThread != PsGetCurrentThread())
{ {
SetLastWin32Error(ERROR_ACCESS_DENIED); SetLastWin32Error(ERROR_ACCESS_DENIED);
return FALSE; return FALSE;
@ -329,7 +331,7 @@ BOOL FASTCALL co_UserHideCaret(PWINDOW_OBJECT Window)
ThreadQueue = (PUSER_MESSAGE_QUEUE)PsGetWin32Thread()->MessageQueue; ThreadQueue = (PUSER_MESSAGE_QUEUE)PsGetWin32Thread()->MessageQueue;
if(ThreadQueue->CaretInfo->hWnd != Window->hSelf) if(Window && ThreadQueue->CaretInfo->hWnd != Window->hSelf)
{ {
SetLastWin32Error(ERROR_ACCESS_DENIED); SetLastWin32Error(ERROR_ACCESS_DENIED);
return FALSE; return FALSE;
@ -337,7 +339,7 @@ BOOL FASTCALL co_UserHideCaret(PWINDOW_OBJECT Window)
if(ThreadQueue->CaretInfo->Visible) if(ThreadQueue->CaretInfo->Visible)
{ {
IntKillTimer(Window->hSelf, IDCARETTIMER, TRUE); IntKillTimer((Window ? Window->hSelf : 0), IDCARETTIMER, TRUE);
co_IntHideCaret(ThreadQueue->CaretInfo); co_IntHideCaret(ThreadQueue->CaretInfo);
ThreadQueue->CaretInfo->Visible = 0; ThreadQueue->CaretInfo->Visible = 0;
@ -350,24 +352,23 @@ BOOL FASTCALL co_UserHideCaret(PWINDOW_OBJECT Window)
BOOL BOOL
STDCALL STDCALL
NtUserHideCaret( NtUserHideCaret(HWND hWnd OPTIONAL)
HWND hWnd)
{ {
PWINDOW_OBJECT Window; PWINDOW_OBJECT Window = NULL;
DECLARE_RETURN(BOOL); DECLARE_RETURN(BOOL);
BOOL ret; BOOL ret;
DPRINT("Enter NtUserHideCaret\n"); DPRINT("Enter NtUserHideCaret\n");
UserEnterExclusive(); UserEnterExclusive();
if(!(Window = UserGetWindowObject(hWnd))) if(hWnd && !(Window = UserGetWindowObject(hWnd)))
{ {
RETURN(FALSE); RETURN(FALSE);
} }
UserRefObjectCo(Window); if (Window) UserRefObjectCo(Window);
ret = co_UserHideCaret(Window); ret = co_UserHideCaret(Window);
UserDerefObjectCo(Window); if (Window) UserDerefObjectCo(Window);
RETURN(ret); RETURN(ret);
@ -378,11 +379,13 @@ CLEANUP:
} }
BOOL FASTCALL co_UserShowCaret(PWINDOW_OBJECT Window) BOOL FASTCALL co_UserShowCaret(PWINDOW_OBJECT Window OPTIONAL)
{ {
PUSER_MESSAGE_QUEUE ThreadQueue; PUSER_MESSAGE_QUEUE ThreadQueue;
if(Window->OwnerThread != PsGetCurrentThread()) if (Window) ASSERT_REFS_CO(Window);
if(Window && Window->OwnerThread != PsGetCurrentThread())
{ {
SetLastWin32Error(ERROR_ACCESS_DENIED); SetLastWin32Error(ERROR_ACCESS_DENIED);
return FALSE; return FALSE;
@ -390,7 +393,7 @@ BOOL FASTCALL co_UserShowCaret(PWINDOW_OBJECT Window)
ThreadQueue = (PUSER_MESSAGE_QUEUE)PsGetWin32Thread()->MessageQueue; ThreadQueue = (PUSER_MESSAGE_QUEUE)PsGetWin32Thread()->MessageQueue;
if(ThreadQueue->CaretInfo->hWnd != Window->hSelf) if(Window && ThreadQueue->CaretInfo->hWnd != Window->hSelf)
{ {
SetLastWin32Error(ERROR_ACCESS_DENIED); SetLastWin32Error(ERROR_ACCESS_DENIED);
return FALSE; return FALSE;
@ -403,7 +406,7 @@ BOOL FASTCALL co_UserShowCaret(PWINDOW_OBJECT Window)
{ {
co_IntSendMessage(ThreadQueue->CaretInfo->hWnd, WM_SYSTIMER, IDCARETTIMER, 0); co_IntSendMessage(ThreadQueue->CaretInfo->hWnd, WM_SYSTIMER, IDCARETTIMER, 0);
} }
IntSetTimer(Window->hSelf, IDCARETTIMER, IntGetCaretBlinkTime(), NULL, TRUE); IntSetTimer((Window ? Window->hSelf : 0), IDCARETTIMER, IntGetCaretBlinkTime(), NULL, TRUE);
} }
return TRUE; return TRUE;
@ -412,24 +415,23 @@ BOOL FASTCALL co_UserShowCaret(PWINDOW_OBJECT Window)
BOOL BOOL
STDCALL STDCALL
NtUserShowCaret( NtUserShowCaret(HWND hWnd OPTIONAL)
HWND hWnd)
{ {
PWINDOW_OBJECT Window; PWINDOW_OBJECT Window = NULL;
DECLARE_RETURN(BOOL); DECLARE_RETURN(BOOL);
BOOL ret; BOOL ret;
DPRINT("Enter NtUserShowCaret\n"); DPRINT("Enter NtUserShowCaret\n");
UserEnterExclusive(); UserEnterExclusive();
if(!(Window = UserGetWindowObject(hWnd))) if(hWnd && !(Window = UserGetWindowObject(hWnd)))
{ {
RETURN(FALSE); RETURN(FALSE);
} }
UserRefObjectCo(Window); if (Window) UserRefObjectCo(Window);
ret = co_UserShowCaret(Window); ret = co_UserShowCaret(Window);
UserDerefObjectCo(Window); if (Window) UserDerefObjectCo(Window);
RETURN(ret); RETURN(ret);

File diff suppressed because it is too large Load diff

View file

@ -250,28 +250,38 @@ co_IntMouseActivateWindow(PWINDOW_OBJECT Window)
return FALSE; return FALSE;
} }
Top = UserGetAncestor(Window->hSelf, GA_ROOT);
if (Top != Window->hSelf) TopWindow = UserGetAncestor(Window, GA_ROOT);
{ if (!TopWindow) return FALSE;
TopWindow = IntGetWindowObject(Top); // if (TopWindow != Window)
if (TopWindow == NULL) // {
{
SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE); // Top = UserGetAncestor(Window, GA_ROOT);
return FALSE; // if (Top != Window->hSelf)
} // {
} // TopWindow = IntGetWindowObject(Top);
else // if (TopWindow == NULL)
{ // {
TopWindow = Window; // SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
} // return FALSE;
// }
// }
// else
// {
// TopWindow = Window;
// }
/* TMN: Check return valud from this function? */ /* TMN: Check return valud from this function? */
UserRefObjectCo(TopWindow);
co_IntSetForegroundAndFocusWindow(TopWindow, Window, TRUE); co_IntSetForegroundAndFocusWindow(TopWindow, Window, TRUE);
UserDerefObjectCo(TopWindow);
if (Top != Window->hSelf) // if (TopWindow != Window)
{ // {
IntReleaseWindowObject(TopWindow); // IntReleaseWindowObject(TopWindow);
} // }
return TRUE; return TRUE;
} }
@ -521,7 +531,8 @@ HWND FASTCALL co_UserSetFocus(PWINDOW_OBJECT Window OPTIONAL)
if (Window) if (Window)
{ {
PUSER_MESSAGE_QUEUE ThreadQueue; PUSER_MESSAGE_QUEUE ThreadQueue;
HWND hWndPrev, hWndTop; HWND hWndPrev;
PWINDOW_OBJECT TopWnd;
ASSERT_REFS_CO(Window); ASSERT_REFS_CO(Window);
@ -538,14 +549,13 @@ HWND FASTCALL co_UserSetFocus(PWINDOW_OBJECT Window OPTIONAL)
return( 0); return( 0);
} }
hWndTop = UserGetAncestor(Window->hSelf, GA_ROOT); TopWnd = UserGetAncestor(Window, GA_ROOT);
if (hWndTop != UserGetActiveWindow()) if (TopWnd->hSelf != UserGetActiveWindow())
{ {
PWINDOW_OBJECT WndTops = UserGetWindowObject(hWndTop); // PWINDOW_OBJECT WndTops = UserGetWindowObject(hWndTop);
UserRefObjectCo(TopWnd);
UserRefObjectCo(WndTops); co_IntSetActiveWindow(TopWnd);
co_IntSetActiveWindow(WndTops); UserDerefObjectCo(TopWnd);
UserDerefObjectCo(WndTops);
} }
hWndPrev = co_IntSetFocusWindow(Window); hWndPrev = co_IntSetFocusWindow(Window);

View file

@ -305,7 +305,7 @@ BOOL FASTCALL ObmCreateHandleTable()
PVOID mem; PVOID mem;
//FIXME: dont alloc all at once! must be mapped into umode also... //FIXME: dont alloc all at once! must be mapped into umode also...
mem = ExAllocatePool(PagedPool, sizeof(USER_HANDLE_ENTRY) * 1024); mem = ExAllocatePool(PagedPool, sizeof(USER_HANDLE_ENTRY) * 1024*2);
if (!mem) if (!mem)
{ {
DPRINT1("Failed creating handle table\n"); DPRINT1("Failed creating handle table\n");
@ -313,7 +313,7 @@ BOOL FASTCALL ObmCreateHandleTable()
} }
//FIXME: make auto growable //FIXME: make auto growable
UserInitHandleTable(&gHandleTable, mem, sizeof(USER_HANDLE_ENTRY) * 1024); UserInitHandleTable(&gHandleTable, mem, sizeof(USER_HANDLE_ENTRY) * 1024*2);
return TRUE; return TRUE;
} }

View file

@ -1452,7 +1452,12 @@ co_IntCreateWindowEx(DWORD dwExStyle,
if ((dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD) if ((dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD)
ParentWindowHandle = hWndParent; ParentWindowHandle = hWndParent;
else else
OwnerWindowHandle = UserGetAncestor(hWndParent, GA_ROOT); {
//temp hack
PWINDOW_OBJECT Par = UserGetWindowObject(hWndParent);
if (Par)
OwnerWindowHandle = UserGetAncestor(Par, GA_ROOT)->hSelf;
}
} }
else if ((dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD) else if ((dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD)
{ {
@ -2622,27 +2627,20 @@ NtUserFlashWindowEx(DWORD Unknown0)
/* /*
* @implemented * @implemented
*/ */
HWND FASTCALL UserGetAncestor(HWND hWnd, UINT Type) PWINDOW_OBJECT FASTCALL UserGetAncestor(PWINDOW_OBJECT Wnd, UINT Type)
{ {
PWINDOW_OBJECT Wnd, WndAncestor, Parent; PWINDOW_OBJECT WndAncestor, Parent;
HWND hWndAncestor;
if (hWnd == IntGetDesktopWindow()) if (Wnd->hSelf == IntGetDesktopWindow())
{ {
return NULL; return NULL;
} }
if (!(Wnd = IntGetWindowObject(hWnd)))
{
SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
return NULL;
}
switch (Type) switch (Type)
{ {
case GA_PARENT: case GA_PARENT:
{ {
WndAncestor = IntGetParentObject(Wnd); WndAncestor = Wnd->Parent;
break; break;
} }
@ -2655,17 +2653,15 @@ HWND FASTCALL UserGetAncestor(HWND hWnd, UINT Type)
for(;;) for(;;)
{ {
tmp = Parent; tmp = Parent;
if(!(Parent = IntGetParentObject(WndAncestor))) if(!(Parent = WndAncestor->Parent))
{ {
break; break;
} }
if(IntIsDesktopWindow(Parent)) if(IntIsDesktopWindow(Parent))
{ {
IntReleaseWindowObject(Parent);
break; break;
} }
if(tmp)
IntReleaseWindowObject(tmp);
WndAncestor = Parent; WndAncestor = Parent;
} }
break; break;
@ -2674,17 +2670,21 @@ HWND FASTCALL UserGetAncestor(HWND hWnd, UINT Type)
case GA_ROOTOWNER: case GA_ROOTOWNER:
{ {
WndAncestor = Wnd; WndAncestor = Wnd;
IntReferenceWindowObject(WndAncestor);
for (;;) for (;;)
{ {
PWINDOW_OBJECT Old; PWINDOW_OBJECT Old;
Old = WndAncestor; Old = WndAncestor;
Parent = IntGetParent(WndAncestor); Parent = IntGetParent(WndAncestor);
IntReleaseWindowObject(Old);
if (!Parent) if (!Parent)
{ {
break; break;
} }
//temp hack
UserDerefObject(Parent);
WndAncestor = Parent; WndAncestor = Parent;
} }
break; break;
@ -2692,18 +2692,11 @@ HWND FASTCALL UserGetAncestor(HWND hWnd, UINT Type)
default: default:
{ {
IntReleaseWindowObject(Wnd);
return NULL; return NULL;
} }
} }
hWndAncestor = (WndAncestor ? WndAncestor->hSelf : NULL); return WndAncestor;
IntReleaseWindowObject(Wnd);
if(WndAncestor && (WndAncestor != Wnd))
IntReleaseWindowObject(WndAncestor);
return hWndAncestor;
} }
@ -2714,12 +2707,21 @@ HWND FASTCALL UserGetAncestor(HWND hWnd, UINT Type)
HWND STDCALL HWND STDCALL
NtUserGetAncestor(HWND hWnd, UINT Type) NtUserGetAncestor(HWND hWnd, UINT Type)
{ {
PWINDOW_OBJECT Window, Ancestor;
DECLARE_RETURN(HWND); DECLARE_RETURN(HWND);
DPRINT("Enter NtUserGetAncestor\n"); DPRINT("Enter NtUserGetAncestor\n");
UserEnterExclusive(); UserEnterExclusive();
if (!(Window = UserGetWindowObject(hWnd)))
{
RETURN(NULL);
}
RETURN(UserGetAncestor(hWnd, Type)); Ancestor = UserGetAncestor(Window, Type);
/* faxme: can UserGetAncestor ever return NULL for a valid window? */
RETURN(Ancestor ? Ancestor->hSelf : NULL);
CLEANUP: CLEANUP:
DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_); DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_);

View file

@ -120,6 +120,24 @@ CLEANUP:
END_CLEANUP; END_CLEANUP;
} }
/*******************************************************************
* can_activate_window
*
* Check if we can activate the specified window.
*/
static BOOL FASTCALL can_activate_window( PWINDOW_OBJECT Wnd )
{
LONG style;
if (!Wnd) return FALSE;
style = Wnd->Style;
if (!(style & WS_VISIBLE)) return FALSE;
if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
return !(style & WS_DISABLED);
}
/******************************************************************* /*******************************************************************
* WinPosActivateOtherWindow * WinPosActivateOtherWindow
* *
@ -128,7 +146,7 @@ CLEANUP:
VOID FASTCALL VOID FASTCALL
co_WinPosActivateOtherWindow(PWINDOW_OBJECT Window OPTIONAL) co_WinPosActivateOtherWindow(PWINDOW_OBJECT Window OPTIONAL)
{ {
PWINDOW_OBJECT Wnd, Old; PWINDOW_OBJECT Wnd;
HWND Fg; HWND Fg;
if (Window) if (Window)
@ -143,20 +161,8 @@ co_WinPosActivateOtherWindow(PWINDOW_OBJECT Window OPTIONAL)
/* If this is popup window, try to activate the owner first. */ /* If this is popup window, try to activate the owner first. */
if ((Window->Style & WS_POPUP) && (Wnd = IntGetOwner(Window))) if ((Window->Style & WS_POPUP) && (Wnd = IntGetOwner(Window)))
{ {
for(;;) Wnd = UserGetAncestor( Wnd, GA_ROOT );
{ if (can_activate_window(Wnd)) goto done;
Old = Wnd;
Wnd = Wnd->Parent;
if(IntIsDesktopWindow(Wnd))
{
Wnd = Old;
break;
}
}
if ((Wnd->Style & (WS_DISABLED | WS_VISIBLE)) == WS_VISIBLE &&
(Wnd->Style & (WS_POPUP | WS_CHILD)) != WS_CHILD)
goto done;
} }
/* Pick a next top-level window. */ /* Pick a next top-level window. */
@ -840,9 +846,11 @@ WinPosFixupFlags(WINDOWPOS *WinPos, PWINDOW_OBJECT Window)
&& HWND_NOTOPMOST != WinPos->hwndInsertAfter && HWND_NOTOPMOST != WinPos->hwndInsertAfter
&& HWND_BOTTOM != WinPos->hwndInsertAfter) && HWND_BOTTOM != WinPos->hwndInsertAfter)
{ {
PWINDOW_OBJECT Parent = Window->Parent; PWINDOW_OBJECT InsAfterWnd, Parent = Window->Parent;
if (UserGetAncestor(WinPos->hwndInsertAfter, GA_PARENT) !=
(Parent ? Parent->hSelf : NULL)) InsAfterWnd = UserGetWindowObject(WinPos->hwndInsertAfter);
if (InsAfterWnd && UserGetAncestor(InsAfterWnd, GA_PARENT) != Parent)
{ {
return FALSE; return FALSE;
} }
@ -932,7 +940,9 @@ co_WinPosSetWindowPos(
if ((WinPos.flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != if ((WinPos.flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) !=
SWP_NOZORDER && SWP_NOZORDER &&
UserGetAncestor(WinPos.hwnd, GA_PARENT) == IntGetDesktopWindow()) // UserGetAncestor(WinPos.hwnd, GA_PARENT) == IntGetDesktopWindow())
//faxme: is WinPos.hwnd constant?? (WinPos.hwnd = Window->hSelf above)
UserGetAncestor(Window, GA_PARENT)->hSelf == IntGetDesktopWindow())
{ {
WinPos.hwndInsertAfter = WinPosDoOwnedPopups(WinPos.hwnd, WinPos.hwndInsertAfter); WinPos.hwndInsertAfter = WinPosDoOwnedPopups(WinPos.hwnd, WinPos.hwndInsertAfter);
} }