Debian Codegraph @

DragDrop/drag_test

raw
1 #!/usr/local/bin/perl -w
2 use Tk;
3 use strict;
4 use Tk::DragDrop qw(Sun);
5 #use Tk::DropSite qw(Sun);
6
7 my $top = MainWindow->new();
8
9 my $thing = $top->Message('-text' => "Drag This with B1")->pack;
10 $thing->DragDrop(-event => '<B1-Motion>', -sitetypes => [qw(Sun)], -handlers => [[\&handler]]);
11
12 $top->Button('-text' => "Sites", '-command' => [\&ShowSites,$top])->pack('-side'=>'left');
13 $top->Button('-text' => "Quit", '-command' => ['destroy',$top])->pack('-side'=>'right');
14
15 MainLoop;
16
17 sub handler
18 {
19 my ($offset,$max) = @_;
20 return "These are dropped Data";
21 }
22
23 sub ShowIt
24 {
25 my $w = shift;
26 my ($id,$x,$y,$width,$height) = @_;
27 my $t = $w->Toplevel;
28 $t->Button('-text'=>$id,'-command'=>['destroy',$t])->pack('-anchor'=>'c','-fill'=>'both');
29 $t->overrideredirect(1);
30 $t->update('idletasks');
31 $t->MoveResizeWindow($x,$y,$width,$height);
32 }
33
34 sub ShowSites
35 {
36 my $w = shift;
37 print "Getting via $w ",$w->PathName,"\n";
38 my @dnd = $w->SelectionGet('-selection'=>"_SUN_DRAGDROP_DSDM",
39 "_SUN_DRAGDROP_SITE_RECTS");
40 while (@dnd)
41 {
42 my $version = shift(@dnd);
43 my $site = shift(@dnd);
44 my $win = shift(@dnd);
45 my $x = shift(@dnd);
46 my $y = shift(@dnd);
47 my $width = shift(@dnd);
48 my $height = shift(@dnd);
49 my $flags = shift(@dnd);
50 ShowIt($w,sprintf("%x:%d",$win,$site),$x,$y,$width,$height);
51 }
52
53 }