line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# See the POD documentation at the end of this |
3
|
|
|
|
|
|
|
# document for detailed copyright information. |
4
|
|
|
|
|
|
|
# (c) 2003-2006 Steffen Mueller, all rights reserved. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Tie::Tk::Listbox; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
22377
|
use 5.006; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
36
|
|
9
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
10
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
11
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
104
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
5
|
use vars qw/$VERSION/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1100
|
|
14
|
|
|
|
|
|
|
$VERSION = '1.02'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub TIEARRAY { |
18
|
0
|
|
|
0
|
|
|
my $proto = shift; |
19
|
0
|
|
0
|
|
|
|
my $class = ref $proto || $proto; |
20
|
0
|
|
|
|
|
|
my $listbox = shift; |
21
|
0
|
0
|
|
|
|
|
unless (defined $listbox) { |
22
|
0
|
|
|
|
|
|
croak "Missing listbox argument."; |
23
|
|
|
|
|
|
|
} |
24
|
0
|
0
|
|
|
|
|
unless (ref $listbox eq 'Tk::Listbox') { |
25
|
0
|
|
|
|
|
|
$listbox = $listbox->Subwidget('listbox'); |
26
|
0
|
0
|
|
|
|
|
croak "Trouble finding listbox." if not defined $listbox; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
bless \$listbox, $class; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub STORE { |
33
|
0
|
|
|
0
|
|
|
my $self = shift; |
34
|
0
|
|
|
|
|
|
my $index = shift; |
35
|
|
|
|
|
|
|
# value is $_[0] now. |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
0
|
|
|
|
my $len = $_[1] || $self->FETCHSIZE(); |
38
|
0
|
0
|
|
|
|
|
if ($index > $len - 1) { |
|
|
0
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$self->EXTEND($index+1, $len); |
40
|
|
|
|
|
|
|
} elsif ($index < 0) { |
41
|
0
|
|
|
|
|
|
$index += $len; |
42
|
0
|
0
|
|
|
|
|
croak "Index out of range." if $index < 0; |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
|
${$self}->delete($index); |
|
0
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
${$self}->insert($index, $_[0]); |
|
0
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub FETCHSIZE { |
49
|
0
|
|
|
0
|
|
|
my $self = shift; |
50
|
0
|
|
|
|
|
|
return ${$self}->index('end'); |
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub STORESIZE { |
54
|
0
|
|
|
0
|
|
|
my $self = shift; |
55
|
0
|
|
|
|
|
|
my $tolen = shift; |
56
|
0
|
|
0
|
|
|
|
my $len = shift || $self->FETCHSIZE(); |
57
|
0
|
0
|
|
|
|
|
if ($tolen > $len) { |
|
|
0
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$self->EXTEND($tolen, $len); |
59
|
|
|
|
|
|
|
} elsif ($tolen < $len) { |
60
|
0
|
|
|
|
|
|
${$self}->delete($tolen, $len-1); |
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub FETCH { |
65
|
0
|
|
|
0
|
|
|
my $self = shift; |
66
|
0
|
|
|
|
|
|
my $ind = shift; |
67
|
0
|
|
0
|
|
|
|
my $len = shift || $self->FETCHSIZE(); |
68
|
0
|
0
|
|
|
|
|
if ($ind < 0) { |
69
|
0
|
|
|
|
|
|
$ind += $len; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
0
|
|
|
|
|
if ($ind >= $len) { |
72
|
0
|
|
|
|
|
|
return undef; |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
|
return ${$self}->get($ind); |
|
0
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub CLEAR { |
78
|
0
|
|
|
0
|
|
|
my $self = shift; |
79
|
0
|
|
|
|
|
|
$self->STORESIZE(0); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub EXTEND { |
83
|
0
|
|
|
0
|
|
|
my $self = shift; |
84
|
0
|
|
|
|
|
|
my $tolen = shift; |
85
|
0
|
|
0
|
|
|
|
my $len = shift || $self->FETCHSIZE(); |
86
|
0
|
0
|
|
|
|
|
if ($tolen > $len) { |
87
|
0
|
|
|
|
|
|
my $diff = $tolen - $len; |
88
|
0
|
|
|
|
|
|
${$self}->insert('end', ( (undef) x $diff )); |
|
0
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
0
|
|
|
sub DESTROY { } |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub SPLICE { |
95
|
0
|
|
|
0
|
|
|
my $self = shift; |
96
|
0
|
|
|
|
|
|
my $len = $self->FETCHSIZE; |
97
|
0
|
0
|
|
|
|
|
my $off = (@_) ? shift : 0; |
98
|
0
|
0
|
|
|
|
|
$off += $len if ($off < 0); |
99
|
0
|
0
|
|
|
|
|
my $diff = (@_) ? shift : $len - $off; |
100
|
0
|
0
|
|
|
|
|
$diff += $len - $off if $diff < 0; |
101
|
0
|
|
|
|
|
|
my @result; |
102
|
0
|
|
|
|
|
|
for (my $i = 0; $i < $diff; $i++) { |
103
|
0
|
|
|
|
|
|
push(@result,$self->FETCH($off+$i)); |
104
|
|
|
|
|
|
|
} |
105
|
0
|
0
|
|
|
|
|
$off = $len if $off > $len; |
106
|
0
|
0
|
|
|
|
|
$diff -= $off + $diff - $len if $off + $diff > $len; |
107
|
0
|
0
|
|
|
|
|
if (@_ > $diff) { |
|
|
0
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# Move items up to make room |
109
|
0
|
|
|
|
|
|
my $d = @_ - $diff; |
110
|
0
|
|
|
|
|
|
my $e = $off+$diff; |
111
|
0
|
|
|
|
|
|
$self->EXTEND($len+$d); |
112
|
0
|
|
|
|
|
|
for (my $i=$len-1; $i >= $e; $i--) { |
113
|
0
|
|
|
|
|
|
my $val = $self->FETCH($i); |
114
|
0
|
|
|
|
|
|
$self->STORE($i+$d,$val); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
elsif (@_ < $diff) { |
118
|
|
|
|
|
|
|
# Move items down to close the gap |
119
|
0
|
|
|
|
|
|
my $d = $diff - @_; |
120
|
0
|
|
|
|
|
|
my $e = $off+$diff; |
121
|
0
|
|
|
|
|
|
for (my $i=$off+$diff; $i < $len; $i++) { |
122
|
0
|
|
|
|
|
|
my $val = $self->FETCH($i); |
123
|
0
|
|
|
|
|
|
$self->STORE($i-$d,$val); |
124
|
|
|
|
|
|
|
} |
125
|
0
|
|
|
|
|
|
$self->STORESIZE($len-$d); |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
for (my $i=0; $i < @_; $i++) { |
128
|
0
|
|
|
|
|
|
$self->STORE($off+$i,$_[$i]); |
129
|
|
|
|
|
|
|
} |
130
|
0
|
0
|
|
|
|
|
return wantarray ? @result : pop @result; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
0
|
|
|
sub UNSHIFT { scalar shift->SPLICE(0,0,@_) } |
134
|
0
|
|
|
0
|
|
|
sub SHIFT { shift->SPLICE(0,1) } |
135
|
|
|
|
|
|
|
sub PUSH { |
136
|
0
|
|
|
0
|
|
|
my $self = shift; |
137
|
0
|
|
|
|
|
|
my $i = $self->FETCHSIZE; |
138
|
0
|
|
|
|
|
|
$self->STORE($i++, shift) while (@_); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub POP { |
142
|
0
|
|
|
0
|
|
|
my $self = shift; |
143
|
0
|
|
|
|
|
|
my $newsize = $self->FETCHSIZE - 1; |
144
|
0
|
|
|
|
|
|
my $val; |
145
|
0
|
0
|
|
|
|
|
if ($newsize >= 0) { |
146
|
0
|
|
|
|
|
|
$val = $self->FETCH($newsize); |
147
|
0
|
|
|
|
|
|
$self->STORESIZE($newsize); |
148
|
|
|
|
|
|
|
} |
149
|
0
|
|
|
|
|
|
$val; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub EXISTS { |
153
|
0
|
|
|
0
|
|
|
my $pkg = ref $_[0]; |
154
|
0
|
|
|
|
|
|
croak "$pkg dosn't define an EXISTS method"; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub DELETE { |
158
|
0
|
|
|
0
|
|
|
my $pkg = ref $_[0]; |
159
|
0
|
|
|
|
|
|
croak "$pkg dosn't define a DELETE method"; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
1; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
__END__ |