Tk
view release on metacpan or search on metacpan
Listbox/Listbox.pm view on Meta::CPAN
my $info = $balloon->GetOption($opt,$listbox);
if ($opt =~ /^-(statusmsg|balloonmsg)$/ && UNIVERSAL::isa($info,'ARRAY'))
{
$balloon->Subclient($index);
if (defined $info->[$index])
{
return $info->[$index];
}
return '';
}
return $info;
}
}
sub ClassInit
{
my ($class,$mw) = @_;
$class->SUPER::ClassInit($mw);
# Standard Motif bindings:
$mw->bind($class,'<1>',[sub {
my $w = shift;
if (Tk::Exists($w)) {
$w->BeginSelect(@_);
}
}, Ev('index',Ev('@'))]);
$mw->bind($class, '<Double-1>' => \&Tk::NoOp);
$mw->bind($class,'<B1-Motion>',['Motion',Ev('index',Ev('@'))]);
$mw->bind($class,'<ButtonRelease-1>','ButtonRelease_1');
;
$mw->bind($class,'<Shift-1>',['BeginExtend',Ev('index',Ev('@'))]);
$mw->bind($class,'<Control-1>',['BeginToggle',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>',['ExtendUpDown',-1]);
$mw->bind($class,'<Down>',['UpDown',1]);
$mw->bind($class,'<Shift-Down>',['ExtendUpDown',1]);
$mw->XscrollBind($class);
$mw->bind($class,'<Prior>', sub {
my $w = shift;
$w->yview('scroll',-1,'pages');
$w->activate('@0,0');
});
$mw->bind($class,'<Next>', sub {
my $w = shift;
$w->yview('scroll',1,'pages');
$w->activate('@0,0');
});
$mw->bind($class,'<Control-Prior>', ['xview', 'scroll', -1, 'pages']);
$mw->bind($class,'<Control-Next>', ['xview', 'scroll', 1, 'pages']);
# <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']);
# XXX What about <<Copy>>? Already handled in Tk::Clipboard?
# $class->clipboardOperations($mw,'Copy');
$mw->bind($class,'<space>',['BeginSelect',Ev('index','active')]);
$mw->bind($class,'<Select>',['BeginSelect',Ev('index','active')]);
$mw->bind($class,'<Control-Shift-space>',['BeginExtend',Ev('index','active')]);
$mw->bind($class,'<Shift-Select>',['BeginExtend',Ev('index','active')]);
$mw->bind($class,'<Escape>','Cancel');
$mw->bind($class,'<Control-slash>','SelectAll');
$mw->bind($class,'<Control-backslash>','Cntrl_backslash');
;
# Additional Tk bindings that aren't part of the Motif look and feel:
$mw->bind($class,'<2>',['scan','mark',Ev('x'),Ev('y')]);
$mw->bind($class,'<B2-Motion>',['scan','dragto',Ev('x'),Ev('y')]);
$mw->MouseWheelBind($class); # XXX Both needed?
$mw->YMouseWheelBind($class);
return $class;
}
1;
__END__
sub TIEARRAY {
my ( $class, $obj, %options ) = @_;
return bless {
OBJECT => \$obj,
OPTION => \%options }, $class;
}
sub TIESCALAR {
my ( $class, $obj, %options ) = @_;
return bless {
OBJECT => \$obj,
OPTION => \%options }, $class;
}
# FETCH
# -----
# Return either the full contents or only the selected items in the
# box depending on whether we tied it to an array or scalar respectively
sub FETCH {
my $class = shift;
my $self = ${$class->{OBJECT}};
my %options = %{$class->{OPTION}} if defined $class->{OPTION};;
# Define the return variable
my $result;
# Check whether we are have a tied array or scalar quantity
if ( @_ ) {
my $i = shift;
# The Tk:: Listbox has been tied to an array, we are returning
# an array list of the current items in the Listbox
$result = $self->get($i);
} else {
# The Tk::Listbox has been tied to a scalar, we are returning a
# reference to an array or hash containing the currently selected items
my ( @array, %hash );
Listbox/Listbox.pm view on Meta::CPAN
}
my $first = $w->index('anchor');
my $last = $Prev;
if ($first > $last)
{
($first, $last) = ($last, $first);
}
$w->selectionClear($first,$last);
while ($first <= $last)
{
if (Tk::lsearch(\@Selection,$first) >= 0)
{
$w->selectionSet($first)
}
$first++
}
$w->eventGenerate("<<ListboxSelect>>");
}
# SelectAll
#
# This procedure is invoked to handle the "select all" operation.
# For single and browse mode, it just selects the active element.
# Otherwise it selects everything in the widget.
#
# Arguments:
# w - The listbox widget.
sub SelectAll
{
my $w = shift;
my $mode = $w->cget('-selectmode');
if ($mode eq 'single' || $mode eq 'browse')
{
$w->selectionClear(0,'end');
$w->selectionSet('active')
}
else
{
$w->selectionSet(0,'end')
}
$w->eventGenerate("<<ListboxSelect>>");
}
# Perl/Tk extensions:
sub SetList
{
my $w = shift;
$w->delete(0,'end');
$w->insert('end',@_);
}
sub deleteSelected
{
my $w = shift;
my $i;
foreach $i (reverse $w->curselection)
{
$w->delete($i);
}
}
sub clipboardPaste
{
my $w = shift;
my $index = $w->index('active') || $w->index($w->XEvent->xy);
my $str;
eval {local $SIG{__DIE__}; $str = $w->clipboardGet };
return if $@;
foreach (split("\n",$str))
{
$w->insert($index++,$_);
}
}
sub getSelected
{
my ($w) = @_;
my $i;
my (@result) = ();
foreach $i ($w->curselection)
{
push(@result,$w->get($i));
}
return (wantarray) ? @result : $result[0];
}
1;
__END__
( run in 0.881 second using v1.01-cache-2.11-cpan-84e82930d8c )