1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
sub del
{
my( $self, @num ) = @_; # pick parameters
$self->close if $self->{container}->ismapped; # close the menu if it is being displayed
# delete menu entries
for my $i (
sort { $b <=> $a } @num # sort this to delete the right entries
) {
$self->{menu}->[$i] -> destroy(); # destroy the menu entry
splice( @{ $self->{menu} }, $i, 1 ); # delete the array member
} # for
return $self; # return object
} # del
sub close
{
my( $self ) = @_; # pick parameters
$self->{shadow} -> withdraw; # close shadow
$self->{container} -> withdraw; # close menu
return $self; # return object
} # close
sub show
{
my( $self, $x, $y ) = @_; # pick parameters
$self->close if $self->{container}->ismapped; # close menu if it is being displayed
# set shadow position
$self->{shadow} -> geometry(
'=' .
$self->{container}->reqwidth . # menu width
'x' .
$self->{container}->reqheight . # menu height
'+' .
( $x + 3 ) . # menu x position + extra pixels for the shadow
'+' .
( $y + 3 ) # menu y position + extra pixels for the shadow
);
$self->{shadow} -> deiconify; # show shadow
$self->{container} -> geometry("+$x+$y"); # set menu position
$self->{container} -> deiconify; # show menu
$self->{container} -> raise( $self->{shadow} ); # draw the menu over the shadow
$self->{container} -> focus(); # give focus() to the menu
return $self; # return object
} # show
1;
Und ein kleines Beispiel wie man diese Klasse anwendet: