Re: Enabling/Disabling Control view hiearchies
Re: Enabling/Disabling Control view hiearchies
- Subject: Re: Enabling/Disabling Control view hiearchies
- From: Shaun Wexler <email@hidden>
- Date: Fri, 18 Jun 2004 15:00:05 -0700
On Jun 18, 2004, at 2:15 PM, Scott Thompson wrote:
>
I'm trying to set up a scheme whereby I can enable and disable a group
>
of related controls all at once. Given the elegance of the rest of
>
the framework, I can only think that I must have misunderstood
>
something. Can anyone help me out by describing the expected strategy
>
for enabling/disabling controls, or by pointing me to the appropriate
>
documentation?
If all controls and cells follow convention and manage state using
accessor methods, you can add a category to NSView, and poseAs
NSControl (and subclasses, as necessary) to enforce its use. Example
(untested, written in Mail.app):
@interface NSView (EnabledState)
- (BOOL)superviewIsEnabled;
- (BOOL)isEnabled;
- (void)setEnabled:(BOOL)enabled;
- (BOOL)enabled;
@end
@implementation NSView (EnabledState)
- (BOOL)superviewIsEnabled
{
return [[self superview] isEnabled];
}
- (BOOL)isEnabled
{
return YES; // Override in subclasses.
}
- (void)setEnabled:(BOOL)enabled
{
// NOP. Override in subclasses, to set ivar.
}
- (BOOL)enabled // KVC/bindings support
{
return [self isEnabled];
}
@end
@interface PosedNSControl : NSControl {}
@end
@implementation PosedNSControl
+ (void)load
{
[self poseAsClass:[NSControl class]];
}
- (BOOL)isEnabled
{
return [super isEnabled] && [self superviewIsEnabled];
}
@end
--
Shaun Wexler
MacFOH
http://www.macfoh.com
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.