From 97075e53a49f0b999a86c775b256c629a75520dd Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Thu, 30 Jan 2003 01:30:42 +0000 Subject: basic treelist handling (it leaks memory, but who cares, compared to gtk :) --- perl-install/Newt/Newt.xs | 52 ++++++++++++++++++++++++++++++++++++++++ perl-install/interactive/newt.pm | 48 ++++++++++++++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 1 deletion(-) (limited to 'perl-install') diff --git a/perl-install/Newt/Newt.xs b/perl-install/Newt/Newt.xs index 0121452db..22a6a79ae 100644 --- a/perl-install/Newt/Newt.xs +++ b/perl-install/Newt/Newt.xs @@ -218,6 +218,58 @@ CODE: OUTPUT: RETVAL + +Newt::Component +newtTree(height,want_scroll) + int height; + int want_scroll; + CODE: + RETVAL = newtCheckboxTree(-1,-1,height, (want_scroll ? NEWT_FLAG_SCROLL : 0) | NEWT_CHECKBOXTREE_HIDE_BOX); + OUTPUT: + RETVAL + +int +newtTreeAdd(co,text,data,parents) + Newt::Component co; + const char * text; + SV * data; + SV * parents; + CODE: + { + int l[10]; + int i; + AV *av = (AV*) SvRV(parents); + for (i = 0; i <= av_len(av); i++) l[i] = SvIV(*av_fetch(av, i, 0)); + l[i++] = NEWT_ARG_APPEND; + l[i] = NEWT_ARG_LAST; + RETVAL = newtCheckboxTreeAddArray(co, text, SvREFCNT_inc(data), 0, l); + } + OUTPUT: + RETVAL + +void +newtTreeSetCurrent(co, data) + Newt::Component co; + SV * data; + CODE: + newtCheckboxTreeSetCurrent(co, data); + +void +newtTreeSetWidth(co,width) + Newt::Component co; + int width; + CODE: + newtCheckboxTreeSetWidth(co, width); + +SV * +newtTreeGetCurrent(co) + Newt::Component co; +CODE: + RETVAL = SvREFCNT_inc(newtCheckboxTreeGetCurrent(co)); +OUTPUT: + RETVAL + + Newt::Component newtTextbox(left,top,width,height,want_scroll) int left; diff --git a/perl-install/interactive/newt.pm b/perl-install/interactive/newt.pm index 6807b0e38..68809f1e3 100644 --- a/perl-install/interactive/newt.pm +++ b/perl-install/interactive/newt.pm @@ -110,7 +110,7 @@ sub ask_fromW_real { my $create_widget = sub { my ($e, $ind) = @_; - $e->{type} = 'list' if $e->{type} =~ /(icon|tree)list/; + $e->{type} = 'list' if $e->{type} =~ /iconlist/; #- combo doesn't exist, fallback to a sensible default $e->{type} = $e->{not_edit} ? 'list' : 'entry' if $e->{type} eq 'combo'; @@ -134,6 +134,52 @@ sub ask_fromW_real { $get = sub { $w->CheckboxGetValue == ord '*' }; } elsif ($e->{type} eq 'button') { $w = Newt::Component::Button(simplify_string(may_apply($e->{format}, ${$e->{val}}))); + } elsif ($e->{type} eq 'treelist') { + $e->{formatted_list} = [ map { may_apply($e->{format}, $_) } @{$e->{list}} ]; + my $data_tree = interactive::helper_separator_tree_to_tree($e->{separator}, $e->{formatted_list}, $e->{list}); + + my $count; $count = sub { + my ($t) = @_; + 1 + ($t->{_leaves_} ? int @{$t->{_leaves_}} : 0) + + ($t->{_order_} ? sum(map { $count->($t->{$_}) } @{$t->{_order_}}) : 0); + }; + $size = $count->($data_tree); + + my ($h) = @$l == 1 && $height > 30 ? 10 : 5; + my $scroll = $size > $h; + $has_scroll = 1; + $size = min($size, $h); + + $w = Newt::Component::Tree($size, $scroll); + + my @lz; + my $wi; + my $add_item = sub { + my ($text, $data, $parents) = @_; + $text = simplify_string($text, $width - 10); + $wi = max($wi, length($text) + 3 * @$parents + 4); + $w->TreeAdd($text, $data, $parents); + }; + + my $populate; $populate = sub { + my ($node, $parents) = @_; + if (my $l = $node->{_order_}) { + each_index { + $add_item->($_, '', $parents); + $populate->($node->{$_}, [ @$parents, $::i ]); + } @$l; + } + if (my $l = $node->{_leaves_}) { + $add_item->($_->[0], $_->[1], $parents) foreach @$l; + } + }; + $populate->($data_tree, []); + + $w->TreeSetWidth($wi + 1); + $get = sub { $w->TreeGetCurrent }; + $set = sub { + #$w->TreeSetCurrent($_[0]); + }; } elsif ($e->{type} =~ /list/) { my ($h) = @$l == 1 && $height > 30 ? 10 : 5; my $scroll = @{$e->{list}} > $h ? 1 << 2 : 0; -- cgit v1.2.1