deletion of Gtk::MenuItem



Hi,

i created a simple MenuBar with submenus. While playing around i noticed
that when a MenuItem in the MenuBar has a submenu, the MenuItem is not
deleted, although it is managed by the MenuBar (see attached file).
Removing line 43 (file_menuitem->set_submenu()) changes that. Is this
behavior intended or did i hit a bug? If intended, how can i ensure the
deletion of every MenuItem without remembering every single pointer?

Thanks,
Marco
#include <gtkmm.h>

class menu_item : public Gtk::MenuItem
{
public:
	menu_item(const Glib::ustring label) : Gtk::MenuItem(label), label(label)
	{
		::printf("construct: %s\n", label.c_str());
	}

	~menu_item(void)
	{
		::printf("destruct: %s\n", label.c_str());
	}
private:
	Glib::ustring label;
};

class my_window : public Gtk::Window
{
public:
	my_window(void)
	{
		menubar = new Gtk::MenuBar;
		menu123 = new Gtk::Menu;

		menu_item *menuitem;
		menu_item *file_menuitem;

		menuitem = new menu_item("New");
		menu123->append(*Gtk::manage(menuitem));

		file_menuitem = Gtk::manage(new menu_item("File"));
		file_menuitem->set_submenu(*Gtk::manage(menu123));

		menubar->append(*Gtk::manage(file_menuitem));

		add(*Gtk::manage(menubar));

		show_all_children();
	}

private:

	Gtk::MenuBar *menubar;
	Gtk::Menu *menu123;
};

int main(int argc, char **argv)
{

	Gtk::Main main(argc, argv);

	my_window window;

	Gtk::Main::run(window);
}


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