[futurebasic] Re: [FB] List boxes

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : July 2003 : Group Archive : Group : All Groups

From: Alain Pastor <apastor@...>
Date: Fri, 25 Jul 2003 21:40:04 +0200

Bernie Wylde wrote:
> Dear All,
> It appears we can create list boxes in a number of different ways. What 
> appears to be the simplest and most straightforward method (to me) is 
> described on page 44 of the manual where it recommends creating an 
> 'ldes' resource with Resorcerer 2.4 or a template in any resource 
> editor. As I'm not about to fork out $256.00 for Resorcerer, can anyone 
> get me started on creating a template in say ResEdit?
> Alternatively, there's a demo file on the CD, 'simple list in Carbon' 
> which eliminates the need for a resource editor. The problem I have with 
> this method is that a click on the list box doesn't generate a button 
> click event. So, do we instead have to detect mouse clicks and calculate 
> the selected cell from mouse position?
> Hope I've made this clear. Any help appreciated.


maybe that one can help:

'                       Runtime : Rntm Appearance.Incl
'                           CPU : Carbon
'                    CALL Req'd : Off

      With the Appearance Manager came a bazillion of new controls
      and among them we can find a control that display lists which
      can be easily built with the APPEARANCE BUTTON statement and
      the _kControlListBoxProc attribute.
      The caveat with that puppy is that no matter what you do
      to install a list after this, nothing happens unless you
      provide also a valid ldes resource to the procedure that
      creates the control in the first place.
      To solve the problem, therefore you need to add a ldes
      resource to your application resource file.
      Or you can use the trick below that allows you to build
      listbox controls on the fly.
      The program creates a simple temporary ldes resource to trick
      the Control Manager then the list can be inserted without
      problem. The temporary ldes resource is deleted after
      the installation of the list.
      by Alain Pastor
      with modifications by Robert P.     26 September 2001

#if ndef _appearanceRuntime
compile shutdown "Must be compiled as an Appearance project"

_listBtn = 10

begin record ldesRec
dim version       as short
dim rows          as short
dim column        as short
dim cellHeight    as short
dim cellWidth     as short
dim hasVertScroll as boolean
dim reserved1     as byte
dim hasHorzScroll as boolean
dim reserved2     as byte
dim resID         as short
dim hasSizeBox    as boolean
dim reserved3     as byte
end record

clear local mode
local fn GetldesResID( listRectPtr as .rect )
dim resH  as ..ldesRec
dim resID as short

SetResLoad( _false )
resH = fn GetResource( _"ldes", 128 )
long if resH
resID = 128 'ID reserved for resource based list control
resH = fn NewHandleClear( sizeof( ldesRec ) )
long if resH
resH..column        = 1
resH..hasVertScroll = 1
resH..cellWidth     = (listRectPtr.right - listRectPtr.left)
resH..cellHeight    = 1.4 * usr FontHeight
resID = fn Unique1ID(_"ldes")
until resID > 128
AddResource( resH, _"ldes", resID, "" )
long if fn ResError == _noErr
ReleaseResource( resH )
resID = 0
DisposeHandle( resH )
end if
end if
end if
SetResLoad( _true )
end fn = resID

clear local mode
local fn RemoveldesRes( listResID as short )
dim resH as handle

resH = fn GetResource( _"ldes", listResID )
long if resH
RmveResource( resH )
long if fn ResError = _noErr
DisposeHandle( resH )
end if
end if
end fn

local mode
local fn PutListInButton( list(_maxInt) as str255, btnID as long )
dim as short    i, nbItems
dim as point    theCell
dim as handle @ listH
dim as long   @ actualSize

nbItems = val&( list(0) ) '1st str in array = number of items
if nbItems == _nil then exit fn

def GetButtonData( btnID, _kControlListBoxPart, ¬
_kControlListBoxListHandleTag, sizeof(listH), listH, actualSize )

long if listH
LSetDrawingMode( _zTrue, listH )
LDelRow( 0, 1, listH )
theCell.h% = 0
for i = 1 to nbItems
theCell.v% = fn LAddRow( 1, i, listH )
LSetCell( @list(i)+1, |@list(i)|, theCell, listH )

end if

end fn

clear local fn BuildWnd
dim listResID       as short
dim r               as rect
dim stringArray(20) as str255

SetRect( r, 0, 0, 250, 130 )
window -1, "List Box", @r, _docNoGrow
def SetWindowBackground(_kThemeActiveDialogBackgroundBrush, _zTrue )
InsetRect(r, 8, 8 )
listResID = fn GetldesResID( r )
appearance button _listBtn, _activeBtn,listResID,0,0, ¬
                   "", @r,_kControlListBoxProc
if listResID > 128 then fn RemoveldesRes( listResID )

stringArray(0) = "9"//number of items
stringArray(1) = "One"
stringArray(2) = "Two"
stringArray(3) = "Three"
stringArray(4) = "Four"
stringArray(5) = "Five"
stringArray(6) = "Six"
stringArray(7) = "Seven"
stringArray(8) = "Height"
stringArray(9) = "Nine"

fn PutListInButton( stringArray(0), _listBtn )
window 1

end fn

local fn DoDialog
dim as long   evnt, id
evnt = dialog( 0 )
id   = dialog( evnt )

select evnt
case _wndClose
case _btnClick : beep
end select
end fn

on dialog fn DoDialog
menu 1, 0, 1, "File"
menu 1, 1, 1, "Quit/Q"
edit menu 2
fn BuildWnd
until _nil