Re: views and mouse events troubles
Re: views and mouse events troubles
- Subject: Re: views and mouse events troubles
- From: Matt Neuburg <email@hidden>
- Date: Wed, 25 Oct 2006 12:33:22 -0700
- Thread-topic: views and mouse events troubles
On Wed, 25 Oct 2006 14:54:57 -0400, Ivan Kourtev <email@hidden> said:
>Could someone please help and explain (or point to a document which
>explains) under what conditions do multiple views get the same mouse
>event? I have a view containing another and when I click on the
>contained view both it and the containing view get the mouse event.
>
>Is that normal? Based on all the docs I've read only one view should
>get the mouse event, or am I wrong to assume so?
>
>I tried many combinations (creating and inserting views into the
>hierarchy programmatically, or via IB, etc.) and nothing seems to
>affect things. If I have N number of views under the mouse pointer
>(contained into each other), then all N of them get the mouse event.
>All view are non-transparent, and completely draw their background.
You are probably misunderstanding your own code.
Look. I put an NSView inside another NSView. Each has a mouseUp method that
logs. I clicked repeatedly in the window, the first click in the middle
(where the view1 is) and the next to its right until finally I was clicking
on the view2 (and not on the view1). Here is the log:
2006-10-25 12:26:14.815 hitTestTest[733] view1: {226, 171}
2006-10-25 12:26:16.542 hitTestTest[733] view1: {248, 173}
2006-10-25 12:26:18.054 hitTestTest[733] view1: {273, 174}
2006-10-25 12:26:20.238 hitTestTest[733] view2: {302, 173}
2006-10-25 12:26:23.574 hitTestTest[733] view2: {310, 174}
So, as you can see, for each click, only one NSView gets the event - the one
that is deepest inside the view hierarchy ("frontmost", as it were).
Pretty simple to test, as you see.
Now, my guess is that you are misinterpreting the behavior of how hitTest
messages are sent. But hitTest is not a mouse event! It's a preparation for
sending a mouse event, which is a very different thing. So, for a single
click in view1, we get this logging:
2006-10-25 12:31:34.425 hitTestTest[769] view2 took a hittest
2006-10-25 12:31:34.426 hitTestTest[769] view1 took a hittest
2006-10-25 12:31:34.521 hitTestTest[769] view1: {228, 181}
So both views are consulted with hitTest - because one of them might want to
override the normal behavior - but only one view gets a mouse event. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden