From WxPerl wiki
Wx::MyApp->new()->MainLoop(); # FYI, this is package main
package MyURLDropTarget;
use Wx::DND;
use strict;
use base qw( Wx::DropTarget ); # package Wx::DropTarget is defined in Wx::DND
sub OnDragOver {
return &Wx::wxDragLink; # very important, don't forget
}
sub new {
my( $class, $canvas) = @_;
my $this = $class->SUPER::new;
my $data = Wx::URLDataObject->new;
for my $f( $data->GetAllFormats() ){ # some metadata
printf "Id: %s\n", $f->GetId if $f->GetId;
printf "Type: %s\n", $f->GetType if $f->GetType;
print "-\n";
}
$this->SetDataObject( $data );
$this->{DATA} = $data;
$this->{CANVAS} = $canvas;
return $this;
}
sub data {$_[0]->{DATA};}
sub canvas {$_[0]->{CANVAS};}
sub OnData {
my( $this, $x, $y, $def ) = @_;
$this->GetData(); # copy the data to $data, our dataobject
my $data = $this->data;
$this->canvas->AppendText( $data->GetURL()."\n" );
return $def; # per manuals instruction
}
1;
package Wx::MyApp;
use Wx;
use base qw(Wx::App);
use strict;
sub OnInit {
my( $self ) = @_;
my( $frame ) = Wx::Frame->new(undef,-1,__PACKAGE__,[50,50],[520,200]);
$frame->SetBackgroundColour( new Wx::Colour(255, 255, 255) ); # white
# files drop target
my $DNDStaticText = Wx::StaticText->new( $frame, -1, 'Drop links below', );
my $dropTarget= Wx::TextCtrl->new(
$frame, -1,
"drop links here\n\n\n",
[0,20],
[500,-1],
&Wx::wxTE_MULTILINE | &Wx::wxTE_READONLY
);
$dropTarget->SetDropTarget( MyURLDropTarget->new( $dropTarget) );
$frame->Show(1);
return 1;
}
1;