10.6 Clips Tooltip if you return NSTextFieldCell in -dataCellForRow:
10.6 Clips Tooltip if you return NSTextFieldCell in -dataCellForRow:
- Subject: 10.6 Clips Tooltip if you return NSTextFieldCell in -dataCellForRow:
- From: Jerry Krinock <email@hidden>
- Date: Mon, 25 Jan 2010 22:48:33 -0800
I've been overriding -[NSTableColumn dataCellForRow:], returning a variation on NSTextFieldCell for years. However I just discovered that, in OS 10.6.2, this breaks the tooltip which shows the entire text when you hover over a truncated cell. (This tooltip feature was added in OS 10.5.) Here's how it looks:
http://sheepsystems.com/engineering/ClippedToolTip.png [1]
Here's the demo project:
http://sheepsystems.com/engineering/ClippedToolTip.zip
No problem either way in Mac OS X 10.5. Snow Leopard AppKit Release Notes don't mention anything about these tooltips.
Here is the demo project code:
@implementation CTDataSource
- (int)numberOfRowsInTableView:(NSTableView *)aTableView {
return 1 ;
}
- (id) tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex {
if ([[aTableColumn identifier] isEqualToString:@"name"]) {
// First column. Long name will be truncated.
return @"Gagikostoupomolis A. B. C. Geiristomzkimcbliskewicz" ;
}
else {
// Second column
return @"email@hidden" ;
}
}
@end
@implementation CTTableColumn
- (id)dataCellForRow:(int)iRow {
#if 1
id aCell = [super dataCell] ;
#else
id aCell = [[[NSTextFieldCell alloc] init] autorelease] ;
#endif
// This is just for logging
if ([[self identifier] isEqualToString:@"name"]) {
NSLog(@"height=%0.1f width=%0.1f %p class=%@ size=%@",
[[self tableView] rowHeight],
[self width],
aCell,
[aCell class],
NSStringFromSize([aCell cellSize])) ;
}
return aCell ;
}
@end
Referring to -dataCellForRow:, if the #if is 1 as shown, it implements the documented fact that "By default, this method just calls dataCell", and the tooltip is OK. OK behavior also if you simply invoke super.
But if you change #if to 0 and return a raw NSTextFieldCell, you get the clipped tooltip.
The console log raises more questions than answers:
With #if 1 (super's -dataCell, good tooltip),
height=20.0 width=159.0 0x5a1a2f0 class=NSTextFieldCell size={60.1641, 17}
height=20.0 width=159.0 0x5a1a2f0 class=NSTextFieldCell size={343.968, 17}
height=20.0 width=159.0 0x5a1a2f0 class=NSTextFieldCell size={343.968, 17}
With #if 0 (Raw NSTextFieldCell, clipped tooltip),
height=20.0 width=159.0 0x5a31680 class=NSTextFieldCell size={31.6094, 16}
height=20.0 width=159.0 0x5b34080 class=NSTextFieldCell size={31.6094, 16}
height=20.0 width=159.0 0x5a622d0 class=NSTextFieldCell size={31.6094, 16}
In both cases, the first two log lines appear immediately when the table is first drawn, and the third appears when I hover my mouse over the cell with the overflow text to display the tooltip. Note: I logged later that iRow is always = 0.
I'm guessing that that the problem has something to do with the cell size. Looking at those cell sizes, I have no idea where initial widths 60.1641 or 31.6094 come from. Same for the heights 16 and 17. Those heights do not vary if I change the row height. However, 343.968 is in fact the width needed to display the text on a single line in the tooltip!
So here are the "star" questions:
* Why in the world would Cocoa be invoking -dataCellForRow in order to display a tooltip? It always uses the same yellow box format with the same font. The tooltip should have no interest whatsoever in the data cell. But it's apparently getting the answer that it wants, a width of 343.968!
* How in the world does -[super dataCell] know that the required width of the text in this particular cell is 343.968? It does not even know the row or column, much less the data object value.
Possibly the answers to these questions will lead to a workaround. Any ideas?
Thanks!
Jerry
[1] Here is a textual description of the clipped tooltip, for the long-term archives:
* The yellow rectangle is only as wide as the column.
* The yellow rectangle looks like it is tall enough to display the several lines that would be needed, if the text were wrapped, but...
* The text is not wrapped. The first line is clipped in mid-character at the right edge. Below this first line, there is one or more blank lines.
* The 1-pixel gray outline appears as usual around all four sides of the yellow rectangle.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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