diff options
Diffstat (limited to 'perl-install/c/stuff.xs.pl')
0 files changed, 0 insertions, 0 deletions
![]() |
index : drakx | |
Mageia Installer and base platform for many utilities | Thierry Vignaud [tv] |
summaryrefslogtreecommitdiffstats |
package interactive_newt; # $Id$
use diagnostics;
use strict;
use vars qw(@ISA);
@ISA = qw(interactive);
use interactive;
use common qw(:common :functional);
use log;
use Newt::Newt; #- !! provides Newt and not Newt::Newt
my ($width, $height) = (80, 25);
my @wait_messages;
sub new() {
Newt::Init;
Newt::Cls;
Newt::SetSuspendCallback;
($width, $height) = Newt::GetScreenSize;
open STDERR,">/dev/null" if $::isStandalone;
bless {}, $_[0];
}
sub enter_console { Newt::Suspend }
sub leave_console { Newt::Resume }
sub suspend { Newt::Suspend }
sub resume { Newt::Resume }
sub end() { Newt::Finished }
sub exit() { end; exit($_[1]) }
END { end() }
sub myTextbox {
my $allow_scroll = shift;
my $width = $width - 9;
my @l = map { /(.{1,$width})/g } map { split "\n" } @_;
my $h = min($height - 13, int @l);
my $flag = 1 << 6;
if ($h < @l) {
if ($allow_scroll) {
$flag |= 1 << 2; #- NEWT_FLAG_SCROLL
} else {
# remove the text, no other way!
@l = @l[0 .. $h-1];
}
}
my $mess = Newt::Component::Textbox(1, 0, my $w = max(map { length } @l) + 1, $h, $flag);
$mess->TextboxSetText(join("\n", @_));
$mess, $w + 1, $h;
}
sub separator {
my $blank = Newt::Component::Form(\undef, '', 0);
$blank->FormSetWidth ($_[0]);
$blank->FormSetHeight($_[1]);
$blank;
}
sub checkval { $_[0] && $_[0] ne ' ' ? '*' : ' ' }
sub ask_from_entries_refW {
my ($o, $common, $l, $l2) = @_;
my $ignore; #-to handle recursivity
my $old_focus = -2;
#-the widgets
my (@widgets, $total_size);
my $set_all = sub {
$ignore = 1;
$_->{set}->(${$_->{e}{val}}) foreach @widgets;
# $_->{w}->set_sensitive(!$_->{e}{disabled}()) foreach @widgets;
$ignore = 0;
};
my $get_all = sub {
${$_->{e}{val}} = $_->{get}->() foreach @widgets;
};
my $create_widget = sub {
my ($e, $ind) = @_;
$e->{type} = 'list' if $e->{type} =~ /(icon|tree)list/;
#- combo doesn't exist, fallback to a sensible default
$e->{type} = $e->{not_edit} ? 'list' : 'entry' if $e->{type} eq 'combo';
my $changed = sub {
return if $ignore;
return $old_focus++ if $old_focus == -2; #- handle special first case
$get_all->();
#- TODO: this is very rough :(
$common->{callbacks}{$old_focus == $ind ? 'changed' : 'focus_out'}->($ind);
$set_all->();
$old_focus = $ind;
};
my ($w, $real_w, $set, $get, $expand, $size);
if ($e->{type} eq 'bool') {
$w = Newt::Component::Checkbox(-1, -1, $e->{text} || '', checkval(${$e->{val}}), " *");
$set = sub { $w->CheckboxSetValue(checkval($_[0])) };
$get = sub { $w->CheckboxGetValue == ord '*' };
} elsif ($e->{type} eq 'button') {
$w = Newt::Component::Button(-1, -1, may_apply($e->{format}, ${$e->{val}}));
} elsif ($e->{type} =~ /list/) {
my ($h, $wi) = (@$l == 1 && $height > 30 ? 10 : 5, 20);
my $scroll = @{$e->{list}} > $h ? 1 << 2 : 0;
$size = min(int @{$e->{list}}, $h);
$w = Newt::Component::Listbox(-1, -1, $h, $scroll); #- NEWT_FLAG_SCROLL
foreach (@{$e->{list}}) {
my $t = may_apply($e->{format}, $_);
$w->ListboxAddEntry($t, $_);
$wi = max($wi, length $t);
}
$w->ListboxSetWidth(min($wi + 3, $width - 7)); # 3 added for the scrollbar (?)
$get = sub { $w->ListboxGetCurrent };