Index: win32ss/user/ntuser/accelerator.c =================================================================== --- win32ss/user/ntuser/accelerator.c (revision 63011) +++ win32ss/user/ntuser/accelerator.c (working copy) @@ -51,7 +51,6 @@ co_IntTranslateAccelerator( HWND hWnd; HMENU hMenu, hSubMenu; PMENU_OBJECT MenuObject, SubMenu; - PMENU_ITEM MenuItem; ASSERT_REFS_CO(Window); @@ -107,7 +106,7 @@ co_IntTranslateAccelerator( pAccel->cmd, MF_BYCOMMAND, &SubMenu, - &MenuItem, + NULL, NULL); if (nPos != (UINT) - 1) hSubMenu = SubMenu->head.h; @@ -126,7 +125,7 @@ co_IntTranslateAccelerator( pAccel->cmd, MF_BYCOMMAND, &SubMenu, - &MenuItem, + NULL, NULL); if (nPos != (UINT) - 1) hSubMenu = SubMenu->head.h; Index: win32ss/user/ntuser/menu.c =================================================================== --- win32ss/user/ntuser/menu.c (revision 63011) +++ win32ss/user/ntuser/menu.c (working copy) @@ -162,20 +162,18 @@ IntRemoveMenuItem(PMENU_OBJECT Menu, UIN BOOL bRecurse) { PMENU_ITEM PrevMenuItem, MenuItem; - if(IntGetMenuItemByFlag(Menu, uPosition, uFlags, &Menu, &MenuItem, + PMENU_OBJECT SubMenu; + if(IntGetMenuItemByFlag(Menu, uPosition, uFlags, &SubMenu, &MenuItem, &PrevMenuItem) > -1) { - if(MenuItem) - { - if(PrevMenuItem) - PrevMenuItem->Next = MenuItem->Next; - else - { - Menu->MenuItemList = MenuItem->Next; - } - Menu->MenuInfo.MenuItemCount--; - return IntFreeMenuItem(Menu, MenuItem, bRecurse); - } + if(SubMenu) + Menu = SubMenu; + if(PrevMenuItem) + PrevMenuItem->Next = MenuItem->Next; + else + Menu->MenuItemList = MenuItem->Next; + Menu->MenuInfo.MenuItemCount--; + return IntFreeMenuItem(Menu, MenuItem, bRecurse); } return FALSE; } @@ -497,7 +495,7 @@ IntGetMenuItemByFlag(PMENU_OBJECT Menu, int p; int ret; - if(MF_BYPOSITION & fFlag) + if(fFlag & MF_BYPOSITION) { p = uSearchBy; while(CurItem && (p > 0)) @@ -512,17 +510,13 @@ IntGetMenuItemByFlag(PMENU_OBJECT Menu, *MenuItem = CurItem; if(PrevMenuItem) *PrevMenuItem = PrevItem; - } - else - { - if(MenuItem) - *MenuItem = NULL; - if(PrevMenuItem) - *PrevMenuItem = NULL; /* ? */ - return -1; - } + if(SubMenu) + *SubMenu = NULL; - return uSearchBy - p; + /* FIXME: uSearchBy == -1 fairly frequently... why? */ + ASSERT(p == 0 || (int)uSearchBy < 0); + return uSearchBy - p; + } } else { @@ -536,8 +530,9 @@ IntGetMenuItemByFlag(PMENU_OBJECT Menu, if(PrevMenuItem) *PrevMenuItem = PrevItem; if(SubMenu) - *SubMenu = Menu; + *SubMenu = Menu; + ASSERT(p >= 0); return p; } else @@ -547,12 +542,13 @@ IntGetMenuItemByFlag(PMENU_OBJECT Menu, PMENU_OBJECT NewMenu = UserGetMenuObject(CurItem->hSubMenu); if(NewMenu) { - ret = IntGetMenuItemByFlag(NewMenu, uSearchBy, fFlag, - SubMenu, MenuItem, PrevMenuItem); - if(ret != -1) - { - return ret; - } + ret = IntGetMenuItemByFlag(NewMenu, uSearchBy, fFlag, + SubMenu, MenuItem, PrevMenuItem); + if(ret != -1) + { + ASSERT(ret >= 0); + return ret; + } } } } @@ -561,6 +557,12 @@ IntGetMenuItemByFlag(PMENU_OBJECT Menu, p++; } } + if(MenuItem) + *MenuItem = NULL; + if(PrevMenuItem) + *PrevMenuItem = NULL; + if(SubMenu) + *SubMenu = NULL; return -1; } @@ -841,7 +843,7 @@ IntInsertMenuItem( } if (SubMenu == NULL) { - /* Default to last position of menu */ + /* Default to last position of menu */ SubMenu = MenuObject; pos = MenuObject->MenuInfo.MenuItemCount; } @@ -890,7 +892,7 @@ IntEnableMenuItem(PMENU_OBJECT MenuObjec { PMENU_ITEM MenuItem; UINT res = IntGetMenuItemByFlag(MenuObject, uIDEnableItem, uEnable, NULL, &MenuItem, NULL); - if(!MenuItem || (res == (UINT)-1)) + if(res == (UINT)-1) { return (UINT)-1; } @@ -1023,7 +1025,7 @@ IntCheckMenuItem(PMENU_OBJECT MenuObject PMENU_ITEM MenuItem; int res = -1; - if((IntGetMenuItemByFlag(MenuObject, uIDCheckItem, uCheck, NULL, &MenuItem, NULL) < 0) || !MenuItem) + if(IntGetMenuItemByFlag(MenuObject, uIDCheckItem, uCheck, NULL, &MenuItem, NULL) < 0) { return -1; } @@ -1052,7 +1054,7 @@ IntHiliteMenuItem(PWND WindowObject, Pos = IntGetMenuItemByFlag(MenuObject, uItemHilite, uHilite, NULL, &MenuItem, NULL); - if (!MenuItem || (uHilite & MF_BYPOSITION && Pos == -1)) + if (Pos < 0) { return FALSE; } @@ -1420,7 +1422,7 @@ UserInsertMenuItem( return FALSE; } -UINT FASTCALL IntGetMenuState( HMENU hMenu, UINT uId, UINT uFlags) +UINT FASTCALL IntGetMenuState(HMENU hMenu, UINT uId, UINT uFlags) { PMENU_OBJECT MenuObject, SubMenu; PMENU_ITEM mi; @@ -1430,39 +1432,24 @@ UINT FASTCALL IntGetMenuState( HMENU hMe return (UINT)-1; } - if (IntGetMenuItemByFlag(MenuObject, uId, uFlags, &SubMenu, &mi, NULL)) + if (IntGetMenuItemByFlag(MenuObject, uId, uFlags, NULL, &mi, NULL)) { if (mi->hSubMenu) { + SubMenu = UserGetMenuObject(mi->hSubMenu); if (SubMenu) { UINT nSubItems = SubMenu->MenuInfo.MenuItemCount; return (nSubItems << 8) | ((mi->fState | mi->fType) & 0xff); } - else - return (UINT)-1; + return (UINT)-1; } return (mi->fType | mi->fState); } return (UINT)-1; } -HMENU FASTCALL IntGetSubMenu( HMENU hMenu, int nPos) -{ - PMENU_OBJECT MenuObject, SubMenu; - - if (!(MenuObject = UserGetMenuObject(hMenu))) - { - return NULL; - } - if (IntGetMenuItemByFlag(MenuObject, nPos, MF_BYPOSITION, &SubMenu, NULL, NULL)) - { - return SubMenu ? UserHMGetHandle(SubMenu) : NULL; - } - return NULL; -} - -UINT FASTCALL IntFindSubMenu(HMENU *hMenu, HMENU hSubTarget ) +UINT FASTCALL IntFindSubMenu(HMENU *hMenu, HMENU hSubTarget) { PMENU_OBJECT MenuObject; PMENU_ITEM mi; @@ -1473,26 +1460,26 @@ UINT FASTCALL IntFindSubMenu(HMENU *hMen for (i = 0; i < MenuObject->MenuInfo.MenuItemCount; i++) { - if (!IntGetMenuItemByFlag(MenuObject, i, MF_BYPOSITION, NULL, &mi, NULL)) + if (IntGetMenuItemByFlag(MenuObject, i, MF_BYPOSITION, NULL, &mi, NULL) < 0) { - return NO_SELECTED_ITEM; + return NO_SELECTED_ITEM; } if (!(mi->hSubMenu)) continue; if (mi->hSubMenu == hSubTarget) { - return i; + return i; } else { - HMENU hsubmenu = mi->hSubMenu; - UINT pos = IntFindSubMenu(&hsubmenu, hSubTarget ); - if (pos != NO_SELECTED_ITEM) - { - *hMenu = hsubmenu; - return pos; - } + HMENU hsubmenu = mi->hSubMenu; + UINT pos = IntFindSubMenu(&hsubmenu, hSubTarget); + if (pos != NO_SELECTED_ITEM) + { + *hMenu = hsubmenu; + return pos; + } } } return NO_SELECTED_ITEM; @@ -1751,19 +1738,18 @@ IntGetMenuItemRect( { LONG XMove, YMove; PMENU_ITEM MenuItem; - int p = 0; if (!pWnd) { HWND hWnd = Menu->MenuInfo.Wnd; if (!(pWnd = UserGetWindowObject(hWnd))) return FALSE; } - - if ((p = IntGetMenuItemByFlag(Menu, uItem, MF_BYPOSITION, NULL, &MenuItem, NULL)) > -1) - *Rect = MenuItem->Rect; + + if (IntGetMenuItemByFlag(Menu, uItem, MF_BYPOSITION, NULL, &MenuItem, NULL) > -1) + *Rect = MenuItem->Rect; else { - ERR("Failed Item Lookup! %d\n", p); + ERR("Failed Item Lookup!\n"); return FALSE; } @@ -1890,7 +1876,7 @@ NtUserGetMenuBarInfo( if ( kmbi.fFocused && Menu->MenuItemList->hSubMenu ) { - SubMenuObject = UserGetMenuObject(Menu->MenuItemList->hSubMenu); + SubMenuObject = UserGetMenuObject(Menu->MenuItemList->hSubMenu); if (SubMenuObject) kmbi.hwndMenu = SubMenuObject->MenuInfo.Wnd; } } @@ -1985,7 +1971,7 @@ NtUserGetMenuItemRect( } if (IntGetMenuItemByFlag(Menu, uItem, MF_BYPOSITION, NULL, &MenuItem, NULL) > -1) - Rect = MenuItem->Rect; + Rect = MenuItem->Rect; else RETURN(FALSE);