NAME
TUI::Help::HelpViewer - scrollable help topic viewer
HIERARCHY
TObject
TView
TScroller
THelpViewer
SYNOPSIS
use TUI::Objects;
use TUI::Help;
open my $source, '<', 'help.txt' or die $!;
my $helpFile = new_THelpFile( $source );
my $viewer = new_THelpViewer(
TRect->new( ax => 0, ay => 0, bx => 60, by => 18 ),
undef, # no horizontal scroll bar
undef, # no vertical scroll bar
$helpFile,
10, # help context of the first topic
);
DESCRIPTION
THelpViewer displays one help topic in a scrollable view. It is the Perl port of the Turbo Vision THelpViewer and derives from TScroller. The viewer is selectable and grows with its owner in both directions. It keeps the help file in hFile and the current topic in topic. The topic is read from the help file by its numeric context when the viewer is constructed. The topic is wrapped to the width of the viewer, the horizontal scroll limit is 78 columns, and the vertical limit is the number of lines in the topic. If the context is unknown, the viewer shows the invalid-context text provided by THelpFile.
Cross-references in the topic are highlighted. At most one cross-reference is selected at a time; selected holds its one-based index and starts at 1. The selected reference is drawn with the selected-keyword color, and the other references use the keyword color.
Commonly Used Features
Create the help file from an open, seekable handle with new_THelpFile, then create the viewer with bounds, the two scroll bar arguments (which may be undef), the help file, and the numeric context of the first topic. Insert the viewer into a window and run that window modally with execView. Keyboard users move between cross-references with Tab and Shift-Tab and follow one with Enter. Mouse users click a cross-reference to select it and double-click it to follow it. Esc posts a cmClose command. The viewer ends the modal view only when its owner is modal; otherwise it leaves the command unhandled.
ATTRIBUTES
The following attributes are read/write:
- hFile
-
The THelpFile object that supplies the topics. It is required by the constructor. The help file keeps its source handle, which remains owned by the caller.
- topic
-
The current THelpTopic. It is set by the constructor and replaced when a cross-reference is followed.
- selected
-
The one-based index of the selected cross-reference (
Int). It starts at 1 and is reset to 1 when another topic is shown.
CONSTRUCTOR
new
my $viewer = THelpViewer->new(
bounds => $bounds,
hScrollBar => $hBar | undef,
vScrollBar => $vBar | undef,
hFile => $helpFile,
context => $context,
);
Creates a viewer for the topic with the numeric context $context. All five arguments are required. The scroll bar arguments must be present as keys, but either may be undef. The arguments aHScrollBar, aVScrollBar, and aHelpFile are accepted as aliases for hScrollBar, vScrollBar, and hFile.
- bounds
-
Bounding rectangle of the viewer (TRect).
- hScrollBar
-
Horizontal scroll bar (TScrollBar) or
undef. - vScrollBar
-
Vertical scroll bar (TScrollBar) or
undef. - hFile
-
Help file (THelpFile) that supplies the topics.
- context
-
Numeric help context (
PositiveOrZeroInt) of the first topic to display.
new_THelpViewer
my $viewer = new_THelpViewer( $bounds, $hBar | undef, $vBar | undef,
$helpFile, $context );
Positional factory for the same constructor, with the arguments in the order listed above.
METHODS
The following methods override the corresponding methods of TScroller.
changeBounds
$viewer->changeBounds($bounds);
Applies the new bounds through the scroller and rewraps the current topic to the new width. The vertical scroll limit is updated to the number of lines in the rewrapped topic. The horizontal limit is unchanged.
draw
$viewer->draw();
Draws the visible part of the topic at the current scroll offset. Normal text uses palette entry 1, cross-references use palette entry 2, and the selected cross-reference uses palette entry 3.
getPalette
my $palette = $viewer->getPalette();
Returns a copy of the palette of the help viewer, which is built from the constant cHelpViewer.
handleEvent
$viewer->handleEvent($event);
Passes the event to the scroller first, then handles the following events:
Tab selects the next cross-reference and wraps from the last one to the first. Shift-Tab selects the previous one and wraps from the first one to the last.
Enter follows the selected cross-reference, which replaces
topic, resetsselectedto 1, and scrolls the view to the top.A mouse click on a cross-reference selects it. A double-click (
meDoubleClick) also follows it.Esc is consumed and posts a
cmClosecommand.A
cmClosecommand ends the modal view withcmClosewhen the owner hassfModalset. The command is consumed in that case. Otherwise it is left unhandled.
Other keys and events are not consumed.
SEE ALSO
TUI::Help, THelpFile, THelpTopic, TUI::Help::Const, TScroller
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).