| 1 |
|
| 2 |
=head1 NAME |
| 3 |
|
| 4 |
Tk::Menu::Item - Base class for Menu items |
| 5 |
|
| 6 |
=for pm Tk/Menu/Item.pm |
| 7 |
|
| 8 |
=for category Implementation |
| 9 |
|
| 10 |
=head1 SYNOPSIS |
| 11 |
|
| 12 |
require Tk::Menu::Item; |
| 13 |
|
| 14 |
my $but = $menu->Button(...); |
| 15 |
$but->configure(...); |
| 16 |
my $what = $but->cget(); |
| 17 |
|
| 18 |
package Whatever; |
| 19 |
require Tk::Menu::Item; |
| 20 |
@ISA = qw(Tk::Menu::Item); |
| 21 |
|
| 22 |
sub PreInit |
| 23 |
{ |
| 24 |
my ($class,$menu,$info) = @_; |
| 25 |
$info->{'-xxxxx'} = ... |
| 26 |
my $y = delete $info->{'-yyyy'}; |
| 27 |
} |
| 28 |
|
| 29 |
=head1 DESCRIPTION |
| 30 |
|
| 31 |
Tk::Menu::Item is the base class from which Tk::Menu::Button, |
| 32 |
Tk::Menu::Cascade, Tk::Menu::Radiobutton and Tk::Menu::Checkbutton are derived. |
| 33 |
There is also a Tk::Menu::Separator. |
| 34 |
|
| 35 |
Constructors are declared so that $menu-E<gt>Button(...) etc. do what you would |
| 36 |
expect. |
| 37 |
|
| 38 |
The C<-label> option is pre-processed allowing ~ to be prefixed to the character |
| 39 |
to derive a C<-underline> value. Thus |
| 40 |
|
| 41 |
$menu->Button(-label => 'Goto ~Home',...) |
| 42 |
|
| 43 |
is equivalent to |
| 44 |
|
| 45 |
$menu->Button(-label => 'Goto Home', -underline => 6, ...) |
| 46 |
|
| 47 |
The C<Cascade> menu item creates a sub-menu and accepts |
| 48 |
these options: |
| 49 |
|
| 50 |
=over 4 |
| 51 |
|
| 52 |
=item B<-menuitems> |
| 53 |
|
| 54 |
A list of items for the sub-menu. |
| 55 |
Within this list (which is also accepted by Menu and Menubutton) the first |
| 56 |
two elements of each item should be the "constructor" name and the label: |
| 57 |
|
| 58 |
-menuitems => [ |
| 59 |
[Button => '~Quit', -command => [destroy => $mw]], |
| 60 |
[Checkbutton => '~Oil', -variable => \$oil], |
| 61 |
] |
| 62 |
|
| 63 |
=item B<-postcommand> |
| 64 |
|
| 65 |
A callback to be invoked before posting the menu. |
| 66 |
|
| 67 |
=item B<-tearoff> |
| 68 |
|
| 69 |
Specifies whether sub-menu can be torn-off or not. |
| 70 |
|
| 71 |
=item B<-menuvar> |
| 72 |
|
| 73 |
Scalar reference that will be set to the newly-created sub-menu. |
| 74 |
|
| 75 |
=back |
| 76 |
|
| 77 |
The returned object is currently a blessed reference to an array of two items: |
| 78 |
the containing Menu and the 'label'. |
| 79 |
Methods C<configure> and C<cget> are mapped onto underlying C<entryconfigure> |
| 80 |
and C<entrycget>. |
| 81 |
|
| 82 |
The main purpose of the OO interface is to allow derived item classes to |
| 83 |
be defined which pre-set the options used to create a more basic item. |
| 84 |
|
| 85 |
=head1 BUGS |
| 86 |
|
| 87 |
This OO interface is very new. Using the label as the "key" is a problem |
| 88 |
for separaror items which don't have one. The alternative would be to |
| 89 |
use an index into the menu but that is a problem if items are deleted |
| 90 |
(or inserted other than at the end). |
| 91 |
|
| 92 |
There should probably be a PostInit entry point too, or a more widget like |
| 93 |
defered 'configure'. |
| 94 |
|
| 95 |
=cut |
| 96 |
|