Commit db79a9f2 authored by Alexandre Julliard's avatar Alexandre Julliard

user32: Use client-side user handles for menus.

parent 4bb95f4d
...@@ -92,8 +92,8 @@ typedef struct { ...@@ -92,8 +92,8 @@ typedef struct {
/* Popup menu structure */ /* Popup menu structure */
typedef struct { typedef struct {
struct user_object obj;
WORD wFlags; /* Menu flags (MF_POPUP, MF_SYSMENU) */ WORD wFlags; /* Menu flags (MF_POPUP, MF_SYSMENU) */
WORD wMagic; /* Magic number */
WORD Width; /* Width of the whole menu */ WORD Width; /* Width of the whole menu */
WORD Height; /* Height of the whole menu */ WORD Height; /* Height of the whole menu */
UINT nItems; /* Number of items in the menu */ UINT nItems; /* Number of items in the menu */
...@@ -299,12 +299,15 @@ static void do_debug_print_menuitem(const char *prefix, const MENUITEM *mp, ...@@ -299,12 +299,15 @@ static void do_debug_print_menuitem(const char *prefix, const MENUITEM *mp,
*/ */
static POPUPMENU *MENU_GetMenu(HMENU hMenu) static POPUPMENU *MENU_GetMenu(HMENU hMenu)
{ {
POPUPMENU *menu = USER_HEAP_LIN_ADDR(hMenu); POPUPMENU *menu = get_user_handle_ptr( hMenu, USER_MENU );
if (!menu || menu->wMagic != MENU_MAGIC)
if (menu == OBJ_OTHER_PROCESS)
{ {
WARN("invalid menu handle=%p, ptr=%p, magic=%x\n", hMenu, menu, menu? menu->wMagic:0); WARN( "other process menu %p?\n", hMenu);
menu = NULL; return NULL;
} }
if (menu) release_user_handle_ptr( menu ); /* FIXME! */
else WARN("invalid menu handle=%p\n", hMenu);
return menu; return menu;
} }
...@@ -4028,14 +4031,13 @@ HMENU WINAPI CreateMenu(void) ...@@ -4028,14 +4031,13 @@ HMENU WINAPI CreateMenu(void)
{ {
HMENU hMenu; HMENU hMenu;
LPPOPUPMENU menu; LPPOPUPMENU menu;
if (!(hMenu = USER_HEAP_ALLOC( sizeof(POPUPMENU) ))) return 0;
menu = USER_HEAP_LIN_ADDR(hMenu);
ZeroMemory(menu, sizeof(POPUPMENU)); if (!(menu = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*menu) ))) return 0;
menu->wMagic = MENU_MAGIC;
menu->FocusedItem = NO_SELECTED_ITEM; menu->FocusedItem = NO_SELECTED_ITEM;
menu->bTimeToHide = FALSE; menu->bTimeToHide = FALSE;
if (!(hMenu = alloc_user_handle( &menu->obj, USER_MENU ))) HeapFree( GetProcessHeap(), 0, menu );
TRACE("return %p\n", hMenu ); TRACE("return %p\n", hMenu );
return hMenu; return hMenu;
...@@ -4047,14 +4049,12 @@ HMENU WINAPI CreateMenu(void) ...@@ -4047,14 +4049,12 @@ HMENU WINAPI CreateMenu(void)
*/ */
BOOL WINAPI DestroyMenu( HMENU hMenu ) BOOL WINAPI DestroyMenu( HMENU hMenu )
{ {
LPPOPUPMENU lppop = MENU_GetMenu(hMenu); LPPOPUPMENU lppop;
TRACE("(%p)\n", hMenu); TRACE("(%p)\n", hMenu);
if (!(lppop = free_user_handle( hMenu, USER_MENU ))) return FALSE;
if (!lppop) return FALSE; if (lppop == OBJ_OTHER_PROCESS) return FALSE;
lppop->wMagic = 0; /* Mark it as destroyed */
/* DestroyMenu should not destroy system menu popup owner */ /* DestroyMenu should not destroy system menu popup owner */
if ((lppop->wFlags & (MF_POPUP | MF_SYSMENU)) == MF_POPUP && lppop->hWnd) if ((lppop->wFlags & (MF_POPUP | MF_SYSMENU)) == MF_POPUP && lppop->hWnd)
...@@ -4074,7 +4074,7 @@ BOOL WINAPI DestroyMenu( HMENU hMenu ) ...@@ -4074,7 +4074,7 @@ BOOL WINAPI DestroyMenu( HMENU hMenu )
} }
HeapFree( GetProcessHeap(), 0, lppop->items ); HeapFree( GetProcessHeap(), 0, lppop->items );
} }
USER_HEAP_FREE( hMenu ); HeapFree( GetProcessHeap(), 0, lppop );
return TRUE; return TRUE;
} }
......
...@@ -173,6 +173,7 @@ struct hook16_queue_info; ...@@ -173,6 +173,7 @@ struct hook16_queue_info;
enum user_obj_type enum user_obj_type
{ {
USER_WINDOW = 1, /* window */ USER_WINDOW = 1, /* window */
USER_MENU, /* menu */
USER_DWP /* DeferWindowPos structure */ USER_DWP /* DeferWindowPos structure */
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment