Enabling/Disabling Control view hiearchies

  • I'm trying to set up a scheme whereby I can enable and disable a group
    of related controls all at once.  Under most of the application
    frameworks that I am more familiar with (Carbon/HIView, PowerPlant,
    etc...) one can set up a view hierarchy of controls and then
    enable/disable the parent view to change the enabled state of the
    children.  Most are clever enough that when you reenable the parent
    view, if any of the children were enabled before the parent was
    disabled, then those "latently enabled" controls will be enabled again.

    If I'm reading things properly, however, Cocoa distinguishes itself
    from those other frameworks in that NSView doesn't have the concept of
    being enabled.  You don't see enabling behavior in the hierarchy until
    you get to NSControl.

    This, however, begs the question of how to group controls so that they
    enable or disable together (i.e. if I turn on this checkbox then I
    enable all the controls related to it).

    As far as I can tell, you have to do something like maintain IB outlets
    that point to the controls (including static text labels) and then
    enable/disable them one-by-one.

    I thought to group the controls inside of an NSBox that had no border,
    but NSBox doesn't seem to understand enabling or disabling itself (and
    it's subviews) either.

    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?

    Scott
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Before bindings, I never found (though I'll admit I didn't
    whole-heartedly search) a good way to enable/disable groups of
    controls.
    With bindings, however, it's quite simple and relatively elegant.  For
    every control you want to group together, bind its "enabled" property
    to the same key within a controller.
    Then just modify that key to enable/disable those controls.
    Example: [theController setValue:[NSNumber numberWithBool:YES]
    forKey:@"groupFooEnabled"];

    - Mark

    On Jun 18, 2004, at 4: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.  Under most of the application
    > frameworks that I am more familiar with (Carbon/HIView, PowerPlant,
    > etc...) one can set up a view hierarchy of controls and then
    > enable/disable the parent view to change the enabled state of the
    > children.  Most are clever enough that when you reenable the parent
    > view, if any of the children were enabled before the parent was
    > disabled, then those "latently enabled" controls will be enabled
    > again.
    >
    > If I'm reading things properly, however, Cocoa distinguishes itself
    > from those other frameworks in that NSView doesn't have the concept of
    > being enabled.  You don't see enabling behavior in the hierarchy until
    > you get to NSControl.
    >
    > This, however, begs the question of how to group controls so that they
    > enable or disable together (i.e. if I turn on this checkbox then I
    > enable all the controls related to it).
    >
    > As far as I can tell, you have to do something like maintain IB
    > outlets that point to the controls (including static text labels) and
    > then enable/disable them one-by-one.
    >
    > I thought to group the controls inside of an NSBox that had no border,
    > but NSBox doesn't seem to understand enabling or disabling itself (and
    > it's subviews) either.
    >
    > 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?
    >
    > Scott
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > 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 | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • 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 | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Followup:

    I just tested this, and it works fine; in fact, I added it to my base
    framework.  However, you'll need to change the -superviewIsEnabled
    method as shown:

    - (BOOL)superviewIsEnabled
    {
    NSView *superview;
    if ((superview = [self superview])) {
      return [superview isEnabled];
    }
    return YES;
    }

    I'd written it correctly at first, and it apparently got fuxored during
    an undo/redo while editing in Mail.app.

    Good luck!
    --
    Shaun Wexler
    MacFOH
    http://www.macfoh.com

    On Jun 18, 2004, at 3:00 PM, Shaun Wexler wrote:

    > 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 | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • I have a subclass of NSQuickDraw that I play some quickdraw based
    graphics into that include some controls (think Flash movie)

      As soon as I right click and bring up a context menu I can no longer
    interact with the quickdraw content. I'm pretty puzzled about this, but
    since Cocoa does all the work for a context menu I'm at a bit of a loss
    as to why the view no longer sees things like mousedowns.

    My Cocoa view is still getting the events, but when I pass them along
    to the quickdraw nothing happens.

    It all works fine until this menu is popped up, it seems *something* is
    being deactivated, but I can't figure out what.

    john pattenden
    screentime media.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • My email cheesed out, so I did not get any messages for many hours
    after I posted this...

    I have a subclass of NSQuickDraw that I play some quickdraw based
    graphics into that include some controls (think Flash movie)

      As soon as I right click and bring up a context menu I can no longer
    interact with the quickdraw content. I'm pretty puzzled about this, but
    since Cocoa does all the work for a context menu I'm at a bit of a loss
    as to why the view no longer sees things like mousedowns. It will still
    track a mouse (not dragging just following the mouse) and continues to
    draw on its own - it is just that control no longer respond.

    My Cocoa view is still getting the events, but when I pass them along
    to the quickdraw environement nothing happens.

    everything works fine until this menu is popped up, it seems
    *something* is being deactivated, but I can't figure out what.

    john pattenden
    screentime media.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.