X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9f855638c382770ac416068d1c4dcd356150f293..7fbc727b20f39088ddd5e5cf4b6aed930da69119:/src/msw/menu.cpp?ds=sidebyside diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index e4e5317d3d..4769e1b00b 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -397,8 +397,8 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) pos = GetMenuItemCount() - 1; } - // adjust position to account for the title, if any - if ( !m_title.empty() ) + // adjust position to account for the title of a popup menu, if any + if ( !GetMenuBar() && !m_title.empty() ) pos += 2; // for the title itself and its separator BOOL ok = false; @@ -885,6 +885,30 @@ bool wxMenu::MSWCommand(WXUINT WXUNUSED(param), WXWORD id_) return true; } +// get the menu with given handle (recursively) +wxMenu* wxMenu::MSWGetMenu(WXHMENU hMenu) +{ + // check self + if ( GetHMenu() == hMenu ) + return this; + + // recursively query submenus + for ( size_t n = 0 ; n < GetMenuItemCount(); ++n ) + { + wxMenuItem* item = FindItemByPosition(n); + wxMenu* submenu = item->GetSubMenu(); + if ( submenu ) + { + submenu = submenu->MSWGetMenu(hMenu); + if (submenu) + return submenu; + } + } + + // unknown hMenu + return NULL; +} + // --------------------------------------------------------------------------- // Menu Bar // --------------------------------------------------------------------------- @@ -1467,4 +1491,22 @@ void wxMenuBar::Detach() wxMenuBarBase::Detach(); } +// get the menu with given handle (recursively) +wxMenu* wxMenuBar::MSWGetMenu(WXHMENU hMenu) +{ + wxCHECK_MSG( GetHMenu() != hMenu, NULL, + wxT("wxMenuBar::MSWGetMenu(): menu handle is wxMenuBar, not wxMenu") ); + + // query all menus + for ( size_t n = 0 ; n < GetMenuCount(); ++n ) + { + wxMenu* menu = GetMenu(n)->MSWGetMenu(hMenu); + if ( menu ) + return menu; + } + + // unknown hMenu + return NULL; +} + #endif // wxUSE_MENUS