X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/589c9fff0437340c1816363e39e9854f3eb49e78..f5ba273ecd799f652736ce2bc830283787302a56:/src/gtk/menu.cpp diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 8f5de087be..3aff75731f 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -78,7 +78,7 @@ wxMenuBar::wxMenuBar( long style ) } PostCreation(); - + ApplyWidgetStyle(); } @@ -110,7 +110,7 @@ wxMenuBar::wxMenuBar() m_widget = GTK_WIDGET(m_menubar); PostCreation(); - + ApplyWidgetStyle(); } @@ -146,13 +146,15 @@ static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ) { menu->SetInvokingWindow( win ); -#if (GTK_MINOR_VERSION > 0) +#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) wxWindow *top_frame = win; while (top_frame->GetParent() && !(top_frame->IsTopLevel())) top_frame = top_frame->GetParent(); /* support for native hot keys */ - gtk_accel_group_attach( menu->m_accel, GTK_OBJECT(top_frame->m_widget) ); + GtkObject *obj = GTK_OBJECT(top_frame->m_widget); + if ( !g_slist_find( menu->m_accel->attach_objects, obj ) ) + gtk_accel_group_attach( menu->m_accel, obj ); #endif wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); @@ -174,7 +176,9 @@ void wxMenuBar::SetInvokingWindow( wxWindow *win ) top_frame = top_frame->GetParent(); /* support for native key accelerators indicated by underscroes */ - gtk_accel_group_attach( m_accel, GTK_OBJECT(top_frame->m_widget) ); + GtkObject *obj = GTK_OBJECT(top_frame->m_widget); + if ( !g_slist_find( m_accel->attach_objects, obj ) ) + gtk_accel_group_attach( m_accel, obj ); #endif wxMenuList::Node *node = m_menus.GetFirst(); @@ -313,6 +317,9 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title) 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); @@ -331,9 +338,6 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title) wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title) { - if ( !wxMenuBarBase::Replace(pos, menu, title) ) - return (wxMenu*) NULL; - // remove the old item and insert a new one wxMenu *menuOld = Remove(pos); if ( menuOld && !Insert(pos, menu, title) ) @@ -351,25 +355,25 @@ wxMenu *wxMenuBar::Remove(size_t pos) if ( !menu ) return (wxMenu*) NULL; - GtkMenuShell *menu_shell = GTK_MENU_SHELL(m_factory->widget); /* + 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 ) ); */ - + // 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 ); - + /* 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 ) ); */ - + return menu; } @@ -489,7 +493,7 @@ void wxMenuBar::SetLabelTop( size_t pos, const wxString& label ) static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) { if (g_isIdle) wxapp_install_idle_handler(); - + int id = menu->FindMenuIdByMenuItem(widget); /* should find it for normal (not popup) menu */