blob: 492c32ccc1ea20964be81fad473d6f196f9cb29a (
plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# NOTE: Derived from ..\blib\lib\Tk\Listbox.pm.
# Changes made here will be lost when autosplit is run again.
# See AutoSplit.pm.
package Tk::Listbox;
#line 232 "..\blib\lib\Tk\Listbox.pm (autosplit into ..\blib\lib\auto\Tk\Listbox\STORE.al)"
# STORE
# -----
# If tied to an array we will modify the Listbox contents, while if tied
# to a scalar we will select and clear elements.
sub STORE {
if ( scalar(@_) == 2 ) {
# we have a tied scalar
my ( $class, $selected ) = @_;
my $self = ${$class->{OBJECT}};
my %options = %{$class->{OPTION}} if defined $class->{OPTION};;
# clear currently selected elements
$self->selectionClear(0,'end');
# set selected elements
if ( defined $options{ReturnType} ) {
# THREE-WAY SWITCH
if ( $options{ReturnType} eq "index" ) {
for ( my $i=0; $i < scalar(@$selected) ; $i++ ) {
for ( my $j=0; $j < $self->size() ; $j++ ) {
if( $j == $$selected[$i] ) {
$self->selectionSet($j); last; }
}
}
} elsif ( $options{ReturnType} eq "element" ) {
for ( my $k=0; $k < scalar(@$selected) ; $k++ ) {
for ( my $l=0; $l < $self->size() ; $l++ ) {
if( $self->get($l) eq $$selected[$k] ) {
$self->selectionSet($l); last; }
}
}
} elsif ( $options{ReturnType} eq "both" ) {
foreach my $key ( keys %$selected ) {
$self->selectionSet($key)
if $$selected{$key} eq $self->get($key);
}
}
} else {
# return elements (default)
for ( my $k=0; $k < scalar(@$selected) ; $k++ ) {
for ( my $l=0; $l < $self->size() ; $l++ ) {
if( $self->get($l) eq $$selected[$k] ) {
$self->selectionSet($l); last; }
}
}
}
} else {
# we have a tied array
my ( $class, $index, $value ) = @_;
my $self = ${$class->{OBJECT}};
# check size of current contents list
my $sizeof = $self->size();
if ( $index <= $sizeof ) {
# Change a current listbox entry
$self->delete($index);
$self->insert($index, $value);
} else {
# Add a new value
if ( defined $index ) {
$self->insert($index, $value);
} else {
$self->insert("end", $value);
}
}
}
}
# end of Tk::Listbox::STORE
1;
|