view release on metacpan or search on metacpan
lib/Curses/UI/Grid.pm view on Meta::CPAN
By default, the following mappings are used for basebindings:
KEY ROUTINE
------------------ ----------
CUI_TAB next_cell
KEY_ENTER() next_cell
KEY_BTAB() prev-cell
KEY_UP() prev_row
KEY_DOWN() next_row
KEY_RIGHT() cursor_right
KEY_LEFT() cursor_left
KEY_HOME() cursor_home
KEY_END() cursor_end
KEY_PPAGE() grid_pageup
KEY_NPAGE() grid_pagedown
=cut
my %basebindings = (
CUI_TAB() => 'next-cell',
KEY_ENTER() => 'next-cell',
KEY_BTAB() => 'prev-cell',
KEY_UP() => 'prev-row',
KEY_DOWN() => 'next-row',
KEY_RIGHT() => 'cursor-right',
KEY_LEFT() => 'cursor-left',
KEY_HOME() => 'cursor-home',
KEY_END() => 'cursor-end',
KEY_PPAGE() => 'grid-pageup',
KEY_NPAGE() => 'grid-pagedown',
);
=item * B<-editindings> < HASHREF >
By default, the following mappings are used for basebindings:
KEY ROUTINE
lib/Curses/UI/Grid.pm view on Meta::CPAN
next_row make next row active
prev_row make prev row active
next_cell make next cell active
prev_cell make prev cell active
first_cell make first row active
last_cell make last row active
cursor_home move cursor into home pos in focused cell
cursor_end move cursor into end pos in focused cell
cursor_righ move cursor right in focused cell
cursor_left move cursor left in focused cell
add_string add string to focused cell
delete_row delete active row from grid, shift rows upstairs
insert_row insert row in current position
delete_character delete_character from focused cell
backspace delete_character from focused cell
=cut
my %routines = (
'loose-focus' => \&loose_focus,
'cursor-right' => \&cursor_right,
'cursor-left' => \&cursor_left,
'add-string' => \&add_string,
'grid-pageup' => \&grid_pageup,
'grid-pagedown' => \&grid_pagedown,
'cursor-home' => \&cursor_to_home,
'cursor-end' => \&cursor_to_end,
'next-cell' => \&next_cell,
'prev-cell' => \&prev_cell,
'next-row' => \&next_row,
'prev-row' => \&prev_row,
'insert-row' => \&insert_row,
'delete-row' => \&delete_row,
'delete-character' => \&delete_character,
'backspace' => \&backspace,
'mouse-button1' => \&mouse_button1,
);
lib/Curses/UI/Grid.pm view on Meta::CPAN
# Parent info
-parent => undef, # the parent object
# Position and size
-x => 0, # horizontal position (rel. to -window)
-y => 0, # vertical position (rel. to -window)
-width => undef, # horizontal editsize, undef = stretch
-height => undef, # vertical editsize, undef = stretch
# Initial state
-xpos => 0, # cursor position
-ypos => 0, # cursor position
# General options
-border => undef, # use border?
-frozen_with => 0,
-x_offsetbar => 0, # show vertical scrollbar
-hscrollbar => 0, # show horizontal scrollbar
-x_offset => 0, # vertical offset
-hscroll => 0, # horizontal offset
-editable => 1, # 0 - only used as viewer
-focus => 1,
lib/Curses/UI/Grid.pm view on Meta::CPAN
Initialises Grid object
=cut
sub initialise {
my ($this, %args) = @_;
$this->{-page_size} = $this->canvasheight - 2;
$this->add_row('header', %args, -type => 'head');
$this->create_default_cells; # if column is not FALSE add empty cells to grid
$this->create_default_rows; # if rows is not FALSE add empty rows to grid
$this->{-xpos} = 0; # X position for cursor in the document
$this->{-ypos} = 0; # Y position for cursor in the document
$this->layout_content;
$this->editable($args{-editable});
return $this;
}
=item id2cell
Return cell object, taks cell id.
lib/Curses/UI/Grid.pm view on Meta::CPAN
undef $new_obj;
undef $new_id;
OBJECT: for(;;) {
$idx += $direction;
if($idx > @{$this->{$collection}} - 1){
if($type eq 'row') {
# if curent position is less than page size and grid is editable
# and cursor down then add new row
return $this->insert_row(-1)
if ($idx <= $this->{-page_size} && $this->{-editable});
$onnextpage = 1; #set trigger flag to next_page
}
$idx = 0;
}
if($idx < 0) {
$idx = @{$this->{$collection}}-1 ;
$onprevpage = 1
lib/Curses/UI/Grid.pm view on Meta::CPAN
=cut
sub draw {
my ($this, $no_doupdate) = @_;
$no_doupdate ||= 0;
$this->SUPER::draw(1) or return $this
unless $this->test_more;
$this->draw_grid(1);
$this->{-nocursor} = $this->rows_count ? 0 : 1;
doupdate()
if ! $no_doupdate && ! $this->test_more;
$this;
}
=item draw_grid
Draws grid.
lib/Curses/UI/Grid.pm view on Meta::CPAN
$this->get_foused_cell;
}
=back
=head3 Cells methods.
=over
=item cursor_left
Calls cursor left on focsed cell.
Return focued cells.
=cut
sub cursor_left {
my $this = shift;
my $cell = $this->get_foused_cell;
$cell->cursor_left;
$cell;
}
=item cursor_right
Calls cursor right on focsed cell.
Return focued cells.
=cut
sub cursor_right {
my $this = shift;
my $cell = $this->get_foused_cell;
$cell->cursor_right;
$cell;
}
=item cursor_to_home
Calls cursor home on focsed cell.
Return focued cells.
=cut
sub cursor_to_home {
my $this = shift;
my $cell = $this->get_foused_cell;
$cell->cursor_to_home;
$cell;
}
=item cursor_to_end
Calls cursor end on focsed cell.
Return focued cells.
=cut
sub cursor_to_end {
my $this = shift;
my $cell = $this->get_foused_cell;
$cell->cursor_to_end;
$cell;
}
=item delete_character
Calls delete character on focsed cell.
Return focued cells.
=cut
lib/Curses/UI/Grid/Cell.pm view on Meta::CPAN
my %args = (
# Parent info
-parent => undef # the parent object
,-row => undef # row object
# Position and size
,-x => 0 # horizontal position (rel. to -window)
,-current_width => undef
,-width => undef # default width 10
,-align => 'L' # align L - left, R - right
# Initial state
,-xpos => 0 # cursor position
# General options
,-maxlength => 0 # the maximum length. 0 = infinite
,-overwrite => 1 # immdiately overwrite cell unless function char
,-overwritetext => 1 # contol overwrite and function char (internally set)
# Grid model
,-text => '' # text
,-fldname => '' # field name for data bididngs
,-frozen => 0 # field name for data bididngs
lib/Curses/UI/Grid/Cell.pm view on Meta::CPAN
,-bg_ => undef # user defined background color
,-fg_ => undef # user defined font color
);
# Create the Widget.
my $this = {%args};
bless $this;
$this->{-xoffset} = 0; #
$this->{-xpos} = 0; # X position for cursor in the document
$this->parent->layout_content;
$this;
}
# set layout
sub set_position {
my ($this, $x, $current_width) = @_;
$this->x($x);
$this->current_width($current_width);
if($current_width > 0) {
lib/Curses/UI/Grid/Cell.pm view on Meta::CPAN
my $this = shift;
my $no_doupdate = shift || 0;
# Return immediately if this object is hidden.
return $this if $this->hidden;
return $this if $Curses::UI::screen_too_small;
my $grid =$this->parent;
my $row=$this->row(1);
if( $#{$grid->{_rows}} > 1 ) {
$this->{-nocursor}=0;
} else {
$this->{-nocursor}=1;
}
$row->canvasscr->attron(A_BOLD) if($row->{-focus});
$this->draw_cell(1,$row);
$row->canvasscr->attroff(A_BOLD) if($row->{-focus});
doupdate() if ! $no_doupdate && ! $grid->test_more;
$row->canvasscr->move($row->y,$this->xabs_pos);
$row->canvasscr->noutrefresh;
lib/Curses/UI/Grid/Cell.pm view on Meta::CPAN
$this->{-label}=$text;
} else {
$row->{-cells}{$id}=$text;
}
}
$result = $type eq 'head' ? $this->{-label} : exists $row->{-cells}{$id} ? $row->{-cells}{$id} :'' if($type) ;
return $result;
}
sub cursor_right($) {
my $this = shift;
$this->overwriteoff;
$this->xoffset($this->xoffset-1) if($this->xpos() == ($this->current_width -1) );
$this->xpos($this->xpos+1);
$this->draw(1);
return $this; return $this;
}
sub cursor_left($) {
my $this = shift;
$this->overwriteoff;
$this->xoffset($this->xoffset+1) unless($this->xpos($this->xpos));
$this->xpos($this->xpos-1);
$this->draw(1);
return $this;
}
sub cursor_to_home($) {
my $this = shift;
$this->overwriteoff;
my $text = $this->text;
my $current_width = $this->current_width;
my $align = $this->align;
$this->xoffset($align eq 'L'
? $current_width
: (length($text) - $current_width > 0
? length($text) - $current_width
lib/Curses/UI/Grid/Cell.pm view on Meta::CPAN
);
$this->xpos($align eq 'L'
? 0
: $current_width - length($text)
);
$this->draw(1);
}
sub cursor_to_end($) {
my $this = shift;
$this->overwriteoff;
my $text_lenght = length $this->text;
my $current_width = $this->current_width;
my $align = $this->align;
$current_width = $current_width > $text_lenght && $align eq 'L'
? $text_lenght + 1
: $current_width;
$this->xoffset(
$align eq 'R'
lib/Curses/UI/Grid/Cell.pm view on Meta::CPAN
sub backspace($) {
my $this = shift;
my $ch = shift;
return if $this->readonly;
my $grid =$this->parent;
$grid->run_event('-oncellkeypress', $this, $ch)
or return;
$this->overwriteoff;
my ($align,$xo)=($this->align,$this->xoffset);
$this->cursor_left;
$this->delete_character();
$this->cursor_right if($align eq 'R' );
}
sub add_string($$;) {
my $this = shift;
my $ch = shift;
return if $this->readonly;
my $grid = $this->parent;
my $ret= $grid->run_event('-oncellkeypress', $this, $ch)
or return;
lib/Curses/UI/Grid/Cell.pm view on Meta::CPAN
}
$this->text('') if( $this->overwritetext );
my ($xo,$pos,$len,$align)= ($this->xoffset ,$this->text_xpos, length($this->text),$this->align);
my $text=$this->text;
substr($text, abs($pos) , 0) = $ch if($pos <= $len );
$this->text($text);
$this->cursor_right if($align eq 'L');
$this->draw();
$grid->run_event('-onaftercellkeypress', $this, $ch);
}
# x of cell
sub x($;) {
my $this=shift;
my $x=shift;
lib/Curses/UI/Grid/Cell.pm view on Meta::CPAN
# absolute x position to row
sub xabs_pos($;) {
my $this=shift;
my $result="";
my $xpos=( $this->xpos > ($this->current_width-1) ? $this->current_width-1 : $this->xpos );
$xpos =0 if($xpos < 0);
return $this->{-x} + $xpos;
}
# cursor relative x pos
sub xpos($;) {
my $this=shift;
my $x=shift;
if(defined $x){
$x = 0 if($x < 0);
$x= $this->width-1 if($x > $this->width-1 );
$this->{-xpos}=$x;
}
return $this->{-xpos};
}
# cursor position in text
sub text_xpos($;) {
my $this=shift;
my ($w,$x,$xo,$align,$l)=($this->current_width-1,$this->xpos,$this->xoffset,$this->align,length($this->text));
return $align eq 'R' ? $l-($w-$x+abs($xo)) : $x-$xo;
}
# offset to x pos
sub xoffset($;) {
my $this=shift;
lib/Curses/UI/Grid/Cell.pm view on Meta::CPAN
This option will make apropriate align for the data cell.
ALIGN could be either R or L.
R - rigth align;
L - left align;
=item * B<-overwrite> < BOOLEAN >
If BOOLEAN is true, and when add_string method is called first time
after the cell becomes focused the old value will be cleared
unless the function key will be pressed earlier. (cursor_left,cursor_to_end,etc.)
=back
=head1 METHODS
=over 4
=item * B<new> ( OPTIONS )
lib/Curses/UI/Grid/Cell.pm view on Meta::CPAN
=item * B<add_string>
=item * B<align>
=item * B<backspace>
=item * B<current_width>
=item * B<cursor_left>
=item * B<cursor_right>
=item * B<cursor_to_end>
=item * B<cursor_to_home>
=item * B<delete_character>
=item * B<event_onblur>
=item * B<event_onfocus>
=item * B<focus>
=item * B<frozen>