RE: [Q] How to frame NSTableView and NSOutlineView?
RE: [Q] How to frame NSTableView and NSOutlineView?
- Subject: RE: [Q] How to frame NSTableView and NSOutlineView?
- From: "Cristian Savu" <email@hidden>
- Date: Tue, 23 Jul 2002 15:12:52 +0300
>
I have a window with several NSTableViews and NSOutlineViews.
>
I'd like
>
to be able to frame (draw a rect) around the table or outline
>
that has
>
the current "focus." Iow, the last table or outline that was
>
clicked in
>
or tabbed to, to give user feedback as which one can have
>
certain tools
>
acted upon.
Here you have the code you need. Just add this files to IB and instead of
NSScrollView use this class.
This code is not the creation of my neuron. I found it on this list. I think
mmalcom is the author, but I can't be sure.
Hope it works.
Regards, Cristian
// RSFocusScrollView.h
#import <Cocoa/Cocoa.h>
@interface RSFocusScrollView : NSScrollView
{
BOOL shouldDrawFocusRing;
NSResponder *lastResp;
}
@end
// RSFocusScrollView.m
#import "RSFocusScrollView.h"
@implementation RSFocusScrollView
- (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];
if (shouldDrawFocusRing)
{
NSSetFocusRingStyle(NSFocusRingOnly);
NSRectFill(rect);
}
}
@end
_______________________________________________
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.