]> git.saurik.com Git - wxWidgets.git/commitdiff
flatten the single item submenus under Maemo
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 12 Nov 2007 20:55:18 +0000 (20:55 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 12 Nov 2007 20:55:18 +0000 (20:55 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49871 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/gtk/menu.cpp

index 7f04189b925a1cd22920a753460131a0574845c8..1262d32ec10f9f3f7438368808f7be31d5725b97 100644 (file)
@@ -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 );