On May 26, 2008, at 7:39 PM, Robert Purves wrote: > > On 27/05/2008, at 12:15 PM, Brian Stevens wrote: > >> >> On May 26, 2008, at 12:41 AM, Robert Purves wrote: >> >>> local fn ControlContextualMenuHandler( nextHandler as >>> EventHandlerCallRef, theEvent as EventRef, userData as pointer ) >>> as OSStatus >>> '~'1 >>> dim as HIViewRef c >>> dim as HIPoint myPoint >>> dim as Point qdPoint >>> fn GetEventParameter( theEvent, _kEventParamDirectObject, >>> _typeControlRef, #0, sizeof( c ), #0, @c ) >>> fn GetEventParameter( theEvent, _kEventParamMouseLocation, >>> _typeHIPoint, #0, sizeof( HIPoint ), #0, @myPoint ) >>> fn HIViewConvertPoint( @myPoint, c, 0 ) // window-local coords >>> qdPoint.h = myPoint.x >>> qdPoint.v = myPoint.y >>> LocalToGlobal( @qdPoint ) >>> fn DoContextMenuForClick( qdPoint ) >>> end fn = _noErr >> >> >> I discovered the LocalToGlobal call does not always work ( while >> watching in the debugger the h and v values did not change after >> the call to LocalToGlobal ). Since there are many windows open, my >> assumption was the port was not what I thought it was. A call to >> SetPort ( see below ) solves the problem. I'm not convinced this is >> the best method, so maybe the list will have a better approach. >> ... >> qdPoint.v = myPoint.y >> w = fn GetControlOwner( c )// get windowRef of control >> SetPort( fn GetWindowPort( w ) ) >> LocalToGlobal( @qdPoint ) > > > // HIGeometry.h > #define HICoordinateSpace as UInt32 > toolbox HIPointConvert( HIPoint * ioPoint, HICoordinateSpace > inSourceSpace, pointer inSourceObject, HICoordinateSpace > inDestinationSpace, pointer inDestinationObject ) > _kHICoordSpace72DPIGlobal = 1 > _kHICoordSpaceView = 4 > > local fn ControlContextualMenuHandler( nextHandler as > EventHandlerCallRef, theEvent as EventRef, userData as pointer ) as > OSStatus > '~'1 > dim as HIViewRef c > dim as HIPoint myPoint > dim as Point qdPoint > fn GetEventParameter( theEvent, _kEventParamDirectObject, > _typeControlRef, #0, sizeof( c ), #0, @c ) > fn GetEventParameter( theEvent, _kEventParamMouseLocation, > _typeHIPoint, #0, sizeof( HIPoint ), #0, @myPoint ) > HIPointConvert( @myPoint, _kHICoordSpaceView, c, > _kHICoordSpace72DPIGlobal, 0 ) > qdPoint.h = myPoint.x > qdPoint.v = myPoint.y > fn DoContextMenuForClick( qdPoint ) > end fn = _noErr Perfect. Thank you. HIPointConvert handles nicely and there is no need to do any archaic SetPorts. Brian S.