开发者

Is it possible to get an NSView to pass rightMouseDown: to the next responder without subclassing?

I have a view which contains a few subviews:

mainView
    subViewA
    subViewB
    SubViewC

mainView is an NSView constructed from a nib and is controlled with an NSViewController subclass. The subviews are standard views such as NSTextField and NSImageView and are configured to be non-editable. I want mainView to receive rightMouseDown: even when th开发者_运维百科e event is triggered in one of the subviews.

The default implementation of rightMouseDown: in NSResponder passes the event to the next responder, but NSView changes the default behaviour and does not pass it to the next responder.

I could subclass all of the subviews but this doesn't seem like a very elegant or maintainable solution.

How can I get the subviews to pass rightMouseDown: messages to the next responder without subclassing all of the subviews?


This is usually accomplished by overriding the superviews's -hitTest: method?


Override NSApplication's - (void)sendEvent:

- (void)sendEvent:(NSEvent *)event {
  if([event type]== NSRightMouseDown)
    redirect to wherever
  else
    [super sendEvent:event];
}


My solution is to add a subview to the mainView which I've called clickCatcher. clickCatcher is transparent and equal in size to mainView and is added so that it's the top most view:

[self addSubview:clickCatcher positioned:NSWindowAbove relativeTo:nil];

The XXXmouseDown: methods of clickCatcher call superview.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