package MyDragDrop; use Tk; use Tk::DropSite; use Tk::DragDrop; @ISA = qw(Tk::DropSite Tk::DragDrop); #公開したいサブルーチン #@EXPORT = qw(); use strict; sub new { my ($module) = @_; my $self = {}; #new Tk::DropSite(); return bless $self, ref($module) || $module; } sub SetDropSite { my ($this, $widget, @a) = @_; $widget->DropSite(@a); } sub ConfigureDrop { my ($this, $AcceptWidget, @ConfigArray) = @_; $AcceptWidget->DropSite( -dropcommand => sub { $this->AcceptDrop($AcceptWidget, \@ConfigArray, @_); }, -droptypes => ( $^O eq 'MSWin32' ? 'Win32' : [ 'XDND', 'Sun' ] ) # -droptypes => ( $^O eq 'MSWin32' ? 'Win32' : [ 'KDE', 'XDND', 'Sun' ] ) ); } sub AcceptDrop { my ($this, $widget, $pConfigArray, $selection, $a, $b, $c) = @_; #print "this=$this, w=$widget, s=$selection, a=$a, b=$b, c=$c\n"; my $filename; eval { if ( $^O eq 'MSWin32' ) { $filename = $widget->SelectionGet( -selection => $selection, 'STRING' ); } else { $filename = $widget->SelectionGet( -selection => $selection, 'FILE_NAME' ); } }; print "Dropped: FileName=$filename\n"; my $nConfig = @$pConfigArray; for(my $i = 0 ; $i < $nConfig ; $i++) { my $pArray = $pConfigArray->[$i]; my ($regexp, $Entry, $Func) = @$pArray; # my $y = $widget->pointery() - $widget->rooty(); # my $nearest = $widget->nearest($y); #print "$i [$filename]: $regexp, $Entry, $Func\n"; next if($filename !~ /$regexp/i); my $ret = &$Func($filename); last; } } 1;