From: Andrew Eikum aeikum@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/user32/menu.c | 69 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 33 deletions(-)
diff --git a/dlls/user32/menu.c b/dlls/user32/menu.c index 0aa4fb7ee5..71bd5dd51a 100644 --- a/dlls/user32/menu.c +++ b/dlls/user32/menu.c @@ -196,6 +196,10 @@ const struct builtin_class_descr MENU_builtin_class = (HBRUSH)(COLOR_MENU+1) /* brush */ };
+static HMENU MENU_GetHandle(const POPUPMENU *menu) +{ + return menu ? menu->obj.handle : NULL; +}
/*********************************************************************** * debug_print_menuitem @@ -1837,14 +1841,14 @@ UINT MENU_DrawMenuBar( HDC hDC, LPRECT lprect, HWND hwnd ) * * Popup menu initialization before WM_ENTERMENULOOP. */ -static BOOL MENU_InitPopup( HWND hwndOwner, HMENU hmenu, UINT flags ) +static BOOL MENU_InitPopup( HWND hwndOwner, POPUPMENU *menu, UINT flags ) { - POPUPMENU *menu; DWORD ex_style = 0;
- TRACE("owner=%p hmenu=%p\n", hwndOwner, hmenu); + TRACE("owner=%p menu=%p\n", hwndOwner, menu);
- if (!(menu = MENU_GetMenu( hmenu ))) return FALSE; + if (!menu) + return FALSE;
/* store the owner for DrawItem */ if (!IsWindow( hwndOwner )) @@ -1861,7 +1865,7 @@ static BOOL MENU_InitPopup( HWND hwndOwner, HMENU hmenu, UINT flags ) menu->hWnd = CreateWindowExW( ex_style, (LPCWSTR)POPUPMENU_CLASS_ATOM, NULL, WS_POPUP, 0, 0, 0, 0, hwndOwner, 0, (HINSTANCE)GetWindowLongPtrW(hwndOwner, GWLP_HINSTANCE), - (LPVOID)hmenu ); + (void *)MENU_GetHandle(menu) ); if( !menu->hWnd ) return FALSE; return TRUE; } @@ -1872,19 +1876,20 @@ static BOOL MENU_InitPopup( HWND hwndOwner, HMENU hmenu, UINT flags ) * * Display a popup menu. */ -static BOOL MENU_ShowPopup( HWND hwndOwner, HMENU hmenu, UINT id, UINT flags, +static BOOL MENU_ShowPopup( HWND hwndOwner, POPUPMENU *menu, UINT id, UINT flags, INT x, INT y, INT xanchor, INT yanchor ) { - POPUPMENU *menu; POINT pt; HMONITOR monitor; MONITORINFO info; UINT max_height;
- TRACE("owner=%p hmenu=%p id=0x%04x x=0x%04x y=0x%04x xa=0x%04x ya=0x%04x\n", - hwndOwner, hmenu, id, x, y, xanchor, yanchor); + TRACE("owner=%p menu=%p id=0x%04x x=0x%04x y=0x%04x xa=0x%04x ya=0x%04x\n", + hwndOwner, menu, id, x, y, xanchor, yanchor); + + if (!menu) + return FALSE;
- if (!(menu = MENU_GetMenu( hmenu ))) return FALSE; if (menu->FocusedItem != NO_SELECTED_ITEM) { menu->items[menu->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT); @@ -1939,7 +1944,7 @@ static BOOL MENU_ShowPopup( HWND hwndOwner, HMENU hmenu, UINT id, UINT flags,
if (!top_popup) { top_popup = menu->hWnd; - top_popup_hmenu = hmenu; + top_popup_hmenu = MENU_GetHandle(menu); } /* Display the window */
@@ -2290,16 +2295,13 @@ static HMENU MENU_GetSubPopup( HMENU hmenu ) * * Hide the sub-popup menus of this menu. */ -static void MENU_HideSubPopups( HWND hwndOwner, HMENU hmenu, +static void MENU_HideSubPopups( HWND hwndOwner, POPUPMENU *menu, BOOL sendMenuSelect, UINT wFlags ) { - POPUPMENU *menu = MENU_GetMenu( hmenu ); - - TRACE("owner=%p hmenu=%p 0x%04x\n", hwndOwner, hmenu, sendMenuSelect); + TRACE("owner=%p menu=%p 0x%04x\n", hwndOwner, menu, sendMenuSelect);
if (menu && top_popup) { - HMENU hsubmenu; POPUPMENU *submenu; MENUITEM *item;
@@ -2309,17 +2311,17 @@ static void MENU_HideSubPopups( HWND hwndOwner, HMENU hmenu, if (!(item->fType & MF_POPUP) || !(item->fState & MF_MOUSESELECT)) return; item->fState &= ~MF_MOUSESELECT; - hsubmenu = item->hSubMenu; + submenu = MENU_GetMenu(item->hSubMenu); } else return;
- if (!(submenu = MENU_GetMenu( hsubmenu ))) return; - MENU_HideSubPopups( hwndOwner, hsubmenu, FALSE, wFlags ); - MENU_SelectItem( hwndOwner, hsubmenu, NO_SELECTED_ITEM, sendMenuSelect, 0 ); + if (!submenu) return; + MENU_HideSubPopups( hwndOwner, submenu, FALSE, wFlags ); + MENU_SelectItem( hwndOwner, MENU_GetHandle(submenu), NO_SELECTED_ITEM, sendMenuSelect, 0 ); DestroyWindow( submenu->hWnd ); submenu->hWnd = 0;
if (!(wFlags & TPM_NONOTIFY)) - SendMessageW( hwndOwner, WM_UNINITMENUPOPUP, (WPARAM)hsubmenu, + SendMessageW( hwndOwner, WM_UNINITMENUPOPUP, (WPARAM)MENU_GetHandle(submenu), MAKELPARAM(0, IS_SYSTEM_MENU(submenu)) ); } } @@ -2423,9 +2425,9 @@ static HMENU MENU_ShowSubPopup( HWND hwndOwner, HMENU hmenu, /* use default alignment for submenus */ wFlags &= ~(TPM_CENTERALIGN | TPM_RIGHTALIGN | TPM_VCENTERALIGN | TPM_BOTTOMALIGN);
- MENU_InitPopup( hwndOwner, item->hSubMenu, wFlags ); + MENU_InitPopup( hwndOwner, MENU_GetMenu(item->hSubMenu), wFlags );
- MENU_ShowPopup( hwndOwner, item->hSubMenu, menu->FocusedItem, wFlags, + 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 ); @@ -2563,11 +2565,12 @@ static void MENU_SwitchTracking( MTRACKER* pmt, HMENU hPtMenu, UINT id, UINT wFl !((ptmenu->wFlags | topmenu->wFlags) & MF_POPUP) ) { /* both are top level menus (system and menu-bar) */ - MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE, wFlags ); + MENU_HideSubPopups( pmt->hOwnerWnd, MENU_GetMenu(pmt->hTopMenu), FALSE, wFlags ); MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE, 0 ); pmt->hTopMenu = hPtMenu; } - else MENU_HideSubPopups( pmt->hOwnerWnd, hPtMenu, FALSE, wFlags ); + else + MENU_HideSubPopups( pmt->hOwnerWnd, ptmenu, FALSE, wFlags ); MENU_SelectItem( pmt->hOwnerWnd, hPtMenu, id, TRUE, 0 ); }
@@ -2811,7 +2814,7 @@ static LRESULT MENU_DoNextMenu( MTRACKER* pmt, UINT vk, UINT wFlags ) MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE, 0 ); if( pmt->hCurrentMenu != pmt->hTopMenu ) - MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE, wFlags ); + MENU_HideSubPopups( pmt->hOwnerWnd, MENU_GetMenu(pmt->hTopMenu), FALSE, wFlags ); }
if( hNewWnd != pmt->hOwnerWnd ) @@ -2892,7 +2895,7 @@ static BOOL MENU_KeyEscape(MTRACKER* pmt, UINT wFlags) hmenutmp = MENU_GetSubPopup( hmenuprev ); }
- MENU_HideSubPopups( pmt->hOwnerWnd, hmenuprev, TRUE, wFlags ); + MENU_HideSubPopups( pmt->hOwnerWnd, MENU_GetMenu(hmenuprev), TRUE, wFlags ); pmt->hCurrentMenu = hmenuprev; bEndMenu = FALSE; } @@ -2931,7 +2934,7 @@ static void MENU_KeyLeft( MTRACKER* pmt, UINT wFlags, UINT msg ) hmenutmp = MENU_GetSubPopup( hmenuprev ); }
- MENU_HideSubPopups( pmt->hOwnerWnd, hmenuprev, TRUE, wFlags ); + MENU_HideSubPopups( pmt->hOwnerWnd, MENU_GetMenu(hmenuprev), TRUE, wFlags ); pmt->hCurrentMenu = hmenuprev;
if ( (hmenuprev == pmt->hTopMenu) && !(menu->wFlags & MF_POPUP) ) @@ -2994,7 +2997,7 @@ static void MENU_KeyRight( MTRACKER* pmt, UINT wFlags, UINT msg ) { if( pmt->hCurrentMenu != pmt->hTopMenu ) { - MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE, wFlags ); + MENU_HideSubPopups( pmt->hOwnerWnd, MENU_GetMenu(pmt->hTopMenu), FALSE, wFlags ); hmenutmp = pmt->hCurrentMenu = pmt->hTopMenu; } else hmenutmp = 0;
@@ -3297,7 +3300,7 @@ static BOOL MENU_TrackMenu( HMENU hmenu, UINT wFlags, INT x, INT y,
if( IsWindow( mt.hOwnerWnd ) ) { - MENU_HideSubPopups( mt.hOwnerWnd, mt.hTopMenu, FALSE, wFlags ); + MENU_HideSubPopups( mt.hOwnerWnd, menu, FALSE, wFlags );
if (menu && (menu->wFlags & MF_POPUP)) { @@ -3494,7 +3497,7 @@ BOOL WINAPI TrackPopupMenuEx( HMENU hMenu, UINT wFlags, INT x, INT y, return FALSE; }
- if (MENU_InitPopup( hWnd, hMenu, wFlags )) + if (MENU_InitPopup( hWnd, menu, wFlags )) { MENU_InitTracking(hWnd, hMenu, TRUE, wFlags);
@@ -3506,7 +3509,7 @@ BOOL WINAPI TrackPopupMenuEx( HMENU hMenu, UINT wFlags, INT x, INT y, MENU_InitSysMenuPopup( hMenu, GetWindowLongW( hWnd, GWL_STYLE ), GetClassLongW( hWnd, GCL_STYLE));
- if (MENU_ShowPopup( hWnd, hMenu, 0, wFlags, x, y, 0, 0 )) + if (MENU_ShowPopup( hWnd, MENU_GetMenu(hMenu), 0, wFlags, x, y, 0, 0 )) ret = MENU_TrackMenu( hMenu, wFlags | TPM_POPUPMENU, 0, 0, hWnd, lpTpm ? &lpTpm->rcExclude : NULL ); MENU_ExitTracking(hWnd, TRUE); @@ -3796,7 +3799,7 @@ BOOL WINAPI HiliteMenuItem( HWND hWnd, HMENU hMenu, UINT wItemID, if (!MENU_FindItem( &hMenu, &wItemID, wHilite )) return FALSE; if (!(menu = MENU_GetMenu(hMenu))) return FALSE; if (menu->FocusedItem == wItemID) return TRUE; - MENU_HideSubPopups( hWnd, hMenu, FALSE, 0 ); + MENU_HideSubPopups( hWnd, menu, FALSE, 0 ); MENU_SelectItem( hWnd, hMenu, wItemID, TRUE, 0 ); return TRUE; }