Table field behavior

Eric Chatonet eric.chatonet at sosmartsoftware.com
Fri May 20 09:17:56 EDT 2005


Hello Bill,

I am working on a How-To stack about table fields.
It's not finished but here is an excerpt from this stack which might  
help you without waiting for the release :-)
As you will see it, it's a little bit dry and tricky :-(
But fully commented :-)
Following scripts are placed in the card script.

> By default, a table has no limits: you can use the arrowkeys or the  
> tabkey to navigate as far as you wish.
> Practically, you will often need to display a x*y cells table  
> without scrollbars as a matrix where all cells are visible and let  
> the user navigate in carousel (go from the last cell in a row to  
> the first cell in the next row and so on) through the limits you  
> have set.
> In order to set these limits, you will trigger the keyboard events  
> within a rawKeyDown handler.
> Here the limits which are integers are stored as custom properties  
> named xLimit and yLimit in the table field named "MyTable":
>
> on rawKeyDown pKey
>   -- allows tabbing and arrowkeys to act in carousel
>   -- horizontal and vertical limits are stored in 2 custom  
> properties (xLimit and yLimit) in the table field
>
>   if "revCell" is in the target then
>     -- when editing a table field, target function returns  
> something like: field "revCell-1,1"
>     if the xLimit of fld "MyTable" = "None" or the xLimit of fld  
> "MyTable" is empty then pass rawKeyDown -- no limits
>     -----
>     switch pKey
>     case 65363 -- arrow key right
>     case 65289 -- tab key
>       if the cRevTable["currentxcell"] of fld "MyTable" = the  
> xLimit of fld "MyTable" then
>         if the cRevTable["currentycell"] of fld "MyTable" = the  
> yLimit of fld "MyTable" then
>           SelectCell "MyTable",1,1 -- the first table cell
>         else
>           SelectCell "MyTable",1,the cRevTable["currentycell"] of  
> fld "MyTable" + 1 -- the first table cell in the next line
>         end if
>       else pass rawKeyDown
>       break
>       -----
>     case 65361 -- arrow key left
>       if the cRevTable["currentxcell"] of fld "MyTable" = 1 then
>         if the cRevTable["currentycell"] of fld "MyTable" <> 1 then
>           SelectCell "MyTable",the xLimit of fld "MyTable",the  
> cRevTable["currentycell"] of fld "MyTable" - 1 -- Æ
>           -- the last allowed table cell in the previous line
>         else
>           SelectCell "MyTable",the xLimit of fld "MyTable",the  
> yLimit of fld "MyTable" -- Æ
>           -- the last allowed table cell
>         end if
>       else pass rawKeyDown
>       break
>       -----
>     case 65364 -- arrow key down
>       if the cRevTable["currentycell"] of fld "MyTable" = the  
> yLimit of fld "MyTable" then
>         if the cRevTable["currentxcell"] of fld "MyTable" = the  
> xLimit of fld "MyTable" then
>           SelectCell "MyTable",1,1 -- the first table cell
>         else SelectCell "MyTable",the cRevTable["currentxcell"] of  
> fld "MyTable" + 1,1 -- Æ
>         -- the first table cell in the next column
>       else pass rawKeyDown
>       break
>       -----
>     case 65362 -- arrow key up
>       if the cRevTable["currentycell"] of fld "MyTable" = 1 then
>         if the cRevTable["currentxcell"] of fld "MyTable" <> 1 then
>           SelectCell "MyTable",the cRevTable["currentxcell"] of fld  
> "MyTable" - 1,the yLimit of fld "MyTable" -- Æ
>           -- the last allowed table cell in the previous column
>         else SelectCell "MyTable",the xLimit of fld "MyTable",the  
> yLimit of fld "MyTable" -- Æ
>         -- the last allowed table cell
>       else pass rawKeyDown
>       break
>       -----
>     default
>       pass rawKeyDown -- lets the engine do it
>     end switch
>   else pass rawKeyDown
> end rawKeyDown
> ----------------------------------------------------------------
>
> on SelectCell pFieldName,pColumn,pRow
>   -- select a cell
>
>   -- pFieldName parameter is the short name of the table field
>   -- pColumn parameter is the column number (an integer)
>   -- pRow parameter is the row number (an integer)
>
>   SetCurXCell pFieldName,pColumn -- Æ
>   SetCurYCell pFieldName,pRow -- Æ
>   -----
>   SetScroll "hScroll",the cRevTable["cellxspacing"] of fld  
> pFieldName * (pColumn - 1),pFieldName,"Header" -- Æ
>   SetScroll "vScroll",the cRevTable["cellyspacing"] of fld  
> pFieldName * (pRow - 1),pFieldName,"Rows" -- Æ
>   -----
>   click at CellLoc(pFieldName,pColumn,pRow) -- Æ
>   -----
>   -- to select again the current cell, you can use:
>   -- click at the cRevTable["currentxmouseloc"] of fld  
> pFieldName,the cRevTable["currentymouseloc"] of fld pFieldName
> end SelectCell
>
> ----------------------------------------------------------------
>
> function CellLoc pFieldName,pColumn,pRow
>   -- returns the loc of any cell
>
>   -- pFieldName parameter is the short name of the table field
>   -- pColumn parameter is the column number (an integer)
>   -- pRow parameter is the row number (an integer)
>
>   local  
> tLeft,tTop,tCellxspacing,tCellyspacing,tCurrenthscroll,tCurrentvscroll
>   -----
>   put the left of fld pFieldName into tLeft
>   put the top of fld pFieldName into tTop
>   put the cRevTable["cellxspacing"] of fld pFieldName into  
> tCellxspacing
>   put the cRevTable["cellyspacing"] of fld pFieldName into  
> tCellyspacing
>   put the hScroll of fld pFieldName into tCurrenthscroll
>   put the vScroll of fld pFieldName into tCurrentvscroll
>   return ((pColumn - 1) * tCellxspacing) + (tCellxspacing div 2) +  
> tLeft - tCurrenthscroll, \
>       ((pRow - 1) * tCellyspacing) + (tCellyspacing div 2) + tTop -  
> tCurrentvscroll
> end CellLoc
> ----------------------------------------------------------------
>
> on SetCurXCell pFieldName,pValue
>   -- updates prop in the cRevTable of the table field
>
>   -- pFieldName parameter is the short name of the table field
>   -- pValue parameter is the column number (an integer)
>
>   set the cRevTable["currentxcell"] of fld pFieldName to pValue
> end SetCurXCell
>
> ----------------------------------------------------------------
>
> on SetCurYCell pFieldName,pValue
>   -- updates prop in the cRevTable of the table field
>
>   -- pFieldName parameter is the short name of the table field
>   -- pValue parameter is the row number (an integer)
>
>   set the cRevTable["currentycell"] of fld pFieldName to pValue
> end SetCurYCell
>
> ----------------------------------------------------------------
>
> on SetScroll
>   -- sets the table field and header fields scrolls if they are any
>   -- the syntax is not very comprehensible since this handler can  
> set the scroll of an unknown number of fields
>   -- then it refers to parameters by order/number and not by name  
> using the do command
>
>   lock screen
>   lock messages
>   repeat with i = 3 to the paramcount
>     do "put there is a fld" && param(i) && "into tFlag"
>     if tFlag then do "set the" && param(1) && "of fld" && param(i)  
> && "to" && param(2)
>     -- param (3) to param(x) are the names of the fields
>   end repeat
>   unlock messages
>   unlock screen
> end SetScroll

That's all!
Is it enough?
LOL

Le 20 mai 05 ˆ 14:58, Bill a Žcrit :

> The docs on table fields is rather sparse.
>
> An example table field has six cells across. It is unlocked on Mac  
> OSX. When
> you enter data and tab across to the next cell and enter data for  
> that cell
> and tab it works fine until you get to the last cell then it  
> automatically
> scrolls to the right (there are no scroll bars set for either  
> vertical or
> horizontal). This automatic scroll to the right makes all the  
> previously
> entered data not visible and is a behavior I want to prevent. I tried
> locking position and that didn't work.
>
> How do I do this?


Best regards from Paris,

Eric Chatonet.
----------------------------------------------------------------
So Smart Software

For institutions, companies and associations
Built-to-order applications: management, multimedia, internet, etc.
Windows, Mac OS and Linux... With the French touch

Plugins, tutorials and more on our website
----------------------------------------------------------------
Web site        http://www.sosmartsoftware.com/
Email        eric.chatonet at sosmartsoftware.com/
Phone        33 (0)1 43 31 77 62
Mobile        33 (0)6 20 74 50 86
----------------------------------------------------------------



More information about the use-livecode mailing list