CheckBox.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
« ChildNotification.pm ↑ Summary Columns.pm »
1 package Tk::CheckBox;
2  
3 0 ▶use Tk;
Subroutine BEGIN: called CC=1 SCAR=2.6
4 use Tk::Canvas;
5 use Tk::Frame;
6  
7 use vars qw ($VERSION);
8 use strict;
9 use Carp;
10  
11 $VERSION = '0.01';
12  
13 use base qw (Tk::Derived Tk::Frame);
14  
15 Tk::Widget->Construct ('CheckBox');
16  
17 *textvariable = \&Tk::CheckBox::TextVariable;
18 *get = \&Tk::CheckBox::CurrentState;
19 *disable = \&Tk::CheckBox::Disable;
20 *enable = \&Tk::CheckBox::Enable;
21 *state = \&Tk::CheckBox::State;
22 *set = \&Tk::CheckBox::State;
23  
24 sub ClassInit
25 {
26 my ($p_Class, $p_Window) = (@_);
27 $p_Window->bind ($p_Class, '<ButtonPress-1>', 'State');
28 $p_Window->bind ($p_Class, '<space>', 'State');
29 $p_Window->bind ($p_Class, '<Control-Tab>','focusNext');
30 $p_Window->bind ($p_Class, '<Control-Shift-Tab>','focusPrev');
31 $p_Window->bind ($p_Class, '<Tab>', 'focus');
32 return $p_Class;
33 }
34  
35 sub new
36 {
37 my $p_Class = shift;
38 my $this = $p_Class->SUPER::new (@_);
39 $this->MapWindow();
40  
41 my $l_Canvas = $this->Component
42 (
43 'Canvas' => 'Canvas',
44 '-background' => $this->cget ('-background'),
45 '-height' => 15,
46 '-width' => 15,
47 );
48  
49 $l_Canvas->pack
50 (
51 '-fill' => 'both',
52 '-expand' => 'true',
53 );
54  
55 $this->{m_CheckMark} = $l_Canvas->create
56 (
57 'polygon',
58 0, 8,
59 3, 12,
60 4, 14,
61 4, 15,
62 11, 4,
63 15, 0,
64 4, 11,
65 0, 8,
66 );
67  
68 $l_Canvas->Tk::bind ('<ButtonPress-1>' => sub {$this->State();});
69 $this->bind ('<Tab>' => sub {$this->focus();});
70 $this->Enable();
71 $this->State ('off');
72 return $this;
73 }
74  
75 sub Populate
76 {
77 my ($this) = (shift, @_);
78  
79 $this->SUPER::Populate (@_);
80  
81 $this->configure ('-background' => 'white');
82  
83 $this->ConfigSpecs
84 (
85 '-foreground' => [['SELF', 'PASSIVE'], 'foreground', 'Foreground', 'red'],
86 '-textvariable' => ['METHOD', 'textvariable', 'TextVariable', \$this->{m_Value}],
87 '-borderwidth' => [['SELF', 'PASSIVE'], 'borderwidth', 'BorderWidth', 2],
88 '-relief' => [['SELF', 'PASSIVE'], 'relief', 'Relief', 'sunken'],
89 '-enable' => ['METHOD', 'Enable', 'Enable', 'true'],
90 '-state' => ['METHOD', 'State', 'State', 'on'],
91 );
92  
93 return $this;
94 }
95  
96 sub Disable
97 {
98 $_[0]->Enable ('false');
99 }
100  
101 sub Enable
102 {
103 $_[0]->{m_Enabled} = ($_[1] eq 'true' || ! defined ($_[1]));
104 }
105  
106 sub State
107 {
108 my ($this, $p_State) = (shift, @_);
109 my $l_Canvas = $this->Subwidget ('Canvas');
110  
111 $this->{m_State} =
112 (
113 $this->{m_Enabled} ?
114 (
115 defined ($p_State) ?
116 ($p_State eq 'on' || $p_State eq 'true' || $p_State > 0 || $p_State < 0) :
117 (! $this->{m_State})
118 ) :
119 $this->{m_State}
120 );
121  
122 my $l_Color =
123 (
124 $this->{m_State} ?
125 $this->cget ('-foreground') :
126 $this->cget ('-background')
127 );
128  
129 if (Exists ($l_Canvas))
130 {
131 $l_Canvas->itemconfigure
132 (
133 $this->{m_CheckMark},
134 '-outline' => $l_Color,
135 '-fill' => $l_Color,
136 );
137 }
138  
139 if (defined ($this->{m_TextVariable} = $this->{Configure}{-textvariable}))
140 {
141 ${$this->{m_TextVariable}} = $this->{m_State};
142 }
143 }
144  
145 sub TextVariable
146 {
147 my ($this, $p_Reference) = (shift, @_);
148  
149 return $this->{m_TextVariable} unless (defined ($p_Reference));
150  
151 $this->afterCancel ($this->{m_AfterID}) if (defined ($this->{m_AfterID}));
152  
153 $this->{m_AfterID} = $this->repeat
154 (
155 1000,
156 sub {$this->State (${$p_Reference});}
157 );
158  
159 return ($this->{m_TextVariable} = $p_Reference);
160 }
161  
162 sub CurrentState
163 {
164 return $_[0]->{m_State};
165 }
166
167 1;
168 __END__
« ChildNotification.pm ↑ Summary Columns.pm »