#!perl -w

use strict;

use Win32::GUI;

my $obMW;
my $obCW;

my $clW = new Win32::GUI::Class(-name => "NoFlicker", -style => 0);

$obMW = Win32::GUI::Window->new(
	-title    	=> "Hierarchical Controls",
	-class		=> $clW,
	-pos		=> [ 100, 100 ],
	-size     	=> [ 240, 150 ],
	-minsize    => [ 240, 150 ],
	-dialogui	=> 1,
	-onResize	=> sub { $obCW->Move(0, $obMW->Height-100);
						 $obCW->Resize(($obMW->GetClientRect)[2], 50);
						 1
					   },
	-onActivate	=> sub { $obCW->Show(); 1 },
);

$obMW->AddButton(
	-name		=> "btParent",
	-text		=> "Button 1",
	-size		=> [ 70, 22 ],
	-pos		=> [ 20, 20 ],
	-tabstop	=> 1,
	-onClick	=> sub { $obMW->txParent->Text("Button 1");
						 $obCW->txChild->Text("Button 1");
						 $obCW->Enable($obCW->IsEnabled ? 0 : 1);
						 $obCW->InvalidateRect(1);
						 1;
					   },
);

$obMW->AddTextfield(
	-name		=> "txParent",
	-text		=> "Textfield 1",
	-size		=> [ 100, 22 ],
	-pos		=> [ 100, 22 ],
	-tabstop	=> 1,
);

$obCW = new Win32::GUI::Window(
  	-name		=> 'cw',
  	-parent		=> $obMW,
    -remstyle	=> WS_CAPTION | WS_SIZEBOX,
	-addstyle	=> WS_CHILD | WS_CLIPCHILDREN,
	-addexstyle	=> WS_EX_CONTROLPARENT,
	-onResize	=> sub { return 1 unless exists $obCW->{txChild}; 
						 $obCW->txChild->Resize(($obCW->GetClientRect)[2]-130,22);
						 1;
					   },
);

$obMW->AddButton(
	-name		=> "btChild",
	-parent		=> $obCW,
	-text		=> "Button 2",
	-size		=> [ 70, 22 ],
	-pos		=> [ 20, 5 ],
	-tabstop	=> 1,
	-onClick	=> sub { $obMW->txParent->Text("Button 2");
						 $obCW->txChild->Text("Button 2");
						 $obMW->txParent->Enable($obMW->txParent->IsEnabled ? 0 : 1);
						 $obMW->btParent->Enable($obMW->btParent->IsEnabled ? 0 : 1);
						 1;
					   },
);

$obMW->AddTextfield(
	-name		=> "txChild",
	-parent		=> $obCW,
	-text		=> "Textfield 2",
	-pos		=> [ 100, 5 ],
	-tabstop	=> 1,
);

$obMW->Show();
Win32::GUI::Dialog();
undef $obMW;
