In [initImageCell:] and [initTextCell:] set the default menu.

In all [XXXValue] methods try to get the value from the objectValue
first and use [stringValue] instead of accessing the contents directly.
Removed AUTORELEASE calls from [attributedStringValue] and similar
places.
In [cellSize] use [attributedStringValue] to get the string to size.
In [drawInteriorWithFrame:inView:] use [attributedStringValue] to
get the string to draw. This make the method [_drawText:inFrame:]
obsolete for this class, but subclasses still use it.
New method [_setupTextWithFrame:inView:editor:] with the common
text view setup from [editWithFrame:inView:editor:delegate:event:]
and [selectWithFrame:inView:editor:delegate:start:length:].
Calls to [setFont:] and [setAlignment:] switch the cell to NSTextCellType.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@14952 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2002-11-07 23:33:33 +00:00
parent fc55efe8ac
commit 27314cde11

View file

@ -51,6 +51,8 @@
#include <AppKit/NSColor.h> #include <AppKit/NSColor.h>
#include <AppKit/NSParagraphStyle.h> #include <AppKit/NSParagraphStyle.h>
#include <AppKit/NSMenu.h> #include <AppKit/NSMenu.h>
#include <AppKit/NSTextView.h>
#include <AppKit/NSTextContainer.h>
#include <AppKit/PSOperators.h> #include <AppKit/PSOperators.h>
#include <AppKit/NSAttributedString.h> #include <AppKit/NSAttributedString.h>
@ -151,6 +153,7 @@ static NSColor *shadowCol;
//_cell.is_continuous = NO; //_cell.is_continuous = NO;
//_cell.state = 0; //_cell.state = 0;
_action_mask = NSLeftMouseUpMask; _action_mask = NSLeftMouseUpMask;
_menu = [isa defaultMenu];
return self; return self;
} }
@ -176,6 +179,7 @@ static NSColor *shadowCol;
//_cell.is_selectable = NO; //_cell.is_selectable = NO;
//_cell.is_continuous = NO; //_cell.is_continuous = NO;
_action_mask = NSLeftMouseUpMask; _action_mask = NSLeftMouseUpMask;
_menu = [isa defaultMenu];
return self; return self;
} }
@ -215,37 +219,40 @@ static NSColor *shadowCol;
- (double) doubleValue - (double) doubleValue
{ {
if (_cell.contents_is_attributed_string == NO) if ((_cell.has_valid_object_value == YES) &&
([_objectValue respondsToSelector: @selector(doubleValue)]))
{ {
return [_contents doubleValue]; return [_objectValue doubleValue];
} }
else else
{ {
return [[(NSAttributedString *)_contents string] doubleValue]; return [[self stringValue] doubleValue];
} }
} }
- (float) floatValue - (float) floatValue
{ {
if (_cell.contents_is_attributed_string == NO) if ((_cell.has_valid_object_value == YES) &&
([_objectValue respondsToSelector: @selector(floatValue)]))
{ {
return [_contents floatValue]; return [_objectValue floatValue];
} }
else else
{ {
return [[(NSAttributedString *)_contents string] floatValue]; return [[self stringValue] floatValue];
} }
} }
- (int) intValue - (int) intValue
{ {
if (_cell.contents_is_attributed_string == NO) if ((_cell.has_valid_object_value == YES) &&
([_objectValue respondsToSelector: @selector(intValue)]))
{ {
return [_contents intValue]; return [_objectValue intValue];
} }
else else
{ {
return [[(NSAttributedString *)_contents string] intValue]; return [[self stringValue] intValue];
} }
} }
@ -253,11 +260,12 @@ static NSColor *shadowCol;
{ {
if (_cell.contents_is_attributed_string == NO) if (_cell.contents_is_attributed_string == NO)
{ {
// If we have a formatter this is also the string of the _objectValue
return _contents; return _contents;
} }
else else
{ {
return AUTORELEASE ([[(NSAttributedString *)_contents string] copy]); return [(NSAttributedString *)_contents string];
} }
} }
@ -713,6 +721,7 @@ static NSColor *shadowCol;
- (void) setAlignment: (NSTextAlignment)mode - (void) setAlignment: (NSTextAlignment)mode
{ {
// This does not have any influence on attributed strings
_cell.text_align = mode; _cell.text_align = mode;
} }
@ -728,7 +737,13 @@ static NSColor *shadowCol;
- (void) setFont: (NSFont*)fontObject - (void) setFont: (NSFont*)fontObject
{ {
// This does not have any influence on attributed strings
ASSIGN (_font, fontObject); ASSIGN (_font, fontObject);
if (_cell.type != NSTextCellType)
{
_cell.type = NSTextCellType;
}
} }
- (void) setSelectable: (BOOL)flag - (void) setSelectable: (BOOL)flag
@ -793,10 +808,10 @@ static NSColor *shadowCol;
NSDictionary *attributes; NSDictionary *attributes;
NSAttributedString *attrStr; NSAttributedString *attrStr;
attributes = AUTORELEASE ([self _nonAutoreleasedTypingAttributes]); attributes = [self _nonAutoreleasedTypingAttributes];
attrStr = [_formatter attributedStringForObjectValue: _objectValue attrStr = [_formatter attributedStringForObjectValue: _objectValue
withDefaultAttributes: attributes]; withDefaultAttributes: attributes];
RELEASE(attributes);
if (attrStr != nil) if (attrStr != nil)
{ {
return attrStr; return attrStr;
@ -813,10 +828,11 @@ static NSColor *shadowCol;
NSDictionary *dict; NSDictionary *dict;
NSAttributedString *attrStr; NSAttributedString *attrStr;
dict = AUTORELEASE ([self _nonAutoreleasedTypingAttributes]); dict = [self _nonAutoreleasedTypingAttributes];
attrStr = [[NSAttributedString alloc] initWithString: _contents attrStr = [[NSAttributedString alloc] initWithString: _contents
attributes: dict]; attributes: dict];
return AUTORELEASE (attrStr); RELEASE(dict);
return AUTORELEASE(attrStr);
} }
} }
@ -1071,16 +1087,7 @@ static NSColor *shadowCol;
- (NSString*) mnemonic - (NSString*) mnemonic
{ {
unsigned int location = [self mnemonicLocation]; unsigned int location = [self mnemonicLocation];
NSString *c; NSString *c = [self stringValue];
if (_cell.contents_is_attributed_string)
{
c = AUTORELEASE ([[(NSAttributedString *)_contents string] copy]);
}
else
{
c = _contents;
}
if ((location == NSNotFound) || location >= [c length]) if ((location == NSNotFound) || location >= [c length])
return @""; return @"";
@ -1468,21 +1475,16 @@ static NSColor *shadowCol;
{ {
case NSTextCellType: case NSTextCellType:
{ {
if (_cell.contents_is_attributed_string) NSAttributedString *attrStr;
attrStr = [self attributedStringValue];
if ([attrStr length] != 0)
{ {
s = [(NSAttributedString *)_contents size]; s = [attrStr size];
} }
else else
{ {
if ((_contents != nil) s = [self _sizeText: @"A"];
&& ([_contents isEqualToString: @""] == NO))
{
s = [self _sizeText: _contents];
}
else
{
s = [self _sizeText: @"A"];
}
} }
} }
break; break;
@ -1597,16 +1599,11 @@ static NSColor *shadowCol;
switch (_cell.type) switch (_cell.type)
{ {
case NSTextCellType: case NSTextCellType:
if (_cell.contents_is_attributed_string) {
{ [self _drawAttributedText: [self attributedStringValue]
[self _drawAttributedText: (NSAttributedString *)_contents inFrame: cellFrame];
inFrame: cellFrame]; }
} break;
else
{
[self _drawText: _contents inFrame: cellFrame];
}
break;
case NSImageCellType: case NSImageCellType:
if (_cell_image) if (_cell_image)
@ -1697,6 +1694,31 @@ static NSColor *shadowCol;
} }
} }
- (void) _setupTextWithFrame: (NSRect)aRect
inView: (NSView*)controlView
editor: (NSText*)textObject
{
NSRect titleRect = [self titleRectForBounds: aRect];
NSSize maxSize = NSMakeSize(3000, titleRect.size.height);
NSClipView *cv = [[NSClipView alloc]
initWithFrame: titleRect];
NSTextContainer *ct = [(NSTextView*)textObject textContainer];
[controlView addSubview: cv];
RELEASE(cv);
[cv setAutoresizesSubviews: NO];
[cv setDocumentView: textObject];
[textObject setFrame: [cv bounds]];
[textObject setHorizontallyResizable: YES];
[textObject setVerticallyResizable: NO];
[textObject setMaxSize: maxSize];
[textObject setMinSize: titleRect.size];
[ct setContainerSize: maxSize];
[ct setHeightTracksTextView: NO];
[ct setWidthTracksTextView: NO];
}
/* /*
* Editing Text * Editing Text
*/ */
@ -1709,32 +1731,9 @@ static NSColor *shadowCol;
if (!controlView || !textObject || (_cell.type != NSTextCellType)) if (!controlView || !textObject || (_cell.type != NSTextCellType))
return; return;
{ [self _setupTextWithFrame: aRect
NSClipView *cv = [[NSClipView alloc] inView: controlView
initWithFrame: editor: textObject];
[self titleRectForBounds: aRect]];
[controlView addSubview: cv];
RELEASE(cv);
[cv setAutoresizesSubviews: NO];
[cv setDocumentView: textObject];
[textObject setFrame: [cv bounds]];
[textObject setHorizontallyResizable: YES];
[textObject setVerticallyResizable: NO];
[textObject
setMaxSize:
NSMakeSize (3000,
[self titleRectForBounds: aRect].size.height)];
[textObject
setMinSize:
[self titleRectForBounds: aRect].size];
[[textObject textContainer]
setContainerSize:
NSMakeSize (3000,
[self titleRectForBounds: aRect].size.height)];
[[textObject textContainer] setHeightTracksTextView: NO];
[[textObject textContainer] setWidthTracksTextView: NO];
}
if (_formatter != nil) if (_formatter != nil)
{ {
@ -1773,6 +1772,7 @@ static NSColor *shadowCol;
- (void) endEditing: (NSText*)textObject - (void) endEditing: (NSText*)textObject
{ {
NSClipView *cv; NSClipView *cv;
[textObject setDelegate: nil]; [textObject setDelegate: nil];
cv = (NSClipView*)[textObject superview]; cv = (NSClipView*)[textObject superview];
[textObject removeFromSuperview]; [textObject removeFromSuperview];
@ -1789,31 +1789,9 @@ static NSColor *shadowCol;
if (!controlView || !textObject || (_cell.type != NSTextCellType)) if (!controlView || !textObject || (_cell.type != NSTextCellType))
return; return;
{ [self _setupTextWithFrame: aRect
NSClipView *cv = [[NSClipView alloc] inView: controlView
initWithFrame: editor: textObject];
[self titleRectForBounds: aRect]];
[controlView addSubview: cv];
RELEASE(cv);
[cv setAutoresizesSubviews: NO];
[cv setDocumentView: textObject];
[textObject setFrame: [cv bounds]];
[textObject setHorizontallyResizable: YES];
[textObject setVerticallyResizable: NO];
[textObject
setMaxSize:
NSMakeSize (3000,
[self titleRectForBounds: aRect].size.height)];
[textObject
setMinSize:
[self titleRectForBounds: aRect].size];
[[textObject textContainer]
setContainerSize:
NSMakeSize (3000,
[self titleRectForBounds: aRect].size.height)];
[[textObject textContainer] setWidthTracksTextView: NO];
[[textObject textContainer] setWidthTracksTextView: NO];
}
if (_formatter != nil) if (_formatter != nil)
{ {