Add code from Eggplant to shorten strings when displaying in a rect.

This code has been partially rewritten.
This commit is contained in:
fredkiefer 2019-12-10 22:23:51 +01:00
parent f30ec504a4
commit 4b8a25072c

View file

@ -2,7 +2,7 @@
<abstract>The abstract cell class</abstract>
Copyright (C) 1996-2012 Free Software Foundation, Inc.
Copyright (C) 1996-2012,2019 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: 1996
@ -27,8 +27,8 @@
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
@ -134,7 +134,7 @@ static NSColor *dtxtCol;
return NSFocusRingTypeDefault;
}
/**<p>This class method returns NO. This method should be overrided by
/**<p>This class method returns NO. This method should be overrided by
subclasses.</p>
*/
+ (BOOL) prefersTrackingUntilMouseUp
@ -150,8 +150,8 @@ static NSColor *dtxtCol;
return [self initTextCell: @""];
}
/**<p>Initializes and returns a new NSCell with a NSImage <var>anImage</var>.
This method sets the image position to <ref type="type"
/**<p>Initializes and returns a new NSCell with a NSImage <var>anImage</var>.
This method sets the image position to <ref type="type"
id="NSCellImagePosition">NSImageOnly</ref> and the cell's type to
<ref type="type" id="NSCellType">NSImageCellType</ref>.</p>
<p>See Also: -initTextCell: </p>
@ -187,7 +187,7 @@ static NSColor *dtxtCol;
return self;
}
/**<p>Initializes and returns a new NSCell with a NSString aString.
/**<p>Initializes and returns a new NSCell with a NSString aString.
This method sets the cell's type to <ref type="type" id="NSCellType">
NSTextCellType</ref>.</p>
<p>See Also: -initImageCell: </p>
@ -339,19 +339,19 @@ static NSColor *dtxtCol;
}
}
- (void) setObjectValue: (id)object
- (void) setObjectValue: (id)object
{
id newContents;
ASSIGN (_object_value, object);
if (_formatter == nil)
if (_formatter == nil)
{
if (object == nil || [object isKindOfClass: [NSString class]] == YES)
{
newContents = object;
_cell.contents_is_attributed_string = NO;
_cell.has_valid_object_value = YES;
// If we are in single line mode, trim the new line characters
if(_cell.uses_single_line_mode == YES)
{
@ -380,7 +380,7 @@ static NSColor *dtxtCol;
}
else if ([_object_value respondsToSelector: @selector(stringValue)])
{
// If the thing that was assigned is not a string, but
// If the thing that was assigned is not a string, but
// responds to stringValue then get that.
newContents = [_object_value stringValue];
_cell.contents_is_attributed_string = NO;
@ -412,7 +412,7 @@ static NSColor *dtxtCol;
/**<p>Sets the NSCell's value to aDouble.</p>
*<p>See Also: -doubleValue</p>
*<p>See Also: -doubleValue</p>
*/
- (void) setDoubleValue: (double)aDouble
{
@ -425,16 +425,16 @@ static NSColor *dtxtCol;
}
/**
*<p>Sets the NSCell's value to a aFloat. This used for example in
*<p>Sets the NSCell's value to a aFloat. This used for example in
NSSliderCell</p>
*<p>See Also: -floatValue</p>
*<p>See Also: -floatValue</p>
*/
- (void) setFloatValue: (float)aFloat
{
NSNumber *number;
// NB: GNUstep can set a float value for an image cell.
// NSSliderCell is an example of it!
// NB: GNUstep can set a float value for an image cell.
// NSSliderCell is an example of it!
number = [NSNumber numberWithFloat: aFloat];
[self setObjectValue: number];
@ -443,13 +443,13 @@ static NSColor *dtxtCol;
/**
*<p>Sets the NSCell's value to anInt.</p>
*<p>See Also: -intValue</p>
*<p>See Also: -intValue</p>
*/
- (void) setIntValue: (int)anInt
{
NSNumber *number;
// NB: GNUstep can set an int value for an image cell.
// NB: GNUstep can set an int value for an image cell.
number = [NSNumber numberWithInt: anInt];
[self setObjectValue: number];
@ -457,21 +457,21 @@ static NSColor *dtxtCol;
/**
*<p>Sets the NSCell's value to anInt.</p>
*<p>See Also: -integerValue</p>
*<p>See Also: -integerValue</p>
*/
- (void) setIntegerValue: (NSInteger)anInt
{
NSNumber *number;
// NB: GNUstep can set an int value for an image cell.
// NB: GNUstep can set an int value for an image cell.
number = [NSNumber numberWithInteger: anInt];
[self setObjectValue: number];
}
/**<p>Sets the cell's value to a NSString.
/**<p>Sets the cell's value to a NSString.
The NSCell's type is set to NSTextCellType if needed</p>
<p>See Also: -stringValue</p>
<p>See Also: -stringValue</p>
*/
- (void) setStringValue: (NSString*)aString
{
@ -479,7 +479,7 @@ static NSColor *dtxtCol;
nil. */
if (aString == nil)
{
NSDebugMLLog (@"MacOSXCompatibility",
NSDebugMLLog (@"MacOSXCompatibility",
@"Attempt to use nil as string value");
}
@ -495,9 +495,9 @@ static NSColor *dtxtCol;
else
{
id newObjectValue;
if ([_formatter getObjectValue: &newObjectValue
forString: aString
if ([_formatter getObjectValue: &newObjectValue
forString: aString
errorDescription: NULL])
{
[self setObjectValue: newObjectValue];
@ -524,30 +524,30 @@ static NSColor *dtxtCol;
case NSCellEditable: return _cell.is_editable;
case NSCellHighlighted: return _cell.is_highlighted;
case NSCellIsBordered: return _cell.is_bordered;
case NSCellAllowsMixedState: return _cell.allows_mixed_state;
case NSCellAllowsMixedState: return _cell.allows_mixed_state;
/*
case NSPushInCell: return 0;
case NSChangeGrayCell: return 0;
case NSCellLightsByContents: return 0;
case NSCellLightsByGray: return 0;
case NSChangeBackgroundCell: return 0;
case NSCellLightsByBackground: return 0;
case NSCellChangesContents: return 0;
case NSCellIsInsetButton: return 0;
case NSPushInCell: return 0;
case NSChangeGrayCell: return 0;
case NSCellLightsByContents: return 0;
case NSCellLightsByGray: return 0;
case NSChangeBackgroundCell: return 0;
case NSCellLightsByBackground: return 0;
case NSCellChangesContents: return 0;
case NSCellIsInsetButton: return 0;
*/
case NSCellHasOverlappingImage:
case NSCellHasOverlappingImage:
{
return _cell.image_position == NSImageOverlaps;
}
case NSCellHasImageHorizontal:
case NSCellHasImageHorizontal:
{
return (_cell.image_position == NSImageRight)
return (_cell.image_position == NSImageRight)
|| (_cell.image_position == NSImageLeft);
}
case NSCellHasImageOnLeftOrBottom:
case NSCellHasImageOnLeftOrBottom:
{
return (_cell.image_position == NSImageBelow)
return (_cell.image_position == NSImageBelow)
|| (_cell.image_position == NSImageLeft);
}
default:
@ -556,7 +556,7 @@ static NSColor *dtxtCol;
break;
}
}
return 0;
}
@ -689,7 +689,7 @@ static NSColor *dtxtCol;
{
return;
}
_cell.type = aType;
switch (_cell.type)
{
@ -711,15 +711,15 @@ static NSColor *dtxtCol;
}
/**<p>Returns the cell's type. Returns NSNullCellType if the
cell's type flag is set to NSImageCellType and if the cell's image
is nil. See <ref type="type" id="NSCellType">NSCellType</ref> for more
cell's type flag is set to NSImageCellType and if the cell's image
is nil. See <ref type="type" id="NSCellType">NSCellType</ref> for more
information.</p><p>See Also -setType:</p>
*/
- (NSCellType) type
{
if (_cell.type == NSImageCellType && _cell_image == nil)
return NSNullCellType;
return _cell.type;
}
@ -737,7 +737,7 @@ static NSColor *dtxtCol;
*/
- (void) setEnabled: (BOOL)flag
{
_cell.is_disabled = !flag;
_cell.is_disabled = !flag;
}
/**<p>Returns whether the NSCell has a bezeled border. By default a NSCell
@ -748,7 +748,7 @@ static NSColor *dtxtCol;
return _cell.is_bezeled;
}
/**<p>Returns whether the NSCell has a border. By default a NSCell has
/**<p>Returns whether the NSCell has a border. By default a NSCell has
border</p><p>See Also: -setBordered: -setBezeled: -isBezeled</p>
*/
- (BOOL) isBordered
@ -763,7 +763,7 @@ static NSColor *dtxtCol;
return NO;
}
/**<p>Sets whether the cell has a bezeled border.
/**<p>Sets whether the cell has a bezeled border.
If this method is called, the bordered flag is turn off.
By default a NSCell has no bezeled border</p>
<p>See Also: -isBezeled -setBordered: -isBordered</p>
@ -774,7 +774,7 @@ static NSColor *dtxtCol;
_cell.is_bordered = NO;
}
/**<p>Sets whether the cell has a border. If this method is called,
/**<p>Sets whether the cell has a border. If this method is called,
the bezeled flag is turn off. By default a NSCell has no border</p>
<p>See Also: -isBordered -setBezeled: -isBezeled</p>
*/
@ -815,7 +815,7 @@ static NSColor *dtxtCol;
{
_cell.state = NSOffState;
}
else
else
{
_cell.state = NSMixedState;
}
@ -875,9 +875,9 @@ static NSColor *dtxtCol;
[self setState: [self nextState]];
}
/**<p>Returns the alignment of the text used in the NSCell. See
/**<p>Returns the alignment of the text used in the NSCell. See
<ref type="type" id="NSTextAlignment">NSTextAlignment</ref> for more
informations. By default the text alignment is <ref type="type"
informations. By default the text alignment is <ref type="type"
id="NSTextAlignment">NSJustifiedTextAlignment</ref></p>
<p>See Also: -setAlignment:</p>
*/
@ -902,7 +902,7 @@ static NSColor *dtxtCol;
return _cell.is_editable;
}
/**<p>Returns whether the cell is selectable. This method returns YES if
/**<p>Returns whether the cell is selectable. This method returns YES if
the cell is selectable or editable. NO otherwise</p>
<p>See Also: -setSelectable: -isEditable -setEditable: </p>
*/
@ -919,7 +919,7 @@ static NSColor *dtxtCol;
return _cell.is_scrollable;
}
/**<p>Sets the alignment of the text. See <ref type="type"
/**<p>Sets the alignment of the text. See <ref type="type"
id="NSTextAlignment">NSTextAlignment</ref>.</p><p>See Also: -alignment </p>
*/
- (void) setAlignment: (NSTextAlignment)mode
@ -936,7 +936,7 @@ static NSColor *dtxtCol;
/*
* The cell_editable flag is also checked to see if the cell is
* selectable so turning edit on also turns selectability on (until
* edit is turned off again).
* edit is turned off again).
*/
_cell.is_editable = flag;
}
@ -1005,9 +1005,9 @@ static NSColor *dtxtCol;
if (_formatter != nil)
{
id newObjectValue;
if ([_formatter getObjectValue: &newObjectValue
forString: [attribStr string]
if ([_formatter getObjectValue: &newObjectValue
forString: [attribStr string]
errorDescription: NULL] == YES)
{
[self setObjectValue: newObjectValue];
@ -1034,7 +1034,7 @@ static NSColor *dtxtCol;
NSAttributedString *attrStr;
attributes = [self _nonAutoreleasedTypingAttributes];
attrStr = [_formatter attributedStringForObjectValue: _object_value
attrStr = [_formatter attributedStringForObjectValue: _object_value
withDefaultAttributes: attributes];
RELEASE(attributes);
if (attrStr != nil)
@ -1129,7 +1129,7 @@ static NSColor *dtxtCol;
return NULL;
}
/** <p>Implemented by subclasses to set the action method.
/** <p>Implemented by subclasses to set the action method.
The NSCell implementation raises a NSInternalInconsistencyException</p>
<p>See Also: -action -setTarget: -target</p>
*/
@ -1149,7 +1149,7 @@ static NSColor *dtxtCol;
format: @"attempt to set a target in an NSCell"];
}
/**<p>Implemented by subclass to return the target object.
/**<p>Implemented by subclass to return the target object.
The NSCell implementation returns nil</p>
<p>See Also: -setTarget: -setAction: -action</p>
*/
@ -1177,7 +1177,7 @@ static NSColor *dtxtCol;
{
_action_mask |= NSPeriodicMask;
}
else
else
{
_action_mask &= ~NSPeriodicMask;
}
@ -1194,7 +1194,7 @@ static NSColor *dtxtCol;
return previousMask;
}
/**<p>Returns the NSCell's image if the NSCell's type is <ref type="type"
/**<p>Returns the NSCell's image if the NSCell's type is <ref type="type"
id="NSCellType">NSImageCellType</ref>,
returns nil otherwise.</p>
<p>See Also: -setImage: -setType: -type</p>
@ -1209,24 +1209,24 @@ static NSColor *dtxtCol;
return nil;
}
/**<p>Sets the NSCell's image to anImage. This method sets the cell's type
/**<p>Sets the NSCell's image to anImage. This method sets the cell's type
to NSImageCellType if needed. Raises an NSInvalidArgumentException if
the anImage is not an NSImage (sub)class. The new image is retained and the
old one is released</p><p>See Also: -image</p>
*/
- (void) setImage: (NSImage*)anImage
{
if (anImage)
if (anImage)
{
NSAssert ([anImage isKindOfClass: imageClass],
NSInvalidArgumentException);
}
if (_cell.type != NSImageCellType)
{
[self setType: NSImageCellType];
}
ASSIGN (_cell_image, anImage);
}
@ -1240,7 +1240,7 @@ static NSColor *dtxtCol;
format: @"attempt to set a tag in an NSCell"];
}
/**<p>Implemented by subclasses to Return the tag.
/**<p>Implemented by subclasses to Return the tag.
The NSCell implementation returns -1 </p><p>See Also: -setTag:</p>
*/
- (NSInteger) tag
@ -1268,7 +1268,7 @@ static NSColor *dtxtCol;
[format appendString: @"#"];
}
}
else
else
{
while (leftDigits--)
{
@ -1287,7 +1287,7 @@ static NSColor *dtxtCol;
RELEASE(formatter);
}
- (void) setFormatter: (NSFormatter*)newFormatter
- (void) setFormatter: (NSFormatter*)newFormatter
{
ASSIGN(_formatter, newFormatter);
}
@ -1318,12 +1318,12 @@ static NSColor *dtxtCol;
if ((_formatter != nil) && ![aString isEqualToString: @""])
{
id newObjectValue;
return [_formatter getObjectValue: &newObjectValue
forString: aString
return [_formatter getObjectValue: &newObjectValue
forString: aString
errorDescription: NULL];
}
else
else
{
return YES;
}
@ -1332,7 +1332,7 @@ static NSColor *dtxtCol;
/*
* Menu
*/
- (void) setMenu: (NSMenu*)aMenu
- (void) setMenu: (NSMenu*)aMenu
{
ASSIGN (_menu, aMenu);
}
@ -1342,8 +1342,8 @@ static NSColor *dtxtCol;
return _menu;
}
- (NSMenu*) menuForEvent: (NSEvent*)anEvent
inRect: (NSRect)cellFrame
- (NSMenu*) menuForEvent: (NSEvent*)anEvent
inRect: (NSRect)cellFrame
ofView: (NSView*)aView
{
return [self menu];
@ -1381,7 +1381,7 @@ static NSColor *dtxtCol;
return _cell.is_disabled == NO && _cell.refuses_first_responder == NO;
}
- (void) setShowsFirstResponder: (BOOL)flag
- (void) setShowsFirstResponder: (BOOL)flag
{
_cell.shows_first_responder = flag;
}
@ -1398,10 +1398,10 @@ static NSColor *dtxtCol;
if (r.length > 0)
{
NSUInteger location = r.location;
[self setTitle: [[aString substringToIndex: location]
stringByAppendingString:
[self setTitle: [[aString substringToIndex: location]
stringByAppendingString:
[aString substringFromIndex: NSMaxRange(r)]]];
// TODO: We should underline this character
[self setMnemonicLocation: location];
@ -1419,7 +1419,7 @@ static NSColor *dtxtCol;
return [c substringWithRange: NSMakeRange (location, 1)];
}
- (void) setMnemonicLocation: (NSUInteger)location
- (void) setMnemonicLocation: (NSUInteger)location
{
_cell.mnemonic_location = location;
}
@ -1448,7 +1448,7 @@ static NSColor *dtxtCol;
{
NSView *cv = [self controlView];
if (cv != nil)
if (cv != nil)
[self performClickWithFrame: [cv bounds] inView: cv];
}
@ -1493,17 +1493,17 @@ static NSColor *dtxtCol;
[self setNextState];
if ((controlView != nil) && [controlView canDraw])
{
{
NSWindow *cvWin = [controlView window];
NSDate *limit = [NSDate dateWithTimeIntervalSinceNow: 0.1];
[controlView lockFocus];
[self highlight: YES withFrame: cellFrame inView: controlView];
[cvWin flushWindow];
// Wait approx 1/10 seconds
[[NSRunLoop currentRunLoop] runUntilDate: limit];
[self highlight: NO withFrame: cellFrame inView: controlView];
[cvWin flushWindow];
[controlView unlockFocus];
@ -1587,11 +1587,11 @@ static NSColor *dtxtCol;
_cell.background_style = backgroundStyle;
}
/**<p>Returns the mouse flags. This flags are usally sets in
/**<p>Returns the mouse flags. This flags are usally sets in
the -trackMouse:inRect:ofView:untilMouseUp: method</p>
*/
- (NSInteger) mouseDownFlags
{
{
return _mouse_down_flags;
}
@ -1738,7 +1738,7 @@ static NSColor *dtxtCol;
NSWindow *w = [controlView window];
/*
* Too many periodic events in succession -
* Too many periodic events in succession -
* update the mouse location and reset the counter.
*/
location = [w mouseLocationOutsideOfEventStream];
@ -1777,7 +1777,7 @@ static NSColor *dtxtCol;
{
[self _sendActionFrom: controlView];
}
theEvent = [theApp nextEventMatchingMask: event_mask
untilDate: [NSDate distantFuture]
inMode: NSEventTrackingRunLoopMode
@ -1827,7 +1827,7 @@ static NSColor *dtxtCol;
{
if (_cell.type == NSImageCellType)
{
if ((_cell_image != nil) &&
if ((_cell_image != nil) &&
NSMouseInRect([controlView convertPoint: [event locationInWindow]
fromView: nil],
[self imageRectForBounds: [controlView bounds]],
@ -1894,7 +1894,7 @@ static NSColor *dtxtCol;
}
}
/**<p>Implemented by subclasses to returns the key equivalent.
/**<p>Implemented by subclasses to returns the key equivalent.
The NSCell implementation returns an empty NSString. </p>
*/
- (NSString*) keyEquivalent
@ -1911,11 +1911,11 @@ static NSColor *dtxtCol;
}
/**Returns the minimun size needed to display the NSCell.
This size is calculate by adding :
This size is calculate by adding :
<list>
<item> the borders (plain or bezeled) size</item>
<item> the spacing between the border and inside the cell</item>
<item> the TODO ... if the cell is type of NSTextCellType
<item> the TODO ... if the cell is type of NSTextCellType
or the image size if the cell has a NSImageCellType type.</item>
</list>
<p>This method returns NSZeroSize if the cell has a NSNullCellType type
@ -1934,10 +1934,10 @@ static NSColor *dtxtCol;
aType = NSBezelBorder;
else
aType = NSNoBorder;
borderSize = [[GSTheme theme] sizeForBorderType: aType];
// Add spacing between border and inside
// Add spacing between border and inside
if (_cell.is_bordered || _cell.is_bezeled)
{
borderSize.height += 1;
@ -1984,7 +1984,7 @@ static NSColor *dtxtCol;
// Add in border size
s.width += 2 * borderSize.width;
s.height += 2 * borderSize.height;
return s;
}
@ -2015,7 +2015,7 @@ static NSColor *dtxtCol;
aType = NSBezelBorder;
else
aType = NSNoBorder;
borderSize = [[GSTheme theme] sizeForBorderType: aType];
return NSInsetRect(theRect, borderSize.width, borderSize.height);
}
@ -2027,8 +2027,8 @@ static NSColor *dtxtCol;
if (_cell.type == NSImageCellType)
{
NSRect frame = [self drawingRectForBounds: theRect];
// Add spacing between border and inside
// Add spacing between border and inside
if (_cell.is_bordered || _cell.is_bezeled)
{
frame.origin.x += 3;
@ -2051,8 +2051,8 @@ static NSColor *dtxtCol;
if (_cell.type == NSTextCellType)
{
NSRect frame = [self drawingRectForBounds: theRect];
// Add spacing between border and inside
// Add spacing between border and inside
if (_cell.is_bordered || _cell.is_bezeled)
{
frame.origin.x += 3;
@ -2125,7 +2125,7 @@ static NSColor *dtxtCol;
NSPoint position;
NSRect drawingRect = [self imageRectForBounds: cellFrame];
NSRect rect;
size = [_cell_image size];
position.x = MAX(NSMidX(drawingRect) - (size.width/2.),0.);
position.y = MAX(NSMidY(drawingRect) - (size.height/2.),0.);
@ -2205,8 +2205,8 @@ static NSColor *dtxtCol;
/*
* NB: This has a visible effect only if subclasses override
* drawWithFrame:inView: to draw something special when the
* cell is highlighted.
* NSCell simply draws border+text/image and makes no highlighting,
* cell is highlighted.
* NSCell simply draws border+text/image and makes no highlighting,
* for easier subclassing.
*/
if ([self isOpaque] == NO)
@ -2342,7 +2342,7 @@ static NSColor *dtxtCol;
_cell.in_editing = YES;
}
/**<p>Ends any text editing. This method sets the text object's delegate
/**<p>Ends any text editing. This method sets the text object's delegate
to nil, and remove the NSClipView and the text object used for editing</p>
<p>See Also: -editWithFrame:inView:editor:delegate:event:</p>
*/
@ -2353,7 +2353,7 @@ static NSColor *dtxtCol;
_cell.in_editing = NO;
[textObject setString: @""];
[textObject setDelegate: nil];
clipView = (NSClipView*)[textObject superview];
if ([clipView isKindOfClass: [NSClipView class]])
{
@ -2413,7 +2413,7 @@ static NSColor *dtxtCol;
range: NSMakeRange(selStart, selLength)];
}
- (BOOL) sendsActionOnEndEditing
- (BOOL) sendsActionOnEndEditing
{
return _cell.sends_action_on_end_editing;
}
@ -2477,7 +2477,7 @@ static NSColor *dtxtCol;
cFlags |= (_action_mask & NSLeftMouseDraggedMask) ? 0x100 : 0;
cFlags |= (_action_mask & NSLeftMouseDownMask) ? 0x40000 : 0;
cFlags |= [self isContinuous] ? 0x80000 : 0;
cFlags |= [self isScrollable] ? 0x100000 : 0;
cFlags |= [self isScrollable] ? 0x100000 : 0;
cFlags |= [self isSelectable] ? 0x200000 : 0;
cFlags |= [self isBezeled] ? 0x400000 : 0;
cFlags |= [self isBordered] ? 0x800000 : 0;
@ -2487,7 +2487,7 @@ static NSColor *dtxtCol;
cFlags |= [self isHighlighted] ? 0x40000000 : 0;
cFlags |= ([self state] == NSOnState) ? 0x80000000 : 0;
[aCoder encodeInt: cFlags forKey: @"NSCellFlags"];
// flags part 2
cFlags2 |= ([self usesSingleLineMode] ? 0x40 : 0);
cFlags2 |= (([self allowsUndo] == NO) ? 0x1000 : 0);
@ -2501,7 +2501,7 @@ static NSColor *dtxtCol;
cFlags2 |= [self importsGraphics] ? 0x20000000 : 0;
cFlags2 |= [self allowsEditingTextAttributes] ? 0x40000000 : 0;
[aCoder encodeInt: cFlags2 forKey: @"NSCellFlags2"];
if (_cell.type == NSTextCellType)
{
// font and formatter.
@ -2509,7 +2509,7 @@ static NSColor *dtxtCol;
{
[aCoder encodeObject: [self font] forKey: @"NSSupport"];
}
if ([self formatter])
{
[aCoder encodeObject: [self formatter] forKey: @"NSFormatter"];
@ -2524,7 +2524,7 @@ static NSColor *dtxtCol;
{
BOOL flag;
unsigned int tmp_int;
[aCoder encodeObject: _contents];
[aCoder encodeObject: _cell_image];
[aCoder encodeObject: _font];
@ -2621,13 +2621,13 @@ static NSColor *dtxtCol;
self = [self init];
[self setObjectValue: contents];
}
if ([aDecoder containsValueForKey: @"NSCellFlags"])
{
unsigned long cFlags;
NSUInteger mask = 0;
cFlags = [aDecoder decodeIntForKey: @"NSCellFlags"];
[self setFocusRingType: (cFlags & 0x3)];
[self setShowsFirstResponder: ((cFlags & 0x4) == 0x4)];
// This bit flag is the other way around!
@ -2656,7 +2656,7 @@ static NSColor *dtxtCol;
if ([aDecoder containsValueForKey: @"NSCellFlags2"])
{
int cFlags2;
cFlags2 = [aDecoder decodeIntForKey: @"NSCellFlags2"];
[self setUsesSingleLineMode: (cFlags2 & 0x40)];
[self setControlTint: ((cFlags2 & 0xE0) >> 5)];
@ -2685,7 +2685,7 @@ static NSColor *dtxtCol;
if ([aDecoder containsValueForKey: @"NSFormatter"])
{
NSFormatter *formatter = [aDecoder decodeObjectForKey: @"NSFormatter"];
[self setFormatter: formatter];
}
}
@ -2747,7 +2747,7 @@ static NSColor *dtxtCol;
_cell.state = tmp_int;
[aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &tmp_int];
_cell.mnemonic_location = tmp_int;
[aDecoder decodeValueOfObjCType: @encode(NSUInteger)
[aDecoder decodeValueOfObjCType: @encode(NSUInteger)
at: &_mouse_down_flags];
[aDecoder decodeValueOfObjCType: @encode(NSUInteger) at: &_action_mask];
if (version < 3)
@ -2841,7 +2841,7 @@ static NSColor *dtxtCol;
}
_action_mask = mask;
}
_action_mask |= NSLeftMouseUpMask;
_action_mask |= NSLeftMouseUpMask;
[aDecoder decodeValueOfObjCType: @encode(id) at: &formatter];
[self setFormatter: formatter];
[aDecoder decodeValueOfObjCType: @encode(id) at: &menu];
@ -2882,7 +2882,7 @@ static NSColor *dtxtCol;
wraps attribute. */
[self setWraps: wraps];
}
if (version >= 4)
{
[aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &tmp_int];
@ -2924,13 +2924,13 @@ static NSColor *dtxtCol;
if (_cell.is_disabled)
return dtxtCol;
else
return txtCol;
return txtCol;
}
/* This method is an exception and returns a non-autoreleased
dictionary, so that calling methods can deallocate it immediately
using release. Otherwise if many cells are drawn/their size
computed, we pile up hundreds or thousands of these objects before they
computed, we pile up hundreds or thousands of these objects before they
are deallocated at the end of the run loop. */
- (NSDictionary*) _nonAutoreleasedTypingAttributes
{
@ -2939,14 +2939,14 @@ static NSColor *dtxtCol;
NSMutableParagraphStyle *paragraphStyle;
color = [self textColor];
/* Note: There are only a few possible paragraph styles for cells.
/* Note: There are only a few possible paragraph styles for cells.
TODO: Cache them and reuse them for the whole app lifetime. */
paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setLineBreakMode: [self lineBreakMode]];
[paragraphStyle setBaseWritingDirection: [self baseWritingDirection]];
[paragraphStyle setAlignment: [self alignment]];
attr = [[NSDictionary alloc] initWithObjectsAndKeys:
attr = [[NSDictionary alloc] initWithObjectsAndKeys:
_font, NSFontAttributeName,
color, NSForegroundColorAttributeName,
paragraphStyle, NSParagraphStyleAttributeName,
@ -2977,7 +2977,7 @@ static NSColor *dtxtCol;
- (NSAttributedString*) _drawAttributedString
{
if (!_cell.is_disabled)
{
{
return [self attributedStringValue];
}
else
@ -2985,23 +2985,59 @@ static NSColor *dtxtCol;
NSAttributedString *attrStr = [self attributedStringValue];
NSDictionary *attribs;
NSMutableDictionary *newAttribs;
attribs = [attrStr attributesAtIndex: 0
attribs = [attrStr attributesAtIndex: 0
effectiveRange: NULL];
newAttribs = [NSMutableDictionary dictionaryWithDictionary: attribs];
[newAttribs setObject: [NSColor disabledControlTextColor]
forKey: NSForegroundColorAttributeName];
return AUTORELEASE([[NSAttributedString alloc]
initWithString: [attrStr string]
attributes: newAttribs]);
}
}
- (BOOL) _shouldShortenStringForRect: (NSRect)titleRect size: (NSSize)titleSize length: (NSUInteger)length
{
NSLineBreakMode mode = [self lineBreakMode];
return ((titleSize.width > titleRect.size.width) && (length > 4) &&
(mode == NSLineBreakByTruncatingHead ||
mode == NSLineBreakByTruncatingTail ||
mode == NSLineBreakByTruncatingMiddle));
}
- (NSAttributedString*) _resizeAttributedString: (NSAttributedString*)attrstring forRect: (NSRect)titleRect
{
// Redo string based on selected truncation mask...
NSMutableAttributedString *mutableString = AUTORELEASE([attrstring mutableCopy]);
NSString *ellipsis = @"...";
NSLineBreakMode mode = [self lineBreakMode];
// FIXME: This code shortens the string one character at a time.
// Maybe we should start off propertional: string.length * (string.width - titleRect.width) / string.width
do
{
NSRange replaceRange;
if (mode == NSLineBreakByTruncatingHead)
replaceRange = NSMakeRange(0, 4);
else if (mode == NSLineBreakByTruncatingTail)
replaceRange = NSMakeRange([mutableString length] - 4, 4);
else
replaceRange = NSMakeRange(([mutableString length] / 2) - 2, 4);
[mutableString replaceCharactersInRange: replaceRange withString: ellipsis];
} while ([mutableString length] > 4 && [mutableString size].width > titleRect.size.width);
// Return the modified attributed string...
return attrstring;
}
/**
* Private internal method to display an attributed string.
*/
- (void) _drawAttributedText: (NSAttributedString*)aString
- (void) _drawAttributedText: (NSAttributedString*)aString
inFrame: (NSRect)aRect
{
NSSize titleSize;
@ -3010,13 +3046,18 @@ static NSColor *dtxtCol;
return;
titleSize = [aString size];
if ([self _shouldShortenStringForRect: aRect size: titleSize length: [aString length]])
{
aString = [self _resizeAttributedString: aString forRect: aRect];
titleSize = [aString size];
}
/** Important: text should always be vertically centered without
* considering descender [as if descender did not exist].
* This is particularly important for single line texts.
* Please make sure the output remains always correct.
*/
aRect.origin.y = NSMidY (aRect) - titleSize.height/2;
aRect.origin.y = NSMidY (aRect) - titleSize.height/2;
aRect.size.height = titleSize.height;
[aString drawInRect: aRect];
@ -3032,13 +3073,19 @@ static NSColor *dtxtCol;
attributes = [self _nonAutoreleasedTypingAttributes];
titleSize = [aString sizeWithAttributes: attributes];
if ([self _shouldShortenStringForRect: cellFrame size: titleSize length: [aString length]])
{
NSAttributedString *attrstring = AUTORELEASE([[NSAttributedString alloc] initWithString: aString
attributes: attributes]);
return [self _drawAttributedText: attrstring inFrame: cellFrame];
}
/** Important: text should always be vertically centered without
* considering descender [as if descender did not exist].
* This is particularly important for single line texts.
* Please make sure the output remains always correct.
*/
cellFrame.origin.y = NSMidY (cellFrame) - titleSize.height/2;
cellFrame.origin.y = NSMidY (cellFrame) - titleSize.height/2;
cellFrame.size.height = titleSize.height;
[aString drawInRect: cellFrame withAttributes: attributes];
@ -3046,7 +3093,7 @@ static NSColor *dtxtCol;
}
// Private helper method overridden in subclasses
- (void) _drawBorderAndBackgroundWithFrame: (NSRect)cellFrame
- (void) _drawBorderAndBackgroundWithFrame: (NSRect)cellFrame
inView: (NSView*)controlView
{
NSBorderType aType;
@ -3082,7 +3129,7 @@ static NSColor *dtxtCol;
case NSFocusRingTypeNone:
default:
break;
}
}
}
}
@ -3128,7 +3175,7 @@ static NSColor *dtxtCol;
{
if (_formatter != nil)
{
NSString *contents;
NSString *contents;
contents = [_formatter editingStringForObjectValue: _object_value];
if (contents == nil)
@ -3156,7 +3203,7 @@ static NSColor *dtxtCol;
}
else
{
NSString *contents;
NSString *contents;
if (nil == _contents)
{
@ -3209,7 +3256,7 @@ scaleProportionally(NSSize imageSize, NSSize canvasSize, BOOL scaleUpOrDown)
/* Get the smaller ratio and scale the image size by it. */
ratio = MIN(canvasSize.width / imageSize.width,
canvasSize.height / imageSize.height);
/* Only scale down, unless scaleUpOrDown is YES */
if (ratio < 1.0 || scaleUpOrDown)
{