Tracking rectangles with Cocoa views in Carbon windows
Tracking rectangles with Cocoa views in Carbon windows
- Subject: Tracking rectangles with Cocoa views in Carbon windows
- From: David Elliott <email@hidden>
- Date: Thu, 16 Aug 2007 12:31:10 -0400
Hi,
It seems there is a bug with tracking rectangles when they are set
from a Cocoa view living in a Carbon window. The specific case is
that of a Cocoa PDE running on Tiger.
I spent some time debugging this a while back and observed a few
interesting things. I used TextEdit as the host application and I
suspect that some of my observations are dependent upon Cocoa running
the main event loop.
The first observation is that TextEdit's NSApplication event loop
does seem to receive the mouse entered and mouse exited events. It
also knows which window they are for and thus does invoke
[NSCarbonWindow sendEvent:]. Examining the NSEvent record shows that
it has the correct tracking rect tag. From there, NSCarbonWindow
sends them off to some Carbon event handling code and they never come
back. I suspect this is because Cocoa never installed any Carbon
event handlers for the tracking rectangles.
To fix this I am considering doing something special when [[myView
window] isKindOfClass:[NSCarbonWindow class]]. Is this the best way
to check for this or is there a better way?
What to do I am not entirely sure. One thought that crosses my mind
is to read up on the Carbon event manager and figure out how I can
install a hook which will send the mouseEntered:/mouseExited:
messages as Cocoa would have.
Another thought that crosses my mind is to use an offscreen window
sized to the full screen space, that is taking into account every
NSScreen in the screens array and coming up with a rectangle that
encompasses all of them. From there it should be possible to use the
addTrackingRect:owner:userData:assumeInside: method on its
contentView which should, assuming tracking rects work for windows
that aren't displayed on the screen, cause the mouse entered and
mouse exited events to go to the dummy offscreen window (which will
be a normal Cocoa window) and be sent to the owner object as
mouseEntered:/mouseExited: messages.
Does anyone have any particular experience with this? Am I on the
right track? Am I missing an easier way to do it? Does Apple ever
plan to fix this bug? If so, how can I make sure not to use the
workaround when it isn't needed?
I have not yet verified this on Leopard although I certainly plan to.
-Dave
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden