Re: Overlapping NSViews and mouseDown Events
Re: Overlapping NSViews and mouseDown Events
- Subject: Re: Overlapping NSViews and mouseDown Events
- From: Thomas Wetmore <email@hidden>
- Date: Wed, 24 Jun 2015 23:40:25 -0400
Ken,
Thanks. I must admit that I will have to work for awhile to figure out what your answer means. This is the first time I’ve done any out of the ordinary custom view stuff, and I’m having to learn almost everything as I go along. Getting dragging and resizing to work cleanly was a big accomplishment for me. Though, when it’s done, it’s surprising how little code is needed.
I don’t yet know what call through to super means in this context. Do you mean to try calling hitTest on the superview?
I did just override opaque in the custom view to be true (yes, I’m doing it all in Swift) , but it didn’t change the behavior. I was hoping for an easy fix!
Thanks again.
Tom Wetmore
> On Jun 24, 2015, at 10:20 PM, Ken Thomases <email@hidden> wrote:
>
> 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