Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!intercon!amanda@mermaid.intercon.com From: amanda@mermaid.intercon.com (Amanda Walker) Newsgroups: comp.sys.mac.programmer Subject: Re: List Bummers Revisited Message-ID: <1622@intercon.com> Date: 13 Dec 89 16:28:00 GMT References: Sender: news@intercon.com Reply-To: amanda@mermaid.intercon.com (Amanda Walker) Lines: 79 In article , es2q+@andrew.cmu.edu (Erik Warren Selberg) writes: > Is there any way to access > variables in the main program from an LDEF, and if so, how??! Well, they way I do it is to have a baby LDEF that, by default, just draws a string they way LDEF 0 does, but if the list's refCon is non-zero, treats it as a pointer to a function and calls it to do the drawing. All you have to do is make sure A5 is set correctly. Here's the source for the LDEF in MPW C 3.0, taken in its entirety from known working code. It does contain "the cast from Hell," but hey :-). ---------------------- /* Simple Custom LDEF Amanda Walker, InterCon Corporation 6 October 1988 This is a very simple custom LDEF. It acts just like LDEF 0 if the refCon field of the list is 0. If it is non-zero, the LDEF treats it as the address of a routine to call to actually draw a list element. */ #include #include #include #define nil ((void *) 0L) pascal void STUBLDEF(lMessage, lSelect, lRect, lCell, lDataOffset, lDataLen, lHandle) short lMessage; Boolean lSelect; Rect *lRect; Cell *lCell; short lDataOffset, lDataLen; ListHandle lHandle; { char *p; long savedA5; /* Make sure A5 is valid so the draw code can use its globals. */ savedA5 = SetCurrentA5(); p = (char *) 0x938; /* HiliteMode for color QD */ lMessage--; /* no initialization */ if (!lMessage--) { /* draw the cell */ if ((**lHandle).refCon) (*((pascal void (*)(Rect *, Cell *, short, short, ListHandle)) (**lHandle).refCon))(lRect, lCell, lDataOffset, lDataLen, lHandle); else { MoveTo(lRect->left + 5, lRect->top + 12); HLock((**lHandle).cells); DrawText(*((**lHandle).cells), lDataOffset, lDataLen); HUnlock((**lHandle).cells); } if (lSelect) { *p = *p & 0x7f; InvertRect(lRect); } } else if (!lMessage--) { /* toggle highlighting */ *p = *p & 0x7f; InvertRect(lRect); } SetA5(savedA5); /* no closing code */ } ---------------------- If you don't know how to build code resources with MPW C, take a look at the examples in the CExamples directory. Hope this helps, Amanda Walker InterCon Systems Corporation --