Home Page - SourceForge Project Page

IconFamily

Inherits from:
Conforms to:
Declared in:
IconFamily.h

IconFamily is a Cocoa/Objective-C wrapper for the Mac OS X Carbon API's "icon family" data type. Its main purpose is to enable Cocoa applications to easily create custom file icons from NSImage instances, and thus take advantage of Mac OS X's high-resolution RGBA "thumbnail" icon formats to provide richly detailed thumbnail previews of the files' contents.

Using IconFamily, this becomes as simple as:

id iconFamily = [IconFamily iconFamilyWithThumbnailsOfImage:anImage];
[iconFamily setAsCustomIconForFile:anExistingFile];

You can also write an icon family to an .icns file using the -writeToFile: method.

Method Types

Setting an IconFamily's elements
Writing .icns files
Interfacing with the pasteboard (Carbon scrap manager)

Class Methods

+ (BOOL) canInitWithScrap

Returns YES if an IconFamily can be created from 'icns' data on the pasteboard, NO if no such data is present.

+ (IconFamily*) iconFamily

Returns an autoreleased IconFamily initialized using the -init method.

+ (IconFamily*) iconFamilyWithContentsOfFile:(NSString*)path

Returns an autoreleased IconFamily initialized using the -initWithContentsOfFile: method.

+ (IconFamily*) iconFamilyWithIconFamilyHandle:(IconFamilyHandle)hNewIconFamily

Returns an autoreleased IconFamily initialized using the -initWithIconFamilyHandle: method.

+ (IconFamily*) iconFamilyWithIconOfFile:(NSString*)path

Returns an autoreleased IconFamily initialized using the -initWithIconOfFile: method.

+ (IconFamily*) iconFamilyWithScrap

Returns an autoreleased IconFamily initialized using the -initWithScrap method.

+ (IconFamily*) iconFamilyWithSystemIcon:(int)fourByteCode

Returns an autoreleased IconFamily initialized using the -initWithSystemIcon: method.

+ (IconFamily*) iconFamilyWithThumbnailsOfImage:(NSImage*)image

Returns an autoreleased IconFamily initialized using the -initWithThumbnailsOfImage: method.

+ (IconFamily*) iconFamilyWithThumbnailsOfImage:(NSImage*)image usingImageInterpolation:(NSImageInterpolation)imageInterpolation

Returns an autoreleased IconFamily initialized using the -initWithThumbnailsOfImage:usingImageInterpolation: method.

+ (BOOL) removeCustomIconFromDirectory:(NSString*)path

Removes the custom icon (if any) from the specified folder.

+ (BOOL) removeCustomIconFromFile:(NSString*)path

Removes the custom icon (if any) from the specified file's resource fork, and clears the necessary Finder bits for the file.

Instance Methods

- (NSBitmapImageRep*) bitmapImageRepWithAlphaForIconFamilyElement:(OSType)elementType

Gets the image data for one of the icon family's elements as a new, 32-bit RGBA NSBitmapImageRep. The specified elementType should be one of kIconServices512PixelDataARGB, kIconServices256PixelDataARGB, kThumbnail32BitData, kLarge32BitData, or kSmall32BitData.

The returned NSBitmapImageRep will have the corresponding 8-bit mask data in its alpha channel, or a fully opaque alpha channel if the icon family has no 8-bit mask data for the specified alpha channel.

Returns nil if the requested element cannot be retrieved (e.g. if the icon family has no such 32BitData element).

- (NSImage*) imageWithAllReps

Creates and returns an NSImage that contains the icon family's various elements as its NSImageReps.

- init

Initializes the receiver as a new, empty IconFamily. This is IconFamily's designated initializer method.

- initWithContentsOfFile:(NSString*)path

Initializes an IconFamily by loading the contents of an .icns file.

- initWithIconFamilyHandle:(IconFamilyHandle)hNewIconFamily

Initializes an IconFamily from an existing Carbon IconFamilyHandle.

