.\" 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 "Widgets 3pm" .TH Widgets 3pm "2015-09-19" "perl v5.20.2" "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" Curses::Widgets \- Base widget class for use with the Curses::Application framework .SH "MODULE VERSION" .IX Header "MODULE VERSION" \&\f(CW$Id:\fR Widgets.pm,v 1.997 2002/11/14 01:30:19 corliss Exp corliss $ .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Curses::Widgets; \& \& $rv = test_colour(); \& test_color(); \& \& $colpr = select_colour($fore, $back); \& $colpr = select_color($fore, $back); \& \& $key = scankey($mwh); \& \& @lines = textwrap($text, 40); \& \& # The following are provided for use with descendent \& # classes, and while they are not expected to be \& # overridden, they can be. \& $obj = Curses::Widgets\->new({KEY => \*(Aqvalue\*(Aq}); \& $obj\->_copy($href1, $href2); \& $obj\->reset; \& $obj\->input($string); \& $value = $obj\->getField(\*(AqVALUE\*(Aq); \& $obj\->setField( \& \*(AqFIELD1\*(Aq => 1, \& \*(AqFIELD2\*(Aq => \*(Aqvalue\*(Aq \& ); \& $obj\->execute($mwh); \& $obj\->draw($mwh, 1); \& @geom = $obj\->_geometry; \& @geom = $obj\->_cgeometry; \& $dwh = $obj\->_canvas($mwh, @geom); \& $obj\->_save($mwh); \& $obj\->_restore($mwh); \& $obj\->_border($mwh); \& $obj\->_caption \& \& # The following are provided for use with descendent \& # classes, and are expected to be overridden. \& $obj\->_conf(%conf); \& $obj\->input_key($ch); \& $obj\->_content($mwh); \& $obj\->_cursor .Ve .SH "REQUIREMENTS" .IX Header "REQUIREMENTS" .IP "Curses" 4 .IX Item "Curses" .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module serves two purposes: to provide a framework for creating custom widget classes, and importing a few useful functions for global use. .PP Widget specific methods are documented in each Widget's pod, of which the following widgets are currently available: .IP "Button Set (Curses::Widgets::ButtonSet)" 4 .IX Item "Button Set (Curses::Widgets::ButtonSet)" .PD 0 .IP "Calendar (Curses::Widgets::Calendar)" 4 .IX Item "Calendar (Curses::Widgets::Calendar)" .IP "Combo-Box (Curses::Widgets::ComboBox)" 4 .IX Item "Combo-Box (Curses::Widgets::ComboBox)" .IP "Label (Curses::Widgets::Label)" 4 .IX Item "Label (Curses::Widgets::Label)" .IP "List Box (Curses::Widgets::ListBox)" 4 .IX Item "List Box (Curses::Widgets::ListBox)" .IP "Multicolumn List Box (Curses::Widgets::ListBox::MultiColumn)" 4 .IX Item "Multicolumn List Box (Curses::Widgets::ListBox::MultiColumn)" .IP "Menu (Curses::Widgets::Menu)" 4 .IX Item "Menu (Curses::Widgets::Menu)" .IP "Progress Bar (Curses::Widgets::ProgressBar)" 4 .IX Item "Progress Bar (Curses::Widgets::ProgressBar)" .IP "Text Field (Curses::Widgets::TextField)" 4 .IX Item "Text Field (Curses::Widgets::TextField)" .IP "Text Memo (Curses::Widgets::TextMemo)" 4 .IX Item "Text Memo (Curses::Widgets::TextMemo)" .PD .PP The following tutorials are available: .IP "Widget Usage \*(-- General Usage & Tips (Curses::Widgets::Tutorial)" 4 .IX Item "Widget Usage General Usage & Tips (Curses::Widgets::Tutorial)" .PD 0 .IP "Widget Creation (Curses::Widgets::Tutorial::Creation)" 4 .IX Item "Widget Creation (Curses::Widgets::Tutorial::Creation)" .IP "Widget Creation \*(-- ComboBox Example (Curses::Widgets::Tutorial::ComboBox)" 4 .IX Item "Widget Creation ComboBox Example (Curses::Widgets::Tutorial::ComboBox)" .PD .PP For even higher (and simpler) level control over collections of widgets on \&\*(L"forms\*(R", please see \fBCurses::Forms\fR, which uses this module as well. .SH "EXPORTED FUNCTIONS" .IX Header "EXPORTED FUNCTIONS" .SS "test_colour/test_color" .IX Subsection "test_colour/test_color" .Vb 2 \& $rv = test_colour(); \& test_color(); .Ve .PP This function tests the console for colour capability, and if found, it will set \fB\f(CB$Curses::Widgets::DEFAULTFG\fB\fR and \fB\f(CB$Curses::Widgets::DEFAULTBG\fB\fR to the default foreground and background colour, respectively. .PP It also calls the Curses \fBstart_color\fR for you. Unless you need to know the default foreground/background colours ahead of time, you won't need to call this, \fBselect_colour\fR will do it for you the first time it's called, if necessary. .PP This function returns a true or false, designating colour support. .SS "select_colour/select_color" .IX Subsection "select_colour/select_color" .Vb 2 \& $colpr = select_colour($fore, $back); \& $colpr = select_color($fore, $back); .Ve .PP This function returns the number of the specified colour pair. In doing so, it saves quite a few steps. .PP After the initial colour test, this function will safely (and quietly) return on all subsequent calls if no colour support is found. It returns \&'0', which is hardwired to your terminal default. If colour support is present, it allocates the colour pair using (n)curses \fBinit_pair\fR for you, if it hasn't been done already. .PP Most terminals have a limited number of colour pairs that can be defined. Because of this 0 (the terminal default colour pair) will be returned in lieu of attempting to allocate more colour pairs than the terminal supports. If you need a specific set of colours to be available, you might want allocate each pair ahead of time using this function to prevent less important pairs from running you out of pairs. .PP As a final note, yes, both the British and American spellings of \&'colo(u)r' are supported. .PP Known colours: .PP .Vb 4 \& black cyan \& green magenta \& red white \& yellow blue .Ve .PP The colours are not case sensitive. .SS "scankey" .IX Subsection "scankey" .Vb 1 \& $key = scankey($mwh); .Ve .PP The scankey function returns the key pressed, when it does. All it does is loop over a (n)curses \fBgetch\fR call until something other than \-1 is returned. Whether or not the \fBgetch\fR call is (half)\-blocking or cooked output is determined by how the (n)curses environment was initialised by your application. This is provided only to provide the most basic input functionality to your application, should you decide not to implement your own. .PP The only argument is a handle to a curses/window object. .SS "textwrap" .IX Subsection "textwrap" .Vb 1 \& @lines = textwrap($text, 40); .Ve .PP The textwrap function takes a string and splits according to the passed column limit, splitting preferrably along whitespace. Newlines are preserved. .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" .Vb 1 \& $obj = Curses::Widgets\->new({KEY => \*(Aqvalue\*(Aq}); .Ve .PP The new class method provides a basic constructor for all descendent widget classes. Internally, it assumes any configuration information to be passed in a hash ref as the sole argument. It dereferences that ref and passes it to the internal method \fB_conf\fR, which is expected to do any input validation/initialisation required by your widget. That method should return a 1 or 0, which will determine if \fBnew\fR returns a handle to the new object. .PP If \fB_conf\fR returns a 1, the \fB_copy\fR is called to back up the initial state information. .PP If descendent widgets use the methods provided in the class (instead of overriding them) then the following keys should always be recognised: .PP .Vb 8 \& Key Description \& ==================================================== \& FOREGROUND Foreground colour \& BACKGROUND Background colour \& BORDERCOL Border (foreground) colour \& CAPTIONCOL Caption (foreground) colour \& BORDER Whether or not to display a border \& CAPTION The string to use as the caption .Ve .PP The colours will default to the terminal foreground/background defaults. Other arguments may have defaults defined by the descendent classes. .SS "_conf" .IX Subsection "_conf" .Vb 1 \& $obj\->_conf(%conf); .Ve .PP This method should be overridden in your descendant class. As mentioned above, it should do any initialisation and validation required, based on the passed configuration hash. It should return a 1 or 0, depending on whether any critical errors were encountered during instantiation. .PP \&\fBNote:\fR your \fB_conf\fR method should call, as a last act, \&\fBSUPER::_conf\fR. This is important to do, since this method takes care of some colour initialisation steps for you automatically. The following keys are known by this module, and are used by certain rendering and initiation methods: .PP .Vb 6 \& Field Default Description \& ============================================================ \& FOREGROUND (terminal default) Default foreground colour \& BACKGROUND (terminal default) Default background colour \& BORDERCOL (FOREGROUND) Default border colour \& CAPTIONCOL (FOREGROUND) Default caption colour .Ve .PP As a final note, here are some rules regarding the structure of your configuration hash. You *must* save your state information in this hash. Another subroutine will copy that information after object instantiation in order to support the reset method. Also note that everything stored in this should *not* be more than one additional level deep (in other words, values can be hash or array refs, but none of the values in *that* structure should be refs), otherwise those refs will be copied over, instead of the data inside the structure. This essentially destroys your backup. .PP If you have special requirements, override the _copy method as well. .SS "_copy" .IX Subsection "_copy" .Vb 1 \& $obj\->_copy($href1, $href2); .Ve .PP This method copies the contents of \f(CW$href1\fR to \f(CW$href2\fR. This will only copy two levels of data, so any reference values deeper than that will be passed by reference, not as a copy of reference's (dereferenced) value. .SS "reset" .IX Subsection "reset" .Vb 1 \& $obj\->reset; .Ve .PP The reset method resets the object back to the original state by copying the original configuration information into the working hash. .SS "input_key" .IX Subsection "input_key" .Vb 1 \& $obj\->input_key($ch); .Ve .PP The input_key method should be overridden in all descendent classes. This method should accept character input and update it's internal state information appropriately. This method will be used in both interactive and non-interactive modes to send keystrokes to the widget. .SS "input" .IX Subsection "input" .Vb 1 \& $obj\->input($string); .Ve .PP The input method provides a non-interactive method for sending input to the widget. This is essentially just a wrapper for the \fBinput_key\fR method, but will accept any number of string arguments at once. It splits all of the input into separate characters for feeding to the \&\fBinput_key\fR method. .SS "execute" .IX Subsection "execute" .Vb 1 \& $obj\->execute($mwh); .Ve .PP This method puts the widget into interactive mode, which consists of calling the \fBdraw\fR method, scanning for keyboard input, feeding it to the \fBinput_key\fR method, and redrawing. .PP execute uses the widget's configuration information to allow easy modification of its behavoiur. First, it checks for the existance of a \s-1INPUTFUNC\s0 key. Setting its value to a subroutine reference allows you to substitute any custom keyboard scanning/polling routine in leiu of the default \fBscankey\fR provided by this module. .PP Second, it checks the return value of the input function against the regular expression stored in \s-1FOCUSSWITCH,\s0 if any. Any matches against that expression will tell this method to exit, returning the key that matches it. This effectively causes the widget to 'lose focus'. .PP The only argument is a handle to a valid curses window object. .PP \&\fB\s-1NOTE\s0\fR: If \et is in your regex, \s-1KEY_STAB\s0 will also be a trigger for a focus switch. .SS "getField" .IX Subsection "getField" .Vb 1 \& $value = $obj\->getField(\*(AqVALUE\*(Aq); .Ve .PP The getField method retrieves the value(s) for every field requested that exists in the configuration hash. .SS "setField" .IX Subsection "setField" .Vb 4 \& $obj\->setField( \& \*(AqFIELD1\*(Aq => 1, \& \*(AqFIELD2\*(Aq => \*(Aqvalue\*(Aq \& ); .Ve .PP The setField method sets the value for every key/value pair passed. .SS "draw" .IX Subsection "draw" .Vb 1 \& $obj\->draw($mwh, 1); .Ve .PP The draw method can be overridden in each descendant class. It is reponsible for the rendering of the widget, and only that. The first argument is mandatory, being a valid window handle with which to create the widget's derived window. The second is optional, but if set to true, will tell the widget to draw itself in an 'active' state. For instance, the TextField widget will also render a cursor, while a ButtonSet widget will render the selected button in standout mode. .PP The rendering sequence defined in this class is as follows: .PP .Vb 3 \& # Get the canvas geometry and create a window handle to it \& $dwh = $self\->_canvas($mwh, $self\->_geometry); \& return 0 unless $dwh; \& \& $self\->_init($dwh); \& $self\->_border($dwh); \& $self\->_caption($dwh); \& \& # Get the content area geometry and create a window handle to it \& $cwh = $self\->_canvas($dwh, $self\->_cgeometry); \& unless (defined $cwh) { \& $dwh\->delwin; \& return 0; \& } \& \& $self\->_content($cwh); \& $self\->_cursor($cwh) if $active; .Ve .SS "_geometry" .IX Subsection "_geometry" .Vb 1 \& @geom = $obj\->_geometry; .Ve .PP This method returns the size of the canvas, with dimensions adjusted to account for a border (based on the value of \fB\s-1BORDER\s0\fR in the configuration hash). .SS "_cgeometry" .IX Subsection "_cgeometry" .Vb 1 \& @geom = $obj\->_cgeometry; .Ve .PP This method returns the size of the content area. The Y and X coordinates are adjusted appropriately for rendering in a widget canvas. (0, 0) is returned for widgets with no border, and (1, 1) is returned for widgets with a border (based on the value of \fB\s-1BORDER\s0\fR in the configuration hash). .SS "_canvas" .IX Subsection "_canvas" .Vb 1 \& $dwh = $obj\->_canvas($mwh, @geom); .Ve .PP This method returns a window handle to a derived window in the passed window, using the specified geometry. This will return undef and produce a warning if the call fails for any reason. .SS "_init" .IX Subsection "_init" .Vb 1 \& $obj\->_init($mwh); .Ve .PP This method erases the window and sets the foreground/background colours as found in the configuration hash. .SS "_save" .IX Subsection "_save" .Vb 1 \& $obj\->_save($mwh); .Ve .PP This method saves the current attributes and colour pair in the passed window. This method would typically be called by the draw routine after _init is called on the derived window (though the current _init method calls this for you). .SS "_restore" .IX Subsection "_restore" .Vb 1 \& $obj\->_restore($mwh); .Ve .PP This method restores the last saved attributes and colour pair used in the window. This should be called at the end of any rendering phase that may alter the default colour and attribute settings. .SS "_border" .IX Subsection "_border" .Vb 1 \& $obj\->_border($mwh); .Ve .PP This method draws the border around the passed window if \fB\s-1BORDER\s0\fR is true within the configuration hash. .SS "_caption" .IX Subsection "_caption" .Vb 1 \& $obj\->_caption .Ve .PP This method draws a caption on the first line of the passed window if \&\fB\s-1CAPTION\s0\fR is defined within the configuration hash. .SS "_content" .IX Subsection "_content" .Vb 1 \& $obj\->_content($mwh); .Ve .PP This method should be overridden in all descendent classes, and should render any content in the passed window. The \fBdraw\fR method, as defined in this class, will pass a window the exact size of the content area, so no adjustments will need to be made to accommodate a border. .SS "_cursor" .IX Subsection "_cursor" .Vb 1 \& $obj\->_cursor .Ve .PP This method should be overridden in all descendent classes that display a cursor in the content area. The \fBdraw\fR method, as defined in this class, calls this method after the content is rendered, and passes it a window handle the exact size of the content area. .SH "HISTORY" .IX Header "HISTORY" .IP "2001/07/05 \*(-- First implementation of the base class." 4 .IX Item "2001/07/05 First implementation of the base class." .SH "AUTHOR/COPYRIGHT" .IX Header "AUTHOR/COPYRIGHT" (c) 2001 Arthur Corliss (corliss@digitalmages.com)