Adding to my own post I just found this in my snippets collection:

This listing shows how you draw such a focus ring. It requires you to override 
the NSCell drawWithFrame:inView: In this method, if the cell is supposed to 
draw evidence of first-responder status, set the rectangle for the focus ring, 
call NSSetFocusRingStyle with an argument of NSFocusRingOnly, and then create 
and fill a bezier path defining that rectangle. Filling in this case simply 
draws the ring.

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
{
    // other stuff might happen here
    if ([self showsFirstResponder]) {
         // showsFirstResponder is set for us by the NSControl that is drawing  
us.
        NSRect focusRingFrame = cellFrame;
        focusRingFrame.size.height -= 2.0f;
        [NSGraphicsContextsaveGraphicsState];
        NSSetFocusRingStyle(NSFocusRingOnly);
        [[NSBezierPath bezierPathWithRect: NSInsetRect(focusRingFrame, 4.0f, 
4.0f)] fill];
        [NSGraphicsContext restoreGraphicsState];
    }
    // other stuff might happen here
}

So possibly you could create your own NSTextFieldCell, set your NSTextField to 
use it, call [super drawWithFrame.....] somewhere in the above method to do the 
standard drawing and move on from there. The flashing could be implemented 
using a CALayer animation or something.

If you manage to implement this you should make it open source :-) since I 
guess it's quite a bit of work to get it done.

> Read carefully:
> 
> The original poster stated: "any more text" - or are you suggesting that he 
> should disable the text box when a certain number of characters are reached? 
> I guess not.
> 
> AFAIK, the focus ring is not accessible programmatically, except form setting 
> it by making something the first responder.
> 
> You could use a text formatter or one of the validation methods and simply 
> stop accepting key strokes, change the text color to red and/or display an 
> alert.
> 
> Am 06.10.2011 um 17:43 schrieb Thomas Davie:
> 
>> The correct way to notify a user that he can't enter text in a text box is 
>> to disabled it.
>> 
>> Bob
>> if (*ra4 != 0xffc78948) { return false; }
>> 
>> On 6 Oct 2011, at 16:33, Nick wrote:
>> 
>>> Hello
>>> I am wondering if there's a way to do this, notifying the user that he can't
>>> enter any more text into NSTextField edit box?
>>> Is there a way to change the color of the NSTextField's focus ring to red
>>> (to highlight that this is an error)?
>>> How difficult would that be to implement?
>>> Thank you!
>>> _______________________________________________
>>> 
>>> 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/tom.davie%40gmail.com
>>> 
>>> This email sent to tom.da...@gmail.com
>> 
> _______________________________________________

_______________________________________________

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