[comp.sys.mac.programmer] Problem with GetNextEvent trap patch in MultiFinder

cmcclary@bronze.ucs.indiana.edu (Charles McClary) (01/16/91)

I am trying to patch the GetNextEvent trap A970.  My test patch 
seems to work correctly in Finder, but not in MultiFinder.  In 
MultiFinder, when a desktop icon (disk icon) is covered up by a 
volume or folder window and the window is then moved to uncover 
the icon, the portion of the desktop icon which was covered remains 
invisible.  This does not happen in finder.  Below is the source code 
for the patch.  I am using Think C 4.0.  What an I leaving out?

Thanks in advance,

Charles McClary
Indiana University
cmcclary@bronze.ucs.indiana.edu


/*************  Patch to GetNextEvent  **********/
#include <SetUpA4.h>

#definenil0L

#defineGetNextEventTrap0xA970

longoldGetNextEvent;
Str255trash;

pascal Boolean NewGetNextEvent(int eventMask, EventRecord 
*theEvent);
void main(void);

pascal Boolean NewGetNextEvent(eventMask, theEvent)
inteventMask;
EventRecord* theEvent;
{
SetUpA4();

CallPascalB(eventMask, theEvent, oldGetNextEvent);

RestoreA4();
}

void main()
{
HandlemyHandle = nil;
PtrmyPtr;
SysEnvRecworld;
Str255*namePtr;

asm
{
move.l A0, myPtr
}
RememberA0();
SetUpA4();
if (!Button())
{
myHandle = RecoverHandle(myPtr);
DetachResource(myHandle);

oldGetNextEvent = NGetTrapAddress(GetNextEventTrap, 
ToolTrap);
NSetTrapAddress(NewGetNextEvent, GetNextEventTrap, 
ToolTrap);
}
RestoreA4();
}


Charles McClary
Workstations Division
University Computing Services
Indiana University
cmcclary@bronze.ucs.indiana.edu

beard@ux5.lbl.gov (Patrick C Beard) (01/17/91)

In article <1991Jan15.200340.28431@bronze.ucs.indiana.edu> cmcclary@bronze.ucs.indiana.edu (Charles McClary) writes:
#I am trying to patch the GetNextEvent trap A970.  My test patch 
#seems to work correctly in Finder, but not in MultiFinder.  In 
#MultiFinder, when a desktop icon (disk icon) is covered up by a 
#volume or folder window and the window is then moved to uncover 
#the icon, the portion of the desktop icon which was covered remains 
#invisible.  This does not happen in finder.  Below is the source code 
#for the patch.  I am using Think C 4.0.  What an I leaving out?

You, sir, are tail-patching GetNextEvent, which is most certainly a
no-no.  (I know, I've attempted it before, and had EXACTLY this behaviour.)

#pascal Boolean NewGetNextEvent(eventMask, theEvent)
#inteventMask;
#EventRecord* theEvent;
#{
#SetUpA4();
#
#CallPascalB(eventMask, theEvent, oldGetNextEvent);

essentially:

	asm {
		move.l oldGetNextEvent, a0
		move.w eventMask,-(sp)
		pea theEvent
		jsr (a0)
	}

#
#RestoreA4();
#}

The only way to patch GetNextEvent safely, that I've found, is to 
use a head patch, which basically means, do your patch behaviour, then
jump directly to the old address.  This part obviously has to be done
in assembly language.  Exercise for the reader.

--
-------------------------------------------------------------------------------
-  Patrick Beard, Macintosh Programmer                        (beard@lbl.gov) -
-  Berkeley Systems, Inc.  ".......<dead air>.......Good day!" - Paul Harvey  -
-------------------------------------------------------------------------------

jwwalker@opusc.csd.scarolina.edu (Jim Walker) (01/18/91)

In article <9093@dog.ee.lbl.gov> beard@ux5.lbl.gov (Patrick C Beard)
writes:
[stuff deleted]
|The only way to patch GetNextEvent safely, that I've found, is to 
|use a head patch, which basically means, do your patch behaviour, then
|jump directly to the old address.  This part obviously has to be done
|in assembly language.  Exercise for the reader.

What about the good old jGNEFilter global?  It's pretty safe, isn't it?
-- 
  -- Jim Walker 76367.2271@compuserve.com