views:

23

answers:

2

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!)

  1. Create a new cocoa project
  2. Create the following class
  3. Drag a custom view on the window and make the class GTTest
  4. 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 nsresponder right?) DOES fire my IBAction method; what is my class above missing to also work correctly?

What can I do?

A: 

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:

http://stackoverflow.com/questions/1490331/mouse-click-events-in-an-nsview-subclass

JWWalker
Thank you for your answer, but it's not related but I tried anyway. It doesn't work sadly. There is a issue on 10.5's nssplitview. If I only could work around it in some way.
Ger Teunis
+1  A: 

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!

Ger Teunis