mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:50:48 +00:00
(+imageRepsWithContentsOfFile:): If the filename has no extension, use the data to determine the type.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19726 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0df41169fd
commit
ea3ee18eba
2 changed files with 47 additions and 27 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2004-07-13 02:54 Alexander Malmberg <alexander@malmberg.org>
|
||||||
|
|
||||||
|
* Source/NSImageRep.m (+_imageRepsWithData:): New method.
|
||||||
|
(+imageRepsWithContentsOfURL:): Use +_imageRepsWithData:.
|
||||||
|
(+imageRepsWithContentsOfFile:): If the filename has no extension,
|
||||||
|
use +_imageRepsWithData: to load it.
|
||||||
|
|
||||||
2004-07-13 01:15 Alexander Malmberg <alexander@malmberg.org>
|
2004-07-13 01:15 Alexander Malmberg <alexander@malmberg.org>
|
||||||
|
|
||||||
* Source/NSWindow.m (+_handleAutodisplay:, +_addAutodisplayedWindow:,
|
* Source/NSWindow.m (+_handleAutodisplay:, +_addAutodisplayedWindow:,
|
||||||
|
|
|
@ -156,6 +156,39 @@ static Class NSImageRep_class = NULL;
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Helper for +imageRepsWithContentsOfFile: and imageRepsWithContentsOfURL:.
|
||||||
|
It would make sense (and make initialization of images from data more natural
|
||||||
|
for the user) to make this a real method and call it +imageRepsWithData:, but
|
||||||
|
that's already the name of one of the method concrete image reps need to
|
||||||
|
implement, so we can't do that. */
|
||||||
|
+ (NSArray *) _imageRepsWithData: (NSData *)data
|
||||||
|
{
|
||||||
|
Class rep;
|
||||||
|
|
||||||
|
if (self == NSImageRep_class)
|
||||||
|
{
|
||||||
|
rep = [self imageRepClassForData: data];
|
||||||
|
}
|
||||||
|
else if ([self canInitWithData: data])
|
||||||
|
{
|
||||||
|
rep = self;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return nil;
|
||||||
|
|
||||||
|
if ([rep respondsToSelector: @selector(imageRepsWithData:)])
|
||||||
|
return [rep imageRepsWithData: data];
|
||||||
|
else if ([rep respondsToSelector: @selector(imageRepWithData:)])
|
||||||
|
{
|
||||||
|
NSImageRep *imageRep = [rep imageRepWithData: data];
|
||||||
|
|
||||||
|
if (imageRep != nil)
|
||||||
|
return [NSArray arrayWithObject: imageRep];
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
+ (NSArray *) imageRepsWithContentsOfFile: (NSString *)filename
|
+ (NSArray *) imageRepsWithContentsOfFile: (NSString *)filename
|
||||||
{
|
{
|
||||||
NSString *ext;
|
NSString *ext;
|
||||||
|
@ -165,9 +198,11 @@ static Class NSImageRep_class = NULL;
|
||||||
ext = [filename pathExtension];
|
ext = [filename pathExtension];
|
||||||
if (!ext)
|
if (!ext)
|
||||||
{
|
{
|
||||||
// FIXME: Should this be an exception?
|
/* With no extension, we can't tell the type from the file name.
|
||||||
NSLog(@"Extension missing from image filename - '%@'", filename);
|
Use the data instead. */
|
||||||
return nil;
|
NSData *data;
|
||||||
|
data = [NSData dataWithContentsOfFile: filename];
|
||||||
|
return [self _imageRepsWithData: data];
|
||||||
}
|
}
|
||||||
ext = [ext lowercaseString];
|
ext = [ext lowercaseString];
|
||||||
|
|
||||||
|
@ -212,34 +247,12 @@ static Class NSImageRep_class = NULL;
|
||||||
|
|
||||||
+ (NSArray *)imageRepsWithContentsOfURL:(NSURL *)anURL
|
+ (NSArray *)imageRepsWithContentsOfURL:(NSURL *)anURL
|
||||||
{
|
{
|
||||||
Class rep;
|
NSData *data;
|
||||||
NSData* data;
|
|
||||||
|
|
||||||
// FIXME: Should we use the file type for URLs or only check the data?
|
// FIXME: Should we use the file type for URLs or only check the data?
|
||||||
data = [anURL resourceDataUsingCache: YES];
|
data = [anURL resourceDataUsingCache: YES];
|
||||||
|
|
||||||
if (self == NSImageRep_class)
|
return [self _imageRepsWithData: data];
|
||||||
{
|
|
||||||
rep = [self imageRepClassForData: data];
|
|
||||||
}
|
|
||||||
else if ([self canInitWithData: data])
|
|
||||||
{
|
|
||||||
rep = self;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
if ([rep respondsToSelector: @selector(imageRepsWithData:)])
|
|
||||||
return [rep imageRepsWithData: data];
|
|
||||||
else if ([rep respondsToSelector: @selector(imageRepWithData:)])
|
|
||||||
{
|
|
||||||
NSImageRep *imageRep = [rep imageRepWithData: data];
|
|
||||||
|
|
||||||
if (imageRep != nil)
|
|
||||||
return [NSArray arrayWithObject: imageRep];
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (id) imageRepWithPasteboard: (NSPasteboard *)pasteboard
|
+ (id) imageRepWithPasteboard: (NSPasteboard *)pasteboard
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue