Menu patch (2/2)

François Gouget fgouget at codeweavers.com
Wed Nov 14 15:03:45 CST 2001


   This patch is independent from the previous one and focuses on fixing
observed bugs.

Changelog:

   François Gouget <fgouget at codeweavers.com>

 * controls/menu.c

   MENU_InsertItem must return item's position so that InsertMenuW can
remove it if necessary
   SetMenuItemInfo_common must change all the TYPE_MASK bits otherwise
MF_HELP is ignored
   Added support for MIIM_BITMAP in SetMenuItemInfo_common

-- 
François Gouget
fgouget at codeweavers.com
-------------- next part --------------
Index: controls/menu.c
===================================================================
RCS file: /home/wine/wine/controls/menu.c,v
retrieving revision 1.133
diff -u -r1.133 menu.c
--- controls/menu.c	2001/11/06 20:57:13	1.133
+++ controls/menu.c	2001/11/14 18:42:02
@@ -1794,7 +1795,7 @@
  *
  * Insert a new item into a menu.
  */
-static MENUITEM *MENU_InsertItem( HMENU hMenu, UINT pos, UINT flags )
+static MENUITEM *MENU_InsertItem( HMENU hMenu, UINT* pos, UINT flags )
 {
     MENUITEM *newItems;
     POPUPMENU *menu;
@@ -1805,11 +1806,11 @@
     /* Find where to insert new item */
 
     if (flags & MF_BYPOSITION) {
-        if (pos > menu->nItems) 
-            pos = menu->nItems;
+        if (*pos > menu->nItems) 
+            *pos = menu->nItems;
     } else {
-        if (!MENU_FindItem( &hMenu, &pos, flags )) 
-            pos = menu->nItems;
+        if (!MENU_FindItem( &hMenu, pos, flags )) 
+            *pos = menu->nItems;
         else {
             if (!(menu = MENU_GetMenu( hMenu )))
                 return NULL;
@@ -1826,17 +1827,17 @@
     }
     if (menu->nItems > 0)
     {
-	  /* Copy the old array into the new one */
-	if (pos > 0) memcpy( newItems, menu->items, pos * sizeof(MENUITEM) );
-	if (pos < menu->nItems) memcpy( &newItems[pos+1], &menu->items[pos],
-					(menu->nItems-pos)*sizeof(MENUITEM) );
+        /* Copy the old array into the new one */
+        if (*pos > 0) memcpy( newItems, menu->items, *pos * sizeof(MENUITEM) );
+        if (*pos < menu->nItems) memcpy( &newItems[*pos+1], &menu->items[*pos],
+                                        (menu->nItems-*pos)*sizeof(MENUITEM) );
         HeapFree( GetProcessHeap(), 0, menu->items );
     }
     menu->items = newItems;
     menu->nItems++;
-    memset( &newItems[pos], 0, sizeof(*newItems) );
+    memset( &newItems[*pos], 0, sizeof(*newItems) );
     menu->Height = 0; /* force size recalculate */
-    return &newItems[pos];
+    return &newItems[*pos];
 }
 
 
@@ -3470,7 +3471,7 @@
 		       "id %04x, str %08lx (not a string)\n",
                        hMenu, pos, flags, id, (DWORD)str );
 
-    if (!(item = MENU_InsertItem( hMenu, pos, flags ))) return FALSE;
+    if (!(item = MENU_InsertItem( hMenu, &pos, flags ))) return FALSE;
 
     if (!(MENU_SetItemData( item, flags, id, str )))
     {
@@ -4312,9 +4310,9 @@
 	    menu->text = NULL;
 	}
 
-	/* make only MENU_ITEM_TYPE bits in menu->fType equal lpmii->fType */ 
-	menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
-	menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
+	/* only change the TYPE_MASK bits in menu->fType */
+	menu->fType &= ~(menu->fType & TYPE_MASK);
+	menu->fType |= (lpmii->fType & TYPE_MASK);
 
 	menu->text = lpmii->dwTypeData;
 
@@ -4342,6 +4328,10 @@
 	}
     }
 
+    if (lpmii->fMask & MIIM_BITMAP ) {
+        menu->hbmpItem = lpmii->hbmpItem;
+    }
+
     if (lpmii->fMask & MIIM_STATE)
     {
 	/* fixme: MFS_DEFAULT do we have to reset the other menu items? */
@@ -4534,7 +4524,7 @@
 BOOL WINAPI InsertMenuItemA(HMENU hMenu, UINT uItem, BOOL bypos,
                                 const MENUITEMINFOA *lpmii)
 {
-    MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
+    MENUITEM *item = MENU_InsertItem(hMenu, &uItem, bypos ? MF_BYPOSITION : 0 );
     return SetMenuItemInfo_common(item, (const MENUITEMINFOW *)lpmii, FALSE);
 }
 
@@ -4545,7 +4535,7 @@
 BOOL WINAPI InsertMenuItemW(HMENU hMenu, UINT uItem, BOOL bypos,
                                 const MENUITEMINFOW *lpmii)
 {
-    MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
+    MENUITEM *item = MENU_InsertItem(hMenu, &uItem, bypos ? MF_BYPOSITION : 0 );
     return SetMenuItemInfo_common(item, lpmii, TRUE);
 }
 


More information about the wine-patches mailing list