This seems like it should be simple but for some reason I can not get it to work. I've tried a million different things with no success. All I want to do is set the color of the text in a NSPopUpButtonCell. One of my columns in an a subclass of NSTableView contains popup menus. Everything is working great so I move on to the last issue (I hope). I need to be able to set the color of the menu items based on certain criteria. But before I got to that I just tried to change the color from black to anything else. It just doesn't work. Below is the relevant code from my project. I don't usually post this much code but this is killing me and I was hoping someone might be able to spot something I am doing wrong and set me straight. Thanks in advance for any help. Basically, I just have subclasses of NSTableView, NSPopupButtonCell and NSTableColumn. I've stripped out all the junk not relevent to this problem.
********************* NSTableView Subclass ****************************
@interface ListBoxControl : NSTableView {
MyDataSource *TheDataSource;
myButtonCellClass *pcell;
}
- (void)awakeFromNib;
-(MyDataSource*) getDataSource;
-(myNSCell*) getCustomPCell;
@end
@implementation ListBoxControl
- (void)awakeFromNib;
{
NSAttributedString *redString;
NSMenu *colorMenu;
NSMenuItem *theRedItem;
NSMutableDictionary *red_attrs;
TheDataSource = [[MyDataSource alloc] init];
[TheDataSource retain];
[TheDataSource initData];
[TheDataSource setHostView:self];
[self setDataSource:TheDataSource];
red_attrs = [NSMutableDictionary dictionaryWithCapacity:2];
[red_attrs setValueNSColor redColor] forKey"NSForegroundColorAttributeName"];
[red_attrs setValueNSColor redColor] forKey"NSStrokeColorAttributeName"];
redString = [[[NSAttributedString alloc] initWithString"Red" attributes:red_attrs] retain];
colorMenu = [[NSMenu alloc] initWithTitle"COLORMENU"];
theRedItem = [[NSMenuItem alloc] initWithTitle"Title1" action:NULL keyEquivalent""];
[theRedItem setAttributedTitle:redString];
[colorMenu addItem: theRedItem];
pcell = [[[myButtonCellClass alloc] initTextCell"" pullsDown:false] retain];
[pcell setEditable:NO];
[pcell setBordered:NO];
[pcell setMenu:colorMenu];
}
-(myNSCell*) getCustomPCell
{
return pcell;
}
-(MyDataSource*) getDataSource
{
return TheDataSource;
}
@end
********************* NSPopUpButtonCell Subclass ****************************
@interface myButtonCellClass : NSPopUpButtonCell {
}
@end
@implementation myButtonCellClass
@end
********************* NSTableColumn Subclass ****************************
@interface customColumn : NSTableColumn {
}
- (id)dataCellForRowNSInteger)row;
@end
@implementation customColumn
- (id)dataCellForRowNSInteger)row
{
return [[self tableView] getCustomPCell];
}
@end
********************* NSTableView Subclass ****************************
@interface ListBoxControl : NSTableView {
MyDataSource *TheDataSource;
myButtonCellClass *pcell;
}
- (void)awakeFromNib;
-(MyDataSource*) getDataSource;
-(myNSCell*) getCustomPCell;
@end
@implementation ListBoxControl
- (void)awakeFromNib;
{
NSAttributedString *redString;
NSMenu *colorMenu;
NSMenuItem *theRedItem;
NSMutableDictionary *red_attrs;
TheDataSource = [[MyDataSource alloc] init];
[TheDataSource retain];
[TheDataSource initData];
[TheDataSource setHostView:self];
[self setDataSource:TheDataSource];
red_attrs = [NSMutableDictionary dictionaryWithCapacity:2];
[red_attrs setValueNSColor redColor] forKey"NSForegroundColorAttributeName"];
[red_attrs setValueNSColor redColor] forKey"NSStrokeColorAttributeName"];
redString = [[[NSAttributedString alloc] initWithString"Red" attributes:red_attrs] retain];
colorMenu = [[NSMenu alloc] initWithTitle"COLORMENU"];
theRedItem = [[NSMenuItem alloc] initWithTitle"Title1" action:NULL keyEquivalent""];
[theRedItem setAttributedTitle:redString];
[colorMenu addItem: theRedItem];
pcell = [[[myButtonCellClass alloc] initTextCell"" pullsDown:false] retain];
[pcell setEditable:NO];
[pcell setBordered:NO];
[pcell setMenu:colorMenu];
}
-(myNSCell*) getCustomPCell
{
return pcell;
}
-(MyDataSource*) getDataSource
{
return TheDataSource;
}
@end
********************* NSPopUpButtonCell Subclass ****************************
@interface myButtonCellClass : NSPopUpButtonCell {
}
@end
@implementation myButtonCellClass
@end
********************* NSTableColumn Subclass ****************************
@interface customColumn : NSTableColumn {
}
- (id)dataCellForRowNSInteger)row;
@end
@implementation customColumn
- (id)dataCellForRowNSInteger)row
{
return [[self tableView] getCustomPCell];
}
@end