No MouseUp:/Down: on custom view in NSSplitView on Leopard
I am currently working on a project build for OSX 10.5 and up. First of all, the 10.6 users do not see this; only 10.5 users have this issue. You are not able to reproduce this on 10.6.
In short: when placing an custom extended class of NSView with an overload implementation of - (void)mouseUp:(NSEvent *)theEvent the mouseUp doesn't get called when its wrapped in NSSplitView. rightMouseUp:/Down: DOES work on the extended NSView.
The event gets called when I place the custom view on my window, when I wrap it directly in a nssplitview the mouseup doesn't get called for the leopard (10.5) users.
Steps to reproduce (on 10.5!)
- Create a new cocoa project
- Create the following class
- Drag a custom view on the window and make the class GTTest
- Drag a splitview on the window and just add a GTTest in one of it's content views
Class:
@interface GTTest : NSView {
}
#import "GTTest.h"
@implementation GTTest
- (void)mouseUp:(NSEvent *)theEvent {
NSLog(@"Ger");
}
Clicking on the GTTest direclty on the window logs the nice line, clicking on the NSSplitView one does nothing (try a breakpoint as well). rightMouseDown:/Up: DOES work on the NSView.
ps> When I add a button to the splitview (also a derived nsview, with nsr开发者_如何学Goesponder right?) DOES fire my IBAction method; what is my class above missing to also work correctly?
What can I do?
Okay, i found a fix for this:
Implement an extended class of NSSplitView and override the methods and 'bubble up' the events if the splitter is hovered (detectable via cursor) and if not just do nothing. This do nothing will cause the event to be received by the custom view.
- (void)mouseUp:(NSEvent *)theEvent {
if ([NSCursor currentCursor]==[NSCursor resizeLeftCursor]
|| [NSCursor currentCursor]==[NSCursor resizeRightCursor]
|| [NSCursor currentCursor]==[NSCursor resizeLeftRightCursor]) {
[super mouseUp:theEvent];
}
if ([NSCursor currentCursor]==[NSCursor resizeUpCursor]
|| [NSCursor currentCursor]==[NSCursor resizeDownCursor]
|| [NSCursor currentCursor]==[NSCursor resizeUpDownCursor])
{
[super mouseUp:theEvent];
}
}
And use that class as the splitview; Suddently the events are received to the custom NSViews. Weird but true!
I don't know why 10.5 and 10.6 would be different in this regard, but you might try overriding mouseDownCanMoveWindow
to return NO, as in this question:
mouse click events in an NSView subclass
精彩评论