#!/usr/bin/perl -w
use strict;

# We do not want STDERR to clutter our screen.
open STDERR, ">/dev/null";

use FindBin;
use lib "$FindBin::RealBin/../lib";
use Curses::UI;
my $cui = new Curses::UI ( -clear_on_exit => 1 );

my $win = $cui->add('window_id', 'Window');

$win->add(
        'label0', 'Label',
        -text => "Press <CTRL+Q> to leave this demo."
);

$win->add(
	'label1', 'Label', -y => 2,
        -text => "Here, the calendar widget\n"
               . "and the textentry are linked\n"
               . "together using onChange events."
);

$win->add(
	'calendar', 'Calendar',
	-border => 1,
	-y => 7,
	-x => 1,
	-onChange => sub {
		my $cal = shift;
		my $win = $cal->parent;
		$win->getobj('entry')->text($cal->get);
	},
);

$win->add(
	'entry', 'TextEntry',
	-border => 1,
	-width => $win->getobj('calendar')->width,
	-y => 20,
	-x => 1,
	-onChange => sub {
		my $entry = shift;
		my $win = $entry->parent;
		$win->getobj('calendar')->setdate($entry->get);
		$win->getobj('calendar')->date_selected;
	}
);

$win->add(
	'label2', 'Label', -y => 2, -x => 34,
        -text => "Here, the onFocus and onBlur events\n"
               . "are linked to the popupmenu to present\n"
               . "a status dialog. The onChange event\n"
               . "is used to update the status label."
);

$win->add(
	'popup', 'Popupmenu',
	-x => 34, -y => 7,
	-values => ['First item', 'Second item', 
                    'Third item', 'Fourth item',
		    'Fifth item', 'Sixth item',
 		    'Seventh item', 'Eighth item'],
	-onChange => sub {
		my $pu = shift;
		my $win = $pu->parent;
		$win->getobj('popup_status')->text("status: " . $pu->get);
	},
	-onFocus => sub {
		my $pu = shift;
		$pu->root->status("onFocus event for the popupmenu");
		sleep 1;
		$pu->root->nostatus;
	},
	-onBlur => sub {
		my $pu = shift;
		$pu->root->status("onBlur event for the popupmenu");
		sleep 1;
		$pu->root->nostatus;
	},
);

$win->add(
	'popup_status', 'Label',
	-x => 34, -y => 9,
	-text => "status: none selected"
);

$win->returnkeys("\cC", "\cQ");
$win->focus;

