Class LISTITEM

Name

LISTITEM  --  Class are destined to control of associated in list data values. For example, it can be list of files.

Synopsis

 ListItemNew(<nLrow>,<nLcol>,<nRrow>,<nRcol>[,<nColumns>[,<sDelimiter>[,<sColor>]]]) --> ListItem object

Description

Class are destined to control of associated in list data values. For example, it can be list of files.

Attributes

<ClassName> LISTITEM
<Item> Array, array of data value
<nTop> Numeric, a LISTITEM viewport coordinates
<nLeft> Numeric, a LISTITEM viewport coordinates
<nBottom> Numeric, a LISTITEM viewport coordinates
<nRight> Numeric, a LISTITEM viewport coordinates
<ColorSpec> String, color specification.
  
  "clr1, clr2, clr3, clr4, clr5, clr6, clr7"
  clr1 - border and items color
  clr2 - current item colors if object in focus
  clr3 - current item colors if object outof focus
  clr4 - title colors
  clr5 - selected item colors
  clr6 - current selected item colors
  clr7 - founded symbol colors
  
  
<ItemCount> Numeric, items count
<Buffer> Numeric, the cuurent items number
<First> Numeric, the number of first element into viewport
<ItemWin> Numeric, items into viewport
<Line> Numeric, a current cursor coordinates - line
<Col> Numeric, a current cursor coordinates - column
<Pos> Numeric, a current column
<ColWin> Numeric, a number columns into viewport
<RowWin> Numeric, a number rows into viewport
<LenCol> Array, array with columns width
<Title> Array, array of string that contain columns titles
<Delim> String, columns delimiters
<HasFocus> Logical, is TRUE if object in focus
<FindBuffer> String, the find buffer
  

Methods

ADDITEM Add new element to listing.
CLEAR Remove all items from listing.
CLEARFINDBUFFER Crears find buffer.
DELITEM Delete an listing element.
DOWN Goes next element.
DRAWTITLE Draw columns header.
END Goes to last element of array <::Item>.
FIND Find substring.
GETITEM Gets current item.
GETSELECTED Returns selected items numbers.
HANDLEKEY Simple handle key.
HOME Goes to first element of array <::Item>.
INSITEM Insert new element into listing.
KILLFOCUS Kill focus.
LEFT Goes to left.
LISTITEMNEW LISTITEM object constructor.
PAGEDOWN Goes to next page of array <::Item>.
PAGEUP Goes to previouse page of array <::Item>.
REFRESH Refreshed viewport.
RIGHT Goes to right.
SELECT Select item.
SETCOLUMNS Set columns count.
SETFOCUS Set focus to object.
SETITEM Sets new current item.
SETKEY Set a code block associated with code key value.
SETTITLE Set columns header.
SETWIDTHCOL Set columns width.
UP Goes previous element.

Method LISTITEM:ADDITEM()

 AddItem(<vData>[, <sColor>][, <sSelColor>]) 	--> 0 || 1

AddItem() added new element to the end listing <::Item>.

Method LISTITEM:CLEAR()

 Clear() 	--> NIL

Clear() removes all items from a <::Item> and sets counters to zero.

Method LISTITEM:CLEARFINDBUFFER()

 ClearFindBuffer() 	--> NIL

ClearFindBuffer() is clears find buffer. <::FindBuffer> sets to empty string.

Method LISTITEM:DELITEM()

 DelItem(<nPos>) 	--> 0 || 1

DelItem() is deletes an element <nPos> from an listing <::Item>. The contents of the element is lost, and all elements from <nPos>+1 position shifted up one element. The last element in the array discarded.

Method LISTITEM:DOWN()

 Down() 	--> NIL

Down() is moves cursor to next element of <::Item>.

Method LISTITEM:DRAWTITLE()

 DrawTitle() 	--> TRUE

DrawTitle() is drew headers for listing columns.

Method LISTITEM:END()

 End() 	--> NIL

End() is moves cursor to the last element of <::Item> listing. The new current element will be len(<::Item>).

Method LISTITEM:FIND()

 Find(<sStr>) 	--> TRUE || FALSE

Find() is addes substring <sStr> to the end of find buffer <::FindBuffer> and searching <::FindBuffer> within <::Item>. If <::FindBuffer> is empty, searching start with first element of <::Item>, in other searching start with current position <::Buffer>.

The <::FindBuffer> value is compared to the array element beginning with the leftmost character in the <::Item> element and proceeding until there are no more characters left in <::FindBuffer>. If <::FindBuffer> is found seraching stopped, <::Buffer> sets to position founded element and Find() returns TRUE. If there is no match, <::Buffer> no changed, <sStr> removes from a <::FIndBuffer> and Find() returns FALSE.

Method LISTITEM:GETITEM()

 GetItem() 	--> <vData>

GetItem() is gets the current element <::Buffer> into listing <::Item>. If array <::Item> is empty, method return NIL.

Method LISTITEM:GETSELECTED()

 GetSelected() 	--> <aSelectedItems>

GetSelected() returns array of selected items numbers.

Method LISTITEM:HANDLEKEY()

 HandleKey(<nKey>) 	--> .T. || .F.

HandleKey() is evaluates code block that associated with key code <nKey>. The keypress/code block definition creates within SetKey() method.

A default key code cursor moves associates with corresponded methods Left(), Right(), Up(), Down() and more of LISTITEM class.

