Implemented [initWithBitmapHandle:], [initWithIconHandle:] and

[initWithContentsOfURL:]. [copyWithZone:] dont copy cached image reps.
Allways use [self representations], so that the representation is
loaded if needed.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@8428 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2000-12-24 14:05:12 +00:00
parent a079c95741
commit 8dd31d83b4

View file

@ -125,7 +125,6 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
- (BOOL) _loadFromFile: (NSString *)fileName; - (BOOL) _loadFromFile: (NSString *)fileName;
- (NSImageRep*) _cacheForRep: (NSImageRep*)rep; - (NSImageRep*) _cacheForRep: (NSImageRep*)rep;
- (NSImageRep*) _doImageCache; - (NSImageRep*) _doImageCache;
- (void) _loadImageFilenames;
@end @end
@implementation NSImage @implementation NSImage
@ -330,20 +329,45 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
- (id)initWithBitmapHandle:(void *)bitmap - (id)initWithBitmapHandle:(void *)bitmap
{ {
// Only needed on MS Windows NSImageRep *rep = [[NSBitmapImageRep alloc] initWithBitmapHandle: bitmap];
return nil;
if (rep == nil)
{
RELEASE(self);
return nil;
}
self = [self init];
[self addRepresentation: rep];
return self;
} }
- (id)initWithIconHandle:(void *)icon - (id)initWithIconHandle:(void *)icon
{ {
// Only needed on MS Windows // Only needed on MS Windows
return nil; NSImageRep *rep = [[NSBitmapImageRep alloc] initWithIconHandle: icon];
if (rep == nil)
{
RELEASE(self);
return nil;
}
self = [self init];
[self addRepresentation: rep];
return self;
} }
- (id)initWithContentsOfURL:(NSURL *)anURL - (id)initWithContentsOfURL:(NSURL *)anURL
{ {
// TODO NSArray *array = [NSImageRep imageRepsWithContentsOfURL: anURL];
return nil;
if (!array)
{
RELEASE(self);
return nil;
}
self = [self init];
[self addRepresentations: array];
return self;
} }
- (id) initWithPasteboard: (NSPasteboard *)pasteboard - (id) initWithPasteboard: (NSPasteboard *)pasteboard
@ -402,6 +426,9 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
- (id) copyWithZone: (NSZone *)zone - (id) copyWithZone: (NSZone *)zone
{ {
NSImage *copy; NSImage *copy;
NSArray *reps = [self representations];
NSEnumerator *enumerator = [reps objectEnumerator];
NSImageRep *rep;
// FIXME: maybe we should retain if _flags.dataRetained = NO // FIXME: maybe we should retain if _flags.dataRetained = NO
copy = (NSImage*)NSCopyObject (self, 0, zone); copy = (NSImage*)NSCopyObject (self, 0, zone);
@ -410,9 +437,16 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
RETAIN(_fileName); RETAIN(_fileName);
RETAIN(_color); RETAIN(_color);
copy->_lockedView = nil; copy->_lockedView = nil;
copy->_reps = [NSMutableArray new]; copy->_reps = [[NSMutableArray alloc] initWithCapacity: [_reps count]];
// FIXME: We should not copy cached reps.
[copy addRepresentations: [self representations]]; // Only copy non-cached reps.
while ((rep = [enumerator nextObject]) != nil)
{
if (![rep isKindOfClass: cachedClass])
{
[copy addRepresentation: rep];
}
}
return copy; return copy;
} }
@ -756,41 +790,25 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
- (NSImageRep*) bestRepresentationForDevice: (NSDictionary*)deviceDescription - (NSImageRep*) bestRepresentationForDevice: (NSDictionary*)deviceDescription
{ {
NSImageRep *rep = nil; NSArray *reps = [self representations];
unsigned count; NSEnumerator *enumerator = [reps objectEnumerator];
NSImageRep *rep = nil;
NSImageRep *best = nil;
/* Make sure we have the images loaded in. */ while ((rep = [enumerator nextObject]) != nil)
if (_flags.syncLoad)
[self _loadImageFilenames];
count = [_reps count];
if (count > 0)
{ {
GSRepData *reps[count];
unsigned i;
/* /*
* What's the best representation? FIXME * What's the best representation?
* At the moment we take the last bitmap we find. * FIXME: At the moment we take the last bitmap we find.
* If we can't find a bitmap, we take whatever we can! * If we can't find a bitmap, we take whatever we can.
* Do no change this without changing the Backend stuff on image dragging!
*/ */
[_reps getObjects: reps]; if ([rep isKindOfClass: bitmapClass])
for (i = 0; i < count; i++) best = rep;
{ else if (best == nil)
GSRepData *repd = reps[i]; best = rep;
if ([repd->rep isKindOfClass: bitmapClass])
{
rep = repd->rep;
}
else if (rep == nil)
{
rep = repd->rep;
}
}
} }
return rep; return best;
} }
- (NSArray *) representations - (NSArray *) representations
@ -799,8 +817,12 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
if (_flags.syncLoad) if (_flags.syncLoad)
{ {
[self _loadImageFilenames]; /* Make sure any images that were added with _useFromFile: are loaded
in and added to the representation list. */
[self _loadFromFile: _fileName];
_flags.syncLoad = NO;
} }
count = [_reps count]; count = [_reps count];
if (count == 0) if (count == 0)
{ {
@ -1065,14 +1087,6 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
} }
@implementation NSImage (Private) @implementation NSImage (Private)
/* Make sure any images that were added with _useFromFile: are loaded
in and added to the representation list. */
- (void) _loadImageFilenames
{
[self _loadFromFile: _fileName];
_flags.syncLoad = NO;
}
- (BOOL)_loadFromData: (NSData *)data - (BOOL)_loadFromData: (NSData *)data
{ {