NAME
Prima::Notebooks - multipage widgets
DESCRIPTION
The module contains several widgets useful for organizing multipage containers, notebooks. Prima::Notebook
provides the basic functionality of such a widget container. Prima::TabSet
is a page selector control, and Prima::TabbedNotebook
combines these two into a ready-to-use multipage control with interactive navigation.
SYNOPSIS
use Prima qw(Notebooks Buttons Application);
my $nb = Prima::TabbedNotebook-> new(
tabs => [ 'First page', 'Second page', 'Second page' ],
size => [ 300, 200 ],
);
$nb-> insert_to_page( 1, 'Prima::Button' );
$nb-> insert_to_page( 2,
[ 'Prima::Button', bottom => 10 ],
[ 'Prima::Button', bottom => 150 ],
);
$nb-> Notebook-> backColor( cl::Green );
run Prima;
Prima::Notebook
Properties
Provides basic widget container functionality. Acts as a merely grouping widget, hiding and showing the children widgets when the pageIndex
property is changed.
- defaultInsertPage INTEGER
-
Selects the page where widgets attached the by
insert
call are assigned. If set toundef
, the default page is the current page.Default value:
undef
. - pageCount INTEGER
-
Selects the number of pages. If the number of pages is reduced, the widgets that belong to the rejected pages are removed from the notebook's storage.
- pageIndex INTEGER
-
Selects the index of the current page. Valid values are from 0 to
pageCount - 1
.
Methods
- attach_to_page INDEX, @WIDGETS
-
Attaches WIDGETS to INDEXth page. The widgets not necessarily must be children of the notebook widget. If the INDEXth page is not current, the widgets get hidden and disabled; otherwise their state is not changed.
- contains_widget WIDGET
-
Searches for WIDGET in the attached widgets list. If found, returns two integers: location page index and widget list index. Otherwise returns an empty list.
- delete_page [ INDEX = -1, REMOVE_CHILDREN = 1 ]
-
Deletes the INDEXth page, and detaches the widgets associated with it. If REMOVE_CHILDREN is 1, the detached widgets are destroyed.
- delete_widget WIDGET
-
Detaches WIDGET from the widget list and destroys the widget.
- detach_from_page WIDGET
-
Detaches WIDGET from the widget list.
- insert CLASS, %PROFILE [[ CLASS, %PROFILE], ... ]
-
Creates one or more widgets with the
owner
property set to the caller widget, and returns the list of references to the newly created objects.See "insert" in Prima::Widget for details.
- insert_page [ INDEX = -1 ]
-
Inserts a new empty page at INDEX. The valid range is from 0 to
pageCount
; setting INDEX equal topageCount
is equivalent to appending a page to the end of the page list. - insert_to_page INDEX, CLASS, %PROFILE, [[ CLASS, %PROFILE], ... ]
-
Inserts one or more widgets to the INDEXth page. The semantics of setting CLASS and PROFILE, as well as the return values are fully equivalent to the
insert
method.See "insert" in Prima::Widget for details.
- insert_transparent CLASS, %PROFILE, [[ CLASS, %PROFILE], ... ]
-
Inserts one or more widgets to the notebook widget, but does not add widgets to the widget list, so the widgets are not flipped together with pages. Useful for setting omnipresent ( or transparent ) widgets, visible on all pages.
The semantics of setting CLASS and PROFILE, as well as the return values are fully equivalent to the
insert
method.See "insert" in Prima::Widget for details.
- move_widget WIDGET, INDEX
-
Moves WIDGET to the INDEXth page.
- widget_get WIDGET, PROPERTY
-
Returns PROPERTY value of WIDGET. If PROPERTY is affected by the page flipping mechanism, the internal flag value is returned instead.
- widget_set WIDGET, %PROFILE
-
Calls
set
on WIDGET with PROFILE and updates the internalvisible
,enabled
,current
, andgeometry
properties if these are present in PROFILE. - widgets_from_page INDEX
-
Returns list of widgets associated with the INDEXth page.
Events
- Change OLD_PAGE_INDEX, NEW_PAGE_INDEX
-
Called when the
pageIndex
value is changed from OLD_PAGE_INDEX to NEW_PAGE_INDEX. Current implementation invokes this notification while the notebook widget is in the locked state so no redraw requests are honored during the execution of the notification.
Bugs
Since the notebook operates directly on children widgets' ::visible
and ::enable
properties, there is a problem when a widget associated with a non-active page must be explicitly hidden or disabled. As a result, such a widget would become visible and enabled anyway. This happens because Prima API does not cache property requests. For example, after the execution of the following code
$notebook-> pageIndex(1);
my $widget = $notebook-> insert_to_page( 0, ... );
$widget-> visible(0);
$notebook-> pageIndex(0);
$widget
will still become visible. As a workaround, the widget_set
method can be suggested, to be called together with the explicit state calls. Changing the
$widget-> visible(0);
code to
$notebook-> widget_set( $widget, visible => 0);
solves the problem, but introduces an inconsistency in API.
Prima::TabSet
The Prima::TabSet
class implements the functionality of an interactive page switcher. A widget is presented as a set of horizontal bookmark-styled tabs with text identifiers.
Properties
- colored BOOLEAN
-
A boolean property, selects whether each tab uses unique color ( OS/2 Warp 4 style ), or all tabs are drawn with
backColor
.Default value: 1
- colorset ARRAY
-
Allows to specify custom colors for the tabs.
Used only when
colored
is set to 1. - firstTab INTEGER
-
Selects the first ( leftmost ) visible tab.
- focusedTab INTEGER
-
Selects the currently focused tab. This property value is almost always equal to
tabIndex
except when the widget is navigated by arrow keys, and the tab selection does not occur until the user presses the return key. - topMost BOOLEAN
-
Selects the way the widget is oriented. If 1, the widget is drawn as if it resides on top of another widget. If 0, it is drawn as if it is at the bottom.
Default value: 1
- tabIndex INDEX
-
Selects the INDEXth tab. When changed, the
Change
notification is triggered. - tabs ARRAY
-
An array of text scalars. Each scalar corresponds to a tab and is displayed correspondingly. The class supports single-line text strings only; newline characters are not respected.
Methods
- get_item_width INDEX
-
Returns width in pixels of the INDEXth tab.
- tab2firstTab INDEX
-
Returns the index of the tab that will be drawn leftmost if the INDEXth tab is to be displayed.
- insert_tab TEXT, [ POSITION = -1 ]
-
Inserts a new tab text at the given position, which is at the end by default
- delete_tab POSITION
-
Removes the tab from the given position
Events
- Change
-
Triggered when the
tabIndex
property is changed. - DrawTab CANVAS, INDEX, COLOR_SET, POLYGON1, POLYGON2
-
Called when the INDEXth tab is to be drawn on CANVAS. COLOR_SET is an array reference that consists of four cached color values: foreground, background, dark 3d color, and light 3d color. POLYGON1 and POLYGON2 are array references that contain four points as integer pairs in (X,Y)-coordinates. POLYGON1 keeps the coordinates of the larger polygon of a tab, while POLYGON2 of the smaller. Text is displayed inside the larger polygon:
Depending on the
topMost
property value, POLYGON1 and POLYGON2 change their mutual vertical orientation.The notification is always called from within the
begin_paint/end_paint
block. - MeasureTab INDEX, REF
-
Stores the width of the INDEXth tab in pixels into the REF scalar value. This notification must be called from within the
begin_paint_info/end_paint_info
block.
Prima::TabbedNotebook
The class combines the functionality of Prima::TabSet
and Prima::Notebook
, providing the interactive multipage widget functionality. The page indexing scheme has two levels: the first level is equivalent to the tabs provided by Prima::TabSet
. Each first-level tab, in turn, may contain one or more second-level pages, which can be switched using native Prima::TabbedNotebook
controls.
The first-level tabs are referred to as tabs, and the second-level as pages.
Properties
The class forwards the following properties of Prima::TabSet
, which are described in Prima::TabSet: colored
, colorset
- defaultInsertPage INTEGER
-
Selects the page where widgets attached by the
insert
call are assigned to. If set toundef
, the default page is the current page.Default value:
undef
. - notebookClass STRING
-
Assigns the notebook widget class.
Create-only property.
Default value:
Prima::Notebook
- notebookProfile HASH
-
Assigns a hash of properties passed to the notebook widget during the creation.
Create-only property.
- notebookDelegations ARRAY
-
Assigns a list of delegated notifications to the notebook widget.
Create-only property.
- orientation INTEGER
-
Selects one of the following tno::XXX constants
- tno::Top
-
The TabSet will be drawn at the top of the widget.
- tno::Bottom
-
The TabSet will be drawn at the bottom of the widget.
Default value: tno::Top
- pageIndex INTEGER
-
Selects the INDEXth page or a tabset widget ( the second-level tab ). When this property is triggered,
tabIndex
can change its value, and theChange
notification is triggered. - style INTEGER
-
Selects one of the following tns::XXX constants
- tns::Standard
-
The widget will have a raised border surrounding it and a +/- control at the top for moving between pages.
- tns::Simple
-
The widget will have no decorations (other than a standard border). It is recommended to have only one second-level page per tab with this style.
Default value: tns::Standard
- tabIndex INTEGER
-
Selects the INDEXth tab on the tabset widget using the first-level tab numeration.
- tabs ARRAY
-
Manages the number and names of notebook pages. ARRAY is an anonymous array of text scalars where each corresponds to a single first-level tab and a single notebook page, however, with a single exception. To define second-level tabs, the same text string must be repeated as many times as many second-level tabs are needed. For example, the code
$nb-> tabs('1st', ('2nd') x 3);
results in the creation of a notebook of four pages and two first-level tabs. The tab
'2nd'
contains three second-level pages.The property implicitly operates the underlying notebook's
pageCount
property. When changed at run-time, its effect on the children widgets is therefore the same. See pageCount for more information. - tabsetClass STRING
-
Assigns the tab set widget class.
Create-only property.
Default value:
Prima::TabSet
- tabsetProfile HASH
-
Assigns a hash of properties passed to the tab set widget during the creation.
Create-only property.
- tabsetDelegations ARRAY
-
Assigns a list of delegated notifications to the tab set widget.
Create-only property.
Methods
The class forwards the following methods of Prima::Notebook
, which are described in Prima::Notebook: attach_to_page
, insert_to_page
, insert
, insert_transparent
, delete_widget
, detach_from_page
, move_widget
, contains_widget
, widget_get
, widget_set
, widgets_from_page
.
- tab2page INDEX
-
Returns the second-level tab index that corresponds to the INDEXth first-level tab.
- page2tab INDEX
-
Returns the first-level tab index that corresponds to the INDEXth second-level tab.
- insert_page TEXT, [ POSITION = -1 ]
-
Inserts a new page with text at the given position, which is at the end by default. If the TEXT is the same as the existing tab left or right from POSITION, the page is joined to the existing tab as a page; otherwise, a new tab is created.
- delete_page POSITION
-
Removes the page from the given position.
Events
- Change OLD_PAGE_INDEX, NEW_PAGE_INDEX
-
Triggered when the
pageIndex
property changes its value from OLD_PAGE_INDEX to NEW_PAGE_INDEX.
AUTHORS
Dmitry Karasik, <dmitry@karasik.eu.org>. Teo Sankaro, <teo_sankaro@hotmail.com>.
SEE ALSO
Prima, Prima::Widget, examples/notebook.pl.