• 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
Checkbox as title for NSBox
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Checkbox as title for NSBox


  • Subject: Checkbox as title for NSBox
  • From: Doug Brown <email@hidden>
  • Date: Sat, 18 May 2002 21:40:30 -0700

Hello everyone,

I searched the archives at http://cocoa.mamasam.com/ for "NSBox AND checkbox" and came up with a nice thread on this topic, but it never got resolved, so I'm wondering if anyone found a solution to this problem.

I want to have an NSBox with a checkbox for its title for enabling/disabling entire features. I'm sure you know what I mean, because it's used in many applications. Today, I made some sample code to attempt to get this working, by looking in NSBox.h. (dirty code alert)

I subclassed NSBox (yes - I could have made a category, but I fear this is going to take some subclassing now)

- (void)setTitleCell:(id)cell
{
id temp = [cell copy];
[_titleCell release];
_titleCell = temp;

// set the new title cell

[self setTitleWidth:[[[self titleCell] controlView] bounds].size]; // takes width from the size passed to it - I will make it cleaner later

// this resizes the empty space at the top of the box so the entire control fits - see code below

[[self titleCell] setState:NSOnState];
[[self titleCell] setEnabled:YES];

[self setNeedsDisplay:YES];
}

- (void)setTitleWidth:(NSSize)size
{
float width = size.width;
NSPoint origin = _titleRect.origin; // keep the old origin
NSSize newSize = _titleRect.size; // the new size is almost identical to old size
NSRect newRect;

newSize.width = width; // except for the width

newRect.origin = origin;
newRect.size = newSize;

_titleRect = newRect; // set the new title rect
}

This code works pretty well when I pass the cell of a checkbox to the setTitleCell: method I made. I have two problems:

1) The checkbox appears disabled in the box's title, whether I send setEnabled:YES to it or not. It appears checked no matter what, because I set its state to NSOnState. I can set it to NSOffState and it appears unchecked, but still disabled.

2) Clicking on the checkbox does nothing. This is probably a side effect of the button appearing disabled. I put a test NSButton into my nib file, and I'm using its cell to set the titleCell. The test NSButton is enabled and works properly. I also tried programmatically setting the action and method, to no avail.

Anyone have any ideas? This code is coming along, but there are just a few minor bugs that need to be worked out.

Thanks,

Doug
_______________________________________________
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.

  • Follow-Ups:
    • Re: Checkbox as title for NSBox
      • From: email@hidden
  • Prev by Date: Re: Dock Magnification Effect
  • Next by Date: Re: can PB boilerplate text be changed?
  • Previous by thread: rotated NSAffineTransforms and clipping
  • Next by thread: Re: Checkbox as title for NSBox
  • Index(es):
    • Date
    • Thread