• 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: Exterior focus rings with custom views
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Exterior focus rings with custom views


  • Subject: Re: Exterior focus rings with custom views
  • From: Tony Royal <email@hidden>
  • Date: Fri, 11 Jun 2004 14:03:02 -0400

Here's a subclass of NSScrollView that gives the behavior you describe.
I don't know who was the original author of this code.

//
// JJIScrollView.h
//

#import <AppKit/AppKit.h>

@interface JJIScrollView:NSScrollView
{
BOOL shouldDrawFocusRing;
NSResponder *lastResp;
}
@end

//
// JJIScrollView.m
//
//This code puts the focus ring around NSScrollView and is used for
NSTableView and NSTextView that currently does not support this
feature.

#import "JJIScrollView.h"

@implementation JJIScrollView

- (BOOL)needsDisplay;
{
NSResponder *resp = nil;
if ([[self window] isKeyWindow])
{
resp = [[self window] firstResponder];
if (resp == lastResp) return [super needsDisplay];
}
else if (lastResp == nil)
{
return [super needsDisplay];
}
shouldDrawFocusRing = (resp != nil && [resp isKindOfClass: [NSView
class]] && [(NSView *)resp isDescendantOf: self]); // [sic]
lastResp = resp;
[self setKeyboardFocusRingNeedsDisplayInRect: [self bounds]];
return YES;
}

- (void)drawRect:(NSRect)rect
{
[super drawRect: rect];
#ifdef DEBUG
NSLog(@"%@ drawing focus ring? %hd", self, shouldDrawFocusRing);
#endif
if (shouldDrawFocusRing)
{
NSSetFocusRingStyle(NSFocusRingOnly);
NSRectFill(rect);
}
}

Tony Royal
VP Technology
Jenike & Johanson, Inc.
One Technology Park Drive
Westford MA 01886
voice: (978) 392-0300 x106
email@hidden

On Jun 10, 2004, at 5:42 PM, Josh Anon wrote:

> Hi all,
> I have a custom view in a scroll view, and I'd like it to have a focus
> ring around it, similar to NSTableView. I initially thought that I'd
> get this for free, especially with full keyboard access on, but that
> doesn't seem to be the case.
>
> From the doc, my first thought was just to call setFocusRingType: in
> awakeFromNib, and I did a [self
> setFocusRingType:NSFocusRingTypeDefault] in awakeFromNib. No effect.
> Next thought was that I needed to call setFocusRingType on the scroll
> view. Still no effect. Then, I found that the exterior focus ring is
> different from the default type. I tried passing in
> NSFocusRingTypeExterior to both the custom view and to the scroll
> view. Nothing. I tried overriding +defaultFocusRing on the view,
> too, and still nothing. If I do an interior focus ring using the
> visible bounds, I at least get something, but copy-on-scroll bites me.
>
> Has anyone managed to put an exterior focus ring around a custom view
> in a scroll view before?
>
> Thanks,
> Josh
>
> ---
> Josh Anon
> Studio Tools, Pixar Animation Studios
> email@hidden
> _______________________________________________
> cocoa-dev mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Exterior focus rings with custom views (From: Josh Anon <email@hidden>)

  • Prev by Date: Re: Cocoa internet Proxy app
  • Next by Date: KVO for Java
  • Previous by thread: Exterior focus rings with custom views
  • Next by thread: Cocoa internet Proxy app
  • Index(es):
    • Date
    • Thread