/*************************************************************************
 * File Name: NSImage_MiscExtensions.m
 * Version  : 0.0 alpha
 * Date     : Sun 17-Aug-1997
 *************************************************************************
 *  COPYWHAT (C) 1997 by Tomi Engel
 *
 * This notice may not be removed from this source code.
 * The use and distribution of this software is governed by the
 * terms of the MiscKit license agreement.  Refer to the license
 * document included with the MiscKit distribution for the terms.
 *                    ALL RIGHTS RESERVED
 *
 *************************************************************************
 * Notes      :
 * Bugs       :
 * Author(s)  : tsengel
 * Last update: $Date: 1997/08/17 13:50:37 $
 * History    : $Log: NSImage_MiscExtensions.m,v $
 * History    : Revision 1.1  1997/07/23 13:50:37  tsengel
 * History    : Create classes to handle other image creation
 * History    :
 *************************************************************************/

#import "NSImage_MiscExtensions.h"

@implementation NSImage (MiscExtensions)

+ (id)imageNamed:(NSString *)name inContext:(id)object
/*"
    Just calls imageNamed:inContext:searchAllBundles: with a search applied to all bundles.
"*/
{
    return [self imageNamed:(NSString *)name inContext:(id)object searchAllBundles:YES];
}

+ (id)imageNamed:(NSString *)name inContext:(id)object searchAllBundles:(BOOL)flag
/*"
    First searches in the context of object. If object is a normal instance the it checks the bundle where object came from. If object is a instance of NSBundle we first check that bundle.
    If we were not successful we will try the regular imageNAmed method.
    <<HACK..not yet implemented>> If that still doesn't help we will go out and try to check with all bundles which have been registered up to now.
    <<HACK>> We currently on check for tiff images ! This will change so taht we will accept all valid image formats !
"*/
{
    id		ourImage = nil;
    id		aPath;
    id		aBundle;

    // So first check in the context bundle

    if( [object isKindOfClass:[NSBundle class]] )
        aBundle = object;
    else
        aBundle = [NSBundle bundleForClass:[object class]];

    aPath = [aBundle pathForResource:name ofType:@"tiff"];

    if( aPath )
    {
        // <<NOTE>> Setting the name could be a little smarter.

        ourImage = [[NSImage alloc] initWithContentsOfFile:aPath];
        [ourImage setName:name];
        return [ourImage autorelease];
    }

    // Since we were not succesful yet...try the regular access

    ourImage = [self imageNamed:name];
    if( ourImage ) return [ourImage autorelease];

    // Seems like we really need to check all bundles :-(

    // <<HACK>> Code missing here...we nned to find a smooth way to learn about all loaded bundles.
    // Maybe the MiscBundle class could help here isnce the following only works on 4.x  not 4.0 etc. 
    // + (NSArray *)allBundles;
    // + (NSArray *)allFrameworks;
    //  Maybe we should use the MiscBundle and add these methopds on platforms where they are not supported ??

    return nil;
}

@end
