+ m_needParent = FALSE; // hmmm
+
+ PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, "menu" );
+
+ m_menus.DeleteContents( TRUE );
+
+ m_menubar = gtk_menu_bar_new();
+
+ if (style & wxMB_DOCKABLE)
+ {
+ m_widget = gtk_handle_box_new();
+ gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_menubar) );
+ gtk_widget_show( GTK_WIDGET(m_menubar) );
+ }
+ else
+ {
+ m_widget = GTK_WIDGET(m_menubar);
+ }
+
+ PostCreation();
+
+ Show( TRUE );
+}
+
+wxMenuBar::wxMenuBar()
+{
+ m_needParent = FALSE; // hmmm
+
+ PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, "menu" );
+
+ m_menus.DeleteContents( TRUE );
+
+ m_menubar = gtk_menu_bar_new();
+
+ m_widget = GTK_WIDGET(m_menubar);
+
+ PostCreation();
+
+ Show( TRUE );
+}
+
+void wxMenuBar::Append( wxMenu *menu, const wxString &title )
+{
+ m_menus.Append( menu );
+ menu->m_title = title;
+
+ int pos;
+ do
+ {
+ pos = menu->m_title.First( '&' );
+ if (pos != -1) menu->m_title.Remove( pos, 1 );
+ } while (pos != -1);
+
+ menu->m_owner = gtk_menu_item_new_with_label( WXSTRINGCAST(menu->m_title) );
+ gtk_widget_show( menu->m_owner );
+ gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu );
+
+ gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), menu->m_owner );
+}
+
+static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
+{
+ if (menu->m_title == menuString)
+ {
+ int res = menu->FindItem( itemString );
+ if (res != -1) return res;
+ }
+
+ wxNode *node = menu->m_items.First();
+ while (node)
+ {
+ wxMenuItem *item = (wxMenuItem*)node->Data();
+ if (item->IsSubMenu())
+ return FindMenuItemRecursive(item->GetSubMenu(), menuString, itemString);
+
+ node = node->Next();
+ }
+
+ return -1;
+}
+
+int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemString ) const
+{
+ wxNode *node = m_menus.First();
+ while (node)
+ {
+ wxMenu *menu = (wxMenu*)node->Data();
+ int res = FindMenuItemRecursive( menu, menuString, itemString);
+ if (res != -1) return res;
+ node = node->Next();
+ }
+ return -1;
+}
+
+/* Find a wxMenuItem using its id. Recurses down into sub-menus */
+static wxMenuItem* FindMenuItemByIdRecursive(const wxMenu* menu, int id)
+{
+ wxMenuItem* result = menu->FindItem(id);
+
+ wxNode *node = menu->m_items.First();
+ while ( node && result == NULL )
+ {
+ wxMenuItem *item = (wxMenuItem*)node->Data();
+ if (item->IsSubMenu())
+ {
+ result = FindMenuItemByIdRecursive( item->GetSubMenu(), id );
+ }
+ node = node->Next();
+ }
+
+ return result;
+}
+
+wxMenuItem* wxMenuBar::FindMenuItemById( int id ) const
+{
+ wxMenuItem* result = 0;
+ wxNode *node = m_menus.First();
+ while (node && result == 0)
+ {
+ wxMenu *menu = (wxMenu*)node->Data();
+ result = FindMenuItemByIdRecursive( menu, id );
+ node = node->Next();
+ }
+
+ return result;
+}
+
+void wxMenuBar::Check( int id, bool check )
+{
+ wxMenuItem* item = FindMenuItemById( id );
+ if (item) item->Check(check);
+}
+
+bool wxMenuBar::Checked( int id ) const
+{
+ wxMenuItem* item = FindMenuItemById( id );
+ if (item) return item->IsChecked();
+ return FALSE;
+}
+
+void wxMenuBar::Enable( int id, bool enable )
+{
+ wxMenuItem* item = FindMenuItemById( id );
+ if (item) item->Enable(enable);
+}
+
+bool wxMenuBar::Enabled( int id ) const
+{
+ wxMenuItem* item = FindMenuItemById( id );
+ if (item) return item->IsEnabled();
+
+ return FALSE;
+}