Method LISTITEM:HOME()

 Home() 	--> NIL

Home() is moves cursor to the first element of <::Item> listing. The new current element will be 1.

Method LISTITEM:INSITEM()

 InsItem(<vData>, <nPos>[, <sColor>][, <sSelColor>][, <lSelected>]) 	--> 0 || 1

InsItem() inserted new element <vData> into listing <::Item>. New element inserted at position <nPos>. Before insertion, size of <::Item> increased by 1 and all elements with <nPos> shifted down one elemen.

Method LISTITEM:KILLFOCUS()

 KillFocus() 	--> NIL

KillFocus() is kils focus for object of LISTITEM class. Attribute <::HasFocus> take value FALSE.

Method LISTITEM:LEFT()

 Left() 	--> NIL

Left() is moves cursor to left of current column. The new current element will be <::Buffer> - <::RowWin>.

Method LISTITEM:LISTITEMNEW()

 ListItemNew(<nLrow>,<nLcol>,<nRrow>,<nRcol>[,<nColumns>[,<sDelimiter>[,<sColor>]]]) --> ListItem object

ListItemNew() is constructs and returns new LISTITEM object. That class can be used to edit, view, control associated in list data.

Method LISTITEM:PAGEDOWN()

 PageDown() 	--> NIL

PageDown() is moves cursor to the next page of <::Item> listing. The size of page is <::ItemWin>. The current element will be <::Buffer>+<::ItemWin>.

Method LISTITEM:PAGEUP()

 PageUp() 	--> NIL

PageUp() is moves cursor to the previouse page of <::Item> listing. The size of page is <::ItemWin>. The current element will be <::Buffer>-<::ItemWin>.

Method LISTITEM:REFRESH()

 Refresh() 	--> NIL

Refresh() is refreshes viewport. Called within methods of class LISTITEM automaticaly.

Method LISTITEM:RIGHT()

 Right() 	--> NIL

Right() is moves cursor to right of current column. The new current element will be <::Buffer> + <::RowWin>.

Method LISTITEM:SELECT()

 Select([<vItem>]) 	--> TRUE

Select() is sets selected (one or more) items of listing <::Item>.

Method LISTITEM:SETCOLUMNS()

 SetColumns(<nCol>) 	--> TRUE || FALSE

SetColumns() is sets columns count and sets new balanced width for all columns.

Method LISTITEM:SETFOCUS()

 SetFocus() 	--> NIL

SetFocus() is sets focus to object of LISTITEM class. Attribute <::HasFocus> take value TRUE.

Method LISTITEM:SETITEM()

 SetItem(<nPos>) 	--> 0 || 1

SetItem() is sets new current element with number <nPos>. If <nPos> is more than length of <::Item>, method returns 0. If array <::Item> is empty, method return NIL.

Method LISTITEM:SETKEY()

 SetKey(<nKey>[, <bData>]) 	--> bPreviouse

SetKey() is sets a new code block associated with code <nKey>. When replacing an existing code block definition, it returns previous code block, in other returns current one. Its associated key code will be evaluated HandleKey() methods.

If <bData> is NIL, SetKey() returns old block code and remove keypress/code block definition.

A default key code is cursor moves(K_UP, K_DOWN, K_LEFT, K_RIGHT, K_PGUP, K_PGDN, K_HOME, K_END ....) associates with corresponded methods Left(), Right(), Up(), Down() and more.

Users code block take two parameters: link to LISTITEM object and key code; and can be returns one of next values:

-1 User request for the LISTITEM to lose input focus

0 Code block associated with <nKey> was evaluated

1 Unable to locate <nKey> in the dictionary, key was not processed

Method LISTITEM:SETTITLE()

 SetTitle(<aTitle>) 	--> TRUE || FALSE

SetTitle() is sets headers for listing columns. Headers sets for first len(<aTitle>) columns, the rest columns becomes empty header.

Method LISTITEM:SETWIDTHCOL()

 SetWidthCol(<aWidth>) 	--> TRUE || FALSE

SetWidthCol() is sets columns width. If <aWidth[i]>==0, for column with number <i> automaticaly sets balanced width.

Method LISTITEM:UP()

 Up() 	--> NIL

Up() is moves cursor to previouse element of <::Item>.

Example:

  #include <inkey.ch>
 #define FA_NORMAL	0
 #define FA_READONLY	1
 #define FA_HIDDEN	2
 #define FA_SYSTEM	4
 #define FA_VOLUME	8
 #define FA_DIRECTORY	16
 #define FA_ARCHIVE	32
 
 clear screen
 wopen(5, 5, 20, 30)
 li := ListItemNew(0, 0, maxrow(), maxcol()) //  create new ListItem object
 wbox()
 fname = fileseek("./", FA_ARCHIVE+FA_VOLUME+FA_SYSTEM+FA_HIDDEN+FA_READONLY)
 do while !empty(fname)
 li:AddItem(fname, "R/N, N/W")	// --> 1
 fname = fileseek()
 enddo
 li:SetKey(K_ENTER, {|oLI, nKey| alert(toString(oLI:Buffer)+ " " + oLi:GetItem())})
 li:SetFocus()
 do while .t.
 nKey := inkey(0)
 ret := li:HandleKey(nKey)
 if ret == -1
 exit
 endif
 enddo
 wclose()
 
 
 

Platforms

No dependies of platform.