
Tk::LineNumberText - Line numbers for your favorite Text-derived widget

$linenumtext = $parent->LineNumberText(Text-Derived Widget,?options?);

use Tk;
use Tk::LineNumberText;
my $mw=tkinit;
$mw->LineNumberText('Text',
-wrap=>'word',
-font=>['Courier',12],
-linenumfont=>['Courier',12],
-curlinehighlight=>'both',
-bg=>'white')->pack(-fill=>'both', -expand=>1);
MainLoop;

This version is NOT backwards compatible. Some options have been deleted and others have changed. This was to be expected anyways - as v0.1 was documented as beta. For various reasons - I have jumped straight to a v0.5. Whenever the word "Text" is used within this documentation - it is assumed that it refers to the "Text-derived widget" you pass at instantiation.

LineNumberText is a composite widget which provides line numbers for your favorite widget derived from Tk::Text or, of course, even for Tk::Text itself.

LineNumberText ISA Tk::Frame consisting of a Canvas to plot the line numbers and a Scrolled Text widget. This code has been tested using Tk::Text, Tk::CodeText and Tk::TextUndo.
The line numbers should adjust automatically as text is edited or scrolled (either programmatically or interactively). If you find cases where this doesn't happen - please contact the author with the particulars.
LineNumberText does not sub-class any of the Text methods. Instead, AUTOLOAD is used to get at the Text methods and then the line number update is done. The previous version used to actually override all these methods, which caused problems for some users. This is no longer the case.

All options should be available as per your Text widget documentation. Additionally the following options are offered..
Boolean to allow <1> or disallow <0> user-interactive bookmarks.
Fill color for bookmark.
Outline color for bookmark.
Shape of bookmark must be one of: rectangle, circle or triangle
Bitmap stipple for bookmarks. eg/ gray50
Background color of the current line. The current line is defined as the line containing the insert cursor.
Foreground color of the current line. The current line is defined as the line containing the insert cursor.
Must be ONE of the following:
Bitmap stipple to use on the current line highlight background. Default is no stipple (i.e. undef).
Active color of the line numbers. Done by adjusting the -activefill option of a canvas text item.
Anchor position for the line numbers with respect to the canvas. Must be one of left, center or right.
Background color of the line numbers. This is the background color of the canvas itself.
Foreground color of the line numbers. Done by adjusting the -fill option of a canvas text item.
Font type of the line numbers. Done by adjusting the -font option of a canvas text item.
Specifies which side of the text widget to place the line numbers. Must be either left or right. Default is left.

As stated above, all methods should find their way to the proper module by the AUTOLOAD routine. The following widget-specific methods also exist.
Programmatically add bookmarks to each line number specified in the list passed. Note: Array references are not yet supported.
Programmatically delete bookmarks at each line number specified in the list passed. Note: Array references are not yet supported.
Hide the linenumber widget. (i.e. gridForget)
Show the linenumber widget. (i.e. grid)
Toggle the visibility of the linenumber widget.
Returns a boolean value to indicate the visibility of the linenumber widget.
Force line numbers to update.
NOTE: This method should not have to be called manually. This widget is designed to do the updates for you. However - I have provided this to allow the force the update just in case there are situations when it fails to do so. But I hope you would e-mail me if you come across any bugs.

Set insert mark of text widget to the line number clicked.
Toggle bookmark.
Navigation menu.


The following widgets are advertised:
The text or text-derived widget.
The text or text-derived widget. (Same as scrolled above)
The frame containing the scrollbars and text widget (As per the Tk::Scrolled method).
The scrollbar widget using for vertical scrolling.
The Scrollbar widget using for horizontal scrolling.
The frame in the corner between the vertical and horizontal scrollbars.
The canvas widget used for the line numbers.

There will always be a line number on the first display line -- even if the text could actually be wrapped from a line which is off screen. I did this to ensure that at least one line number is shown at all times.



Tk::Frame, Tk::Text, Tk::Scrolled, Tk::Canvas.

Thanks go to the following people for their kind advice, suggestions and code samples.
Dean Arnold, Eric Hodges, Darin McBride, Brian McCauley, Brian McGonigle, Ala Qumsieh, Steve Schulze.

Jack Dunnigan <goodcall1@hotmail.com>
Copyright (C) 2004. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Inspired by ctext.tcl written by George Peter Staplin.