How do I get the button's rect in this method?
In the below method the NSRect buttonRect = ???
is the place where I need to get the frame / rect
of NSButtonCell
object named _buttonCell
.
- (NSCellHitResult)hitTestForEvent:(NSEvent *)event
inRect:(NSRect)cellFrame
ofView:(NSView *)controlView {
NSCellHitResult hitType = [super hitTestForEvent:event inRect:cellFrame ofView:controlView];
NSPoint location = [event locationInWindow];
location = [controlView convertPoint:location fromView:nil];
NSRect buttonRect = ??? //_buttonCell.frame;
if (NSMouseInRect(location, buttonRect, [controlView isFlipped])) {
// We are only sent tracking messages for trackable areas.
hitType |= NSCellHitTrackableArea;
NSLog(@"hit ");
[_buttonCell setState:NSControlStateValueOn];
}
return hitType;
}
The _buttonCell is drawn as:
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView{
int x = cellFrame.origin.x;
int y = cellFrame.origin.y;
NSRect buttonRect = NSMakeRect(x, y, 24, 24);
NSRect imageRect = NSMakeRect(x+24, y, 24, 24);
NSRect textRect = NSMakeRect(x+48, y, cellFrame.size.width-50, 24);
[_buttonCell drawWithFrame:buttonRect inView:controlView];
[_imageCell drawWithFrame:imageRect inView:controlView];
[_textCell drawWithFrame:textRect inView:controlView];
}