/usr/lib/x86_64-linux-gnu/perl5/5.22/Prima/Label.pm is in libprima-perl 1.28-1.4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | #
# Copyright (c) 1997-2002 The Protein Laboratory, University of Copenhagen
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# Created by Dmitry Karasik <dk@plab.ku.dk>
#
# $Id: Label.pm,v 1.25 2005/12/05 21:48:12 dk Exp $
package Prima::Label;
use vars qw(@ISA);
@ISA = qw(Prima::Widget);
use Carp;
use Prima::Const;
use Prima::Classes;
use strict;
sub profile_default
{
my $font = $_[ 0]-> get_default_font;
return {
%{$_[ 0]-> SUPER::profile_default},
alignment => ta::Left,
autoHeight => 0,
autoWidth => 1,
focusLink => undef,
height => 4 + $font-> { height},
ownerBackColor => 1,
selectable => 0,
showAccelChar => 0,
showPartial => 1,
tabStop => 0,
valignment => ta::Top,
widgetClass => wc::Label,
wordWrap => 0,
}
}
sub profile_check_in
{
my ( $self, $p, $default) = @_;
$p-> { autoWidth} = 0 if
! exists $p->{autoWidth} and (
exists $p-> {width} ||
exists $p-> {size} ||
exists $p-> {rect} ||
( exists $p-> {left} && exists $p-> {right})
);
$p-> {autoHeight} = 0 if
! exists $p-> {autoHeight} and (
exists $p-> {height} ||
exists $p-> {size} ||
exists $p-> {rect} ||
( exists $p-> {top} && exists $p-> {bottom})
);
$self-> SUPER::profile_check_in( $p, $default);
my $vertical = exists $p-> {vertical} ?
$p-> {vertical} :
$default-> { vertical};
}
sub init
{
my $self = shift;
my %profile = $self-> SUPER::init(@_);
$self-> { alignment} = $profile{ alignment};
$self-> { valignment} = $profile{ valignment};
$self-> { autoHeight} = $profile{ autoHeight};
$self-> { autoWidth} = $profile{ autoWidth};
$self-> { wordWrap} = $profile{ wordWrap};
$self-> { focusLink} = $profile{ focusLink};
$self-> { showAccelChar} = $profile{ showAccelChar};
$self-> { showPartial} = $profile{ showPartial};
$self-> check_auto_size;
return %profile;
}
sub on_paint
{
my ($self,$canvas) = @_;
my @size = $canvas-> size;
my @clr;
if ( $self-> enabled) {
if ( $self-> focused) {
@clr = ($self-> hiliteColor, $self-> hiliteBackColor);
} else {
@clr = ($self-> color, $self-> backColor);
}
} else {
@clr = ($self-> disabledColor, $self-> disabledBackColor);
}
unless ( $self-> transparent) {
$canvas-> color( $clr[1]);
$canvas-> bar(0,0,@size);
}
my $fh = $canvas-> font-> height;
my $ta = $self-> {alignment};
my $wx = $self-> {widths};
my $ws = $self-> {words};
my ($starty,$ycommon) = (0, scalar @{$ws} * $fh);
if ( $self-> {valignment} == ta::Top) {
$starty = $size[1] - $fh;
} elsif ( $self-> {valignment} == ta::Bottom) {
$starty = $ycommon - $fh;
} else {
$starty = ( $size[1] + $ycommon)/2 - $fh;
}
my $y = $starty;
my $tl = $self-> {tildeLine};
my $i;
my $paintLine = !$self-> {showAccelChar} && defined($tl) && $tl < scalar @{$ws};
unless ( $self-> enabled) {
$canvas-> color( $self-> light3DColor);
for ( $i = 0; $i < scalar @{$ws}; $i++) {
my $x = 0;
if ( $ta == ta::Center) {
$x = ( $size[0] - $$wx[$i]) / 2;
} elsif ( $ta == ta::Right) {
$x = $size[0] - $$wx[$i];
}
$canvas-> text_out( $$ws[$i], $x + 1, $y - 1);
$y -= $fh;
}
$y = $starty;
if ( $paintLine) {
my $x = 0;
if ( $ta == ta::Center) {
$x = ( $size[0] - $$wx[$tl]) / 2;
} elsif ( $ta == ta::Right) {
$x = $size[0] - $$wx[$tl];
}
$canvas-> line(
$x + $self-> {tildeStart} + 1, $starty - $fh * $tl - 1,
$x + $self-> {tildeEnd} + 1, $starty - $fh * $tl - 1
);
}
}
$canvas-> color( $clr[0]);
for ( $i = 0; $i < scalar @{$ws}; $i++) {
my $x = 0;
if ( $ta == ta::Center) {
$x = ( $size[0] - $$wx[$i]) / 2;
} elsif ( $ta == ta::Right) {
$x = $size[0] - $$wx[$i];
}
$canvas-> text_out( $$ws[$i], $x, $y);
$y -= $fh;
}
if ( $paintLine) {
my $x = 0;
if ( $ta == ta::Center) { $x = ( $size[0] - $$wx[$tl]) / 2; }
elsif ( $ta == ta::Right) { $x = $size[0] - $$wx[$tl]; }
$canvas-> line(
$x + $self-> {tildeStart}, $starty - $fh * $tl,
$x + $self-> {tildeEnd}, $starty - $fh * $tl
);
}
}
sub text
{
return $_[0]-> SUPER::text unless $#_;
my $self = $_[0];
$self-> SUPER::text( $_[1]);
$self-> check_auto_size;
$self-> repaint;
}
sub on_translateaccel
{
my ( $self, $code, $key, $mod) = @_;
if (
!$self-> {showAccelChar} &&
defined $self-> {accel} &&
( $key == kb::NoKey) &&
lc chr $code eq $self-> { accel}
) {
$self-> clear_event;
$self-> notify( 'Click');
}
}
sub on_click
{
my ( $self, $f) = ( $_[0], $_[0]-> {focusLink});
$f-> select if defined $f && $f-> alive && $f-> enabled;
}
sub on_keydown
{
my ( $self, $code, $key, $mod) = @_;
if (
defined $self-> {accel} &&
( $key == kb::NoKey) &&
lc chr $code eq $self-> { accel}
) {
$self-> notify( 'Click');
$self-> clear_event;
}
}
sub on_mousedown
{
my $self = $_[0];
$self-> notify( 'Click');
$self-> clear_event;
}
sub on_fontchanged
{
$_[0]-> check_auto_size;
}
sub on_size
{
$_[0]-> reset_lines;
}
sub on_enable { $_[0]-> repaint } sub on_disable { $_[0]-> repaint }
sub set_alignment
{
$_[0]-> {alignment} = $_[1];
$_[0]-> repaint;
}
sub set_valignment
{
$_[0]-> {valignment} = $_[1];
$_[0]-> repaint;
}
sub reset_lines
{
my $self = $_[0];
my @res;
my $maxLines = int($self-> height / $self-> font-> height);
$maxLines++ if $self-> {showPartial} and (($self-> height % $self-> font-> height) > 0);
my $opt = tw::NewLineBreak|tw::ReturnLines|tw::WordBreak|tw::CalcMnemonic|tw::ExpandTabs|tw::CalcTabs;
my $width = 1000000;
$opt |= tw::CollapseTilde unless $self-> {showAccelChar};
$width = $self-> width if $self-> {wordWrap};
$self-> begin_paint_info;
my $lines = $self-> text_wrap( $self-> text, $width, $opt);
my $lastRef = pop @{$lines};
$self-> {textLines} = scalar @$lines;
for( qw( tildeStart tildeEnd tildeLine)) {$self-> {$_} = $lastRef-> {$_}}
$self-> {accel} = defined($self-> {tildeStart}) ? lc( $lastRef-> {tildeChar}) : undef;
splice( @{$lines}, $maxLines) if scalar @{$lines} > $maxLines;
$self-> {words} = $lines;
my @len;
for ( @{$lines}) { push @len, $self-> get_text_width( $_); }
$self-> {widths} = [@len];
$self-> end_paint_info;
}
sub check_auto_size
{
my $self = $_[0];
my $cap = $self-> text;
$cap =~ s/~//s unless $self-> {showAccelChar};
my %sets;
if ( $self-> {wordWrap}) {
$self-> reset_lines;
if ( $self-> {autoHeight}) {
$self-> geomHeight( $self-> {textLines} * $self-> font-> height + 2);
}
} else {
my @lines = split "\n", $cap;
if ( $self-> {autoWidth}) {
$self-> begin_paint_info;
$sets{geomWidth} = 0;
for my $line ( @lines) {
my $width = $self-> get_text_width( $line);
$sets{geomWidth} = $width if
$sets{geomWidth} < $width;
}
$sets{geomWidth} += 6;
$self-> end_paint_info;
}
$sets{ geomHeight} = scalar(@lines) * $self-> font-> height + 2
if $self-> {autoHeight};
$self-> set( %sets);
$self-> reset_lines;
}
}
sub set_auto_width
{
my ( $self, $aw) = @_;
return if $self-> {autoWidth} == $aw;
$self-> {autoWidth} = $aw;
$self-> check_auto_size;
}
sub set_auto_height
{
my ( $self, $ah) = @_;
return if $self-> {autoHeight} == $ah;
$self-> {autoHeight} = $ah;
$self-> check_auto_size;
}
sub set_word_wrap
{
my ( $self, $ww) = @_;
return if $self-> {wordWrap} == $ww;
$self-> {wordWrap} = $ww;
$self-> check_auto_size;
}
sub set_show_accel_char
{
my ( $self, $sac) = @_;
return if $self-> {showAccelChar} == $sac;
$self-> {showAccelChar} = $sac;
$self-> check_auto_size;
}
sub set_show_partial
{
my ( $self, $sp) = @_;
return if $self-> {showPartial} == $sp;
$self-> {showPartial} = $sp;
$self-> check_auto_size;
}
sub get_lines
{
return @{$_[0]-> {words}};
}
sub showAccelChar {($#_)?($_[0]-> set_show_accel_char($_[1])) :return $_[0]-> {showAccelChar}}
sub showPartial {($#_)?($_[0]-> set_show_partial($_[1])) :return $_[0]-> {showPartial}}
sub focusLink {($#_)?($_[0]-> {focusLink} = $_[1]) :return $_[0]-> {focusLink} }
sub alignment {($#_)?($_[0]-> set_alignment( $_[1])) :return $_[0]-> {alignment} }
sub valignment {($#_)?($_[0]-> set_valignment( $_[1])) :return $_[0]-> {valignment} }
sub autoWidth {($#_)?($_[0]-> set_auto_width( $_[1])) :return $_[0]-> {autoWidth} }
sub autoHeight {($#_)?($_[0]-> set_auto_height( $_[1])) :return $_[0]-> {autoHeight} }
sub wordWrap {($#_)?($_[0]-> set_word_wrap( $_[1])) :return $_[0]-> {wordWrap} }
1;
__DATA__
=pod
=head1 NAME
Prima::Label - static text widget
=head1 DESCRIPTION
The class is designed for display of text, and assumes no
user interaction. The text output capabilities include wrapping,
horizontal and vertical alignment, and automatic widget resizing to
match text extension. If text contains a tilde-escaped ( hot ) character, the label can
explicitly focus the specified widget upon press of the character key, what feature
is useful for dialog design.
=head1 SYNOPSIS
my $label = Prima::Label-> create(
text => 'Enter ~name:',
focusLink => $name_inputline,
alignment => ta::Center,
);
=head1 API
=head2 Properties
=over
=item alignment INTEGER
One of the following C<ta::XXX> constants:
ta::Left
ta::Center
ta::Right
Selects the horizontal text alignment.
Default value: C<ta::Left>
=item autoHeight BOOLEAN
If 1, the widget height is automatically changed as text extensions
change.
Default value: 0
=item autoWidth BOOLEAN
If 1, the widget width is automatically changed as text extensions
change.
Default value: 1
=item focusLink WIDGET
Points to a widget, which is explicitly focused when the user
presses the combination of a hot key with the C<Alt> key.
Prima::Label does not provide a separate property to access the
hot key value, however it can be read from the C<{accel}> variable.
Default value: C<undef>.
=item showAccelChar BOOLEAN
If 0, the tilde ( ~ ) character is collapsed from the text,
and the hot character is underlined. When the user presses combination
of the escaped character with the C<Alt> key, the C<focusLink>
widget is explicitly focused.
If 1, the text is showed as is, and no hot character is underlined.
Key combinations with C<Alt> key are not recognized.
Default value: 0
=item showPartial BOOLEAN
Used to determine if the last line of text should be drawn if
it can not be vertically fit in the widget interior. If 1, the
last line is shown even if not visible in full. If 0, only full
lines are drawn.
Default value: 1
=item wordWrap BOOLEAN
If 1, the text is wrapped if it can not be horizontally fit in the
widget interior.
If 0, the text is not wrapped unless new line characters are present
in the text.
New line characters signal line wrapping with no respect to C<wordWrap>
property value.
Default value: 0
=item valignment INTEGER
One of the following C<ta::XXX> constants:
ta::Top
ta::Middle or ta::Center
ta::Bottom
Selects the vertical text alignment.
NB: C<ta::Middle> value is not equal to C<ta::Center>'s, however
the both constants produce equal effect here.
Default value: C<ta::Top>
=back
=head1 AUTHOR
Dmitry Karasik, E<lt>dmitry@karasik.eu.orgE<gt>.
=head1 SEE ALSO
L<Prima>, L<Prima::Widget>, F<examples/label.pl>
=cut
|