Curses-Simp
view release on metacpan or search on metacpan
}
}
}
$self->{'_data'} = $self->{'_dtxt'};
if($self->{'_type'} eq 'drop'){
$self->{'_flagdrop'} = 1;
$self->{'_flagdown'} = 0;
$self->{'_flagcntr'} = 0;
$self->{'_lndx'} = 0 unless($self->{'_lndx'});
$self->{'_hite'} = 3;
if($self->{'_widt'} == (getmaxx() - 4) && @{$self->{'_text'}}){
$self->{'_widt'} = 3;
for(@{$self->{'_text'}}){
$self->{'_widt'} = (length($_) + 6) if($self->{'_widt'} < (length($_) + 6));
}
$self->{'_dtxt'} = $self->{'_text'}->[$self->{'_lndx'}];
$self->{'_data'} = $self->{'_dtxt'};
}
unshift(@{$self->{'_text'}}, $self->{'_data'});
}else{
$self->{'_text'}->[0] = $self->{'_data'} unless(@{$self->{'_text'}});
}
$self->{'_curs'} = length($self->{'_data'});
if($self->{'_widt'} < length($self->{'_titl'}) + 4){
$self->{'_widt'} = length($self->{'_titl'}) + 4;
}
$twid = $self->{'_widt'} - 2;
unless($self->{'_curs'} <= $twid){ # scrolling necessary off to the left
substr($self->{'_text'}->[0], 0, $twid, substr($self->{'_data'}, -$twid, $twid));
}
if($self->{'_flagclru'}){
$self->{'_fclr'}->[0] = $self->{'_hifc'} if($self->{'_curs'});
$self->{'_bclr'}->[0] = $self->{'_hibc'} if($self->{'_curs'});
}
$self->{'_ycrs'} = 0;
$self->{'_xcrs'} = $self->{'_curs'};
$self->{'_flagshrk'} = 0 if($self->{'_hite'} && $self->{'_widt'});
$self->Updt(1);
$self->{'_wind'} = newwin($self->{'_hite'}, $self->{'_widt'},
$self->{'_yoff'}, $self->{'_xoff'});
unless(exists($self->{'_wind'}) && defined($self->{'_wind'})){
croak "!*EROR*! Curses::Simp::Prmt could not create new window with hite:$self->{'_hite'}, widt:$self->{'_widt'}, yoff:$self->{'_yoff'}, xoff:$self->{'_xoff'}!\n";
}
$self->FlagCVis(); # set cursor visibility to new object state
$self->TestDraw();
$self->{'_dndx'} = @DISPSTAK; # add object to display order stack
push(@DISPSTAK, \$self);
if($self->{'_type'} =~ /^(drop)$/){
return($self); # $self must be given explicit focus via Focu()
}else{
$self->Focu(); # give Prompt focus (to handle GetK loops)
${$self->{'_dref'}} = $self->{'_data'} if(exists($self->{'_dref'}));
$data = $self->{'_data'};
$self->DelW();
$main->ShokScrn(2);# redraw rest
$main->FlagCVis(); # reset cursor visibility to calling object state
return($data); # return updated text data
}
}
# Focu() is a Curses::Simp method which give focus to special
# typed objects like CheckBoxes or DropDownMenus.
# Maybe later, it will change the border type / color of normal
# Simp object windows as they gain focus.
sub Focu{
my $self = shift; return() unless(exists($self->{'_type'}));
my $updt = shift || 0; my $char = -1; my $tchr;
unless($updt) {
if ($self->{'_type'} eq 'ckbx') {
$self->Draw('fclr' => [ 'C' ]) if($self->{'_flagclru'});
$char = $self->GetK(-1);
$self->Draw('fclr' => [ 'c' ]) if($self->{'_flagclru'});
if($char =~ /^SDLK_(SPACE)$/) { # checkbox toggle keys
$self->{'_stat'} ^= 1; # any other key loses focus
$updt = 1; # leaving ckbx state same
}
} elsif($self->{'_type'} =~ /^(prmt|drop)$/) { # big Prmt (drop)? focus
my $cmov; my $done = 0; # input handler
$self->FlagCVis(1);
while(!$done) {
$char = $self->GetK(-1);
$tchr = $char;
$tchr =~ s/SDLK_//;
$done = 1 if($tchr eq 'RETURN');
if($self->{'_elmo'} eq 'brws' && $self->{'_flagdrop'} &&
(($tchr eq 'F1') ||
($tchr =~ /^[bcfhu]$/ && $self->{'_kmod'}->{'KMOD_CTRL'}) ||
($tchr =~ /^(ESCAPE|SPACE|TILDE|BACKQUOTE)$/ && $self->{'_flagdown'}) ||
($tchr =~ /^(UP|DOWN|LEFT|RIGHT|j|k)$/ && !$self->{'_flagdown'}) ||
$tchr =~ /^(TAB)$/)) {
if($self->{'_flagdrop'} && !$self->{'_flagdown'}) {
$self->{'_dtxt'} = $self->{'_data'};
if($self->{'_flagclru'}) {
$self->{'_fclr'}->[$self->{'_lndx'}] = $self->{'_hifc'};
$self->{'_bclr'}->[$self->{'_lndx'}] = $self->{'_hibc'};
}
}
$self->{'_echg'} = 1;
$done = 1;
}elsif($tchr eq 'TAB'){
$tchr = ' ';
}
$tchr = uc($tchr) if($self->{'_kmod'}->{'KMOD_SHIFT'});
if($self->{'_flagdrop'} && $self->{'_flagdown'}){ # DropIsDown
if($char ne 'SDLK_TAB'){
if ($tchr =~ /^(RETURN|ESCAPE|SPACE|TILDE|BACKQUOTE)$/) {
$self->{'_flagdown'} = 0; # Close Drop down
$self->{'_dtxt'} = $self->{'_text'}->[$self->{'_lndx'}];
$self->{'_data'} = $self->{'_dtxt'};
unshift(@{$self->{'_text'}}, $self->{'_data'});
$self->{'_hite'} = 3;
if($self->{'_flagclru'}){
$self->{'_fclr'}->[$self->{'_lndx'}] = $self->{'_dtfc'};
$self->{'_bclr'}->[$self->{'_lndx'}] = $self->{'_dtbc'};
$self->{'_fclr'}->[0] = $self->{'_hifc'};
$self->{'_bclr'}->[0] = $self->{'_hibc'};
}
$char = -1 if($tchr eq 'RETURN');
$self->{'_echg'} = 1 if($self->{'_elmo'} eq 'brws');
}elsif($tchr =~ /^(UP|LEFT|k)$/){
if($self->{'_lndx'}) {
$self->{'_lndx'}--;
( run in 2.830 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )