| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Tk::HexEntryPlain; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2749
|
use Tk (); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use Tk::Derived; |
|
5
|
|
|
|
|
|
|
use Tk::Entry; |
|
6
|
|
|
|
|
|
|
use strict; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use vars qw(@ISA $VERSION); |
|
9
|
|
|
|
|
|
|
@ISA = qw(Tk::Derived Tk::Entry); |
|
10
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 0.01 $ =~ /(\d+)\.(\d+)/); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Construct Tk::Widget 'HexEntryPlain'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub ClassInit { |
|
15
|
|
|
|
|
|
|
my ($class,$mw) = @_; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$class->SUPER::ClassInit($mw); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$mw->bind($class,'', 'Leave'); |
|
20
|
|
|
|
|
|
|
$mw->bind($class,'', 'Leave'); |
|
21
|
|
|
|
|
|
|
$mw->bind($class,'', 'Return'); |
|
22
|
|
|
|
|
|
|
$mw->bind($class,'', 'Up'); |
|
23
|
|
|
|
|
|
|
$mw->bind($class,'', 'Down'); |
|
24
|
|
|
|
|
|
|
$mw->bind($class,'', 'Home'); |
|
25
|
|
|
|
|
|
|
$mw->bind($class,'', 'End'); |
|
26
|
|
|
|
|
|
|
$mw->bind($class,'', 'Prior'); |
|
27
|
|
|
|
|
|
|
$mw->bind($class,'', 'Next'); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
## Bindings callbacks |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub Leave { |
|
34
|
|
|
|
|
|
|
my $e = shift; |
|
35
|
|
|
|
|
|
|
$e->incdec(0); # range check |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub Return { |
|
39
|
|
|
|
|
|
|
my $e = shift; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $v = $e->value; # range check |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$e->Callback(-command => $v); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub Up { |
|
47
|
|
|
|
|
|
|
my $e = shift; |
|
48
|
|
|
|
|
|
|
$e->incdec($e->cget(-increment)); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub Down { |
|
52
|
|
|
|
|
|
|
my $e = shift; |
|
53
|
|
|
|
|
|
|
$e->incdec(-$e->cget(-increment)); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub Prior { |
|
57
|
|
|
|
|
|
|
my $e = shift; |
|
58
|
|
|
|
|
|
|
$e->incdec($e->cget(-bigincrement) || 1); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub Next { |
|
62
|
|
|
|
|
|
|
my $e = shift; |
|
63
|
|
|
|
|
|
|
$e->incdec(-($e->cget(-bigincrement) || 1)); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub Insert { |
|
67
|
|
|
|
|
|
|
my($e,$c) = @_; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $dot = ($e->cget(-increment) =~ /\./ ? '.' : ''); |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
if($c =~ /^[-0-9A-Fa-f$dot]$/) { |
|
72
|
|
|
|
|
|
|
$e->SUPER::Insert($c); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
elsif(defined($c) && length($c)) { |
|
75
|
|
|
|
|
|
|
$e->_ringBell; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub Home { |
|
80
|
|
|
|
|
|
|
my $e = shift; |
|
81
|
|
|
|
|
|
|
my $min_val = $e->cget(-minvalue); |
|
82
|
|
|
|
|
|
|
return unless defined $min_val; |
|
83
|
|
|
|
|
|
|
$e->value($min_val); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub End { |
|
87
|
|
|
|
|
|
|
my $e = shift; |
|
88
|
|
|
|
|
|
|
my $max_val = $e->cget(-maxvalue); |
|
89
|
|
|
|
|
|
|
return unless defined $max_val; |
|
90
|
|
|
|
|
|
|
$e->value($max_val); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
## Widget constructor |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub Populate { |
|
96
|
|
|
|
|
|
|
my ($e, $args) = @_; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# $e->SUPER::Populate($args); |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$e->ConfigSpecs( |
|
102
|
|
|
|
|
|
|
-value => [METHOD => undef, undef, "0" ], |
|
103
|
|
|
|
|
|
|
-defaultvalue => [PASSIVE => undef, undef, undef ], |
|
104
|
|
|
|
|
|
|
-maxvalue => [PASSIVE => undef, undef, undef ], |
|
105
|
|
|
|
|
|
|
-minvalue => [PASSIVE => undef, undef, undef ], |
|
106
|
|
|
|
|
|
|
-bell => [PASSIVE => "bell", "Bell", 1 ], |
|
107
|
|
|
|
|
|
|
-command => [CALLBACK => undef, undef, undef ], |
|
108
|
|
|
|
|
|
|
-increment => [PASSIVE => undef, undef, 1 ], |
|
109
|
|
|
|
|
|
|
-bigincrement => [PASSIVE => undef, undef, undef ], |
|
110
|
|
|
|
|
|
|
); |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
## Options implementation |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub value { |
|
117
|
|
|
|
|
|
|
my $e = shift; |
|
118
|
|
|
|
|
|
|
my $old; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
if(@_) { |
|
121
|
|
|
|
|
|
|
my $new = shift; |
|
122
|
|
|
|
|
|
|
my $pos = $e->index('insert'); |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
$old = $e->get; |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
$e->delete(0,'end'); |
|
127
|
|
|
|
|
|
|
$e->insert(0,$new); |
|
128
|
|
|
|
|
|
|
$e->icursor($pos); |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
else { |
|
131
|
|
|
|
|
|
|
$e->incdec(0); # range check |
|
132
|
|
|
|
|
|
|
$old = $e->get; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# Do a range check after all configuration has finished, |
|
136
|
|
|
|
|
|
|
# as we may not yet know the range |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$e->afterIdle([ $e => 'incdec', 0]); |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
length($old) ? $old + 0 : $e->{Configure}{'-defaultvalue'}; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub _ringBell { |
|
144
|
|
|
|
|
|
|
my $e = shift; |
|
145
|
|
|
|
|
|
|
my $v; |
|
146
|
|
|
|
|
|
|
return |
|
147
|
|
|
|
|
|
|
unless defined($v = $e->{Configure}{'-bell'}); |
|
148
|
|
|
|
|
|
|
$e->bell |
|
149
|
|
|
|
|
|
|
if(($v =~ /^[0-9a-f]+$/ && $v) || $v =~ /^true$/i); |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub incdec { |
|
154
|
|
|
|
|
|
|
my($e,$inc) = @_; |
|
155
|
|
|
|
|
|
|
my $val = hex($e->get); |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
if(! $inc && $val =~ /^-?$/) { |
|
158
|
|
|
|
|
|
|
$val = ""; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
else { |
|
161
|
|
|
|
|
|
|
my $min = $e->{Configure}{'-minvalue'}; |
|
162
|
|
|
|
|
|
|
my $max = $e->{Configure}{'-maxvalue'}; |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
$val = 0 if !$val; |
|
165
|
|
|
|
|
|
|
$val = $val + $inc; |
|
166
|
|
|
|
|
|
|
my $limit = undef; |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
$limit = $val = $min |
|
169
|
|
|
|
|
|
|
if(defined($min) && $val < $min); |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$limit = $val = $max |
|
172
|
|
|
|
|
|
|
if(defined($max) && $val > $max); |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
if(defined $limit) { |
|
175
|
|
|
|
|
|
|
$e->_ringBell |
|
176
|
|
|
|
|
|
|
if $inc; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
my $pos = $e->index('insert'); |
|
181
|
|
|
|
|
|
|
$e->delete(0,'end'); |
|
182
|
|
|
|
|
|
|
$e->insert(0, hx($val)); |
|
183
|
|
|
|
|
|
|
$e->icursor($pos); |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub hx { |
|
187
|
|
|
|
|
|
|
my $value = shift; |
|
188
|
|
|
|
|
|
|
return sprintf('%x', $value); |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
__END__ |