[PATCH] user32: GetMenuItemRect works without draw if the menu isn't a popup

Andy Clayton q3aiml at gmail.com
Thu Jul 28 21:43:06 CDT 2011


Fixes http://bugs.winehq.org/show_bug.cgi?id=27886
---
 dlls/user32/menu.c       |   11 ++++--
 dlls/user32/tests/menu.c |   70 ++++++++++++++++++++++++++++++----------------
 2 files changed, 53 insertions(+), 28 deletions(-)

diff --git a/dlls/user32/menu.c b/dlls/user32/menu.c
index 3ec682f..1b17474 100644
--- a/dlls/user32/menu.c
+++ b/dlls/user32/menu.c
@@ -4982,12 +4982,15 @@ BOOL WINAPI GetMenuItemRect (HWND hwnd, HMENU hMenu, UINT uItem,
      item = MENU_FindItem (&hMenu, &uItem, MF_BYPOSITION);
      referenceHwnd = hwnd;
 
+     itemMenu = MENU_GetMenu(hMenu);
+     if (itemMenu == NULL)
+         return FALSE;
+
+     if ((itemMenu->Height == 0 || itemMenu->Width == 0) && itemMenu->wFlags ^ MF_POPUP)
+        MENU_PopupMenuCalcSize(itemMenu);
+
      if(!hwnd)
      {
-	 itemMenu = MENU_GetMenu(hMenu);
-	 if (itemMenu == NULL)
-	     return FALSE;
-
 	 if(itemMenu->hWnd == 0)
 	     return FALSE;
 	 referenceHwnd = itemMenu->hWnd;
diff --git a/dlls/user32/tests/menu.c b/dlls/user32/tests/menu.c
index 823e19e..90bb144 100644
--- a/dlls/user32/tests/menu.c
+++ b/dlls/user32/tests/menu.c
@@ -512,7 +512,8 @@ static void test_menu_ownerdraw(void)
 /* helper for test_menu_bmp_and_string() */
 static void test_mbs_help( int ispop, int hassub, int mnuopt,
         HWND hwnd, int arrowwidth, int count, HBITMAP hbmp,
-        SIZE bmpsize, LPCSTR text, SIZE size, SIZE sc_size)
+        SIZE bmpsize, LPCSTR text, SIZE size, SIZE sc_size,
+        int drawmenu)
 {
     BOOL ret;
     HMENU hmenu, submenu;
@@ -522,6 +523,7 @@ static void test_mbs_help( int ispop, int hassub, int mnuopt,
     CHAR text_copy[16];
     int hastab,  expect;
     int failed = 0;
+    int hassize = 0;
 
     MOD_GotDrawItemMsg = FALSE;
     mii.fMask = MIIM_FTYPE | MIIM_DATA | MIIM_STATE;
@@ -578,16 +580,29 @@ static void test_mbs_help( int ispop, int hassub, int mnuopt,
         TextOut( hdc, 10, 50, buf, strlen( buf));
         ReleaseDC( hwnd, hdc);
     }
-    if(ispop)
-        TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
-    else {
-        ret = SetMenu( hwnd, hmenu);
-        ok(ret, "SetMenu failed with error %d\n", GetLastError());
-        DrawMenuBar( hwnd);
+    if(drawmenu) {
+        if(ispop)
+            TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
+        else {
+	    ret = SetMenu( hwnd, hmenu);
+	    ok(ret, "SetMenu failed with error %d\n", GetLastError());
+	    DrawMenuBar( hwnd);
+	}
     }
     ret = GetMenuItemRect( hwnd, hmenu, 0, &rc);
     ok(ret, "GetMenuItemRect failed with error %d\n", GetLastError());
 
+    if(text || hbmp) {
+        hassize = drawmenu || !ispop;
+        ok(rc.right - rc.left > 0 || !hassize,
+                "menu width wrong, got %d expected %s0\n", rc.right - rc.left, hassize ? ">" : "");
+        failed = failed || !(rc.right - rc.left > 0 || !hassize);
+        ok(rc.bottom - rc.top > 0 || !hassize,
+            "menu height wrong, got %d expected %s0\n", rc.bottom - rc.top, hassize ? ">" : "");
+        failed = failed || !(rc.bottom - rc.top > 0 || !hassize);
+    }
+
+
     if (0)  /* comment out menu size checks, behavior is different in almost every Windows version */
             /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
             /* with a variety of dpis and desktop font sizes */
@@ -649,9 +664,9 @@ static void test_mbs_help( int ispop, int hassub, int mnuopt,
     }
     /* if there was a failure, report details */
     if( failed) {
-        trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
+        trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d drawmenu %d\n",
                 count, (ispop? "POPUP": "MENUBAR"),text ? text: "(nil)", hbmp, bmpsize.cx, bmpsize.cy,
-                size.cx, size.cy, sc_size.cx, mnuopt, hastab);
+                size.cx, size.cy, sc_size.cx, mnuopt, hastab, drawmenu);
         trace("    check %d,%d arrow %d avechar %d\n",
                 GetSystemMetrics(SM_CXMENUCHECK ),
                 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
@@ -659,6 +674,9 @@ static void test_mbs_help( int ispop, int hassub, int mnuopt,
             trace( "    rc %d,%d-%d,%d bmp.rc %d,%d-%d,%d\n",
                 rc.left, rc.top, rc.top, rc.bottom, MOD_rc[0].left,
                 MOD_rc[0].top,MOD_rc[0].right, MOD_rc[0].bottom);
+        else
+            trace("    rc %d,%d-%d,%d\n",
+                rc.left, rc.top, rc.top, rc.bottom);
     }
     /* clean up */
     ret = DestroyMenu(submenu);
@@ -678,7 +696,7 @@ static void test_menu_bmp_and_string(void)
     HMENU hsysmenu;
     MENUINFO mi= {sizeof(MENUINFO)};
     MENUITEMINFOA mii= {sizeof(MENUITEMINFOA)};
-    int count, szidx, txtidx, bmpidx, hassub, mnuopt, ispop;
+    int count, szidx, txtidx, bmpidx, hassub, mnuopt, ispop, drawmenu;
     BOOL got;
 
     if( !pGetMenuInfo)
@@ -731,20 +749,24 @@ static void test_menu_bmp_and_string(void)
                 for( hassub = 0; hassub < 2 ; hassub++) { /* add submenu item */
                     for( mnuopt = 0; mnuopt < 3 ; mnuopt++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
                         for( bmpidx = 0; bmpidx <sizeof(bitmaps)/sizeof(HBITMAP); bmpidx++) {
-                            /* no need to test NULL bitmaps of several sizes */
-                            if( !bitmaps[bmpidx] && szidx > 0) continue;
-                            /* the HBMMENU_POPUP not to test for menu bars */
-                            if( !ispop &&
-                                bitmaps[bmpidx] >= HBMMENU_POPUP_CLOSE &&
-                                bitmaps[bmpidx] <= HBMMENU_POPUP_MINIMIZE) continue;
-                            if( !ispop && hassub) continue;
-                            test_mbs_help( ispop, hassub, mnuopt,
-                                    hwnd, arrowwidth, ++count,
-                                    bitmaps[bmpidx],
-                                    bmsizes[szidx],
-                                    MOD_txtsizes[txtidx].text,
-                                    MOD_txtsizes[txtidx].size,
-                                    MOD_txtsizes[txtidx].sc_size);
+                            /* GetMenuItemRect works without draw if not popup */
+                            for( drawmenu = 0; drawmenu < 2 ; drawmenu++) {
+                                /* no need to test NULL bitmaps of several sizes */
+                                if( !bitmaps[bmpidx] && szidx > 0) continue;
+                                /* the HBMMENU_POPUP not to test for menu bars */
+                                if( !ispop &&
+                                    bitmaps[bmpidx] >= HBMMENU_POPUP_CLOSE &&
+                                    bitmaps[bmpidx] <= HBMMENU_POPUP_MINIMIZE) continue;
+                                if( !ispop && hassub) continue;
+                                test_mbs_help( ispop, hassub, mnuopt,
+                                        hwnd, arrowwidth, ++count,
+                                        bitmaps[bmpidx],
+                                        bmsizes[szidx],
+                                        MOD_txtsizes[txtidx].text,
+                                        MOD_txtsizes[txtidx].size,
+                                        MOD_txtsizes[txtidx].sc_size,
+                                        drawmenu);
+                            }
                         }
                     }
                 }
-- 
1.7.4.1




More information about the wine-patches mailing list