Licensing ITMac under the GNU Lesser General Public License version 2.1.
[ITMac.git] / ITMacResource.m
1 #import "ITMacResource.h"
2
3 @implementation ITMacResource
4
5 + (Class)subclassForType:(ITMacResourceType)type {
6         NSEnumerator *subclassEnumerator = [[self subclasses] objectEnumerator];
7         Class subclass;
8         
9         while ((subclass = [subclassEnumerator nextObject])) {
10                 if ([subclass supportsResourceType:type]) {
11                         return subclass;
12                 }
13         }
14         
15         return self;
16 }
17
18 + (NSArray *)supportedResourceTypes {
19         return [NSArray array];
20 }
21
22 + (BOOL)supportsResourceType:(ITMacResourceType)type {
23         return [[self supportedResourceTypes] containsObject:[NSString stringWithFourCharCode:type]];
24 }
25
26 + (id)resourceWithHandle:(Handle)handle {
27         return [[[self alloc] initWithHandle:handle] autorelease];
28 }
29
30 - (id)initWithHandle:(Handle)handle {
31         if (self = [super init]) {
32                 _handle = handle;
33         }
34         return self;
35 }
36
37 - (Handle)handle {
38         return _handle;
39 }
40
41 - (NSData *)data {
42         NSData *_data;
43         HLock(_handle);
44         _data = [NSData dataWithBytes:(*_handle) length:GetHandleSize(_handle)];
45         HUnlock(_handle);
46         return _data;
47 }
48
49 - (ITMacResourceType)type {
50         short _id;
51         ResType _type;
52         Str255 _name;
53         GetResInfo(_handle, &_id, &_type, _name);
54         return (ITMacResourceType)_type;
55 }
56
57 - (short)id {
58         short _id;
59         ResType _type;
60         Str255 _name;
61         GetResInfo(_handle, &_id, &_type, _name);
62         return _id;
63 }
64
65 - (NSString *)name {
66         short _id;
67         ResType _type;
68         Str255 _name;
69         GetResInfo(_handle, &_id, &_type, _name);
70         return [(NSString*)CFStringCreateWithPascalString(NULL, 
71 _name, kCFStringEncodingMacRomanLatin1) autorelease];
72 }
73
74 - (Class)nativeRepresentationClass {
75         return nil;
76 }
77
78 - (id)nativeRepresentation {
79         return nil;
80 }
81
82 - (void)dealloc {
83         if (_handle) {
84                 ReleaseResource(_handle);
85         }
86         [super dealloc];
87 }
88
89 @end