From: Vadim Zeitlin Date: Mon, 12 Nov 2007 20:55:18 +0000 (+0000) Subject: flatten the single item submenus under Maemo X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6c76d1ce5928c3f463368e04fd8435d783f7b86d flatten the single item submenus under Maemo git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49871 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 7f04189b92..1262d32ec1 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -40,6 +40,8 @@ // we use normal item but with a special id for the menu title static const int wxGTK_TITLE_ID = -3; +extern "C" static void gtk_menu_clicked_callback(GtkWidget *widget, wxMenu *menu); + //----------------------------------------------------------------------------- // idle system //----------------------------------------------------------------------------- @@ -295,18 +297,42 @@ bool wxMenuBar::Append( wxMenu *menu, const wxString &title ) bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title, int pos) { - const wxString str(wxConvertMnemonicsToGTK(title)); + menu->SetLayoutDirection(GetLayoutDirection()); - // This doesn't have much effect right now. - menu->SetTitle( str ); +#if wxUSE_LIBHILDON + // if the menu has only one item, append it directly to the top level menu + // instead of inserting a useless submenu + if ( menu->GetMenuItemCount() == 1 ) + { + wxMenuItem * const item = menu->FindItemByPosition(0); - // The "m_owner" is the "menu item" - menu->m_owner = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str ) ); - menu->SetLayoutDirection(GetLayoutDirection()); + // remove both mnemonics and accelerator: neither is useful under Maemo + const wxString str(wxStripMenuCodes(item->GetItemLabel())); - gtk_widget_show( menu->m_owner ); + if ( item->IsSubMenu() ) + return GtkAppend(item->GetSubMenu(), str, pos); + + menu->m_owner = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str ) ); + + g_signal_connect(menu->m_owner, "activate", + G_CALLBACK(gtk_menu_clicked_callback), menu); + item->SetMenuItem(menu->m_owner); + } + else +#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON + { + const wxString str(wxConvertMnemonicsToGTK(title)); + + // This doesn't have much effect right now. + menu->SetTitle( str ); - gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); + // The "m_owner" is the "menu item" + menu->m_owner = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str ) ); + + gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); + } + + gtk_widget_show( menu->m_owner ); if (pos == -1) gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar), menu->m_owner );