diff --git a/ChangeLog b/ChangeLog index 02f2acdb2..19eca5c70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-04-22 Doug Simons + + * Source/NSTextFieldCell.m: Add support for NSLineBreakByTruncatingHead/Tail/Middle + line break modes. + 2013-03-13 Jonathan Gillaspie * Source\NSWorkspace.m: Log instead of raise fatal exceptions when unable to obtain a diff --git a/Source/NSTextFieldCell.m b/Source/NSTextFieldCell.m index 9c2754eed..0b20fe303 100644 --- a/Source/NSTextFieldCell.m +++ b/Source/NSTextFieldCell.m @@ -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]; } }