user32: when needed, recalculate menu size of menu bar before tracking starts. (take 2)

Rein Klazes wijn at online.nl
Tue Apr 28 02:13:04 CDT 2009


Fixes bug 10845

Changes from previous patch: menu position calculations moved to
nonclient.c.
---
 dlls/user32/controls.h  |    1 +
 dlls/user32/menu.c      |   16 +++++++++++++++-
 dlls/user32/nonclient.c |   20 ++++++++++++++++++++
 3 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/dlls/user32/controls.h b/dlls/user32/controls.h
index f51a3d9..1815ad4 100644
--- a/dlls/user32/controls.h
+++ b/dlls/user32/controls.h
@@ -101,6 +101,7 @@ extern LRESULT NC_HandleSysCommand( HWND hwnd, WPARAM wParam, LPARAM lParam ) DE
 extern LRESULT NC_HandleSetCursor( HWND hwnd, WPARAM wParam, LPARAM lParam ) DECLSPEC_HIDDEN;
 extern BOOL NC_DrawSysButton( HWND hwnd, HDC hdc, BOOL down ) DECLSPEC_HIDDEN;
 extern void NC_GetSysPopupPos( HWND hwnd, RECT* rect ) DECLSPEC_HIDDEN;
+extern void NC_CalcMenuRect( HWND hwnd, RECT* prc) DECLSPEC_HIDDEN;
 
 /* scrollbar */
 extern void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar, BOOL arrows, BOOL interior ) DECLSPEC_HIDDEN;
diff --git a/dlls/user32/menu.c b/dlls/user32/menu.c
index 69936fa..41f199b 100644
--- a/dlls/user32/menu.c
+++ b/dlls/user32/menu.c
@@ -3069,6 +3069,19 @@ static BOOL MENU_TrackMenu( HMENU hmenu, UINT wFlags, INT x, INT y,
         return FALSE;
     }
 
+    /* recalc the menubar size if needed */
+    /* eg if the application modified the menu in the WM_INITMENU message */
+    if (!( wFlags & TPM_POPUPMENU) && !menu->Height)
+    {
+        RECT rc;
+        HDC hdc = GetDCEx( hwnd, 0, DCX_CACHE | DCX_WINDOW );
+
+        SelectObject( hdc, get_menu_font(FALSE));
+        NC_CalcMenuRect( hwnd, &rc); 
+        MENU_MenuBarCalcSize( hdc, &rc, menu, hwnd );
+        ReleaseDC( hwnd, hdc );
+    }
+
     if (wFlags & TPM_BUTTONDOWN)
     {
 	/* Get the result in order to start the tracking or not */
@@ -3361,7 +3374,8 @@ static BOOL MENU_InitTracking(HWND hWnd, HMENU hMenu, BOOL bPopup, UINT wFlags)
     {
        SendMessageW( hWnd, WM_INITMENU, (WPARAM)hMenu, 0 );
        /* If an app changed/recreated menu bar entries in WM_INITMENU
-        * menu sizes will be recalculated once the menu created/shown.
+        * menu sizes must be recalculated.
+        * Either in MENU_TrackMenu or when the menu is created/shown.
         */
     }
     
diff --git a/dlls/user32/nonclient.c b/dlls/user32/nonclient.c
index 708ed80..ef978ba 100644
--- a/dlls/user32/nonclient.c
+++ b/dlls/user32/nonclient.c
@@ -1685,3 +1685,23 @@ BOOL WINAPI GetTitleBarInfo(HWND hwnd, PTITLEBARINFO tbi) {
         tbi->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
     return TRUE;
 }
+
+/***********************************************************************
+ *           NC_CalcMenuRect
+ *
+ * Calculate rectangle for menu bar (called from menu track logic)
+ */
+void NC_CalcMenuRect( HWND hwnd, RECT *prc) 
+{
+    LONG style = GetWindowLongW( hwnd, GWL_STYLE );
+    LONG exstyle = GetWindowLongW( hwnd, GWL_EXSTYLE );
+    RECT tmprc = { 0, 0, 0, 0 };
+
+    GetWindowRect( hwnd, prc);
+    NC_AdjustRectOuter( &tmprc, style, FALSE, exstyle);
+    prc->right = prc->right - prc->left - tmprc.right;
+    prc->left = -tmprc.left;
+    prc->top = -tmprc.top;
+    prc->bottom = prc->top + GetSystemMetrics(SM_CYMENU);
+    TRACE("Calculated MenuBar rect (%s)\n", wine_dbgstr_rect(prc));
+}
-- 
1.6.2.1




More information about the wine-patches mailing list