$VERSION = '3.002'; # $Id: //depot/Tk8/TextList/Reindex.pm#2 $
use base qw(Tk::Derived);
$w->_callbase('Populate',$args);
$w->ConfigSpecs(-linestart
=> ["PASSIVE", "lineStart", "LineStart", 0],
-toindexcmd
=> ["CALLBACK", "toIndexCmd", "ToIndexCmd" , [\
&to_index
,$w]],
-fromindexcmd
=> ["CALLBACK", "fromIndexCmd","FromIndexCmd", [\
&from_index
,$w]]);
*{"${pkg}::_reindexbase"}=sub{$base};
my($w,$sub)=(shift,shift);
my $supersub=$w->_reindexbase()."::$sub";
# list of subroutines and index argument number (-1 as first element means return value)
'dump' => \
&_find_dump_index
,
'mark' => \
&_find_mark_index
,
'search' => \
&_find_search_index
,
'tag' => \
&_find_tag_index
,
foreach my $sub (keys %subs)
my $argsub=ref $args eq 'CODE'?
$args:sub{$args};
my(@iargs)=grep($_<=$#_,@
{$argsub->(@_)});
my $iret=shift @iargs if @iargs && $iargs[0]==-1;
@args[@iargs]=$w->Callback(-toindexcmd
,@args[@iargs]);
my(@ret)=$w->_callbase($sub,@args);
@ret=$w->Callback(-fromindexcmd
,@ret) if $iret;
my $offset=$w->cget(-linestart
)+1;
s/^\d+(?=\.)/$&+$offset/e;
my $offset=$w->cget(-linestart
)+1;
s/^\d+(?=\.)/$&-$offset/e
my $idx=_count_options
(@_);
my $idx=_count_options
(@_);
$idx++ if $' eq 'count
' or $' eq 'command';
return [1] if $_[0] eq 'names
';
return [2,3] if $_[0]=~/^(add|remove|nextrange|prevrange)$/;
return [-1] if $_[0] eq 'ranges
';
return [2] if $_[0] eq 'set
';
return [1] if $_[0] eq 'next' or $_[0] eq 'previous
';
Tk::Reindex - change the base index of Text-like widgets
=for category Derived Widgets
$t1=$w->ReindexedText(-linestart => 2);
$t2=$w->ReindexedROText(-linestart => 0);
Creates a new widget class based on B<Text>-like widgets that can
redefine the line number base (normally B<Text> widgets start line
numbers at 1), or possibly other manipulations on indexes.
The newly-defined widget takes all the same options as the base
widget, which defaults to B<Text>.
=head1 WIDGET-SPECIFIC OPTIONS
=item Class: B<LineStart>
=item Switch: B<-linestart>
Sets the line number of the first line in the B<Text> widget. The
default B<-toindexcmd> and B<-fromindexcmd> use this configuration
-item Name: B<toIndexCmd> B<fromIndexCmd>
-item Class: B<ToIndexCmd> B<FromIndexCmd>
-item Switch: B<-toindexcmd> B<-fromindexcmd>
These two options specify callbacks that are called with a list of
indexes and are responsible for translating them to/from indexes that
the base B<Text> widget can understand. The callback is passed the
widget followed by a list of indexes, and should return a list of
translated indexes. B<-toindexcmd> should translate from 'user
'
indexes to 'native
' B<Text>-compatible indexes, and B<-fromindexcmd>
should translate from 'native
' indexes to 'user
' indexes.
The default callbacks simply add/subtract the offset given by the
B<-linestart> option for all indexes in 'line
.character
' format.
It would probably be prudent to make these functions inverses of each
To make new Reindex widgets, this function should be called via B<use>
with the name of the Text-like base class that you are extending with
"Reindex" capability. 'use base
(Tk
::Reindex Tk
::nameofbasewidget
)'
should also be specified for that widget.
I've used the word
"indexes" instead of
"indices" throughout the
All the built
-in perl code
for widget bindings
& methods will
use the
new
'user' indexes
. Which means all this
index manipulation might
might
break code that is trying to parse
/manipulate indexes
. Or even
assume that
'1.0' is the beginning
index. B
<Tk
::Text
::Contents
> comes
Andrew Allen <ada@fc.hp.com>
This code may be distributed under the same conditions as Perl.