#!/bin/sh
#-*-Perl-*-

exec perl -x $0 "$@";

#!perl

use Tk;
use Tk::MulColListbox;

$top = new MainWindow();

$frame = $top->Frame(-background=>"red",
		    )->pack(-side=>top,
			    -expand=>1,
			    -fill=>"both",
			    -padx=>10,
			    -pady=>10);

$mcl = $frame->MulColListbox(-headerbackground=>"green",
			     -headerlight=>"lightgreen",
			     -headerdark=>"darkgreen",
			     -headerforeground=>"black",
			     -headerborderwidth=>1,
                             -marker=>1,
			     -markerstyle=>"diamond",
			     -background=>"white",
			     -foreground=>"black",
			     -relief=>"sunken",
			     -borderwidth=>2,
			     -height=>0,
			     -width=>0,
			     -scrollbarrelief=>"flat",
			     -scrollbarborderwidth=>1,
			     -scrollbarwidth=>10,
			    )->pack(-side=>"top",
				    -expand=>1,
				    -fill=>"both");

$mcl->AddColumn(-header=>"Sender",
		-key=>"sender",
		-width=>25);
$mcl->AddColumn(-header=>"Subject",
		-key=>"subject",
		-width=>50);
$mcl->AddColumn(-header=>"Date",
		-key=>"date",
		-width=>100);

$top->Button(-text=>"insert some",
	     -command=>sub {
	       $mcl->insert(0,
			    {
			     sender=>"pgmillard\@jabber.org",
			     subject=>"Hey",
			     date=>"2000/06/10 11:52"
			    },
			    {
			     sender=>"pgmillard\@jabber.org",
			     subject=>"re: Hey",
			     date=>"2000/06/10 11:54"
			    });
	     })->pack();

$top->Button(-text=>"insert more",
	     -command=>sub {

	       foreach (0..40) {
		 $mcl->insert(0,
			      {
			       sender=>"pgmillard\@jabber.org",
			       subject=>"re: Hey",
			       date=>"2000/06/10 11:54 $_"
			      }
			     );
	       }	
	     })->pack();


$top->Button(-text=>"delete",
	     -command=>sub {
	       $mcl->delete(3,7);
	     })->pack();

$top->Button(-text=>"curselection",
	     -command=>sub {
	       print "curselection: (",$mcl->curselection(),")\n";
	     })->pack();

$top->Button(-text=>"Delete Sender",
	     -command=>sub {
	       $mcl->DeleteColumn("sender");
	     })->pack();

$top->Button(-text=>"Delete Subject",
	     -command=>sub {
	       $mcl->DeleteColumn("subject");
	     })->pack();

$top->Button(-text=>"Delete Date",
	     -command=>sub {
	       $mcl->DeleteColumn("date");
	     })->pack();

$top->Button(-text=>"Add Sender",
	     -command=>sub {
		 $mcl->AddColumn(-header=>"Sender",
				 -key=>"sender",
				 -width=>50);
	     })->pack();
$top->Button(-text=>"Add Subject",
	     -command=>sub {
		 $mcl->AddColumn(-header=>"Subject",
				 -key=>"subject",
				 -width=>200);
	     })->pack();
$top->Button(-text=>"Add Date",
	     -command=>sub {
		 $mcl->AddColumn(-header=>"Date",
				 -key=>"date",
				 -width=>100);
	     })->pack();



$mcl->bind("<Button-3>",
	   [ sub {
	       my ($mcl,$y) = @_;

	       print "mcl($mcl)\n";
	       print "y($y)\n";
	       print $mcl->nearest($y),"\n";
	     },
	     Ev('y')
	   ]
	  );

&MainLoop();

