Reputation: 1219
How to get the current NSControl clicked on NSWindow? I have a mouse down event on NSWindowController,
-(void)mouseDown:(NSEvent *)theEvent {
but when I click inside NSControls placed on NSWindow I dont get the mouse down event called at all.
I have even subclassed NSControls to custom NSViews but I dont receive their mouse down events too when clicked inside. I added setAcceptsTouchEvents
to yes and calling acceptsFirstResponder but its not helping. Surprisingly, when I click on NSWindow and not on any NSControls I get the mousedown event.
What am I doing wrong here?
Upvotes: 0
Views: 1557
Reputation: 28553
try this out
- (void) mouseDown:(NSEvent *)theEvent
{
if ( ([theEvent modifierFlags] & NSCommandKeyMask) != 0)
{
[self setFloatValue:100.0f];
[self.target performSelector:self.action withObject:self];
}
else
[super mouseDown:theEvent];
}
edit:
The target should be the class instance where that method is implemented. So, for example, if you had an IBAction in your app delegate that was connected to your slider called sliderReport: then do this:
[self sendAction:@selector(sliderReport:) to:[NSApp delegate]];
Upvotes: 1