Patch for bug 1848 - TrackPopupMenu returns wrong result, when menu is canceled

Andreas Rosenberg sonix2003 at ctf-z.de
Thu Dec 11 12:20:18 CST 2003


I fix for the wrong results of TrackPopupMenu. I compared the results with
Windows and Wine and it seems ok, except for the behavior of "GetLastError",
when passing wrong parameters. I assume the "MENU_GetMenu" case could be ok,
but somebody should look at the "WIN_GetFullHandle" case too.


diff -urN wine-20031118/controls/menu.c wine-20031211/controls/menu.c
--- wine-20031118/controls/menu.c	2003-11-18 20:42:31.000000000 +0100
+++ wine-20031211/controls/menu.c	2003-12-11 17:40:29.000000000 +0100
@@ -2652,6 +2652,10 @@
     mt.trackFlags = 0;
     mt.hCurrentMenu = hmenu;
     mt.hTopMenu = hmenu;
+    /* What happens if an invalid window handle is being passed? I tried to find out what's
+    going on in such a case, but I know to little about communication with the wine server.
+    Somebody who might know about this, please add a test and return FALSE here with a
+    SetLastError(ERROR_INVALID_WINDOW_HANDLE); - added be A.Rosenberg 2003.12.11*/
     mt.hOwnerWnd = WIN_GetFullHandle( hwnd );
     mt.pt.x = x;
     mt.pt.y = y;
@@ -2661,7 +2665,11 @@
           (lprect) ? lprect->right : 0,  (lprect) ? lprect->bottom : 0);
 
     fEndMenu = FALSE;
-    if (!(menu = MENU_GetMenu( hmenu ))) return FALSE;
+    if (!(menu = MENU_GetMenu( hmenu )))
+    	{
+	SetLastError(ERROR_INVALID_MENU_HANDLE);  /* - added by A.Rosenberg 2003.12.11 */
+    	return FALSE;
+	}
 
     if (wFlags & TPM_BUTTONDOWN)
     {
@@ -2926,7 +2934,8 @@
     }
 
     /* The return value is only used by TrackPopupMenu */
-    return ((executedMenuId != -1) ? executedMenuId : 0);
+    return (executedMenuId);   /* changed by A.Rosenberg 2003.12.11 */
+                               /* required to fix return code of TrackPopupMenu */
 }
 
 /***********************************************************************
@@ -3071,11 +3080,19 @@
         SendMessageW( hWnd, WM_INITMENUPOPUP, (WPARAM)hMenu, 0);
 
     if (MENU_ShowPopup( hWnd, hMenu, 0, x, y, 0, 0 ))
+        /* -1 is returned when the menu was canceled */
 	ret = MENU_TrackMenu( hMenu, wFlags | TPM_POPUPMENU, 0, 0, hWnd, lpRect );
     MENU_ExitTracking(hWnd);
 
-    if( (!(wFlags & TPM_RETURNCMD)) && (ret != FALSE) )
-	ret = 1;
+    /* changed by A.Rosenberg 2003.12.11 - fixes return code when menu is being canceled*/
+    if (ret < 0)
+        if (wFlags & TPM_RETURNCMD)
+	       ret = 0;
+	   else
+	       ret = 1;
+    else
+        if ((!(wFlags & TPM_RETURNCMD)) && (ret > 0))
+            ret = 1;
 
     return ret;
 }




More information about the wine-patches mailing list