Re: NSButtonCell in NSTableView.
Re: NSButtonCell in NSTableView.
- Subject: Re: NSButtonCell in NSTableView.
- From: Jerry Krinock <email@hidden>
- Date: Wed, 6 Jun 2007 04:39:05 -0700
On 2007 Jun, 06, at 4:15, Sachin Kumar Tulla wrote:
I want to use buttons in the NSTableView for a column.
Initially I made particular column as buttoncelltype in the
NSTableView. But the properties of all the buttons in the column
are same. How to customize....? like changes in title string or its
On/Off State., etc.,
Any idea... or sample code....
If you mean to change all the buttons in a column, there are plenty
of properties available in the Inspector, but I've never been able to
figure out how to select an NSCell by clicking on the table. You
have to activate the nib/document window, click the "outline" icon on
the right to put it in outline view, and then select the NSButtonCell.
If you mean that you want buttons in different rows to look
different, the answer is to subclass NSTableColumn and over-ride -
dataCellForRow to switch or if/else as a function of row. Or, use -
[NSTableView itemAtRow:] to switch as a function of item type.
You won't be able to compile the following because of all the global
constants and stuff, but here's the idea...
@implementation MyTableColumn
// This is a callback from the OS
- (id)dataCellForRow:(int)iRow
{
if (iRow < 0) // OS wants generic cell information
return ([self dataCell]) ;
SSTextFieldCell * thisCell =[[SSTextFieldCell alloc] init];
BmItem* theItem = [[self tableView] itemAtRow:iRow] ;
// If tableView is an NSOutlineView, it will respond directly to
itemAtRow.
// If tableView is an NSTableView, it will respond via a
category method in SSUtilityCategories
// which will pass the message on to its data source, where I
have put the implementation.
enum NodeType nodeType = [theItem nodeType] ;
if (nodeType <= BookdogFolder)
{
// Set font and text color
if ([[self identifier] isEqualToString:@"name"])
{
if (nodeType <= BookdogPermanent)
[thisCell setFont:gSSAppFontTableBoldItalic];
else
[thisCell setFont:gSSAppFontTableBold];
}
else // url
{
[thisCell setFont:gSSAppFontTable];
[thisCell setTextColor:[NSColor grayColor]];
}
// Set Icon
if ([[self identifier] isEqualToString:@"name"]) {
if ([[theItem sorted] boolValue] > 0) {
[thisCell setIcon1:[NSImage
imageNamed:@"IconSorted"]] ;
}
else {
[thisCell setIcon1:[NSImage
imageNamed:@"IconUnsorted"]] ;
}
}
else if ([[self identifier] isEqualToString:@"browservName"]) {
[thisCell setIcon1:[[theItem bmDoc] browserIcon]] ;
}
// Set background color
if ([[theItem lineageNames] count] == 1)
{
// This is the top line, "User's Bookmarks".
if ([[theItem sorted] boolValue] > 0)
[thisCell
setBackgroundColor:gSSAppDarkTurquoiseBackground] ;
else
[thisCell
setBackgroundColor:gSSAppDarkPurpleBackground] ;
[thisCell setDrawsBackground:YES] ;
}
else if ([[theItem lineageNames] count] == 2)
{
// this is a Collection
if ([[theItem sorted] boolValue] > 0)
[thisCell
setBackgroundColor:gSSAppMediumTurquoiseBackground] ;
else
[thisCell
setBackgroundColor:gSSAppMediumPurpleBackground] ;
[thisCell setDrawsBackground:YES] ;
}
else if ([theItem nodeType] <= BookdogFolder)
{
// this is a (sub)folder inside a collection
if ([[theItem sorted] boolValue] > 0)
[thisCell
setBackgroundColor:gSSAppLightTurquoiseBackground] ;
else
[thisCell
setBackgroundColor:gSSAppLightPurpleBackground] ;
[thisCell setDrawsBackground:YES] ;
}
// Set editability
if (nodeType <= BookdogPermanent)
{
[thisCell setEditable:NO] ;
}
else
{
[thisCell setEditable:[self isEditable]] ;
}
}
else if (nodeType == BookdogBookmark) {
if ([[self identifier] isEqualToString:@"url"])
[thisCell setFont:gSSAppFontTableItalic];
else // url
[thisCell setFont:gSSAppFontTable];
[thisCell setEditable:[self isEditable]] ;
// Set Icon
NSString* feedURL = nil ;
if ([[self identifier] isEqualToString:@"name"]) {
[thisCell setIcon1:[NSImage
imageNamed:@"BookmarkWhiteBkgnd"]] ;
}
else if ([[self identifier] isEqualToString:@"browservName"]) {
[thisCell setIcon1:[[theItem bmDoc] browserIcon]] ;
}
else if ([[self identifier] isEqualToString:@"url"]) {
if ((feedURL = [theItem feedurl])) {
if ([feedURL length] > 0) {
[thisCell setIcon1:[NSImage
imageNamed:@"RSSWhiteBkgnd"]] ;
}
}
}
}
else if (nodeType == BookdogSeparator) {
[thisCell setFont:gSSAppFontTable] ;
[thisCell setEditable:NO] ;
}
return [thisCell autorelease] ;
/* Other cool stuff which can be done in here:
switch(row)
{
case 0:
NSImageCell * cell =[[NSImageCell alloc] init];
[cell setBordered:YES];
return [cell autorelease] ;
break;
case 1:
NSPopUpButtonCell *cell=[[NSPopUpButtonCell alloc]
init];
[cell setBordered:YES];
return [cell autorelease] ;
break;
case 2:
NSTextFieldCell * cell =[[NSTextFieldCell alloc] init];
[cell setBordered:YES];
return [cell autorelease] ;
break;
case 3:
NSButtonCell * cell =[[NSButtonCell alloc] init];
[cell setBordered:YES];
return [cell autorelease] ;
break;
}*/
}
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden