Re: Checkbox in NSTableView
Re: Checkbox in NSTableView
- Subject: Re: Checkbox in NSTableView
- From: Stéphane Sudre <email@hidden>
- Date: Thu, 24 Jan 2002 11:51:45 +0100
On Wednesday, January 23, 2002, at 08:40 PM, Chuck Pisula wrote:
Sounds like this could be considered a bug. I'm sure you can accomplish
what you want by using a subclass of NSButtonCell, and overriding the
some appropriate methods. In fact, I was able to do this by simply
overriding drawWithFrame:inView:, and drawingRectForBounds:.
Argh ! Just use the code I posted...
[tPrototypeCell setImagePosition:NSImageOnly];
It's not a bug, it's the designed behavior(tm).
The width of the Control is determined by the width of the Column as
stated in the original post.
What is not taken into consideration is that the Prototype of the cell
is changed in the awakeFromNib (just a supposition). Since the prototype
is changed, I don't see how the attributes could be kept.
Another issue is that there must be a call to [tPrototypeCell
setButtonType:NSSwitchButton];
If this selector is called, you can say bye bye to your Alignment
property even if it was saved by some kind of miracle.
Should you need to align the text (the text and not the control), you
would have to call [tPrototypeCell setAlignment: NSCenterTextAlignment];
AFTER the setButtonType: Call.
But the most important fact is that the setAlignment: selector is used
by the NSButton cell to align the TEXT not the control itself. It can
make the behavior look different from the one of the default cell used
by NSTableView but the behavior is correct.
As stated in the documentation of NSCell:
setAlignment:
- (void)setAlignment:(NSTextAlignment)mode
Sets the alignment of text in the receiver. mode is one of five
constants: NSLeftTextAlignment, NSRightTextAlignment,
NSCenterTextAlignment, NSJustifiedTextAlignment, NSNaturalTextAlignment
(the default alignment for the text).
So the easy way to center the checkbox is to call [tPrototypeCell
setImagePosition:NSImageOnly]; after having called [tPrototypeCell
setButtonType:NSSwitchButton];
Subclassing NSButtonCell is a time-killer.
Since I don'y have the AppKit source code under my eyes, what I'm
describing is just a guess from what I've been experiencing.
--------------------
Designed behavior is a Trademark of email@hidden