From: Mattia B. <mb...@ds...> - 2002-04-23 20:08:22
|
> hello > > i wish to drag items from a listctrl to a treeITEM. > i set the treectrl as TextDropTarge,t but this is not usuable for me. > > i wish that dragging data over a treeitem selects this > and only this is allowd (wxDragNone if in treectrl window / > not over an treeItem) > > i have really no idea of how to do this or if this > is possible at all. > > hints/help apprechiated. Code below, I hope it is clear; it accepts a bitmap, you just need to supply a different data object HTH Mattia package TreeDropTarget; use base qw(Wx::DropTarget); sub new { my $class = shift; my $tree = shift; my $canvas = shift; my $this = $class->SUPER::new; my $data = Wx::BitmapDataObject->new; $this->SetDataObject( $data ); $this->{TREE} = $tree; $this->{DATA} = $data; $this->{CANVAS} = $canvas; return $this; } sub data { $_[0]->{DATA} } sub canvas { $_[0]->{CANVAS} } use Wx qw(:treectrl wxDragNone wxDragCopy); sub OnDragOver { my( $this, $x, $y ) = @_; my $tree = $this->{TREE}; my( $item, $flags ) = $tree->HitTest( [$x, $y] ); if( $flags & wxTREE_HITTEST_ONITEMLABEL ) { $tree->SelectItem( $item ); return wxDragCopy; } else { $tree->Unselect(); return wxDragNone; } } sub OnData { my( $this, $x, $y, $def ) = @_; $this->GetData; $this->canvas->SetBitmap( $this->data->GetBitmap ); return $def; } |