Add support for NSLineBreakByTruncatingHead/Tail/Middle line break modes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@36562 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Doug Simons 2013-04-22 20:12:01 +00:00
parent cd9c1f8d04
commit 6f9a0ad102
2 changed files with 28 additions and 1 deletions

View file

@ -1,3 +1,8 @@
2013-04-22 Doug Simons <doug.simons@testplant.com>
* Source/NSTextFieldCell.m: Add support for NSLineBreakByTruncatingHead/Tail/Middle
line break modes.
2013-03-13 Jonathan Gillaspie <jonathan.gillaspie@testplant.com>
* Source\NSWorkspace.m: Log instead of raise fatal exceptions when unable to obtain a

View file

@ -238,7 +238,29 @@
well). */
_cell.type = NSTextCellType;
titleRect = [self titleRectForBounds: cellFrame];
[[self _drawAttributedString] drawInRect: titleRect];
NSAttributedString *string = [self _drawAttributedString];
NSSize size = [string size];
if (size.width > titleRect.size.width && [string length] > 4)
{
NSLineBreakMode mode = [self lineBreakMode];
if (mode == NSLineBreakByTruncatingHead || mode == NSLineBreakByTruncatingTail || mode == NSLineBreakByTruncatingMiddle)
{
string = [[string mutableCopy] autorelease];
//unichar ell = 0x2026;
NSString *ellipsis = @"..."; //[NSString stringWithCharacters:&ell length:1];
do {
NSRange replaceRange;
if (mode == NSLineBreakByTruncatingHead)
replaceRange = NSMakeRange(0,4);
else if (mode == NSLineBreakByTruncatingTail)
replaceRange = NSMakeRange([string length]-4,4);
else
replaceRange = NSMakeRange(([string length] / 2)-2, 4);
[(NSMutableAttributedString *)string replaceCharactersInRange:replaceRange withString:ellipsis];
} while ([string length] > 4 && [string size].width > titleRect.size.width);
}
}
[string drawInRect: titleRect];
}
}