line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: TiedListbox.pm 1.5 Mon, 21 Sep 1998 23:02:17 +0200 ach $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# TiedListbox: tie together the scrolling and/or selection of Listboxes |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Tk::TiedListbox; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
760
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
331
|
|
8
|
1
|
|
|
1
|
|
2120
|
use Tk::Listbox; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Carp; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use vars qw($VERSION @ISA); |
12
|
|
|
|
|
|
|
$VERSION = substr(q$Revision: 1.5 $, 10) + 1; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
@ISA = qw(Tk::Derived Tk::Listbox); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Tk::Widget->Construct('TiedListbox'); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Tk::Submethods ( 'tie' => [qw(scroll selection all)], |
21
|
|
|
|
|
|
|
'selection' => [qw(anchor clear includes set)], |
22
|
|
|
|
|
|
|
'scan' => [qw(mark dragto)] |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub tie { |
26
|
|
|
|
|
|
|
my $cw=shift; |
27
|
|
|
|
|
|
|
bless $cw,"Tk::TiedListbox"; |
28
|
|
|
|
|
|
|
if(@_) { |
29
|
|
|
|
|
|
|
$cw->untie; |
30
|
|
|
|
|
|
|
$cw->{-tieoption}='all'; |
31
|
|
|
|
|
|
|
if($_[0] eq 'scroll' || $_[0] eq 'selection' || $_[0] eq 'all') { |
32
|
|
|
|
|
|
|
$cw->{-tieoption}=shift; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
@_=@{$_[0]} if ref($_[0]) eq 'ARRAY'; |
35
|
|
|
|
|
|
|
$cw->{-tiedto}=[@_]; |
36
|
|
|
|
|
|
|
my $w; |
37
|
|
|
|
|
|
|
foreach $w (@_) { |
38
|
|
|
|
|
|
|
bless $w,ref($cw) if(ref($w)=~/Listbox$/); # Let's hope this works |
39
|
|
|
|
|
|
|
if(ref($w) eq ref($cw)) { |
40
|
|
|
|
|
|
|
$w->untie; |
41
|
|
|
|
|
|
|
$w->{-tieoption}=$cw->{-tieoption}; |
42
|
|
|
|
|
|
|
$w->{-tiedto}=[$cw,grep($_ ne $w,@_)]; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
|
|
|
|
|
|
carp "trying to tie a non-Listbox $w"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
return $cw; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else { |
51
|
|
|
|
|
|
|
$cw->{-tieoption}='all',$cw->{-tiedto}=[] |
52
|
|
|
|
|
|
|
unless ref $cw->{-tiedto}; |
53
|
|
|
|
|
|
|
return($cw->{-tieoption},$cw->{-tiedto}); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub untie |
58
|
|
|
|
|
|
|
{ |
59
|
|
|
|
|
|
|
my $cw=shift; |
60
|
|
|
|
|
|
|
my @ret=$cw->tie; |
61
|
|
|
|
|
|
|
my $w; |
62
|
|
|
|
|
|
|
foreach $w (@{$cw->{-tiedto}}) { |
63
|
|
|
|
|
|
|
$w->{-tiedto}=[grep($_ ne $cw,@{$w->{-tiedto}})]; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
@ret; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub Tk::Listbox::tie { |
69
|
|
|
|
|
|
|
shift->Tk::TiedListbox::tie(@_); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub activate { |
73
|
|
|
|
|
|
|
my $cw=shift; |
74
|
|
|
|
|
|
|
$cw->CallTie('selection','activate',[$cw->index($_[0])],\&ActivateTie); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub ActivateTie { |
78
|
|
|
|
|
|
|
my($w,$sub,$index)=@_; |
79
|
|
|
|
|
|
|
$w->$sub($index) if $index<$w->size; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub scan { |
83
|
|
|
|
|
|
|
my $cw=shift; |
84
|
|
|
|
|
|
|
$cw->SUPER::scan(@_); |
85
|
|
|
|
|
|
|
$cw->CallTie('scroll','yview',[int(($cw->SUPER::yview)[0]*$cw->size+.5)]); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub see { |
89
|
|
|
|
|
|
|
my $cw=shift; |
90
|
|
|
|
|
|
|
$cw->CallTie('scroll','see',[$cw->index($_[0])]); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub selection { |
94
|
|
|
|
|
|
|
my $cw=shift; |
95
|
|
|
|
|
|
|
if($_[0] eq 'anchor') { |
96
|
|
|
|
|
|
|
$cw->CallTie('selection','selection',['anchor',$cw->index($_[1])], |
97
|
|
|
|
|
|
|
\&SelectionAnchorTie); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
if($_[0] eq 'clear' || $_[0] eq 'set') { |
100
|
|
|
|
|
|
|
$cw->CallTie('selection','selection', |
101
|
|
|
|
|
|
|
[$_[0],map($cw->index($_),@_[1..@_-1])], |
102
|
|
|
|
|
|
|
\&SelectionSetClearTie); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
elsif($_[0] eq 'includes') { |
105
|
|
|
|
|
|
|
return $cw->SUPER::selection(@_); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub SelectionAnchorTie { |
110
|
|
|
|
|
|
|
my($w,$sub,$action,$index)=@_; |
111
|
|
|
|
|
|
|
$w->$sub($action,$index) if $index<$w->size; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub SelectionSetClearTie { |
115
|
|
|
|
|
|
|
my($w,$sub,$action,@index)=@_; |
116
|
|
|
|
|
|
|
$w->$sub($action,@index) if $index[0]<$w->size || |
117
|
|
|
|
|
|
|
($#index>=1 && $index[1]<$w->size); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub yview { |
121
|
|
|
|
|
|
|
my $cw=shift; |
122
|
|
|
|
|
|
|
if(@_) { |
123
|
|
|
|
|
|
|
if($_[0] eq 'moveto') { |
124
|
|
|
|
|
|
|
$cw->SUPER::yview(@_); |
125
|
|
|
|
|
|
|
$cw->CallTie('scroll','yview',[int(($cw->SUPER::yview)[0]*$cw->size+.5)]); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
elsif($_[0] eq 'scroll') { |
128
|
|
|
|
|
|
|
$cw->SUPER::yview(@_); |
129
|
|
|
|
|
|
|
$cw->CallTie('scroll','yview',[int(($cw->SUPER::yview)[0]*$cw->size+.5)]); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
else { |
132
|
|
|
|
|
|
|
$cw->CallTie('scroll','yview',[$cw->index($_[0])]); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
else { |
136
|
|
|
|
|
|
|
return $cw->SUPER::yview(); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub CallTie { |
141
|
|
|
|
|
|
|
my($cw,$option,$sub,$args,$tiesub)=@_; |
142
|
|
|
|
|
|
|
my $supersub="SUPER::$sub"; |
143
|
|
|
|
|
|
|
$tiesub=sub{my($w,$sub)=(shift,shift); $w->$sub(@_);} |
144
|
|
|
|
|
|
|
unless defined $tiesub; |
145
|
|
|
|
|
|
|
my @ret=&$tiesub($cw,$supersub,@$args); |
146
|
|
|
|
|
|
|
if(ref($cw->{'-tiedto'}) && |
147
|
|
|
|
|
|
|
($cw->{'-tieoption'} eq 'all' || |
148
|
|
|
|
|
|
|
$cw->{'-tieoption'} eq $option)) { |
149
|
|
|
|
|
|
|
my $w; |
150
|
|
|
|
|
|
|
foreach $w (@{$cw->{'-tiedto'}}) { |
151
|
|
|
|
|
|
|
&$tiesub($w,$supersub,@$args); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
@ret; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
1; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
__END__ |