Re: Tooltip for cell or column of NSTableView?
Re: Tooltip for cell or column of NSTableView?
- Subject: Re: Tooltip for cell or column of NSTableView?
- From: Bjoern Kriews <email@hidden>
- Date: Wed, 25 Feb 2004 01:16:41 +0100
On 25.02.2004, at 00:16, Tom wrote:
Is there a way to assign a tooltip to a cell of NSTableView? Or at
least to a column?
see
http://www.harmless.de/cocoa.html @
http://www.harmless.de/cocoa.html
If you want tooltips for columns take a look at the code below,
(cut from a larger project, will not compile out of the box)
At startup or every time you reconfigure columns:
call [placeToolTips...
and, if reconfiguring:
[[tableView headerView] removeAllTooltips];
And some wild guessing:
I got crashes when I didn't retain the owner object I give to
[headerView addToolTipRect: [headerView headerRectOfColumn:
columnIndex] owner: columnDescriptor userData: nil];
so I expect it doesn't retain it - which makes sense to me because it
will often be the view itself -
the docs don't say anything about it.
I pass my ColumnDescriptor object as the tooltip owner - so i get its
description method called - you could also
pass an NSString.
--- code ---
#define RC_NO_COLUMN (-1)
- (void)tableViewColumnDidMove:(NSNotification *)aNotification
{
[self placeToolTipsForResultSet: [self resultSet] onTableView:
[aNotification object]];
}
- (void)tableViewColumnDidResize:(NSNotification *)aNotification
{
[self placeToolTipsForResultSet: [self resultSet] onTableView:
[aNotification object]];
}
- (void) placeToolTipsForResultSet: (ResultSet *) resultSet
onTableView: (NSTableView *) aTableView
{
NSTableHeaderView *headerView = [aTableView headerView];
[headerView removeAllToolTips];
NSEnumerator *e = [[resultSet columnDescriptors] objectEnumerator];
id columnDescriptor;
int columnIndex;
while( ( columnDescriptor = [e nextObject] ) ) {
NSString *identifier = [columnDescriptor valueForKey:
@"identifier"];
columnIndex = [aTableView columnWithIdentifier: identifier];
debug(6, @"identifier: %@ index: %d", identifier, columnIndex);
if( columnIndex == RC_NO_COLUMN )
continue;
// owner does not seem to be retained, but is kept safe for our
lifetime in the columnDescriptor
[headerView addToolTipRect: [headerView headerRectOfColumn:
columnIndex] owner: columnDescriptor userData: nil];
}
}
_______________________________________________
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.