X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/32db328c7a66ab2c479e1b9dc567b74e0f23257e..79f585d90388128f9d245f7c92d3013b98b9ed14:/src/gtk1/menu.cpp diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index f5bdffe433..3aff75731f 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -78,6 +78,8 @@ wxMenuBar::wxMenuBar( long style ) } PostCreation(); + + ApplyWidgetStyle(); } wxMenuBar::wxMenuBar() @@ -108,6 +110,8 @@ wxMenuBar::wxMenuBar() m_widget = GTK_WIDGET(m_menubar); PostCreation(); + + ApplyWidgetStyle(); } wxMenuBar::~wxMenuBar() @@ -142,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(); @@ -170,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(); @@ -309,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); @@ -327,14 +338,11 @@ 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 FALSE; - // remove the old item and insert a new one wxMenu *menuOld = Remove(pos); if ( menuOld && !Insert(pos, menu, title) ) { - return NULL; + return (wxMenu*) NULL; } // either Insert() succeeded or Remove() failed and menuOld is NULL @@ -345,35 +353,28 @@ wxMenu *wxMenuBar::Remove(size_t pos) { wxMenu *menu = wxMenuBarBase::Remove(pos); if ( !menu ) - return FALSE; + return (wxMenu*) NULL; -#ifdef __WXGTK12__ - // gtk_item_factory_delete_entry() is buggy as of GTK+ 1.2.6, so don't use - // it but delete the widget manually instead - wxString path = _T("
/"), - title = menu->GetTitle(); - for ( const wxChar *p = title.c_str(); *p; p++ ) - { - if ( *p != _T('_') ) - path += *p; - } +/* + GtkMenuShell *menu_shell = GTK_MENU_SHELL(m_factory->widget); - GtkWidget *widget = gtk_item_factory_get_item(m_factory, path.mb_str()); - if ( widget ) - { - gtk_widget_destroy(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 ) ); +*/ - return 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 ); - // shouldn't happen (FIXME but does now) - wxFAIL_MSG( _T("gtk_item_factory_get_item() failed") ); -#else // GTK < 1.2 - // this should be very simple to implement - wxFAIL_MSG( wxT("TODO") ); -#endif // GTK 1.2/1.0 + 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 NULL; + return menu; } static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString ) @@ -633,11 +634,12 @@ wxMenuItem::~wxMenuItem() } // return the menu item text without any menu accels -wxString wxMenuItem::GetLabel() const +/* static */ +wxString wxMenuItemBase::GetLabelFromText(const wxString& text) { wxString label; #if (GTK_MINOR_VERSION > 0) - for ( const wxChar *pc = m_text.c_str(); *pc; pc++ ) + for ( const wxChar *pc = text.c_str(); *pc; pc++ ) { if ( *pc == wxT('_') ) { @@ -648,7 +650,7 @@ wxString wxMenuItem::GetLabel() const label += *pc; } #else // GTK+ 1.0 - label = m_text; + label = text; #endif // GTK+ 1.2/1.0 return label; @@ -963,9 +965,9 @@ bool wxMenu::DoInsert(size_t pos, wxMenuItem *item) #else // GTK < 1.2 // this should be easy to do... wxFAIL_MSG( wxT("not implemented") ); -#endif // GTK 1.2/1.0 return FALSE; +#endif // GTK 1.2/1.0 } wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)