From 49826dabe6e238d9dd7c109fdf9fcc762ce2233d Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 22 Apr 2004 22:05:52 +0000 Subject: [PATCH] Fix wxGTK's menu and menubar so Insert does something other than always append. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26921 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/menu.h | 6 +++--- include/wx/gtk1/menu.h | 6 +++--- src/gtk/menu.cpp | 39 ++++++++++++++++++++++++++++----------- src/gtk1/menu.cpp | 39 ++++++++++++++++++++++++++++----------- 4 files changed, 62 insertions(+), 28 deletions(-) diff --git a/include/wx/gtk/menu.h b/include/wx/gtk/menu.h index 123f23b86b..a154a64e21 100644 --- a/include/wx/gtk/menu.h +++ b/include/wx/gtk/menu.h @@ -46,7 +46,7 @@ public: void UnsetInvokingWindow( wxWindow *win ); // common part of Append and Insert - bool GtkAppend(wxMenu *menu, const wxString& title); + bool GtkAppend(wxMenu *menu, const wxString& title, int pos=-1); #ifndef __WXGTK20__ GtkAccelGroup *m_accel; @@ -93,8 +93,8 @@ private: // common code for all constructors: void Init(); - // common part of Append and Insert - bool GtkAppend(wxMenuItem *item); + // common part of Append (if pos == -1) and Insert + bool GtkAppend(wxMenuItem *item, int pos=-1); GtkWidget *m_prevRadio; diff --git a/include/wx/gtk1/menu.h b/include/wx/gtk1/menu.h index 123f23b86b..a154a64e21 100644 --- a/include/wx/gtk1/menu.h +++ b/include/wx/gtk1/menu.h @@ -46,7 +46,7 @@ public: void UnsetInvokingWindow( wxWindow *win ); // common part of Append and Insert - bool GtkAppend(wxMenu *menu, const wxString& title); + bool GtkAppend(wxMenu *menu, const wxString& title, int pos=-1); #ifndef __WXGTK20__ GtkAccelGroup *m_accel; @@ -93,8 +93,8 @@ private: // common code for all constructors: void Init(); - // common part of Append and Insert - bool GtkAppend(wxMenuItem *item); + // common part of Append (if pos == -1) and Insert + bool GtkAppend(wxMenuItem *item, int pos=-1); GtkWidget *m_prevRadio; diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index f4d591fe98..c8c37a1fcb 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -330,7 +330,7 @@ bool wxMenuBar::Append( wxMenu *menu, const wxString &title ) return GtkAppend(menu, title); } -bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title) +bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title, int pos) { wxString str( wxReplaceUnderscore( title ) ); @@ -362,7 +362,10 @@ bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title) gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); - gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar), menu->m_owner ); + if (pos == -1) + gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar), menu->m_owner ); + else + gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar), menu->m_owner, pos ); gtk_signal_connect( GTK_OBJECT(menu->m_owner), "activate", GTK_SIGNAL_FUNC(gtk_menu_open_callback), @@ -396,7 +399,7 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title) // TODO - if ( !GtkAppend(menu, title) ) + if ( !GtkAppend(menu, title, (int)pos) ) return FALSE; return TRUE; @@ -1005,7 +1008,7 @@ wxMenu::~wxMenu() gtk_widget_destroy( m_menu ); } -bool wxMenu::GtkAppend(wxMenuItem *mitem) +bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos) { GtkWidget *menuItem; @@ -1017,8 +1020,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem) // TODO menuItem = gtk_menu_item_new(); #endif - gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); - + if (pos == -1) + gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); + else + gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos); } else if ( mitem->IsSubMenu() ) { @@ -1046,7 +1051,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem) #endif gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu ); - gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); + if (pos == -1) + gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); + else + gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos); gtk_widget_show( mitem->GetSubMenu()->m_menu ); @@ -1077,7 +1085,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem) GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), (gpointer)this ); - gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); + if (pos == -1) + gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); + else + gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos); #else menuItem = gtk_pixmap_menu_item_new (); @@ -1126,7 +1137,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem) GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), (gpointer)this ); - gtk_menu_append( GTK_MENU(m_menu), menuItem ); + if (pos == -1) + gtk_menu_append( GTK_MENU(m_menu), menuItem ); + else + gtk_menu_insert( GTK_MENU(m_menu), menuItem, pos ); gtk_widget_show( menuItem ); #endif @@ -1251,7 +1265,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem) GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), (gpointer)this ); - gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); + if (pos == -1) + gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); + else + gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos); } guint accel_key; @@ -1311,7 +1328,7 @@ wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item) return NULL; // TODO - if ( !GtkAppend(item) ) + if ( !GtkAppend(item, (int)pos) ) return NULL; return item; diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index f4d591fe98..c8c37a1fcb 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -330,7 +330,7 @@ bool wxMenuBar::Append( wxMenu *menu, const wxString &title ) return GtkAppend(menu, title); } -bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title) +bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title, int pos) { wxString str( wxReplaceUnderscore( title ) ); @@ -362,7 +362,10 @@ bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title) gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); - gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar), menu->m_owner ); + if (pos == -1) + gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar), menu->m_owner ); + else + gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar), menu->m_owner, pos ); gtk_signal_connect( GTK_OBJECT(menu->m_owner), "activate", GTK_SIGNAL_FUNC(gtk_menu_open_callback), @@ -396,7 +399,7 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title) // TODO - if ( !GtkAppend(menu, title) ) + if ( !GtkAppend(menu, title, (int)pos) ) return FALSE; return TRUE; @@ -1005,7 +1008,7 @@ wxMenu::~wxMenu() gtk_widget_destroy( m_menu ); } -bool wxMenu::GtkAppend(wxMenuItem *mitem) +bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos) { GtkWidget *menuItem; @@ -1017,8 +1020,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem) // TODO menuItem = gtk_menu_item_new(); #endif - gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); - + if (pos == -1) + gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); + else + gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos); } else if ( mitem->IsSubMenu() ) { @@ -1046,7 +1051,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem) #endif gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu ); - gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); + if (pos == -1) + gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); + else + gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos); gtk_widget_show( mitem->GetSubMenu()->m_menu ); @@ -1077,7 +1085,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem) GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), (gpointer)this ); - gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); + if (pos == -1) + gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); + else + gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos); #else menuItem = gtk_pixmap_menu_item_new (); @@ -1126,7 +1137,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem) GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), (gpointer)this ); - gtk_menu_append( GTK_MENU(m_menu), menuItem ); + if (pos == -1) + gtk_menu_append( GTK_MENU(m_menu), menuItem ); + else + gtk_menu_insert( GTK_MENU(m_menu), menuItem, pos ); gtk_widget_show( menuItem ); #endif @@ -1251,7 +1265,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem) GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), (gpointer)this ); - gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); + if (pos == -1) + gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem); + else + gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos); } guint accel_key; @@ -1311,7 +1328,7 @@ wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item) return NULL; // TODO - if ( !GtkAppend(item) ) + if ( !GtkAppend(item, (int)pos) ) return NULL; return item; -- 2.45.2