line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tk::FilterEntry;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7082
|
use vars qw($VERSION);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
4
|
|
|
|
|
|
|
$VERSION = '0.02';
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
8
|
use strict;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
7
|
1
|
|
|
1
|
|
1569
|
use Tk;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Tk::Entry;
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use base qw(Tk::Derived Tk::Entry);
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Construct Tk::Widget 'FilterEntry';
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub ClassInit {
|
15
|
|
|
|
|
|
|
my ($class, $mw) = @_;
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$class->SUPER::ClassInit($mw);
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$mw->bind($class, '' => \&FocusIn);
|
20
|
|
|
|
|
|
|
$mw->bind($class, '' => \&FocusOut);
|
21
|
|
|
|
|
|
|
$mw->bind($class, '' => \&FocusOut);
|
22
|
|
|
|
|
|
|
}
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub Populate {
|
25
|
|
|
|
|
|
|
my ($self, $args) = @_;
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$self->SUPER::Populate($args);
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$self->ConfigSpecs(
|
30
|
|
|
|
|
|
|
-background => ['PASSIVE', 'background', undef, 'white'],
|
31
|
|
|
|
|
|
|
-fg_valid => ['PASSIVE', 'fg_valid', undef, 'black'],
|
32
|
|
|
|
|
|
|
-fg_invalid => ['PASSIVE', 'fg_invalid', undef, 'red'],
|
33
|
|
|
|
|
|
|
-filter => ['PASSIVE', 'filter', undef, '.*'],
|
34
|
|
|
|
|
|
|
-anchors => ['PASSIVE', 'anchors', undef, 1],
|
35
|
|
|
|
|
|
|
-trim => ['PASSIVE', 'trim', undef, 1],
|
36
|
|
|
|
|
|
|
);
|
37
|
|
|
|
|
|
|
}
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub FocusIn {
|
40
|
|
|
|
|
|
|
my $self = shift;
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $fg = $self->cget(-fg_valid);
|
43
|
|
|
|
|
|
|
$self->Tk::Entry::configure(-foreground => $fg);
|
44
|
|
|
|
|
|
|
}
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub FocusOut {
|
47
|
|
|
|
|
|
|
my $self = shift;
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $filter = $self->cget(-filter);
|
50
|
|
|
|
|
|
|
my $trim = $self->cget(-trim);
|
51
|
|
|
|
|
|
|
my $anchors = $self->cget(-anchors);
|
52
|
|
|
|
|
|
|
$filter = '\s*' . $filter . '\s*' if ($trim);
|
53
|
|
|
|
|
|
|
$filter = '^' . $filter . '$' if ($anchors);
|
54
|
|
|
|
|
|
|
my $value = $self->get();
|
55
|
|
|
|
|
|
|
my $r_vcmd = $self->cget(-validatecommand);
|
56
|
|
|
|
|
|
|
my (@vcmd, $vcmd);
|
57
|
|
|
|
|
|
|
if (defined $r_vcmd) {
|
58
|
|
|
|
|
|
|
@vcmd = @{$r_vcmd};
|
59
|
|
|
|
|
|
|
$vcmd = shift @vcmd;
|
60
|
|
|
|
|
|
|
}
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
if ( ( defined $vcmd and ! &{$vcmd}($self, @vcmd) )
|
63
|
|
|
|
|
|
|
or ( defined $filter and ( $value !~ /$filter/ ) ) ) {
|
64
|
|
|
|
|
|
|
my $fg = $self->cget(-fg_invalid);
|
65
|
|
|
|
|
|
|
$self->Tk::Entry::configure(-foreground => $fg);
|
66
|
|
|
|
|
|
|
my $r_invcmd = $self->cget(-invalidcommand);
|
67
|
|
|
|
|
|
|
if (defined $r_invcmd) {
|
68
|
|
|
|
|
|
|
my @invcmd = @{$r_invcmd};
|
69
|
|
|
|
|
|
|
my $invcmd = shift @invcmd;
|
70
|
|
|
|
|
|
|
&{$invcmd}($self, @invcmd);
|
71
|
|
|
|
|
|
|
}
|
72
|
|
|
|
|
|
|
}
|
73
|
|
|
|
|
|
|
}
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub validate {
|
76
|
|
|
|
|
|
|
my $self = shift;
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $r_vcmd = $self->cget(-validatecommand);
|
79
|
|
|
|
|
|
|
if (defined $r_vcmd) {
|
80
|
|
|
|
|
|
|
my @vcmd = @{$r_vcmd};
|
81
|
|
|
|
|
|
|
my $vcmd = shift @vcmd;
|
82
|
|
|
|
|
|
|
return &{$vcmd}($self, @vcmd);
|
83
|
|
|
|
|
|
|
}
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $filter = $self->cget(-filter);
|
86
|
|
|
|
|
|
|
my $trim = $self->cget(-trim);
|
87
|
|
|
|
|
|
|
my $anchors = $self->cget(-anchors);
|
88
|
|
|
|
|
|
|
$filter = '\s*' . $filter . '\s*' if ($trim);
|
89
|
|
|
|
|
|
|
$filter = '^' . $filter . '$' if ($anchors);
|
90
|
|
|
|
|
|
|
my $value = $self->get();
|
91
|
|
|
|
|
|
|
return ( $value =~ /$filter/ ) if (defined $filter);
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
return 1;
|
94
|
|
|
|
|
|
|
}
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1;
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__
|