in reply to Re^2: TK-Hlist -> Drag&Drop
in thread TK-Hlist -> Drag&Drop
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: TK-Hlist -> Drag&Drop
by choroba (Cardinal) on Sep 12, 2013 at 12:59 UTC | |
by kean (Sexton) on Sep 12, 2013 at 13:13 UTC | |
by choroba (Cardinal) on Sep 12, 2013 at 13:46 UTC | |
by kean (Sexton) on Sep 12, 2013 at 14:22 UTC |