|
Posted by Ch Lamprecht on March 5, 2007, 5:57 pm
Please log in for more thread options
~greg wrote:
> "Ch Lamprecht" > wrote ...
>
>>One way is setting up a timer:
>>This one will trigger group_drop_handler 50ms after the last call to
OnSourceDrop.
>
> It works!
> And I'm sure it's robust enough.
>
> But I was kinda hoping for something
> that didn't depend on timing. :)
>
> Following up on your suggestion,
> I found, and then substituted, ->afterIdle()
> for ->after().
>
> And this works too.
Reading the source I found, that it is not necessary to have the filenames
separated first, then appended to the clipboard, then read one by one by a
callback. A callback could as well get the filenames directly.
The code for the derived class is ugly because Tk::DragDrop::Win32Site is not
strictly OO - but it works:
(the code in main gets much shorter that way)
use strict;
use warnings;
#use Data::Dumper;
use Tk;
package Tk::DragDrop::Win32DirectSite;
require Tk::DragDrop::Win32Site;
our @ISA = ('Tk::DragDrop::Win32Site');
Tk::DropSite->Type('Win32Direct');
sub Win32Drop{
my ($w,$site,$msg,$wParam,$lParam) = @_;
my ($x,$y,@files) = Tk::DragDrop::Win32Site::DropInfo($wParam);
my $cb = $site->;
#$site->Apply(-entercommand => $x, $y, 1);
if ($cb){
$cb->Call($w,\@files);# passing the target widget
# and an arrayref containing the filenames
}
#$site->Apply(-entercommand => $x, $y, 0);
return 0;
}
sub WM_DROPFILES ()
sub InitSite{
my ($class,$site) = @_;
my $w = $site->widget;
$w->BindClientMessage(WM_DROPFILES,[\&Win32Drop,$site]);
Tk::DragDrop::Win32Site::DragAcceptFiles($w,1);
}
package main;
require Tk::DropSite ;
my $mw = MainWindow->new();
my $lb = $mw->Scrolled('Listbox',
-scrollbars => "osoe",
)->pack(-expand => 1,
-fill => 'both',
);
$lb->DropSite(-droptype => 'Win32Direct',
-dropcommand => \&drop_handler,
);
MainLoop;
sub drop_handler{
my ($w,$files) = @_;# target widget, filenames
@$files = map {$_ .= -d $_ ? '\':''} @$files;
$w->insert('end',@$files);
}
--
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub);MainLoop
|
|
Posted by ~greg on March 5, 2007, 6:45 pm
Please log in for more thread options
"Ch Lamprecht" > wrote...
> Reading the source I found, ...
Thank you!
I am not very good at reading the source yet,
although I know that it's often the best or the only documentation.
Below is the entire pod for Tk::DropSite!
I once asked if there was a contest for the worst documented module.
This would have to be one of my first choices.
Thank you!
~greg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tk::DropSite - Receive side of Drag & Drop abstraction
NAME
SYNOPSIS
DESCRIPTION
NAME
Tk::DropSite - Receive side of Drag & Drop abstraction
SYNOPSIS
use Tk::DropSite qw(...);
$widget->DropSite(-entercommand => ...,
-dropcommand => ...,
-motioncommand => ...,
-dropcommand => ...,
);
DESCRIPTION
DropSite creates an object which represents a site on which things may be
"Dropped".
A DropSite provides the following methods:
$site->Enter($token,$event)
$site->Leave($token,$event)
$site->Motion($token,$event)
$site->Drop($token,$event)
|
| Similar Threads | Posted | | DBI question | November 5, 2004, 4:28 pm |
| Newbie Question | January 3, 2005, 4:11 pm |
| LWP question on windows98 | October 7, 2004, 8:19 pm |
| Question to WIN32::OLE | October 14, 2004, 11:34 am |
| Simple question | September 15, 2005, 4:17 am |
| Getopt::Std question | September 7, 2005, 9:42 am |
| Question regarding databases.. | November 18, 2005, 9:41 am |
| Module Question | October 25, 2004, 11:42 am |
| A question of name space | October 31, 2004, 2:55 pm |
| Mechanize question | November 8, 2004, 10:57 pm |
|