For posterity, if anyone needs the answer to this, I discovered that I need to 
also over-ride needsPanelToBecomeKey to return YES so that a mouse-click can 
give focus to the control. I found this in the ClockControl example, I'd not 
seen that method before.
Toby

On 5 May 2011, at 23:40, Wood, Tobias C wrote:

> Hello,
> I am trying to create a simple NSControl sub-class that will respond to mouse 
> clicks and key presses, however I cannot get it to take First Responder 
> status despite having over-ridden acceptsFirstResponder to return YES. If I 
> place breakpoints in acceptsFirstResponder and becomeFirstResponder then 
> acceptsFirstResponder is called, returns YES, but becomeFirstResponder never 
> gets called and so the class never receives a keyDown message. Mouse-down 
> messages are received correctly. My current implementation is below, am I 
> missing something simple?
> Thanks in advance,
> Toby Wood
> 
> @implementation testControl
> + (Class)cellClass
> {     return [NSActionCell class];    }
> 
> - (BOOL)acceptsFirstResponder
> {     return YES;     }
> 
> - (BOOL)becomeFirstResponder
> {
>       [super becomeFirstResponder];
>       NSLog(@"Became first responder.");
>       return YES;
> }
> 
> - (void)drawRect:(NSRect)dirtyRect {
>   // Drawing code here.
>       NSRect bounds = [self bounds];
>       [[NSColor whiteColor] set];
>       [NSBezierPath fillRect:bounds];
> }
> 
> - (void)keyDown:(NSEvent *)theEvent
> {     NSLog(@"Got a key.");   }
> 
> - (void)mouseDown:(NSEvent *)theEvent
> {
>       NSLog(@"Got a mouse down.");
>       [NSApp sendAction:[self action] to:[self target] from:self];
> }
> @end_______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/t.wood07%40imperial.ac.uk
> 
> This email sent to t.woo...@imperial.ac.uk

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to