Menu patch (1/2)

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


   This patch contains cleanups more than true fixes. AFAICT these are
correct and the tests seem to confirm this. But the more people check
the better.


Changelog:

   François Gouget <fgouget at codeweavers.com>

 * controls/menu.c

   dwTypeData is unused, remove it
   Remove redundant IS_BITMAP_ITEM check in MENU_DrawMenuItem
   Cleanup MF_POPUP handling in MENU_SetItemData
   Remove MF_POPUP code from InsertMenuW: setting MF_POPUP on the
submenu is already done in MENU_SetItemData
   Cleanup MIIM_TYPE|MIIM_STRING handling in GetMenuItemInfo_common
   Remove redundant handling of MIIM_FTYPE 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
@@ -53,7 +53,6 @@
     HBITMAP hUnCheckBit;	/* Bitmap when unchecked.  */
     LPWSTR text;			/* Item text or bitmap handle.  */
     DWORD dwItemData;		/* Application defined.  */
-    DWORD dwTypeData;		/* depends on fMask */
     HBITMAP hbmpItem;		/* bitmap in win98 style menus */
     /* ----------- Wine stuff ----------- */
     RECT      rect;		/* Item area (relative to menu window) */
@@ -147,7 +146,7 @@
 
 static HBITMAP hStdMnArrow = 0;
 
-/* Minimze/restore/close buttons to be inserted in menubar */
+/* Minimize/restore/close buttons to be inserted in menubar */
 static HBITMAP hBmpMinimize = 0;
 static HBITMAP hBmpMinimizeD = 0;
 static HBITMAP hBmpMaximize = 0;
@@ -1293,7 +1292,7 @@
             left=rect.left;
             if (TWEAK_WineLook == WIN95_LOOK) {
                 rop=((lpitem->fState & MF_HILITE) && !IS_MAGIC_ITEM(lpitem->text)) ? NOTSRCCOPY : SRCCOPY;
-                if ((lpitem->fState & MF_HILITE) && IS_BITMAP_ITEM(lpitem->fType))
+                if (lpitem->fState & MF_HILITE)
                     SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
             } else {
                 left++;
@@ -1745,43 +1744,45 @@
         item->text = (LPWSTR)(HBITMAP)LOWORD(str);
     else item->text = NULL;
 
-    if (flags & MF_OWNERDRAW) 
+    if (flags & MF_OWNERDRAW)
         item->dwItemData = (DWORD)str;
     else
         item->dwItemData = 0;
 
-    if ((item->fType & MF_POPUP) && (flags & MF_POPUP) && (item->hSubMenu != id) )
-	DestroyMenu( item->hSubMenu );   /* ModifyMenu() spec */
-
     if (flags & MF_POPUP)
     {
-	POPUPMENU *menu = MENU_GetMenu((UINT16)id);
-        if (menu) menu->wFlags |= MF_POPUP;
-	else
+        POPUPMENU* menu;
+
+        if ((item->fType & MF_POPUP) && (item->hSubMenu != id) )
+        {
+            /* Destroy the old popup menu per ModifyMenu() spec */
+            DestroyMenu( item->hSubMenu );
+        }
+        menu = MENU_GetMenu((HMENU)id);
+        if (!menu)
         {
             item->wID = 0;
             item->hSubMenu = 0;
             item->fType = 0;
             item->fState = 0;
-	    return FALSE;
+            return FALSE;
         }
-    } 
+        menu->wFlags |= MF_POPUP;
+        item->hSubMenu = id;
+    }
+    else if (item->fType & MF_POPUP)
+    {
+        /* ModifyMenu() preserves popup menus even if MF_POPUP is not set*/
+        flags |= MF_POPUP;
+    }
 
     item->wID = id;
-    if (flags & MF_POPUP)
-      item->hSubMenu = id;
-
-    if ((item->fType & MF_POPUP) && !(flags & MF_POPUP) )
-      flags |= MF_POPUP; /* keep popup */
-
     item->fType = flags & TYPE_MASK;
     item->fState = (flags & STATE_MASK) &
         ~(MF_HILITE | MF_MOUSESELECT | MF_BYPOSITION);
 
