mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 04:50:54 +00:00
Process text for truncation
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@38654 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
95e8009b70
commit
adbe4f1121
2 changed files with 62 additions and 5 deletions
|
@ -2999,6 +2999,57 @@ static NSColor *dtxtCol;
|
|||
}
|
||||
}
|
||||
|
||||
- (NSAttributedString*)_resizeAttributedString: (NSAttributedString*)attrstring forRect:(NSRect)titleRect
|
||||
{
|
||||
// Redo string based on selected truncation mask...
|
||||
NSSize titleSize = [attrstring size];
|
||||
if (titleSize.width > titleRect.size.width && [attrstring length] > 4)
|
||||
{
|
||||
NSLineBreakMode mode = [self lineBreakMode];
|
||||
if (mode == NSLineBreakByTruncatingHead || mode == NSLineBreakByTruncatingTail || mode == NSLineBreakByTruncatingMiddle)
|
||||
{
|
||||
attrstring = [[attrstring 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([attrstring length]-4,4);
|
||||
else
|
||||
replaceRange = NSMakeRange(([attrstring length] / 2)-2, 4);
|
||||
[(NSMutableAttributedString *)attrstring replaceCharactersInRange:replaceRange withString:ellipsis];
|
||||
} while ([attrstring length] > 4 && [attrstring size].width > titleRect.size.width);
|
||||
|
||||
// Return the modified attributed string...
|
||||
return(attrstring);
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise just return the string...
|
||||
return(attrstring);
|
||||
}
|
||||
|
||||
- (NSString*)_resizeDrawString: (NSString*)string withAttrbutes:(NSDictionary*)attributes forRect:(NSRect)titleRect
|
||||
{
|
||||
// Redo string based on selected truncation mask...
|
||||
NSLineBreakMode mode = [self lineBreakMode];
|
||||
NSSize titleSize = [string sizeWithAttributes: attributes];
|
||||
if (titleSize.width > titleRect.size.width && [string length] > 4)
|
||||
{
|
||||
if (mode == NSLineBreakByTruncatingHead || mode == NSLineBreakByTruncatingTail || mode == NSLineBreakByTruncatingMiddle)
|
||||
{
|
||||
NSAttributedString *attrstring = [[[NSAttributedString alloc] initWithString:string attributes:attributes] autorelease];
|
||||
return([[self _resizeAttributedString:attrstring forRect:titleRect] string]);
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise just return the string...
|
||||
return(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Private internal method to display an attributed string.
|
||||
*/
|
||||
|
@ -3019,6 +3070,7 @@ static NSColor *dtxtCol;
|
|||
*/
|
||||
aRect.origin.y = NSMidY (aRect) - titleSize.height/2;
|
||||
aRect.size.height = titleSize.height;
|
||||
aString = [self _resizeAttributedString:aString forRect:aRect];
|
||||
|
||||
[aString drawInRect: aRect];
|
||||
}
|
||||
|
@ -3041,6 +3093,7 @@ static NSColor *dtxtCol;
|
|||
*/
|
||||
cellFrame.origin.y = NSMidY (cellFrame) - titleSize.height/2;
|
||||
cellFrame.size.height = titleSize.height;
|
||||
aString = [self _resizeDrawString:aString withAttrbutes:attributes forRect:cellFrame];
|
||||
|
||||
[aString drawInRect: cellFrame withAttributes: attributes];
|
||||
RELEASE (attributes);
|
||||
|
|
|
@ -528,9 +528,13 @@ static NSString *commandKeyString = @"#";
|
|||
|
||||
if (_mcell_belongs_to_popupbutton && _cell.image_position)
|
||||
{
|
||||
// Special case: draw image on the extreme right
|
||||
cellFrame.origin.x += [_menuView imageAndTitleOffset];
|
||||
cellFrame.size.width = _titleWidth;
|
||||
// TODO: Need to find this out somehow...Testplant-MAL
|
||||
static const NSUInteger ButtonMargin = 5;
|
||||
// Special case: image is drawn on the extreme right
|
||||
// First inset the title rect...Testplant-MAL
|
||||
cellFrame = NSInsetRect(cellFrame, ButtonMargin, 0);
|
||||
// Adjust for image on right side i.e. down arrow popup indicator...Testplant-MAL
|
||||
cellFrame.size.width -= _imageWidth + ButtonMargin;
|
||||
return cellFrame;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue