
user: remove more menu item pointers from function interfaces


Thomas Kho

---

 dlls/user/menu.c |   85 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 58 insertions(+), 27 deletions(-)

diff --git a/dlls/user/menu.c b/dlls/user/menu.c
index 7780bd5..c688931 100644
--- a/dlls/user/menu.c
+++ b/dlls/user/menu.c
@@ -789,7 +789,7 @@ MENU_AdjustMenuItemRect(HMENU hmenu, LPR
  * not work for child windows and therefore should not be called for
  * an arbitrary system menu.
  */
-static MENUITEM *MENU_FindItemByCoords( HMENU hmenu, POINT pt, UINT *pos )
+static void MENU_FindItemByCoords( HMENU hmenu, POINT pt, UINT *pos )
 {
     MENUITEM *item;
     UINT i;
@@ -799,7 +799,9 @@ static MENUITEM *MENU_FindItemByCoords( 
     LPPOPUPMENU menu = &tmpmenu;
     MENU_GetMenu(hmenu, menu);
 
-    if (!GetWindowRect(menu->hWnd,&wrect)) return NULL;
+    *pos = ITEM_NOT_FOUND;
+
+    if (!GetWindowRect(menu->hWnd,&wrect)) return;
     pt.x -= wrect.left;pt.y -= wrect.top;
     item = menu->items;
     for (i = 0; i < menu->nItems; i++, item++)
@@ -810,10 +812,10 @@ static MENUITEM *MENU_FindItemByCoords( 
 	    (pt.y >= rect.top) && (pt.y < rect.bottom))
 	{
 	    if (pos) *pos = i;
-	    return item;
+	    return;
 	}
     }
-    return NULL;
+    return;
 }
 
 
@@ -2206,14 +2208,14 @@ static BOOL MENU_SetItemData( MENUITEM *
  *
  * Insert (allocate) a new item into a menu.
  */
-static MENUITEM *MENU_InsertItem( HMENU hMenu, UINT pos, UINT flags )
+static UINT MENU_InsertItem( HMENU hMenu, UINT pos, UINT flags )
 {
     MENUITEM *newItems;
     POPUPMENU tmpmenu;
     POPUPMENU *menu = &tmpmenu;
 
     if (MENU_GetMenu(hMenu, menu))
-        return NULL;
+        return ITEM_NOT_FOUND;
 
     /* Find where to insert new item */
 
@@ -2225,7 +2227,7 @@ static MENUITEM *MENU_InsertItem( HMENU 
             pos = menu->nItems;
         else {
             if (MENU_GetMenu(hMenu, menu))
-                return NULL;
+                return ITEM_NOT_FOUND;
         }
     }
 
@@ -2235,7 +2237,7 @@ static MENUITEM *MENU_InsertItem( HMENU 
     if (!newItems)
     {
         WARN("allocation failed\n" );
-        return NULL;
+        return ITEM_NOT_FOUND;
     }
     if (menu->nItems > 0)
     {
@@ -2250,7 +2252,7 @@ static MENUITEM *MENU_InsertItem( HMENU 
     memset( &newItems[pos], 0, sizeof(*newItems) );
     menu->Height = 0; /* force size recalculate */
     MENU_UpdateMenu(hMenu, menu, SET_MI_ITEMS|SET_MI_NITEMS|SET_MI_HEIGHT);
-    return &newItems[pos];
+    return pos;
 }
 
 
@@ -2660,7 +2662,12 @@ static BOOL MENU_ButtonDown( MTRACKER* p
 	if( IS_SYSTEM_MENU(ptmenu) )
 	    item = ptmenu->items;
 	else
-	    item = MENU_FindItemByCoords( hPtMenu, pmt->pt, &id );
+        {
+            POPUPMENU menu;
+	    MENU_FindItemByCoords( hPtMenu, pmt->pt, &id );
+            MENU_GetMenu(hPtMenu, &menu);
+            item = (id == ITEM_NOT_FOUND) ? NULL : &menu.items[id];
+        }
 
 	if( item )
 	{
@@ -2703,7 +2710,12 @@ static INT MENU_ButtonUp( MTRACKER* pmt,
         if( IS_SYSTEM_MENU(ptmenu) )
             item = ptmenu->items;
         else
-            item = MENU_FindItemByCoords( hPtMenu, pmt->pt, &id );
+        {
+            POPUPMENU menu;
+            MENU_FindItemByCoords( hPtMenu, pmt->pt, &id );
+            MENU_GetMenu(hPtMenu, &menu);
+            item = (id == ITEM_NOT_FOUND) ? NULL : &menu.items[id];
+        }
 
 	if( item && (MENU_GetLocalMenu(hPtMenu)->FocusedItem == id ))
 	{
@@ -3898,6 +3910,7 @@ BOOL WINAPI InsertMenuW( HMENU hMenu, UI
                          UINT_PTR id, LPCWSTR str )
 {
     MENUITEM *item;
+    UINT i;
 
     if (IS_STRING_ITEM(flags) && str)
         TRACE("hMenu %p, pos %d, flags %08x, id %04x, str %s\n",
@@ -3905,7 +3918,14 @@ BOOL WINAPI InsertMenuW( HMENU hMenu, UI
     else TRACE("hMenu %p, pos %d, flags %08x, id %04x, str %p (not a string)\n",
                hMenu, pos, flags, id, str );
 
-    if (!(item = MENU_InsertItem( hMenu, pos, flags ))) return FALSE;
+    if ((i = MENU_InsertItem( hMenu, pos, flags )) == ITEM_NOT_FOUND)
+        return FALSE;
+    else
+    {
+        POPUPMENU menu;
+        MENU_GetMenu(hMenu, &menu);
+        item = &menu.items[i];
+    }
 
     if (!(MENU_SetItemData( item, flags, id, str )))
     {
@@ -4805,11 +4825,16 @@ inline static void set_menu_item_text( M
  *		SetMenuItemInfo_common
  */
 
-static BOOL SetMenuItemInfo_common(MENUITEM * menu,
+static BOOL SetMenuItemInfo_common(HMENU hmenu, UINT pos,
 				       const MENUITEMINFOW *lpmii,
 				       BOOL unicode)
 {
-    if (!menu) return FALSE;
+    POPUPMENU pm;
+    MENUITEM *menu;
+    if (pos == ITEM_NOT_FOUND) return FALSE;
+    if (MENU_GetMenu(hmenu, &pm)) return FALSE;
+    if (!pm.items) return FALSE;
+    menu = &pm.items[pos];
 
     debug_print_menuitem("SetmenuItemInfo_common from: ", menu, "");
 
@@ -4902,7 +4927,6 @@ BOOL WINAPI SetMenuItemInfoA(HMENU hmenu
                                  const MENUITEMINFOA *lpmii)
 {
     MENUITEMINFOA mii;
-    POPUPMENU menu;
     UINT pos;
     if( lpmii->cbSize != sizeof( mii) &&
             lpmii->cbSize != sizeof( mii) - sizeof ( mii.hbmpItem)) {
@@ -4915,9 +4939,7 @@ BOOL WINAPI SetMenuItemInfoA(HMENU hmenu
         mii.hbmpItem = NULL;
     }
     pos = MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0);
-    MENU_GetMenu(hmenu, &menu);
-    return SetMenuItemInfo_common(pos == ITEM_NOT_FOUND ? NULL
-                                  : &menu.items[pos],
+    return SetMenuItemInfo_common(hmenu, pos,
                                   (const MENUITEMINFOW *)&mii, FALSE);
 }
 
@@ -4928,7 +4950,6 @@ BOOL WINAPI SetMenuItemInfoW(HMENU hmenu
                                  const MENUITEMINFOW *lpmii)
 {
     MENUITEMINFOW mii;
-    POPUPMENU menu;
     UINT pos;
     if( lpmii->cbSize != sizeof( mii) &&
             lpmii->cbSize != sizeof( mii) - sizeof ( mii.hbmpItem)) {
@@ -4941,9 +4962,7 @@ BOOL WINAPI SetMenuItemInfoW(HMENU hmenu
         mii.hbmpItem = NULL;
     }
     pos = MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0);
-    MENU_GetMenu(hmenu, &menu);
-    return SetMenuItemInfo_common(pos == ITEM_NOT_FOUND ? NULL
-                                  : &menu.items[pos], &mii, TRUE);
+    return SetMenuItemInfo_common(hmenu, pos, &mii, TRUE);
 }
 
 /**********************************************************************
@@ -5045,8 +5064,13 @@ UINT WINAPI GetMenuDefaultItem(HMENU hme
 BOOL WINAPI InsertMenuItemA(HMENU hMenu, UINT uItem, BOOL bypos,
                                 const MENUITEMINFOA *lpmii)
 {
-    MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
+    MENUITEM *item;
+    UINT pos;
+    POPUPMENU menu;
     MENUITEMINFOA mii;
+    pos = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
+    MENU_GetMenu(hMenu, &menu);
+    item = &menu.items[pos];
     if( lpmii->cbSize != sizeof( mii) &&
             lpmii->cbSize != sizeof( mii) - sizeof ( mii.hbmpItem)) {
         SetLastError( ERROR_INVALID_PARAMETER);
@@ -5057,7 +5081,8 @@ BOOL WINAPI InsertMenuItemA(HMENU hMenu,
         mii.cbSize = sizeof( mii);
         mii.hbmpItem = NULL;
     }
-    return SetMenuItemInfo_common(item, (const MENUITEMINFOW *)&mii, FALSE);
+    return SetMenuItemInfo_common(hMenu, pos,
+                                  (const MENUITEMINFOW *)&mii, FALSE);
 }
 
 
@@ -5067,8 +5092,13 @@ BOOL WINAPI InsertMenuItemA(HMENU hMenu,
 BOOL WINAPI InsertMenuItemW(HMENU hMenu, UINT uItem, BOOL bypos,
                                 const MENUITEMINFOW *lpmii)
 {
-    MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
+    MENUITEM *item;
+    UINT pos;
+    POPUPMENU menu;
     MENUITEMINFOW mii;
+    pos = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
+    MENU_GetMenu(hMenu, &menu);
+    item = &menu.items[pos];
     if( lpmii->cbSize != sizeof( mii) &&
             lpmii->cbSize != sizeof( mii) - sizeof ( mii.hbmpItem)) {
         SetLastError( ERROR_INVALID_PARAMETER);
@@ -5079,7 +5109,7 @@ BOOL WINAPI InsertMenuItemW(HMENU hMenu,
         mii.cbSize = sizeof( mii);
         mii.hbmpItem = NULL;
     }
-    return SetMenuItemInfo_common(item, &mii, TRUE);
+    return SetMenuItemInfo_common(hMenu, pos, &mii, TRUE);
 }
 
 /**********************************************************************
@@ -5301,7 +5331,8 @@ INT WINAPI MenuItemFromPoint(HWND hWnd, 
 
     /*FIXME: Do we have to handle hWnd here? */
     if (MENU_GetMenu(hMenu, menu)) return -1;
-    if (!MENU_FindItemByCoords(hMenu, ptScreen, &pos)) return -1;
+    MENU_FindItemByCoords(hMenu, ptScreen, &pos);
+    if (pos == ITEM_NOT_FOUND) return -1;
     return pos;
 }
 

