| 1 |
#!/usr/local/bin/perl -w |
| 2 |
use Tk; |
| 3 |
use strict; |
| 4 |
use Tk::DragDrop; |
| 5 |
use Tk::DropSite; |
| 6 |
|
| 7 |
my $top = MainWindow->new(); |
| 8 |
|
| 9 |
my $lb = $top->Scrolled('Listbox',-width => 40); |
| 10 |
|
| 11 |
my $thing = $top->Message('-text' => "Drag This with B1")->pack; |
| 12 |
|
| 13 |
my $source = $thing->DragDrop(-event => '<B1-Motion>', |
| 14 |
-sitetypes => [qw(Local)], |
| 15 |
-handlers => [[\&send_string], [-type => 'FILE_NAME', \&send_file]]); |
| 16 |
|
| 17 |
my $loc = $top->Message('-text' => "Local Drops here", '-relief' => 'ridge' )->pack(-side => 'right'); |
| 18 |
$loc->DropSite(-droptypes => [qw(Local)], -dropcommand => [\&ShowTargets,$lb]); |
| 19 |
|
| 20 |
$lb->pack(-side => 'bottom'); |
| 21 |
|
| 22 |
$top->Button('-text' => "Sites", '-command' => [\&ShowSites,$top])->pack('-side'=>'left'); |
| 23 |
$top->Button('-text' => "Quit", '-command' => ['destroy',$top])->pack('-side'=>'right'); |
| 24 |
|
| 25 |
MainLoop; |
| 26 |
|
| 27 |
sub send_string |
| 28 |
{ |
| 29 |
my ($offset,$max) = @_; |
| 30 |
return "These are dropped Data"; |
| 31 |
} |
| 32 |
|
| 33 |
sub send_file |
| 34 |
{ |
| 35 |
my ($offset,$max) = @_; |
| 36 |
return __FILE__; |
| 37 |
} |
| 38 |
|
| 39 |
sub ShowIt |
| 40 |
{ |
| 41 |
my $w = shift; |
| 42 |
my ($id,$x,$y,$width,$height) = @_; |
| 43 |
my $t = $w->Toplevel; |
| 44 |
$t->Button('-text'=>$id,'-command'=>['destroy',$t])->pack('-anchor'=>'c','-fill'=>'both'); |
| 45 |
$t->overrideredirect(1); |
| 46 |
$t->update('idletasks'); |
| 47 |
$t->MoveResizeWindow($x,$y,$width,$height); |
| 48 |
} |
| 49 |
|
| 50 |
sub ShowTargets |
| 51 |
{ |
| 52 |
my $lb = shift; |
| 53 |
my $seln = shift; |
| 54 |
my @targ = $lb->SelectionGet('-selection'=>$seln,'TARGETS'); |
| 55 |
$lb->delete(0,'end'); |
| 56 |
$lb->insert('end',@targ); |
| 57 |
} |
| 58 |
|
| 59 |
sub ShowSites |
| 60 |
{ |
| 61 |
my $w = shift; |
| 62 |
my @dnd = $w->SelectionGet('-selection'=>"_SUN_DRAGDROP_DSDM", |
| 63 |
"_SUN_DRAGDROP_SITE_RECTS"); |
| 64 |
while (@dnd) |
| 65 |
{ |
| 66 |
my $version = shift(@dnd); |
| 67 |
my $site = shift(@dnd); |
| 68 |
my $win = shift(@dnd); |
| 69 |
my $x = shift(@dnd); |
| 70 |
my $y = shift(@dnd); |
| 71 |
my $width = shift(@dnd); |
| 72 |
my $height = shift(@dnd); |
| 73 |
my $flags = shift(@dnd); |
| 74 |
ShowIt($w,sprintf("%x:%d",$win,$site),$x,$y,$width,$height); |
| 75 |
} |
| 76 |
|
| 77 |
} |
| 78 |
|