wxMenu::Insert() seems to work, bug in wxMenuBase::Insert() is corrected

(inserting an item at pos == GetCount() should be the same as appending and
not an error)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4818 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 1999-12-04 14:10:31 +00:00
parent f03ec224dc
commit 32db328c7a
6 changed files with 74 additions and 91 deletions

View File

@ -99,6 +99,9 @@ private:
// common code for all constructors:
void Init();
// common part of Append and Insert
bool GtkAppend(wxMenuItem *item);
DECLARE_DYNAMIC_CLASS(wxMenu)
};

View File

@ -99,6 +99,9 @@ private:
// common code for all constructors:
void Init();
// common part of Append and Insert
bool GtkAppend(wxMenuItem *item);
DECLARE_DYNAMIC_CLASS(wxMenu)
};

View File

@ -460,6 +460,8 @@ void MyFrame::OnCheckMenuItem(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnUpdateCheckMenuItemUI(wxUpdateUIEvent& event)
{
wxLogNull nolog;
wxMenuItem *item = GetLastMenuItem();
event.Enable(item && item->IsCheckable());

View File

@ -153,10 +153,18 @@ bool wxMenuBase::DoAppend(wxMenuItem *item)
bool wxMenuBase::Insert(size_t pos, wxMenuItem *item)
{
wxCHECK_MSG( item, FALSE, wxT("invalid item in wxMenu::Insert") );
wxCHECK_MSG( pos < GetMenuItemCount(), FALSE,
wxT("invalid index in wxMenu::Insert") );
return DoInsert(pos, item);
if ( pos == GetMenuItemCount() )
{
return DoAppend(item);
}
else
{
wxCHECK_MSG( pos < GetMenuItemCount(), FALSE,
wxT("invalid index in wxMenu::Insert") );
return DoInsert(pos, item);
}
}
bool wxMenuBase::DoInsert(size_t pos, wxMenuItem *item)
@ -487,16 +495,23 @@ bool wxMenuBarBase::Append(wxMenu *menu, const wxString& WXUNUSED(title))
}
bool wxMenuBarBase::Insert(size_t pos, wxMenu *menu,
const wxString& WXUNUSED(title))
const wxString& title)
{
wxCHECK_MSG( menu, FALSE, wxT("can't insert NULL menu") );
if ( pos == m_menus.GetCount() )
{
return Append(menu, title);
}
else
{
wxCHECK_MSG( menu, FALSE, wxT("can't insert NULL menu") );
wxMenuList::Node *node = m_menus.Item(pos);
wxCHECK_MSG( node, FALSE, wxT("bad index in wxMenuBar::Insert()") );
wxMenuList::Node *node = m_menus.Item(pos);
wxCHECK_MSG( node, FALSE, wxT("bad index in wxMenuBar::Insert()") );
m_menus.Insert(node, menu);
m_menus.Insert(node, menu);
return TRUE;
return TRUE;
}
}
wxMenu *wxMenuBarBase::Replace(size_t pos, wxMenu *menu,

View File

@ -820,7 +820,7 @@ wxMenu::~wxMenu()
gtk_object_unref( GTK_OBJECT(m_factory) );
}
bool wxMenu::DoAppend(wxMenuItem *mitem)
bool wxMenu::GtkAppend(wxMenuItem *mitem)
{
GtkWidget *menuItem;
@ -934,56 +934,36 @@ bool wxMenu::DoAppend(wxMenuItem *mitem)
mitem->SetMenuItem(menuItem);
return wxMenuBase::DoAppend(mitem);
return TRUE;
}
// VZ: this seems to be GTK+ 1.0 only code, I don't understand why there were
// both specialized versions of Append() and this one before my changes,
// but it seems that the others are better...
#if 0
void wxMenu::Append( wxMenuItem *item )
bool wxMenu::DoAppend(wxMenuItem *mitem)
{
GtkWidget *menuItem = (GtkWidget*) NULL;
if (item->IsSeparator())
menuItem = gtk_menu_item_new();
else if (item->IsSubMenu())
menuItem = gtk_menu_item_new_with_label(item->GetText().mbc_str());
else
menuItem = item->IsCheckable() ? gtk_check_menu_item_new_with_label(item->GetText().mbc_str())
: gtk_menu_item_new_with_label(item->GetText().mbc_str());
if (!item->IsSeparator())
{
gtk_signal_connect( GTK_OBJECT(menuItem), "select",
GTK_SIGNAL_FUNC(gtk_menu_hilight_callback),
(gpointer*)this );
gtk_signal_connect( GTK_OBJECT(menuItem), "deselect",
GTK_SIGNAL_FUNC(gtk_menu_nolight_callback),
(gpointer*)this );
if (!item->IsSubMenu())
{
gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
(gpointer*)this );
}
}
gtk_menu_append( GTK_MENU(m_menu), menuItem );
gtk_widget_show( menuItem );
item->SetMenuItem(menuItem);
return GtkAppend(mitem) && wxMenuBase::DoAppend(mitem);
}
#endif // 0
bool wxMenu::DoInsert(size_t pos, wxMenuItem *item)
{
if ( !wxMenuBase::DoInsert(pos, item) )
return FALSE;
wxFAIL_MSG(wxT("not implemented"));
#ifdef __WXGTK12__
// GTK+ doesn't have a function to insert a menu using GtkItemFactory (as
// of version 1.2.6), so we first append the item and then change its
// index
if ( !GtkAppend(item) )
return FALSE;
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);
menu_shell->children = g_list_insert(menu_shell->children, data, pos);
return TRUE;
#else // GTK < 1.2
// this should be easy to do...
wxFAIL_MSG( wxT("not implemented") );
#endif // GTK 1.2/1.0
return FALSE;
}

