Umm, I know it's back there a bit, but you will find postings from myself and Rob on this issue. There are even examples in the Win32::GUI package for dragndrop operations.

If you can't locate it, let us know and I will dig up the files from my own archives ( I have it somewhere)

Regards,

Jason Plum

Duane Osborne wrote:
Hi,
I'm new to Win32 GUI and I've been trying to set up a
TreeView control with drag and drop capability.  I'd
just like
to be able to drag one node onto another within the
program (I don't need to drag in any outside data). I've been
searching and reading the posts in this list for help
but I haven't been able to get the TreeView to work
with drag
and drop.  Here are my three main issues:

1.  I can't get the expand/collapse events to work
when I have mouse down and mouse up events for the
same TreeView.
 What I mean is that when I create subroutines for
mouse up/down/move, my expand/collapse code will not
execute.
When I comment out the -onMouseUp/Down/Move in the
TreeView initiation, the expand/collapse subroutines
run.

2.  When clicking on the +/- box to expand a node, the
script thinks I'm starting a drag in addition to
expanding
the node.  Doing this corrupts the display by
partially highlighting items and creating ghost images
of the drag
icon.  (From reading the posts and through my own
testing, it seems that clicking the +/- symbol
initiates both the
collapse/expand event as well as the click/mouse down
event.)

3.  I'm not really sure how to drop the node on the
target.

If anyone has any ideas/thoughts, I'd greatly
appreciate them.  I'm currently using Perl 5.6.1.626
and Win32-GUI
1.03.  The test code that I'm using is listed below.

Thanks!

#!perl -w

use Win32::GUI;

# Build the window
$winMain = new GUI::Window(
   -name    => "winMain",
   -title   => "My TreeView Test",
-height => 480, -width => 640, -left => 100, -top => 100,
);

# Build the ImageList
$icoFolderClosed = new
GUI::Icon("tree-folder-closed.ico");
$icoFolderOpened = new
GUI::Icon("tree-folder-opened.ico");
$imlTreeView = new Win32::GUI::ImageList(16, 16, 1 |
0x0010, 2, 2);
$imlTreeView->AddIcon($icoFolderClosed);
$imlTreeView->AddIcon($icoFolderOpened);

# Build the TreeView control
$trvMain = $winMain->AddTreeView(
   -name             => "trvMain",
   -width            => 200,
   -height           => $winMain->ScaleHeight,
-left => 0, -top => 0, -lines => 1, -rootlines => 1,
   -buttons          => 1,
   -visible          => 1,
   -imagelist        => $imlTreeView,
   #-disabledragdrop  => 0,
   -onMouseDown      => \&mouseDown,
   -onMouseMove      => \&mouseMove,
   -onMouseUp        => \&mouseUp,
);

# Add several nodes to the tree
$nodeRoot = $trvMain->InsertItem(
   -text    => "Root",
   -image   => 0,
);
$nodeSub1 = $trvMain->InsertItem(
   -parent  => $nodeRoot,
   -text    => "Sub 1",
   -image   => 0,
);
$nodeSub2 = $trvMain->InsertItem(
   -parent  => $nodeRoot,
   -text    => "Sub 2",
   -image   => 0,
);
$nodeSub3 = $trvMain->InsertItem(
   -parent  => $nodeRoot,
   -text    => "Sub 3",
   -image   => 0,
);

# Show the main window
$winMain->Show();
# Enter event mode
Win32::GUI::Dialog();

# Subs

sub trvMain_Expand {
   my $node = $_[0];
   # Change the folder image to opened
   $trvMain->SetItem($node, -image => 1);
}

sub trvMain_Collapse {
   my $node = $_[0];
   # Change the folder image to closed
   $trvMain->SetItem($node, -image => 0);
}

sub mouseDown {
   # Get incoming variables
   my($object, $x, $y) = @_;
   # Set variable to indicate we are dragging
   $dragMode = 1;
   # Get the node that was clicked for dragging
   $draggedNode = $object->HitTest($x, $y);
   $object->SelectItem($draggedNode);
   # Create the drag image
   my $imlDrag =
$object->CreateDragImage($draggedNode);
   # Begin drag
   Win32::GUI::ImageList::BeginDrag($imlDrag, 0, 0,
0);
   # Enter the drag
   Win32::GUI::ImageList::DragEnter($object, $x, $y);
   return 1;
}

sub mouseMove {
   # Get incoming variables
   my($object, $x, $y) = @_;
   # Don't do anything unless the left mouse button is
down
   return unless $dragMode;
   # Move the drag image
   Win32::GUI::ImageList::DragMove($x, $y);
   # Highlight the nearest target node
   $targetNode = $object->HitTest($x, $y);
   $object->SelectDropTarget($targetNode);
   return 1;
}

sub mouseUp {
   # Get incoming variables
   my($object, $x, $y) = @_;
   # Don't do anything unless the left mouse button is
down
   return unless $dragMode;
   # Set variable to indicate end of dragging
   $dragMode = 0;
   # Leave and end the drag operation
   Win32::GUI::ImageList::DragLeave($object);
   # Move the node
   # ?????????
   Win32::GUI::ImageList::EndDrag();
   return 1;
}

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/




Reply via email to