I am writing a program that has a number of subclassed NSViews (Frame) with varying contents that can be dragged around by the mouse in their superview. All of the views contain one subview, called contentView, which in turn can contain a more complicated hierarchy.
If I have a non-editable NSTextField as the contentView the mouseDown: and mouseDragged: events get passed on to its superview without a problem and dragging works just fine.
mouseDown: ---> [NSTextField] ---> [Frame]
mouseDragged: ---> [NSTextField] ---> [Frame]
If the contentView is a subclass of NSView that in turn contains a number of NSTextFields the mouseDragged: event is not passed on from the NSTextFields to the superview.
mouseDown: ---> [NSTextField] ---> [subclassed NSView] ---> [Frame]
mouseDragged: ---> [NSTextField] -x->
The mouseDown: event is received by the frame. Clicking in the gaps between the NSTextFields and dragging the contentView directly works at well.
The NSTextFields are set up like this in the contentView:
NSTextField *textfield = [[NSTextField alloc] initWithFrame:rect];
[textfield setBordered:NO];
[textfield setSelectable:NO];
[textfield setEditable:NO];
[textfield setTextColor:[NSColor blackColor]];
[textfield setBackgroundColor:[NSColor clearColor]];
[textfield setDrawsBackground:NO];
[textfield setAlignment:NSRightTextAlignment];
[textfield setFont:[NSFont fontWithName:@"Helvetica" size:14]];
[self addSubview:textfield];
[textfield release];
I have tried adding a mouseDragged: method to both a subclassed NSTextField and the subclassed NSView, as well as leaving the method out. Neither made a difference. The problem also exists with other NSControls that are at the same subview level.
- (void)mouseDragged:(NSEvent *)theEvent
{
[super mouseDragged:theEvent];
}
or
- (void)mouseDragged:(NSEvent *)theEvent
{
[self.superview mouseDragged:theEvent];
}
At the moment this behaviour seems completely unintuitive to me. Is there something I am missing? (I am working with Xcode 4.6.2 on Mountain Lion.)