line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#===============================================================================
|
2
|
|
|
|
|
|
|
# Tie/Tk/Text.pm
|
3
|
|
|
|
|
|
|
#===============================================================================
|
4
|
|
|
|
|
|
|
package Tie::Tk::Text;
|
5
|
4
|
|
|
4
|
|
113206
|
use strict;
|
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
165
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
23
|
use vars qw'$VERSION';
|
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
4294
|
|
8
|
|
|
|
|
|
|
$VERSION = '0.92';
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Notes:
|
11
|
|
|
|
|
|
|
# * Text widgets use 1-based indexing so line number = array index + 1
|
12
|
|
|
|
|
|
|
# * Text widgets *always* have a newline at the end. It's returned by
|
13
|
|
|
|
|
|
|
# $w->get('1.0', 'end') but isn't deleted by $w->delete('1.0', 'end')
|
14
|
|
|
|
|
|
|
# * $w->get('1.0', '1.0 lineend') doesn't include the trailing newline.
|
15
|
|
|
|
|
|
|
# You need to use one of these instead:
|
16
|
|
|
|
|
|
|
# $w->get('1.0', '2.0')
|
17
|
|
|
|
|
|
|
# $w->get('1.0', '1.0 lineend + 1 chars)
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub TIEARRAY {
|
20
|
0
|
|
|
0
|
|
|
my $class = shift;
|
21
|
0
|
|
|
|
|
|
my $widget = shift;
|
22
|
0
|
|
|
|
|
|
return bless \$widget, $class;
|
23
|
|
|
|
|
|
|
}
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub CLEAR {
|
27
|
0
|
|
|
0
|
|
|
my $self = shift;
|
28
|
0
|
|
|
|
|
|
$$self->delete('1.0', 'end');
|
29
|
|
|
|
|
|
|
}
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub FETCH {
|
33
|
0
|
|
|
0
|
|
|
my $self = shift;
|
34
|
0
|
|
|
|
|
|
my $line = shift() + 1;
|
35
|
0
|
|
|
|
|
|
return $$self->get("$line.0", "$line.end + 1 chars");
|
36
|
|
|
|
|
|
|
}
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub STORE {
|
40
|
0
|
|
|
0
|
|
|
my $self = shift;
|
41
|
0
|
|
|
|
|
|
my $idx = shift;
|
42
|
0
|
|
|
|
|
|
my $text = shift;
|
43
|
0
|
|
|
|
|
|
my $line = $idx + 1;
|
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$$self->insert('end', "\n") while ($self->FETCHSIZE <= $idx);
|
46
|
0
|
|
|
|
|
|
$self->_delete($idx);
|
47
|
0
|
|
|
|
|
|
$$self->insert("$line.0", $text);
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub FETCHSIZE {
|
52
|
0
|
|
|
0
|
|
|
my $self = shift;
|
53
|
0
|
|
|
|
|
|
my $c = $$self->get('end - 1 chars');
|
54
|
0
|
0
|
|
|
|
|
my $n = $c eq "\n" ? 2 : 1; # cf. module notes
|
55
|
0
|
|
|
|
|
|
my $l = (split(/\./, $$self->index("end - $n chars")))[0];
|
56
|
0
|
|
|
|
|
|
return $l;
|
57
|
|
|
|
|
|
|
}
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub STORESIZE {
|
61
|
0
|
|
|
0
|
|
|
my $self = shift;
|
62
|
0
|
|
|
|
|
|
my $size = shift;
|
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
if ($self->FETCHSIZE > $size) {
|
65
|
0
|
|
|
|
|
|
my $n = $size + 1;
|
66
|
0
|
|
|
|
|
|
$$self->delete("$n.0", 'end');
|
67
|
|
|
|
|
|
|
}
|
68
|
|
|
|
|
|
|
else {
|
69
|
0
|
|
|
|
|
|
$$self->insert('end', "\n") while ($self->FETCHSIZE < $size);
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
}
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub EXISTS {
|
75
|
0
|
|
|
0
|
|
|
my $self = shift;
|
76
|
0
|
|
|
|
|
|
my $idx = shift;
|
77
|
0
|
|
|
|
|
|
return $idx < $self->FETCHSIZE;
|
78
|
|
|
|
|
|
|
}
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub DELETE {
|
82
|
0
|
|
|
0
|
|
|
my $self = shift;
|
83
|
0
|
|
|
|
|
|
my $idx = shift;
|
84
|
0
|
0
|
|
|
|
|
my $text = $self->EXISTS($idx) ? $self->FETCH($idx) : undef;
|
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $l = $idx + 1;
|
87
|
0
|
|
|
|
|
|
$$self->delete("$l.0", "$l.0 lineend"); # don't delete the \n
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# collapse trailing "undef" (\n) values
|
90
|
0
|
|
|
|
|
|
while ($self->FETCH($self->FETCHSIZE - 1) eq "\n") {
|
91
|
0
|
|
|
|
|
|
$self->POP;
|
92
|
|
|
|
|
|
|
}
|
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return $text;
|
95
|
|
|
|
|
|
|
}
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub PUSH {
|
99
|
0
|
|
|
0
|
|
|
my $self = shift;
|
100
|
0
|
|
|
|
|
|
$$self->insert('end', $_) foreach @_;
|
101
|
|
|
|
|
|
|
}
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub POP {
|
105
|
0
|
|
|
0
|
|
|
my $self = shift;
|
106
|
0
|
|
|
|
|
|
return $self->_delete($self->FETCHSIZE - 1);
|
107
|
|
|
|
|
|
|
}
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub UNSHIFT {
|
111
|
0
|
|
|
0
|
|
|
my $self = shift;
|
112
|
0
|
|
|
|
|
|
$$self->insert('1.0', $_) foreach reverse @_;
|
113
|
|
|
|
|
|
|
}
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub SHIFT {
|
117
|
0
|
|
|
0
|
|
|
my $self = shift;
|
118
|
0
|
|
|
|
|
|
return $self->_delete(0);
|
119
|
|
|
|
|
|
|
}
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub SPLICE {
|
123
|
0
|
|
|
0
|
|
|
my $self = shift;
|
124
|
0
|
|
|
|
|
|
my $o = shift; # offset
|
125
|
0
|
|
|
|
|
|
my $l = shift; # length
|
126
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
|
$o = 0 unless defined $o;
|
128
|
0
|
0
|
|
|
|
|
$o = $self->FETCHSIZE + $o if $o < 0;
|
129
|
0
|
0
|
|
|
|
|
$l = $self->FETCHSIZE - $o unless defined $l;
|
130
|
0
|
0
|
|
|
|
|
$l = $self->FETCHSIZE - $o + $l if $l < 0;
|
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
my @deleted;
|
133
|
0
|
|
|
|
|
|
foreach my $i (reverse ($o .. $o + $l - 1)) {
|
134
|
0
|
|
|
|
|
|
unshift @deleted, $self->_delete($i);
|
135
|
|
|
|
|
|
|
}
|
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
foreach my $r (reverse @_) {
|
138
|
0
|
|
|
|
|
|
my $x = $o + $l - 1;
|
139
|
0
|
|
|
|
|
|
$$self->insert("$x.0", $r);
|
140
|
|
|
|
|
|
|
}
|
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
return @deleted;
|
143
|
|
|
|
|
|
|
}
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
0
|
|
|
sub EXTEND {}
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
149
|
|
|
|
|
|
|
# Method : Remove and (really) delete element
|
150
|
|
|
|
|
|
|
# Purpose :
|
151
|
|
|
|
|
|
|
# Notes :
|
152
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
153
|
|
|
|
|
|
|
sub _delete {
|
154
|
0
|
|
|
0
|
|
|
my $self = shift;
|
155
|
0
|
|
|
|
|
|
my $idx = shift;
|
156
|
0
|
|
|
|
|
|
my $text = $self->FETCH($idx);
|
157
|
0
|
|
|
|
|
|
my $line = $idx+1;
|
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
$$self->delete("$line.0", "$line.end + 1 chars");
|
160
|
0
|
|
|
|
|
|
return $text;
|
161
|
|
|
|
|
|
|
}
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
1;
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
__END__
|