# # $Header$ # # r.m. # package Gtk2::SimpleMenu; use Carp; use Gtk2; use base 'Gtk2::ItemFactory'; our $VERSION = 0.10; sub new { my $class = shift; my $menu_tree = shift; my $user_data = shift; my $self = Gtk2::ItemFactory->new('Gtk2::MenuBar', '
', undef); bless($self, $class); $self->parse($menu_tree); $self->create_items($user_data, @{$self->{items}}); $self->{widget} = $self->get_widget('
'); return $self; } sub parse { my $self = shift; my $menu = shift; my @opts = @_; our @items = (); our @groups = (); sub parse_level { my $path = shift; my $label = shift; my $itms = shift; unless( exists($itms->{item_type}) ) { $itms->{item_type} = ''; } if( $itms->{item_type} eq 'root' ) { my $i = 0; for( $i = 0; $i < scalar(@{$itms->{items}}); $i += 2) { parse_level ('/', $itms->{items}[$i], $itms->{items}[$i+1]); } } elsif( $itms->{item_type} =~ /Branch/ ) { push @items, [ $path.$label, undef, undef, undef, $itms->{item_type}, ]; $label =~ s/_//g; my $i = 0; for( $i = 0; $i < scalar(@{$itms->{items}}); $i += 2) { parse_level ($path.$label.'/', $itms->{items}[$i], $itms->{items}[$i+1]); } } elsif( $itms->{item_type} =~ /Radio/ ) { my $grp = $itms->{group}; if( exists($groups[$grp]) ) { push @items, [ $path.$label, $itms->{accelerator}, $itms->{callback}, $itms->{callback_action}, $groups[$grp], $itms->{extra_data}, ]; } else { push @items, [ $path.$label, $itms->{accelerator}, $itms->{callback}, $itms->{callback_action}, $itms->{item_type}, $itms->{extra_data}, ]; $groups[$grp] = $path.$label; $groups[$grp] =~ s/_//g; } } else { push @items, [ $path.$label, $itms->{accelerator}, $itms->{callback}, $itms->{callback_action}, $itms->{item_type}, $itms->{extra_data}, ]; } } parse_level (undef, undef, { item_type => 'root', items => $menu }); $self->{items} = \ items; } 1;