#!/usr/local/bin/perl -w
use Tk;
use strict;
use Tk::DropSite;
my $kind;
if ($^O eq 'MSWin32')
 {
  use Tk::DropSite qw(Win32);
  $kind = 'Win32';
 }
else
 {
  use Tk::DropSite qw(Sun);
  $kind = 'Sun';
 }
use Tk::Menubar;  

sub enter_leave
{          
 my ($ds,$flag) = @_;
 $ds->configure(-relief => ($flag) ? 'sunken' : 'ridge');
 return 1;
}



my $top = MainWindow->new();
my $mb  = $top->Menubar;
$mb->Menubutton(-text => '~File', -menuitems => [
                [ Button => 'E~xit', -command => [ destroy => $top]],
                ]);

my $lb = $top->Scrolled('Listbox',-width => 40);

my $sun = $top->Message('-text' => "$kind Drops here", '-relief' => 'ridge' )->pack(-side => 'left');
$sun->DropSite(-dropcommand => [\&ShowTargets,$lb], -droptypes => $kind);

my $loc = $top->Message('-text' => "Local Drops here", '-relief' => 'ridge' )->pack(-side => 'right');
$loc->DropSite(-dropcommand => [\&ShowTargets,$lb], -droptypes => ['Local']);

my $eth = $top->Message('-text' => "Either Drops here", '-relief' => 'ridge' )->pack(-side => 'right');
$eth->DropSite(-dropcommand => [\&ShowTargets,$lb], 
               -entercommand => [\&enter_leave,$eth]
);

$lb->pack(-side => 'bottom');

$top->Button('-text' => "Primary Targets", '-command' => [\&ShowTargets,$lb,'PRIMARY'])->pack('-side'=>'left');
$top->Button('-text' => "Quit", '-command' => ['destroy',$top])->pack('-side'=>'right');

MainLoop;

sub ShowTargets
{
 my $lb = shift;
 my $seln = shift;
 my $own =  $lb->SelectionExists('-selection'=>$seln);
 printf "owner of $seln is %x\n",$own;
 my @targ = $lb->SelectionGet('-selection'=>$seln,'TARGETS');
 $lb->delete(0,'end');
 $lb->insert('end',@targ);
 foreach (@targ)
  {
   if (/FILE_NAME/)
    {
     print $lb->SelectionGet('-selection'=>$seln,'FILE_NAME'),"\n";
    }
   if ($^O eq 'MSWin32' && /STRING/)
    {
     print $lb->SelectionGet('-selection'=>$seln,$_),"\n";
    } 
  }
}


