#!/usr/bin/perl -I/mit/gimp/lib/perl5/site_perl

use Gtk;
use Gtk::Atoms;

init Gtk;

sub destroy_window {
	my($widget, $windowref, $w2) = @_;
	$$windowref = undef;
	$w2 = undef if defined $w2;
	0;
}


sub do_exit {
	Gtk->exit(0);
}

sub create_main_window {

    my @item_names = ( "hello",
		      "the quick brown fox",
		      "the quick brown fox",
		      "the quick brown dog",
		      "the quick brown elephant",
		      "the quick brown fox",
		      "the quick brown fox",
		      "the quick brown tangental stirring rod",
		      "the quick brown\ntangental stirring rod",
		      "the quick brown fox",
		      "the quick brown fox",
		      "jumped over the lazy" );

    my ($window, $outervb, $scw, $scrollbox, $utcount);
    
    my $UTcount = scalar @item_names;

    $window = new Gtk::Window('toplevel');
    $window->set_name("Grading Checklist");
    $window->set_uposition(20, 20);
    $window->set_usize(500, 300);
    
    $window->signal_connect("destroy" => \&do_exit);
    $window->signal_connect("delete_event" => \&do_exit);

    $outervb = new Gtk::VBox(0,0);
    $window->add($outervb);
    $outervb->show;

    $scw = new Gtk::ScrolledWindow(undef, undef);
    $scw->set_policy('automatic', 'automatic');
    $scw->show;
    $scw->border_width(10);
    $outervb->pack_start($scw, 1, 1, 0);

    $scrollbox =  new Gtk::VBox(0, 0);
    #border_width $box2 10;
    $scrollbox->show;
    $scrollbox->border_width(10);
    $scw->add($scrollbox);
	

    for $iname (@item_names) {
	print "adding $iname\n";	
	#my $button = new Gtk::Button($_);
	#$scrollbox->pack_start($button, 0, 0, 0);
	#show $button;
	my $listline = new Gtk::HBox(0,0);
	$listline->show;

	my $untested = new Gtk::RadioButton "untested";
	$listline->pack_start($untested,0,0,0);
	$untested->set_state(1);
	$untested->show;
	$untested->signal_connect("toggled",  
				  sub { 
				      my ($b, $ut) = @_;
				      printf "toggle <%s> (%s) (%s)!\n", $b, 
				      $b->active, $$ut; 
				      if   ($b->active) {$$ut++;}
				      else {$$ut--;}
				      $utcount->set_text($$ut);
				  }, \$UTcount);

	my $pass = new Gtk::RadioButton "pass", $untested;
	$listline->pack_start($pass,0,0,0);
	$pass->show;

	my $fail = new Gtk::RadioButton "fail", $untested;
	$listline->pack_start($fail,0,0,0);
	$fail->show;

	my $label = new Gtk::Label $iname;
	$listline->pack_start($label,0,0,20);
	$label->show;

	$scrollbox->pack_start($listline,0,0,0);
	$scrollbox->show;
	
	my $hline = new Gtk::HSeparator;
	$scrollbox->pack_start($hline,1,1,0);
	$hline->show;
    }

    my $nameline = new Gtk::HBox(0,10);
    $outervb->pack_start($nameline, 0, 0, 5);
    my $namelabel = new Gtk::Label("Name: ");
    $namelabel->show;
    $nameline->pack_start($namelabel, 0, 0, 5);
    my $name = new Gtk::Entry;
    $name->set_text("");
    $nameline->pack_start($name, 0, 0, 5);
    $name->show;
    $nameline->show;

    my $resultline = new Gtk::HBox(0,10);
    $outervb->pack_start($resultline, 0, 0, 5);
    my $untested_count_label = new Gtk::Label("Untested: ");
    $untested_count_label->show;
    $resultline->pack_start($untested_count_label, 0, 0, 5);
    $utcount = new Gtk::Entry;
    $utcount->set_text($UTcount);
    $utcount->set_editable(0);
    $resultline->pack_start($utcount, 0, 0, 5);
    $utcount->show;
    $resultline->show;

    


    $window->show;

}



parse Gtk::Rc "checklist.gtkrc";

create_main_window;

main Gtk;
