NAME
TUI::Outline::OutlineViewer - abstract base for scrollable outline viewers
HIERARCHY
TObject
TView
TScroller
TOutlineViewer
SYNOPSIS
package MyOutlineViewer {
use TUI::toolkit;
use TUI::Outline;
use TUI::Views;
extends TOutlineViewer;
# implement adjust, getChild, getNumChildren, getRoot, getText,
# hasChildren and isExpanded
}
DESCRIPTION
TOutlineViewer is the abstract base class for views that display a hierarchy of TNode objects. It derives from TScroller, so the outline scrolls horizontally and vertically through its scroll bars.
The class does not know how the tree is stored. A subclass must implement the abstract methods adjust, getChild, getNumChildren, getRoot, getText, hasChildren and isExpanded. The viewer then draws the graph (level lines and expand/retract markers) for each visible node, handles keyboard and mouse navigation, and expands or retracts nodes.
The explicit disposal of nodes is not needed. Memory of the node tree is managed by Perl reference counting. Streaming is supported through Storable serialization.
ATTRIBUTES
foc
The display position of the focused node, starting at 0 (Int).
CONSTRUCTOR
new
my $viewer = MyOutlineViewer->new(
bounds => $bounds,
hScrollBar => $hScrollBar,
vScrollBar => $vScrollBar
);
Creates a new outline viewer. The viewer grows with its owner in both directions.
- bounds
-
Bounding rectangle of the outline viewer (TRect).
- hScrollBar
-
Optional horizontal scroll bar (TScrollBar or
undef). - vScrollBar
-
Optional vertical scroll bar (TScrollBar or
undef).
new_TOutlineViewer
my $viewer = new_TOutlineViewer($bounds, $hScrollBar | undef,
$vScrollBar | undef);
Factory constructor that mirrors the positional Turbo Vision constructor.
METHODS
adjust
$viewer->adjust($node, $expand);
Expands ($expand true) or retracts ($expand false) the node. Abstract: a subclass must implement this method.
createGraph
my $graph = $viewer->createGraph($level, $lines, $flags, $levWidth,
$endWidth, $chars);
Builds the graph string for one node. $chars holds the eight graph characters in CP437 order (level filler, level mark, end first, end first last child, end filler, end child, retracted, expanded).
draw
$viewer->draw();
Draws the visible part of the outline.
expandAll
$viewer->expandAll($node);
Expands the node and all its descendants.
firstThat
my $node = $viewer->firstThat(\&test);
Walks the visible tree in display order and returns the first node for which test returns true. test is called as
test($viewer, $node, $level, $position, $lines, $flags)
focused
$viewer->focused($i);
Called when the node at position $i receives focus. Sets "foc".
forEach
$viewer->forEach(\&action);
Calls action for every visible node in display order. The arguments are the same as for firstThat.
getChild
my $child = $viewer->getChild($node, $i);
Returns the child with index $i of the node. Abstract: a subclass must implement this method.
getGraph
my $graph = $viewer->getGraph($level, $lines, $flags);
Returns the graph characters drawn before the text of a node. Uses createGraph with the default widths.
getNode
my $node = $viewer->getNode($i);
Returns the node displayed at position $i, or undef.
getNumChildren
my $count = $viewer->getNumChildren($node);
Returns the number of children of the node. Abstract: a subclass must implement this method.
getPalette
my $palette = $viewer->getPalette();
Returns the outline palette.
getRoot
my $root = $viewer->getRoot();
Returns the root node of the outline, or undef if the outline is empty. Abstract: a subclass must implement this method.
getText
my $text = $viewer->getText($node);
Returns the text displayed for the node. Abstract: a subclass must implement this method.
handleEvent
$viewer->handleEvent($event);
Handles keyboard and mouse events. Keyboard keys - and + retract or expand the focused node, and * expands it with all its children.
hasChildren
my $bool = $viewer->hasChildren($node);
Returns true if the node has children. Abstract: a subclass must implement this method.
isExpanded
my $bool = $viewer->isExpanded($node);
Returns true if the node is expanded. Abstract: a subclass must implement this method.
isSelected
my $bool = $viewer->isSelected($i);
Returns true if the node at position $i is selected. By default only the focused node is selected.
selected
$viewer->selected($i);
Called when the node at position $i is selected by the user. Does nothing by default.
setState
$viewer->setState($aState, $enable);
Redraws the outline when the focus state changes.
update
$viewer->update();
Recalculates the limits of the viewer. Call it after the data of the outline has changed.
SEE ALSO
AUTHORS
Borland International (original Turbo Vision design)
J. Schneider <brickpool@cpan.org> (Perl implementation and maintenance)
COPYRIGHT AND LICENSE
Copyright (c) 1990-1994, 1997 by Borland International
Copyright (c) 2026 the "AUTHORS" as listed above.
This software is licensed under the MIT license (see the LICENSE file, which is part of the distribution).