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
 }
};

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.