X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3b59cdbfaf7df79499424c92ff6177736429ff8a..2035e10e83324c6925d12725b842768f6e2b00a2:/src/gtk/menu.cpp diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index daff7c92be..12185fcd39 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,20 +355,25 @@ wxMenu *wxMenuBar::Remove(size_t 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 ) ); - +*/ + // 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; } @@ -484,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 */ @@ -632,9 +641,10 @@ wxString wxMenuItemBase::GetLabelFromText(const wxString& text) #if (GTK_MINOR_VERSION > 0) for ( const wxChar *pc = text.c_str(); *pc; pc++ ) { - if ( *pc == wxT('_') ) + if ( *pc == wxT('_') || *pc == wxT('&') ) { - // this is the escape character for GTK+ - skip it + // '_' is the escape character for GTK+ and '&' is the one for + // wxWindows - skip both of them continue; }