in reply to Re: TK-Hlist -> Drag&Drop
in thread TK-Hlist -> Drag&Drop

I fear it means it is not possible.

I think it doesn't mean that -- I think it means you have to use bind+dragsiteSet/dragsiteClear/dropsiteSet/dropsiteClear to implement the move-this-list-item-over-here-logic

Replies are listed 'Best First'.
Re^3: TK-Hlist -> Drag&Drop
by kean (Sexton) on Sep 12, 2013 at 12:40 UTC
    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"; }
      Case matters! The drop coordinates are X, Y, not x, y!
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        When i chance the x to X and y to Y the Drag and Drop functions report both the false idx... With lower case the Drag function returns the right idx but the drop return the same idx :-(
Re^3: TK-Hlist -> Drag&Drop
by kean (Sexton) on Sep 12, 2013 at 11:09 UTC
    I hope so.. And searching a sample for this