Tag Archives: Tbrowse
SetKey()
Template
Class
Name
SetKey()
Category
TBrowse Method
Oneliner
Get an optionaly Set an new Code block associated to a inkey value
Syntax
SetKey(<nKey>[,<bBlock>]) --> bOldBlock
Arguments
<nKey> An valid inkey Code
<bBlock> An optional action to associate to the inkey value.
Returns
<bOldBlock> If an Keypress has it code block changes, it will return the previus one; otherwise, it will return the current one
Description
This method Get an optionaly set an code block that is associated to an inkey value. The table below show the default keypress/Code Block definitions
Inkey Value Code Block
K_DOWN {| oB, nKey | oB:Down(), 0 }
K_END {| oB, nKey | oB:End(), 0 }
K_CTRL_PGDN {| oB, nKey | oB:GoBottom(), 0 }
K_CTRL_PGUP {| oB, nKey | oB:GoTop(), 0 }
K_HOME {| oB, nKey | oB:Home(), 0 }
K_LEFT {| oB, nKey | oB:Left(), 0 }
K_PGDN {| oB, nKey | oB:PageDown(), 0 }
K_PGUP {| oB, nKey | oB:PageUp(), 0 }
K_CTRL_END {| oB, nKey | oB:PanEnd(), 0 }
K_CTRL_HOME {| oB, nKey | oB:PanHome(), 0 }
K_CTRL_LEFT {| oB, nKey | oB:PanLeft(), 0 }
K_CTRL_RIGHT {| oB, nKey | oB:PanRight(), 0 }
K_RIGHT {| oB, nKey | oB:Right(), 0 }
K_UP {| oB, nKey | oB:Up(), 0 }
K_ESC {| oB, nKey | -1 }
The keys handlers can be queried, added and replace an removed from the internal keyboard dictionary. See the example.
oTb:SetKey( K_TAB, {| oTb, nKey | -1 } )
An default key handler can be declared by specifyin a value of 0 for <nKey>. It associate code block will be evaluated each time TBrowse:Applykey() is called with an key value that is not contained in the dictionary. For example
oTb:SetKey( 0, {| oTb, nKey | DefKeyHandler( otb, nkey } ) This call the a function named DefKeyHandler() when nKey is not contained in the dictionary.
To remove an keypress/code block definition, specify NIL for <bBlock> oTb:SetKey( K_ESC, NIL )
Examples
oTb:SeyKey( K_F10, {| otb, nkey | ShowListByname( otb ) }
Applykey()
Template
Class
Name
Applykey()
Category
TBrowse Method
Oneliner
Evaluates an code block associated with an specific key
Syntax
ApplyKey(<nKey>) --> nResult
Arguments
<nKey> An valid Inkey code
Returns
<nResult> Value returned from the evaluated Code Block.
See Table Below :
Value Meaning
-1 User request for the browse lost input focus
0 Code block associated with <nkey> was evaluated
1 Unable to locate <nKey> in the dictionary,Key was not processed
Description
This method evaluate an code block associated with <nkey> that is contained in the TBrowse:SetKey() dictionary.
Examples
DO WHILE .T.
oTb:forceStable()
IF oTb:applykey( Inkey( 0 ) ) == -1
EXIT
ENDIF
ENDDO
AddColumn()
Template
Class
Name
AddColumn()
Category
TBrowse Method
Oneliner
Add an New Column to an TBrowse Object
Syntax
AddColumn(oCol) --> Self
Arguments
<oCol> Is an TbColumn object
Returns
<Self> The Current object
Description
This method add an new column object specified as <oCol> to the assigned browsing object.
SP_SACHOICE
SACHOICE()
Short:
------
SACHOICE() Achoice replacement, uses TBROWSE, codeblock
Returns:
--------
<nSelection> => selection, 0 if none
Syntax:
-------
SACHOICE(nTop,nLeft,nBottom,nRight,aOptions,[bKeyBlock],[nStart],[@nRow],;
[nMRow, nMCol],[bMouse])
Description:
------------
This semi-replaces ACHOICE() by using TBROWSE
instead, and by accepting an exception codeblock instead of a user
defined function.
<nTop,nLeft,nBottom,nRight> are the dimensions.
<aOptions> is the array. It need not be of type
Character.
First-letter presses go to the next matching letter
of the next character-type element.
Up/down/home/end/pageup/pagedown are used to position the
cursor. ENTER returns the current selection. Escape returns 0.
The screen is not saved and restored. This is a
building block function, like ACHOICE(), so save and restore the
screen, draw a box around it, etc, as you would ACHOICE().
[bKeyBlock] a codeblock which will be executed if an
exception key is received (any key not otherwise meaningful). The
codeblock will be evaluated and will be passed:
1. current element #
2. exception key value
3. the tbrowse object
as parameters.
[nStart] is an optional starting element. Default is 1.
[@nRow] is an optional starting row. Default is 1. Pass by reference
to retain value between calls.
[nMRow, nMCol] (new in 3.5) Directs sachoice() to draw
the "[.][.]" for mouse up/down at nMrow, nMCol, and to be aware of mouse
clicks on these buttons. (the screen under the arrows is saved/restored)
[bMouse] is a codeblock to evaluate mouse clicks other than those
meaningful to sachoice(). The codeblock is evaluated as follows:
eval(bMouse,mouserow, mousecolumn)
Examples:
---------
USE CUSTOMER
aFlds := afieldsx()
bExcept := {|e,k|msg("You pressed ",str(k))}
?SACHOICE(10,10,20,12,aFlds,bExcept)
//to retain element and position between calls
nSelect := 1
nRow := 1
aMeals := {"Pizza","Chicken","Chinese"}
while nSelect > 0
nSelect := sachoice(10,10,20,20,aMeals,nil,nSelect,@nRow)
// code
endif
Notes:
-------
This will be a lot easier to mouse-ize than ACHOICE.
(or is that RAT-ify..)
Source:
-------
S_ACHOI.PRG
SP_MCHOICE
MCHOICE()
Short:
------
MCHOICE() Does a boxed, achoice() style popup on an array
Returns:
--------
<expN> Achoice selection
Syntax:
-------
MCHOICE(aOptions,[nTop,nLeft],[nBottom,nRight],[cTitle],[lTrigger],;
[nStart],[@nRow],[aSelectable])
Description:
------------
Provides a box for selection from array <aOptions> of
character elements.
[nTop,nLeft] may be specifed to determine the
starting top and left of the popup box.
[nBottom,nRight] may be specified to complete the box
dimensions.
Default box dimensions are centered on the screen. If the dimensions
passed are not wide enough to display the mouse hot areas on the
bottom, the box is widened and centered on the screen.
[cTitle] is a string to display at the top of the box.
[lTrigger] determines (yes or no) whether a return is
to be executed on a first letter match.(default .f.)
[nStart] optional starting element (default 1)
[@nRow] optional starting row. Pass by reference to retain value
between calls.
[aSelectable] is an array of logicals that determines which items
are selectable. This array must be the same size as [aOptions], and
all elements must be either True or False, not NIL. Where an element
is False, the corresponding element in [aOptions] will be dimmed
and will emit a BEEP when you attempt to select it.
Examples:
---------
aMeals := {"Pizza","Chicken","Chinese"}
nSelect := mchoice(aMeals)
// or box with title
aMeals := {"Pizza","Chicken","Chinese"}
nSelect := mchoice(aMeals,,,,"Meals")
// or box with title, first letter match = return and top/left specified
aMeals := {"Pizza","Chicken","Chinese"}
nSelect := mchoice(aMeals,10,10,,,"Meals",.t.)
//to retain element and position between calls
nSelect := 1
nRow := 1
aMeals := {"Pizza","Chicken","Chinese"}
while nSelect > 0
nSelect := mchoice(aMeals,,,,,"Meals",.t.,nSelect,@nRow)
// code
endif
Notes:
-------
Bottom of window adjusts (shrinks) to adjust to array
size if needed.
Now uses Tbrowse() instead of ACHOICE().
Source:
-------
S_MCHOI.PRG
SP_MBRZMOVE
MBRZMOVE()
Short:
------
MBRZMOVE() Checks for mouse click at and moves to Tbrowse row/col
Returns:
--------
<lClicked> => If the mouse clicked on a new Tbrowse Row/Column.
Syntax:
-------
MBRZMOVE(oTBrowse, nMouseRow, nMouseCol,[nTop,nLeft,nBottom,nRight])
Description:
------------
Determines if the mouse coordinates <nMouseRow> and <nMouseCol>
are on a new Tbrowse row/column, and causes the Tbrowse cursor to
move there.
[nTop,nLeft,nBottom,nRight] determine the Tbrowse 'live' area - the
area exclusive of headers, footers, seperators etc. MBRZMOVE() can
determine this on its own, but it is much faster to pass these
coordinates if you can.
Examples:
---------
from MCHOICE():
case nLastKey == K_MOUSELEFT
do case
case ISMOUSEAT(nMouseR, nMouseC, nBottom,nRight-3, nBottom, nRight-2)
oTb:down()
IFMOUSEHD({||oTb:down()},oTb)
case MBRZMOVE(oTb,nMouseR, nMouseC,nTop+1,nLeft+1,nBottom-1,nRight-1)
keyboard chr(K_ENTER)
case MBRZMOVE(oTb,nMouseR, nMouseC)
EXIT
endcase
endcase
Source:
-------
S_MOOSE.PRG
SP_MBRZCLICK
MBRZCLICK()
Short:
------
MBRZCLICK() Checks for mouse click on current Tbrowse row/col
Returns:
--------
<lClicked> => if the mouse clicked on the current Tbrowse cursor row and
column.
Syntax:
-------
MBRZCLICK(oTBrowse, nMouseRow, nMouseCol)
Description:
------------
Determines if the mouse coordinates <nMouseRow> and <nMouseCol>
are within the area of the current Tbrowse row and column.
Examples:
---------
from MCHOICE():
case nLastKey == K_MOUSELEFT
do case
case ISMOUSEAT(nMouseR, nMouseC, nBottom,nRight-3, nBottom, nRight-2)
oTb:down()
IFMOUSEHD({||oTb:down()},oTb)
case MBRZMOVE(oTb,nMouseR, nMouseC,nTop+1,nLeft+1,nBottom-1,nRight-1)
keyboard chr(K_ENTER)
case MBRZCLICK(oTb,nMouseR, nMouseC) //<-----here
EXIT
endcase
endcase
Source:
-------
S_MOOSE.PRG
SP_BROWSESDF
BROWSESDF()
Short:
------
BROWSESDF() Tbrowse an SDF file
Returns:
--------
Nothing
Syntax:
-------
BROWSESDF(cFile,aDesc,aTypes,aLengths)
Description:
------------
Tbrowses an SDF file <cFile>, using column headers in
<aDesc>, with field 'types' in <aTypes>, and field lengths in
<aLengths>
Examples:
---------
//sample.sdf looks like this:
//AHLBERG STEPHEN 23.4519890226
//SMITH JEFF 45.0019890301
//SMITH DENNIS 0.0019890313
//ALVARADO DAVID 25.0019890330
//note: widths have to be exact
browseSDF("sample.sdf",{"Last","First","Due","Date"},;
{"C","C","N","D"},;
{20,15,8,8})
Source:
-------
S_BRSDF.PRG
SP_BROWSEDELIM
BROWSEDELIM()
Short:
------
BROWSEDELIM() Tbrowse a delimited file
Returns:
--------
Nothing
Syntax:
-------
BROWSEDELIM(cFile,aDesc,aTypes,aLens,[cFieldDelim],;
[cCharDelim])
Description:
------------
Browse delimited file <cFile>.
Column titles are contained in <aDesc> (one for each 'field').
Field types are contained in <aTypes>, Field lengths
are contained in <aLens>.
[cFieldDelim] - Field delimiter - default is a comma [,]
[cCharDelim] - Character type delimiter - default is
a double quote [""]
Examples:
---------
//sample.asc looks like this:
//"AHLBERG","STEPHEN",23.45,19890226
//"SMITH","JEFF",45.00,19890301
//"SMITH","DENNIS",0.00,19890313
//"ALVARADO","DAVID",25.00,19890330
//"AMPOLSUK","EARL",60.00,19890406
//"ANDRADE","GARRY",55.00,19890301
//"ANDRADE","WALT",99.99,19890703
browsedelim("sample.asc",{"First","Last","Due","Date"},;
{"C","C","N","D"},;
{15,25,6,8})
Source:
-------
S_BDELIM.PRG