View File

@ -820,7 +820,7 @@ wxMenu::~wxMenu()
gtk_object_unref( GTK_OBJECT(m_factory) );
}
bool wxMenu::DoAppend(wxMenuItem *mitem)
bool wxMenu::GtkAppend(wxMenuItem *mitem)
{
GtkWidget *menuItem;
@ -934,56 +934,36 @@ bool wxMenu::DoAppend(wxMenuItem *mitem)
mitem->SetMenuItem(menuItem);
return wxMenuBase::DoAppend(mitem);
return TRUE;
}
// VZ: this seems to be GTK+ 1.0 only code, I don't understand why there were
// both specialized versions of Append() and this one before my changes,
// but it seems that the others are better...
#if 0
void wxMenu::Append( wxMenuItem *item )
bool wxMenu::DoAppend(wxMenuItem *mitem)
{
GtkWidget *menuItem = (GtkWidget*) NULL;
if (item->IsSeparator())
menuItem = gtk_menu_item_new();
else if (item->IsSubMenu())
menuItem = gtk_menu_item_new_with_label(item->GetText().mbc_str());
else
menuItem = item->IsCheckable() ? gtk_check_menu_item_new_with_label(item->GetText().mbc_str())
: gtk_menu_item_new_with_label(item->GetText().mbc_str());
if (!item->IsSeparator())
{
gtk_signal_connect( GTK_OBJECT(menuItem), "select",
GTK_SIGNAL_FUNC(gtk_menu_hilight_callback),
(gpointer*)this );
gtk_signal_connect( GTK_OBJECT(menuItem), "deselect",
GTK_SIGNAL_FUNC(gtk_menu_nolight_callback),
(gpointer*)this );
if (!item->IsSubMenu())
{
gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
(gpointer*)this );
}
}
gtk_menu_append( GTK_MENU(m_menu), menuItem );
gtk_widget_show( menuItem );
item->SetMenuItem(menuItem);
return GtkAppend(mitem) && wxMenuBase::DoAppend(mitem);
}
#endif // 0
bool wxMenu::DoInsert(size_t pos, wxMenuItem *item)
{
if ( !wxMenuBase::DoInsert(pos, item) )
return FALSE;
wxFAIL_MSG(wxT("not implemented"));
#ifdef __WXGTK12__
// GTK+ doesn't have a function to insert a menu using GtkItemFactory (as
// of version 1.2.6), so we first append the item and then change its
// index
if ( !GtkAppend(item) )
return FALSE;
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);
menu_shell->children = g_list_insert(menu_shell->children, data, pos);
return TRUE;
#else // GTK < 1.2
// this should be easy to do...
wxFAIL_MSG( wxT("not implemented") );
#endif // GTK 1.2/1.0
return FALSE;
}