Tk-HListbox

 view release on metacpan or  search on metacpan

lib/Tk/HListbox.pm  view on Meta::CPAN

    $selected = \@array;

would select elements "a", "b" and "f" in the HListbox.

Again, if the "index" we indicate we want to use indices in the options hash 
then the indices are use instead of elements, e.g.

    @array = ( 0, 1, 5 );
    $selected = \@array;

would have the same effect, selecting elements "a", "b" and "f" if the 
$selected variable was tied with %options = ( ReturnType => "index" ).

If we are returning "both", i.e. the tied scalar points to a hash, both key 
and value must match, e.g.

    %hash = ( 0 => "a", 1 => "b", 5 => "f" );
    $selected = \%hash;

would have the same effect as the previous examples.

It should be noted that, despite being a reference to an array (or possibly 
a hash), you still can not copy the tied variable without it being untied, 
instead you must pass a reference to the tied scalar between subroutines.

=back

=head1 AUTHOR

Jim Turner, C<< <https://metacpan.org/author/TURNERJW> >>.

=head1 COPYRIGHT

Copyright (c) 2015-2023 Jim Turner C<< <mailto://turnerjw784@yahoo.com> >>.
All rights reserved.  

This program is free software; you can redistribute 
it and/or modify it under the same terms as Perl itself.

This is a derived work from Tk::Listbox and Tk::HList.

=head1 KEYWORDS

hlistbox, listbox, hlist

=head1 SEE ALSO

L<Tk::HList>, L<Tk::Listbox>, L<Tk::ItemStyle>, L<Tk::DItem>.

=cut

##### NOTE:  DO AN "export jwtlistboxhack=1" (env. variable) TO GET MY (MUCH BETTER) KEYBOARD FUNCTION BINDING!

package Tk::HListbox;
use strict;
use warnings;
use POSIX qw(ceil);
use Carp;
use Tk;
use Tk::ItemStyle;
use base qw(Tk::Derived Tk::HList);
use vars qw($VERSION $DEFAULTFONT);
$VERSION = '3.00';

Tk::Widget->Construct('HListbox');

my $bummer = ($^O =~ /MSWin/) ? 1 : 0;   #Bummer if you're stuck running M$-Windows! ;)
my $JWTLISTBOXHACK = defined($ENV{jwtlistboxhack}) ? $ENV{jwtlistboxhack} : 0;
$DEFAULTFONT = $bummer ? '{MS Sans Serif} 8' : 'Helvetica -12 bold';  # ADDED 2.301 by Jeff Stephens

sub ClassInit
{
	my ($class,$mw) = @_;

	$class->SUPER::ClassInit($mw);
 # Standard Motif bindings:

# $mw->bind($class, '<Double-1>' => \&Tk::NoOp);
	$mw->bind($class,'<Double-1>' => ['DoubleButton1',Ev('index',Ev('@'))]);
	$mw->bind($class,'<B1-Motion>',['Motion',Ev('index',Ev('@'))]);
	$mw->bind($class,'<Alt-ButtonRelease-1>',['jwtAltButtonRelease_1', Ev('index',Ev('@'))]);
	$mw->bind($class,'<ButtonRelease-1>','ButtonRelease_1');
	$mw->bind($class,'<Shift-1>',['ShiftButton1',Ev('index',Ev('@'))]);  #JWT:ADDED 20091020!
	$mw->bind($class,'<Control-ButtonPress-1>',['BeginToggle',Ev('index',Ev('@'))]);
	$mw->bind($class,'<ButtonPress-1>',['ButtonPress_1', Ev('index',Ev('@'))]);
	$mw->bind($class,'<B1-Leave>',['AutoScan',Ev('x'),Ev('y')]);
	$mw->bind($class,'<B1-Enter>','CancelRepeat');
	$mw->bind($class,'<Up>',['UpDown',-1]);
	$mw->bind($class,'<Shift-Up>',['ShiftUpDown',-1]);
	$mw->bind($class,'<Down>',['UpDown',1]);
	$mw->bind($class,'<Shift-Down>',['ShiftUpDown',1]);
	$mw->XscrollBind($class);
	$mw->bind($class, '<Control-Prior>', ['CtrlPriorNext',-1]);  #JWT:DIFFERENT FROM Listbox!:
	$mw->bind($class, '<Control-Next>', ['CtrlPriorNext',1]);
 # <Home> and <End> defined in XscrollBind
	$mw->bind($class, '<Control-Home>','Cntrl_Home');
	$mw->bind($class,'<Shift-Control-Home>',['DataExtend',0]);
	$mw->bind($class, '<Control-End>','Cntrl_End');
	$mw->bind($class,'<Shift-Control-End>',['DataExtend','end']);
	$mw->bind($class,'<space>',['SpaceSelect',Ev('index','active')]);
	$mw->bind($class,'<Select>',['BeginSelect',Ev('index','active')]);

 # Additional Tk bindings that aren't part of the Motif look and feel:
	if ($JWTLISTBOXHACK) {
		$mw->bind($class,'<Shift-space>',['ShiftSpace',Ev('index','active')]);  #JWT:ADDED 20091020!
		$mw->bind($class,'<Alt-space>',['jwtAltSpace',Ev('index','active')]);  #JWT:ADDED 20091020!
		$mw->bind($class,'<plus>',['KeyboardToggleIndicator','<Activate>',Ev('index','active')]);
		$mw->bind($class,'<minus>',['KeyboardToggleIndicator','<Disarm>',Ev('index','active')]);
	}
	$mw->bind($class,'<Shift-Select>',['BeginExtend',Ev('index','active')]);  #JWT:ADDED 20091020!
	$mw->bind($class, '<Escape>', 'Cancel');
	$mw->bind($class, '<Control-slash>','SelectAll');
	$mw->bind($class, '<Control-backslash>','Cntrl_backslash');
	$mw->bind($class,'<2>',['scan','mark',Ev('x'),Ev('y')]);
	$mw->bind($class,'<B2-Motion>',['scan','dragto',Ev('x'),Ev('y')]);
	$mw->bind($class,'<Return>', ['InvokeCommand']);
	$mw->bind($class,'<FocusIn>','focus');
	$mw->bind($class,'<FocusOut>','unfocus');
	$mw->MouseWheelBind($class); # XXX Both needed?
	$mw->YMouseWheelBind($class);



( run in 2.931 seconds using v1.01-cache-2.11-cpan-364913b4093 )