• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Fuzzy Focus Ring
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fuzzy Focus Ring


  • Subject: Re: Fuzzy Focus Ring
  • From: Corbin Dunn <email@hidden>
  • Date: Thu, 28 Jan 2010 17:01:45 -0800

> 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@hidden)
>
> 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:
>
> This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

References: 
 >Fuzzy Focus Ring (From: Charles Jenkins <email@hidden>)
 >Re: Fuzzy Focus Ring (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: Simulating drag and drop to another application - possible?
  • Next by Date: Re: IKImageBrowserView drop operation always highlighting a specific row
  • Previous by thread: Re: Fuzzy Focus Ring
  • Next by thread: Re: Fuzzy Focus Ring
  • Index(es):
    • Date
    • Thread