[PATCH 4/6] user32: Don't rely on HMENU for selecting menus
Nikolay Sivov
nsivov at codeweavers.com
Tue Apr 10 01:36:53 CDT 2018
From: Andrew Eikum <aeikum at codeweavers.com>
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
dlls/user32/menu.c | 79 ++++++++++++++++++++++++------------------------------
1 file changed, 35 insertions(+), 44 deletions(-)
diff --git a/dlls/user32/menu.c b/dlls/user32/menu.c
index f5176fdeca..9a786dbb85 100644
--- a/dlls/user32/menu.c
+++ b/dlls/user32/menu.c
@@ -2008,15 +2008,13 @@ MENU_EnsureMenuItemVisible(LPPOPUPMENU lppop, UINT wIndex, HDC hdc)
/***********************************************************************
* MENU_SelectItem
*/
-static void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex,
- BOOL sendMenuSelect, HMENU htopmenu )
+static void MENU_SelectItem( HWND hwndOwner, POPUPMENU *lppop, UINT wIndex,
+ BOOL sendMenuSelect, POPUPMENU *topmenu )
{
- LPPOPUPMENU lppop;
HDC hdc;
- TRACE("owner=%p menu=%p index=0x%04x select=0x%04x\n", hwndOwner, hmenu, wIndex, sendMenuSelect);
+ TRACE("owner=%p menu=%p index=0x%04x select=0x%04x\n", hwndOwner, lppop, wIndex, sendMenuSelect);
- lppop = MENU_GetMenu( hmenu );
if ((!lppop) || (!lppop->nItems) || (!lppop->hWnd)) return;
if (lppop->FocusedItem == wIndex) return;
@@ -2024,7 +2022,7 @@ static void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex,
else hdc = GetDCEx( lppop->hWnd, 0, DCX_CACHE | DCX_WINDOW);
if (!top_popup) {
top_popup = lppop->hWnd;
- top_popup_hmenu = hmenu;
+ top_popup_hmenu = MENU_GetHandle(lppop);
}
SelectObject( hdc, get_menu_font(FALSE));
@@ -2053,13 +2051,12 @@ static void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex,
SendMessageW( hwndOwner, WM_MENUSELECT,
MAKEWPARAM(ip->fType & MF_POPUP ? wIndex: ip->wID,
ip->fType | ip->fState |
- (lppop->wFlags & MF_SYSMENU)), (LPARAM)hmenu);
+ (lppop->wFlags & MF_SYSMENU)), (LPARAM)MENU_GetHandle(lppop));
}
}
- else if (sendMenuSelect) {
- POPUPMENU *topmenu;
-
- if (htopmenu && (topmenu = MENU_GetMenu(htopmenu)))
+ else if (sendMenuSelect)
+ {
+ if (topmenu)
{
int pos;
if ((pos=MENU_FindSubMenu(&topmenu, lppop)) != NO_SELECTED_ITEM)
@@ -2067,7 +2064,7 @@ static void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex,
MENUITEM *ip = &topmenu->items[pos];
SendMessageW( hwndOwner, WM_MENUSELECT, MAKEWPARAM(pos,
ip->fType | ip->fState |
- (topmenu->wFlags & MF_SYSMENU)), (LPARAM)htopmenu);
+ (topmenu->wFlags & MF_SYSMENU)), (LPARAM)MENU_GetHandle(topmenu));
}
}
}
@@ -2082,14 +2079,12 @@ static void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex,
* If there is no selection then it should select the last item if
* offset is ITEM_PREV or the first item if offset is ITEM_NEXT.
*/
-static void MENU_MoveSelection( HWND hwndOwner, HMENU hmenu, INT offset )
+static void MENU_MoveSelection( HWND hwndOwner, POPUPMENU *menu, INT offset )
{
INT i;
- POPUPMENU *menu;
- TRACE("hwnd=%p hmenu=%p off=0x%04x\n", hwndOwner, hmenu, offset);
+ TRACE("hwnd=%p menu=%p off=0x%04x\n", hwndOwner, menu, offset);
- menu = MENU_GetMenu( hmenu );
if ((!menu) || (!menu->items)) return;
if ( menu->FocusedItem != NO_SELECTED_ITEM )
@@ -2099,7 +2094,7 @@ static void MENU_MoveSelection( HWND hwndOwner, HMENU hmenu, INT offset )
; i += offset)
if (!(menu->items[i].fType & MF_SEPARATOR))
{
- MENU_SelectItem( hwndOwner, hmenu, i, TRUE, 0 );
+ MENU_SelectItem( hwndOwner, menu, i, TRUE, 0 );
return;
}
}
@@ -2108,7 +2103,7 @@ static void MENU_MoveSelection( HWND hwndOwner, HMENU hmenu, INT offset )
i >= 0 && i < menu->nItems ; i += offset)
if (!(menu->items[i].fType & MF_SEPARATOR))
{
- MENU_SelectItem( hwndOwner, hmenu, i, TRUE, 0 );
+ MENU_SelectItem( hwndOwner, menu, i, TRUE, 0 );
return;
}
}
@@ -2323,7 +2318,7 @@ static void MENU_HideSubPopups( HWND hwndOwner, POPUPMENU *menu,
if (!submenu) return;
MENU_HideSubPopups( hwndOwner, submenu, FALSE, wFlags );
- MENU_SelectItem( hwndOwner, MENU_GetHandle(submenu), NO_SELECTED_ITEM, sendMenuSelect, 0 );
+ MENU_SelectItem( hwndOwner, submenu, NO_SELECTED_ITEM, sendMenuSelect, 0 );
DestroyWindow( submenu->hWnd );
submenu->hWnd = 0;
@@ -2437,7 +2432,7 @@ static HMENU MENU_ShowSubPopup( HWND hwndOwner, HMENU hmenu,
MENU_ShowPopup( hwndOwner, MENU_GetMenu(item->hSubMenu), menu->FocusedItem, wFlags,
rect.left, rect.top, rect.right, rect.bottom );
if (selectFirst)
- MENU_MoveSelection( hwndOwner, item->hSubMenu, ITEM_NEXT );
+ MENU_MoveSelection( hwndOwner, MENU_GetMenu(item->hSubMenu), ITEM_NEXT );
return item->hSubMenu;
}
@@ -2571,14 +2566,14 @@ static void MENU_SwitchTracking( MTRACKER* pmt, HMENU hPtMenu, UINT id, UINT wFl
if( pmt->hTopMenu != hPtMenu &&
!((ptmenu->wFlags | topmenu->wFlags) & MF_POPUP) )
{
- /* both are top level menus (system and menu-bar) */
- MENU_HideSubPopups( pmt->hOwnerWnd, MENU_GetMenu(pmt->hTopMenu), FALSE, wFlags );
- MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
+ /* both are top level menus (system and menu-bar) */
+ MENU_HideSubPopups( pmt->hOwnerWnd, topmenu, FALSE, wFlags );
+ MENU_SelectItem( pmt->hOwnerWnd, topmenu, NO_SELECTED_ITEM, FALSE, 0 );
pmt->hTopMenu = hPtMenu;
}
else
MENU_HideSubPopups( pmt->hOwnerWnd, ptmenu, FALSE, wFlags );
- MENU_SelectItem( pmt->hOwnerWnd, hPtMenu, id, TRUE, 0 );
+ MENU_SelectItem( pmt->hOwnerWnd, ptmenu, id, TRUE, 0 );
}
@@ -2692,9 +2687,8 @@ static BOOL MENU_MouseMove( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags )
if( id == NO_SELECTED_ITEM )
{
- MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
- NO_SELECTED_ITEM, TRUE, pmt->hTopMenu);
-
+ MENU_SelectItem( pmt->hOwnerWnd, MENU_GetMenu(pmt->hCurrentMenu),
+ NO_SELECTED_ITEM, TRUE, MENU_GetMenu(pmt->hTopMenu));
}
else if( ptmenu->FocusedItem != id )
{
@@ -2818,7 +2812,7 @@ static LRESULT MENU_DoNextMenu( MTRACKER* pmt, UINT vk, UINT wFlags )
if( hNewMenu != pmt->hTopMenu )
{
- MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM,
+ MENU_SelectItem( pmt->hOwnerWnd, MENU_GetMenu(pmt->hTopMenu), NO_SELECTED_ITEM,
FALSE, 0 );
if( pmt->hCurrentMenu != pmt->hTopMenu )
MENU_HideSubPopups( pmt->hOwnerWnd, MENU_GetMenu(pmt->hTopMenu), FALSE, wFlags );
@@ -2831,7 +2825,7 @@ static LRESULT MENU_DoNextMenu( MTRACKER* pmt, UINT vk, UINT wFlags )
}
pmt->hTopMenu = pmt->hCurrentMenu = hNewMenu; /* all subpopups are hidden */
- MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, id, TRUE, 0 );
+ MENU_SelectItem( pmt->hOwnerWnd, MENU_GetMenu(pmt->hTopMenu), id, TRUE, 0 );
return TRUE;
}
@@ -2929,8 +2923,7 @@ static void MENU_KeyLeft( MTRACKER* pmt, UINT wFlags, UINT msg )
if( (prevcol = MENU_GetStartOfPrevColumn( pmt->hCurrentMenu )) !=
NO_SELECTED_ITEM ) {
- MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
- prevcol, TRUE, 0 );
+ MENU_SelectItem( pmt->hOwnerWnd, MENU_GetMenu(pmt->hCurrentMenu), prevcol, TRUE, 0 );
return;
}
@@ -2949,7 +2942,7 @@ static void MENU_KeyLeft( MTRACKER* pmt, UINT wFlags, UINT msg )
/* move menu bar selection if no more popups are left */
if( !MENU_DoNextMenu( pmt, VK_LEFT, wFlags ) )
- MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_PREV );
+ MENU_MoveSelection( pmt->hOwnerWnd, MENU_GetMenu(pmt->hTopMenu), ITEM_PREV );
if ( hmenuprev != hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
{
@@ -2995,8 +2988,7 @@ static void MENU_KeyRight( MTRACKER* pmt, UINT wFlags, UINT msg )
if( (nextcol = MENU_GetStartOfNextColumn( pmt->hCurrentMenu )) !=
NO_SELECTED_ITEM ) {
TRACE("Going to %d.\n", nextcol );
- MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
- nextcol, TRUE, 0 );
+ MENU_SelectItem( pmt->hOwnerWnd, MENU_GetMenu(pmt->hCurrentMenu), nextcol, TRUE, 0 );
return;
}
@@ -3010,7 +3002,7 @@ static void MENU_KeyRight( MTRACKER* pmt, UINT wFlags, UINT msg )
/* try to move to the next item */
if( !MENU_DoNextMenu( pmt, VK_RIGHT, wFlags ) )
- MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_NEXT );
+ MENU_MoveSelection( pmt->hOwnerWnd, menu, ITEM_NEXT );
if( hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
if( !MENU_SuspendPopup( pmt, msg ) )
@@ -3197,9 +3189,9 @@ static BOOL MENU_TrackMenu( HMENU hmenu, UINT wFlags, INT x, INT y,
case VK_HOME:
case VK_END:
- MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu,
+ MENU_SelectItem( mt.hOwnerWnd, MENU_GetMenu(mt.hCurrentMenu),
NO_SELECTED_ITEM, FALSE, 0 );
- MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu,
+ MENU_MoveSelection( mt.hOwnerWnd, MENU_GetMenu(mt.hCurrentMenu),
(msg.wParam == VK_HOME)? ITEM_NEXT : ITEM_PREV );
break;
@@ -3210,7 +3202,7 @@ static BOOL MENU_TrackMenu( HMENU hmenu, UINT wFlags, INT x, INT y,
if (!(menu->wFlags & MF_POPUP))
mt.hCurrentMenu = MENU_ShowSubPopup(mt.hOwnerWnd, mt.hTopMenu, TRUE, wFlags);
else /* otherwise try to move selection */
- MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu,
+ MENU_MoveSelection( mt.hOwnerWnd, MENU_GetMenu(mt.hCurrentMenu),
(msg.wParam == VK_UP)? ITEM_PREV : ITEM_NEXT );
break;
@@ -3271,8 +3263,7 @@ static BOOL MENU_TrackMenu( HMENU hmenu, UINT wFlags, INT x, INT y,
else if (pos == (UINT)-1) MessageBeep(0);
else
{
- MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu, pos,
- TRUE, 0 );
+ MENU_SelectItem( mt.hOwnerWnd, MENU_GetMenu(mt.hCurrentMenu), pos, TRUE, 0 );
executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
fEndMenu = (executedMenuId != -2);
}
@@ -3318,7 +3309,7 @@ static BOOL MENU_TrackMenu( HMENU hmenu, UINT wFlags, INT x, INT y,
SendMessageW( mt.hOwnerWnd, WM_UNINITMENUPOPUP, (WPARAM)mt.hTopMenu,
MAKELPARAM(0, IS_SYSTEM_MENU(menu)) );
}
- MENU_SelectItem( mt.hOwnerWnd, mt.hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
+ MENU_SelectItem( mt.hOwnerWnd, MENU_GetMenu(mt.hTopMenu), NO_SELECTED_ITEM, FALSE, 0 );
SendMessageW( mt.hOwnerWnd, WM_MENUSELECT, MAKEWPARAM(0,0xffff), 0 );
}
}
@@ -3461,12 +3452,12 @@ void MENU_TrackKbdMenuBar( HWND hwnd, UINT wParam, WCHAR wChar)
}
}
- MENU_SelectItem( hwnd, hTrackMenu, uItem, TRUE, 0 );
+ MENU_SelectItem( hwnd, MENU_GetMenu(hTrackMenu), uItem, TRUE, 0 );
if (!(wParam & HTSYSMENU) || wChar == ' ')
{
if( uItem == NO_SELECTED_ITEM )
- MENU_MoveSelection( hwnd, hTrackMenu, ITEM_NEXT );
+ MENU_MoveSelection( hwnd, MENU_GetMenu(hTrackMenu), ITEM_NEXT );
else
PostMessageW( hwnd, WM_KEYDOWN, VK_RETURN, 0 );
}
@@ -3813,7 +3804,7 @@ BOOL WINAPI HiliteMenuItem( HWND hWnd, HMENU hMenu, UINT wItemID,
if (!(item = MENU_FindItem( &menu, &wItemID, wHilite ))) return FALSE;
if (menu->FocusedItem == wItemID) return TRUE;
MENU_HideSubPopups( hWnd, menu, FALSE, 0 );
- MENU_SelectItem( hWnd, MENU_GetHandle(menu), wItemID, TRUE, 0 );
+ MENU_SelectItem( hWnd, menu, wItemID, TRUE, 0 );
return TRUE;
}
--
2.16.3
More information about the wine-devel
mailing list