Fix accelerators in appended submenu items in wxGTK.

They were not previously taken into account because we didn't call
gtk_widget_add_accelerator() on the right GtkAccelGroup.

Closes #16050.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@76113 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-03-11 15:20:56 +00:00
parent 7f4969c9e2
commit de20880064
2 changed files with 36 additions and 2 deletions

View File

@@ -612,6 +612,7 @@ wxGTK:
- Fix wxStaticBoxSizer size calculation. - Fix wxStaticBoxSizer size calculation.
- Fix AUI panel re-docking. - Fix AUI panel re-docking.
- Add support for wxDD_DIR_MUST_EXIST to wxDirDialog. - Add support for wxDD_DIR_MUST_EXIST to wxDirDialog.
- Fix handling of the accelerators for sub menu items (Chaobin Zhang).
- Fix disappearing mouse clicks when using wxTreeCtrl. - Fix disappearing mouse clicks when using wxTreeCtrl.
- Fix calls to Move{Before,After}InTabOrder() after parent window creation. - Fix calls to Move{Before,After}InTabOrder() after parent window creation.

View File

@@ -86,6 +86,36 @@ static void DoCommonMenuCallbackCode(wxMenu *menu, wxMenuEvent& event)
win->HandleWindowEvent( event ); win->HandleWindowEvent( event );
} }
// Return the top level menu containing this menu (possibly this menu itself).
static wxMenu* GetRootParentMenu(wxMenu* menu)
{
while ( menu->GetParent() )
menu = menu->GetParent();
return menu;
}
// Call SetGtkLabel() to update the labels of all the items in this items sub
// menu, recursively.
static void UpdateSubMenuItemLabels(wxMenuItem* itemMenu)
{
wxMenu* const menu = itemMenu->GetSubMenu();
wxCHECK_RET( menu, "should only be called for sub menus" );
const wxMenuItemList& items = menu->GetMenuItems();
for ( wxMenuItemList::const_iterator
it = items.begin(); it != items.end(); ++it )
{
wxMenuItem* const item = *it;
if ( !item->IsSeparator() )
{
item->SetGtkLabel();
if ( item->IsSubMenu() )
UpdateSubMenuItemLabels(item);
}
}
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxMenuBar // wxMenuBar
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -658,7 +688,7 @@ void wxMenuItem::SetItemLabel( const wxString& str )
if (accel_key) if (accel_key)
{ {
gtk_widget_remove_accelerator( gtk_widget_remove_accelerator(
m_menuItem, m_parentMenu->m_accel, accel_key, accel_mods); m_menuItem, GetRootParentMenu(m_parentMenu)->m_accel, accel_key, accel_mods);
} }
} }
#endif // wxUSE_ACCEL #endif // wxUSE_ACCEL
@@ -679,7 +709,7 @@ void wxMenuItem::SetGtkLabel()
if (accel_key) if (accel_key)
{ {
gtk_widget_add_accelerator( gtk_widget_add_accelerator(
m_menuItem, "activate", m_parentMenu->m_accel, m_menuItem, "activate", GetRootParentMenu(m_parentMenu)->m_accel,
accel_key, accel_mods, GTK_ACCEL_VISIBLE); accel_key, accel_mods, GTK_ACCEL_VISIBLE);
} }
#endif // wxUSE_ACCEL #endif // wxUSE_ACCEL
@@ -931,6 +961,9 @@ void wxMenu::GtkAppend(wxMenuItem* mitem, int pos)
if ( !mitem->IsSeparator() ) if ( !mitem->IsSeparator() )
{ {
mitem->SetGtkLabel(); mitem->SetGtkLabel();
if ( mitem->IsSubMenu() )
UpdateSubMenuItemLabels(mitem);
g_signal_connect (menuItem, "select", g_signal_connect (menuItem, "select",
G_CALLBACK(menuitem_select), mitem); G_CALLBACK(menuitem_select), mitem);
g_signal_connect (menuItem, "deselect", g_signal_connect (menuItem, "deselect",