TweetFollow Us on Twitter

List of Controls
Volume Number:5
Issue Number:6
Column Tag:Advanced Mac'ing

Related Info: List Manager Control Manager

List of Controls LDEF

By James Plamondon, Berkeley, CA

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

List-Of-Controls LDEF

Introduction

I recently needed to implement a list, in which each cell would be an active control. It turned out to be a little harder to do than I thought it would be. To save others the trouble, I thought I’d describe how I made it all work.

Overview

I use Apple’s List Manager to manipulate my list of controls. Each element of the list contains a ControlHandle to a PopUp-Menu control. Whenever a mouseDown event occurs in the list, I find out if it is one of the controls, and if so, call TrackControl() (IM v1 p323) to deal with it. If the mouseDown is in the list, but not in an active part of the control, I pass the event off to LClick() (IM v4 p273), so the Apple List Manager can handle it.

Whenever the user selects or unselects a list element, or brings a new control into view by scrolling the list, the List Manager will send a message to the list’s LDEF telling it to draw or hilite the list element. My LDEF will then set the control’s hilite state as needed to assure that it is drawn properly, and then call Draw1Control() (IM v4 p53) to do the actual drawing.

A routine called FixCtlRects() is called in the test program whenever a control may have changed position in the list’s display, to make sure that its controlRect field matches its list rectangle, and that it won’t be drawn if it is out of the list’s display area.

The example program uses the PopUp-Menu control described in MacTutor, September 1988, PopUp-Menu Control CDEF. I could have used a different CDEF, but I would have had to include the CDEF’s source code, and I didn’t want to make this article any longer than necessary.

LDEFs

LDEFs are described on pages 278-277 of Inside Mac, Volume Four, in the List Manager chapter (pages 259-282). The ‘LDEF’ associated with a list is loaded into memory when the list is created. Like other _DEFs (MDEFs, CDEFs, etc.), the code resource has a single entry point at its first byte (i.e., it has no jump table). The entry point must be a procedure with the following definition:

PROCEDURE MyLDEF(
 lMessage: INTEGER;
 lSelect: Boolean;
 lRect: Rect;
 lCell: Cell;
 lDataOffset,
 lDataLen: INTEGER;
 lHandle: ListHandle);

The function and argument names may be changed, of course, but their order and type must be as shown here (from IM v4 p276).

When a new list is created using the LNew() function (IM v4 p270), one of the parameters you must give to LNew() is the resource ID of the LDEF you want the list to use. Apple’s default LDEF has a resource ID of 0. Our LDEF has a resource ID of RES_ID (128). When we create the new list, the List Manager will load the specified LDEF, and store a handle to it in the listDefProc field of the resulting list record. Whenever a cell of the list needs to be drawn or hilited, the List Manager will send a message to the LDEF, and the LDEF will do the work.

LDEF Messages

An LDEF message is just a procedure call to the LDEF’s MyLDEF() routine, with lMessage (an integer) equal to a meaningful value. If the List Manager wants the LDEF to draw a cell, it calls MyLDEF() with lMessage equal to lDrawMsg (1). If the cell is to be hilited, MyLDEF() is called with lMessage equal to lHiliteMsg (2). MyLDEF() contains a CASE statement, keyed to the lMessage parameter’s value. If lMessage equals lDrawMsg, the routine doDrawMsg() is called. If lMessage equals lHiliteMsg, doHiliteMsg() is called. That’s all there is to LDEF message passing.

There are four different messages an LDEF may receive. Two of them, lDrawMsg and lHiliteMsg, must be handled by all LDEFs.

When the LDEF gets a lDrawMsg message, it needs to draw the given list cell. If the list cell is selected (ie., if lSelect is TRUE), then you need to hilite the cell, to tell the user that it’s been selected. The LDEF used in this article simply calls Draw1Control() to draw the control stored in the given cell. First it has to diddle with the control’s rectangle, though, as we’ll see later.

The lHiliteMsg message is sent to the LDEF when a previously drawn cell needs to be hilited or unhilited. In most cases, this is done by simply inverting the cell’s rectangle. Our LDEF has to get a little fancier.

The other two LDEF messages, lInitMsg and lCloseMsg, need only be implemented by the LDEF if each list handled by the LDEF needs to be initialized in some way, and then have its initialization voided when the list is disposed of. In this LDEF, however, no such initialization or deinitialization need be done, so it does nothing when it receives those messages.

List Hilighting

We need to be able to draw the control in such a way as to make it look selected in the list. The mechanism for inverting the control’s title already exists in the CDEF, so we’ll use that to indicate that the control is selected in the list.

The careful readers of the PopUp-Menu CDEF article and code may have noticed that a partCode was defined for the title of the pop-up menu (titlePart = 2), but that this partCode was never returned by doTestCntl(). The part code exists solely for this article. By setting the contrlHilite field of the control to be drawn to titlePart before calling Draw1Control(), we can guarantee that the control will have its title hilighted when it is drawn.

The Example Program

The example program is a very stripped Mac application. It simply initializes all of the usual managers, throws up a dialog, and cycles through ModalDialog() (IM v1 p415) until the user selects the dialog’s OK button. Most of the work of handling the list and the controls it contains is done by the filterProc MyFilter() -- the address of which is passed to ModalDialog() in the main program -- and its helper functions, doMouseDown() and doKeyDown().

After the user clicks the OK button, the program exits the ModalDialog() loop, disposes of the controls, list, and dialog, and quits. The final values of the controls are not accessed, because I’m not actually doing anything with them. In a real program you’d get the final values out of the controls, using GetCtlMax() and GetCtlMin() as described in PopUp-Menu Control CDEF.

