[comp.sys.mac.programmer] clikLoop -- Unclear on the concept

audit038@spacm1.spac.spc.com (02/21/91)

In using my own clikLoop function with TE records I came up with the following
problem:

Window A has a TE record with a ptr to clikLoop A. (works fine)
Create Window B with another TE record and clikLoop B.

Now when I return to window A,  clikLoop A is no longer called.

If I put a SetClikLoop in my window update routine (i.e every time the
window becomes active I reset the clikLoop ptr) the clikLoop routine is once
again called.

Can one of you experts please hit me upside the head and tell me what I'm
doing wrong?

-- 
John Coffman

olson@bootsie.uucp (Eric K. Olson) (02/21/91)

In article <2305.27c2a58c@spacm1.spac.spc.com> audit038@spacm1.spac.spc.com writes:
>In using my own clikLoop function with TE records I came up with the following
>problem:
>
>Window A has a TE record with a ptr to clikLoop A. (works fine)
>Create Window B with another TE record and clikLoop B.
>
>Now when I return to window A,  clikLoop A is no longer called.
>
>If I put a SetClikLoop in my window update routine (i.e every time the
>window becomes active I reset the clikLoop ptr) the clikLoop routine is once
>again called.

This is a misfeature of the glue provided by Apple for SetClikLoop().
This misfeature occurs in THINK C and MPW C (because they both use
Apple glue).  To avoid the problem, don't use SetClikLoop().  Instead,
use this:

Instead of SetClikLoop(realClickLoop):

	(*teHandle)->clikLoop = (ProcPtr) TEClikGlue;

Here's the glue:

	Boolean	TEClickGlue()
	{
	asm {
		move.l	d2,-(a7)	; Preserve d2
		clr.b	-(a7)		; Boolean return
		jsr	realClickLoop	; Jump to the routine
		move.b	(a7)+,d0	; Result in d0
		move.l	(a7)+,d2	; Restore d2
		tst.b	d0		; Set cond codes
		rts
		}
	}

A Sample clikLoop function:

	pascal Boolean realClickLoop()
	{
		SysBeep(1);
		return TRUE;
		}

Note that if you do it this way, you still need a separate glue
procedure for each possible clikLoop function.  There's probably
a better way, but this works, anyway.

-Eric


-- 
Eric K. Olson, Editor, Prepare()      NOTE:     olson@bootsie.uucp doesn't work
Lexington Software Design             Internet: olson@endor.harvard.edu
72A Lowell St., Lexington, MA  02173  Uucp:     harvard!endor!olson
(617) 863-9624                        Bitnet:   OLSON@HARVARD

djvelleman@amherst.bitnet (02/22/91)

In article <1991Feb21.043729.25610@bootsie.uucp>, olson@bootsie.uucp (Eric K. Olson) writes:
> In article <2305.27c2a58c@spacm1.spac.spc.com> audit038@spacm1.spac.spc.com writes:
>>In using my own clikLoop function with TE records I came up with the following
>>problem:
>>
>>Window A has a TE record with a ptr to clikLoop A. (works fine)
>>Create Window B with another TE record and clikLoop B.
>>
>>Now when I return to window A,  clikLoop A is no longer called.
>>
>>If I put a SetClikLoop in my window update routine (i.e every time the
>>window becomes active I reset the clikLoop ptr) the clikLoop routine is once
>>again called.
> 
> This is a misfeature of the glue provided by Apple for SetClikLoop().
> This misfeature occurs in THINK C and MPW C (because they both use
> Apple glue).  To avoid the problem, don't use SetClikLoop().  Instead,
> use this:

  Does anyone know if there are similar problems with WordBreak routines?  I
once tried to install my own WordBreak routine, and could never get it to
work, and could never figure out why.

  -Dan Velleman