CursesWidgets
view release on metacpan or search on metacpan
Widgets/ComboBox.pm view on Meta::CPAN
# hasn't been defined
$conf{LISTCOLUMNS} = $conf{COLUMNS} unless exists $conf{LISTLENGTH};
# Make sure no errors are returned by the parent method
$err = 1 unless $self->SUPER::_conf(%conf);
# Get updated conf hash
%conf = ();
%conf = %{$self->{CONF}};
# Create a list box object for the popup if no errors were encountered
$self->{LISTBOX} = Curses::Widgets::ListBox->new({
X => 0,
Y => 0,
LISTITEMS => $conf{LISTITEMS},
INPUTFUNC => $conf{INPUTFUNC},
BORDERCOL => $conf{BORDERCOL},
FOREGROUND => $conf{FOREGROUND},
BACKGROUND => $conf{BACKGROUND},
LINES => $conf{LISTLINES},
COLUMNS => $conf{LISTCOLUMNS},
Widgets/ComboBox.pm view on Meta::CPAN
my ($by, $bx);
# Get and store the window's beginning y & x
$mwh->getbegyx($by, $bx);
$self->{BEGYX} = [$by, $bx];
# Call the parent draw
return $self->SUPER::draw($mwh, $active);
}
=head2 popup
$combo->popup;
This method causes the drop down list to be displayed. Since, theoretically,
this list should never be seen unless it's being actively used, we will always
assume that we need to draw a cursor on the list as well.
=cut
sub popup {
my $self = shift;
my $conf = $self->{CONF};
my ($x, $y, $border) = @$conf{qw(X Y BORDER)};
my ($by, $bx) = @{$self->{BEGYX}};
my $lb = $self->{LISTBOX};
my ($pwh, $items, $cp, $in, $key);
# Calculate the border column/lines
$border *= 2;
if ($border) {
$y--;
} else {
$y++;
}
# Create the popup window
unless ($pwh = newwin($$conf{LISTLINES} + $border, $$conf{LISTCOLUMNS} +
$border, $y + $border + $by, $x + $border + $bx)) {
carp ref($self), ": Popup creation failed, possible geometry problems";
return;
}
$pwh->keypad(1);
# Render the list box
$key = $lb->execute($pwh);
Widgets/ComboBox.pm view on Meta::CPAN
# Internal use only.
my $self = shift;
my $in = shift;
my $conf = $self->{CONF};
# Handle only special keys that will pull down the list
if ($in eq "\n") {
} elsif ($in eq KEY_DOWN) {
$self->popup;
# Hand everything else to the text widget
} else {
$self->SUPER::input_key($in);
}
}
1;
=head1 HISTORY
Widgets/Menu.pm view on Meta::CPAN
$conf{CURSORPOS} = $conf{MENUS}{MENUORDER}[0] unless
defined $conf{CURSORPOS};
# Make sure no errors are returned by the parent method
$err = 1 unless $self->SUPER::_conf(%conf);
# Get the updated conf hash
%conf = ();
%conf = %{$self->{CONF}};
# Create a listbox as our popup menu
$self->{LISTBOX} = Curses::Widgets::ListBox->new({
X => 0,
Y => 0,
LISTITEMS => [],
FOREGROUND => $conf{FOREGROUND},
BACKGROUND => $conf{BACKGROUND},
LINES => 3,
COLUMNS => 10,
FOCUSSWITCH => "\n\e",
INPUTFUNC => $conf{INPUTFUNC},
Widgets/Menu.pm view on Meta::CPAN
$label = join(' ', @{$$menu{MENUORDER}});
if ($label =~ /^(.*\b)\Q$pos\E\b/) {
$x = length($1);
$dwh->chgat(0, $x, length($pos), A_STANDOUT, select_colour(
@$conf{qw(FOREGROUND BACKGROUND)}), 0);
}
$self->_restore($dwh);
}
=head2 popup
$menu->popup;
This method causes the menu to be displayed. Since, theoretically, the menu
should never be seen unless it's being actively used, we will always assume
that we need to draw a cursor on the list as well.
=cut
sub popup {
my $self = shift;
my $conf = $self->{CONF};
my ($x, $y, $border) = (@$conf{qw(X Y)}, 1);
my $lb = $self->{LISTBOX};
my ($pwh, $items, $cp, $in, $rv, $l);
# Calculate the border column/lines
$border *= 2;
# Create the popup window
unless ($pwh = newwin($lb->getField('LINES') + $border,
$lb->getField('COLUMNS') + $border, $y, $x)) {
carp ref($self), ": Popup creation failed, possible geometry problems";
return;
}
$pwh->keypad(1);
# Render the list box
$rv = $lb->execute($pwh);
Widgets/Menu.pm view on Meta::CPAN
if ($in eq KEY_LEFT) {
--$i;
$i = $#{$$menus{MENUORDER}} if $i < 0;
} elsif ($in eq KEY_RIGHT) {
++$i;
$i = 0 if $i > $#{$$menus{MENUORDER}};
# Display the Menu
} elsif ($in eq KEY_DOWN || $in eq "\n") {
# Calculate and set popup geometry
$x = 0;
for (0..$i) {
$x += (length($$menus{MENUORDER}[$i]) + 2) if $_ != $i;
}
$x += 1 if $$conf{BORDER};
$x += $self->{BEGYX}->[1];
$y = $$conf{BORDER} ? 2 : 1;
$y += $self->{BEGYX}->[0];
@$conf{qw(Y X)} = ($y, $x);
$l = 0;
foreach (@{$$menus{$item}{ITEMORDER}}) {
$l = length($_) if $l < length($_) };
$lb->setField(
LISTITEMS => [ @{$$menus{$item}{ITEMORDER}} ],
LINES => scalar @{$$menus{$item}{ITEMORDER}},
COLUMNS => $l,
CURSORPOS => 0,
);
# Display the popup
$rv = $self->popup;
if (defined $rv) {
$$conf{EXIT} = 1;
# Execute the reference
{
no strict 'refs';
$sub = $$menus{$item}{$rv};
if (defined $sub) {
&$sub();
( run in 2.162 seconds using v1.01-cache-2.11-cpan-364913b4093 )