package main;
my ($app) = MyApp->new();
$app->MainLoop();
package MyApp;
use base qw(Wx::App);
sub OnInit {
my ($self) = shift;
my ($frame) = MyFrame->new;
$frame->Show(1);
$self->SetTopWindow($frame);
return 1;
}
package MyFrame;
use Wx::Perl::Carp;
use Wx;
use base 'Wx::Frame';
sub new {
my $class = shift;
my $self = $class->SUPER::new( undef, -1, 'Hiya there' );
my $panel = Wx::Panel->new( $self, -1 );
use Wx qw' wxLB_SINGLE ';
$self->{lb1} = Wx::ListBox->new(
$panel, -1,
[ 10, 10 ],
[ 100, 200 ],
[ "red", "green", "blue", 1 .. 8 ], wxLB_SINGLE
);
use Wx::Event qw( EVT_LISTBOX );
EVT_LISTBOX( $self, $self->{lb1}, \&on_select );
$self->{lb2} = Wx::ListBox->new(
$panel, -1,
[ 120, 10 ],
[ 100, 200 ],
[ "10", "20", "30" ], wxLB_SINGLE
);
use Wx qw' wxTE_READONLY wxTE_MULTILINE wxDefaultPosition wxDefa
+ultSize ';
$self->{logtext} = Wx::TextCtrl->new(
$self, -1, "Welcome to wxPerl\n",
wxDefaultPosition,
[ 200, 100 ],
wxTE_READONLY | wxTE_MULTILINE
);
Wx::Log::SetActiveTarget( Wx::LogTextCtrl->new( $self->{logtext} )
+ );
use Wx qw' wxVERTICAL wxEXPAND wxHORIZONTAL wxALL ';
my ($topsizer) = Wx::BoxSizer->new(wxVERTICAL);
my ($logsizer) = Wx::BoxSizer->new(wxHORIZONTAL);
$topsizer->Add( $panel, 0, wxEXPAND );
$topsizer->AddSpacer(1);
$logsizer->Add( $self->{logtext}, 1, wxALL | wxEXPAND, 0 );
$topsizer->Add( $logsizer, 1, wxEXPAND );
$self->SetSizer($topsizer);
$self->Layout();
$topsizer->Fit($self);
$topsizer->SetSizeHints($self);
$self->{target} = MyTextTarget->new( $self->{lb2} );
return $self;
}
sub on_select {
my ( $self, $event ) = @_;
my $selection = $self->{lb1}->GetSelection();
my $text = $self->{lb1}->GetStringSelection();
carp( 'selected text ', $text );
my $text_obj = Wx::TextDataObject->new($text);
my $source = Wx::DropSource->new( $self->{lb1} );
$source->SetData($text_obj);
use Wx qw' wxDrag_AllowMove wxDrag_DefaultMove wxDragMove wxDragCo
+py
wxDragMove
wxDragLink
wxDragCancel
wxDragNone
';
my $drop_result = $source->DoDragDrop(wxDrag_DefaultMove);
carp(
'drop_result(',
$drop_result,
') ',
'wxDragCopy (',
wxDragCopy,
') ',
'wxDragMove (',
wxDragMove,
') ',
'wxDragLink (',
wxDragLink,
') ',
'wxDragCancel (',
wxDragCancel,
') ',
'wxDragNone (',
wxDragNone,
') '
);
if ( $drop_result == wxDragMove ) { #the selection was moved-no
+t copied
carp( 'deleting ', $self->{lb1}->Delete($selection) );
}
}
package MyTextTarget;
use Wx::Perl::Carp;
use Wx::DND;
use strict;
use base qw( Wx::TextDropTarget );
sub new {
my $class = shift;
my $target_widget = shift;
my $self = $class->SUPER::new(@_);
$self->{target_widget} = $target_widget;
$self->{target_widget}->SetDropTarget($self);
$self->{text_obj} = Wx::TextDataObject->new($target_widget);
$self->SetDataObject( $self->{text_obj} );
return $self;
}
sub OnDropText {
carp("OnDropText @_ ");
my ( $self, $x, $y, $d ) = @_;
$self->GetData();
my $text = $self->{text_obj}->GetText();
my $c = $self->{target_widget}->GetCount();
carp( 'count ', $c );
$self->{target_widget}->InsertItems( [$text], $c );
return 1; # important
}
__END__
|