ListBrowser/Item.pm

filter: Statementstmt 8.9% 39 / 436 Branchbran 2.5% 5 / 198 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 23.9% 11 / 46 Podpod 15.0% 6 / 40 totaltotal 8.1% 61 / 750 CC 110 SCAR 47.2
CC
110
Cov
7%
draw
462.0
requestedSize
240.0
drawSelect
132.0
CRAP 111.7
« ListBrowser.pm ↑ Summary ListBrowser/SelectXPM.pm »
1 package Tk::ListBrowser::Item;
2  
3 =head1 NAME
4  
5 Tk::ListBrowser::Item - Side column item holding object.
6  
7 =cut
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use vars qw ($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 require Tk::ListBrowser::SelectXPM;
14 1 ▶use Math::Round qw(round);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 $VERSION = 0.16;
17  
18 1 ▶use base qw(Tk::ListBrowser::BaseItem);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 #used in formatText
21 1 my $dlmreg = qr/\.|\(|\)|\:|\!|\+|\,|\-|\<|\=|\>|\%|\&|\*|\"|\'|\/|\;|\?|\[|\]|\^|\{|\||\}|\~|\\|\$|\@|\#|\`|\s/;
22  
23 =head1 SYNOPSIS
24  
25 my $entry = $listbrowser->add($entryname, @entryoptions);
26  
27 my $item = $listbrowser->itemCreate($entryname, $columnname, @itemoptions);
28  
29 =head1 DESCRIPTION
30  
31 Inherits L<Tk::ListBrowser::BaseItem>.
32  
33 This module creates an object that holds all information of
34 a cell in a side column. You will never need to create an
35 item object yourself.
36  
37 Besides the options in it's parent, you can use the I<-data>, I<-image>,
38 and I<-text> options.
39  
40 =head1 METHODS
41  
42 =over 4
43  
44 =cut
45  
46 4 ▶sub new {
Subroutine new: called CC=3 SCAR=11.2
Pod undocumented
47 4 my $class = shift;
48 4 my $self = $class->SUPER::new(@_);
49 4 ▶ $self->drawrect(1) unless $self->configSet('-drawrect');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->configSet("-drawrect") 4 0 4
50 4 ▶ $self->croptext(1) unless $self->configSet('-croptext');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->configSet("-croptext") 4 0 4
51 4 $self->rectX(0);
52 4 $self->rectY(0);
53 4 return $self
54 }
55  
56 0 ▶sub cimage {
Subroutine cimage: not called CC=2 SCAR=17.9
Pod undocumented
57 0 my $self = shift;
58 0 ▶ $self->{CIMAGE} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
59 return $self->{CIMAGE}
60 0 }
61  
62 0 ▶sub clear {
Subroutine clear: not called CC=3 SCAR=24.8
Pod documented
63 0 my $self = shift;
64 0 my $c = $self->Subwidget('Canvas');
65 0 for ($self->cimage, $self->ctext) {
66 0 ▶ $c->delete($_) if defined $_;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_ 0 0 0
67 }
68  
69 0 $self->cimage(undef);
70 0 $self->ctext(undef);
71 0 $self->row(undef);
72 0 $self->column(undef);
73 0 $self->rectX(0);
74 0 $self->rectY(0);
75 0 $self->SUPER::clear;
76 }
77  
78 0 ▶sub column {
Subroutine column: not called CC=2 SCAR=17.9
Pod undocumented
79 0 my $self = shift;
80 0 ▶ $self->{COLUMN} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
81 return $self->{COLUMN}
82 0 }
83  
84 4 ▶sub croptext {
Subroutine croptext: called CC=2 SCAR=7.1
Pod undocumented
85 4 my $self = shift;
86 4 ▶ $self->{CROPTEXT} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 4 0 4
87 return $self->{CROPTEXT}
88 4 }
89  
90 0 ▶sub ctext {
Subroutine ctext: not called CC=2 SCAR=17.9
Pod undocumented
91 0 my $self = shift;
92 0 ▶ $self->{CTEXT} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
93 return $self->{CTEXT}
94 0 }
95  
96 0 ▶sub data {
Subroutine data: not called CC=2 SCAR=17.9
Pod undocumented
97 0 my $self = shift;
98 0 ▶ $self->{DATA} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
99 return $self->{DATA}
100 0 }
101  
102 0 ▶sub deleteImage {
Subroutine deleteImage: not called CC=2 SCAR=17.9
Pod undocumented
103 0 my $self = shift;
104 0 my $i = $self->cimage;
105 0 ▶ return unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 0 0 0
106  
107 0 my $c = $self->Subwidget('Canvas');
108 0 $c->delete($i);
109 0 $self->cimage(undef);
110 }
111  
112 0 ▶sub deleteRect {
Subroutine deleteRect: not called CC=2 SCAR=17.9
Pod undocumented
113 0 my $self = shift;
114 0 my $r = $self->crect;
115 0 ▶ return unless defined $r;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r 0 0 0
116  
117 0 my $c = $self->Subwidget('Canvas');
118 0 $c->delete($r);
119 0 $self->crect(undef);
120 }
121  
122 0 ▶sub deleteSelect {
Subroutine deleteSelect: not called CC=1 SCAR=6.9
Pod undocumented
123 0 my $self = shift;
124 0 $self->deleteRect;
125 }
126  
127 0 ▶sub deleteText {
Subroutine deleteText: not called CC=2 SCAR=17.9
Pod undocumented
128 0 my $self = shift;
129 0 my $t = $self->ctext;
130 0 ▶ return unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 0 0
131  
132 0 my $c = $self->Subwidget('Canvas');
133 0 $c->delete($t);
134 0 $self->ctext(undef);
135 }
136  
137 0 ▶sub draw {
Subroutine draw: not called CC=21 SCAR=61.4
Pod undocumented
138 0 my ($self, $x, $y, $column, $row, $type) = @_;
139  
140 0 my $image = $self->image;
141 0 my $ih = 0;
142 0 my $iw = 0;
143 0 ▶ if (defined $image) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $image) 0 0 0
144 0 $ih = $image->height;
145 0 $iw = $image->width;
146 }
147  
148 0 my $text = $self->text;
149 0 my $th = 0;
150 0 my $tw = 0;
151 0 ▶ if (defined $text) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text) 0 0 0
152 0 my $textf = $self->textFormat($text);
153 0 $th = $self->textHeight($textf);
154 0 $tw = $self->textWidth($textf);
155 0 $self->textFormatted($textf);
156 }
157  
158 0 my $imageoffsetx = 0;
159 0 my $imageoffsety = 0;
160 0 my $textoffsetx = 0;
161 0 my $textoffsety = 0;
162 0 my @textcavity = (0, 0, 0, 0);
163  
164 0 my $owner = $self->owner;
165  
166 0 my $cellheight = $owner->cget('-cellheight');
167 0 my $cellwidth = $owner->cget('-cellwidth');
168 0 my $imageheight = $owner->cget('-cellimageheight');
169 0 my $imagewidth = $owner->cget('-cellimagewidth');
170 0 my $textheight = $owner->cget('-celltextheight');
171 0 my $textwidth = $owner->cget('-celltextwidth');
172  
173 0 my $itemtype = $owner->cget('-itemtype');
174 0 ▶ if ($itemtype eq 'image') {
Branch: 2 branches
BranchTrueFalseTotal
if ($itemtype eq 'image') { } 0 0 0
elsif ($itemtype eq 'text') { } 0 0 0
175 0 $imageoffsetx = int(($cellwidth - $iw)/2);
176 0 $imageoffsety = int(($cellheight - $ih)/2);
177 } elsif ($itemtype eq 'text') {
178 0 @textcavity = (0 ,0, $cellwidth, $cellheight)
179 } else {
180 0 my $textside = $owner->cget('-textside');
181 0 ▶ if ($textside eq 'top') {
Branch: 4 branches
BranchTrueFalseTotal
if ($textside eq 'top') { } 0 0 0
elsif ($textside eq 'bottom') { } 0 0 0
elsif ($textside eq 'left') { } 0 0 0
elsif ($textside eq 'right') { } 0 0 0
182 0 @textcavity = (0, 0, $cellwidth, $textheight);
183 0 $imageoffsety = $textheight + int(($imageheight - $ih)/2);
184 0 $imageoffsetx = $imageoffsetx + int(($cellwidth - $iw)/2);
185 } elsif ($textside eq 'bottom') {
186 0 @textcavity = (0, $imageheight, $cellwidth, $cellheight);
187 0 $imageoffsetx = $imageoffsetx + int(($cellwidth - $iw)/2);
188 0 $imageoffsety = $imageoffsety + int(($imageheight - $ih)/2);
189 } elsif ($textside eq 'left') {
190 0 @textcavity = (0, 0, $textwidth, $cellheight);
191 0 $imageoffsety = $imageoffsety + int(($cellheight - $ih)/2);
192 0 $imageoffsetx = $textwidth;
193 } elsif ($textside eq 'right') {
194 0 @textcavity = ($imagewidth, 0, $cellwidth, $cellheight);
195 0 $imageoffsety = $imageoffsety + int(($cellheight - $ih)/2);
196 0 $imageoffsetx = int(($imagewidth - $iw)/2);
197 }
198 }
199  
200 0 my $centerx = $textcavity[0] + int(($textcavity[2] - $textcavity[0] - $tw)/2);
201 0 my $centery = $textcavity[1] + int(($textcavity[3] - $textcavity[1] - $th)/2);
202  
203 0 my $lb = $self->listbrowser;
204 0 my $padx = $lb->cget('-itempadx');
205 0 my $pady = $lb->cget('-itempady');
206  
207 0 my $textanchor = $owner->cget('-textanchor');
208 0 ▶ if ($textanchor eq '') {
Branch: 9 branches
BranchTrueFalseTotal
if ($textanchor eq '') { } 0 0 0
elsif ($textanchor eq 's') { } 0 0 0
elsif ($textanchor eq 'e') { } 0 0 0
elsif ($textanchor eq 'n') { } 0 0 0
elsif ($textanchor eq 'w') { } 0 0 0
elsif ($textanchor eq 'se') { } 0 0 0
elsif ($textanchor eq 'sw') { } 0 0 0
elsif ($textanchor eq 'ne') { } 0 0 0
elsif ($textanchor eq 'nw') { } 0 0 0
209 0 $textoffsetx = $centerx;
210 0 $textoffsety = $centery;
211 } elsif ($textanchor eq 's') {
212 0 $textoffsetx = $centerx;
213 0 $textoffsety = $textcavity[3] - $th - $pady;
214 } elsif ($textanchor eq 'e') {
215 0 $textoffsetx = $textcavity[2] - $tw - $padx;
216 0 $textoffsety = $centery;
217 } elsif ($textanchor eq 'n') {
218 0 $textoffsetx = $centerx;
219 0 $textoffsety = $textcavity[1] + $pady;
220 } elsif ($textanchor eq 'w') {
221 0 $textoffsetx = $textcavity[0] + $padx;
222 0 $textoffsety = $centery;
223 } elsif ($textanchor eq 'se') {
224 0 $textoffsetx = $textcavity[2] - $tw - $padx;
225 0 $textoffsety = $textcavity[3] - $th - $pady;
226 } elsif ($textanchor eq 'sw') {
227 0 $textoffsetx = $textcavity[0] + $padx;
228 0 $textoffsety = $textcavity[3] - $th - $pady;
229 } elsif ($textanchor eq 'ne') {
230 0 $textoffsetx = $textcavity[2] - $tw - $padx;
231 0 $textoffsety = $textcavity[1] + $pady;
232 } elsif ($textanchor eq 'nw') {
233 0 $textoffsetx = $textcavity[0] + $padx;
234 0 $textoffsety = $textcavity[1] + $pady;
235 }
236 0 $self->imageX($x + $imageoffsetx);
237 0 $self->imageY($y + $imageoffsety);
238 0 $self->rectX($x);
239 0 $self->rectY($y);
240 0 $self->textX($x + $textoffsetx);
241 0 $self->textY($y + $textoffsety);
242  
243 0 my $n = $self->name;
244 0 my $entry = $self->get($n);
245 0 my $e = ref $entry;
246 0 ▶ my $sel = $entry->selected and $self->ismapped;
Branch: 1 branch
BranchTrueFalseTotal
my $sel = $entry->selected and $self->ismapped 0 0 0
247 0 $self->setRegion;
248 0 ▶ $self->drawRect unless $sel;
Branch: 1 branch
BranchTrueFalseTotal
unless $sel 0 0 0
249 0 ▶ $self->drawSelect if $sel;
Branch: 1 branch
BranchTrueFalseTotal
if $sel 0 0 0
250 0 $self->drawImage;
251 0 $self->drawText;
252  
253 0 $self->column($column);
254 0 $self->row($row);
255 0 $self->ismapped(1);
256 }
257  
258 0 ▶sub drawImage {
Subroutine drawImage: not called CC=3 SCAR=24.8
Pod undocumented
259 0 my $self = shift;
260 0 my $image = $self->image;
261 0 ▶ return unless defined $image;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $image 0 0 0
262 0 ▶ return unless $self->itemtype =~ /image/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->itemtype =~ /image/ 0 0 0
263 0 $self->deleteImage;
264  
265 0 my $itag;
266 0 my $c = $self->Subwidget('Canvas');
267 0 $itag = $c->createImage($self->imageX, $self->imageY,
268 -image => $image,
269 -anchor => 'nw',
270 -tags => $self->tags,
271 );
272  
273 0 $self->cimage($itag);
274 # $self->anchorRaise($itag);
275 }
276  
277 0 ▶sub drawRect {
Subroutine drawRect: not called CC=3 SCAR=24.8
Pod undocumented
278 0 my $self = shift;
279 0 $self->deleteRect;
280 0 ▶ return unless $self->drawrect;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->drawrect 0 0 0
281 0 my $owner = $self->owner;
282 0 my $c = $self->Subwidget('Canvas');
283  
284 0 my ($x, $y, $dx, $dy) = $self->region;
285 0 ▶ $x -- unless $self->isentry; #make overlapping columns better readable
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isentry 0 0 0
286 0 my $rtag = $c->createRectangle($x, $y, $dx, $dy,
287 -fill => $self->background,
288 -outline => $self->background,
289 -tags => ['rect'],
290 );
291 # $self->anchorRaise($rtag);
292 0 $self->crect($rtag);
293 }
294  
295 0 ▶sub drawSelect {
Subroutine drawSelect: not called CC=11 SCAR=48.8
Pod undocumented
296 0 my ($self) = @_;
297 0 $self->deleteSelect;
298 0 my $lb = $self->listbrowser;
299 0 ▶ return unless $self->get($self->name)->selected ;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get($self->name)->selected 0 0 0
300 0 ▶ return unless $lb->ismapped;
Branch: 1 branch
BranchTrueFalseTotal
unless $lb->ismapped 0 0 0
301  
302 0 my $left = 1;
303 0 my $right = 1;
304 0 my $owner = $self->owner;
305 0 my $c = $lb->Subwidget('Canvas');
306 0 my $si = Tk::ListBrowser::SelectXPM->new($lb);
307 0 my @ecoords = $self->elementCoords;
308  
309 0 ▶ unless ($self->listMode) { #non list mode, keep it simple and be done
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->listMode) 0 0 0
310 0 my ($x, $y) = @ecoords;
311 0 my $pixmap = $si->selectimage(@ecoords, $left, $right);
312 0 my $image = $c->createImage($x, $y,
313 -image => $pixmap,
314 -anchor => 'nw',
315 -tags => ['sel', 'rect', $self->name],
316 );
317 0 $self->crect($image);
318 return
319 0 }
320  
321 0 my @columns = $self->columnList;
322 0 my @coords = $self->region;
323  
324 #check if we are out of the picture
325 0 ▶ return if $coords[2] < $ecoords[0];
Branch: 1 branch
BranchTrueFalseTotal
if $coords[2] < $ecoords[0] 0 0 0
326 0 ▶ return if $coords[0] > $ecoords[2];
Branch: 1 branch
BranchTrueFalseTotal
if $coords[0] > $ecoords[2] 0 0 0
327  
328 0 ▶ if ($self->isentry) { #this is an entry
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isentry) { } 0 0 0
329 0 ▶ if (@columns) { #we have to consider columns
Branch: 1 branch
BranchTrueFalseTotal
if (@columns) { } 0 0 0
330 0 $coords[0] = $ecoords[0];
331 0 $right = 0;
332 } else { #no columns
333 0 @coords = @ecoords;
334 }
335 } else { #this is a column item
336 0 $coords[0] = $coords[0] - 1; #make overlapping columns better readable.
337 0 my $lastcolumn = pop @columns;
338 0 ▶ if ($lastcolumn eq $owner->name) { #the item is in the last column
Branch: 1 branch
BranchTrueFalseTotal
if ($lastcolumn eq $owner->name) { } 0 0 0
339 0 $left = 0;
340 0 $coords[2] = $ecoords[2];
341 } else {
342 0 $left = 0;
343 0 $right = 0;
344 }
345 }
346  
347 #let's draw something
348 0 my ($x, $y) = @coords;
349 0 my $pixmap = $si->selectimage(@coords, $left, $right);
350 0 my $image = $c->createImage($x, $y,
351 -image => $pixmap,
352 -anchor => 'nw',
353 -tags => ['sel', 'rect', $self->name],
354 );
355  
356 #some administration
357 0 $self->crect($image);
358 0 my @guides = $c->find('withtag', 'guides');
359 0 ▶ $c->raise('guides', 'sel') if @guides;
Branch: 1 branch
BranchTrueFalseTotal
if @guides 0 0 0
360 0 $c->raise('indicator', 'sel');
361 0 ▶ $c->raise('indicator', 'guides') if @guides;
Branch: 1 branch
BranchTrueFalseTotal
if @guides 0 0 0
362 }
363  
364 0 ▶sub drawText {
Subroutine drawText: not called CC=5 SCAR=34.0
Pod undocumented
365 0 my $self = shift;
366 0 my $text = $self->textFormatted;
367 0 ▶ return unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 0 0
368 0 ▶ return unless $self->itemtype =~ /text/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->itemtype =~ /text/ 0 0 0
369 0 my $lb = $self->listbrowser;
370 0 $self->deleteText;
371 0 my $x = $self->textX;
372 0 my $y = $self->textY;
373 0 my $fill = $self->foreground;
374 0 ▶ $fill = $lb->cget('-selectforeground') if $self->selected;
Branch: 1 branch
BranchTrueFalseTotal
if $self->selected 0 0 0
375  
376 0 my $ttag;
377 0 my $c = $self->Subwidget('Canvas');
378 0 ▶ $ttag = $c->createText($x, $y,
Branch: 1 branch
BranchTrueFalseTotal
if defined $text 0 0 0
379 -fill => $fill,
380 -text => $text,
381 -justify => $self->textjustify,
382 -anchor => 'nw',
383 -font => $self->font,
384 -tags => $self->tags,
385 ) if defined $text;
386  
387 # $self->anchorRaise($ttag);
388 0 $self->ctext($ttag);
389  
390 # if ($self->listMode) {
391 # my $owner = $self->owner;
392 # my @cl = $self->columnList;
393 # if ($owner eq $lb) {
394 # for (@cl) {
395 # my $col = $self->columnGet($_);
396 # my $colrect = $col->crect;
397 # }
398 # }
399 # }
400 }
401  
402 0 ▶sub elementCoords {
Subroutine elementCoords: not called CC=3 SCAR=24.8
Pod undocumented
403 0 my $self = shift;
404 0 my $lb = $self->listbrowser;
405 0 my $c = $lb->Subwidget('Canvas');
406  
407 0 my @coords = $self->region;
408  
409 0 ▶ if ($self->listMode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->listMode) 0 0 0
410  
411 0 my ($width) = $lb->lastScrollRegion;
412 0 my ($cw) = $self->canvasSize;
413  
414 0 my ($xv) = $c->xview;
415  
416 0 my $x1 = int($width * $xv);
417 0 $coords[0] = $x1;
418 0 my $x2 = $cw;
419 0 ▶ if ($xv > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xv > 0) 0 0 0
420 0 $x2 = $x1 + $cw
421 }
422 0 $coords[2] = $x2;
423 }
424 return @coords
425 0 }
426  
427 0 ▶sub getRegion {
Subroutine getRegion: not called CC=8 SCAR=42.8
Pod undocumented
428 0 my $self = shift;
429 0 my $owner = $self->owner;
430 0 my $lb = $self->listbrowser;
431 0 my $x1 = $self->rectX;
432 0 my $y1 = $self->rectY;
433 0 my $x2 = $x1 + $owner->cget('-cellwidth');
434 0 my $y2 = $y1 + $owner->cget('-cellheight');
435 0 ▶ if (($self->listMode) and ($owner eq $lb)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->listMode and $owner eq $lb) 0 0 0
Condition0%0/3
$self->listMode and $owner eq $lb
!ll&&!rl&&r
000
MC/DC0%0/2
$self->listMode and $owner eq $lb
$self->listMode $owner eq $lb
Truth table0%0/3
A and B
A= $self->listModeB= $owner eq $lb
ABresult
0X0
100
111
436 0 ▶ if ($self->hierarchy){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->hierarchy) 0 0 0
437 0 $x2 = $x1 + $self->cget('-cellwidth');
438 0 my $indent = $lb->cget('-indent');
439 0 my $arrange = $lb->cget('-arrange');
440 0 ▶ if (($arrange eq 'HList') or ($arrange eq 'Tree')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arrange eq "HList" or $arrange eq "Tree") 0 0 0
Condition0%0/3
$arrange eq "HList" or $arrange eq "Tree"
l!l&&r!l&&!r
000
MC/DC0%0/2
$arrange eq "HList" or $arrange eq "Tree"
$arrange eq "HList" $arrange eq "Tree"
Truth table0%0/3
A or B
A= $arrange eq "HList"B= $arrange eq "Tree"
ABresult
1X1
011
000
441 0 $x2 = $x2 + ($indent * $lb->handler->calculateIndent($self));
442 0 ▶ $x2 = $x2 + $indent if $arrange eq 'Tree';
Branch: 1 branch
BranchTrueFalseTotal
if $arrange eq "Tree" 0 0 0
443 }
444 }
445 0 my @col = $self->columnList;
446 0 for (@col) {
447 0 my $cl = $self->columnGet($_);
448 0 $x2 = $x2 + $cl->cget('-cellwidth');
449 }
450 }
451 0 return ($x1, $y1, $x2, $y2)
452 }
453  
454 0 ▶sub image {
Subroutine image: not called CC=3 SCAR=24.8
Pod undocumented
455 0 my $self = shift;
456 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
457 0 $self->{IMAGE} = shift;
458 0 ▶ $self->drawImage if $self->ismapped;
Branch: 1 branch
BranchTrueFalseTotal
if $self->ismapped 0 0 0
459 }
460 return $self->{IMAGE}
461 0 }
462  
463 0 ▶sub imageX {
Subroutine imageX: not called CC=2 SCAR=17.9
Pod undocumented
464 0 my $self = shift;
465 0 ▶ $self->{IMAGEX} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
466 return $self->{IMAGEX}
467 0 }
468  
469 0 ▶sub imageY {
Subroutine imageY: not called CC=2 SCAR=17.9
Pod undocumented
470 0 my $self = shift;
471 0 ▶ $self->{IMAGEY} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
472 return $self->{IMAGEY}
473 0 }
474  
475 0 ▶sub isentry {
Subroutine isentry: not called CC=1 SCAR=6.9
Pod undocumented
476 0 my $self = shift;
477 0 return $self->owner eq $self->listbrowser;
478 }
479  
480 25 ▶sub name { return $_[0]->{NAME} }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
481  
482 4 ▶sub rectX {
Subroutine rectX: called CC=2 SCAR=7.1
Pod undocumented
483 4 my $self = shift;
484 4 ▶ $self->{RECTX} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 4 0 4
485 return $self->{RECTX}
486 4 }
487  
488 4 ▶sub rectY {
Subroutine rectY: called CC=2 SCAR=7.1
Pod undocumented
489 4 my $self = shift;
490 4 ▶ $self->{RECTY} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 4 0 4
491 return $self->{RECTY}
492 4 }
493  
494 0 ▶sub region {
Subroutine region: not called CC=2 SCAR=17.9
Pod undocumented
495 0 my $self = shift;
496 0 ▶ $self->{REGION} = [@_] if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
497 0 my $r = $self->{REGION};
498 0 return @$r;
499 }
500  
501 0 ▶sub requestedSize {
Subroutine requestedSize: not called CC=15 SCAR=54.8
Pod undocumented
502 0 my $self = shift;
503 0 my $cellheight = 0;
504 0 my $cellwidth = 0;;
505 0 my $imageheight = 0;
506 0 my $imagewidth = 0;
507 0 my $textheight = 0;
508 0 my $textwidth = 0;
509 0 my $image = $self->image;
510 0 ▶ if (defined $image) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $image) 0 0 0
511 0 $imageheight = $image->height;
512 0 $imagewidth = $image->width;
513 }
514 0 my $text = $self->text;
515 0 ▶ if (defined $text) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text) 0 0 0
516 0 $text = $self->textFormat($text);
517 0 $textheight = $self->textHeight($text);
518 0 $textwidth = $self->textWidth($text);
519 }
520 0 my $lb = $self->listbrowser;
521 # my $padx = $lb->cget('-itempadx');
522 # my $pady = $lb->cget('-itempady');
523 0 my $padx = 6;
524 0 my $pady = 6;
525 # $pad = 6 if $itemtype ne 'imagetext';
526 0 ▶ $imageheight = $imageheight + $pady if $imageheight > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $imageheight > 0 0 0 0
527 0 ▶ $imagewidth = $imagewidth + $padx if $imagewidth > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $imagewidth > 0 0 0 0
528 0 ▶ $textheight = $textheight + $pady if $textheight > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $textheight > 0 0 0 0
529 0 ▶ $textwidth = $textwidth + $padx if $textwidth > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $textwidth > 0 0 0 0
530 0 my $itemtype = $self->cget('-itemtype');
531  
532 0 ▶ if ($itemtype eq 'image') {
Branch: 2 branches
BranchTrueFalseTotal
if ($itemtype eq 'image') { } 0 0 0
elsif ($itemtype eq 'text') { } 0 0 0
533 0 $cellheight = $imageheight;
534 0 $cellwidth = $imagewidth;
535 } elsif ($itemtype eq 'text') {
536 0 $cellheight = $textheight;
537 0 $cellwidth = $textwidth;
538 } else {
539 0 my $textside = $self->cget('-textside');
540 0 ▶ if (($textside eq 'top') or ($textside eq 'bottom')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($textside eq 'top' or $textside eq 'bottom') { } 0 0 0
elsif ($textside eq 'left' or $textside eq 'right') { } 0 0 0
Condition0%0/3
$textside eq "top" or $textside eq "bottom"
l!l&&r!l&&!r
000
MC/DC0%0/2
$textside eq "top" or $textside eq "bottom"
$textside eq "top" $textside eq "bottom"
Truth table0%0/3
A or B
A= $textside eq "top"B= $textside eq "bottom"
ABresult
1X1
011
000
541 0 $cellheight = $imageheight + $textheight;
542 0 $cellwidth = $imagewidth;
543 0 ▶ $cellwidth = $textwidth if $textwidth > $cellwidth;
Branch: 1 branch
BranchTrueFalseTotal
if $textwidth > $cellwidth 0 0 0
544 ▶ } elsif (($textside eq 'left') or ($textside eq 'right')) {
Condition0%0/3
$textside eq "left" or $textside eq "right"
l!l&&r!l&&!r
000
MC/DC0%0/2
$textside eq "left" or $textside eq "right"
$textside eq "left" $textside eq "right"
Truth table0%0/3
A or B
A= $textside eq "left"B= $textside eq "right"
ABresult
1X1
011
000
545 0 $cellheight = $imageheight;
546 0 ▶ $cellheight = $textheight if $textheight > $cellheight;
Branch: 1 branch
BranchTrueFalseTotal
if $textheight > $cellheight 0 0 0
547 0 $cellwidth = $imagewidth + $textwidth;
548 }
549 }
550  
551 0 return ($cellwidth, $cellheight, $imagewidth, $imageheight, $textwidth, $textheight)
552 }
553  
554 0 ▶sub row {
Subroutine row: not called CC=2 SCAR=17.9
Pod undocumented
555 0 my $self = shift;
556 0 ▶ $self->{ROW} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
557 return $self->{ROW}
558 0 }
559  
560 0 ▶sub selected {
Subroutine selected: not called CC=1 SCAR=6.9
Pod undocumented
561 0 my $self = shift;
562 0 my $item = $self;
563 0 $item = $self->get($self->name);
564 return $item->{SELECTED}
565 0 }
566  
567 0 ▶sub setRegion {
Subroutine setRegion: not called CC=1 SCAR=6.9
Pod undocumented
568 0 my $self = shift;
569 0 my ($x, $y, $dx, $dy) = $self->getRegion;
570 0 $self->region($x, $y, $dx, $dy);
571 }
572  
573 0 ▶sub tags {
Subroutine tags: not called CC=2 SCAR=17.9
Pod undocumented
574 0 my $self = shift;
575 0 my $owner = $self->owner;
576 0 my @tags;
577 0 ▶ if ($owner eq $self->listbrowser) {
Branch: 1 branch
BranchTrueFalseTotal
if ($owner eq $self->listbrowser) { } 0 0 0
578 0 push @tags, 'main'
579 } else {
580 0 push @tags, $owner->crect;
581 }
582 0 return \@tags;
583 }
584  
585 0 ▶sub text {
Subroutine text: not called CC=4 SCAR=30.0
Pod undocumented
586 0 my $self = shift;
587 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
588 0 my $t = shift;
589 0 $self->{TEXT} = $t;
590 0 ▶ if ((defined $t) and ($self->ismapped)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t and $self->ismapped) 0 0 0
Condition0%0/3
defined $t and $self->ismapped
!ll&&!rl&&r
000
MC/DC0%0/2
defined $t and $self->ismapped
defined $t $self->ismapped
Truth table0%0/3
A and B
A= defined $tB= $self->ismapped
ABresult
0X0
100
111
591 0 $self->textFormatted($self->textFormat($t));
592 0 $self->drawText
593 }
594 }
595 return $self->{TEXT}
596 0 }
597  
598 =item B<textAbbreviate>I<($string, ?$size?, ?$firstsize?)>
599  
600 Shortens $string to $size by leaving out a middle part. Then returns it.
601 $size is set to 30 unless you specify it. $firstsize is set to 25% of $size
602 unless you set it.
603  
604 =cut
605  
606 0 ▶sub textAbbreviate {
Subroutine textAbbreviate: not called CC=4 SCAR=30.0
Pod documented
607 0 my ($self, $string, $size, $firstsize) = @_;
608 0 ▶ $size = 30 unless defined $size;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size 0 0 0
609 0 ▶ $firstsize = int($size / 4) unless defined $firstsize;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $firstsize 0 0 0
610 0 my $length = length($string);
611 0 ▶ if ($length > $size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > $size) 0 0 0
612 0 my $first = substr($string, 0, $firstsize) . ' ... ';
613 0 my $lastsize = $size - $firstsize - 5;
614 0 my $last = substr($string, $length - $lastsize, $lastsize);
615 0 $string = $first . $last;
616 }
617 0 return $string;
618 }
619  
620 0 ▶sub textCrop {
Subroutine textCrop: not called CC=7 SCAR=40.3
Pod undocumented
621 0 my ($self, $text) = @_;
622 # print "textCrop\n";
623 0 ▶ return $text unless $self->listMode;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->listMode 0 0 0
624 0 ▶ return $text unless $self->croptext;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->croptext 0 0 0
625 0 my $c = $self->Subwidget('Canvas');
626 0 my $owner = $self->owner;
627  
628 0 my @col = $self->columnList;
629 0 ▶ if (@col) {
Branch: 1 branch
BranchTrueFalseTotal
if (@col) 0 0 0
630 0 ▶ if (($self->isentry) or ($owner->name ne $col[@col-1])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isentry or $owner->name ne $col[@col - 1]) 0 0 0
Condition0%0/3
$self->isentry or $owner->name ne $col[@col - 1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->isentry or $owner->name ne $col[@col - 1]
$self->isentry $owner->name ne $col[@col - 1]
Truth table0%0/3
A or B
A= $self->isentryB= $owner->name ne $col[@col - 1]
ABresult
1X1
011
000
631 0 my $cellwidth = $owner->cget('-cellwidth');
632 0 my $pixlength = $self->fontMeasure($self->font, $text);
633 0 ▶ if ($pixlength > $cellwidth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pixlength > $cellwidth) 0 0 0
634 0 my $charlength = length($text);
635 0 my $pixperchar = $pixlength / $charlength;
636 0 my $newlength = int($cellwidth/$pixperchar) + 2;
637 0 $text = substr($text, 0, $newlength);
638 }
639 }
640 }
641  
642 0 return $text
643 }
644  
645 0 ▶sub textFormatted {
Subroutine textFormatted: not called CC=2 SCAR=17.9
Pod undocumented
646 0 my $self = shift;
647 0 ▶ $self->{TEXTFORMATTED} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
648 return $self->{TEXTFORMATTED}
649 0 }
650  
651  
652 =item B<textFormat>I<($text)>
653  
654 Formats, basically wraps, I<$text> taking the option I<-wraplength> into account.
655 I<$text> can be a multi line string.
656  
657 =cut
658  
659 0 ▶sub textFormat {
Subroutine textFormat: not called CC=9 SCAR=45.0
Pod documented
660 0 my ($self, $text) = @_;
661 0 my $wraplength = $self->wraplength;
662 0 my $font = $self->font;
663 0 my $length = $self->textlength;
664 0 ▶ $text = $self->textAbbreviate($text, $length) if $length > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $length > 0 0 0 0
665 0 ▶ return $self->textCrop($text) if $wraplength eq 0;
Branch: 1 branch
BranchTrueFalseTotal
if $wraplength eq 0 0 0 0
666 0 my @lines = split (/\n/, $text);
667 0 my @out;
668 0 for (@lines) {
669 0 my $line = $_;
670 0 my $length = $self->fontMeasure($font, $line);
671 0 ▶ if ($length > $wraplength) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > $wraplength) { } 0 0 0
672 0 my $res = $length / length($line);
673 0 my $oklength = int($wraplength/$res);
674 0 ▶ while (length($line) > $oklength) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $line > $oklength) 0 0 0
675 0 my $t = substr($line, 0, $oklength, '');
676 0 ▶ if ($t =~ s/([$dlmreg])([^$dlmreg]+$)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ s/([$dlmreg])([^$dlmreg]+$)//) 0 0 0
677 0 $line = "$2$line";
678 0 $t = "$t$1";
679 }
680 0 push @out, $t;
681 }
682 0 push @out, $line;
683 } else {
684 0 push @out, $line;
685 }
686 }
687 0 my $result = '';
688 0 ▶ while (@out) {
Branch: 1 branch
BranchTrueFalseTotal
if (@out) 0 0 0
689 0 $result = $result . $self->textCrop(shift @out);
690 0 ▶ $result = "$result\n" if @out
Branch: 1 branch
BranchTrueFalseTotal
if @out 0 0 0
691 }
692 0 return $result
693 }
694  
695 =item B<textHeight>I<($text)>
696  
697 Returns the display height of I<$text> in pixels.
698 I<$text> can be a multi line string.
699  
700 =cut
701  
702 0 ▶sub textHeight {
Subroutine textHeight: not called CC=3 SCAR=24.8
Pod documented
703 0 my ($self, $text) = @_;
704 0 ▶ return 0 if $text eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $text eq "" 0 0 0
705 0 my $height = 1;
706 0 ▶ while ($text =~ /\n/g) { $height ++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /\n/g) 0 0 0
707 0 my $font = $self->cget('-font');
708 0 return ($height * $self->fontMetrics($font, '-linespace')) #+ $self->fontMetrics($font, '-descent');;
709 }
710  
711 =item B<textWidth>I<($text)>
712  
713 Returns the display width of I<$text> in pixels.
714 I<$text> can be a multi line string.
715  
716 =cut
717  
718 0 ▶sub textWidth {
Subroutine textWidth: not called CC=3 SCAR=24.8
Pod documented
719 0 my ($self, $text) = @_;
720 0 my $font = $self->font;
721 0 my $width = 0;
722 0 my @lines = split("\n", $text);
723 0 for (@lines) {
724 0 my $w = $self->fontMeasure($font, $_);
725 0 ▶ $width = $w if $w > $width;
Branch: 1 branch
BranchTrueFalseTotal
if $w > $width 0 0 0
726 }
727 0 return $width
728 }
729  
730 0 ▶sub textX {
Subroutine textX: not called CC=2 SCAR=17.9
Pod undocumented
731 0 my $self = shift;
732 0 ▶ $self->{TEXTX} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
733 return $self->{TEXTX}
734 0 }
735  
736 0 ▶sub textY {
Subroutine textY: not called CC=2 SCAR=17.9
Pod undocumented
737 0 my $self = shift;
738 0 ▶ $self->{TEXTY} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
739 return $self->{TEXTY}
740 0 }
741  
742 =back
743  
744 =head1 LICENSE
745  
746 Same as Perl.
747  
748 =head1 AUTHOR
749  
750 Hans Jeuken (hanje at cpan dot org)
751  
752 =head1 BUGS AND CAVEATS
753  
754 If you find any bugs, please report them here: L<https://github.com/haje61/Tk-ListBrowser/issues>.
755  
756 =head1 SEE ALSO
757  
758 =over 4
759  
760 =item L<Tk::ListBrowser::BaseItem>
761  
762 =back
763  
764 =cut
765  
766 1 1;
« ListBrowser.pm ↑ Summary ListBrowser/SelectXPM.pm »