| 1 | package Tk::ListBrowser::BaseItem; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Tk::ListBrowser::BaseItem - Base class for Item and SideColumn. | ||||||||||
| 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 $AUTOLOAD); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | $VERSION = 0.15; | |||||||||
| 15 | |||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||
| 17 | |||||||||||
| 18 | You never do this yourself. But this is how it works. | ||||||||||
| 19 | |||||||||||
| 20 | my $base = Tk::ListBrowser::BaseItem->new(%options, | ||||||||||
| 21 | -name => $name, | ||||||||||
| 22 | -listbrowser => $reftolistbrowserobject, | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||
| 27 | |||||||||||
| 28 | Provides a base class for modules L<Tk::ListBrowser::Item> and L<Tk::ListBrowser::SidePanel>. | ||||||||||
| 29 | It provides a method overload to the L<Tk::ListBrowser> object. | ||||||||||
| 30 | |||||||||||
| 31 | Available options are I<-background>, I<-drawrect>, I<-font>, I<-foreground>, I<-owner>, | ||||||||||
| 32 | I<-itemtype>, I<-textanchor>, I<-textjustify>, I<-textlength>, I<-textside> and I<-wraplength>. | ||||||||||
| 33 | |||||||||||
| 34 | The I<-owner> option specifies which object (side column or ListBrowser widget) | ||||||||||
| 35 | is holding this item. By default it is set to the ListBrowser widget. | ||||||||||
| 36 | |||||||||||
| 37 | The I<-drawrect> option specifies whether a rectangle, in the background color should be drawn | ||||||||||
| 38 | as area indicator. | ||||||||||
| 39 | |||||||||||
| 40 | If an option is not defined this module will look for the corresponding option in it's owner. | ||||||||||
| 41 | |||||||||||
| 42 | =head1 METHODS | ||||||||||
| 43 | |||||||||||
| 44 | =over 4 | ||||||||||
| 45 | |||||||||||
| 46 | =cut | ||||||||||
| 47 | |||||||||||
| 48 | 4 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=6 SCAR=18.8
Pod
undocumented
| |||||||||||
| 49 | 4 | my $class = shift; | |||||||||
| 50 | |||||||||||
| 51 | 4 | my %args = @_; | |||||||||
| 52 | |||||||||||
| 53 | 4 | my $lb = delete $args{'-listbrowser'}; | |||||||||
| 54 | 4 | ▶ | croak 'You did not specify a listbrowser' unless defined $lb; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | |||||||||||
| 56 | 4 | my $name = delete $args{'-name'}; | |||||||||
| 57 | 4 | ▶ | croak 'You did not specify a name' unless defined $name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | |||||||||||
| 59 | |||||||||||
| 60 | 4 | my $self = { | |||||||||
| 61 | ISMAPPED => '', | ||||||||||
| 62 | LISTBROWSER => $lb, | ||||||||||
| 63 | NAME => $name, | ||||||||||
| 64 | REGION => [0, 0, 0, 0], | ||||||||||
| 65 | }; | ||||||||||
| 66 | 4 | bless($self, $class); | |||||||||
| 67 | |||||||||||
| 68 | 4 | my %configset; | |||||||||
| 69 | 4 | for (keys %args) { | |||||||||
| 70 | 0 | $self->configure($_, $args{$_}); | |||||||||
| 71 | 0 | $configset{$_} = 1; | |||||||||
| 72 | } | ||||||||||
| 73 | 4 | $self->{CONFIGSET} = \%configset; | |||||||||
| 74 | |||||||||||
| 75 | 4 | ▶ | $self->drawrect(0) unless defined $self->drawrect; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 4 | ▶ | $self->owner($self->listbrowser) unless defined $self->owner; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | |||||||||||
| 78 | 4 | return $self | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 4 | ▶ | sub AUTOLOAD { | ||||||||
|
Subroutine
AUTOLOAD: called CC=2 SCAR=9.2
| |||||||||||
| 82 | 4 | my $self = shift; | |||||||||
| 83 | 4 | ▶ | return if $AUTOLOAD =~ /::DESTROY$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 0 | $AUTOLOAD =~ s/^.*:://; | |||||||||
| 85 | 0 | return $self->{LISTBROWSER}->$AUTOLOAD(@_); | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 0 | ▶ | sub background { | ||||||||
|
Subroutine
background: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 89 | 0 | my $self = shift; | |||||||||
| 90 | 0 | ▶ | $self->{BACKGROUND} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 0 | ▶ | return $self->{BACKGROUND} if defined $self->{BACKGROUND}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 0 | return $self->owner->cget('-background') | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | =item B<cget>I<($option)> | ||||||||||
| 96 | |||||||||||
| 97 | Returns the value of option I<$option>. | ||||||||||
| 98 | |||||||||||
| 99 | =cut | ||||||||||
| 100 | |||||||||||
| 101 | 0 | ▶ | sub cget { | ||||||||
|
Subroutine
cget: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 102 | 0 | my ($self, $option) = @_; | |||||||||
| 103 | 0 | my $d = quotemeta('-'); | |||||||||
| 104 | 0 | $option =~ s/^$d//; | |||||||||
| 105 | 0 | ▶ | if ($self->can($option)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | 0 | return $self->$option | |||||||||
| 107 | } else { | ||||||||||
| 108 | 0 | return $self->listbrowser->cget("-$option") | |||||||||
| 109 | } | ||||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | |||||||||||
| 113 | =item B<clear> | ||||||||||
| 114 | |||||||||||
| 115 | Clears all visible items on the canvas belonging to this item. | ||||||||||
| 116 | |||||||||||
| 117 | =cut | ||||||||||
| 118 | |||||||||||
| 119 | 0 | ▶ | sub clear { | ||||||||
|
Subroutine
clear: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 120 | 0 | my $self = shift; | |||||||||
| 121 | 0 | my $c = $self->Subwidget('Canvas'); | |||||||||
| 122 | 0 | $self->ismapped(''); | |||||||||
| 123 | 0 | $self->region(0, 0, 0, 0); | |||||||||
| 124 | 0 | my $rect = $self->crect; | |||||||||
| 125 | 0 | ▶ | $c->delete($rect) if defined $rect; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 126 | 0 | $self->crect(undef); | |||||||||
| 127 | } | ||||||||||
| 128 | |||||||||||
| 129 | =item B<configure>I<(%options)> | ||||||||||
| 130 | |||||||||||
| 131 | Configures I<%options>. | ||||||||||
| 132 | |||||||||||
| 133 | =cut | ||||||||||
| 134 | |||||||||||
| 135 | 0 | ▶ | sub configure { | ||||||||
|
Subroutine
configure: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 136 | 0 | my ($self, %options) = @_; | |||||||||
| 137 | 0 | my $d = quotemeta('-'); | |||||||||
| 138 | 0 | for (keys %options) { | |||||||||
| 139 | 0 | my $option = $_; | |||||||||
| 140 | 0 | my $value = $options{$option}; | |||||||||
| 141 | 0 | $option =~ s/^$d//; | |||||||||
| 142 | 0 | ▶ | if ($self->can($option)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 143 | 0 | $self->$option($value) | |||||||||
| 144 | } else { | ||||||||||
| 145 | 0 | $self->listbrowser->configure("-$option", $value) | |||||||||
| 146 | } | ||||||||||
| 147 | } | ||||||||||
| 148 | } | ||||||||||
| 149 | |||||||||||
| 150 | 12 | ▶ | sub configSet { | ||||||||
|
Subroutine
configSet: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 151 | 12 | my ($self, $option) = @_; | |||||||||
| 152 | 12 | my $cs = $self->{CONFIGSET}; | |||||||||
| 153 | 12 | return exists $cs->{$option}; | |||||||||
| 154 | } | ||||||||||
| 155 | |||||||||||
| 156 | 0 | ▶ | sub crect { | ||||||||
|
Subroutine
crect: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 157 | 0 | my $self = shift; | |||||||||
| 158 | 0 | ▶ | $self->{CRECT} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 159 | return $self->{CRECT} | ||||||||||
| 160 | 0 | } | |||||||||
| 161 | |||||||||||
| 162 | 16 | ▶ | sub drawrect { | ||||||||
|
Subroutine
drawrect: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 163 | 16 | my $self = shift; | |||||||||
| 164 | 16 | ▶ | $self->{DRAWRECT} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 165 | return $self->{DRAWRECT} | ||||||||||
| 166 | 16 | } | |||||||||
| 167 | |||||||||||
| 168 | 0 | ▶ | sub font { | ||||||||
|
Subroutine
font: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 169 | 0 | my $self = shift; | |||||||||
| 170 | 0 | ▶ | $self->{FONT} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 171 | 0 | ▶ | return $self->{FONT} if defined $self->{FONT}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 172 | 0 | return $self->owner->cget('-font') | |||||||||
| 173 | } | ||||||||||
| 174 | |||||||||||
| 175 | 0 | ▶ | sub foreground { | ||||||||
|
Subroutine
foreground: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 176 | 0 | my $self = shift; | |||||||||
| 177 | 0 | ▶ | $self->{FOREGROUND} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 178 | 0 | ▶ | return $self->{FOREGROUND} if defined $self->{FOREGROUND}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 179 | 0 | return $self->owner->cget('-foreground') | |||||||||
| 180 | } | ||||||||||
| 181 | |||||||||||
| 182 | =item B<inregion>I<($x, $y)> | ||||||||||
| 183 | |||||||||||
| 184 | Returns true if the point at I<$x>, I<$y> is inside | ||||||||||
| 185 | the region of this entry. | ||||||||||
| 186 | |||||||||||
| 187 | =cut | ||||||||||
| 188 | |||||||||||
| 189 | 0 | ▶ | sub inregion { | ||||||||
|
Subroutine
inregion: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 190 | 0 | my ($self, $x, $y) = @_; | |||||||||
| 191 | 0 | my ($cx, $cy, $cdx, $cdy) = $self->region; | |||||||||
| 192 | 0 | ▶ | return '' unless $x >= $cx; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 193 | 0 | ▶ | return '' unless $x <= $cdx; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 194 | 0 | ▶ | return '' unless $y >= $cy; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 195 | 0 | ▶ | return '' unless $y <= $cdy; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 196 | 0 | return 1 | |||||||||
| 197 | } | ||||||||||
| 198 | |||||||||||
| 199 | 0 | ▶ | sub ismapped { | ||||||||
|
Subroutine
ismapped: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 200 | 0 | my $self = shift; | |||||||||
| 201 | 0 | ▶ | $self->{ISMAPPED} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 202 | return $self->{ISMAPPED} | ||||||||||
| 203 | 0 | } | |||||||||
| 204 | |||||||||||
| 205 | 0 | ▶ | sub itemtype { | ||||||||
|
Subroutine
itemtype: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 206 | 0 | my $self = shift; | |||||||||
| 207 | 0 | ▶ | $self->{ITEMTYPE} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 208 | 0 | ▶ | return $self->{ITEMTYPE} if defined $self->{ITEMTYPE}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 209 | 0 | return $self->owner->cget('-itemtype') | |||||||||
| 210 | } | ||||||||||
| 211 | |||||||||||
| 212 | 4 | ▶ | sub listbrowser { return $_[0]->{LISTBROWSER} } | ||||||||
|
Subroutine
listbrowser: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 213 | |||||||||||
| 214 | =item B<name> | ||||||||||
| 215 | |||||||||||
| 216 | Returns the name of this entry. | ||||||||||
| 217 | |||||||||||
| 218 | =cut | ||||||||||
| 219 | |||||||||||
| 220 | 0 | ▶ | sub name { return $_[0]->{NAME} } | ||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 221 | |||||||||||
| 222 | 8 | ▶ | sub owner { | ||||||||
|
Subroutine
owner: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 223 | 8 | my $self = shift; | |||||||||
| 224 | 8 | ▶ | $self->{OWNER} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 225 | return $self->{OWNER} | ||||||||||
| 226 | 8 | } | |||||||||
| 227 | |||||||||||
| 228 | 0 | ▶ | sub region { | ||||||||
|
Subroutine
region: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 229 | 0 | my $self = shift; | |||||||||
| 230 | 0 | ▶ | $self->{REGION} = [@_] if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 231 | 0 | my $r = $self->{REGION}; | |||||||||
| 232 | 0 | return @$r; | |||||||||
| 233 | } | ||||||||||
| 234 | |||||||||||
| 235 | 0 | ▶ | sub textanchor { | ||||||||
|
Subroutine
textanchor: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 236 | 0 | my $self = shift; | |||||||||
| 237 | 0 | ▶ | $self->{TEXTANCHOR} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 238 | 0 | ▶ | return $self->{TEXTANCHOR} if defined $self->{TEXTANCHOR}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 239 | 0 | return $self->owner->cget('-textanchor') | |||||||||
| 240 | } | ||||||||||
| 241 | |||||||||||
| 242 | 0 | ▶ | sub textjustify { | ||||||||
|
Subroutine
textjustify: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 243 | 0 | my $self = shift; | |||||||||
| 244 | 0 | ▶ | $self->{TEXTJUSTIFY} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 245 | 0 | ▶ | return $self->{TEXTJUSTIFY} if defined $self->{TEXTJUSTIFY}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 246 | 0 | return $self->owner->cget('-textjustify') | |||||||||
| 247 | } | ||||||||||
| 248 | |||||||||||
| 249 | 0 | ▶ | sub textlength { | ||||||||
|
Subroutine
textlength: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 250 | 0 | my $self = shift; | |||||||||
| 251 | 0 | ▶ | $self->{TEXTLENGTH} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 252 | 0 | ▶ | return $self->{TEXTLENGTH} if defined $self->{TEXTLENGTH}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 253 | 0 | return $self->owner->cget('-textlength') | |||||||||
| 254 | } | ||||||||||
| 255 | |||||||||||
| 256 | 0 | ▶ | sub textside { | ||||||||
|
Subroutine
textside: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 257 | 0 | my $self = shift; | |||||||||
| 258 | 0 | ▶ | $self->{TEXTSIDE} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 259 | 0 | ▶ | return $self->{TEXTSIDE} if defined $self->{TEXTSIDE}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 260 | 0 | return $self->owner->cget('-textside') | |||||||||
| 261 | } | ||||||||||
| 262 | |||||||||||
| 263 | 0 | ▶ | sub wraplength { | ||||||||
|
Subroutine
wraplength: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||
| 264 | 0 | my $self = shift; | |||||||||
| 265 | 0 | ▶ | if (@_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 266 | 0 | my $l = shift; | |||||||||
| 267 | 0 | ▶ | if ($l > 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 268 | 0 | ▶ | $l = 40 if $l < 40; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 269 | } | ||||||||||
| 270 | 0 | $self->{WRAPLENGTH} = $l; | |||||||||
| 271 | } | ||||||||||
| 272 | 0 | ▶ | return $self->{WRAPLENGTH} if defined $self->{WRAPLENGTH}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 273 | 0 | return $self->owner->cget('-wraplength') | |||||||||
| 274 | } | ||||||||||
| 275 | |||||||||||
| 276 | |||||||||||
| 277 | =back | ||||||||||
| 278 | |||||||||||
| 279 | =head1 LICENSE | ||||||||||
| 280 | |||||||||||
| 281 | Same as Perl. | ||||||||||
| 282 | |||||||||||
| 283 | =head1 AUTHOR | ||||||||||
| 284 | |||||||||||
| 285 | Hans Jeuken (hanje at cpan dot org) | ||||||||||
| 286 | |||||||||||
| 287 | =head1 TODO | ||||||||||
| 288 | |||||||||||
| 289 | =over 4 | ||||||||||
| 290 | |||||||||||
| 291 | =back | ||||||||||
| 292 | |||||||||||
| 293 | =head1 BUGS AND CAVEATS | ||||||||||
| 294 | |||||||||||
| 295 | If you find any bugs, please report them here: L<https://github.com/haje61/Tk-ListBrowser/issues>. | ||||||||||
| 296 | |||||||||||
| 297 | =head1 SEE ALSO | ||||||||||
| 298 | |||||||||||
| 299 | =over 4 | ||||||||||
| 300 | |||||||||||
| 301 | =back | ||||||||||
| 302 | |||||||||||
| 303 | =cut | ||||||||||
| 304 | |||||||||||
| 305 | 1 | 1; | |||||||||