use strict;
use warnings;
use Gtk2 "-init";


first_example();

warn "one item was not destoyed for me\n";

my $window=Gtk2::Window->new;
$window->signal_connect(delete_event => sub { $_[0]->destroy; });
my $button=Gtk2::Button->new("open test window\nthe menuitem in the test window will only be destroyed if it has been displayed");
$button->signal_connect(clicked => \&second_example);
$window->add($button);
$window->show_all;

Gtk2->main;


sub first_example # simply create the menuitems and return, $item2 is not destroyed
{	my $item=Gtk2::MenuItem->new;
	my $item2=Gtk2::MenuItem->new('t');
	my $item3=Gtk2::MenuItem->new;
	$item3->add( Gtk2::Label->new('t') );
	$_->show_all for $item, $item2, $item3;
	warn "+++++ created $_\n" for $item, $item2, $item3;

	$_->signal_connect( destroy => sub {warn "----- destroyed $_[0]\n"; }) for $item, $item2, $item3;

}



sub second_example
{	my $win=Gtk2::Window->new;
	my $check=Gtk2::CheckButton->new('loooooooooooooooooooooooooonnnnnnnnnnnnng');
	my $toolbar=Gtk2::Toolbar->new;
	my $toolitem=Gtk2::ToolItem->new;
	$toolitem->add($check);
	my $item=Gtk2::CheckMenuItem->new('loooooooooooooooooooooooooonnnnnnnnnnnnng');
	$toolitem->set_proxy_menu_item('key',$item);

	warn "+++++ created $_\n" for $toolbar, $toolitem, $item;
	$_->signal_connect( destroy => sub {warn "----- destroyed $_[0]\n"; }) for $toolbar, $toolitem, $item;

	$toolbar->insert($toolitem,-1);
	$win->add($toolbar);
	$win->show_all;
}