Using the List-Of-Controls LDEF

The LDEF expects to find a control handle in each of its cells. We have to put these handles there ourselves. First we need to create the list itself, which we do with a call to LNew() in the routine InitList(). The only interesting part of this call is the use of RES_ID (128, the resource ID of our LDEF), rather than zero (0), Apple’s default LDEF.

Next, we need to create the controls we wish to add to the list. This is accomplished with calls to NewControl() (IM v1 p319), in the routine ReadData(). I read the resource ID’s of the controls I need from the ‘INT#’’ resource I’ve placed in the resource fork, and then read in the associated ‘CNTL’ resources.

I give the control a rectangle that is out of sight. It gets drawn despite my saying that I want it to be invisible (very irritating), so I just hide it, so that it can’t be seen until I want it to be seen.

After getting a control handle from NewControl(), the control is made visible (but not drawn) by placing TRUE (255) in its contrlVis field. ShowControl() (IM v1 p322) would try to draw the control, but that’s a waste of time, because the window is still invisible.

Finally, the control handle is placed in a new cell in the list. From there, we can extract it, and pass it along to Draw1Control() and TrackControl() as necessary.

Problems

At first I thought that I could just update a control’s rectangle whenever the cell it was in received an lDrawMsg or an lHiliteMsg. But that alone won’t work, because the List Manager uses ScrollRect() (IM v1 p187) to scroll the bits inside the list’s rectangle, and only redraws cells as they come into view. This means that after the initial drawing of the list, the only place in which cells are redrawn is in the top cell frame or in the bottom cell frame. If you modify the control rectangle to match the cell rectangle only when the cell is redrawn, then sooner or later, all of the controls are going to have either the top or bottom cell frame as their rectangles. It may look like there are controls in the middle of the list, but those are just scrolled bit-images; the controls will think they are in the top and bottom frames.

So, when you click in a control in the middle of the list, the control does not respond because it’s not really there. The thing you thought was a control was just a picture of a control. The control is in either the top or bottom cell frame (depending on where it was drawn last). If you click in the top or bottom cell frame, you’ll click in a control, all right, but not necessarily the one you see there. Your click will get picked up by the first control in the window’s control list (not the List Manager list) that was recently redrawn in that frame. Argh!

Here comes the kludge. The only way the user can move the controls on the list is with the list’s scroll bar. Therefore, whenever we receive a mouseDown event in the list that is not in one of our controls, we have to call FixCtlRects(). FixCtlRects() just walks through the list, getting each cell’s rectangle and setting the rectangle of the control in the cell to match. If the cell is invisible, then control is made invisible, and vice versa. This doesn’t take too long for a short list, but if you had a couple of hundred controls, it would be noticeably slow.

We also have to call FixCtlRects() after reading in the controls the first time, to make sure they’re displayed properly.

It’s a kludge, but it works, so what the hey.

Miscellaneous Notes

There are few other things about the LDEF, the pop-up menu CDEF, and its example program that are worth mentioning.

Note that I pass POINTER(-1) to TrackControl() in doMouseDown(). This enables the pop-up menu’s CDEF’s autoTrack function. This is the function that pops up the PopUp-Menu via PopUpMenuSelect() (IM v5 p241), as described in detail in PopUp-Menu Control CDEF.

CenterWindow() just centers a window in the screen, about two-thirds of the way up.

Acknowledgements

I started this project in order to do something we needed to do at work, but it kind of took on a life of its own when I realized that there was an article in it. I’d like to thank the guys at Abacus -- Dan, Jim, and Will -- for letting me spend the time I did on this. It won’t happen again for another week or two, anyway.

Listing:  Test.make

#Test.make
#
#
 
Test    ƒƒTest.r ControlLDEF.LDEF PopMenuCDEF.CDEF
 Rez -rd Test.r -o Test

Test    ƒƒTest.p.o 
 ControlLDEF.LDEF
 PopMenuCDEF.CDEF
 Test.r 
 Link   
 Test.p.o 
 “{Libraries}”Runtime.o   
 “{Libraries}”Interface.o 
 “{PLibraries}”PasLib.o   
 -o Test

ControlLDEF.LDEF ƒƒ ControlLDEF.p.o
 Link -sg ControlLDEF     
  -rt LDEF=1     
  -m MYLDEF ControlLDEF.p.o 
 “{Libraries}”Interface.o 
 -o ControlLDEF.LDEF

PopMenuCDEF.CDEF ƒƒ PopMenuCDEF.p.o
 Link -sg PopMenuCDEF     
  -rt CDEF=1     
  -m MYCONTROL PopMenuCDEF.p.o
 “{Libraries}”Interface.o 
 “{PLibraries}”PasLib.o   
 -o PopMenuCDEF.CDEF

PopMenuCDEF.p.o  ƒ PopMenuCDEF.p PopMenuIntf.p
 Pascal PopMenuCDEF.p -o PopMenuCDEF.p.o

Test.p.oƒ Test.p
 Pascal Test.p -o Test.p.o

ControlLDEF.p.o  ƒ ControlLDEF.p PopMenuIntf.p
 Pascal ControlLDEF.p -o ControlLDEF.p.o

# END OF FILE: Test.make
Listing: ControlLDEF.P

(*****************************************************
ControlLDEF.p:  List Definition Function for list of controls.
*****************************************************)

UNIT ControlLDEF;

INTERFACE
USES
 {$U MemTypes.p  } MemTypes,
 {$U QuickDraw.p   } QuickDraw,
 {$U OSIntf.p      } OSIntf,
 {$U ToolIntf.p    } ToolIntf,
 {$U PackIntf.p    } PackIntf,
 {$U PopMenuIntf.p } PopMenuIntf;

