mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 15:11:37 +00:00
Cleaned up implementation of NSButtonCell title setting. This allowed to
remove special case from NSCell setString:. Removed unneeded NSSliderCell methods. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@29142 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
4c6d79976d
commit
34aba2af74
4 changed files with 44 additions and 67 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2009-12-19 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSCell.m (-setStringValue:): Remove optimisation for
|
||||
simple string case. Now -setObjectValue: is called in most cases.
|
||||
* Source/NSButtonCell.m (-attributedTitle, -setAttributedTitle:,
|
||||
-title, -setTitle:): Replace calls to super implementation with a
|
||||
simple local implementation.
|
||||
* Source/NSSliderCell.m: Remove most of the value setter methods,
|
||||
as they just duplicated super class behaviour.
|
||||
Move the setContinues: call into the init method.
|
||||
|
||||
2009-12-19 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Headers/AppKit/NSTextTable.h,
|
||||
|
|
|
@ -195,11 +195,18 @@ typedef struct _GSButtonCellFlags
|
|||
}
|
||||
|
||||
/** <p>Returns the NSButtonCell's title.</p>
|
||||
<p>See Also: -setTitle: [NSCell-stringValue]</p>
|
||||
*/
|
||||
- (NSString*) title
|
||||
{
|
||||
return [super stringValue];
|
||||
if (_cell.contents_is_attributed_string == NO)
|
||||
{
|
||||
// If we have a formatter this is also the string of the _object_value
|
||||
return _contents;
|
||||
}
|
||||
else
|
||||
{
|
||||
return [(NSAttributedString *)_contents string];
|
||||
}
|
||||
}
|
||||
|
||||
/** <p>Returns the NSButtonCell's alternate title ( used when highlighted ).
|
||||
|
@ -323,11 +330,11 @@ typedef struct _GSButtonCellFlags
|
|||
}
|
||||
|
||||
/**<p>Sets the NSButtonCell's title to <var>aString</var>.</p>
|
||||
<p>See Also: -title [NSCell-setStringValue:]</p>
|
||||
*/
|
||||
- (void) setTitle: (NSString*)aString
|
||||
{
|
||||
[super setStringValue: aString];
|
||||
ASSIGNCOPY(_contents, aString);
|
||||
_cell.contents_is_attributed_string = NO;
|
||||
}
|
||||
|
||||
/**<p>Sets the NSButtonCell's alternate title ( used when highlighted )
|
||||
|
@ -369,12 +376,27 @@ typedef struct _GSButtonCellFlags
|
|||
|
||||
- (NSAttributedString *)attributedTitle
|
||||
{
|
||||
return [super attributedStringValue];
|
||||
if (_cell.contents_is_attributed_string)
|
||||
{
|
||||
return (NSAttributedString *)_contents;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSDictionary *dict;
|
||||
NSAttributedString *attrStr;
|
||||
|
||||
dict = [self _nonAutoreleasedTypingAttributes];
|
||||
attrStr = [[NSAttributedString alloc] initWithString: _contents
|
||||
attributes: dict];
|
||||
RELEASE(dict);
|
||||
return AUTORELEASE(attrStr);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setAttributedTitle:(NSAttributedString *)aString
|
||||
{
|
||||
[super setAttributedStringValue: aString];
|
||||
ASSIGNCOPY(_contents, aString);
|
||||
_cell.contents_is_attributed_string = YES;
|
||||
}
|
||||
|
||||
- (void)setTitleWithMnemonic:(NSString *)aString
|
||||
|
|
|
@ -335,7 +335,7 @@ static NSColor *dtxtCol;
|
|||
_cell.contents_is_attributed_string = YES;
|
||||
_cell.has_valid_object_value = YES;
|
||||
}
|
||||
else if([_object_value respondsToSelector: @selector(stringValue)])
|
||||
else if ([_object_value respondsToSelector: @selector(stringValue)])
|
||||
{
|
||||
// If the thing that was assigned is not a string, but
|
||||
// responds to stringValue then get that.
|
||||
|
@ -433,20 +433,7 @@ static NSColor *dtxtCol;
|
|||
|
||||
if (_formatter == nil)
|
||||
{
|
||||
/* if we are a string, we do an optimization and set the value here instead of
|
||||
* using setObjectValue.
|
||||
* also, we check for nil, since isKindOfClass fails for nil objects */
|
||||
if (aString == nil || [aString isKindOfClass: [NSString class]] == YES)
|
||||
{
|
||||
ASSIGN (_contents, aString);
|
||||
ASSIGN (_object_value, aString);
|
||||
_cell.contents_is_attributed_string = NO;
|
||||
_cell.has_valid_object_value = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
[self setObjectValue: aString];
|
||||
}
|
||||
[self setObjectValue: aString];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -142,7 +142,8 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
|
|||
[self setMaxValue: 1];
|
||||
_cell.is_bordered = YES;
|
||||
_cell.is_bezeled = NO;
|
||||
|
||||
[self setContinuous: YES];
|
||||
|
||||
_knobCell = [NSCell new];
|
||||
_titleCell = [NSTextFieldCell new];
|
||||
[_titleCell setTextColor: [NSColor controlTextColor]];
|
||||
|
@ -395,7 +396,7 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
|
|||
[self setDoubleValue: _maxValue];
|
||||
}
|
||||
|
||||
- (void) setObjectValue:(id)anObject
|
||||
- (void) setObjectValue: (id)anObject
|
||||
{
|
||||
// We substitute an NSNumber containing minValue or maxValue if the given
|
||||
// object's doubleValue lies outside the allowed range, matching OS X
|
||||
|
@ -414,49 +415,6 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
|
|||
[super setObjectValue: [NSNumber numberWithDouble: _minValue]];
|
||||
}
|
||||
|
||||
- (void) setStringValue:(NSString *)aString
|
||||
{
|
||||
// We call setDoubleValue with minValue or maxValue if the given string's
|
||||
// doubleValue lies outside the allowed range.
|
||||
double aDouble = [aString doubleValue];
|
||||
if (aDouble < _minValue)
|
||||
[super setDoubleValue: _minValue];
|
||||
else if (aDouble > _maxValue)
|
||||
[super setDoubleValue: _maxValue];
|
||||
else
|
||||
[super setStringValue: aString];
|
||||
}
|
||||
|
||||
- (void) setDoubleValue:(double)aDouble
|
||||
{
|
||||
if (aDouble < _minValue)
|
||||
[super setDoubleValue: _minValue];
|
||||
else if (aDouble > _maxValue)
|
||||
[super setDoubleValue: _maxValue];
|
||||
else
|
||||
[super setDoubleValue: aDouble];
|
||||
}
|
||||
|
||||
- (void) setFloatValue:(float)aFloat
|
||||
{
|
||||
if (aFloat < _minValue)
|
||||
[super setDoubleValue: _minValue];
|
||||
else if (aFloat > _maxValue)
|
||||
[super setDoubleValue: _maxValue];
|
||||
else
|
||||
[super setFloatValue: aFloat];
|
||||
}
|
||||
|
||||
- (void) setIntValue:(int)anInt
|
||||
{
|
||||
if (anInt < _minValue)
|
||||
[super setDoubleValue: _minValue];
|
||||
else if (anInt > _maxValue)
|
||||
[super setDoubleValue: _maxValue];
|
||||
else
|
||||
[super setIntValue: anInt];
|
||||
}
|
||||
|
||||
/**<p>Returns the cell used to draw the title.</p>
|
||||
<p>See Also: -setTitleCell:</p> */
|
||||
- (id) titleCell
|
||||
|
@ -825,7 +783,6 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
|
|||
// information is not in the nib.
|
||||
[self setBordered: YES];
|
||||
[self setBezeled: NO];
|
||||
[self setContinuous: YES];
|
||||
_isVertical = -1;
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue