.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Prima::Lists 3" .TH Prima::Lists 3 "2009-02-24" "perl v5.20.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Prima::Lists \- user\-selectable item list widgets .SH "DESCRIPTION" .IX Header "DESCRIPTION" The module provides classes for several abstraction layers of item representation. The hierarchy of classes is as follows: .PP .Vb 5 \& AbstractListViewer \& AbstractListBox \& ListViewer \& ProtectedListBox \& ListBox .Ve .PP The root class, \f(CW\*(C`Prima::AbstractListViewer\*(C'\fR, provides common interface, while by itself it is not directly usable. The main differences between classes are centered around the way the item list is stored. The simplest organization of a text-only item list, provided by \f(CW\*(C`Prima::ListBox\*(C'\fR, stores an array of text scalars in a widget. More elaborated storage and representation types are not realized, and the programmer is urged to use the more abstract classes to derive own mechanisms. For example, for a list of items that contain text strings and icons see \*(L"Prima::DirectoryListBox\*(R" in Prima::FileDialog. To organize an item storage, different from \f(CW\*(C`Prima::ListBox\*(C'\fR, it is usually enough to overload either the \f(CW\*(C`Stringify\*(C'\fR, \f(CW\*(C`MeasureItem\*(C'\fR, and \f(CW\*(C`DrawItem\*(C'\fR events, or their method counterparts: \f(CW\*(C`get_item_text\*(C'\fR, \&\f(CW\*(C`get_item_width\*(C'\fR, and \f(CW\*(C`draw_items\*(C'\fR. .SH "Prima::AbstractListViewer" .IX Header "Prima::AbstractListViewer" \&\f(CW\*(C`Prima::AbstractListViewer\*(C'\fR is a descendant of \f(CW\*(C`Prima::GroupScroller\*(C'\fR, and some properties are not described here. See \*(L"Prima::GroupScroller\*(R" in Prima::IntUtils. .PP The class provides interface to generic list browsing functionality, plus functionality for text-oriented lists. The class is not usable directly. .SS "Properties" .IX Subsection "Properties" .IP "autoHeight \s-1BOOLEAN\s0" 4 .IX Item "autoHeight BOOLEAN" If 1, the item height is changed automatically when the widget font is changed; this is useful for text items. If 0, item height is not changed; this is useful for non-text items. .Sp Default value: 1 .IP "count \s-1INTEGER\s0" 4 .IX Item "count INTEGER" An integer property, destined to reflect number of items in the list. Since it is tied to the item storage organization, and hence, to possibility of changing the number of items, this property is often declared as read-only in descendants of \f(CW\*(C`Prima::AbstractListViewer\*(C'\fR. .IP "dragable \s-1BOOLEAN\s0" 4 .IX Item "dragable BOOLEAN" If 1, allows the items to be dragged interactively by pressing control key together with left mouse button. If 0, item dragging is disabled. .Sp Default value: 1 .IP "drawGrid \s-1BOOLEAN\s0" 4 .IX Item "drawGrid BOOLEAN" If 1, vertical grid lines between columns are drawn with \f(CW\*(C`gridColor\*(C'\fR. Actual only in multi-column mode. .Sp Default value: 1 .IP "extendedSelect \s-1BOOLEAN\s0" 4 .IX Item "extendedSelect BOOLEAN" Regards the way the user selects multiple items and is only actual when \f(CW\*(C`multiSelect\*(C'\fR is 1. If 0, the user must click each item in order to mark as selected. If 1, the user can drag mouse or use \f(CW\*(C`Shift\*(C'\fR key plus arrow keys to perform range selection; the \f(CW\*(C`Control\*(C'\fR key can be used to select individual items. .Sp Default value: 0 .IP "focusedItem \s-1INDEX\s0" 4 .IX Item "focusedItem INDEX" Selects the focused item index. If \-1, no item is focused. It is mostly a run-time property, however, it can be set during the widget creation stage given that the item list is accessible on this stage as well. .Sp Default value: \-1 .IP "gridColor \s-1COLOR\s0" 4 .IX Item "gridColor COLOR" Color, used for drawing vertical divider lines for multi-column list widgets. The list classes support also the indirect way of setting the grid color, as well as widget does, via the \f(CW\*(C`colorIndex\*(C'\fR property. To achieve this, \f(CW\*(C`ci::Grid\*(C'\fR constant is declared ( for more detail see \*(L"colorIndex\*(R" in Prima::Widget ). .Sp Default value: \f(CW\*(C`cl::Black\*(C'\fR. .IP "integralHeight \s-1BOOLEAN\s0" 4 .IX Item "integralHeight BOOLEAN" If 1, only the items that fit vertically in the widget interiors are drawn. If 0, the items that are partially visible are drawn also. .Sp Default value: 0 .IP "integralWidth \s-1BOOLEAN\s0" 4 .IX Item "integralWidth BOOLEAN" If 1, only the items that fit horizontally in the widget interiors are drawn. If 0, the items that are partially visible are drawn also. Actual only in multi-column mode. .Sp Default value: 0 .IP "itemHeight \s-1INTEGER\s0" 4 .IX Item "itemHeight INTEGER" Selects the height of the items in pixels. Since the list classes do not support items with different dimensions, changes to this property affect all items. .Sp Default value: default font height .IP "itemWidth \s-1INTEGER\s0" 4 .IX Item "itemWidth INTEGER" Selects the width of the items in pixels. Since the list classes do not support items with different dimensions, changes to this property affect all items. .Sp Default value: default widget width .IP "multiSelect \s-1BOOLEAN\s0" 4 .IX Item "multiSelect BOOLEAN" If 0, the user can only select one item, and it is reported by the \f(CW\*(C`focusedItem\*(C'\fR property. If 1, the user can select more than one item. In this case, \f(CW\*(C`focusedItem\*(C'\fR'th item is not necessarily selected. To access selected item list, use \f(CW\*(C`selectedItems\*(C'\fR property. .Sp Default value: 0 .IP "multiColumn \s-1BOOLEAN\s0" 4 .IX Item "multiColumn BOOLEAN" If 0, the items are arrayed vertically in one column, and the main scroll bar is vertical. If 1, the items are arrayed in several columns, \f(CW\*(C`itemWidth\*(C'\fR pixels wide each. In this case, the main scroll bar is horizontal. .IP "offset \s-1INTEGER\s0" 4 .IX Item "offset INTEGER" Horizontal offset of an item list in pixels. .IP "topItem \s-1INTEGER\s0" 4 .IX Item "topItem INTEGER" Selects the first item drawn. .IP "selectedCount \s-1INTEGER\s0" 4 .IX Item "selectedCount INTEGER" A read-only property. Returns number of selected items. .IP "selectedItems \s-1ARRAY\s0" 4 .IX Item "selectedItems ARRAY" \&\s-1ARRAY\s0 is an array of integer indices of selected items. .IP "vertical \s-1BOOLEAN\s0" 4 .IX Item "vertical BOOLEAN" Sets seneral direction of items in multi-column mode. If 1, items increase down-to-right. Otherwise, right-to-down. .Sp Doesn't have any effect in single-column mode. Default value: 1. .SS "Methods" .IX Subsection "Methods" .IP "add_selection \s-1ARRAY, FLAG\s0" 4 .IX Item "add_selection ARRAY, FLAG" Sets item indices from \s-1ARRAY\s0 in selected or deselected state, depending on \s-1FLAG\s0 value, correspondingly 1 or 0. .Sp Only for multi-select mode. .IP "deselect_all" 4 .IX Item "deselect_all" Removes selection from all items. .Sp Only for multi-select mode. .IP "draw_items \s-1CANVAS, ITEM_DRAW_DATA\s0" 4 .IX Item "draw_items CANVAS, ITEM_DRAW_DATA" Called from within \f(CW\*(C`Paint\*(C'\fR notification to draw items. The default behavior is to call \f(CW\*(C`DrawItem\*(C'\fR notification for every item in \s-1ITEM_DRAW_DATA\s0 array. \&\s-1ITEM_DRAW_DATA\s0 is an array or arrays, where each array consists of parameters, passed to \f(CW\*(C`DrawItem\*(C'\fR notification. .Sp This method is overridden in some descendant classes, to increase the speed of drawing routine. For example, \f(CW\*(C`std_draw_text_items\*(C'\fR is the optimized routine for drawing unified text-based items. It is used in \f(CW\*(C`Prima::ListBox\*(C'\fR class. .Sp See DrawItem for parameters description. .IP "draw_text_items \s-1CANVAS, FIRST, LAST, STEP, X, Y, OFFSET, CLIP_RECT\s0" 4 .IX Item "draw_text_items CANVAS, FIRST, LAST, STEP, X, Y, OFFSET, CLIP_RECT" Called by \f(CW\*(C`std_draw_text_items\*(C'\fR to draw sequence of text items with indices from \s-1FIRST\s0 to \s-1LAST,\s0 by \s-1STEP,\s0 on \s-1CANVAS,\s0 starting at point X, Y, and incrementing the vertical position with \s-1OFFSET. CLIP_RECT\s0 is a reference to array of four integers with inclusive-inclusive coordinates of the active clipping rectangle. .IP "get_item_text \s-1INDEX\s0" 4 .IX Item "get_item_text INDEX" Returns text string assigned to INDEXth item. Since the class does not assume the item storage organization, the text is queried via \f(CW\*(C`Stringify\*(C'\fR notification. .IP "get_item_width \s-1INDEX\s0" 4 .IX Item "get_item_width INDEX" Returns width in pixels of INDEXth item. Since the class does not assume the item storage organization, the value is queried via \f(CW\*(C`MeasureItem\*(C'\fR notification. .IP "is_selected \s-1INDEX\s0" 4 .IX Item "is_selected INDEX" Returns 1 if INDEXth item is selected, 0 if it is not. .IP "item2rect \s-1INDEX,\s0 [ \s-1WIDTH, HEIGHT \s0]" 4 .IX Item "item2rect INDEX, [ WIDTH, HEIGHT ]" Calculates and returns four integers with rectangle coordinates of INDEXth item within the widget. \s-1WIDTH\s0 and \s-1HEIGHT\s0 are optional parameters with pre-fetched dimension of the widget; if not set, the dimensions are queried by calling \f(CW\*(C`size\*(C'\fR property. If set, however, the \f(CW\*(C`size\*(C'\fR property is not called, thus some speed-up can be achieved. .IP "point2item X, Y" 4 .IX Item "point2item X, Y" Returns the index of an item that contains point (X,Y). If the point belongs to the item outside the widget's interior, returns the index of the first item outside the widget's interior in the direction of the point. .IP "redraw_items \s-1INDICES\s0" 4 .IX Item "redraw_items INDICES" Redraws all items in \s-1INDICES\s0 array. .IP "select_all" 4 .IX Item "select_all" Selects all items. .Sp Only for multi-select mode. .IP "set_item_selected \s-1INDEX, FLAG\s0" 4 .IX Item "set_item_selected INDEX, FLAG" Sets selection flag of INDEXth item. If \s-1FLAG\s0 is 1, the item is selected. If 0, it is deselected. .Sp Only for multi-select mode. .IP "select_item \s-1INDEX\s0" 4 .IX Item "select_item INDEX" Selects INDEXth item. .Sp Only for multi-select mode. .IP "std_draw_text_items \s-1CANVAS, ITEM_DRAW_DATA\s0" 4 .IX Item "std_draw_text_items CANVAS, ITEM_DRAW_DATA" An optimized method, draws unified text-based items. It is fully compatible to \f(CW\*(C`draw_items\*(C'\fR interface, and is used in \f(CW\*(C`Prima::ListBox\*(C'\fR class. .Sp The optimization is derived from the assumption that items maintain common background and foreground colors, that differ in selected and non-selected states only. The routine groups drawing requests for selected and non-selected items, and draws items with reduced number of calls to \f(CW\*(C`color\*(C'\fR property. While the background is drawn by the routine itself, the foreground ( usually text ) is delegated to the \f(CW\*(C`draw_text_items\*(C'\fR method, so the text positioning and eventual decorations would not require full rewrite of code. .Sp \&\s-1ITEM_DRAW_DATA\s0 is an array of arrays of scalars, where each array contains parameters of \f(CW\*(C`DrawItem\*(C'\fR notification. See DrawItem for parameters description. .IP "toggle_item \s-1INDEX\s0" 4 .IX Item "toggle_item INDEX" Toggles selection of INDEXth item. .Sp Only for multi-select mode. .IP "unselect_item \s-1INDEX\s0" 4 .IX Item "unselect_item INDEX" Deselects INDEXth item. .Sp Only for multi-select mode. .SS "Events" .IX Subsection "Events" .IP "Click" 4 .IX Item "Click" Called when the user presses return key or double-clicks on an item. The index of the item is stored in \f(CW\*(C`focusedItem\*(C'\fR. .IP "DragItem \s-1OLD_INDEX, NEW_INDEX\s0" 4 .IX Item "DragItem OLD_INDEX, NEW_INDEX" Called when the user finishes the drag of an item from \s-1OLD_INDEX\s0 to \s-1NEW_INDEX\s0 position. The default action rearranges the item list in accord with the dragging action. .IP "DrawItem \s-1CANVAS, INDEX, X1, Y1, X2, Y2, SELECTED, FOCUSED\s0" 4 .IX Item "DrawItem CANVAS, INDEX, X1, Y1, X2, Y2, SELECTED, FOCUSED" Called when an INDEXth item is to be drawn on \s-1CANVAS. X1, Y1, X2, Y2\s0 designate the item rectangle in widget coordinates, where the item is to be drawn. \s-1SELECTED\s0 and \s-1FOCUSED\s0 are boolean flags, if the item must be drawn correspondingly in selected and focused states. .IP "MeasureItem \s-1INDEX, REF\s0" 4 .IX Item "MeasureItem INDEX, REF" Puts width in pixels of INDEXth item into \s-1REF\s0 scalar reference. This notification must be called from within \f(CW\*(C`begin_paint_info/end_paint_info\*(C'\fR block. .IP "SelectItem \s-1INDEX, FLAG\s0" 4 .IX Item "SelectItem INDEX, FLAG" Called when the item changed its selection state. \&\s-1INDEX\s0 is the index of the item, \s-1FLAG\s0 is its new selection state: 1 if it is selected, 0 if it is not. .IP "Stringify \s-1INDEX, TEXT_REF\s0" 4 .IX Item "Stringify INDEX, TEXT_REF" Puts text string, assigned to INDEXth item into \s-1TEXT_REF\s0 scalar reference. .SH "Prima::AbstractListBox" .IX Header "Prima::AbstractListBox" Exactly the same as its ascendant, \f(CW\*(C`Prima::AbstractListViewer\*(C'\fR, except that it does not propagate \f(CW\*(C`DrawItem\*(C'\fR message, assuming that the items must be drawn as text. .SH "Prima::ListViewer" .IX Header "Prima::ListViewer" The class implements items storage mechanism, but leaves the items format to the programmer. The items are accessible via \&\f(CW\*(C`items\*(C'\fR property and several other helper routines. .PP The class also defines the user navigation, by accepting character keyboard input and jumping to the items that have text assigned with the first letter that match the input. .PP \&\f(CW\*(C`Prima::ListViewer\*(C'\fR is derived from \f(CW\*(C`Prima::AbstractListViewer\*(C'\fR. .SS "Properties" .IX Subsection "Properties" .IP "autoWidth \s-1BOOLEAN\s0" 4 .IX Item "autoWidth BOOLEAN" Selects if the gross item width must be recalculated automatically when either the font changes or item list is changed. .Sp Default value: 1 .IP "count \s-1INTEGER\s0" 4 .IX Item "count INTEGER" A read-only property; returns number of items. .IP "items \s-1ARRAY\s0" 4 .IX Item "items ARRAY" Accesses the storage array of items. The format of items is not defined, it is merely treated as one scalar per index. .SS "Methods" .IX Subsection "Methods" .IP "add_items \s-1ITEMS\s0" 4 .IX Item "add_items ITEMS" Appends array of \s-1ITEMS\s0 to the end of the list. .IP "calibrate" 4 .IX Item "calibrate" Recalculates all item widths and adjusts \f(CW\*(C`itemWidth\*(C'\fR if \&\f(CW\*(C`autoWidth\*(C'\fR is set. .IP "delete_items \s-1INDICES\s0" 4 .IX Item "delete_items INDICES" Deletes items from the list. \s-1INDICES\s0 can be either an array, or a reference to an array of item indices. .IP "get_item_width \s-1INDEX\s0" 4 .IX Item "get_item_width INDEX" Returns width in pixels of INDEXth item from internal cache. .IP "get_items \s-1INDICES\s0" 4 .IX Item "get_items INDICES" Returns array of items. \s-1INDICES\s0 can be either an array, or a reference to an array of item indices. Depending on the caller context, the results are different: in array context the item list is returned; in scalar \- only the first item from the list. The semantic of the last call is naturally usable only for single item retrieval. .IP "insert_items \s-1OFFSET, ITEMS\s0" 4 .IX Item "insert_items OFFSET, ITEMS" Inserts array of items at \s-1OFFSET\s0 index in the list. Offset must be a valid index; to insert items at the end of the list use \f(CW\*(C`add_items\*(C'\fR method. .Sp \&\s-1ITEMS\s0 can be either an array, or a reference to an array of items. .IP "replace_items \s-1OFFSET, ITEMS\s0" 4 .IX Item "replace_items OFFSET, ITEMS" Replaces existing items at \s-1OFFSET\s0 index in the list. Offset must be a valid index. .Sp \&\s-1ITEMS\s0 can be either an array, or a reference to an array of items. .SH "Prima::ProtectedListBox" .IX Header "Prima::ProtectedListBox" A semi-demonstrational class, derived from \f(CW\*(C`Prima::ListViewer\*(C'\fR, that applies certain protection for every item drawing session. Assuming that several item drawing routines can be assembled in one widget, \f(CW\*(C`Prima::ProtectedListBox\*(C'\fR provides a safety layer between these, so, for example, one drawing routine that selects a font or a color and does not care to restore the old value back, does not affect the outlook of the other items. .PP This functionality is implementing by overloading \f(CW\*(C`draw_items\*(C'\fR method and also all graphic properties. .SH "Prima::ListBox" .IX Header "Prima::ListBox" Descendant of \f(CW\*(C`Prima::ListViewer\*(C'\fR, declares format of items as a single text string. Incorporating all of functionality of its predecessors, provides a standard listbox widget. .SS "Synopsis" .IX Subsection "Synopsis" .Vb 7 \& my $lb = Prima::ListBox\-> create( \& items => [qw(First Second Third)], \& focusedItem => 2, \& onClick => sub { \& print $_[0]\-> get_items( $_[0]\-> focusedItem), " is selected\en"; \& } \& ); .Ve .SS "Methods" .IX Subsection "Methods" .IP "get_item_text \s-1INDEX\s0" 4 .IX Item "get_item_text INDEX" Returns text string assigned to INDEXth item. Since the item storage organization is implemented, does so without calling \f(CW\*(C`Stringify\*(C'\fR notification. .SH "AUTHOR" .IX Header "AUTHOR" Dmitry Karasik, . .SH "SEE ALSO" .IX Header "SEE ALSO" Prima, Prima::Widget, Prima::ComboBox, Prima::FileDialog, \fIexamples/editor.pl\fR