Gtk2-Ex-MenuView

 view release on metacpan or  search on metacpan

devel/junk/ArrayMenu.pm  view on Meta::CPAN

      $item->signal_connect ('activate', \&_do_activate, $i);
      $self->append ($item);
    }
    my $elem = $array->[$i];
    my $str = $name_proc->($self, $elem);
    my $label = $item->get_child;
    if ($use_mnemonic) {
      $label->set_text_with_mnemonic ($str);
    } else {
      $label->set_text ($str);
    }
    $item->show;

    $item_proc->($self, $item, $elem);
  }

  # hide any excess children
  for ( ; $i < @children; $i++) {
    my $item = $children[$i];
    $item->hide;
  }
}

# 'show' class closure
sub _do_show {
  my ($self) = @_;
  _freshen_items ($self);
  return shift->signal_chain_from_overridden(@_);
}

sub SET_PROPERTY {
  my ($self, $pspec, $newval) = @_;
  $self->{$pspec->get_name} = $newval;  # per default GET_PROPERTY

  if ($self->visible) {
    _freshen_items ($self);
  }
}

# sub INIT_INSTANCE {
#   my ($self) = @_;
# }

1;
__END__

=for stopwords VAxis Eg arraymenu boolean stringize stringizing

=head1 NAME

Gtk2::Ex::ArrayMenu -- menu of items from an array

=for test_synopsis my ($item)

=head1 SYNOPSIS

 use Gtk2::Ex::ArrayMenu;

 my $menu = Gtk2::Ex::ArrayMenu->new (array => ['One', 'Two']);

 # standalone popup
 $menu->popup;

 # or as a submenu
 $item->set_submenu ($menu);

=head1 WIDGET HIERARCHY

C<Gtk2::Ex::ArrayMenu> is a subclass of C<Gtk2::Menu>.

    Gtk2::Widget
      Gtk2::Container
        Gtk2::MenuShell
          Gtk2::Menu
            Gtk2::Ex::ArrayMenu

=head1 DESCRIPTION

A C<Gtk2::Ex::ArrayMenu> presents menu items from a given array of values.
Those values can be strings to show directly, or functions can be set to
form the strings, and make other setups.  A single C<activate> signal on the
C<ArrayMenu> is called for any item activated.

A new array of desired items to show can be set at any time and the number
of items and their contents are changed accordingly.  The work in doing that
is left until the menu is popped up.

=head1 FUNCTIONS

=over 4

=item C<< Gtk2::Ex::ArrayMenu->new (key=>value,...) >>

Create and return a new VAxis widget.  Optional key/value pairs set initial
properties, as per C<< Glib::Object->new >>.  Eg.

    my $adj = Gtk2::Adjustment->new (5,0,20, 1,8, 10);
    Gtk2::Ex::VAxis->new (adjustment => $adj,
                           decimals => 1);

=back

=head1 SIGNALS

=over 4

=item C<activate>,  parameters (C<$arraymenu>, C<$elem>, C<$userdata>)

Emitted when the user activates one of the items within the arraymenu.  The
corresponding array element is passed as a parameter.

=back

=head1 PROPERTIES

=over 4

=item C<array> (array reference, default empty C<[]>)

Array of items to display.

=item C<use-mnemonic> (boolean, default true)



( run in 0.729 second using v1.01-cache-2.11-cpan-364913b4093 )