Re: NSTableView tooltips
Re: NSTableView tooltips
- Subject: Re: NSTableView tooltips
- From: Eric Forget <email@hidden>
- Date: Sat, 27 Mar 2004 17:35:32 -0500
Hi Moray,
>
I'm sure I've seen this somewhere, but I can't find it, so sorry if
>
this is FAQ. What I want is the tooltips for an NSTableView to be
>
specific to a cell, preferably controlled by the DataSource. I'm sure
>
I've seen an example for it, so if somebody could point it out, that
>
would be great.
Here is the subset of my custom NSTableView, which deals with tooltips:
@interface MyTableView : NSTableView {
BOOL delegateImplementsShouldDisplayToolTips;
BOOL delegateImplementsToolTip;
}
@end
@interface NSObject(MyTableViewDelegate)
- (BOOL)tableViewShouldDisplayCellToolTips:(NSTableView *)tableView;
- (NSString *)tableView:(NSTableView *)tableView
toolTipForTableColumn:(NSTableColumn *)tableColumn row:(int)rowIndex;
@end
@implementation MyTableView
- (void)setDelegate:(id)delegate
{
if (delegate != [self delegate]) {
[super setDelegate:delegate];
delegateImplementsShouldDisplayToolTips = ((delegate &&
[delegate
respondsToSelector:@selector(tableViewShouldDisplayCellToolTips:)]) ? YES :
NO);
delegateImplementsToolTip = ((delegate &&
[delegate
respondsToSelector:@selector(tableView:toolTipForTableColumn:row:)]) ? YES :
NO);
}
}
- (void)reloadData
{
[super reloadData];
[self resetCursorRects];
}
- (void)resetCursorRects
{
[self removeAllToolTips];
if (delegateImplementsShouldDisplayToolTips && [[self delegate]
tableViewShouldDisplayCellToolTips:self]) {
NSRect visibleRect = [self visibleRect];
NSRange colRange = [self columnsInRect:visibleRect];
NSRange rowRange = [self rowsInRect:visibleRect];
NSRect frameOfCell;
for (unsigned col = colRange.location; col < colRange.location +
colRange.length; col++) {
for (unsigned row = rowRange.location; row < rowRange.location +
rowRange.length; row++) {
frameOfCell = [self frameOfCellAtColumn:col row:row];
[self addToolTipRect:frameOfCell owner:self user
Data:NULL];
}
}
}
}
- (NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag
point:(NSPoint)point userData:(void *)matrix
{
int rowIndex = [self rowAtPoint:point];
int columnIndex = [self columnAtPoint:point];
NSTableColumn *tableColumn = (columnIndex != -1) ? [[self
tableColumns] objectAtIndex:columnIndex] : nil;
return (columnIndex != -1) ? [[self delegate] tableView:self
toolTipForTableColumn:tableColumn row:rowIndex] : @"";
}
@end
Hope it will gives you nice start...
Eric
___________________________________________________________________
Eric Forget Cafederic
email@hidden <
http://www.cafederic.com/>
Fingerprint <86D5 38F5 E1FD 5D9C 71C3 BAA3 797E 70A4 6210 C684>
_______________________________________________
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.