root/Trunk/Adium.framework/Versions/A/Headers/IconFamily.h @ 2

Revision 2, 8.5 KB (checked in by jon, 16 years ago)

Initial commit of skeletal project.

Line 
1// IconFamily.h
2// IconFamily class interface
3// by Troy Stephens, Thomas Schnitzer, David Remahl, Nathan Day, Ben Haller, Sven Janssen, Peter Hosey, Conor Dearden, and Elliot Glaysher
4// version 0.9.2
5//
6// Project Home Page:
7//   http://homepage.mac.com/troy_stephens/software/objects/IconFamily/
8//
9// Problems, shortcomings, and uncertainties that I'm aware of are flagged
10// with "NOTE:".  Please address bug reports, bug fixes, suggestions, etc.
11// to me at troy_stephens@mac.com
12
13/*
14    Copyright (c) 2001-2006 Troy N. Stephens
15
16    Use and distribution of this source code is governed by the MIT License, whose terms are as follows.
17
18    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
19
20    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
21
22    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23*/
24
25#import <Carbon/Carbon.h>
26
27// This class is a Cocoa/Objective-C wrapper for the Mac OS X Carbon API's
28// "icon family" data type.  Its main purpose is to enable Cocoa applications
29// to easily create custom file icons from NSImage instances, and thus take
30// advantage of Mac OS X's new 128x128 RGBA "thumbnail" icon format to provide
31// richly detailed thumbnail previews of the files' contents.
32//
33// Using IconFamily, this becomes as simple as:
34//
35//      id iconFamily = [IconFamily iconFamilyWithThumbnailsOfImage:anImage];
36//      [iconFamily setAsCustomIconForFile:anExistingFile];
37//
38// You can also write an icon family to an .icns file using the -writeToFile:
39// method.
40
41@interface IconFamily : NSObject
42{
43    IconFamilyHandle hIconFamily;
44}
45
46// Convenience methods.  These use the corresponding -init... methods to return
47// an autoreleased IconFamily instance.
48
49+ (IconFamily*) iconFamily;
50+ (IconFamily*) iconFamilyWithContentsOfFile:(NSString*)path;
51+ (IconFamily*) iconFamilyWithIconOfFile:(NSString*)path;
52+ (IconFamily*) iconFamilyWithIconFamilyHandle:(IconFamilyHandle)hNewIconFamily;
53+ (IconFamily*) iconFamilyWithSystemIcon:(int)fourByteCode;
54+ (IconFamily*) iconFamilyWithThumbnailsOfImage:(NSImage*)image;
55+ (IconFamily*) iconFamilyWithThumbnailsOfImage:(NSImage*)image usingImageInterpolation:(NSImageInterpolation)imageInterpolation;
56
57// Initializes as a new, empty IconFamily.  This is IconFamily's designated
58// initializer method.
59
60- init;
61
62// Initializes an IconFamily by loading the contents of an .icns file.
63
64- initWithContentsOfFile:(NSString*)path;
65
66// Initializes an IconFamily from an existing Carbon IconFamilyHandle.
67
68- initWithIconFamilyHandle:(IconFamilyHandle)hNewIconFamily;
69
70// Initializes an IconFamily by loading the Finder icon that's assigned to a
71// file.
72
73- initWithIconOfFile:(NSString*)path;
74
75// Initializes an IconFamily by referencing a standard system icon.
76
77- initWithSystemIcon:(int)fourByteCode;
78
79// Initializes an IconFamily by creating its elements from a resampled
80// NSImage.  The second form of this method allows you to specify the degree
81// of antialiasing to be used in resampling the image, by passing in one of
82// the NSImageInterpolation... constants that are defined in
83// NSGraphicsContext.h.  The first form of this initializer simply calls the
84// second form with imageInterpolation set to NSImageInterpolationHigh, which
85// produces highly smoothed thumbnails.
86
87- initWithThumbnailsOfImage:(NSImage*)image;
88- initWithThumbnailsOfImage:(NSImage*)image usingImageInterpolation:(NSImageInterpolation)imageInterpolation;
89
90// Writes the icon family to an .icns file.
91
92- (BOOL) writeToFile:(NSString*)path;
93
94// Sets the image data for one of the icon family's elements from an
95// NSBitmapImageRep.  The "elementType" parameter must be one of the icon
96// family element types listed below, and the format of the "bitmapImageRep"
97// must match the corresponding requirements specified below.  Regardless of
98// the elementType, the bitmapImageRep must also be non-planar and have 8 bits
99// per sample.
100//
101//  elementType           dimensions   format
102//  -------------------   ----------   ---------------------------------------
103//  kThumbnail32BitData    128 x 128   32-bit RGBA, 32-bit RGB, or 24-bit RGB
104//  kThumbnail8BitMask     128 x 128   32-bit RGBA or 8-bit intensity
105//  kLarge32BitData         32 x  32   32-bit RGBA, 32-bit RGB, or 24-bit RGB
106//  kLarge8BitMask          32 x  32   32-bit RGBA or 8-bit intensity
107//  kLarge1BitMask          32 x  32   32-bit RGBA, 8-bit intensity, or 1-bit
108//  kSmall32BitData         16 x  16   32-bit RGBA, 32-bit RGB, or 24-bit RGB
109//  kSmall8BitMask          16 x  16   32-bit RGBA or 8-bit intensity
110//  kSmall1BitMask          16 x  16   32-bit RGBA, 8-bit intensity, or 1-bit
111//
112// When an RGBA image is supplied to set a "Mask" element, the mask data is
113// taken from the image's alpha channel.
114//
115// NOTE: Setting an IconFamily's kLarge1BitMask seems to damage the IconFamily
116//       for some as yet unknown reason.  (If you then assign the icon family
117//       as a file's custom icon using -setAsCustomIconForFile:, the custom
118//       icon doesn't appear for the file in the Finder.)  However, both
119//       custom icon display and mouse-click hit-testing in the Finder seem to
120//       work fine when we only set the other four elements (thus keeping the
121//       existing kLarge1BitMask from the valid icon family from which we
122//       initialized the IconFamily via -initWithContentsOfFile:, since
123//       IconFamily's -init method is currently broken...), so it seems safe
124//       to just leave the kLarge1BitMask alone.
125
126- (BOOL) setIconFamilyElement:(OSType)elementType
127           fromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep;
128
129// Gets the image data for one of the icon family's elements as a new, 32-bit
130// RGBA NSBitmapImageRep.  The specified elementType should be one of
131// kThumbnail32BitData, kLarge32BitData, or kSmall32BitData.
132//
133// The returned NSBitmapImageRep will have the corresponding 8-bit mask data
134// in its alpha channel, or a fully opaque alpha channel if the icon family
135// has no 8-bit mask data for the specified alpha channel.
136//
137// Returns nil if the requested element cannot be retrieved (e.g. if the
138// icon family has no such 32BitData element).
139
140- (NSBitmapImageRep*) bitmapImageRepWithAlphaForIconFamilyElement:(OSType)elementType;
141
142// Creates and returns an NSImage that contains the icon family's various
143// elements as its NSImageReps.
144
145- (NSImage*) imageWithAllReps;
146
147// NOTE: Planned method -- not yet implemented.
148//
149// Gets the image data for one of the icon family's elements as a new
150// NSBitmapImageRep.  The specified elementType should be one of
151// kThumbnail32BitData, kThumbnail32BitMask, kLarge32BitData, kLarge8BitMask,
152// kLarge1BitMask, kSmall32BitData, kSmall8BitMask, or kSmall1BitMask.
153
154// - (NSBitmapImageRep*) bitmapImageRepForIconFamilyElement:(OSType)elementType;
155
156// Writes the icon family to the resource fork of the specified file as its
157// kCustomIconResource, and sets the necessary Finder bits so the icon will
158// be displayed for the file in Finder views.
159
160- (BOOL) setAsCustomIconForFile:(NSString*)path;
161- (BOOL) setAsCustomIconForFile:(NSString*)path withCompatibility:(BOOL)compat;
162
163// Same as the -setAsCustomIconForFile:... methods, but for folders (directories).
164
165- (BOOL) setAsCustomIconForDirectory:(NSString*)path;
166- (BOOL) setAsCustomIconForDirectory:(NSString*)path withCompatibility:(BOOL)compat;
167
168// Removes the custom icon (if any) from the specified file's resource fork,
169// and clears the necessary Finder bits for the file.  (Note that this is a
170// class method, so you don't need an instance of IconFamily to invoke it.)
171
172+ (BOOL) removeCustomIconFromFile:(NSString*)path;
173
174@end
175
176// Methods for interfacing with the Carbon Scrap Manager (analogous to and
177// interoperable with the Cocoa Pasteboard).
178@interface IconFamily (ScrapAdditions)
179+ (BOOL) canInitWithScrap;
180+ (IconFamily*) iconFamilyWithScrap;
181- initWithScrap;
182- (BOOL) putOnScrap;
183@end
Note: See TracBrowser for help on using the browser.