+
+#endif
+
+ gtk_signal_connect( GTK_OBJECT(menu->m_owner), "activate",
+ GTK_SIGNAL_FUNC(gtk_menu_open_callback),
+ (gpointer)menu );
+
+ // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
+ // addings menu later on.
+ if (m_invokingWindow)
+ {
+ wxMenubarSetInvokingWindow( menu, m_invokingWindow );
+
+ // OPTIMISE ME: we should probably cache this, or pass it
+ // directly, but for now this is a minimal
+ // change to validate the new dynamic sizing.
+ // see (and refactor :) similar code in Remove
+ // below.
+
+ wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame );
+
+ if( frame )
+ frame->UpdateMenuBarSize();
+ }
+
+ return TRUE;
+}
+
+bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
+{
+ if ( !wxMenuBarBase::Insert(pos, menu, title) )
+ return FALSE;
+
+ // GTK+ doesn't have a function to insert a menu using GtkItemFactory (as
+ // of version 1.2.6), so we first append the item and then change its
+ // index
+ if ( !GtkAppend(menu, title) )
+ return FALSE;
+
+ if (pos+1 >= m_menus.GetCount())
+ return TRUE;
+
+ GtkMenuShell *menu_shell = GTK_MENU_SHELL(m_factory->widget);
+ gpointer data = g_list_last(menu_shell->children)->data;
+ menu_shell->children = g_list_remove(menu_shell->children, data);
+ menu_shell->children = g_list_insert(menu_shell->children, data, pos);
+
+ return TRUE;
+}
+
+wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
+{
+ // remove the old item and insert a new one
+ wxMenu *menuOld = Remove(pos);
+ if ( menuOld && !Insert(pos, menu, title) )
+ {
+ return (wxMenu*) NULL;
+ }
+
+ // either Insert() succeeded or Remove() failed and menuOld is NULL
+ return menuOld;
+}
+
+static wxMenu *CopyMenu (wxMenu *menu)
+{
+ wxMenu *menucopy = new wxMenu ();
+ wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
+ while (node)
+ {
+ wxMenuItem *item = node->GetData();
+ int itemid = item->GetId();
+ wxString text = item->GetText();
+ text.Replace(wxT("_"), wxT("&"));
+ wxMenu *submenu = item->GetSubMenu();
+ if (!submenu)
+ {
+ wxMenuItem* itemcopy = new wxMenuItem(menucopy,
+ itemid, text,
+ menu->GetHelpString(itemid));
+ itemcopy->SetBitmap(item->GetBitmap());
+ itemcopy->SetCheckable(item->IsCheckable());
+ menucopy->Append(itemcopy);
+ }
+ else
+ menucopy->Append (itemid, text, CopyMenu(submenu),
+ menu->GetHelpString(itemid));
+
+ node = node->GetNext();
+ }
+
+ return menucopy;
+}
+
+wxMenu *wxMenuBar::Remove(size_t pos)
+{
+ wxMenu *menu = wxMenuBarBase::Remove(pos);
+ if ( !menu )
+ return (wxMenu*) NULL;
+
+/*
+ GtkMenuShell *menu_shell = GTK_MENU_SHELL(m_factory->widget);
+
+ printf( "factory entries before %d\n", (int)g_slist_length(m_factory->items) );
+ printf( "menu shell entries before %d\n", (int)g_list_length( menu_shell->children ) );
+*/
+
+ wxMenu *menucopy = CopyMenu( menu );
+
+ // unparent calls unref() and that would delete the widget so we raise
+ // the ref count to 2 artificially before invoking unparent.
+ gtk_widget_ref( menu->m_menu );
+ gtk_widget_unparent( menu->m_menu );
+
+ gtk_widget_destroy( menu->m_owner );
+ delete menu;
+
+ menu = menucopy;
+/*
+ printf( "factory entries after %d\n", (int)g_slist_length(m_factory->items) );
+ printf( "menu shell entries after %d\n", (int)g_list_length( menu_shell->children ) );
+*/
+
+ if (m_invokingWindow)
+ {
+ // OPTIMISE ME: see comment in GtkAppend
+
+ wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame );
+
+ if( frame )
+ frame->UpdateMenuBarSize();
+ }
+
+ return menu;