Advertisement
x6herbius

Reason 5 menu bar fix for Wine 8.4

Mar 23rd, 2023
1,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.83 KB | None | 0 0
  1. diff --git a/dlls/win32u/menu.c b/dlls/win32u/menu.c
  2. index a6b7ec38003..99c60076a12 100644
  3. --- a/dlls/win32u/menu.c
  4. +++ b/dlls/win32u/menu.c
  5. @@ -4069,6 +4069,83 @@ static UINT find_item_by_key( HWND owner, HMENU hmenu, WCHAR key, BOOL force_men
  6.      return -1;
  7.  }
  8.  
  9. +/* Recalculate the menu bar size if needed, eg. if the application
  10. + * modified the menu in the WM_INITMENU message.
  11. + * This tweak is taken (and tidied) from
  12. + * https://www.winehq.org/pipermail/wine-patches/2009-April/071602.html,
  13. + * complete with its original comments, and is simply ported to
  14. + * Wine 8.4 by me (@NoodleCollie). I don't know enough about the
  15. + * codebase to know if this is the best approach (the original
  16. + * author seemed troubled by it), but apparently it was used to
  17. + * generate an ancient "1.6-rc2-Reason5Menu" release, so it must be
  18. + * at least half-decent. */
  19. +static void recalc_menu_bar_if_needed( HWND hwnd, struct menu *menu, UINT flags )
  20. +{
  21. +    RECT rc;
  22. +    LONG style = 0;
  23. +    LONG exstyle = 0;
  24. +    HDC hdc = 0;
  25. +    INT width = 0;
  26. +    INT height = 0;
  27. +
  28. +    if ( (flags & TPM_POPUPMENU) || !menu || menu->Height != 0 )
  29. +    {
  30. +        /* Recalculating size is not needed. */
  31. +        return;
  32. +    }
  33. +
  34. +    style = NtUserGetWindowLongW( hwnd, GWL_STYLE );
  35. +    exstyle = NtUserGetWindowLongW( hwnd, GWL_EXSTYLE );
  36. +    hdc = NtUserGetDCEx( hwnd, 0, DCX_CACHE | DCX_WINDOW );
  37. +
  38. +    NtGdiSelectFont( hdc, get_menu_font(FALSE));
  39. +
  40. +    /* Original author:
  41. +     * FIXME: calculations taken from nonclient.c and uitools.c
  42. +     * unfortunately too intertwined with non-client redrawing
  43. +     * I do not like to introduce another unneeded redraw here
  44. +     * this code should probaby be put there */
  45. +
  46. +    NtUserGetWindowRect( hwnd, &rc);
  47. +    SetRect( &rc, 0, 0, rc.right - rc.left, 0);
  48. +
  49. +    rc.top = NtUserGetSystemMetrics(SM_CYCAPTION);
  50. +
  51. +    if ( style & WS_THICKFRAME )
  52. +    {
  53. +        width += NtUserGetSystemMetrics(SM_CXFRAME) - NtUserGetSystemMetrics(SM_CXDLGFRAME);
  54. +        height += NtUserGetSystemMetrics(SM_CYFRAME) - NtUserGetSystemMetrics(SM_CYDLGFRAME);
  55. +    }
  56. +
  57. +    if ( (style & (WS_BORDER | WS_DLGFRAME)) || (exstyle & WS_EX_DLGMODALFRAME) )
  58. +    {
  59. +        width += NtUserGetSystemMetrics(SM_CXDLGFRAME) - NtUserGetSystemMetrics(SM_CXEDGE);
  60. +        height += NtUserGetSystemMetrics(SM_CYDLGFRAME) - NtUserGetSystemMetrics(SM_CYEDGE);
  61. +    }
  62. +
  63. +    /* HAS_THICKFRAME */
  64. +    if ( (style & WS_THICKFRAME) && !((style & (WS_DLGFRAME | WS_BORDER)) == WS_DLGFRAME) )
  65. +    {
  66. +        width++;
  67. +        height++;
  68. +    }
  69. +
  70. +    /* HAS_BIGFRAME */
  71. +    if ( (style & (WS_THICKFRAME | WS_DLGFRAME)) || (exstyle & WS_EX_DLGMODALFRAME) )
  72. +    {
  73. +        width++;
  74. +        height++;
  75. +    }
  76. +
  77. +    rc.left += width;
  78. +    rc.right -= width;
  79. +    rc.top += height;
  80. +    rc.bottom = rc.top + NtUserGetSystemMetrics(SM_CYMENU);
  81. +
  82. +    calc_menu_bar_size( hdc, &rc, menu, hwnd );
  83. +    NtUserReleaseDC( hwnd, hdc );
  84. +}
  85. +
  86.  static BOOL track_menu( HMENU hmenu, UINT flags, int x, int y, HWND hwnd, const RECT *rect )
  87.  {
  88.      BOOL enter_idle_sent = FALSE;
  89. @@ -4096,6 +4173,8 @@ static BOOL track_menu( HMENU hmenu, UINT flags, int x, int y, HWND hwnd, const
  90.          return FALSE;
  91.      }
  92.  
  93. +    recalc_menu_bar_if_needed( hwnd, menu, flags );
  94. +
  95.      if (flags & TPM_BUTTONDOWN)
  96.      {
  97.          /* Get the result in order to start the tracking or not */
  98. @@ -4383,7 +4462,8 @@ static BOOL init_tracking( HWND hwnd, HMENU handle, BOOL is_popup, UINT flags )
  99.      {
  100.         send_message( hwnd, WM_INITMENU, (WPARAM)handle, 0 );
  101.         /* If an app changed/recreated menu bar entries in WM_INITMENU
  102. -        * menu sizes will be recalculated once the menu created/shown. */
  103. +        * menu sizes will be recalculated either in track_menu() or
  104. +        * once the menu created/shown. */
  105.      }
  106.  
  107.      return TRUE;
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement