package Tk
::DragDrop
::XDNDDrop
;
$VERSION = '3.009'; # $Id: //depot/Tk8/DragDrop/DragDrop/XDNDDrop.pm#9 $
use base qw(Tk::DragDrop::Rect);
sub XDND_PROTOCOL_VERSION
() { 3 }
Tk
::DragDrop
->Type('XDND');
my ($class,$token,$id,@prop) = @_;
my $ver = $token->InternAtom(shift(@prop));
warn "XDND version $ver ".join(' ',@prop)."\n";
$ver = XDND_PROTOCOL_VERSION
if $ver > XDND_PROTOCOL_VERSION
;
my $site = bless { id
=> $id, token
=> $token, ver
=> $ver, state => 0, accept => \
@prop}, $class;
$w->BindClientMessage('XdndStatus',[$site => 'XdndStatus']);
$w->BindClientMessage('XdndFinished',[$site => 'XdndFinished']);
my ($site,$token,$seln,$e) = @_;
my $data = pack('LLLLL',oct($w->id),0,$e->t,0,0);
$w->SendClientMessage('XdndDrop',$site->{id
},32,$data);
my ($class,$token,$X,$Y) = @_;
my $id = $token->PointToWindow($X,$Y);
Tk
::catch
{ @prop = $token->property('get','XdndAware', $id) };
if (!$@
&& shift(@prop) eq 'ATOM')
my $hash = $token->{$class};
$site = $class->new($token,$id,@prop);
$id = $token->PointToWindow($X,$Y,$id)
my ($site,$token,$e) = @_;
$token->InstallHandlers('XdndSelection');
my $seln = $token->cget('-selection');
my @targets = grep(!/^(TARGETS|MULTIPLE|TIMESTAMP)$/,reverse($token->SelectionGet('-selection'=> 'XdndSelection','TARGETS')));
# print join(' ',@targets),"\n";
my $flags = ($site->{ver
} << 24);
my @atarg = map($token->InternAtom($_),@targets);
$w->property('set','XdndTypeList','ATOM',32,\
@atarg);
splice(@atarg,$ntarg,(0 x
3 - $ntarg));
unshift(@atarg,oct($w->id),$flags);
# print join(' ',map(sprintf("%08X",$_),@atarg)),"\n";
my $data = pack('LLLLL',@atarg);
$w->SendClientMessage('XdndEnter',$site->{id
},32,$data);
my ($site,$token,$e) = @_;
my $data = pack('LLLLL',oct($w->id), 0, 0, 0, 0);
$w->SendClientMessage('XdndLeave',$site->{id
},32,$data);
my ($site,$token,$e) = @_;
my $action = $token->InternAtom($site->{'action'} || 'XdndActionCopy');
my @atarg = (oct($w->id),0,($X << 16) | $Y, $e->t, $action);
# print join(' ',map(sprintf("%08X",$_),@atarg)),"\n";
my $data = pack('LLLLL',@atarg);
$w->SendClientMessage('XdndPosition',$site->{id
},32,$data);
my $token = $site->{token
};
# printf "XdndFinished $site\n",
my $token = $site->{token
};
my ($tid,$flags,$xy,$wh,$action) = unpack('LLLLL',$event->A);
$action = $w->GetAtomName($action) if $action;
$site->{'X'} = $xy >> 16;
$site->{'Y'} = $xy & 0xFFFF;
$site->{'width'} = $wh >> 16;
$site->{'height'} = $wh & 0xFFFF;
#printf "XdndStatus $site targ=%x flags=%08X x=%d y=%d w=%d h=%d a=%s\n",
# $tid,$flags,$xy >> 16, $xy & 0xFFFF, $wh >> 16, $wh & 0xFFFF,$action;