package Perlbox::perlboxTK::pDialog::pSimplesDialog;
use Tk;
use strict;

use vars qw( $VERSION @ISA) ;

$VERSION = '0.1.x' ;

require Tk::Toplevel ;

@ISA = qw( Tk::Toplevel ) ;

Construct Tk::Widget 'pSimpleDialog' ;

   my $mw;
   my ($textVar, $titleVar,$okonly);
   my $returnVal;
   return 1;


sub Populate(){

       my $args;
       ($mw, $args) = @_;
        $mw->SUPER::Populate($args);
	    $textVar = delete $args->{"-text"};
        $titleVar= delete $args->{"-title"};
        $okonly = delete $args->{"-OKonly"};
        $mw->protocol( 'WM_DELETE_WINDOW' => sub { } ) ;
        $mw->transient( $mw->MainWindow ) ;

}

sub Show(){
	#construct the size of our widget
	my $ht=150;

	$mw->geometry("200x".$ht."+10+10");
        $mw->title($titleVar);

	my $label=$mw->Label(-text=>$textVar, -wraplength=>190, -font=>($mw->fontCreate(-family=>"courier",-size=>9)),-anchor=>'w',-justify=>'left')->
	           place(-y=>10,-x=>10, -width=>190, -height=>100);
        if($okonly ne 'yes'){
           my $cmdCancel=$mw->Button(-text=>"NO", -relief=>'flat',-command=> sub{&myNo})->
       		   place(-y=>$ht-30,-x=>10,-width=>80, -height=>20);

           my $cmdOk=$mw->Button(-text =>"YES",-relief=>'flat', -command => sub{&myYes;})->
       		   place(-y=>$ht-30,-x=>110,-width=>80,-height=>20);
        }
        else{
           my $cmdOk=$mw->Button(-text =>"OK",-relief=>'flat', -command => sub{&myYes;})->
       		   place(-y=>$ht-30,-x=>110,-width=>80,-height=>20);
        }
        $mw->waitVariable( \$returnVal ) ;
        $mw->withdraw ;

        $returnVal;
}


sub myYes(){
  $returnVal=1;
}

sub myNo(){
   $returnVal=0;
}
