mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 16:10:48 +00:00
Image cache tidyup
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5345 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8176f4ea09
commit
9a2526aa0f
3 changed files with 277 additions and 306 deletions
|
@ -739,7 +739,7 @@ static NSColor *shadowCol;
|
|||
case NSNullCellType:
|
||||
break;
|
||||
}
|
||||
[controlView unlockFocus];
|
||||
[controlView unlockFocus];
|
||||
}
|
||||
|
||||
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||
|
|
379
Source/NSImage.m
379
Source/NSImage.m
|
@ -94,12 +94,9 @@ static NSString* NSImage_PATH = @"Images";
|
|||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (fileName)
|
||||
[fileName release];
|
||||
if (rep)
|
||||
[rep release];
|
||||
if (bg)
|
||||
[bg release];
|
||||
TEST_RELEASE(fileName);
|
||||
TEST_RELEASE(rep);
|
||||
TEST_RELEASE(bg);
|
||||
NSDeallocateObject(self);
|
||||
}
|
||||
@end
|
||||
|
@ -134,15 +131,20 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
|
|||
- (BOOL) loadFromData: (NSData *)data;
|
||||
- (BOOL) loadFromFile: (NSString *)fileName;
|
||||
- (NSImageRep *) lastRepresentation;
|
||||
- (NSImageRep*) cacheForRep: (NSImageRep*)rep
|
||||
onDevice: (NSDictionary*)deviceDescription;
|
||||
- (NSImageRep*) _doImageCache: (NSDictionary*)deviceDescription;
|
||||
@end
|
||||
|
||||
@implementation NSImage
|
||||
|
||||
/* Class variables and functions for class methods */
|
||||
static NSMutableDictionary* nameDict = nil;
|
||||
static NSDictionary* nsmapping = nil;
|
||||
static NSMutableDictionary *nameDict = nil;
|
||||
static NSDictionary *nsmapping = nil;
|
||||
static NSColor *clearColor = nil;
|
||||
static Class cacheClass = 0;
|
||||
|
||||
+ (void)initialize
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSImage class])
|
||||
{
|
||||
|
@ -156,13 +158,14 @@ static NSDictionary* nsmapping = nil;
|
|||
// initialize the class variables
|
||||
nameDict = [[NSMutableDictionary alloc] initWithCapacity: 10];
|
||||
if (path)
|
||||
nsmapping = [[[NSString stringWithContentsOfFile: path]
|
||||
propertyListFromStringsFileFormat]
|
||||
retain];
|
||||
nsmapping = RETAIN([[NSString stringWithContentsOfFile: path]
|
||||
propertyListFromStringsFileFormat]);
|
||||
clearColor = RETAIN([NSColor clearColor]);
|
||||
cacheClass = [NSCachedImageRep class];
|
||||
}
|
||||
}
|
||||
|
||||
+ imageNamed: (NSString *)aName
|
||||
+ (id) imageNamed: (NSString *)aName
|
||||
{
|
||||
NSString *realName = [nsmapping objectForKey: aName];
|
||||
|
||||
|
@ -252,7 +255,7 @@ static NSDictionary* nsmapping = nil;
|
|||
if (image)
|
||||
{
|
||||
[image setName: aName];
|
||||
[image release]; // Retained in dictionary.
|
||||
RELEASE(image); // Retained in dictionary.
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
@ -272,10 +275,10 @@ static NSDictionary* nsmapping = nil;
|
|||
}
|
||||
|
||||
// Designated initializer for nearly everything.
|
||||
- initWithSize: (NSSize)aSize
|
||||
- (id) initWithSize: (NSSize)aSize
|
||||
{
|
||||
[super init];
|
||||
_reps = [[NSMutableArray arrayWithCapacity: 2] retain];
|
||||
_reps = [[NSMutableArray alloc] initWithCapacity: 2];
|
||||
if (aSize.width && aSize.height)
|
||||
{
|
||||
_size = aSize;
|
||||
|
@ -302,7 +305,7 @@ static NSDictionary* nsmapping = nil;
|
|||
_flags.dataRetained = NO;
|
||||
if (![self useFromFile: fileName])
|
||||
{
|
||||
[self release];
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
@ -318,7 +321,7 @@ static NSDictionary* nsmapping = nil;
|
|||
_flags.dataRetained = YES;
|
||||
if (![self useFromFile: fileName])
|
||||
{
|
||||
[self release];
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
@ -333,14 +336,14 @@ static NSDictionary* nsmapping = nil;
|
|||
{
|
||||
if (![self loadFromData: data])
|
||||
{
|
||||
[self release];
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- initWithPasteboard: (NSPasteboard *)pasteboard
|
||||
- (id) initWithPasteboard: (NSPasteboard *)pasteboard
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
|
@ -356,7 +359,8 @@ static NSDictionary* nsmapping = nil;
|
|||
{
|
||||
if (_size.width == 0)
|
||||
{
|
||||
NSImageRep* rep = [self bestRepresentationForDevice: nil];
|
||||
NSImageRep *rep = [self bestRepresentationForDevice: nil];
|
||||
|
||||
_size = [rep size];
|
||||
}
|
||||
return _size;
|
||||
|
@ -365,52 +369,48 @@ static NSDictionary* nsmapping = nil;
|
|||
- (void) dealloc
|
||||
{
|
||||
[self representations];
|
||||
[_repList release];
|
||||
[_reps release];
|
||||
RELEASE(_repList);
|
||||
RELEASE(_reps);
|
||||
/* Make sure we don't remove name from the nameDict if we are just a copy
|
||||
of the named image, not the original image */
|
||||
if (name && self == [nameDict objectForKey: name])
|
||||
[nameDict removeObjectForKey: name];
|
||||
[name release];
|
||||
RELEASE(name);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- copyWithZone: (NSZone *)zone
|
||||
- (id) copyWithZone: (NSZone *)zone
|
||||
{
|
||||
NSImage* copy;
|
||||
NSImage *copy;
|
||||
|
||||
// FIXME: maybe we should retain if _flags.dataRetained = NO
|
||||
copy = (NSImage*)NSCopyObject (self, 0, zone);
|
||||
|
||||
[name retain];
|
||||
RETAIN(name);
|
||||
copy->_reps = [NSMutableArray new];
|
||||
copy->_repList = [NSMutableArray new];
|
||||
[_color retain];
|
||||
RETAIN(_color);
|
||||
_lockedView = nil;
|
||||
[copy addRepresentations: [[[self representations] copyWithZone: zone]
|
||||
autorelease]];
|
||||
[copy addRepresentations: [self representations]];
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
- (BOOL)setName: (NSString *)string
|
||||
- (BOOL) setName: (NSString *)string
|
||||
{
|
||||
if (!nameDict)
|
||||
nameDict = [[NSMutableDictionary dictionaryWithCapacity: 2] retain];
|
||||
nameDict = [[NSMutableDictionary alloc] initWithCapacity: 2];
|
||||
|
||||
if (!string || [nameDict objectForKey: string])
|
||||
return NO;
|
||||
|
||||
[string retain];
|
||||
if (name)
|
||||
[name release];
|
||||
name = string;
|
||||
ASSIGN(name, string);
|
||||
|
||||
[nameDict setObject: self forKey: name];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSString *)name
|
||||
- (NSString *) name
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
@ -421,7 +421,7 @@ static NSDictionary* nsmapping = nil;
|
|||
_flags.useEPSOnResolutionMismatch = flag;
|
||||
}
|
||||
|
||||
- (BOOL)usesEPSOnResolutionMismatch
|
||||
- (BOOL) usesEPSOnResolutionMismatch
|
||||
{
|
||||
return _flags.useEPSOnResolutionMismatch;
|
||||
}
|
||||
|
@ -431,7 +431,7 @@ static NSDictionary* nsmapping = nil;
|
|||
_flags.colorMatchPreferred = flag;
|
||||
}
|
||||
|
||||
- (BOOL)prefersColorMatch
|
||||
- (BOOL) prefersColorMatch
|
||||
{
|
||||
return _flags.colorMatchPreferred;
|
||||
}
|
||||
|
@ -441,7 +441,7 @@ static NSDictionary* nsmapping = nil;
|
|||
_flags.multipleResolutionMatching = flag;
|
||||
}
|
||||
|
||||
- (BOOL)matchesOnMultipleResolution
|
||||
- (BOOL) matchesOnMultipleResolution
|
||||
{
|
||||
return _flags.multipleResolutionMatching;
|
||||
}
|
||||
|
@ -492,15 +492,18 @@ static NSDictionary* nsmapping = nil;
|
|||
GSRepData *repd = (GSRepData*)[_reps objectAtIndex: i];
|
||||
|
||||
if (repd->bg != nil
|
||||
|| [repd->rep isKindOfClass: [NSCachedImageRep class]] == NO)
|
||||
valid = YES;
|
||||
|| [repd->rep isKindOfClass: cacheClass] == NO)
|
||||
{
|
||||
valid = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
- (void) recache
|
||||
{
|
||||
int i, count;
|
||||
unsigned i, count;
|
||||
|
||||
count = [_reps count];
|
||||
for (i = 0; i < count; i++)
|
||||
|
@ -510,8 +513,7 @@ static NSDictionary* nsmapping = nil;
|
|||
repd = (GSRepData*)[_reps objectAtIndex: i];
|
||||
if (repd->bg != nil)
|
||||
{
|
||||
[repd->bg release];
|
||||
repd->bg = nil;
|
||||
DESTROY(repd->bg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -528,18 +530,13 @@ static NSDictionary* nsmapping = nil;
|
|||
|
||||
- (void) setBackgroundColor: (NSColor *)aColor
|
||||
{
|
||||
if (_color != aColor)
|
||||
{
|
||||
if (_color)
|
||||
[_color release];
|
||||
_color = [aColor retain];
|
||||
}
|
||||
ASSIGN(_color, aColor);
|
||||
}
|
||||
|
||||
- (NSColor *) backgroundColor
|
||||
{
|
||||
if (_color == nil)
|
||||
_color = [[NSColor clearColor] retain];
|
||||
_color = RETAIN(clearColor);
|
||||
return _color;
|
||||
}
|
||||
|
||||
|
@ -575,39 +572,24 @@ static NSDictionary* nsmapping = nil;
|
|||
// a cache and no cache exists, create one and draw the representation in it
|
||||
// If a cache exists, but is not valid, redraw the cache from the original
|
||||
// image (if there is one).
|
||||
- (NSImageRep *)_doImageCache
|
||||
- (NSImageRep *)_doImageCache: (NSDictionary*)deviceDesc
|
||||
{
|
||||
NSImageRep *rep = nil;
|
||||
GSRepData *repd;
|
||||
|
||||
repd = repd_for_rep(_reps, [self bestRepresentationForDevice: nil]);
|
||||
repd = repd_for_rep(_reps, [self bestRepresentationForDevice: deviceDesc]);
|
||||
rep = repd->rep;
|
||||
|
||||
if (doesCaching)
|
||||
if (doesCaching == YES)
|
||||
{
|
||||
/*
|
||||
* If this is not a cached image rep - create a cache to be used to
|
||||
* render the image rep into, and switch to the cached rep.
|
||||
*/
|
||||
if ([rep isKindOfClass: [NSCachedImageRep class]] == NO)
|
||||
if ([rep isKindOfClass: cacheClass] == NO)
|
||||
{
|
||||
NSScreen *cur = [NSScreen mainScreen];
|
||||
NSCachedImageRep *cachedRep;
|
||||
NSSize imageSize;
|
||||
|
||||
imageSize = [self size];
|
||||
if (imageSize.width == 0 || imageSize.height == 0)
|
||||
return nil;
|
||||
|
||||
cachedRep = [[NSCachedImageRep alloc] initWithSize: _size
|
||||
depth: [cur depth]
|
||||
separate: NO
|
||||
alpha: NO];
|
||||
[self addRepresentation: cachedRep];
|
||||
[cachedRep release]; /* Retained in _reps array. */
|
||||
repd = repd_for_rep(_reps, cachedRep);
|
||||
repd->original = rep;
|
||||
rep = repd->rep;
|
||||
rep = [self cacheForRep: rep onDevice: deviceDesc];
|
||||
repd = repd_for_rep(_reps, rep);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -620,21 +602,16 @@ static NSDictionary* nsmapping = nil;
|
|||
NSRect bounds;
|
||||
|
||||
[self lockFocusOnRepresentation: rep];
|
||||
/*
|
||||
* If this is not a cache - the lockFocus will have created a
|
||||
* cache that we can use instead.
|
||||
*/
|
||||
if (repd->original == nil)
|
||||
{
|
||||
repd = repd_for_rep(_reps, [self lastRepresentation]);
|
||||
}
|
||||
bounds = [_lockedView bounds];
|
||||
[_color set];
|
||||
NSEraseRect(bounds);
|
||||
if (_color != nil && [_color isEqual: clearColor] == NO)
|
||||
{
|
||||
[_color set];
|
||||
NSEraseRect(bounds);
|
||||
}
|
||||
[self drawRepresentation: repd->original
|
||||
inRect: NSMakeRect(0, 0, _size.width, _size.height)];
|
||||
[self unlockFocus];
|
||||
repd->bg = [_color copy];
|
||||
repd->bg = _color ? [_color copy] : [clearColor copy];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -662,7 +639,7 @@ static NSDictionary* nsmapping = nil;
|
|||
// xxx If fromRect specifies something other than full image
|
||||
// then we need to construct a subimage to draw
|
||||
|
||||
rep = [self _doImageCache];
|
||||
rep = [self _doImageCache: nil];
|
||||
[self drawRepresentation: rep inRect: rect];
|
||||
}
|
||||
|
||||
|
@ -684,7 +661,7 @@ static NSDictionary* nsmapping = nil;
|
|||
// xxx If fromRect specifies something other than full image
|
||||
// then we need to construct a subimage to draw
|
||||
|
||||
rep = [self _doImageCache];
|
||||
rep = [self _doImageCache: nil];
|
||||
[self drawRepresentation: rep inRect: rect];
|
||||
}
|
||||
|
||||
|
@ -751,9 +728,9 @@ static NSDictionary* nsmapping = nil;
|
|||
if ([array indexOfObject: ext] == NSNotFound)
|
||||
return NO;
|
||||
repd = [GSRepData new];
|
||||
repd->fileName = [fileName retain];
|
||||
repd->fileName = RETAIN(fileName);
|
||||
[_reps addObject: repd];
|
||||
[repd release];
|
||||
RELEASE(repd);
|
||||
_flags.syncLoad = YES;
|
||||
return YES;
|
||||
}
|
||||
|
@ -777,31 +754,12 @@ static NSDictionary* nsmapping = nil;
|
|||
for (i = 0; i < count; i++)
|
||||
{
|
||||
repd = [GSRepData new];
|
||||
repd->rep = [[imageRepArray objectAtIndex: i] retain];
|
||||
repd->rep = RETAIN([imageRepArray objectAtIndex: i]);
|
||||
[_reps addObject: repd];
|
||||
[repd release];
|
||||
RELEASE(repd);
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) useCacheWithDepth: (int)depth
|
||||
{
|
||||
NSSize imageSize;
|
||||
NSCachedImageRep* rep;
|
||||
|
||||
imageSize = [self size];
|
||||
if (!imageSize.width || !imageSize.height)
|
||||
return NO;
|
||||
|
||||
|
||||
// FIXME: determine alpha? separate?
|
||||
rep = [[NSCachedImageRep alloc] initWithSize: _size
|
||||
depth: depth
|
||||
separate: NO
|
||||
alpha: NO];
|
||||
[self addRepresentation: rep];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) removeRepresentation: (NSImageRep *)imageRep
|
||||
{
|
||||
unsigned i;
|
||||
|
@ -824,57 +782,45 @@ static NSDictionary* nsmapping = nil;
|
|||
|
||||
- (void) lockFocus
|
||||
{
|
||||
NSScreen *cur = [NSScreen mainScreen];
|
||||
NSImageRep *rep;
|
||||
|
||||
if (!(rep = [self bestRepresentationForDevice: nil]))
|
||||
{
|
||||
[self useCacheWithDepth: [cur depth]];
|
||||
rep = [self lastRepresentation];
|
||||
if ([rep isKindOfClass: cacheClass] == NO)
|
||||
{
|
||||
rep = [self cacheForRep: rep onDevice: nil];
|
||||
}
|
||||
}
|
||||
[self lockFocusOnRepresentation: rep];
|
||||
}
|
||||
|
||||
- (void) lockFocusOnRepresentation: (NSImageRep *)imageRep
|
||||
{
|
||||
NSScreen *cur = [NSScreen mainScreen];
|
||||
NSWindow *window;
|
||||
|
||||
if (!imageRep)
|
||||
if (imageRep == nil)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"Cannot lock focus on nil rep"];
|
||||
|
||||
if (doesCaching)
|
||||
if (doesCaching == YES)
|
||||
{
|
||||
if (![imageRep isKindOfClass: [NSCachedImageRep class]])
|
||||
{
|
||||
GSRepData *cached;
|
||||
int depth;
|
||||
NSWindow *window;
|
||||
|
||||
if (_flags.unboundedCacheDepth)
|
||||
depth = [cur depth]; // FIXME: get depth correctly
|
||||
else
|
||||
depth = [cur depth];
|
||||
if (![self useCacheWithDepth: depth])
|
||||
{
|
||||
[NSException raise: NSImageCacheException
|
||||
format: @"Unable to create cache"];
|
||||
}
|
||||
cached = repd_for_rep(_reps, [self lastRepresentation]);
|
||||
cached->original = imageRep;
|
||||
imageRep = cached->rep;
|
||||
}
|
||||
window = [(NSCachedImageRep *)imageRep window];
|
||||
_lockedView = [window contentView];
|
||||
[_lockedView lockFocus];
|
||||
if ([imageRep isKindOfClass: cacheClass] == NO)
|
||||
{
|
||||
imageRep = [self cacheForRep: imageRep onDevice: nil];
|
||||
}
|
||||
window = [(NSCachedImageRep *)imageRep window];
|
||||
_lockedView = [window contentView];
|
||||
[_lockedView lockFocus];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) unlockFocus
|
||||
{
|
||||
if (_lockedView)
|
||||
[_lockedView unlockFocus];
|
||||
_lockedView = nil;
|
||||
if (_lockedView != nil)
|
||||
{
|
||||
[_lockedView unlockFocus];
|
||||
_lockedView = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSImageRep *) lastRepresentation
|
||||
|
@ -902,8 +848,7 @@ static NSDictionary* nsmapping = nil;
|
|||
|
||||
/*
|
||||
* What's the best representation? FIXME
|
||||
* At the moment we take the last bitmap we find, or the first
|
||||
* rep of any type if we don't find a bitmap.
|
||||
* At the moment we take the last bitmap we find.
|
||||
*/
|
||||
[_reps getObjects: reps];
|
||||
for (i = 0; i < count; i++)
|
||||
|
@ -914,73 +859,99 @@ static NSDictionary* nsmapping = nil;
|
|||
{
|
||||
rep = repd->rep;
|
||||
}
|
||||
else if (rep == nil)
|
||||
{
|
||||
rep = repd->rep;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If we got a representation - see if we already have it cached.
|
||||
*/
|
||||
if (doesCaching)
|
||||
{
|
||||
if (rep != nil)
|
||||
{
|
||||
GSRepData *invalidCache = nil;
|
||||
GSRepData *validCache = nil;
|
||||
|
||||
/*
|
||||
* Search the cached image reps for any whose original is our
|
||||
* 'best' image rep. See if we can notice any invalidated
|
||||
* cache as we go - if we don't find a valid cache, we want to
|
||||
* re-use an invalidated one rather than createing a new one.
|
||||
*/
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
GSRepData *repd = reps[i];
|
||||
|
||||
if (repd->original == rep)
|
||||
{
|
||||
if (repd->bg == nil)
|
||||
{
|
||||
invalidCache = repd;
|
||||
}
|
||||
else if ([repd->bg isEqual: _color] == YES)
|
||||
{
|
||||
validCache = repd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (validCache)
|
||||
{
|
||||
/*
|
||||
* If the image rep has transparencey and we are drawing
|
||||
* without a background (background is clear) then the
|
||||
* cache can't really be valid 'cos we might be drawing
|
||||
* transparency on top of anything. So we invalidate
|
||||
* the cache by removing the background color information.
|
||||
*/
|
||||
if ([rep hasAlpha]
|
||||
&& [validCache->bg isEqual: [NSColor clearColor]])
|
||||
{
|
||||
[validCache->bg release];
|
||||
validCache->bg = nil;
|
||||
}
|
||||
rep = validCache->rep;
|
||||
}
|
||||
else if (invalidCache)
|
||||
{
|
||||
rep = invalidCache->rep;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rep;
|
||||
}
|
||||
|
||||
- (NSImageRep*) cacheForRep: (NSImageRep*)rep
|
||||
onDevice: (NSDictionary*)deviceDescription
|
||||
{
|
||||
if (doesCaching == YES)
|
||||
{
|
||||
NSImageRep *cacheRep = nil;
|
||||
unsigned count = [_reps count];
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
GSRepData *invalidCache = nil;
|
||||
GSRepData *validCache = nil;
|
||||
GSRepData *reps[count];
|
||||
unsigned i;
|
||||
|
||||
[_reps getObjects: reps];
|
||||
|
||||
/*
|
||||
* Search the cached image reps for any whose original is our
|
||||
* 'best' image rep. See if we can notice any invalidated
|
||||
* cache as we go - if we don't find a valid cache, we want to
|
||||
* re-use an invalidated one rather than createing a new one.
|
||||
*/
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
GSRepData *repd = reps[i];
|
||||
|
||||
if (repd->original == rep)
|
||||
{
|
||||
if (repd->bg == nil)
|
||||
{
|
||||
invalidCache = repd;
|
||||
}
|
||||
else if ([repd->bg isEqual: _color] == YES)
|
||||
{
|
||||
validCache = repd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (validCache != nil)
|
||||
{
|
||||
/*
|
||||
* If the image rep has transparencey and we are drawing
|
||||
* without a background (background is clear) then the
|
||||
* cache can't really be valid 'cos we might be drawing
|
||||
* transparency on top of anything. So we invalidate
|
||||
* the cache by removing the background color information.
|
||||
*/
|
||||
if ([rep hasAlpha] && [validCache->bg isEqual: clearColor])
|
||||
{
|
||||
DESTROY(validCache->bg);
|
||||
}
|
||||
cacheRep = validCache->rep;
|
||||
}
|
||||
else if (invalidCache != nil)
|
||||
{
|
||||
cacheRep = invalidCache->rep;
|
||||
}
|
||||
}
|
||||
if (cacheRep == nil)
|
||||
{
|
||||
NSScreen *cur = [NSScreen mainScreen];
|
||||
NSSize imageSize;
|
||||
GSRepData *repd;
|
||||
|
||||
imageSize = [self size];
|
||||
if (imageSize.width == 0 || imageSize.height == 0)
|
||||
return nil;
|
||||
|
||||
cacheRep = [[cacheClass alloc] initWithSize: _size
|
||||
depth: [cur depth]
|
||||
separate: NO
|
||||
alpha: NO];
|
||||
[self addRepresentation: cacheRep];
|
||||
RELEASE(cacheRep); /* Retained in _reps array. */
|
||||
repd = repd_for_rep(_reps, cacheRep);
|
||||
repd->original = rep;
|
||||
}
|
||||
return cacheRep;
|
||||
}
|
||||
else
|
||||
{
|
||||
return rep;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *) representations
|
||||
{
|
||||
unsigned i, count;
|
||||
|
|
|
@ -120,29 +120,29 @@
|
|||
[self setControlView: controlView];
|
||||
|
||||
// do nothing if cell's frame rect is zero
|
||||
if( NSIsEmptyRect(cellFrame) )
|
||||
if (NSIsEmptyRect(cellFrame))
|
||||
return;
|
||||
|
||||
[controlView lockFocus];
|
||||
// draw the border if needed
|
||||
switch( [self imageFrameStyle] )
|
||||
{
|
||||
case NSImageFrameNone:
|
||||
// nada
|
||||
break;
|
||||
case NSImageFramePhoto:
|
||||
// what does this one look like? TODO (in sync with the rest of the code)
|
||||
break;
|
||||
case NSImageFrameGrayBezel:
|
||||
NSDrawGrayBezel(cellFrame, NSZeroRect);
|
||||
break;
|
||||
case NSImageFrameGroove:
|
||||
NSDrawGroove(cellFrame, NSZeroRect);
|
||||
break;
|
||||
case NSImageFrameButton:
|
||||
NSDrawButton(cellFrame, NSZeroRect);
|
||||
break;
|
||||
}
|
||||
switch ([self imageFrameStyle])
|
||||
{
|
||||
case NSImageFrameNone:
|
||||
// nada
|
||||
break;
|
||||
case NSImageFramePhoto:
|
||||
// FIXME
|
||||
break;
|
||||
case NSImageFrameGrayBezel:
|
||||
NSDrawGrayBezel(cellFrame, NSZeroRect);
|
||||
break;
|
||||
case NSImageFrameGroove:
|
||||
NSDrawGroove(cellFrame, NSZeroRect);
|
||||
break;
|
||||
case NSImageFrameButton:
|
||||
NSDrawButton(cellFrame, NSZeroRect);
|
||||
break;
|
||||
}
|
||||
|
||||
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
||||
[controlView unlockFocus];
|
||||
|
@ -165,7 +165,7 @@ static inline float xRightInRect(NSSize innerSize, NSRect outerRect)
|
|||
|
||||
static inline float yTopInRect(NSSize innerSize, NSRect outerRect, BOOL flipped)
|
||||
{
|
||||
if( flipped )
|
||||
if (flipped)
|
||||
return NSMinY(outerRect);
|
||||
else
|
||||
return MAX(NSMaxY(outerRect) - innerSize.height, 0.0);
|
||||
|
@ -178,7 +178,7 @@ static inline float yCenterInRect(NSSize innerSize, NSRect outerRect, BOOL flipp
|
|||
|
||||
static inline float yBottomInRect(NSSize innerSize, NSRect outerRect, BOOL flipped)
|
||||
{
|
||||
if( flipped )
|
||||
if (flipped)
|
||||
return MAX(NSMaxY(outerRect) - innerSize.height, 0.0);
|
||||
else
|
||||
return NSMinY(outerRect);
|
||||
|
@ -207,85 +207,85 @@ static inline NSSize scaleProportionally(NSSize imageSize, NSRect canvasRect)
|
|||
NSDebugLLog(@"NSImageCell", @"NSImageCell drawInteriorWithFrame called");
|
||||
|
||||
image = [self image];
|
||||
if( !image )
|
||||
if (!image)
|
||||
return;
|
||||
|
||||
// leave room for the frame
|
||||
cellFrame = [self drawingRectForBounds: cellFrame];
|
||||
[controlView lockFocus];
|
||||
|
||||
switch( [self imageScaling] )
|
||||
{
|
||||
case NSScaleProportionally:
|
||||
switch ([self imageScaling])
|
||||
{
|
||||
NSDebugLLog(@"NSImageCell", @"NSScaleProportionally");
|
||||
[image setScalesWhenResized:YES];
|
||||
[image setSize: scaleProportionally(_original_image_size, cellFrame)];
|
||||
break;
|
||||
case NSScaleProportionally:
|
||||
{
|
||||
NSDebugLLog(@"NSImageCell", @"NSScaleProportionally");
|
||||
[image setScalesWhenResized:YES];
|
||||
[image setSize: scaleProportionally(_original_image_size, cellFrame)];
|
||||
break;
|
||||
}
|
||||
case NSScaleToFit:
|
||||
{
|
||||
NSDebugLLog(@"NSImageCell", @"NSScaleToFit");
|
||||
[image setScalesWhenResized:YES];
|
||||
[image setSize: cellFrame.size];
|
||||
break;
|
||||
}
|
||||
case NSScaleNone:
|
||||
{
|
||||
NSDebugLLog(@"NSImageCell", @"NSScaleNone");
|
||||
[image setScalesWhenResized:NO];
|
||||
// don't let the image size overrun the space available
|
||||
if (_original_image_size.width > cellFrame.size.width
|
||||
|| _original_image_size.height > cellFrame.size.height)
|
||||
[image setSize: cellFrame.size];
|
||||
else
|
||||
[image setSize: _original_image_size];
|
||||
break;
|
||||
}
|
||||
}
|
||||
case NSScaleToFit:
|
||||
{
|
||||
NSDebugLLog(@"NSImageCell", @"NSScaleToFit");
|
||||
[image setScalesWhenResized:YES];
|
||||
[image setSize: cellFrame.size];
|
||||
break;
|
||||
}
|
||||
case NSScaleNone:
|
||||
{
|
||||
NSDebugLLog(@"NSImageCell", @"NSScaleNone");
|
||||
[image setScalesWhenResized:NO];
|
||||
// don't let the image size overrun the space available
|
||||
if( _original_image_size.width > cellFrame.size.width ||
|
||||
_original_image_size.height > cellFrame.size.height )
|
||||
[image setSize: cellFrame.size];
|
||||
else
|
||||
[image setSize: _original_image_size];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch( [self imageAlignment] )
|
||||
{
|
||||
case NSImageAlignLeft:
|
||||
position.x = xLeftInRect([image size], cellFrame);
|
||||
position.y = yCenterInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignRight:
|
||||
position.x = xRightInRect([image size], cellFrame);
|
||||
position.y = yCenterInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignCenter:
|
||||
position.x = xCenterInRect([image size], cellFrame);
|
||||
position.y = yCenterInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignTop:
|
||||
position.x = xCenterInRect([image size], cellFrame);
|
||||
position.y = yTopInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignBottom:
|
||||
position.x = xCenterInRect([image size], cellFrame);
|
||||
position.y = yBottomInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignTopLeft:
|
||||
position.x = xLeftInRect([image size], cellFrame);
|
||||
position.y = yTopInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignTopRight:
|
||||
position.x = xRightInRect([image size], cellFrame);
|
||||
position.y = yTopInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignBottomLeft:
|
||||
position.x = xLeftInRect([image size], cellFrame);
|
||||
position.y = yBottomInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignBottomRight:
|
||||
position.x = xRightInRect([image size], cellFrame);
|
||||
position.y = yBottomInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
}
|
||||
switch ([self imageAlignment])
|
||||
{
|
||||
case NSImageAlignLeft:
|
||||
position.x = xLeftInRect([image size], cellFrame);
|
||||
position.y = yCenterInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignRight:
|
||||
position.x = xRightInRect([image size], cellFrame);
|
||||
position.y = yCenterInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignCenter:
|
||||
position.x = xCenterInRect([image size], cellFrame);
|
||||
position.y = yCenterInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignTop:
|
||||
position.x = xCenterInRect([image size], cellFrame);
|
||||
position.y = yTopInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignBottom:
|
||||
position.x = xCenterInRect([image size], cellFrame);
|
||||
position.y = yBottomInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignTopLeft:
|
||||
position.x = xLeftInRect([image size], cellFrame);
|
||||
position.y = yTopInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignTopRight:
|
||||
position.x = xRightInRect([image size], cellFrame);
|
||||
position.y = yTopInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignBottomLeft:
|
||||
position.x = xLeftInRect([image size], cellFrame);
|
||||
position.y = yBottomInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
case NSImageAlignBottomRight:
|
||||
position.x = xRightInRect([image size], cellFrame);
|
||||
position.y = yBottomInRect([image size], cellFrame, is_flipped);
|
||||
break;
|
||||
}
|
||||
|
||||
// account for flipped views
|
||||
if( is_flipped )
|
||||
if (is_flipped)
|
||||
position.y += [image size].height;
|
||||
|
||||
// draw!
|
||||
|
@ -300,18 +300,18 @@ static inline NSSize scaleProportionally(NSSize imageSize, NSRect canvasRect)
|
|||
// Get border size
|
||||
switch (_frameStyle)
|
||||
{
|
||||
case NSImageFrameNone:
|
||||
borderSize = [NSCell sizeForBorderType: NSNoBorder];
|
||||
break;
|
||||
case NSImageFramePhoto:
|
||||
// what does this one look like? TODO (in sync with the rest of the code)
|
||||
borderSize = [NSCell sizeForBorderType: NSNoBorder];
|
||||
break;
|
||||
case NSImageFrameGrayBezel:
|
||||
case NSImageFrameGroove:
|
||||
case NSImageFrameButton:
|
||||
borderSize = [NSCell sizeForBorderType: NSBezelBorder];
|
||||
break;
|
||||
case NSImageFrameNone:
|
||||
borderSize = [NSCell sizeForBorderType: NSNoBorder];
|
||||
break;
|
||||
case NSImageFramePhoto:
|
||||
// FIXME
|
||||
borderSize = [NSCell sizeForBorderType: NSNoBorder];
|
||||
break;
|
||||
case NSImageFrameGrayBezel:
|
||||
case NSImageFrameGroove:
|
||||
case NSImageFrameButton:
|
||||
borderSize = [NSCell sizeForBorderType: NSBezelBorder];
|
||||
break;
|
||||
}
|
||||
|
||||
// Get Content Size
|
||||
|
|
Loading…
Reference in a new issue