> Oh, it looks like you can eliminated most of the code below if you're 
> targetting Mac OS 10.5+.
> 
> #import <Cocoa/Cocoa.h>
> 
> @interface NSView (FocusRing)

Ah -- a quick side note on this code sample. Adding a category to NSView with 
generic names (like drawFocusRing) is quite dangerous. The issue is that we 
(AppKit/Apple) could introduce the same name and conflict with your category.

Instead, I recommend using your own unique prefix to the category, ie: 
-cdDrawFocusRing, etc.

corbin

> 
> - (void)patchPreLeopardFocusRingDrawingForScrolling ;
> 
> - (void)drawFocusRing ;
> // Although the above method invokes -lockFocus, and thus will work if
> // invoked while not within -drawRect, it is recommended to invoke this
> // method from within -drawRect, to avoid the possibility of a 
> // later invocation of -drawRect by Cocoa for some other purpose, which it
> // does frequently, will wipe out the focus ring that has just been drawn.
> // This can happen even before the focus ring has a chance to show!
> 
> @end
> 
> @implementation NSView (FocusRing)
> 
> // Invoke the following metod during -awakeFromNib
> - (void)patchPreLeopardFocusRingDrawingForScrolling {
>    if (NSAppKitVersionNumber < 900) {
>        // In Tiger and Panther, the remnants of the focus ring will stay
>        // on screen as the view is scrolled.  The following patch fixes that:
>        NSView* clipView = self;
>        while((clipView = [clipView superview]) != nil) {
>            if([clipView isKindOfClass:[NSClipView class]])
>                break ; 
>        }
> 
>        [(NSClipView*)clipView setCopiesOnScroll:NO] ;
>    }
> }
> 
> - (void)drawFocusRing {
>    [self lockFocus] ; // Needed in case we were not invoked from within 
> drawRect:
>    [[NSColor keyboardFocusIndicatorColor] set];
>    NSRect rect = [self visibleRect] ;
>    [NSGraphicsContext saveGraphicsState];
>    NSSetFocusRingStyle(NSFocusRingOnly);
>    NSFrameRect(rect);
>    [NSGraphicsContext restoreGraphicsState];
>    // The above code is from:
>    // http://www.cocoabuilder.com/archive/message/cocoa/2003/4/7/88648
>    // The remainder of that message applies to pre-Leopard only
>    // and is implemented in this class' 
> -patchPreLeopardFocusRingDrawingForScrolling.
>    [self unlockFocus] ; // Balance lockFocus
> }
> 
> @end
> 
> _______________________________________________
> 
> Cocoa-dev mailing list ([email protected])
> 
> 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/corbind%40apple.com
> 
> This email sent to [email protected]

_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to