PROCEDURE MyLDEF(lMessage: INTEGER;lSelect: Boolean;
 lRect: Rect;lCell: Cell;lDataOffset,lDataLen: INTEGER;
 lHandle: ListHandle);

IMPLEMENTATION
CONST
 isVIS  = 255;
 notVIS = 0;
 
TYPE
 StateStuff = record
 oldPen:PenState;
 oldPort: GrafPtr;
 oldClip: RgnHandle;
 newClip: RgnHandle;
 end;  { StateStuff }

PROCEDURE DrawCell(lSelect: Boolean;lRect: Rect;
 lCell: Cell;lHandle: ListHandle);FORWARD;
 
(*****************************************************
MyLDEF:  List Definition Function for Controls list.
 Responds to LDrawMsg and lHiliteMsg; ignores
 lInitMsg and lCloseMsg.
*****************************************************)

PROCEDURE MyLDEF(lMessage: INTEGER;lSelect: Boolean;
 lRect: Rect;lCell: Cell;lDataOffset,lDataLen: INTEGER;
 lHandle: ListHandle);
BEGIN
 CASE lMessage OF
 lInitMsg:
 ; { no initialization needed }
 lCloseMsg:
 ; { no deallocation needed }
 
 lDrawMsg, lHiliteMsg:
 DrawCell(lSelect, lRect, lCell, lHandle);
 END;  { case }
END;  { MyLDEF }

(*****************************************************
SaveState:  Saves the current drawing environment.
*****************************************************)

PROCEDURE SaveState(VAR oldState:  StateStuff; 
 lRect:  Rect;lHandle: ListHandle);
BEGIN
 WITH oldState DO BEGIN
 { save the current pen state }
 GetPenState(oldPen);
 { save current grafPort, set new grafPort }
 GetPort(oldPort);
 SetPort(lHandle^^.port);
 { allocate space for old and new clipping regions }
 oldClip := NewRgn;
 newClip := NewRgn;
 { save old clipping region }
 GetClip(oldClip);
 { set newClip region to given rectangle }
 RectRgn(newClip, lRect);
 { intersection of rect and region }
 SectRgn(oldClip, newClip, newClip);
 { set grafPorts’ clip region to the intersection }
 SetClip(newClip);
 END;  { with }
END;  { SaveState }

(*****************************************************
RestoreState: Restores current drawing environment.
*****************************************************)

PROCEDURE RestoreState(oldState:  StateStuff);
BEGIN
 WITH oldState DO BEGIN
 { restore the previous clipping region }
 SetClip(oldClip);
 { restore the previous pen state }
 SetPenState(oldPen);
 { restore the previous grafPort }
 SetPort(oldPort);
 { dispose of the regions’ storage }
 DisposeRgn(oldClip);
 DisposeRgn(newClip);
 END;  { with }
END;  { RestoreState }

(*****************************************************
DrawCell:  Draws the given cell, either selected or
 normal, by drawing the control stored in the cell.
*****************************************************)

PROCEDURE DrawCell(lSelect: Boolean;lRect: Rect;
 lCell: Cell;lHandle: ListHandle);
VAR
 oldState:StateStuff;
 ch:    ControlHandle;
 dl:    INTEGER;

BEGIN
 { save the current drawing environment }
 SaveState(oldState, lRect, lHandle);
 
 { get the cell’s data }
 dl := sizeof(Handle);
 LGetCell(@ch, dl, lCell, lHandle);
 
 { update the control’s fields }
 with ch^^ do begin
 contrlRect := lRect;
 contrlVis:= isVIS;
 
 { ensure proper hiliting }
 if (lSelect) then
 contrlHilite := titlePart
 else begin
 contrlHilite := 0;
 end;  { if }
 end;  { with ch^^ }
 
 { draw the control }
 Draw1Control(ch);

 { restore the previous drawing state }
 RestoreState(oldState);
END;  { DrawCell }

END.  { ControlLDEF}
Listing:  Test.p

(*****************************************************
Test.p
 List-of-Controls example, using pop-up menu controls.
*****************************************************)

PROGRAM Test;

USES
 {$U MemTypes.p    } MemTypes,
 {$U QuickDraw.p   } QuickDraw,
 {$U OSIntf.p      } OSIntf,
 {$U ToolIntf.p    } ToolIntf,
 {$U PackIntf.p    } PackIntf,
 {$U PopMenuIntf.p } PopMenuIntf;

CONST
 RES_ID =    128;{ resource ID’s }
 
 iOK    = 1;{ OK button }
 iLIST  = 2;{ list of controls}
 
 { visibility }
 isVIS  =    255;
 notVIS = 0;

