-- v2: user32: Remove no longer needed helpers. win32u: Move menu object declarations to menu.c.
From: Jacek Caban jacek@codeweavers.com
--- dlls/user32/menu.c | 37 ++----------------------------------- dlls/win32u/menu.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/ntuser.h | 1 + 3 files changed, 45 insertions(+), 35 deletions(-)
diff --git a/dlls/user32/menu.c b/dlls/user32/menu.c index 6fb381ea617..afbf4d2fcea 100644 --- a/dlls/user32/menu.c +++ b/dlls/user32/menu.c @@ -911,42 +911,9 @@ BOOL WINAPI SetMenuItemInfoW(HMENU hmenu, UINT item, BOOL bypos, /********************************************************************** * GetMenuDefaultItem (USER32.@) */ -UINT WINAPI GetMenuDefaultItem(HMENU hmenu, UINT bypos, UINT flags) +UINT WINAPI GetMenuDefaultItem( HMENU menu, UINT bypos, UINT flags ) { - POPUPMENU *menu; - MENUITEM * item; - UINT i = 0; - - TRACE("(%p,%d,%d)\n", hmenu, bypos, flags); - - if (!(menu = MENU_GetMenu(hmenu))) return -1; - - /* find default item */ - item = menu->items; - - /* empty menu */ - if (! item) return -1; - - while ( !( item->fState & MFS_DEFAULT ) ) - { - i++; item++; - if (i >= menu->nItems ) return -1; - } - - /* default: don't return disabled items */ - if ( (!(GMDI_USEDISABLED & flags)) && (item->fState & MFS_DISABLED )) return -1; - - /* search rekursiv when needed */ - if ( (item->fType & MF_POPUP) && (flags & GMDI_GOINTOPOPUPS) ) - { - UINT ret; - ret = GetMenuDefaultItem( item->hSubMenu, bypos, flags ); - if ( -1 != ret ) return ret; - - /* when item not found in submenu, return the popup item */ - } - return ( bypos ) ? i : item->wID; - + return NtUserThunkedMenuItemInfo( menu, bypos, flags, NtUserGetMenuDefaultItem, NULL, NULL ); }
diff --git a/dlls/win32u/menu.c b/dlls/win32u/menu.c index 598576437c6..cf755c57a15 100644 --- a/dlls/win32u/menu.c +++ b/dlls/win32u/menu.c @@ -1170,6 +1170,45 @@ static HMENU get_sub_menu( HMENU handle, INT pos ) return submenu; }
+/* see GetMenuDefaultItem */ +static UINT get_menu_default_item( HMENU handle, UINT bypos, UINT flags ) +{ + MENUITEM *item = NULL; + POPUPMENU *menu; + UINT i; + + TRACE( "(%p,%d,%d)\n", handle, bypos, flags ); + + if (!(menu = grab_menu_ptr( handle ))) return -1; + + for (i = 0; i < menu->nItems; i++) + { + if (!(menu->items[i].fState & MFS_DEFAULT)) continue; + item = &menu->items[i]; + break; + } + + /* default: don't return disabled items */ + if (item && (!(GMDI_USEDISABLED & flags)) && (item->fState & MFS_DISABLED)) item = NULL; + + /* search submenu when needed */ + if (item && (item->fType & MF_POPUP) && (flags & GMDI_GOINTOPOPUPS)) + { + UINT ret = get_menu_default_item( item->hSubMenu, bypos, flags ); + if (ret != -1) + { + release_menu_ptr( menu ); + return ret; + } + /* when item not found in submenu, return the popup item */ + } + + if (!item) i = -1; + else if (!bypos) i = item->wID; + release_menu_ptr( menu ); + return i; +} + /********************************************************************** * NtUserThunkedMenuItemInfo (win32u.@) */ @@ -1185,6 +1224,9 @@ UINT WINAPI NtUserThunkedMenuItemInfo( HMENU handle, UINT pos, UINT flags, UINT case NtUserCheckMenuRadioItem: return check_menu_radio_item( handle, pos, info->cch, info->fMask, flags );
+ case NtUserGetMenuDefaultItem: + return get_menu_default_item( handle, pos, flags ); + case NtUserGetMenuItemID: if (!(menu = find_menu_item( handle, pos, flags, &i ))) return -1; ret = menu->items[i].fType & MF_POPUP ? -1 : menu->items[i].wID; diff --git a/include/ntuser.h b/include/ntuser.h index bf4e9f4b13a..e1435bc2626 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -225,6 +225,7 @@ enum NtUserInsertMenuItem, /* Wine extensions */ NtUserCheckMenuRadioItem, + NtUserGetMenuDefaultItem, NtUserGetMenuItemID, NtUserGetMenuItemInfoA, NtUserGetMenuItemInfoW,
From: Jacek Caban jacek@codeweavers.com
--- dlls/user32/menu.c | 3 ++- dlls/user32/tests/menu.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/dlls/user32/menu.c b/dlls/user32/menu.c index afbf4d2fcea..52dc6369e3a 100644 --- a/dlls/user32/menu.c +++ b/dlls/user32/menu.c @@ -489,7 +489,8 @@ static void MENU_mnu2mnuii( UINT flags, UINT_PTR id, LPCWSTR str, pmii->fMask |= MIIM_DATA; pmii->dwItemData = (ULONG_PTR) str; } - if( flags & MF_POPUP && MENU_GetMenu((HMENU)id)) { + if ((flags & MF_POPUP) && IsMenu( UlongToHandle( id ))) + { pmii->fMask |= MIIM_SUBMENU; pmii->hSubMenu = (HMENU)id; } diff --git a/dlls/user32/tests/menu.c b/dlls/user32/tests/menu.c index c7a20e1b8e9..6862f13c6b1 100644 --- a/dlls/user32/tests/menu.c +++ b/dlls/user32/tests/menu.c @@ -3013,6 +3013,7 @@ static void test_InsertMenu(void) { MF_HELP, 1, MAKEINTRESOURCEA(1) } }; HMENU hmenu; + BOOL ret;
#define create_menu(a) create_menu_from_data((a), ARRAY_SIZE(a)) #define create_menuitem(a) create_menuitem_from_data((a), ARRAY_SIZE(a)) @@ -3054,6 +3055,16 @@ static void test_InsertMenu(void) #undef create_menu #undef create_menuitem #undef compare_menu + + hmenu = CreateMenu(); + + SetLastError(0xdeadbeef); + ret = InsertMenuW(hmenu, -1, MF_BYPOSITION | MF_POPUP, 0xdeadbeef, L"test"); + ok(ret && GetLastError() == ERROR_INVALID_MENU_HANDLE, + "InsertMenuW returned %x %lu\n", ret, GetLastError()); + ok(GetMenuItemCount(hmenu) == 1, "GetMenuItemCount() = %d\n", GetMenuItemCount(hmenu)); + + DestroyMenu(hmenu); }
static void test_menu_getmenuinfo(void)
From: Jacek Caban jacek@codeweavers.com
--- dlls/user32/controls.h | 6 -- dlls/user32/menu.c | 124 --------------------------------- dlls/user32/user_main.c | 8 ++- dlls/win32u/menu.c | 129 ++++++++++++++++++++++++++++++++++- dlls/win32u/ntuser_private.h | 1 - include/ntuser.h | 7 ++ 6 files changed, 140 insertions(+), 135 deletions(-)
diff --git a/dlls/user32/controls.h b/dlls/user32/controls.h index 639b9f2214e..48127ca6bb2 100644 --- a/dlls/user32/controls.h +++ b/dlls/user32/controls.h @@ -112,12 +112,6 @@ extern HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType ) DECLSPEC_HIDDEN; /* desktop */ extern BOOL update_wallpaper( const WCHAR *wallpaper, const WCHAR *pattern ) DECLSPEC_HIDDEN;
-/* menu controls */ -extern void MENU_TrackMouseMenuBar( HWND hwnd, INT ht, POINT pt ) DECLSPEC_HIDDEN; -extern void MENU_TrackKbdMenuBar( HWND hwnd, UINT wParam, WCHAR wChar ) DECLSPEC_HIDDEN; -extern void MENU_EndMenu(HWND) DECLSPEC_HIDDEN; -extern HMENU MENU_GetSysMenu( HWND hWnd, HMENU hPopupMenu ) DECLSPEC_HIDDEN; - /* nonclient area */ extern LRESULT NC_HandleNCMouseMove( HWND hwnd, WPARAM wParam, LPARAM lParam ) DECLSPEC_HIDDEN; extern LRESULT NC_HandleNCMouseLeave( HWND hwnd ) DECLSPEC_HIDDEN; diff --git a/dlls/user32/menu.c b/dlls/user32/menu.c index 52dc6369e3a..07be830eed3 100644 --- a/dlls/user32/menu.c +++ b/dlls/user32/menu.c @@ -42,15 +42,10 @@ #include <stdarg.h> #include <string.h>
-#define OEMRESOURCE - #include "windef.h" #include "winbase.h" #include "wingdi.h" #include "winnls.h" -#include "wine/server.h" -#include "wine/exception.h" -#include "win.h" #include "controls.h" #include "user_private.h" #include "wine/debug.h" @@ -58,15 +53,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(menu);
- /* Space between 2 columns */ -#define MENU_COL_SPACE 4 - - /* Margins for popup menus */ -#define MENU_MARGIN 3 - - /* (other menu->FocusedItem values give the position of the focused item) */ -#define NO_SELECTED_ITEM 0xffff - #define MENU_ITEM_TYPE(flags) \ ((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR))
@@ -96,116 +82,6 @@ const struct builtin_class_descr MENU_builtin_class = };
-/*********************************************************************** - * MENU_GetMenu - * - * Validate the given menu handle and returns the menu structure pointer. - */ -static POPUPMENU *MENU_GetMenu(HMENU hMenu) -{ - POPUPMENU *menu = get_user_handle_ptr( hMenu, NTUSER_OBJ_MENU ); - - if (menu == OBJ_OTHER_PROCESS) - { - WARN( "other process menu %p?\n", hMenu); - return NULL; - } - if (menu) release_user_handle_ptr( menu ); /* FIXME! */ - else WARN("invalid menu handle=%p\n", hMenu); - return menu; -} - -/*********************************************************************** - * MENU_CopySysPopup - * - * Return the default system menu. - */ -static HMENU MENU_CopySysPopup(BOOL mdi) -{ - HMENU hMenu = LoadMenuW(user32_module, mdi ? L"SYSMENUMDI" : L"SYSMENU"); - - if( hMenu ) { - MENUINFO minfo; - MENUITEMINFOW miteminfo; - POPUPMENU* menu = MENU_GetMenu(hMenu); - menu->wFlags |= MF_SYSMENU | MF_POPUP; - /* decorate the menu with bitmaps */ - minfo.cbSize = sizeof( MENUINFO); - minfo.dwStyle = MNS_CHECKORBMP; - minfo.fMask = MIM_STYLE; - SetMenuInfo( hMenu, &minfo); - miteminfo.cbSize = sizeof( MENUITEMINFOW); - miteminfo.fMask = MIIM_BITMAP; - miteminfo.hbmpItem = HBMMENU_POPUP_CLOSE; - SetMenuItemInfoW( hMenu, SC_CLOSE, FALSE, &miteminfo); - miteminfo.hbmpItem = HBMMENU_POPUP_RESTORE; - SetMenuItemInfoW( hMenu, SC_RESTORE, FALSE, &miteminfo); - miteminfo.hbmpItem = HBMMENU_POPUP_MAXIMIZE; - SetMenuItemInfoW( hMenu, SC_MAXIMIZE, FALSE, &miteminfo); - miteminfo.hbmpItem = HBMMENU_POPUP_MINIMIZE; - SetMenuItemInfoW( hMenu, SC_MINIMIZE, FALSE, &miteminfo); - NtUserSetMenuDefaultItem( hMenu, SC_CLOSE, FALSE ); - } - else - ERR("Unable to load default system menu\n" ); - - TRACE("returning %p (mdi=%d).\n", hMenu, mdi ); - - return hMenu; -} - - -/********************************************************************** - * MENU_GetSysMenu - * - * Create a copy of the system menu. System menu in Windows is - * a special menu bar with the single entry - system menu popup. - * This popup is presented to the outside world as a "system menu". - * However, the real system menu handle is sometimes seen in the - * WM_MENUSELECT parameters (and Word 6 likes it this way). - */ -HMENU MENU_GetSysMenu( HWND hWnd, HMENU hPopupMenu ) -{ - HMENU hMenu; - - TRACE("loading system menu, hWnd %p, hPopupMenu %p\n", hWnd, hPopupMenu); - if ((hMenu = CreateMenu())) - { - POPUPMENU *menu = MENU_GetMenu(hMenu); - menu->wFlags = MF_SYSMENU; - menu->hWnd = WIN_GetFullHandle( hWnd ); - TRACE("hWnd %p (hMenu %p)\n", menu->hWnd, hMenu); - - if (!hPopupMenu) - { - if (GetWindowLongW(hWnd, GWL_EXSTYLE) & WS_EX_MDICHILD) - hPopupMenu = MENU_CopySysPopup(TRUE); - else - hPopupMenu = MENU_CopySysPopup(FALSE); - } - - if (hPopupMenu) - { - if (GetClassLongW(hWnd, GCL_STYLE) & CS_NOCLOSE) - NtUserDeleteMenu( hPopupMenu, SC_CLOSE, MF_BYCOMMAND ); - - InsertMenuW( hMenu, -1, MF_SYSMENU | MF_POPUP | MF_BYPOSITION, - (UINT_PTR)hPopupMenu, NULL ); - - menu->items[0].fType = MF_SYSMENU | MF_POPUP; - menu->items[0].fState = 0; - if ((menu = MENU_GetMenu(hPopupMenu))) menu->wFlags |= MF_SYSMENU; - - TRACE("hMenu=%p (hPopup %p)\n", hMenu, hPopupMenu ); - return hMenu; - } - NtUserDestroyMenu( hMenu ); - } - ERR("failed to load system menu!\n"); - return 0; -} - - /********************************************************************** * MENU_ParseResource * diff --git a/dlls/user32/user_main.c b/dlls/user32/user_main.c index 55e72dcf203..038f1f0796f 100644 --- a/dlls/user32/user_main.c +++ b/dlls/user32/user_main.c @@ -159,7 +159,6 @@ static const struct user_callbacks user_funcs = NtWaitForMultipleObjects, SCROLL_DrawNCScrollBar, free_win_ptr, - MENU_GetSysMenu, notify_ime, post_dde_message, rawinput_update_device_list, @@ -190,6 +189,12 @@ static NTSTATUS WINAPI User32LoadImage( const struct load_image_params *params, return HandleToUlong( ret ); }
+static NTSTATUS WINAPI User32LoadSysMenu( const struct load_sys_menu_params *params, ULONG size ) +{ + HMENU ret = LoadMenuW( user32_module, params->mdi ? L"SYSMENUMDI" : L"SYSMENU" ); + return HandleToUlong( ret ); +} + static NTSTATUS WINAPI User32FreeCachedClipboardData( const struct free_cached_data_params *params, ULONG size ) { @@ -221,6 +226,7 @@ static const void *kernel_callback_table[NtUserCallCount] = User32FreeCachedClipboardData, User32LoadDriver, User32LoadImage, + User32LoadSysMenu, User32RegisterBuiltinClasses, User32RenderSsynthesizedFormat, }; diff --git a/dlls/win32u/menu.c b/dlls/win32u/menu.c index cf755c57a15..64c832c58a9 100644 --- a/dlls/win32u/menu.c +++ b/dlls/win32u/menu.c @@ -1378,6 +1378,129 @@ BOOL WINAPI NtUserSetMenuContextHelpId( HMENU handle, DWORD id ) return TRUE; }
+/*********************************************************************** + * copy_sys_popup + * + * Return the default system menu. + */ +static HMENU copy_sys_popup( BOOL mdi ) +{ + struct load_sys_menu_params params; + MENUITEMINFOW item_info; + MENUINFO menu_info; + POPUPMENU *menu; + void *ret_ptr; + ULONG ret_len; + HMENU handle; + + params.mdi = mdi; + handle = UlongToHandle( KeUserModeCallback( NtUserLoadSysMenu, ¶ms, sizeof(params), + &ret_ptr, &ret_len )); + + if (!handle || !(menu = grab_menu_ptr( handle ))) + { + ERR("Unable to load default system menu\n" ); + return 0; + } + + menu->wFlags |= MF_SYSMENU | MF_POPUP; + release_menu_ptr( menu ); + + /* decorate the menu with bitmaps */ + menu_info.cbSize = sizeof(MENUINFO); + menu_info.dwStyle = MNS_CHECKORBMP; + menu_info.fMask = MIM_STYLE; + NtUserThunkedMenuInfo( handle, &menu_info ); + item_info.cbSize = sizeof(MENUITEMINFOW); + item_info.fMask = MIIM_BITMAP; + item_info.hbmpItem = HBMMENU_POPUP_CLOSE; + NtUserThunkedMenuItemInfo( handle, SC_CLOSE, 0, NtUserSetMenuItemInfo, &item_info, NULL ); + item_info.hbmpItem = HBMMENU_POPUP_RESTORE; + NtUserThunkedMenuItemInfo( handle, SC_RESTORE, 0, NtUserSetMenuItemInfo, &item_info, NULL ); + item_info.hbmpItem = HBMMENU_POPUP_MAXIMIZE; + NtUserThunkedMenuItemInfo( handle, SC_MAXIMIZE, 0, NtUserSetMenuItemInfo, &item_info, NULL ); + item_info.hbmpItem = HBMMENU_POPUP_MINIMIZE; + NtUserThunkedMenuItemInfo( handle, SC_MINIMIZE, 0, NtUserSetMenuItemInfo, &item_info, NULL ); + NtUserSetMenuDefaultItem( handle, SC_CLOSE, FALSE ); + + TRACE( "returning %p (mdi=%d).\n", handle, mdi ); + return handle; +} + +/********************************************************************** + * get_sys_menu + * + * Create a copy of the system menu. System menu in Windows is + * a special menu bar with the single entry - system menu popup. + * This popup is presented to the outside world as a "system menu". + * However, the real system menu handle is sometimes seen in the + * WM_MENUSELECT parameters (and Word 6 likes it this way). + */ +static HMENU get_sys_menu( HWND hwnd, HMENU popup_menu ) +{ + MENUITEMINFOW info; + POPUPMENU *menu; + HMENU handle; + + TRACE("loading system menu, hwnd %p, popup_menu %p\n", hwnd, popup_menu); + if (!(handle = create_menu( FALSE ))) + { + ERR("failed to load system menu!\n"); + return 0; + } + + if (!(menu = grab_menu_ptr( handle ))) + { + NtUserDestroyMenu( handle ); + return 0; + } + menu->wFlags = MF_SYSMENU; + menu->hWnd = get_full_window_handle( hwnd ); + release_menu_ptr( menu ); + TRACE("hwnd %p (handle %p)\n", menu->hWnd, handle); + + if (!popup_menu) + { + if (get_window_long(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD) + popup_menu = copy_sys_popup(TRUE); + else + popup_menu = copy_sys_popup(FALSE); + } + if (!popup_menu) + { + NtUserDestroyMenu( handle ); + return 0; + } + + if (get_class_long( hwnd, GCL_STYLE, FALSE ) & CS_NOCLOSE) + NtUserDeleteMenu(popup_menu, SC_CLOSE, MF_BYCOMMAND); + + info.cbSize = sizeof(info); + info.fMask = MIIM_STATE | MIIM_ID | MIIM_FTYPE | MIIM_SUBMENU; + info.fState = 0; + info.fType = MF_SYSMENU | MF_POPUP; + info.wID = (UINT_PTR)popup_menu; + info.hSubMenu = popup_menu; + + NtUserThunkedMenuItemInfo( handle, -1, MF_SYSMENU | MF_POPUP | MF_BYPOSITION, + NtUserInsertMenuItem, &info, NULL ); + + if ((menu = grab_menu_ptr( handle ))) + { + menu->items[0].fType = MF_SYSMENU | MF_POPUP; + menu->items[0].fState = 0; + release_menu_ptr( menu ); + } + if ((menu = grab_menu_ptr(popup_menu))) + { + menu->wFlags |= MF_SYSMENU; + release_menu_ptr( menu ); + } + + TRACE("handle=%p (hPopup %p)\n", handle, popup_menu ); + return handle; +} + /********************************************************************** * NtUserMenuItemFromPoint (win32u.@) */ @@ -1414,8 +1537,8 @@ HMENU WINAPI NtUserGetSystemMenu( HWND hwnd, BOOL revert ) win->hSysMenu = 0; }
- if (!win->hSysMenu && (win->dwStyle & WS_SYSMENU) && user_callbacks) - win->hSysMenu = user_callbacks->get_sys_menu( hwnd, 0 ); + if (!win->hSysMenu && (win->dwStyle & WS_SYSMENU)) + win->hSysMenu = get_sys_menu( hwnd, 0 );
if (win->hSysMenu) { @@ -1446,7 +1569,7 @@ BOOL WINAPI NtUserSetSystemMenu( HWND hwnd, HMENU menu ) if (!win || win == WND_OTHER_PROCESS || win == WND_DESKTOP) return FALSE;
if (win->hSysMenu) NtUserDestroyMenu( win->hSysMenu ); - win->hSysMenu = user_callbacks ? user_callbacks->get_sys_menu( hwnd, menu ) : NULL; + win->hSysMenu = get_sys_menu( hwnd, menu ); release_win_ptr( win ); return TRUE; } diff --git a/dlls/win32u/ntuser_private.h b/dlls/win32u/ntuser_private.h index eb851f57cdb..a5b77a85396 100644 --- a/dlls/win32u/ntuser_private.h +++ b/dlls/win32u/ntuser_private.h @@ -37,7 +37,6 @@ struct user_callbacks NTSTATUS (WINAPI *pNtWaitForMultipleObjects)(ULONG,const HANDLE*,BOOLEAN,BOOLEAN,const LARGE_INTEGER*); void (CDECL *draw_nc_scrollbar)( HWND hwnd, HDC hdc, BOOL draw_horizontal, BOOL draw_vertical ); void (CDECL *free_win_ptr)( struct tagWND *win ); - HMENU (CDECL *get_sys_menu)( HWND hwnd, HMENU popup ); void (CDECL *notify_ime)( HWND hwnd, UINT param ); BOOL (CDECL *post_dde_message)( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, DWORD dest_tid, DWORD type ); diff --git a/include/ntuser.h b/include/ntuser.h index e1435bc2626..18ddbcaa4a4 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -37,6 +37,7 @@ enum NtUserFreeCachedClipboardData, NtUserLoadDriver, NtUserLoadImage, + NtUserLoadSysMenu, NtUserRegisterBuiltinClasses, NtUserRenderSynthesizedFormat, /* win16 hooks */ @@ -187,6 +188,12 @@ struct load_image_params UINT flags; };
+/* NtUserLoadSysMenu params */ +struct load_sys_menu_params +{ + BOOL mdi; +}; + /* NtUserRenderSynthesizedFormat params */ struct render_synthesized_format_params {
From: Jacek Caban jacek@codeweavers.com
And drop typedefs. --- dlls/win32u/menu.c | 289 ++++++++++++++++++++--------------- dlls/win32u/ntuser_private.h | 49 ------ 2 files changed, 167 insertions(+), 171 deletions(-)
diff --git a/dlls/win32u/menu.c b/dlls/win32u/menu.c index 64c832c58a9..c67d0e00615 100644 --- a/dlls/win32u/menu.c +++ b/dlls/win32u/menu.c @@ -32,6 +32,51 @@ WINE_DEFAULT_DEBUG_CHANNEL(menu); WINE_DECLARE_DEBUG_CHANNEL(accel);
+ +/* menu item structure */ +struct menu_item +{ + UINT fType; /* item type */ + UINT fState; /* item state */ + UINT_PTR wID; /* item id */ + HMENU hSubMenu; /* pop-up menu */ + HBITMAP hCheckBit; /* bitmap when checked */ + HBITMAP hUnCheckBit; /* bitmap when unchecked */ + LPWSTR text; /* item text */ + ULONG_PTR dwItemData; /* application defined */ + LPWSTR dwTypeData; /* depends on fMask */ + HBITMAP hbmpItem; /* bitmap */ + RECT rect; /* item area (relative to the items_rect), see adjust_menu_item_rect */ + UINT xTab; /* X position of text after Tab */ + SIZE bmpsize; /* size needed for the HBMMENU_CALLBACK bitmap */ +}; + +/* menu user object */ +struct menu +{ + struct user_object obj; + struct menu_item *items; /* array of menu items */ + WORD wFlags; /* menu flags (MF_POPUP, MF_SYSMENU) */ + WORD Width; /* width of the whole menu */ + WORD Height; /* height of the whole menu */ + UINT nItems; /* number of items in the menu */ + HWND hWnd; /* window containing the menu */ + UINT FocusedItem; /* currently focused item */ + HWND hwndOwner; /* window receiving the messages for ownerdraw */ + BOOL bScrolling; /* scroll arrows are active */ + UINT nScrollPos; /* current scroll position */ + UINT nTotalHeight; /* total height of menu items inside menu */ + RECT items_rect; /* rectangle within which the items lie, excludes margins and scroll arrows */ + LONG refcount; + DWORD dwStyle; /* extended menu style */ + UINT cyMax; /* max height of the whole menu, 0 is screen height */ + HBRUSH hbrBack; /* brush for menu background */ + DWORD dwContextHelpID; + ULONG_PTR dwMenuData; /* application defined value */ + HMENU hSysMenuOwner; /* handle to the dummy sys menu holder */ + WORD textOffset; /* offset of text when items have both bitmaps and text */ +}; + /* the accelerator user object */ struct accelerator { @@ -190,7 +235,7 @@ BOOL WINAPI NtUserDestroyAcceleratorTable( HACCEL handle ) if (flags & (bit)) { flags &= ~(bit); strcat(buf, (text)); } \ } while (0)
-static const char *debugstr_menuitem( const MENUITEM *item ) +static const char *debugstr_menuitem( const struct menu_item *item ) { static const char *const hbmmenus[] = { "HBMMENU_CALLBACK", "", "HBMMENU_SYSTEM", "HBMMENU_MBAR_RESTORE", "HBMMENU_MBAR_MINIMIZE", "UNKNOWN BITMAP", "HBMMENU_MBAR_CLOSE", @@ -252,9 +297,9 @@ static const char *debugstr_menuitem( const MENUITEM *item )
#undef MENUFLAG
-static POPUPMENU *grab_menu_ptr( HMENU handle ) +static struct menu *grab_menu_ptr( HMENU handle ) { - POPUPMENU *menu = get_user_handle_ptr( handle, NTUSER_OBJ_MENU ); + struct menu *menu = get_user_handle_ptr( handle, NTUSER_OBJ_MENU );
if (menu == OBJ_OTHER_PROCESS) { @@ -269,7 +314,7 @@ static POPUPMENU *grab_menu_ptr( HMENU handle ) return menu; }
-static void release_menu_ptr( POPUPMENU *menu ) +static void release_menu_ptr( struct menu *menu ) { if (menu) { @@ -282,9 +327,9 @@ static void release_menu_ptr( POPUPMENU *menu ) * Validate the given menu handle and returns the menu structure pointer. * FIXME: this is unsafe, we should use a better mechanism instead. */ -static POPUPMENU *unsafe_menu_ptr( HMENU handle ) +static struct menu *unsafe_menu_ptr( HMENU handle ) { - POPUPMENU *menu = grab_menu_ptr( handle ); + struct menu *menu = grab_menu_ptr( handle ); if (menu) release_menu_ptr( menu ); return menu; } @@ -292,7 +337,7 @@ static POPUPMENU *unsafe_menu_ptr( HMENU handle ) /* see IsMenu */ BOOL is_menu( HMENU handle ) { - POPUPMENU *menu; + struct menu *menu; BOOL is_menu;
menu = grab_menu_ptr( handle ); @@ -320,10 +365,10 @@ static HMENU get_win_sys_menu( HWND hwnd ) return ret; }
-static POPUPMENU *find_menu_item( HMENU handle, UINT id, UINT flags, UINT *pos ) +static struct menu *find_menu_item( HMENU handle, UINT id, UINT flags, UINT *pos ) { UINT fallback_pos = ~0u, i; - POPUPMENU *menu; + struct menu *menu;
menu = grab_menu_ptr( handle ); if (!menu) @@ -342,12 +387,12 @@ static POPUPMENU *find_menu_item( HMENU handle, UINT id, UINT flags, UINT *pos ) } else { - MENUITEM *item = menu->items; + struct menu_item *item = menu->items; for (i = 0; i < menu->nItems; i++, item++) { if (item->fType & MF_POPUP) { - POPUPMENU *submenu = find_menu_item( item->hSubMenu, id, flags, pos ); + struct menu *submenu = find_menu_item( item->hSubMenu, id, flags, pos );
if (submenu) { @@ -379,10 +424,10 @@ static POPUPMENU *find_menu_item( HMENU handle, UINT id, UINT flags, UINT *pos ) return menu; }
-static POPUPMENU *insert_menu_item( HMENU handle, UINT id, UINT flags, UINT *ret_pos ) +static struct menu *insert_menu_item( HMENU handle, UINT id, UINT flags, UINT *ret_pos ) { - MENUITEM *new_items; - POPUPMENU *menu; + struct menu_item *new_items; + struct menu *menu; UINT pos = id;
/* Find where to insert new item */ @@ -403,7 +448,7 @@ static POPUPMENU *insert_menu_item( HMENU handle, UINT id, UINT flags, UINT *ret
TRACE( "inserting at %u flags %x\n", pos, flags );
- new_items = malloc( sizeof(MENUITEM) * (menu->nItems + 1) ); + new_items = malloc( sizeof(*new_items) * (menu->nItems + 1) ); if (!new_items) { release_menu_ptr( menu ); @@ -412,9 +457,9 @@ static POPUPMENU *insert_menu_item( HMENU handle, UINT id, UINT flags, UINT *ret if (menu->nItems > 0) { /* Copy the old array into the new one */ - if (pos > 0) memcpy( new_items, menu->items, pos * sizeof(MENUITEM) ); + if (pos > 0) memcpy( new_items, menu->items, pos * sizeof(*new_items) ); if (pos < menu->nItems) memcpy( &new_items[pos + 1], &menu->items[pos], - (menu->nItems - pos) * sizeof(MENUITEM) ); + (menu->nItems - pos) * sizeof(*new_items) ); free( menu->items ); } menu->items = new_items; @@ -440,8 +485,8 @@ static BOOL is_win_menu_disallowed( HWND hwnd ) */ static UINT find_submenu( HMENU *handle_ptr, HMENU target ) { - POPUPMENU *menu; - MENUITEM *item; + struct menu *menu; + struct menu_item *item; UINT i;
if (*handle_ptr == (HMENU)0xffff || !(menu = grab_menu_ptr( *handle_ptr ))) @@ -474,7 +519,7 @@ static UINT find_submenu( HMENU *handle_ptr, HMENU target ) }
/* Adjust menu item rectangle according to scrolling state */ -static void adjust_menu_item_rect( const POPUPMENU *menu, RECT *rect ) +static void adjust_menu_item_rect( const struct menu *menu, RECT *rect ) { INT scroll_offset = menu->bScrolling ? menu->nScrollPos : 0; OffsetRect( rect, menu->items_rect.left, menu->items_rect.top - scroll_offset ); @@ -493,10 +538,10 @@ static void adjust_menu_item_rect( const POPUPMENU *menu, RECT *rect ) * item that's just outside the items_rect - ie, the one that would * be scrolled completely into view. */ -static enum hittest find_item_by_coords( const POPUPMENU *menu, POINT pt, UINT *pos ) +static enum hittest find_item_by_coords( const struct menu *menu, POINT pt, UINT *pos ) { enum hittest ht = ht_border; - MENUITEM *item; + struct menu_item *item; RECT rect; UINT i;
@@ -552,7 +597,7 @@ HMENU get_menu( HWND hwnd ) /* see CreateMenu and CreatePopupMenu */ HMENU create_menu( BOOL is_popup ) { - POPUPMENU *menu; + struct menu *menu; HMENU handle;
if (!(menu = calloc( 1, sizeof(*menu) ))) return 0; @@ -571,7 +616,7 @@ HMENU create_menu( BOOL is_popup ) */ BOOL WINAPI NtUserDestroyMenu( HMENU handle ) { - POPUPMENU *menu; + struct menu *menu;
TRACE( "(%p)\n", handle );
@@ -588,7 +633,7 @@ BOOL WINAPI NtUserDestroyMenu( HMENU handle ) /* recursively destroy submenus */ if (menu->items) { - MENUITEM *item = menu->items; + struct menu_item *item = menu->items; int i;
for (i = menu->nItems; i > 0; i--, item++) @@ -627,7 +672,7 @@ BOOL set_window_menu( HWND hwnd, HMENU handle )
if (handle) { - POPUPMENU *menu; + struct menu *menu;
if (!(menu = grab_menu_ptr( handle ))) return FALSE; menu->hWnd = hwnd; @@ -657,8 +702,8 @@ BOOL WINAPI NtUserSetMenu( HWND hwnd, HMENU menu ) */ DWORD WINAPI NtUserCheckMenuItem( HMENU handle, UINT id, UINT flags ) { - POPUPMENU *menu; - MENUITEM *item; + struct menu_item *item; + struct menu *menu; DWORD ret; UINT pos;
@@ -679,8 +724,8 @@ DWORD WINAPI NtUserCheckMenuItem( HMENU handle, UINT id, UINT flags ) BOOL WINAPI NtUserEnableMenuItem( HMENU handle, UINT id, UINT flags ) { UINT oldflags, pos; - POPUPMENU *menu; - MENUITEM *item; + struct menu *menu; + struct menu_item *item;
TRACE( "(%p, %04x, %04x)\n", handle, id, flags );
@@ -695,7 +740,7 @@ BOOL WINAPI NtUserEnableMenuItem( HMENU handle, UINT id, UINT flags ) /* If the close item in the system menu change update the close button */ if (item->wID == SC_CLOSE && oldflags != flags && menu->hSysMenuOwner) { - POPUPMENU *parent_menu; + struct menu *parent_menu; RECT rc; HWND hwnd;
@@ -729,7 +774,7 @@ BOOL draw_menu_bar( HWND hwnd )
if ((handle = get_menu( hwnd ))) { - POPUPMENU *menu = grab_menu_ptr( handle ); + struct menu *menu = grab_menu_ptr( handle ); if (menu) { menu->Height = 0; /* Make sure we call MENU_MenuBarCalcSize */ @@ -747,7 +792,7 @@ BOOL draw_menu_bar( HWND hwnd ) */ BOOL WINAPI NtUserGetMenuItemRect( HWND hwnd, HMENU handle, UINT item, RECT *rect ) { - POPUPMENU *menu; + struct menu *menu; UINT pos; RECT window_rect;
@@ -784,7 +829,7 @@ BOOL WINAPI NtUserGetMenuItemRect( HWND hwnd, HMENU handle, UINT item, RECT *rec
static BOOL set_menu_info( HMENU handle, const MENUINFO *info ) { - POPUPMENU *menu; + struct menu *menu;
if (!(menu = grab_menu_ptr( handle ))) return FALSE;
@@ -797,7 +842,7 @@ static BOOL set_menu_info( HMENU handle, const MENUINFO *info ) if (info->fMask & MIM_APPLYTOSUBMENUS) { int i; - MENUITEM *item = menu->items; + struct menu_item *item = menu->items; for (i = menu->nItems; i; i--, item++) if (item->fType & MF_POPUP) set_menu_info( item->hSubMenu, info); @@ -838,7 +883,7 @@ BOOL WINAPI NtUserThunkedMenuInfo( HMENU menu, const MENUINFO *info ) /* see GetMenuInfo */ BOOL get_menu_info( HMENU handle, MENUINFO *info ) { - POPUPMENU *menu; + struct menu *menu;
TRACE( "(%p %p)\n", handle, info );
@@ -863,17 +908,17 @@ BOOL get_menu_info( HMENU handle, MENUINFO *info ) * * detect if there are loops in the menu tree (or the depth is too large) */ -static int menu_depth( POPUPMENU *pmenu, int depth) +static int menu_depth( struct menu *pmenu, int depth) { int i, subdepth; - MENUITEM *item; + struct menu_item *item;
if (++depth > MAXMENUDEPTH) return depth; item = pmenu->items; subdepth = depth; for (i = 0; i < pmenu->nItems && subdepth <= MAXMENUDEPTH; i++, item++) { - POPUPMENU *submenu = item->hSubMenu ? grab_menu_ptr( item->hSubMenu ) : NULL; + struct menu *submenu = item->hSubMenu ? grab_menu_ptr( item->hSubMenu ) : NULL; if (submenu) { int bdepth = menu_depth( submenu, depth); @@ -887,7 +932,7 @@ static int menu_depth( POPUPMENU *pmenu, int depth) return subdepth; }
-static BOOL set_menu_item_info( MENUITEM *menu, const MENUITEMINFOW *info ) +static BOOL set_menu_item_info( struct menu_item *menu, const MENUITEMINFOW *info ) { if (!menu) return FALSE;
@@ -922,7 +967,7 @@ static BOOL set_menu_item_info( MENUITEM *menu, const MENUITEMINFOW *info ) menu->hSubMenu = info->hSubMenu; if (menu->hSubMenu) { - POPUPMENU *submenu = grab_menu_ptr( menu->hSubMenu ); + struct menu *submenu = grab_menu_ptr( menu->hSubMenu ); if (!submenu) { SetLastError( ERROR_INVALID_PARAMETER); @@ -964,9 +1009,9 @@ static BOOL set_menu_item_info( MENUITEM *menu, const MENUITEMINFOW *info ) /* see GetMenuState */ UINT get_menu_state( HMENU handle, UINT item_id, UINT flags ) { - POPUPMENU *menu; + struct menu *menu; UINT state, pos; - MENUITEM *item; + struct menu_item *item;
TRACE( "(menu=%p, id=%04x, flags=%04x);\n", handle, item_id, flags );
@@ -977,7 +1022,7 @@ UINT get_menu_state( HMENU handle, UINT item_id, UINT flags ) TRACE( " item: %s\n", debugstr_menuitem( item )); if (item->fType & MF_POPUP) { - POPUPMENU *submenu = grab_menu_ptr( item->hSubMenu ); + struct menu *submenu = grab_menu_ptr( item->hSubMenu ); if (submenu) state = (submenu->nItems << 8) | ((item->fState | item->fType) & 0xff); else @@ -994,8 +1039,8 @@ UINT get_menu_state( HMENU handle, UINT item_id, UINT flags )
static BOOL get_menu_item_info( HMENU handle, UINT id, UINT flags, MENUITEMINFOW *info, BOOL ansi ) { - POPUPMENU *menu; - MENUITEM *item; + struct menu *menu; + struct menu_item *item; UINT pos;
if (!info || info->cbSize != sizeof(*info)) @@ -1111,13 +1156,13 @@ static BOOL get_menu_item_info( HMENU handle, UINT id, UINT flags, MENUITEMINFOW
static BOOL check_menu_radio_item( HMENU handle, UINT first, UINT last, UINT check, UINT flags ) { - POPUPMENU *first_menu = NULL, *check_menu; + struct menu *first_menu = NULL, *check_menu; UINT i, check_pos; BOOL done = FALSE;
for (i = first; i <= last; i++) { - MENUITEM *item; + struct menu_item *item;
if (!(check_menu = find_menu_item( handle, i, flags, &check_pos ))) continue; if (!first_menu) first_menu = grab_menu_ptr( check_menu->obj.handle ); @@ -1154,7 +1199,7 @@ static BOOL check_menu_radio_item( HMENU handle, UINT first, UINT last, UINT che /* see GetSubMenu */ static HMENU get_sub_menu( HMENU handle, INT pos ) { - POPUPMENU *menu; + struct menu *menu; HMENU submenu; UINT i;
@@ -1173,8 +1218,8 @@ static HMENU get_sub_menu( HMENU handle, INT pos ) /* see GetMenuDefaultItem */ static UINT get_menu_default_item( HMENU handle, UINT bypos, UINT flags ) { - MENUITEM *item = NULL; - POPUPMENU *menu; + struct menu_item *item = NULL; + struct menu *menu; UINT i;
TRACE( "(%p,%d,%d)\n", handle, bypos, flags ); @@ -1215,7 +1260,7 @@ static UINT get_menu_default_item( HMENU handle, UINT bypos, UINT flags ) UINT WINAPI NtUserThunkedMenuItemInfo( HMENU handle, UINT pos, UINT flags, UINT method, MENUITEMINFOW *info, UNICODE_STRING *str ) { - POPUPMENU *menu; + struct menu *menu; UINT i; BOOL ret;
@@ -1294,7 +1339,7 @@ UINT WINAPI NtUserThunkedMenuItemInfo( HMENU handle, UINT pos, UINT flags, UINT /* see GetMenuItemCount */ INT get_menu_item_count( HMENU handle ) { - POPUPMENU *menu; + struct menu *menu; INT count;
if (!(menu = grab_menu_ptr( handle ))) return -1; @@ -1310,7 +1355,7 @@ INT get_menu_item_count( HMENU handle ) */ BOOL WINAPI NtUserRemoveMenu( HMENU handle, UINT id, UINT flags ) { - POPUPMENU *menu; + struct menu *menu; UINT pos;
TRACE( "(menu=%p id=%#x flags=%04x)\n", handle, id, flags ); @@ -1328,7 +1373,7 @@ BOOL WINAPI NtUserRemoveMenu( HMENU handle, UINT id, UINT flags ) } else { - MENUITEM *new_items, *item = &menu->items[pos]; + struct menu_item *new_items, *item = &menu->items[pos];
while (pos < menu->nItems) { @@ -1336,7 +1381,7 @@ BOOL WINAPI NtUserRemoveMenu( HMENU handle, UINT id, UINT flags ) item++; pos++; } - new_items = realloc( menu->items, menu->nItems * sizeof(MENUITEM) ); + new_items = realloc( menu->items, menu->nItems * sizeof(*item) ); if (new_items) menu->items = new_items; }
@@ -1349,7 +1394,7 @@ BOOL WINAPI NtUserRemoveMenu( HMENU handle, UINT id, UINT flags ) */ BOOL WINAPI NtUserDeleteMenu( HMENU handle, UINT id, UINT flags ) { - POPUPMENU *menu; + struct menu *menu; UINT pos;
if (!(menu = find_menu_item( handle, id, flags, &pos ))) @@ -1368,7 +1413,7 @@ BOOL WINAPI NtUserDeleteMenu( HMENU handle, UINT id, UINT flags ) */ BOOL WINAPI NtUserSetMenuContextHelpId( HMENU handle, DWORD id ) { - POPUPMENU *menu; + struct menu *menu;
TRACE( "(%p 0x%08x)\n", handle, id );
@@ -1388,7 +1433,7 @@ static HMENU copy_sys_popup( BOOL mdi ) struct load_sys_menu_params params; MENUITEMINFOW item_info; MENUINFO menu_info; - POPUPMENU *menu; + struct menu *menu; void *ret_ptr; ULONG ret_len; HMENU handle; @@ -1439,7 +1484,7 @@ static HMENU copy_sys_popup( BOOL mdi ) static HMENU get_sys_menu( HWND hwnd, HMENU popup_menu ) { MENUITEMINFOW info; - POPUPMENU *menu; + struct menu *menu; HMENU handle;
TRACE("loading system menu, hwnd %p, popup_menu %p\n", hwnd, popup_menu); @@ -1507,7 +1552,7 @@ static HMENU get_sys_menu( HWND hwnd, HMENU popup_menu ) INT WINAPI NtUserMenuItemFromPoint( HWND hwnd, HMENU handle, int x, int y ) { POINT pt = { .x = x, .y = y }; - POPUPMENU *menu; + struct menu *menu; UINT pos;
if (!(menu = grab_menu_ptr(handle))) return -1; @@ -1542,7 +1587,7 @@ HMENU WINAPI NtUserGetSystemMenu( HWND hwnd, BOOL revert )
if (win->hSysMenu) { - POPUPMENU *menu; + struct menu *menu; retvalue = get_sub_menu( win->hSysMenu, 0 );
/* Store the dummy sysmenu handle to facilitate the refresh */ @@ -1579,8 +1624,8 @@ BOOL WINAPI NtUserSetSystemMenu( HWND hwnd, HMENU menu ) */ BOOL WINAPI NtUserSetMenuDefaultItem( HMENU handle, UINT item, UINT bypos ) { - MENUITEM *menu_item; - POPUPMENU *menu; + struct menu_item *menu_item; + struct menu *menu; unsigned int i; BOOL ret = FALSE;
@@ -1676,7 +1721,7 @@ found: { HMENU menu_handle, submenu, sys_menu; UINT sys_stat = ~0u, stat = ~0u, pos; - POPUPMENU *menu; + struct menu *menu;
menu_handle = (get_window_long( hwnd, GWL_STYLE ) & WS_CHILD) ? 0 : get_menu(hwnd); sys_menu = get_win_sys_menu( hwnd ); @@ -1866,7 +1911,7 @@ static HBITMAP get_arrow_bitmap(void) }
/* Get the size of a bitmap item */ -static void get_bitmap_item_size( MENUITEM *item, SIZE *size, HWND owner ) +static void get_bitmap_item_size( struct menu_item *item, SIZE *size, HWND owner ) { HBITMAP bmp = item->hbmpItem; BITMAP bm; @@ -1922,8 +1967,8 @@ static void get_bitmap_item_size( MENUITEM *item, SIZE *size, HWND owner ) }
/* Calculate the size of the menu item and store it in item->rect */ -static void calc_menu_item_size( HDC hdc, MENUITEM *item, HWND owner, INT org_x, INT org_y, - BOOL menu_bar, POPUPMENU *menu ) +static void calc_menu_item_size( HDC hdc, struct menu_item *item, HWND owner, INT org_x, INT org_y, + BOOL menu_bar, struct menu *menu ) { UINT check_bitmap_width = get_system_metrics( SM_CXMENUCHECK ); UINT arrow_bitmap_width; @@ -2070,11 +2115,11 @@ static void calc_menu_item_size( HDC hdc, MENUITEM *item, HWND owner, INT org_x, }
/* Calculate the size of the menu bar */ -static void calc_menu_bar_size( HDC hdc, RECT *rect, POPUPMENU *menu, HWND owner ) +static void calc_menu_bar_size( HDC hdc, RECT *rect, struct menu *menu, HWND owner ) { UINT start, i, help_pos; int org_x, org_y; - MENUITEM *item; + struct menu_item *item;
if (!rect || !menu || !menu->nItems) return;
@@ -2136,7 +2181,7 @@ static void calc_menu_bar_size( HDC hdc, RECT *rect, POPUPMENU *menu, HWND owner
UINT get_menu_bar_height( HWND hwnd, UINT width, INT org_x, INT org_y ) { - POPUPMENU *menu; + struct menu *menu; RECT rect_bar; HDC hdc;
@@ -2165,8 +2210,8 @@ static void draw_popup_arrow( HDC hdc, RECT rect, UINT arrow_width, UINT arrow_h NtGdiDeleteObjectApp( mem_hdc ); }
-static void draw_bitmap_item( HDC hdc, MENUITEM *item, const RECT *rect, - POPUPMENU *menu, HWND owner, UINT odaction ) +static void draw_bitmap_item( HDC hdc, struct menu_item *item, const RECT *rect, + struct menu *menu, HWND owner, UINT odaction ) { int w = rect->right - rect->left; int h = rect->bottom - rect->top; @@ -2300,8 +2345,8 @@ got_bitmap: }
/* Draw a single menu item */ -static void draw_menu_item( HWND hwnd, POPUPMENU *menu, HWND owner, HDC hdc, - MENUITEM *item, BOOL menu_bar, UINT odaction ) +static void draw_menu_item( HWND hwnd, struct menu *menu, HWND owner, HDC hdc, + struct menu_item *item, BOOL menu_bar, UINT odaction ) { UINT arrow_width = 0, arrow_height = 0; HRGN old_clip = NULL, clip; @@ -2655,7 +2700,7 @@ DWORD WINAPI NtUserDrawMenuBarTemp( HWND hwnd, HDC hdc, RECT *rect, HMENU handle { BOOL flat_menu = FALSE; HFONT prev_font = 0; - POPUPMENU *menu; + struct menu *menu; UINT i, retvalue;
NtUserSystemParametersInfo( SPI_GETFLATMENU, 0, &flat_menu, 0 ); @@ -2696,7 +2741,7 @@ DWORD WINAPI NtUserDrawMenuBarTemp( HWND hwnd, HDC hdc, RECT *rect, HMENU handle return retvalue; }
-static UINT get_scroll_arrow_height( const POPUPMENU *menu ) +static UINT get_scroll_arrow_height( const struct menu *menu ) { return menucharsize.cy + 4; } @@ -2738,7 +2783,7 @@ static void draw_scroll_arrow( HDC hdc, int x, int top, int height, BOOL up, BOO } }
-static void draw_scroll_arrows( const POPUPMENU *menu, HDC hdc ) +static void draw_scroll_arrows( const struct menu *menu, HDC hdc ) { UINT full_height = get_scroll_arrow_height( menu ); UINT arrow_height = full_height / 3; @@ -2770,7 +2815,7 @@ static int frame_rect( HDC hdc, const RECT *rect, HBRUSH hbrush ) static void draw_popup_menu( HWND hwnd, HDC hdc, HMENU hmenu ) { HBRUSH prev_hrush, brush = get_sys_color_brush( COLOR_MENU ); - POPUPMENU *menu = unsafe_menu_ptr( hmenu ); + struct menu *menu = unsafe_menu_ptr( hmenu ); RECT rect;
TRACE( "wnd=%p dc=%p menu=%p\n", hwnd, hdc, hmenu ); @@ -2802,7 +2847,7 @@ static void draw_popup_menu( HWND hwnd, HDC hdc, HMENU hmenu ) /* draw menu items */ if (menu->nItems) { - MENUITEM *item; + struct menu_item *item; UINT u;
item = menu->items; @@ -2887,11 +2932,11 @@ HWND is_menu_active(void) }
/* Calculate the size of a popup menu */ -static void calc_popup_menu_size( POPUPMENU *menu, UINT max_height ) +static void calc_popup_menu_size( struct menu *menu, UINT max_height ) { BOOL textandbmp = FALSE, multi_col = FALSE; int org_x, org_y, max_tab, max_tab_width; - MENUITEM *item; + struct menu_item *item; UINT start, i; HDC hdc;
@@ -2983,7 +3028,7 @@ static void calc_popup_menu_size( POPUPMENU *menu, UINT max_height ) static BOOL show_popup( HWND owner, HMENU hmenu, UINT id, UINT flags, int x, int y, INT xanchor, INT yanchor ) { - POPUPMENU *menu; + struct menu *menu; HMONITOR monitor; MONITORINFO info; UINT max_height; @@ -3048,11 +3093,11 @@ static BOOL show_popup( HWND owner, HMENU hmenu, UINT id, UINT flags, return TRUE; }
-static void ensure_menu_item_visible( POPUPMENU *menu, UINT index, HDC hdc ) +static void ensure_menu_item_visible( struct menu *menu, UINT index, HDC hdc ) { if (menu->bScrolling) { - MENUITEM *item = &menu->items[index]; + struct menu_item *item = &menu->items[index]; UINT prev_pos = menu->nScrollPos; const RECT *rc = &menu->items_rect; UINT scroll_height = rc->bottom - rc->top; @@ -3093,7 +3138,7 @@ static void ensure_menu_item_visible( POPUPMENU *menu, UINT index, HDC hdc )
static void select_item( HWND owner, HMENU hmenu, UINT index, BOOL send_select, HMENU topmenu ) { - POPUPMENU *menu; + struct menu *menu; HDC hdc;
TRACE( "owner %p menu %p index 0x%04x select 0x%04x\n", owner, hmenu, index, send_select ); @@ -3133,7 +3178,7 @@ static void select_item( HWND owner, HMENU hmenu, UINT index, BOOL send_select, } if (send_select) { - MENUITEM *ip = &menu->items[menu->FocusedItem]; + struct menu_item *ip = &menu->items[menu->FocusedItem]; send_message( owner, WM_MENUSELECT, MAKEWPARAM( ip->fType & MF_POPUP ? index: ip->wID, ip->fType | ip->fState | (menu->wFlags & MF_SYSMENU) ), @@ -3147,8 +3192,8 @@ static void select_item( HWND owner, HMENU hmenu, UINT index, BOOL send_select, int pos = find_submenu( &topmenu, hmenu ); if (pos != NO_SELECTED_ITEM) { - POPUPMENU *ptm = unsafe_menu_ptr( topmenu ); - MENUITEM *ip = &ptm->items[pos]; + struct menu *ptm = unsafe_menu_ptr( topmenu ); + struct menu_item *ip = &ptm->items[pos]; send_message( owner, WM_MENUSELECT, MAKEWPARAM( pos, ip->fType | ip->fState | (ptm->wFlags & MF_SYSMENU) ), (LPARAM)topmenu ); @@ -3167,7 +3212,7 @@ static void select_item( HWND owner, HMENU hmenu, UINT index, BOOL send_select, */ static void move_selection( HWND owner, HMENU hmenu, INT offset ) { - POPUPMENU *menu; + struct menu *menu; int i;
TRACE( "hwnd %p hmenu %p off 0x%04x\n", owner, hmenu, offset ); @@ -3196,14 +3241,14 @@ static void move_selection( HWND owner, HMENU hmenu, INT offset )
static void hide_sub_popups( HWND owner, HMENU hmenu, BOOL send_select, UINT flags ) { - POPUPMENU *menu = unsafe_menu_ptr( hmenu ); + struct menu *menu = unsafe_menu_ptr( hmenu );
TRACE( "owner=%p hmenu=%p 0x%04x\n", owner, hmenu, send_select );
if (menu && top_popup) { - POPUPMENU *submenu; - MENUITEM *item; + struct menu *submenu; + struct menu_item *item; HMENU hsubmenu;
if (menu->FocusedItem == NO_SELECTED_ITEM) return; @@ -3250,7 +3295,7 @@ static BOOL init_popup( HWND owner, HMENU hmenu, UINT flags ) { UNICODE_STRING class_name = { .Buffer = MAKEINTRESOURCEW( POPUPMENU_CLASS_ATOM ) }; DWORD ex_style = 0; - POPUPMENU *menu; + struct menu *menu;
TRACE( "owner %p hmenu %p\n", owner, hmenu );
@@ -3283,8 +3328,8 @@ static BOOL init_popup( HWND owner, HMENU hmenu, UINT flags ) */ static HMENU show_sub_popup( HWND owner, HMENU hmenu, BOOL select_first, UINT flags ) { - POPUPMENU *menu; - MENUITEM *item; + struct menu *menu; + struct menu_item *item; RECT rect; HDC hdc;
@@ -3385,8 +3430,8 @@ static HMENU show_sub_popup( HWND owner, HMENU hmenu, BOOL select_first, UINT fl */ static INT exec_focused_item( MTRACKER *pmt, HMENU handle, UINT flags ) { - MENUITEM *item; - POPUPMENU *menu = unsafe_menu_ptr( handle ); + struct menu_item *item; + struct menu *menu = unsafe_menu_ptr( handle );
TRACE( "%p hmenu=%p\n", pmt, handle );
@@ -3414,7 +3459,7 @@ static INT exec_focused_item( MTRACKER *pmt, HMENU handle, UINT flags ) MAKELPARAM( (INT16)pmt->pt.x, (INT16)pmt->pt.y )); else { - POPUPMENU *topmenu = unsafe_menu_ptr( pmt->hTopMenu ); + struct menu *topmenu = unsafe_menu_ptr( pmt->hTopMenu ); DWORD style = menu->dwStyle | (topmenu ? topmenu->dwStyle : 0);
if (style & MNS_NOTIFYBYPOS) @@ -3435,8 +3480,8 @@ static INT exec_focused_item( MTRACKER *pmt, HMENU handle, UINT flags ) */ static void switch_tracking( MTRACKER *pmt, HMENU pt_menu, UINT id, UINT flags ) { - POPUPMENU *ptmenu = unsafe_menu_ptr( pt_menu ); - POPUPMENU *topmenu = unsafe_menu_ptr( pmt->hTopMenu ); + struct menu *ptmenu = unsafe_menu_ptr( pt_menu ); + struct menu *topmenu = unsafe_menu_ptr( pmt->hTopMenu );
TRACE( "%p hmenu=%p 0x%04x\n", pmt, pt_menu, id );
@@ -3462,7 +3507,7 @@ static BOOL menu_button_down( MTRACKER *pmt, UINT message, HMENU pt_menu, UINT f
if (pt_menu) { - POPUPMENU *ptmenu = unsafe_menu_ptr( pt_menu ); + struct menu *ptmenu = unsafe_menu_ptr( pt_menu ); enum hittest ht = ht_item; UINT pos;
@@ -3505,7 +3550,7 @@ static INT menu_button_up( MTRACKER *pmt, HMENU pt_menu, UINT flags )
if (pt_menu) { - POPUPMENU *ptmenu = unsafe_menu_ptr( pt_menu ); + struct menu *ptmenu = unsafe_menu_ptr( pt_menu ); UINT pos;
if (IS_SYSTEM_MENU( ptmenu )) @@ -3548,7 +3593,7 @@ static INT menu_button_up( MTRACKER *pmt, HMENU pt_menu, UINT flags ) */ void end_menu( HWND hwnd ) { - POPUPMENU *menu; + struct menu *menu; BOOL call_end = FALSE; if (top_popup_hmenu && (menu = grab_menu_ptr( top_popup_hmenu ))) { @@ -3566,7 +3611,7 @@ void end_menu( HWND hwnd ) static BOOL menu_mouse_move( MTRACKER* pmt, HMENU pt_menu, UINT flags ) { UINT id = NO_SELECTED_ITEM; - POPUPMENU *ptmenu = NULL; + struct menu *ptmenu = NULL;
if (pt_menu) { @@ -3591,7 +3636,7 @@ static BOOL menu_mouse_move( MTRACKER* pmt, HMENU pt_menu, UINT flags )
static LRESULT do_next_menu( MTRACKER *pmt, UINT vk, UINT flags ) { - POPUPMENU *menu = unsafe_menu_ptr( pmt->hTopMenu ); + struct menu *menu = unsafe_menu_ptr( pmt->hTopMenu ); BOOL at_end = FALSE;
if (vk == VK_LEFT && menu->FocusedItem == 0) @@ -3713,8 +3758,8 @@ static LRESULT do_next_menu( MTRACKER *pmt, UINT vk, UINT flags ) */ static HMENU get_sub_popup( HMENU hmenu ) { - POPUPMENU *menu; - MENUITEM *item; + struct menu *menu; + struct menu_item *item;
menu = unsafe_menu_ptr( hmenu );
@@ -3737,7 +3782,7 @@ static BOOL menu_key_escape( MTRACKER *pmt, UINT flags )
if (pmt->hCurrentMenu != pmt->hTopMenu) { - POPUPMENU *menu = unsafe_menu_ptr( pmt->hCurrentMenu ); + struct menu *menu = unsafe_menu_ptr( pmt->hCurrentMenu );
if (menu->wFlags & MF_POPUP) { @@ -3763,7 +3808,7 @@ static BOOL menu_key_escape( MTRACKER *pmt, UINT flags )
static UINT get_start_of_next_column( HMENU handle ) { - POPUPMENU *menu = unsafe_menu_ptr( handle ); + struct menu *menu = unsafe_menu_ptr( handle ); UINT i;
if (!menu) return NO_SELECTED_ITEM; @@ -3783,7 +3828,7 @@ static UINT get_start_of_next_column( HMENU handle )
static UINT get_start_of_prev_column( HMENU handle ) { - POPUPMENU *menu = unsafe_menu_ptr( handle ); + struct menu *menu = unsafe_menu_ptr( handle ); UINT i;
if (!menu) return NO_SELECTED_ITEM; @@ -3843,7 +3888,7 @@ static BOOL suspend_popup( MTRACKER *pmt, UINT message )
static void menu_key_left( MTRACKER *pmt, UINT flags, UINT msg ) { - POPUPMENU *menu; + struct menu *menu; HMENU tmp_menu, prev_menu; UINT prevcol;
@@ -3885,7 +3930,7 @@ static void menu_key_left( MTRACKER *pmt, UINT flags, UINT msg )
static void menu_right_key( MTRACKER *pmt, UINT flags, UINT msg ) { - POPUPMENU *menu = unsafe_menu_ptr( pmt->hTopMenu ); + struct menu *menu = unsafe_menu_ptr( pmt->hTopMenu ); HMENU tmp_menu; UINT nextcol;
@@ -3937,7 +3982,7 @@ static void menu_right_key( MTRACKER *pmt, UINT flags, UINT msg ) */ static HMENU menu_from_point( HMENU handle, POINT pt ) { - POPUPMENU *menu = unsafe_menu_ptr( handle ); + struct menu *menu = unsafe_menu_ptr( handle ); UINT item = menu->FocusedItem; HMENU ret = 0;
@@ -3975,8 +4020,8 @@ static UINT find_item_by_key( HWND owner, HMENU hmenu, WCHAR key, BOOL force_men
if (hmenu) { - POPUPMENU *menu = unsafe_menu_ptr( hmenu ); - MENUITEM *item = menu->items; + struct menu *menu = unsafe_menu_ptr( hmenu ); + struct menu_item *item = menu->items; LRESULT menuchar;
if (!force_menu_char) @@ -4020,7 +4065,7 @@ static BOOL track_menu_impl( HMENU hmenu, UINT flags, int x, int y, HWND hwnd, c BOOL enter_idle_sent = FALSE; int executed_menu_id = -1; HWND capture_win; - POPUPMENU *menu; + struct menu *menu; BOOL remove; MTRACKER mt; MSG msg; @@ -4331,7 +4376,7 @@ static BOOL track_menu( HMENU handle, UINT flags, int x, int y, HWND hwnd, const
static BOOL init_tracking( HWND hwnd, HMENU handle, BOOL is_popup, UINT flags ) { - POPUPMENU *menu; + struct menu *menu;
TRACE( "hwnd=%p hmenu=%p\n", hwnd, handle );
@@ -4461,7 +4506,7 @@ track_menu: BOOL WINAPI NtUserTrackPopupMenuEx( HMENU handle, UINT flags, INT x, INT y, HWND hwnd, TPMPARAMS *params ) { - POPUPMENU *menu; + struct menu *menu; BOOL ret = FALSE;
TRACE( "hmenu %p flags %04x (%d,%d) hwnd %p params %p rect %s\n", @@ -4519,7 +4564,7 @@ BOOL WINAPI NtUserHiliteMenuItem( HWND hwnd, HMENU handle, UINT item, UINT hilit { HMENU handle_menu; UINT focused_item; - POPUPMENU *menu; + struct menu *menu; UINT pos;
TRACE( "(%p, %p, %04x, %04x);\n", hwnd, handle, item, hilite ); @@ -4544,7 +4589,7 @@ BOOL WINAPI NtUserHiliteMenuItem( HWND hwnd, HMENU handle, UINT item, UINT hilit BOOL WINAPI NtUserGetMenuBarInfo( HWND hwnd, LONG id, LONG item, MENUBARINFO *info ) { HMENU hmenu = NULL; - POPUPMENU *menu; + struct menu *menu; ATOM class_atom;
TRACE( "(%p,0x%08x,0x%08x,%p)\n", hwnd, id, item, info ); @@ -4613,7 +4658,7 @@ BOOL WINAPI NtUserGetMenuBarInfo( HWND hwnd, LONG id, LONG item, MENUBARINFO *in info->fFocused = menu->FocusedItem == item - 1; if (info->fFocused && (menu->items[item - 1].fType & MF_POPUP)) { - POPUPMENU *hwnd_menu = grab_menu_ptr( menu->items[item - 1].hSubMenu ); + struct menu *hwnd_menu = grab_menu_ptr( menu->items[item - 1].hSubMenu ); if (hwnd_menu) { info->hwndMenu = hwnd_menu->hWnd; diff --git a/dlls/win32u/ntuser_private.h b/dlls/win32u/ntuser_private.h index a5b77a85396..fd70c022c6f 100644 --- a/dlls/win32u/ntuser_private.h +++ b/dlls/win32u/ntuser_private.h @@ -205,55 +205,6 @@ enum builtin_winprocs NB_BUILTIN_AW_WINPROCS = WINPROC_DESKTOP };
-/* FIXME: make it private to menu.c */ - -/* Menu item structure */ -typedef struct menu_item -{ - /* ----------- MENUITEMINFO Stuff ----------- */ - UINT fType; /* Item type. */ - UINT fState; /* Item state. */ - UINT_PTR wID; /* Item id. */ - HMENU hSubMenu; /* Pop-up menu. */ - HBITMAP hCheckBit; /* Bitmap when checked. */ - HBITMAP hUnCheckBit; /* Bitmap when unchecked. */ - LPWSTR text; /* Item text. */ - ULONG_PTR dwItemData; /* Application defined. */ - LPWSTR dwTypeData; /* depends on fMask */ - HBITMAP hbmpItem; /* bitmap */ - /* ----------- Wine stuff ----------- */ - RECT rect; /* Item area (relative to the items_rect), - * see MENU_AdjustMenuItemRect(). */ - UINT xTab; /* X position of text after Tab */ - SIZE bmpsize; /* size needed for the HBMMENU_CALLBACK bitmap */ -} MENUITEM; - -typedef struct -{ - struct user_object obj; - WORD wFlags; /* Menu flags (MF_POPUP, MF_SYSMENU) */ - WORD Width; /* Width of the whole menu */ - WORD Height; /* Height of the whole menu */ - UINT nItems; /* Number of items in the menu */ - HWND hWnd; /* Window containing the menu */ - struct menu_item *items; /* Array of menu items */ - UINT FocusedItem; /* Currently focused item */ - HWND hwndOwner; /* window receiving the messages for ownerdraw */ - BOOL bScrolling; /* Scroll arrows are active */ - UINT nScrollPos; /* Current scroll position */ - UINT nTotalHeight; /* Total height of menu items inside menu */ - RECT items_rect; /* Rectangle within which the items lie. Excludes margins and scroll arrows */ - LONG refcount; - /* ------------ MENUINFO members ------ */ - DWORD dwStyle; /* Extended menu style */ - UINT cyMax; /* max height of the whole menu, 0 is screen height */ - HBRUSH hbrBack; /* brush for menu background */ - DWORD dwContextHelpID; - ULONG_PTR dwMenuData; /* application defined value */ - HMENU hSysMenuOwner; /* Handle to the dummy sys menu holder */ - WORD textOffset; /* Offset of text when items have both bitmaps and text */ -} POPUPMENU, *LPPOPUPMENU; - /* FIXME: make it private to class.c */ typedef struct tagWINDOWPROC {
From: Jacek Caban jacek@codeweavers.com
--- dlls/user32/sysparams.c | 19 ------------------- dlls/user32/win.c | 37 ++++++++++++------------------------- dlls/user32/win.h | 9 +-------- 3 files changed, 13 insertions(+), 52 deletions(-)
diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c index 738186afb89..26259ab76e9 100644 --- a/dlls/user32/sysparams.c +++ b/dlls/user32/sysparams.c @@ -669,15 +669,6 @@ BOOL WINAPI EnumDisplaySettingsExW( const WCHAR *device, DWORD mode, return NtUserEnumDisplaySettings( &str, mode, dev_mode, flags ); }
-/********************************************************************** - * get_monitor_dpi - */ -UINT get_monitor_dpi( HMONITOR monitor ) -{ - /* FIXME: use the monitor DPI instead */ - return system_dpi; -} - /********************************************************************** * get_win_monitor_dpi */ @@ -729,16 +720,6 @@ static POINT point_phys_to_win_dpi( HWND hwnd, POINT pt ) return map_dpi_point( pt, get_win_monitor_dpi( hwnd ), GetDpiForWindow( hwnd )); }
-/********************************************************************** - * point_win_to_thread_dpi - */ -POINT point_win_to_thread_dpi( HWND hwnd, POINT pt ) -{ - UINT dpi = get_thread_dpi(); - if (!dpi) dpi = get_win_monitor_dpi( hwnd ); - return map_dpi_point( pt, GetDpiForWindow( hwnd ), dpi ); -} - /********************************************************************** * map_dpi_rect */ diff --git a/dlls/user32/win.c b/dlls/user32/win.c index 9d19376fe44..d1b25da0e68 100644 --- a/dlls/user32/win.c +++ b/dlls/user32/win.c @@ -37,25 +37,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(win);
-/*********************************************************************** - * get_user_handle_ptr - */ -void *get_user_handle_ptr( HANDLE handle, unsigned int type ) -{ - return (void *)NtUserCallTwoParam( HandleToUlong(handle), type, NtUserGetHandlePtr ); -} - - -/*********************************************************************** - * release_user_handle_ptr - */ -void release_user_handle_ptr( void *ptr ) -{ - assert( ptr && ptr != OBJ_OTHER_PROCESS ); - NtUserCallOneParam( 1, NtUserLock ); -} - - /******************************************************************* * list_window_children * @@ -149,16 +130,22 @@ BOOL is_desktop_window( HWND hwnd ) */ WND *WIN_GetPtr( HWND hwnd ) { - WND *ptr; - - if ((ptr = get_user_handle_ptr( hwnd, NTUSER_OBJ_WINDOW )) == WND_OTHER_PROCESS) - { - if (is_desktop_window( hwnd )) ptr = WND_DESKTOP; - } + WND *ptr = (void *)NtUserCallTwoParam( HandleToUlong(hwnd), NTUSER_OBJ_WINDOW, NtUserGetHandlePtr ); + if (ptr == WND_OTHER_PROCESS && is_desktop_window( hwnd )) ptr = WND_DESKTOP; return ptr; }
+/*********************************************************************** + * WIN_ReleasePtr + */ +void WIN_ReleasePtr( WND *ptr ) +{ + assert( ptr && ptr != OBJ_OTHER_PROCESS ); + NtUserCallOneParam( 1, NtUserLock ); +} + + /*********************************************************************** * WIN_IsCurrentProcess * diff --git a/dlls/user32/win.h b/dlls/user32/win.h index bce93617d3f..59a7e0e2e38 100644 --- a/dlls/user32/win.h +++ b/dlls/user32/win.h @@ -37,6 +37,7 @@ struct tagDIALOGINFO; extern HWND get_hwnd_message_parent(void) DECLSPEC_HIDDEN; extern BOOL is_desktop_window( HWND hwnd ) DECLSPEC_HIDDEN; extern WND *WIN_GetPtr( HWND hwnd ) DECLSPEC_HIDDEN; +extern void WIN_ReleasePtr( WND *ptr ) DECLSPEC_HIDDEN; extern HWND WIN_GetFullHandle( HWND hwnd ) DECLSPEC_HIDDEN; extern HWND WIN_IsCurrentProcess( HWND hwnd ) DECLSPEC_HIDDEN; extern HWND WIN_IsCurrentThread( HWND hwnd ) DECLSPEC_HIDDEN; @@ -48,20 +49,12 @@ extern HWND *WIN_ListChildren( HWND hwnd ) DECLSPEC_HIDDEN; extern void MDI_CalcDefaultChildPos( HWND hwndClient, INT total, LPPOINT lpPos, INT delta, UINT *id ) DECLSPEC_HIDDEN; extern HDESK open_winstation_desktop( HWINSTA hwinsta, LPCWSTR name, DWORD flags, BOOL inherit, ACCESS_MASK access ) DECLSPEC_HIDDEN;
-/* to release pointers retrieved by WIN_GetPtr */ -static inline void WIN_ReleasePtr( WND *ptr ) -{ - release_user_handle_ptr( ptr ); -} - extern void WINPOS_ActivateOtherWindow( HWND hwnd ) DECLSPEC_HIDDEN;
-extern UINT get_monitor_dpi( HMONITOR monitor ) DECLSPEC_HIDDEN; extern UINT get_win_monitor_dpi( HWND hwnd ) DECLSPEC_HIDDEN; extern UINT get_thread_dpi(void) DECLSPEC_HIDDEN; extern POINT map_dpi_point( POINT pt, UINT dpi_from, UINT dpi_to ) DECLSPEC_HIDDEN; extern POINT point_win_to_phys_dpi( HWND hwnd, POINT pt ) DECLSPEC_HIDDEN; -extern POINT point_win_to_thread_dpi( HWND hwnd, POINT pt ) DECLSPEC_HIDDEN; extern RECT map_dpi_rect( RECT rect, UINT dpi_from, UINT dpi_to ) DECLSPEC_HIDDEN; extern RECT rect_win_to_thread_dpi( HWND hwnd, RECT rect ) DECLSPEC_HIDDEN;
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=117682
Your paranoid android.
=== debian11 (64 bit WoW report) ===
user32: winstation.c:971: Test failed: unexpected foreground window 0000000000010020
I've pushed v2 which removes a few tabs.
This merge request was approved by Huw Davies.