- initWithIconOfFile:(NSString*)path

Initializes an IconFamily by loading the Finder icon that's assigned to a file.

- initWithScrap

Initializes an IconFamily from 'icns' data on the pasteboard. Use +canInitWithScrap to determine whether such data is present.

- initWithSystemIcon:(int)fourByteCode

Initializes an IconFamily by referencing a standard system icon.

- initWithThumbnailsOfImage:(NSImage*)image

Initializes an IconFamily by creating its elements from a resampled NSImage. This is equivalent to invoking -initWithThumbnailsOfImage:usingImageInterpolation: with an imageInterpolation parameter of NSImageInterpolationHigh, which produces highly smoothed thumbnails.

- initWithThumbnailsOfImage:(NSImage*)image usingImageInterpolation:(NSImageInterpolation)imageInterpolation

Initializes an IconFamily by creating its elements from an NSImage, resampled using the interpolation mode specified by imageInterpolation.

- putOnScrap

Copies an IconFamily to the pasteboard as 'icns' data.

- (BOOL) setAsCustomIconForDirectory:(NSString*)path

Performs the same function as -setAsCustomIconForFile:, but is implemented slightly differently as needed for folders (directories).

- (BOOL) setAsCustomIconForDirectory:(NSString*)path withCompatibility:(BOOL)compat

Performs the same function as -setAsCustomIconForFile:withCompatibility:, but is implemented slightly differently as needed for folders (directories).

- (BOOL) setAsCustomIconForFile:(NSString*)path

Writes the icon family to the resource fork of the specified file as its kCustomIconResource, and sets the necessary Finder bits so the icon will be displayed for the file in Finder views. This is equivalent to invoking -setAsCustomIconForFile:withCompatibility: with a compat parameter of NO.

- (BOOL) setAsCustomIconForFile:(NSString*)path withCompatibility:(BOOL)compat

Writes the icon family to the resource fork of the specified file as its kCustomIconResource, and sets the necessary Finder bits so the icon will be displayed for the file in Finder views. If compat is YES, additional copies of the IconFamily's "large" (32 x 32) and "small" (16 x 16) elements will be written to the file's resource fork as separate resources. This takes additional space in the resource fork, but provides compatibility with pre-Mac OS X versions of Finder, which won't otherwise find and display the custom icon.

- (BOOL) setIconFamilyElement:(OSType)elementType fromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep

Sets the image data for one of the icon family's elements from an NSBitmapImageRep. The elementType parameter must be one of the icon family element types listed below, and the format of the bitmapImageRep must match the corresponding requirements specified below. In all cases, the bitmapImageRep must also be non-planar and have 8 bits per sample.

elementTypedimensionsformat
kIconServices512PixelDataARGB512 x 51232-bit RGBA, 32-bit RGB, or 24-bit RGB
kIconServices256PixelDataARGB256 x 25632-bit RGBA, 32-bit RGB, or 24-bit RGB
kThumbnail32BitData128 x 12832-bit RGBA, 32-bit RGB, or 24-bit RGB
kThumbnail8BitMask128 x 12832-bit RGBA or 8-bit intensity
kLarge32BitData32 x 3232-bit RGBA, 32-bit RGB, or 24-bit RGB
kLarge8BitMask32 x 3232-bit RGBA or 8-bit intensity
kLarge1BitMask32 x 3232-bit RGBA, 8-bit intensity, or 1-bit
kSmall32BitData16 x 1632-bit RGBA, 32-bit RGB, or 24-bit RGB
kSmall8BitMask16 x 1632-bit RGBA or 8-bit intensity
kSmall1BitMask16 x 1632-bit RGBA, 8-bit intensity, or 1-bit

When an RGBA image is supplied to set a "Mask" element, the mask data is taken from the image's alpha channel.

- (BOOL) writeToFile:(NSString*)path

Writes the icon family to an .icns file.

SourceForge.net Logo

Validate: xhtml - css