]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/menu.cpp
mac cgcolor changes
[wxWidgets.git] / src / gtk / menu.cpp
index 7f04189b925a1cd22920a753460131a0574845c8..e0f55864f58e8f15f58e3f754061b10092647c9b 100644 (file)
 // we use normal item but with a special id for the menu title
 static const int wxGTK_TITLE_ID = -3;
 
+// forward declare it as it's used by wxMenuBar too when using Hildon
+extern "C"
+{
+    static void gtk_menu_clicked_callback(GtkWidget *widget, wxMenu *menu);
+}
+
 //-----------------------------------------------------------------------------
 // idle system
 //-----------------------------------------------------------------------------
@@ -295,18 +301,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 ) );
 
-    gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu );
+        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 );
+
+        // 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 );