So i have found a sample for a Listbox and modified it for a HList.
But when i drop, the y coord is not correct...
use strict;
use warnings;
use Tk;
use Tk::DragDrop;
use Tk::DropSite;
use Tk::HList;
my $mw = new MainWindow;
my $hlist = $mw->Scrolled('HList', -scrollbars => "osoe")->pack(-side
+=> "left", -expand => 1, -fill => 'both');
my $cnt = 0;
foreach (sort keys %ENV)
{
$hlist->add($cnt);
$hlist->itemCreate($cnt, 0, -text => $_);
$cnt++;
}
my $token = $hlist->DragDrop(-event => '<B1-Motion>',
-sitetypes => ['Local'],
-startcommand => \&StartDrag);
$hlist->DropSite(-droptypes => ['Local'],
-dropcommand => [\&Drop, $hlist, $token]);
MainLoop;
sub StartDrag {
my $w = $token->parent;
my $e = $w->XEvent;
my $idx = $w->nearest($e->y);
print "Drag Y: " . $e->y . "\n";
print "Pos: $idx\n";
if (defined $idx) {
$token->configure(-text => $w->itemCget($idx, 0, -text));
my($X, $Y) = ($e->X, $e->Y);
$token->MoveToplevelWindow($X, $Y);
$token->raise;
$token->deiconify;
$token->FindSite($X, $Y, $e);
}
}
sub Drop {
my $w = $token->parent;
my $e = $w->XEvent;
my $idx = $w->nearest($e->y);
print "Drop Y: " . $e->y . "\n";
print "Pos: $idx\n";
}
|