HP_16C.pm untested

filter: Statementstmt 0.0% 0 / 185 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 230 CC 15 SCAR 28.7
CC
15
Cov
0%
Populate
30.0
bspclx
30.0
roll_stack
20.0
CRAP 17.6
1 $Tk::Calculator::RPN::HP_16C::VERSION = '1.2';
2  
3 package Tk::Calculator::RPN::HP_16C;
4  
5 use Tk::widgets qw/Compound Frame ROText/;
6 use Tk::Calculator::RPN::HP;
7 use Tk::LCD 1.2;
8 use base qw/Tk::Calculator::RPN::HP/;
9 use strict;
10  
11 our $HELP;
12  
13 sub ClassInit {
14  
15 my ($class, $mw) = @_;
16  
17 $HELP = $class->build_help_window($mw);
18 $class->SUPER::ClassInit($mw);
19  
20 } # end ClassInit
21  
22 sub build_button_rows {
23  
24 my ($self, $parent, $button_descriptions) = @_;
25  
26 foreach my $row (@$button_descriptions) {
27 my $frame = $parent->Frame(-background => $GRAY_LIGHTEST);
28 foreach my $buttons (@$row) {
29 my ($p1, $p2, $p3, $color, $func) = @$buttons;
30  
31 $frame->Tk::Calculator::RPN::HP::Key3_16C(
32 -topl => $p2,
33 -butl => $p1,
34 -botl => $p3,
35 -background => $color,
36 -command => $func,
37 );
38 }
39 $frame->pack(qw/-side top -expand 1 -fill both/);
40 $self->{PB}->set($self->{PB_PERCENT} += 10) if $self->{PB};
41 }
42  
43 } # end build_button_rows
44  
45 sub Populate {
46  
47 my ($self, $args) = @_;
48  
49 $self->{RCFILE} = $^O eq "MSWin32" ?
50 'C:\.hp\hp16c' : "$ENV{HOME}/.hp/hp16c";
51  
52 $self->on; $self->on; # on/off kluge to initialize HP stack
53  
54 # LED display, help button, and HP logo.
55  
56 my $tf = $self->Frame(-background => $SILVER);
57 $tf->pack(qw/-side top -fill both -expand 1/);
58  
59 my $lcdbg = 'honeydew4';
60 my $lcdf = $tf->Frame(
61 -relief => 'sunken',
62 -borderwidth => 10,
63 -background => $lcdbg,
64 )->pack(qw/-side left -expand 1 -fill x -padx 70/);
65  
66 $self->build_help_button($tf, $HELP)->pack(qw/-side left/);
67  
68 $lcdf->LCD(
69 -background => $lcdbg,
70 -elements => 1 + 10,
71 -highlightthickness => 0,
72 -offfill => $lcdbg,
73 -offoutline => $lcdbg,
74 -onfill => 'black',
75 -onoutline => 'black',
76 -size => 'small',
77 -variable => \$self->{XV},
78 )->pack;
79  
80 my $model = " hp \n--\n16C";
81 my $hp = $tf->Button(
82 -text => $model,
83 -relief => 'raised',
84 -command => sub {
85 $self->{ONOFF} = 1;
86 $self->on;
87 &Tk::exit;
88 },
89 );
90 $hp->pack(qw/-side right -expand 1 -fill both -padx 20 -pady 10/);
91 $hp->bind('<Enter>' => sub {$_[0]->configure(-text => "Quit\n--\n16C")});
92 $hp->bind('<Leave>' => sub {$_[0]->configure(-text => $model)});
93  
94 $self->{PB}->set($self->{PB_PERCENT} += 10) if $self->{PB};
95  
96 # Horizontal black and silver lines + vertical left/right silver lines.
97  
98 $self->Frame(qw/-background black -height 10/)->pack(qw/-fill x -expand 1/);
99 $self->Frame(-bg => $SILVER, -height => 5)->pack(qw/-fill x -expand 1/);
100  
101 my $frame0 = $self->Frame(-background => $GRAY_LIGHTEST);
102 $frame0->pack(qw/-side top -fill both -expand 1/);
103  
104 $frame0->Frame(-width => 5, -bg => $SILVER)->
105 pack(qw/-side left -expand 1 -fill y/);
106 $frame0->Frame(-width => 5, -bg => $SILVER)->
107 pack(qw/-side right -expand 1 -fill y/);
108  
109 # These frames hold all the calculator keys.
110  
111 my $frame1 = $frame0->Frame->pack(qw/-side top -fill both -expand 1/);
112 my $frame2 = $frame0->Frame->pack(qw/-side left -fill both -expand 1/);
113 my $frame3 = $frame0->Frame->pack(qw/-side right -fill both -expand 1/);
114  
115 # Bottom finishing detail.
116  
117 $self->Frame(
118 -background => $SILVER,
119 -width => 20,
120 -height => 25,
121 )->pack(qw/-side left -expand 0/);
122 $self->Label(
123 -text => ' H E W L E T T . P A C K A R D ',
124 -font => ['courier', 14, 'bold'],
125 -foreground => $SILVER,
126 -background => $GRAY_LIGHTEST,
127 )->pack(qw/-side left -expand 0/);
128 $self->Frame(
129 -background => $SILVER,
130 -height => 25,
131 )->pack(qw/-side left -expand 1 -fill x/);
132  
133 $self->Frame(
134 -background => $SILVER,
135 -width => 5,
136 -height => 25,
137 )->pack(qw/-side left -expand 0/);
138  
139 $self->{PB}->set($self->{PB_PERCENT} += 10) if $self->{PB};
140  
141 # Build the first 2 rows of the calculator, 10 calculator keys per row.
142  
143 build_button_rows $self, $frame1, [
144 [
145 ['A', 'SL', 'LJ', $GRAY, [$self => 'err']],
146 ['B', 'SR', 'ASR', $GRAY, [$self => 'err']],
147 ['C', 'RL', 'RLC', $GRAY, [$self => 'err']],
148 ['D', 'RR', 'RRC', $GRAY, [$self => 'err']],
149 ['E', 'RLn', 'RLCn', $GRAY, [$self => 'err']],
150 ['F', 'RRn', 'RRCn', $GRAY, [$self => 'err']],
151 ['7', 'MASKL', '#B', $GRAY, [$self => 'key', 7]],
152 ['8', 'MASKR', 'ABS', $GRAY, [$self => 'key', 8]],
153 ['9', 'RMD', 'DBLR', $GRAY, [$self => 'key', 9]],
154 ['/', 'XOR', 'DBL/', $GRAY, [$self => 'math3', $DV, $XR, $DD]],
155 ],
156 [
157 ['GSB', 'x><(i)', 'RTN', $GRAY, [$self => 'err']],
158 ['GTO', 'x><I', 'LBL', $GRAY, [$self => 'err']],
159 ['HEX', 'Show', 'DSZ', $GRAY, [$self => 'err']],
160 ['DEC', 'Show', 'ISZ', $GRAY, [$self => 'err']],
161 ['OCT', 'Show', 'sqrt', $GRAY, [$self => 'gmath', $SQ]],
162 ['BIN', 'Show', '1/x', $GRAY, [$self => 'gmath', $RP]],
163 ['4', 'SB', 'SF', $GRAY, [$self => 'key', 4]],
164 ['5', 'CB', 'CF', $GRAY, [$self => 'key', 5]],
165 ['6', 'B?', 'F?', $GRAY, [$self => 'key', 6]],
166 ['x', 'AND', 'DBLx', $GRAY, [$self => 'math3', $ML, $AN, $DM]],
167 ],
168 ];
169  
170 # Build the leftmost 5 calculator keys of the last 2 rows.
171  
172 build_button_rows $self, $frame2, [
173 [
174 ['R/S', '(i)', 'p/r', $GRAY, [$self => 'err']],
175 ['SST', 'I', 'BST', $GRAY, [$self => 'err']],
176 [$ROLD, 'cPRGM', $ROLU, $GRAY, [$self => 'roll_stack']],
177 [$SWAP, 'cREG', 'PSE', $GRAY, [$self => 'swapxy']],
178 ['BSP', 'cPREFIX', 'CLx', $GRAY, [$self => 'bspclx']],
179 ],
180 [
181 ['ON', '', '', $GRAY, [$self => 'on']],
182 ['f', '', '', $ORANGE, [$self => 'f']],
183 ['g', '', '', $BLUE, [$self => 'g']],
184 ['STO', 'WSIZE', '<', $GRAY, [$self => 'err']],
185 ['RCL', 'FLOAT', '>', $GRAY, [$self => 'err']],
186 ],
187 ];
188  
189 # The 2 column high ENTER key divides the last 2 rows of calculator keys.
190  
191 my $enter = $frame0->Tk::Calculator::RPN::HP::Key3_16C(
192 -topl => 'WINDOW',
193 -butl => "E\nN\nT\nE\nR",
194 -botl => 'LSTx',
195 -background => $GRAY,
196 -command => [$self => 'enter'],
197 -height => 6,
198 );
199 $enter->pack(qw/-side left -expand 1 -fill both/);
200  
201 # Build the rightmost 4 calculator keys of the last two rows.
202  
203 build_button_rows $self, $frame3, [
204 [
205 ['1', '1\'S', 'X<=y', $GRAY, [$self => 'key', 1]],
206 ['2', '2\'S', 'x<0', $GRAY, [$self => 'key', 2]],
207 ['3', 'UNSGN', 'x>y', $GRAY, [$self => 'key', 3]],
208 ['-', 'NOT', 'x>0', $GRAY, [$self => 'math3', $SB, undef, undef]],
209 ],
210 [
211 ['0', 'MEM', 'x!=y', $GRAY, [$self => 'key', 0]],
212 ['.', 'STATUS', 'x!=0', $GRAY, [$self => 'key', '.']],
213 ['CHS', 'EEX', 'x=y', $GRAY, [$self => 'chs']],
214 ['+', 'OR', 'x=0', $GRAY, [$self => 'math3', $AD, $IO, undef]],
215 ],
216 ];
217  
218 $self->set_keypad_bindings;
219
220 $self->{PB}->set($self->{PB_PERCENT} = 90) if $self->{PB};
221  
222 } # end Populate
223  
224 # Function key processors.
225  
226 sub bspclx {
227  
228 my ($self) = @_;
229  
230 return unless $self->{ONOFF};
231 if ($self->{F_PRESSED}) {
232 $self->bell;
233 $self->end;
234 return;
235 }
236  
237 if ($self->{G_PRESSED}) { # CLx
238 $self->clx;
239 } else {
240 if (length($self->{STACK}[0]) <= 2) { # BKSP
241 $self->{STACK}[0] = 0;
242 $self->{CLRX} = 1;
243 $self->{PUSHX} = 0;
244 } else {
245 chop $self->{STACK}[0];
246 }
247 $self->end;
248 }
249  
250 } # end bspclx
251  
252 sub gmath {
253
254 my ($self, $func) = @_;
255  
256 return unless $self->{ONOFF};
257 if ($self->{G_PRESSED}) {
258 $self->math($func);
259 } else {
260 $self->err;
261 }
262  
263 } # end gmath
264  
265 sub roll_stack {
266  
267 my ($self) = @_;
268  
269 return unless $self->{ONOFF};
270 if ($self->{F_PRESSED}) {
271 $self->bell;
272 $self->end;
273 return;
274 }
275  
276 if ($self->{G_PRESSED}) {
277 $self->roll_up;
278 } else {
279 $self->roll_down;
280 }
281  
282 } # end rollstack
283  
284 1;
285  
286 =head1 AUTHOR
287  
288 sol0@Lehigh.EDU
289  
290 Copyright (C) 2001 - 2007, Steve Lidie. All rights reserved.
291  
292 This program is free software; you can redistribute it and/or
293 modify it under the same terms as Perl itself.
294  
295 =head1 KEYWORDS
296  
297 calculator, HP, RPN, HP 16C
298  
299 =cut