Hi all,
I am using Tk 5.8.3, getting problem in drag n drop.
I am creating a tree with optional scroll bar, on each child of this
tree i am creating a frame (colored green in following code), and a
label (colored blue) which is a child of frame.
Now after creating drag n drop bindings for tree & its children drag n
drop is working for each widget.
But after scrolling, if i drag a a widget n drop on blue
label it is not working.
I did debug DragDrop.pm,
where function sub FindSite { } returning a Null site, so line
$site->Motion($token,$e) if (defined $site)
is not getting executed.
I am attaching following code for more debugging purpose.
Please help me to resolve this problem.
Thanks,
Rahul Dashore
Drag n Drop Sample Code:
use Tk;
use Tk::DropSite;
use Tk::DragDrop;
use Tk::Tree;
my $mw = MainWindow->new(-title => 'Tree');
my $sourceItem;
my $tree = $mw->Scrolled(
'Tree',
-scrollbars => 'osoe',
-column => 1,
)->pack(
-side => 'top',
-fill => 'both',
-expand => 1
);
foreach my $val (qw/orange orange.red orange.yellow orange.yellow.lite
orange.yellow.hard green green.blue green.yellow purple purple.red
purple.blue hara hara.lal hara.lal.peela hara.lal.kala/) {
$tree->add($val);
my $imageAndTextFrame = $tree->Frame(
-bg => 'green',
)->pack(
-side => 'left'
);
$imageAndTextFrame->bind(
'<1>' => sub {
my $ent = getMousePositionOnTree($tree);
$tree->selectionSet($ent);
if($ent ne '')
{
$tree->anchorClear();
$tree->anchorSet($ent);
$tree->selectionClear();
$tree->selectionSet($ent);
}
});
my $label = $imageAndTextFrame->Label(
-text => $val,
-bg => 'blue',
-fg => 'red',
)->pack(
-side => 'left',
);
$label->bind(
'<1>' => sub {
my $ent = getMousePositionOnTree($tree);
$tree->selectionSet($ent);
if($ent ne '')
{
$tree->anchorClear();
$tree->anchorSet($ent);
$tree->selectionClear();
$tree->selectionSet($ent);
}
});
$tree->itemCreate(
$val,
0,
-itemtype => 'window',
-widget => $imageAndTextFrame,
);
createDragDropBindings($imageAndTextFrame);
createDragDropBindings($label);
}
createDragDropBindings($tree);
$tree->autosetmode( );
MainLoop;
sub set_sourceItem {
$sourceItem = $tree->infoAnchor();
return;
}
sub dropItemOpr {
my $destinationItem = getMousePositionOnTree($tree);
print "sourceItem = $sourceItem ---- destinationItem =
$destinationItem\n";
}
sub getMousePositionOnTree {
my $treeHandle = shift;
my ($X,$Y) = ($Tk::event->X,$Tk::event->Y);
my $rooty = $treeHandle->rooty;
my $y = $Y - $rooty;
my $ent = $treeHandle->GetNearest($y,1);
return ($ent);
}
sub createDragDropBindings {
my $widget = shift;
$widget->DragDrop(
-event => '<B1-Motion>',
-text => "DND",
-sitetypes => ['Local'],
-startcommand => sub {
set_sourceItem();
},
);
$widget->DropSite(
-droptypes => ['Local'],
-dropcommand => sub {
dropItemOpr();
} ,
);
}
smallpond - 03 Jul 2008 18:11 GMT
> Hi all,
>
> I am using Tk 5.8.3, getting problem in drag n drop.
perl/Tk is independent of the version of Tk installed on your system.
Check its version with:
perl -e 'use Tk; print "Tk version = $Tk::VERSION\n"'
Tk version = 804.027502
> I am creating a tree with optional scroll bar, on each child of this
> tree i am creating a frame (colored green in following code), and a
[quoted text clipped - 14 lines]
> Thanks,
> Rahul Dashore
> sub getMousePositionOnTree {
>
[quoted text clipped - 7 lines]
> return ($ent);
> }
I haven't tried running your code, but I would check whether
this calculation does what you expect using print or ptkdb.
I think event->Y and rooty are screen coordinates of the
mouse and top left window coordinate. You may have to
adjust for the scrolled position to get the widget coordinate.
I'm not familiar with GetNearest, so I don't know what
parameters it expects.
--S
** Posted from http://www.teranews.com **