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
This commit is contained in:
Robin Dunn
2004-04-22 22:05:52 +00:00
parent 57fbd4359a
commit 49826dabe6
4 changed files with 62 additions and 28 deletions

View File

@@ -46,7 +46,7 @@ public:
void UnsetInvokingWindow( wxWindow *win ); void UnsetInvokingWindow( wxWindow *win );
// common part of Append and Insert // 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__ #ifndef __WXGTK20__
GtkAccelGroup *m_accel; GtkAccelGroup *m_accel;
@@ -93,8 +93,8 @@ private:
// common code for all constructors: // common code for all constructors:
void Init(); void Init();
// common part of Append and Insert // common part of Append (if pos == -1) and Insert
bool GtkAppend(wxMenuItem *item); bool GtkAppend(wxMenuItem *item, int pos=-1);
GtkWidget *m_prevRadio; GtkWidget *m_prevRadio;

View File

@@ -46,7 +46,7 @@ public:
void UnsetInvokingWindow( wxWindow *win ); void UnsetInvokingWindow( wxWindow *win );
// common part of Append and Insert // 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__ #ifndef __WXGTK20__
GtkAccelGroup *m_accel; GtkAccelGroup *m_accel;
@@ -93,8 +93,8 @@ private:
// common code for all constructors: // common code for all constructors:
void Init(); void Init();
// common part of Append and Insert // common part of Append (if pos == -1) and Insert
bool GtkAppend(wxMenuItem *item); bool GtkAppend(wxMenuItem *item, int pos=-1);
GtkWidget *m_prevRadio; GtkWidget *m_prevRadio;

View File

@@ -330,7 +330,7 @@ bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
return GtkAppend(menu, 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 ) ); 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_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_connect( GTK_OBJECT(menu->m_owner), "activate",
GTK_SIGNAL_FUNC(gtk_menu_open_callback), GTK_SIGNAL_FUNC(gtk_menu_open_callback),
@@ -396,7 +399,7 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
// TODO // TODO
if ( !GtkAppend(menu, title) ) if ( !GtkAppend(menu, title, (int)pos) )
return FALSE; return FALSE;
return TRUE; return TRUE;
@@ -1005,7 +1008,7 @@ wxMenu::~wxMenu()
gtk_widget_destroy( m_menu ); gtk_widget_destroy( m_menu );
} }
bool wxMenu::GtkAppend(wxMenuItem *mitem) bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
{ {
GtkWidget *menuItem; GtkWidget *menuItem;
@@ -1017,8 +1020,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
// TODO // TODO
menuItem = gtk_menu_item_new(); menuItem = gtk_menu_item_new();
#endif #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() ) else if ( mitem->IsSubMenu() )
{ {
@@ -1046,7 +1051,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
#endif #endif
gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu ); 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 ); gtk_widget_show( mitem->GetSubMenu()->m_menu );
@@ -1077,7 +1085,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
(gpointer)this ); (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 #else
menuItem = gtk_pixmap_menu_item_new (); menuItem = gtk_pixmap_menu_item_new ();
@@ -1126,7 +1137,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
(gpointer)this ); (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 ); gtk_widget_show( menuItem );
#endif #endif
@@ -1251,7 +1265,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
(gpointer)this ); (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; guint accel_key;
@@ -1311,7 +1328,7 @@ wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
return NULL; return NULL;
// TODO // TODO
if ( !GtkAppend(item) ) if ( !GtkAppend(item, (int)pos) )
return NULL; return NULL;
return item; return item;

View File

@@ -330,7 +330,7 @@ bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
return GtkAppend(menu, 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 ) ); 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_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_connect( GTK_OBJECT(menu->m_owner), "activate",
GTK_SIGNAL_FUNC(gtk_menu_open_callback), GTK_SIGNAL_FUNC(gtk_menu_open_callback),
@@ -396,7 +399,7 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
// TODO // TODO
if ( !GtkAppend(menu, title) ) if ( !GtkAppend(menu, title, (int)pos) )
return FALSE; return FALSE;
return TRUE; return TRUE;
@@ -1005,7 +1008,7 @@ wxMenu::~wxMenu()
gtk_widget_destroy( m_menu ); gtk_widget_destroy( m_menu );
} }
bool wxMenu::GtkAppend(wxMenuItem *mitem) bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
{ {
GtkWidget *menuItem; GtkWidget *menuItem;
@@ -1017,8 +1020,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
// TODO // TODO
menuItem = gtk_menu_item_new(); menuItem = gtk_menu_item_new();
#endif #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() ) else if ( mitem->IsSubMenu() )
{ {
@@ -1046,7 +1051,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
#endif #endif
gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu ); 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 ); gtk_widget_show( mitem->GetSubMenu()->m_menu );
@@ -1077,7 +1085,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
(gpointer)this ); (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 #else
menuItem = gtk_pixmap_menu_item_new (); menuItem = gtk_pixmap_menu_item_new ();
@@ -1126,7 +1137,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
(gpointer)this ); (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 ); gtk_widget_show( menuItem );
#endif #endif
@@ -1251,7 +1265,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
(gpointer)this ); (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; guint accel_key;
@@ -1311,7 +1328,7 @@ wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
return NULL; return NULL;
// TODO // TODO
if ( !GtkAppend(item) ) if ( !GtkAppend(item, (int)pos) )
return NULL; return NULL;
return item; return item;