Author: mlytwyn
Date: Wed Jun 17 19:58:33 2015
New Revision: 38654
URL: http://svn.gna.org/viewcvs/gnustep?rev=38654&view=rev
Log:
Process text for truncation
Modified:
libs/gui/branches/gnustep_testplant_branch/Source/NSCell.m
libs/gui/branches/gnustep_testplant_branch/Source/NSMenuItemCell.m
Modified: libs/gui/branches/gnustep_testplant_branch/Source/NSCell.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/NSCell.m?rev=38654&r1=38653&r2=38654&view=diff
==============================================================================
--- libs/gui/branches/gnustep_testplant_branch/Source/NSCell.m (original)
+++ libs/gui/branches/gnustep_testplant_branch/Source/NSCell.m Wed Jun 17
19:58:33 2015
@@ -2999,6 +2999,57 @@
}
}
+- (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,7 +3070,8 @@
*/
aRect.origin.y = NSMidY (aRect) - titleSize.height/2;
aRect.size.height = titleSize.height;
-
+ aString = [self _resizeAttributedString:aString forRect:aRect];
+
[aString drawInRect: aRect];
}
@@ -3041,7 +3093,8 @@
*/
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);
}
Modified: libs/gui/branches/gnustep_testplant_branch/Source/NSMenuItemCell.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/NSMenuItemCell.m?rev=38654&r1=38653&r2=38654&view=diff
==============================================================================
--- libs/gui/branches/gnustep_testplant_branch/Source/NSMenuItemCell.m
(original)
+++ libs/gui/branches/gnustep_testplant_branch/Source/NSMenuItemCell.m Wed Jun
17 19:58:33 2015
@@ -528,9 +528,13 @@
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;
}
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs