[gtkmm] Newbie questions about changing menus and RefPtr



Hello,

I would like to replace a menu item by another one.
To achieve this result, I thought deleting the menu item and then create the 
new one at the same place.
But I have some problems with the delete task.

I found two ways to do it:

(My menu is menu_Game, it contains "New Game Ctrl+N", a separator, "Quit 
Ctrl+Q"; I want to change "New Game Ctrl+N" to "Stop Game", with a new handler)

Gtk::Menu_Helpers::MenuList::type_base::iterator i = menu_Game.items().begin();
i = menu_Game.items().erase(i);
menu_Game.items().insert(i, Gtk::Menu_Helpers::MenuElem("_Stop Game", SigC::slot
(*this, &GameWindow::stopGame)));

OR

menu_Game.items().remove(menu_Game.items()[0]);
menu_Game.items().push_front(Gtk::Menu_Helpers::MenuElem("_Stop Game", 
SigC::slot(*this, &GameWindow::stopGame)));

(The first way seems better to me because it could work even if the item was in 
the middle of the menu)

In both cases, the menu is changed and I can select the new item (Stop Game) 
but if I press Ctrl+N, I can still execute the previous one (New Game)!

So do the erase/remove methods really delete the menu item?
Did I forget something?
Is there an easier way to change a menu item?

I have a quick question about RefPtr which is unrelated with the previous one.
If I create a RefPtr, assign an gtkmm object to it and then reassign another 
object, will the first object be deleted?

I am a newbie with gtkmm, sorry in advance if my questions sound silly to you.

Thank you for your answers.
Pierre



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]