-
     /* Don't call SetRectEmpty here! */
 
-
     if (prevText) HeapFree( GetProcessHeap(), 0, prevText );
 
     debug_print_menuitem("MENU_SetItemData to  : ", item, "");
@@ -3478,9 +3479,6 @@
         return FALSE;
     }
 
-    if (flags & MF_POPUP)  /* Set the MF_POPUP flag on the popup-menu */
-	(MENU_GetMenu((HMENU16)id))->wFlags |= MF_POPUP;
-
     item->hCheckBit = item->hUnCheckBit = 0;
     return TRUE;
 }
@@ -4201,27 +4199,27 @@
          (MENU_ITEM_TYPE(menu->fType) == MF_STRING) && menu->text)
     {
         int len;
+
         if (unicode)
-        {
             len = strlenW(menu->text);
-            if(lpmii->dwTypeData && lpmii->cch)
-                lstrcpynW(lpmii->dwTypeData, menu->text, lpmii->cch);
-        }
         else
-        {
             len = WideCharToMultiByte( CP_ACP, 0, menu->text, -1, NULL, 0, NULL, NULL );
-            if(lpmii->dwTypeData && lpmii->cch)
-                if (!WideCharToMultiByte( CP_ACP, 0, menu->text, -1,
-                                          (LPSTR)lpmii->dwTypeData, lpmii->cch, NULL, NULL ))
-                    ((LPSTR)lpmii->dwTypeData)[lpmii->cch-1] = 0;
-        }
-        /* if we've copied a substring we return its length */
-        if(lpmii->dwTypeData && lpmii->cch)
+
+        if (lpmii->dwTypeData && lpmii->cch)
         {
+            if (unicode)
+                lstrcpynW(lpmii->dwTypeData, menu->text, lpmii->cch);
+            else if (!WideCharToMultiByte( CP_ACP, 0, menu->text, -1,
+                                           (LPSTR)lpmii->dwTypeData, lpmii->cch, NULL, NULL ))
+                ((LPSTR)lpmii->dwTypeData)[lpmii->cch-1] = 0;
+            /* if we've copied a substring we return its length */
             if (lpmii->cch <= len) lpmii->cch--;
         }
-        else /* return length of string */
+        else
+        {
+            /* return length of string */
             lpmii->cch = len;
+        }
     }
 
     if (lpmii->fMask & MIIM_FTYPE)
@@ -4322,18 +4320,6 @@
            set_menu_item_text( menu, lpmii->dwTypeData, unicode );
     }
 
-    if (lpmii->fMask & MIIM_FTYPE ) {
-	/* free the string when the type is changing */
-	if ( (!IS_STRING_ITEM(lpmii->fType)) && IS_STRING_ITEM(menu->fType) && menu->text) {
-	    HeapFree(GetProcessHeap(), 0, menu->text);
-	    menu->text = NULL;
-	}
-	menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
-	menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
-        if ( IS_STRING_ITEM(menu->fType) && !menu->text )
-            menu->fType |= MF_SEPARATOR;
-    }
-
     if (lpmii->fMask & MIIM_STRING ) {
 	/* free the string when used */
 	if ( IS_STRING_ITEM(menu->fType) && menu->text) {
@@ -4354,7 +4344,7 @@
     if (lpmii->fMask & MIIM_SUBMENU) {
 	menu->hSubMenu = lpmii->hSubMenu;
 	if (menu->hSubMenu) {
-	    POPUPMENU *subMenu = MENU_GetMenu((UINT16)menu->hSubMenu);
+	    POPUPMENU *subMenu = MENU_GetMenu(menu->hSubMenu);
 	    if (subMenu) {
 		subMenu->wFlags |= MF_POPUP;
 		menu->fType |= MF_POPUP;


More information about the wine-patches mailing list