Top-aligned NSPopUpButtonCell?
Top-aligned NSPopUpButtonCell?
- Subject: Top-aligned NSPopUpButtonCell?
- From: Keith Blount <email@hidden>
- Date: Tue, 12 Sep 2006 15:48:06 -0700 (PDT)
Hello,
I have an NSOutlineView that can have variable row
heights (using the delegate method
-outlineView:heightOfRowByItem:). A couple of my
columns have NSPopUpButtonCell as their cell class,
though, and these look very odd in a variable
row-height view, because text cells get aligned at the
top whereas popup button cells cet aligned at the
centre vertically. This looks very ugly. Ideally, I
want my NSPopUpButtonCells to be aligned at the top
just like the text (I am surprised that there is no
way of doing this, and yes, I should definitely file
an enhancement request).
So, I have subclassed NSPopUpButtonCell so that it
knows the default row height of the table (as opposed
to the height set by the delegate method) and can
force a draw in the top of the cell (I have appended
my code for this subclass to this mail). That works
fine - it looks and works great, except for one minor
thing: if you click on the popup, the menu appears
centered vertically, as it would do were the normally,
rather than centered over the text and arrows that are
now drawn at the top of the cell. I thought I might
just need to overrided -performClick:withFrame:inView:
to fix this, but that doesn't work as it seems that it
never gets called.
So, my (rather long-winded) question is: how can I get
the menu of my custom popup button cell to appear
where the user expects it? That is, over where I am
now drawing the title and arrows at the top of the
cell/row rather than in the centre?
Many thanks in advance for any help or suggestions,
Keith
CODE:
@implementation KBTopAlignedPopUpButtonCell
- (id)initTextCell:(NSString *)stringValue
pullsDown:(BOOL)pullDown
{
if (self = [super initTextCell:stringValue
pullsDown:pullDown])
{
[self setRowHeight:16.0];
[self setBordered:NO];
}
return self;
}
- (id)initWithRowHeight:(float)height
{
if (self = [super init])
{
rowHeight = height;
[self setBordered:NO];
}
return self;
}
- (void)setRowHeight:(float)height
{
rowHeight = height;
}
- (float)rowHeight
{
return rowHeight;
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView
*)controlView
{
// Force the cell only to draw within the standard
row height, so
// that it draws at the top in tables or outlines
with variable row heights.
cellFrame.size.height = rowHeight;
[super drawWithFrame:cellFrame inView:controlView];
}
@end
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden