Skip to content

Instantly share code, notes, and snippets.

@TomLiu
Created June 13, 2012 12:39
Show Gist options
  • Save TomLiu/2923820 to your computer and use it in GitHub Desktop.
Save TomLiu/2923820 to your computer and use it in GitHub Desktop.
NSCell with checkbox
- (NSUInteger)hitTestForEvent:(NSEvent *)event inRect:(NSRect)frame ofView:(NSView *)controlView {
NSRect checkBoxFrame = [self _checkBoxFrameForInteriorFrame:frame];
NSPoint point = [controlView convertPoint:[event locationInWindow] fromView:nil];
// Delegate hit testing to other cells
if (_checkBoxCell) {
if (NSPointInRect(point, checkBoxFrame)) {
return NSCellHitTrackableArea;
}
}
return NSCellHitNone;
}
+ (BOOL)prefersTrackingUntilMouseUp {
// you want a single, long tracking "session" from mouse down till up
return YES;
}
- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView {
[_checkBoxCell setHighlighted:YES];
return YES; // keep tracking
}
- (BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)controlView {
// if |currentPoint| is in the button, highlight it
// otherwise, unhighlight it
return YES; // keep on tracking
}
- (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)controlView mouseIsUp:(BOOL)flag {
// if |flag| and mouse in button's rect, then
// and, finally,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment