Thanks!

On Mon, 9 Jan 2017 09:57:10 -0700, Cannon Smith wrote:
> Hi Chip,
> 
> I pasted some code below you might be interested in. It is from a 
> method I named LB_Header_SplitLabels. You can run it after setting up 
> a listbox, whenever you add/remove columns from a listbox, whenever 
> you change the label in a listbox column header, and whenever a 
> listbox column width is changed. It works especially nice in v16 in 
> On Column Resize since it is run continuously now.
> 
> Basically what it does is split each header label at spaces so that 
> it will fit inside the column width. It even takes into account the 
> sort indicator which takes up some room. It then adjusts the height 
> of the listbox header to fit the label with the most lines in it.
> 
> Even though it is working on the entire listbox each time it is 
> called, it is surprisingly fast. It is kind of fun to watch when 
> running in v16―to see the header height dynamically change as you 
> resize a column.
> 
> Two caveats:
> 
> 1. The $lExtraWidth variable should work on macOS. I haven’t tested 
> on Windows yet which may need a bit more nudge room.
> 2. There is currently a bug (ACI0096187) in v16 where 4D will give a 
> series of stack space errors (or even crash) when this method runs. I 
> find it doesn’t happen very often, but you may see it.
> 
> Anyway, feel free to use the method if it can add to what you’re doing.
> 
> --
> Cannon Smith
> Synergy Farm Solutions Inc.
> Hill Spring, AB Canada
> 403-626-3236
> <[email protected]>
> <www.synergyfarmsolutions.com>
> 
> 
>   //Given a listbox and a column, this method will split a header 
> label at spaces when the column width becomes
>   //too small. It also resizes the header height to accomodate the 
> header with the most lines. It works no matter
>   //the font, size, style, or how high the header is. It will simply 
> split on spaces when necessary and put as
>   //much of the label as possible in the header area.
> 
>   //This can be called when setting up a listbox. It can also be 
> called during On Column Resize..
> 
> C_POINTER($1;$pLB)  //A pointer to the listbox
> 
> $pLB:=$1
> 
> C_TEXT($tLabel;$tFont)
> C_LONGINT($x;$y;$lWidth;$lSize;$lStyle;$lMaxLines;$lExtraWidth)
> ARRAY TEXT($atColNames;0)
> ARRAY TEXT($atHeadNames;0)
> ARRAY POINTER($apColVars;0)
> ARRAY POINTER($apHeadVars;0)
> ARRAY BOOLEAN($afVisible;0)
> ARRAY POINTER($apStyles;0)
> ARRAY TEXT($atLines;0)
> 
>   //Loop through every visible column in the listbox, splitting the 
> label into lines based on the current
>   //width of the column. Also, keep track of the column with the 
> greatest number of lines.
> $lMaxLines:=1
> LISTBOX GET 
> 
ARRAYS($pLB->;$atColNames;$atHeadNames;$apColVars;$apHeadVars;$afVisible;$apStyles)
> For ($x;1;Size of array($atColNames))
>       If ($afVisible{$x}=True)
>               $lExtraWidth:=Choose($apHeadVars{$x}->>0;15;5)  //Need extra 
> room, 
> more if there is a sort indicator
>               $lWidth:=LISTBOX Get column 
> width(*;$atColNames{$x})-$lExtraWidth
>               $tLabel:=Replace string(OBJECT Get 
> title(*;$atHeadNames{$x});"\r";" ")
>               $tFont:=OBJECT Get font(*;$atHeadNames{$x})
>               $lSize:=OBJECT Get font size(*;$atHeadNames{$x})
>               $lStyle:=OBJECT Get font style(*;$atHeadNames{$x})
>               TEXT TO ARRAY($tLabel;$atLines;$lWidth;$tFont;$lSize;$lStyle)
>               
>               $tLabel:=""
>               For ($y;1;Size of array($atLines))
>                       $tLabel:=$tLabel+$atLines{$y}+Choose($y<Size of 
> array($atLines);"\r";"")
>               End for 
>               OBJECT SET TITLE(*;$atHeadNames{$x};$tLabel)
>               
>               $lMaxLines:=Choose(Size of 
> array($atLines)<=$lMaxLines;$lMaxLines;Size of array($atLines))
>               
>       End if 
> End for 
> 
>   //Change the listbox header height if it needs to be different than it is
> If (LISTBOX Get headers height($pLB->;lk lines)#$lMaxLines)
>       LISTBOX SET HEADERS HEIGHT($pLB->;$lMaxLines;lk lines)
> End if 
> 
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[email protected]
> **********************************************************************
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to