Thread drag & drop (8 answers)
Opened by Optalamia at 2003-12-12 14:03

esskar
 2003-12-12 16:07
#46424 #46424
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/local/bin/perl -w

use Tk;
use Tk::DragDrop;
use Tk::DropSite;
use strict;
use vars qw($top $listbox $dnd);

$top = new MainWindow;
$top->Label(-text => "The drop area:")->pack;

$listbox = $top->Scrolled('Listbox', -scrollbars => "osoe")->pack;

$listbox->DropSite(
-dropcommand => [\&accept_drop, $listbox],
-droptypes => ($^O eq 'MSWin32' ? 'Win32' : ['KDE', 'XDND', 'Sun'])
);

$dnd = $listbox->DragDrop(
-event => '<B1-Motion>',
-sitetypes => ($^O eq 'MSWin32' ? 'Win32' : ['KDE', 'XDND', 'Sun']),
-startcommand => \&start_drag,
-handlers => [[-type => 'STRING', \&send_string]]
);

MainLoop;

sub start_drag
{
my($token) = @_;
my $w = $token->parent;
my $e = $w->XEvent;
my $idx = $w->nearest($e->y);

if(defined $idx)
{
$token->configure(-text => $w->get($idx));
my($X, $Y) = ($e->X, $e->Y);
$token->MoveToplevelWindow($X, $Y);
$token->raise;
$token->deiconify;
$token->FindSite($X, $Y, $e);
}
}

sub send_string
{
my ($offset, $max) = @_;

my ($lb_sel) = $listbox->curselection;
my ($req) = $listbox->get($lb_sel);
return $req;
}


sub accept_drop
{
my($widget, $selection) = @_;

my $filename;
eval {
if ($^O eq 'MSWin32') {
$filename = $widget->SelectionGet(-selection => $selection, 'STRING');
} else {
$filename = $widget->SelectionGet(-selection => $selection, 'FILE_NAME');
}
};
if (defined $filename) {
$widget->insert(0, $filename);
}
}



ist mal ein anfang...
man kann file(name)s reindroppen und auch rausziehen...
aber das loslassen im explorer zeigt keine wirkung...

muss weg

View full thread drag & drop