TYPE
 { Pascal equivalent of ‘INT#’ resource type }
 IntList = record
 count: INTEGER;
 int:   array[1..1024] of INTEGER;
 end;  { IntList }
 
 ILPointer = ^IntList;
 ILHandle = ^ILPointer;

VAR
 myDialog:DialogPtr; { test dialog }
 lh:    ListHandle;{ handle to list}
 itemHit: INTEGER; { user’s choice}
 savePort:GrafPtr; { to save port in}

(*****************************************************
CenterWindow:  Centers the given window in the screen.  If the ‘show’ 
argument is TRUE, then the window is shown.
*****************************************************)

PROCEDURE CenterWindow(wPtr: WindowPtr; show: Boolean);
VAR
 pRect: Rect;
 wRect: Rect;
 h, v:  INTEGER;
 
BEGIN
 pRect := screenBits.bounds;
 wRect := WindowPeek(wPtr)^.port.portRect;
 v := ((pRect.bottom - pRect.top) -
 (wRect.bottom - wRect.top)) div 3;
 h := ((pRect.right - pRect.left) -
 (wRect.right - wRect.left)) div 2;
 MoveWindow(wPtr, h, v, show);
 if (show) then begin
 ShowWindow(wPtr);
 end;
END;  { CenterWindow }

(*****************************************************
FixCtlRects:  Make the contrlRects of all controls in
 the list match their list rectangles, and that controls
 in invisible cells are also invisible.
*****************************************************)

PROCEDURE FixCtlRects(lh: ListHandle);
VAR
 ch:    ControlHandle;
 i:INTEGER;
 dl:    INTEGER;
 toRect:Rect;
 c:Cell;
 
BEGIN
 { default }
 dl := sizeof(Handle);
 { update the controls in the list }
 FOR i := 0 to (lh^^.dataBounds.bottom - 1) DO BEGIN
 { define cell to access }
 SetPt(Point(c), 0, i);
 { get the control handle from the cell }
 LGetCell(@ch, dl, c, lh);
 IF (PtInRect(Point(c), lh^^.visible)) THEN
 BEGIN
 { get cell rect; copy into control rect }
 LRect(toRect, c, lh);
 ch^^.contrlRect := toRect;
 { make sure the control is visible }
 ch^^.contrlVis := isVIS;
 END
 ELSE BEGIN
 { make sure the control is invisible }
 ch^^.contrlVis := notVIS;
 END;
 END;
END;  { FixCtlRects }

(*****************************************************
FindCell:  Find the cell in the given list containing
 the given point, which is assumed to be in local
 coördinates.  If the point is not in the list’s
 rectangle, the resulting cell will have both
 h and v set to (-1).
*****************************************************)

FUNCTION FindCell(p: Point; lh: ListHandle): Cell;
VAR
 c:   Cell;

BEGIN
 with lh^^ do begin
 if (not PtInRect(p, rView)) then
 SetPt(Point(c), -1, -1)
 else with rView.topLeft do begin
 c.h := ((p.h - h) DIV cellSize.h) + visible.left;
 c.v := ((p.v - v) DIV cellSize.v) + visible.top;
 end;  { else, with rView.topLeft }
 end;  { with lh^^ }
 FindCell := c;
END;  { FindCell }

(*****************************************************
doKeyDown:  Filters all keyDown events in the modal
 dialog, implementing the standard keyboard
 equivalents for the OK button.
*****************************************************)
FUNCTION doKeyDown(dPtr: DialogPtr; VAR theEvent:  EventRecord; VAR itemHit: 
INTEGER): Boolean;
VAR
 c:LONGINT;
BEGIN
 { default }
 doKeyDown := FALSE;
 
 { get the ascii code }
 c := BitAnd(theEvent.message, charCodeMask);
 
 { check for Return or Enter }
 IF ((c = 3) or ( c = 13)) THEN BEGIN
 itemHit := iOK;
 doKeyDown := TRUE;
 END;  { if }
END;  { doKeyDown }

(*****************************************************
doMouseDown
*****************************************************)
FUNCTION doMouseDown(dPtr: DialogPtr; VAR theEvent:  EventRecord; VAR 
itemHit: INTEGER): Boolean;
VAR
 item:  INTEGER;
 part:  INTEGER;
 pt:    Point;
 c:Cell;
 ch:    ControlHandle;
 dbl:   Boolean;
 sel:   Boolean;
BEGIN
 pt := theEvent.where;
 GlobalToLocal(pt);
 
 { See Tech Note #112, FindDItem() }
 item := FindDItem(dPtr, pt) + 1;
 
 IF (item = iLIST) THEN
 BEGIN
 { in whom did the mouseDown occur? }
 part := FindControl(pt, dPtr, ch);
 
 IF ((ch = nil) or (ch = lh^^.vScroll)) THEN
 BEGIN
 { clicked in list or in scroll bar }
 dbl := LClick(pt,
 theEvent.modifiers,
 lh);
 
 { fix the controls’ contrlRects }
 FixCtlRects(lh);
 END
 ELSE BEGIN { clicked in pop-up menu }
 part := TrackControl(ch, pt, POINTER(-1));
 { what cell was the mouseDown in? }
 c := FindCell(pt, lh);
 { redraw the control if cell was selected }
 if (LGetSelect(false, c, lh)) then begin
 HiliteControl(ch, titlePart);
 end;  { if }
 END;  { else }
 doMouseDown := TRUE;
 END  { item = iLIST }
 ELSE BEGIN
 doMouseDown := FALSE;
 END;
END;  { doMouseDown }

(*****************************************************
doUpdateEvt
*****************************************************)
FUNCTION doUpdateEvt(dPtr: DialogPtr; VAR theEvent:  EventRecord; VAR 
itemHit: INTEGER): Boolean;
BEGIN
 { begin the update }
 BeginUpdate(dPtr);
 
 { update the dialog items }
 UpdtDialog(dPtr, dPtr^.visRgn);
 
 { update the list }
 LUpdate(dPtr^.visRgn, lh);
 
 { end the update } 
 EndUpdate(dPtr);
 
 { always return true (we handled it) }
 doUpdateEvt := TRUE;
END;  { doUpdateEvt }

(*****************************************************
MyFilter
*****************************************************)
FUNCTION MyFilter(dPtr: DialogPtr; VAR theEvent:  EventRecord; VAR itemHit: 
INTEGER): Boolean;
BEGIN
 CASE theEvent.what OF
 keyDown:
 MyFilter := doKeyDown(dPtr, theEvent,
 itemHit);
 mouseDown:
 MyFilter := doMouseDown(dPtr, theEvent, 
 itemHit);
 updateEvt:
 MyFilter := doUpdateEvt(dPtr, theEvent, 
 itemHit);
 OTHERWISE
 MyFilter := FALSE;
 END;  { case }
END;  { MyFilter }

(*****************************************************
DrawUserItems
*****************************************************)
PROCEDURE DrawUserItems(wPtr: WindowPtr;itemNo: INTEGER);
VAR
 savePen: PenState;
 ik:    INTEGER;
 ih:    Handle;
 ib:    Rect;
BEGIN { DrawUserItems }
 { save, naormalize the pen state }
 GetPenState(savePen);
 PenNormal;
 
 { frame the list }
 GetDItem(wPtr, iLIST, ik, ih, ib);
 FrameRect(ib);
 
 { frame the default button }
 GetDItem(wPtr, iOK, ik, ih, ib);
 InsetRect(ib, -4, -4);
 PenSize(3, 3);
 FrameRoundRect(ib, 16, 16);
 
 { restore the pen’s state }
 SetPenState(savePen);
END;  { DrawUserItems }

(*****************************************************
ReadData: Reads in a number of controls, as specified
 by a ‘INT#’ integer-array resource.  Defines new
 controls for each.
*****************************************************)
FUNCTION ReadData(dPtr: DialogPtr): Boolean;
VAR
 ch:    ControlHandle;
 iah:   ILHandle;
 i:INTEGER;
 n:INTEGER;
 ignore:INTEGER;
 aCell: Cell;
 p:Point;
 aRect: Rect;
BEGIN { ReadData }
 { get handle to ‘INT#’ resource }
 iah := ILHandle(GetResource(‘INT#’, RES_ID));
 
 IF (iah <> nil) THEN BEGIN
 { disable list drawing }
 LDoDraw(false, lh);
 
 FOR i := 1 TO iah^^.count DO BEGIN
 { create a new control  }
 ch := GetNewControl(iah^^.int[i], dPtr);
 
 IF (ch = nil) THEN LEAVE;
 
 { make the control visible, without drawing }
 ch^^.contrlVis := 255;
 
 ignore := LAddRow(1, 32767, lh);
 SetPt(Point(aCell), 0, i - 1);
 LSetCell(@ch, sizeof(Handle), aCell, lh);
 END;  { for }
 
 { fix the controls’ contrlRects }
 FixCtlRects(lh);
 
 { select first control }
 SetPt(Point(aCell), 0, 0);
 LSetSelect(true, aCell, lh);
 
 { enable list drawing }
 LDoDraw(true, lh);
 END;  { iah <> nil }
 
 { return TRUE if controls were read OK }
 ReadData := (iah <> nil);
END;  { ReadData }

(*****************************************************
InitList:  Define and allocate new list, into which
 will be placed a number of control handles.
 (See ReadData(), above.)
*****************************************************)
PROCEDURE InitList(dPtr: DialogPtr);
VAR
 ik:    INTEGER;
 ih:    Handle;
 ib:    Rect;
 dBounds: Rect;
 cSize: Point;
BEGIN
 { set up the userItem drawing routine }
 GetDItem(dPtr, iLIST, ik, ih, ib);
 SetDItem(dPtr, iLIST, ik, Handle(@DrawUserItems), ib);
 
 { inset rect, for drawing; leave room for scroll bar }
 InsetRect(ib, 1, 1);
 ib.right := ib.right - 15;
 
 { allocate space for a single column, no rows }
 SetRect(dBounds, 0, 0, 1, 0);
 
 { indicate cell size }
 SetPt(cSize, ib.right-ib.left, 20);
 
 { create the list }
 lh := LNew(ib,  { rView  }
 dBounds, { dataBounds  }
 cSize, { cell size}
 RES_ID,   { resource ID  }
 dPtr,    { this window }
 false, { draw it}
 false, { grow box }
 false, { sBar, horiz}
 true); { sBar, vert }
END;  { InitList }

(*****************************************************
CleanUp:  My name is CleanUp().  You killed my dialog.
 Prepare to die!
*****************************************************)
PROCEDURE CleanUp(dPtr: DialogPtr);
VAR
 ch:    ControlHandle;
 i:INTEGER;
 dl:    INTEGER;
 c:Cell;
BEGIN
 { default }
 dl := sizeof(Handle);
 
 { indicate wait }
 SetCursor(GetCursor(watchCursor)^^);
 
 { deallocate the controls from the list }
 FOR i := 0 to (lh^^.dataBounds.bottom - 1) DO BEGIN
 SetPt(Point(c), 0, i);
 LGetCell(@ch, dl, c, lh);
 DisposeControl(ch);
 END;  { for }
 
 { dispose of the list }
 LDispose(lh);
 { dispose of the dialog }
 DisposDialog(dPtr);
END;  { CleanUp }

(*****************************************************
Main
*****************************************************)
BEGIN
 { perform the ritual incantation }
 InitGraf(@thePort); 
 InitFonts; 
 FlushEvents(everyEvent, 0);
 InitWindows;    
 InitMenus; 
 TEInit;
 InitDialogs(NIL); 
 InitCursor;

 { read in the dialog from its resource template }
 myDialog := GetNewDialog(RES_ID, NIL, POINTER(-1));
 
 { create and init the list of controls }
 InitList(myDialog);
 
 IF (ReadData(myDialog)) THEN BEGIN
 { center and show the dialog }
 CenterWindow(myDialog, true);
 
 { save grafPort, make ours current }
 GetPort(savePort);
 SetPort(myDialog);
 
 { cycle through ModalDialog() }
 REPEAT
 ModalDialog(@MyFilter, itemHit);
 UNTIL itemHit = iOK;
 
 { restore grafPort }
 SetPort(savePort);
 END;
 { dispose of the dialog’s storage }
 CleanUp(myDialog);
END.  { FILE Test.p, PROGRAM Test.p }
Listing:  Test.r

/*****************************************************
Test.r
 Resources for List-Of-Controls example.
*****************************************************/
/***********************Types***********************/
#include “Types.r”
#include “PopMenuCDEF.r”

type ‘INT#’ {
 integer = $$Countof(IntegerArray);
 
 array IntegerArray {
 integer;
 };
};
/**********************Defines**********************/
#define RES_ID   128
/*********************Resources********************/
data ‘LDEF’ (RES_ID, “ControlLDEF”) {
 $$resource(“ControlLDEF.LDEF”, ‘LDEF’, 1)
};
data ‘CDEF’ (pmCDEFResID, “popMenus”) {
 $$resource(“PopMenuCDEF.CDEF”, ‘CDEF’, 1)
};
resource ‘DLOG’ (RES_ID, “RES_ID”) {
 {54, 170, 254, 470},
 dBoxProc,
 invisible,
 noGoAway,
 0x0,
 RES_ID,
 “”
};
resource ‘DITL’ (RES_ID, “RES_ID”) {
 { /* array DITLarray: 3 elements */
 /* [1] */
 {170, 125, 190, 185},
 Button {
 enabled,
 “OK”
 },
 /* [2] */
 {10, 10, 72, 290},
 UserItem {
 enabled
 },
 /* [3] */
 {82, 10, 160, 290},
 StaticText {
 disabled,
 “List of Controls LDEF example.  “
 “James Plamondon, Abacus Concepts, “
 “1984 Bonita Avenue, Berkeley, CA  “
 “94704.”
 }
 }
};
resource ‘INT#’ (RES_ID, “Control ID’s”) {
 { /* array INTArray: 5 elements */
 /* [1] */
 128,
 /* [2] */
 129,
 /* [3] */
 130,
 /* [4] */
 131,
 /* [5] */
 132
 }
};
resource ‘CNTL’ (128) {
 {0, 0, 0, 0},   /* rect:  contrlRect*/
 128,   /* value: menu rsrc ID   */
 invisible, /* vis:  standard */
 128,   /* max:  default menuID  */
 2,/* min:  default item #*/
 popMenuProc   /* ProcID:  3  */
 + mCheck,/* var: Check selection  */
 0,/* rfCon: for user’s use */
 “Thanks to: “   /* title: standard*/
};
resource ‘MENU’ (128) {
 128,
 textMenuProc,
 allEnabled,
 enabled,
 “Thanks To: “,
 { /* 11 items */
 “Mark Williams”,
 noIcon, noKey, noMark, plain;
 “Mark Bennet”,
 noIcon, noKey, appleChar, plain;
 “Joseph Daniel”,
 noIcon, noKey, noMark, plain;
 “Dr. Don Morrison”,
 noIcon, noKey, noMark, plain;
 “Andrew Stone”,
 noIcon, noKey, noMark, plain;
 “Eleanor Plamondon”,
 noIcon, noKey, noMark, plain;
 “Bruce Wampler”,
 noIcon, noKey, noMark, plain;
 “Patricia Guffey”,
 noIcon, noKey, noMark, plain;
 “Greta Shaw”,
 noIcon, noKey, noMark, plain;
 “Monty \”Montana-Unit\” Cole”,
 noIcon, noKey, noMark, plain;
 “Dr. Bernard Moret”,
 noIcon, noKey, noMark, plain
 }
};
resource ‘CNTL’ (129) {
 {0, 0, 0, 0},   /* rect:  contrlRect*/
 129,   /* value: rsrc ID */
 invisible, /* vis:  standard */
 129,   /* max: default  menuID  */
 2,/* min:  default item #*/
 popMenuProc   /* ProcID: 3 */
 + mRes /* var: add res names */
 + mCheck,/* var: Check selection  */
 ‘FONT’,/* rfCon: OSType  */
 “Fonts: “/* title: standard*/
};
resource ‘MENU’ (129) {
 129,
 textMenuProc,
 allEnabled,
 enabled,
 “Fonts:        “,
 { /* 0 items */
 }
};
resource ‘CNTL’ (130) {
 {0, 0, 0, 0},   /* rect:  contrlRect*/
 130,   /* value: rsrc ID */
 invisible, /* vis:  standard */
 133,   /* max:  default menuID  */
 1,/* min: default  item #*/
 popMenuProc/* ProcID: 3  */
 + mCheck /* var: Check selection  */
 + mSub,/* var: sub-menus */
 0,/* rfCon: for user’s use */
 “SubMenu: “/* title: standard*/
};
resource ‘MENU’ (130) {
 130,
 textMenuProc,
 allEnabled,
 enabled,
 “Root:          “,
 { /* 2 items */
 “Root Item1”,
 noIcon, parent, “\0D131”, plain;
 “Root Item2”,
 noIcon, parent, “\0D132”, plain
 }
};
resource ‘MENU’ (131) {
 131,
 textMenuProc,
 allEnabled,
 enabled,
 “”,
 { /* 2 items */
 “Sub-1 Item1”,
 noIcon, noKey, noMark, plain;
 “Sub-1 Item2”,
 noIcon, noKey, noMark, plain;
 “Sub-1 Item3”,
 noIcon, parent, “\0D133”, plain
 }
};
resource ‘MENU’ (132) {
 132,
 textMenuProc,
 allEnabled,
 enabled,
 “”,
 { /* 2 items */
 “Sub-2 Item1”,
 noIcon, noKey, noMark, plain;
 “Sub-2 Item2”,
 noIcon, noKey, noMark, plain;
 “Sub-2 Item3 (a very, very, very wide item)”,
 noIcon, noKey, noMark, plain
 }
};
resource ‘MENU’ (133) {
 133,
 textMenuProc,
 allEnabled,
 enabled,
 “”,
 { /* 2 items */
 “Sub-3 Item1”,
 noIcon, noKey, noMark, plain;
 “Sub-3 Item2”,
 noIcon, noKey, noMark, plain;
 “Sub-3 Item3”,
 noIcon, noKey, noMark, plain
 }
};
resource ‘CNTL’ (131) {
 {0, 0, 0, 0},   /* rect:  contrlRect*/
 134,   /* value: menu rsrc ID   */
 invisible, /* vis:  standard */
 134,   /* max:  default menuID  */
 1,/* min:  default item #*/
 popMenuProc   /* ProcID:  3  */
 + mCheck,/* var: Check selection  */
 0,/* rfCon: for user’s use */
 “At Abacus: “   /* title: standard*/
};
resource ‘MENU’ (134) {
 134,
 textMenuProc,
 allEnabled,
 enabled,
 “At Abacus: “,
 { /* 5 items */
 “Dan Feldman”,
 noIcon, noKey, noMark, plain;
 “Jim Gagnon”,
 noIcon, noKey, noMark, plain;
 “Will Scoggin”,
 noIcon, noKey, noMark, plain;
 “James Plamondon”,
 noIcon, noKey, noMark, plain;
 “Jay Roth”,
 noIcon, noKey, noMark, plain;
 “Tiffiny Fyans”,
 noIcon, noKey, noMark, plain;
 “Jeanette Stafford”,
 noIcon, noKey, noMark, plain
 }
};
resource ‘CNTL’ (132) {
 {0, 0, 0, 0},   /* rect:  contrlRect*/
 135,   /* value: menu rsrc ID   */
 invisible, /* vis:  standard */
 135,   /* max:  default menuID  */
 1,/* min:  default item #*/
 popMenuProc   /* ProcID:  3  */
 + mCheck,/* var: Check selection  */
 0,/* rfCon: for user’s use */
 “Programs: “    /* title: standard*/
};
\resource ‘MENU’ (135) {
 135,
 textMenuProc,
 allEnabled,
 enabled,
 “Programs: “,
 { /* 5 items */
 “StatView”,
 noIcon, noKey, noMark, plain;
 “StatView 512+”,
 noIcon, noKey, noMark, plain;
 “StatView SE+Graphics”,
 noIcon, noKey, noMark, plain;
 “StatView II”,
 noIcon, noKey, noMark, plain;
 “SuperANOVA”,
 noIcon, noKey, noMark, plain
 }
};

 
AAPL
$108.00
Apple Inc.
+1.02
MSFT
$46.95
Microsoft Corpora
+0.90
GOOG
$559.08
Google Inc.
+8.77

MacTech Search:
Community Search:

Software Updates via MacUpdate

Vitamin-R 2.20b1 - Personal productivity...
Vitamin-R creates the optimal conditions for your brain to work at its best by structuring your work into short bursts of distraction-free, highly focused activity alternating with opportunities for... Read more
Dropbox 2.10.44 - Cloud synchronization...
Dropbox is an application that creates a special Finder folder that automatically syncs online and between your computers. It allows you to both backup files and keep them up-to-date between systems... Read more
Sandvox 2.9.2 - Easily build eye-catchin...
Sandvox is for Mac users who want to create a professional looking website quickly and easily. With Sandvox, you don't need to be a Web genius to build a stylish, feature-rich, standards-compliant... Read more
Cocktail 8.0.1 - General maintenance and...
Cocktail is a general purpose utility for OS X that lets you clean, repair and optimize your Mac. It is a powerful digital toolset that helps hundreds of thousands of Mac users around the world get... Read more
LibreOffice 4.3.3.2 - Free Open Source o...
LibreOffice is an office suite (word processor, spreadsheet, presentations, drawing tool) compatible with other major office suites. The Document Foundation is coordinating development and... Read more
VMware Fusion 7.0.1 - Run Windows apps a...
VMware Fusion allows you to create a Virtual Machine on your Mac and run Windows (including Windows 8.1) and Windows software on your Mac. Run your favorite Windows applications alongside Mac... Read more
OneNote 15.3.2 - Free digital notebook f...
OneNote is your very own digital notebook. With OneNote, you can capture that flash of genius, that moment of inspiration, or that list of errands that's too important to forget. Whether you're at... Read more
Audio Hijack Pro 2.11.4 - Record and enh...
Audio Hijack Pro drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio with Audio Hijack... Read more
Iridient Developer 3.0.0 beta 3 - Powerf...
Iridient Developer (was RAW Developer) is a powerful image conversion application designed specifically for OS X. Iridient Developer gives advanced photographers total control over every aspect of... Read more
TextWrangler 4.5.11 - Free general purpo...
TextWrangler is the powerful general purpose text editor, and Unix and server administrator's tool. Oh, and also, like the best things in life, it's free. TextWrangler is the "little brother" to... Read more

Latest Forum Discussions

See All

Monster Flash Review
Monster Flash Review By Jordan Minor on October 31st, 2014 Our Rating: :: ALONE IN THE DARKUniversal App - Designed for iPhone and iPad Solid shooting and a surprising amount of spooky tension make Monster Flash a great portable... | Read more »
Retry Review
Retry Review By Rob Thomas on October 31st, 2014 Our Rating: :: SOARING HIGHUniversal App - Designed for iPhone and iPad Flappy who? Let Retry wash all those bad bird-related memories away on a cool retro-flavored flight… right... | Read more »
Dementia: Book of the Dead Review
Dementia: Book of the Dead Review By Lee Hamlet on October 31st, 2014 Our Rating: :: A TOUGH READUniversal App - Designed for iPhone and iPad A witch hunter is sent after a demonic book in the spooky but short-lived Dementia: Book... | Read more »
Card Dungeon, the Semi-Board Game Roguel...
Card Dungeon, the Semi-Board Game Roguelike, Has Been Renovated Posted by Jessica Fisher on October 31st, 2014 [ permalink ] | Read more »
Logitech Protection + Power iPhone5/5S C...
Made by: Logitech Price: $99.99 Hardware/iOS Integration Rating: 3 out of 5 stars Usability Rating: 0.5 out of 5 stars Reuse Value Rating: 0.75 out of 5 stars Build Quality Rating: 0.75 out of 5 stars Overall Rating: 1.25 out of 5 stars | Read more »
This Is Not a Test Goes Free, Permanentl...
This Is Not a Test Goes Free, Permanently Posted by Jessica Fisher on October 31st, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Swap Heroes Review
Swap Heroes Review By Campbell Bird on October 31st, 2014 Our Rating: :: STRATEGIC SWAPPINGUniversal App - Designed for iPhone and iPad Rotate a cast of heroes to fend of waves of monsters in this difficult, puzzle rpg.   | Read more »
Night Sky Pro™ (Reference)
Night Sky Pro™ 3.0.1 Device: iOS Universal Category: Reference Price: $2.99, Version: 3.0.1 (iTunes) Description: Night Sky Pro™Wonder No More™ Night Sky Pro™ is the ultimate stargazing experience. From the creators of the original... | Read more »
Audio Defence : Zombie Arena (Games)
Audio Defence : Zombie Arena 1.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0 (iTunes) Description: A zombie shooter audio game. Made from gut-wrenching 3D binaural sound, for a new kind of weird immersion. You... | Read more »
RPG Asdivine Hearts (Games)
RPG Asdivine Hearts 1.1.0 Device: iOS Universal Category: Games Price: $3.99, Version: 1.1.0 (iTunes) Description: SPECIAL PRICE50% OFF (USD 7.99 -> USD 3.99)!!! Travel alongside four companions and a cat in the adventure of a... | Read more »

Price Scanner via MacPrices.net

Apple now offering refurbished 2014 13-inch R...
The Apple Store is now offering Apple Certified Refurbished 2014 13″ Retina MacBook Pros for up to $270 off the cost of new models. An Apple one-year warranty is included with each model, and... Read more
Apple Regains Momentum As Windows Stutters An...
The latest smartphone sales data from Kantar Worldpanel ComTech, for the three months to March 2014, shows Apple performing strongly in the first quarter of the year, with sales bouncing back in... Read more
Worldwide Smartphone Shipments Increase 25.2%...
New smartphone releases and an increased emphasis on emerging markets drove global smartphone shipments above 300 million units for the second consecutive quarter, according to preliminary data from... Read more
Apple now offering refurbished 2014 15-inch M...
The Apple Store is now offering Apple Certified Refurbished 2014 15″ Retina MacBook Pros for up to $400 off the cost of new models. An Apple one-year warranty is included with each model, and... Read more
Apple drops prices on refurbished 2013 Retina...
The Apple Store has dropped prices on 2013 Apple Certified Refurbished 13″ and 15″ Retina MacBook Pros, with Retina models now available starting at $999. Apple’s one-year warranty is standard, and... Read more
New 2.8GHz Mac mini on sale for $949, save $5...
Abt Electronics has the new 2.8GHz Mac mini in stock and on sale for $949.05 including free shipping. Their price is $50 off MSRP, and it’s the lowest price available for this model from any reseller... Read more
Sale! 3.7GHz Quad Core Mac Pro available for...
 B&H Photo has the 3.7GHz Quad Core Mac Pro on sale for $2649 including free shipping plus NY sales tax only. Their price is $350 off MSRP, and it’s the lowest price for this model from any... Read more
Mujjo Steps Up The Game With Refined Touchscr...
Netherlands based Mujjo have just launched their Refined Touchscreen Gloves, stepping up their game. The gloves feature a updated elegant design that takes these knitted gloves to the next level. A... Read more
Sale! Preorder the new 27-inch 5K iMac for $2...
 Abt Electronics has the new 27″ 3.5GHz 5K iMac on sale and available for preorder for $2374.05 including free shipping. Their price is $125 off MSRP, and it’s the lowest price available for this... Read more
Simplex Solutions Inc. Brings Secure Web Surf...
New York based Simplex Solutions Inc. has announced the release and immediate availability of Private Browser 1.0, its revolutionary new secure web browser developed for iPhone, iPad and iPod touch... Read more

Jobs Board

Solutions Specialist with *Apple* Knowledge...
Company Description: We are an Apple Authorized Sales and Service Provider. We have been selling and servicing Apple computers in the Fairfield County area for over Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** Every day, business customers come to the Apple Store to discover what powerful, easy-to-use Apple products can do for them. As a Business Leader, Read more
Sr. Manager, *Apple* Deployment Programs fo...
**Job Summary** Apple is seeking candidates for a new position on the Education Content and Technology team. iPad and Mac is in the hands of millions of teachers and Read more
*Apple* Solutions Consultant (ASC) - Apple I...
…important role that the ASC serves is that of providing an excellent Apple Customer Experience. Responsibilities include: * Promoting Apple products and solutions Read more
*Apple* Solutions Consultant (ASC) - Apple I...
…important role that the ASC serves is that of providing an excellent Apple Customer Experience. Responsibilities include: * Promoting Apple products and solutions Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.