AppWindow/Ext/StatusBar/SMessageItem.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 58 CC 2 SCAR 10.3
CC
2
Cov
0%
Message
6.0
Populate
2.0
Clear
2.0
CRAP 2.8
1 package Tk::AppWindow::Ext::StatusBar::SMessageItem;
2  
3 use strict;
4 use warnings;
5 use Tk;
6 use base qw(Tk::AppWindow::Ext::StatusBar::SBaseItem);
7 Construct Tk::Widget 'SMessageItem';
8  
9 sub Populate {
10 my ($self,$args) = @_;
11  
12 $self->SUPER::Populate($args);
13  
14 my $e = $self->Label(
15 -text => ' ',
16 -anchor => 'w',
17 )->pack(-side => 'left', -expand => 1, -fill => 'x');
18 $self->{L} = $e;
19 $self->{COLORBCK} = $e->cget('-foreground');
20 $self->toplevel->bind('<Any-KeyPress>', sub { $self->Clear });
21 $self->toplevel->bind('<Button-1>', sub { $self->Clear });
22 $self->ConfigSpecs(
23 -borderwidth => ['SELF'],
24 -relief => ['SELF'],
25 DEFAULT => [$e],
26 );
27 $self->Delegates(
28 'DEFAULT' => $e,
29 );
30 }
31  
32 sub Clear {
33 $_[0]->configure(
34 -text => '',
35 -foreground => $_[0]->{COLORBCK},
36 );
37 }
38  
39 sub Message {
40 my ($self, $message, $color) = @_;
41 $color = $self->{COLORBCK} unless defined $color;
42  
43 #shorten message if it is larger than the label allows.
44 my $l = $self->{L};
45 my $lw = $l->width;
46 my $font = $l->cget('-font');
47 my $width = $self->fontMeasure($font, $message);
48 while ($width > $lw) {
49 $message = substr($message, 0, length($message) - 1);
50 $width = $self->fontMeasure($font, $message);
51 }
52  
53 $self->configure(
54 -text => $message,
55 -foreground => $color,
56 );
57 }
58  
59 sub Remove {
60 my $self = shift;
61 $self->toplevel->bindRelease('<Any-KeyPress>');
62 $self->toplevel->bindRelease('<Button-1>');
63 $self->SUPER::Remove;
64 }
65  
66 sub Update {}
67  
68 1;
69