Fixed a possible crasher where an ITMultilineTextFieldCell is treated as
[ITKit.git] / ITMacResource.m
1 //
2 //  ITMacResource.m
3 //  ITKit
4 //
5 //  Created by Joseph Spiros on Thu Dec 25 2003.
6 //  Copyright (c) 2003 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "ITMacResource.h"
10
11
12 @implementation ITMacResource
13
14 static NSMutableDictionary *_resourceTypeClasses = nil;
15
16 + (void)_registerClass:(Class)class forType:(ITMacResourceType)type {
17     if (!_resourceTypeClasses) {
18         _resourceTypeClasses = [[NSMutableDictionary dictionary] retain];
19     }
20     [_resourceTypeClasses setObject:class forKey:[NSString stringWithCString:(char *)type]];
21 }
22
23 + (Class)_classForType:(ITMacResourceType)type {
24     Class _class = [_resourceTypeClasses objectForKey:[NSString stringWithCString:(char *)type]];
25     return ((_class == nil) ? [ITMacResource class] : _class);
26 }
27
28 + (id)_resourceWithHandle:(Handle)handle { // THIS *WILL* RETURN A MORE SPECIFIC INSTANCE USING THE REGISTRATION DATABASE IF SUCH A CLASS EXISTS
29     return [[[self alloc] _initWithHandle:handle] autorelease];
30 }
31
32 - (id)_initWithHandle:(Handle)handle {
33     if (self = [super init]) {
34         _handle = handle;
35     }
36     return self;
37 }
38
39 - (Handle)_handle {
40     return _handle;
41 }
42
43 - (NSData *)data {
44     NSData *_data;
45     HLock(_handle);
46     _data = [NSData dataWithBytes:(*_handle) length:GetHandleSize(_handle)];
47     HUnlock(_handle);
48     return _data;
49 }
50
51 - (ITMacResourceType)type {
52     short _id;
53     ResType _type;
54     Str255 _name;
55     GetResInfo(_handle, &_id, &_type, _name);
56     return (ITMacResourceType)_type;
57 }
58
59 - (NSNumber *)id {
60     short _id;
61     ResType _type;
62     Str255 _name;
63     GetResInfo(_handle, &_id, &_type, _name);
64     return [NSNumber numberWithShort:_id];
65 }
66
67 - (NSString *)name {
68     short _id;
69     ResType _type;
70     Str255 _name;
71     GetResInfo(_handle, &_id, &_type, _name);
72     return [(NSString*)CFStringCreateWithPascalString(NULL, 
73 _name, kCFStringEncodingMacRomanLatin1) autorelease];
74 }
75
76 - (Class)nativeRepresentationClass {
77     return nil;
78 }
79
80 - (id)nativeRepresentation {
81     return nil;
82 }
83
84 - (void)dealloc {
85     ReleaseResource(_handle);
86     [super dealloc];
87 }
88
89 @end