Re: Overlapping NSViews and mouseDown Events
Re: Overlapping NSViews and mouseDown Events
- Subject: Re: Overlapping NSViews and mouseDown Events
- From: Ken Thomases <email@hidden>
- Date: Wed, 24 Jun 2015 21:20:24 -0500
On Jun 24, 2015, at 7:44 PM, Thomas Wetmore <email@hidden> wrote:
> I am having a problem with NSViews and mouseDown events.
>
> I have defined a custom view (call it CardView) that is an NSOutlineView centered in a slightly larger view used as a border. When displayed, a CardView looks like an index card holding an outline inside a narrow border. There are a few small bezier paths defined in the border that are used as controls; one is used as a resize handle.
>
> If the user clicks in the resize handle the view resizes correctly. If the user clicks in any non-control part of the border, the view becomes draggable and the user can drag it anywhere in the window. All the other control functions also.
>
> I can put as many of these CardViews into a window as I like, overlap them anyway I like, and they all drag around fine and they all resize fine.
>
> EXCEPT FOR ONE THING, and I haven’t been able to find any help from the docs or from Googling:
>
> When I click in the BORDER area of a CardView, and the click spot happens to be OVER an OUTLINE part of an UNDERLYING CardView, the UNDERLYING NSOutlineView gets the mouseDown event instead of border of the top CardView (“top” here is defined as the CardView that is first in the list of subviews of the Window’s content view). However, if I click in the outline area of the CardView on top, regardless what other CardViews are under that CardView, the top outline view always gets the mouseDown as it should.
>
> So I have a view in which one of the subviews seems to work fine with respect to mouse events, but the border subview around it seems to be invisible to the event system.
>
> How do I make the border areas visible to the window when it decides where to dispatch the mouse events? Does anyone have any advice? Thanks.
Make sure that -[NSView hitTest:] is returning self for any point which is supposed to hit it (rather than, say, one of its subviews or a view behind it). Call through to super and, if super returned nil, check the position against relevant parts of self's frame (note the point is in the superview's coordinate, so that's frame, not bounds) and, if it's a hit, return self. Otherwise, return whatever super returned.
If your view completely fills its bounds with opaque drawing, then it can override -isOpaque to return true.
Regards,
Ken
_______________________________________________
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