package Tk::MyListbox; require Tk::Listbox; @ISA = qw(Tk::Listbox); Construct Tk::Widget 'MyListbox'; #公開したいサブルーチン #@EXPORT = qw(); use strict; #use base qw(Tk::Widget); sub Populate { my($cw, $args) = @_; $cw->SUPER::Populate($args); return; # my $b = $cw->Button(); # $b->pack(-expand => 1, -fill => 'both'); # $cw->Advertise('MyButton', => $b); # $cw->ConfigSpecs(DEFAULT => [$b]); # $cw->Delegates(DEFAULT => $b); } sub ClassInit { my ($class, $mw) = @_; return $class; } sub ClearAll { shift->DeleteAllItem(); } BEGIN { } sub new { my ($class, @args) = @_; my $self = Tk::Listbox->new(@args); my $this = bless $self, ref($class) || $class; $this->bind( '', [ sub { $_[0]->yviewScroll(-($_[1]/120)*3, 'units'); }, Tk::Ev('D') ] ); return $this; } sub DESTROY { my $this = shift; $this->SUPER::DESTROY(@_); } sub GetItemNumber { my ($this) = @_; return $this->size(); } #$indexの項目が見えるようにスクロールする sub ShowIndexItem { my ($this, $index) = @_; return $this->see($index); } sub GetText { my ($this) = @_; return $this->get("active"); } sub GetCurSelItem { my ($this) = @_; return $this->get("active"); } sub GetCurSel { my ($this) = @_; return $this->index("active"); } sub GetSel { my ($this, $index) = @_; return $this->selectionIncludes($index); } sub SetCurSel { my ($this, $index) = @_; $this->SetSel(1, $index); return $this->activate($index); } sub SetSel { my ($this, $set, $s, $e) = @_; $this->selectionClear(0, 'end'); if(!$e) { if($set) { return $this->selectionSet($s); } return $this->selectionClear($s); } if($set) { return $this->selectionSet($s, $e); } return $this->selectionClear($s, $e); } sub DeleteItem { my ($this, $s, $e) = @_; if(!$e) { return $this->delete($s); } return $this->delete($s, $e); } sub DeleteAllItem { my ($this) = @_; return $this->delete(0, "end"); } sub GetItem { my ($this, $s, $e) = @_; if(!$e) { return $this->get($s); } return $this->get($s, $e); } sub ReplaceItem { my ($this, $index, @lists) = @_; my $IsSelected = $this->selectionIncludes($index); $this->DeleteItem($index); $this->InsertItem($index, @lists); $this->selectionSet($index) if($IsSelected); } sub InsertItem { my ($this, $index, @lists) = @_; return $this->insert($index, @lists); } sub AddItem { my ($this, @lists) = @_; return $this->insert("end", @lists); } 1;