Created
September 4, 2012 05:08
-
-
Save arufian/3616801 to your computer and use it in GitHub Desktop.
Click detection on button inside NSCell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL) trackMouse:(NSEvent *)event inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)flag | |
{ | |
// Check if the button was hit. | |
int hitType = [self hitTestForEvent:[NSApp currentEvent] inRect:cellFrame ofView:controlView]; | |
BOOL isButtonClicked = hitType == (NSCellHitContentArea | NSCellHitTrackableArea); | |
if (!isButtonClicked) return YES; | |
// Ignore events other than mouse down. | |
if ([event type] != NSLeftMouseDown) return YES; | |
// Grab all events until a mouse up event. | |
while ([event type] != NSLeftMouseUp) { | |
// Check if link arrow was hit. | |
hitType = [self hitTestForEvent:[NSApp currentEvent] inRect:cellFrame ofView:controlView]; | |
isButtonClicked = hitType == (NSCellHitContentArea | NSCellHitTrackableArea); | |
// Update the cell's display. | |
[controlView setNeedsDisplayInRect:cellFrame]; | |
// Pass event if not hit. | |
if (!isButtonClicked) { | |
[NSApp sendEvent:event]; | |
} | |
// Grab next event. | |
event = [[controlView window] nextEventMatchingMask:(NSLeftMouseUpMask | NSLeftMouseDraggedMask | NSMouseEnteredMask | NSMouseExitedMask)]; | |
} | |
// Perform click only if the button was hit. | |
if (isButtonClicked) { | |
[aButton performClick:self]; | |
} | |
return YES; | |
} | |
- (IBAction)clickButton:(id)sender | |
{ | |
NSLog(@"here ... button was clicked"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[aButton setAction:@selector(clickButton:)]; // assign callback method after button clicked |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment