>At the moment, this kind of thing can just about be done, but it requires
>complex and painful scripting.  I believe there are one or two example
>stacks where people have tried varying different ways to produce a table
>like this, check out the contributors section to see if anything does what
>you need.  Improving field features is certainly under consideration for
>2.4.
>
>Regards,
>
>Kevin

I've managed to do within-column wrapping by using a hidden 
additional field ('temp' say).  I size this to the pixel width of a 
column and lay the text into this temp field.  Then I get the 
'formattedText' of this field which has hard line returns in it and 
place this into the target field.

The following handler returns hard wrapped lines of text (Note: it 
assumes the target field uses same font metrics as the temp field, 
otherwise you'd have to pass and set textFont, textSize, textStyle, 
etc. within the handler):

   function wrappedText theText, pixelWidth
     put theText into field "Temp"
     set the width of field "Temp" to pixelWidth
     return the formattedText of field "Temp"
   end wrappedText

You can calculate the 'pixelWidth' of a column as follows (I make it 
slightly smaller than it really is to make the text wrap avoid going 
too close to the column margin):

   put the tabStops of field tableField into theTabs
   set the itemDelimiter to comma
   put item 2 of theTabs - item 1 of theTabs - 10 into col1Width
   put item 3 of theTabs - item 2 of theTabs - 10 into col2Width
   # etc.

Placing variable length wrapped text in a 'table' together with other 
material can be a bit challenging, but the following script snippet 
shows how I did it (I assume that I have a sourceText variable that 
contains table 'rows' as lines, with each 'column' value separated 
from the next by a tab):

   set itemDelimiter to tab
   put 1 into tableLine
   repeat for each line i in sourceText
     # put non-wrapping stuff in first:
     put item 1 of i into item 1 of line tableLine of field tableField
     put item 4 of i into item 4 of line tableLine of field tableField
     # generate wrapped text:
     put wrappedText(item 2 of i,col2Width) into col2
     put wrappedText(item 3 of i,col3Width) into col3
     # work out max depth of wrapping columns:
     put max(number of lines in col2,number of lines in col3) into maxLine
     # now place wrapped fragments into the columns:
     repeat with k = 1 to maxLine
       put line k of col2 into col2Fragment
       if col2Fragment is not empty then \
          put col2Fragment into item 2 of line tableLine of field tableField
       put line k of col3 into col3Fragment
       if col3Fragment is not empty then \
          put col3Fragment into item 3 of line tableLine of field tableField
       add 1 to tableLine
     end repeat
   end repeat

By way of a 'bonus', the following handler returns the number of the 
column of a 'table' clicked by the user - quite useful for using 
'switch' within the table's mouseUp handler:

   function clickColumn clickPixel, theTabs
     set itemDelimiter to comma
     put 1 into theColumn
     repeat with t = (number of items in theTabs - 1) down to 1
       if clickPixel >= (item t of theTabs) then
         put t + 1 into theColumn
         exit repeat
       end if
     end repeat
     return theColumn
     set itemDelimiter to tab
   end clickColumn

You can determine the 'clickPixel' of a field and then convert this 
into the clicked column as follows:

   put clickH() - left of me into theClickPixel
   put clickColumn(theClickPixel, the tabStops of me) into theClickedColumn

I wouldn't like to claim the above is the most elegant or efficient 
way of producing wrapping tables, but it does work!

Cheers
Peter

PS Sorry if this is contribution is a bit long!

--------------------------------------------------------
Peter Reid
Reid-IT Limited, Loughborough, Leics., UK
Tel: +44 (0)1509 268843 Fax: +44 (0)870 052 7576
E-mail: [EMAIL PROTECTED]
Web: http://www.reidit.co.uk

This is the MetaCard mailing list.
Archives: http://www.mail-archive.com/metacard%40lists.best.com/
Info: http://www.xworlds.com/metacard/mailinglist.htm

Reply via email to