Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 126 lines (106 sloc) 3.915 kb
720b0e7 Uli Kusterer Added licensing information to the source files.
authored
1 //
2 // UKNibOwner.m
3 // CocoaTADS
4 //
5 // Created by Uli Kusterer on 13.11.2004.
6 // Copyright 2004 Uli Kusterer.
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would be
19 // appreciated but is not required.
20 //
21 // 2. Altered source versions must be plainly marked as such, and must not be
22 // misrepresented as being the original software.
23 //
24 // 3. This notice may not be removed or altered from any source
25 // distribution.
26 //
dc5be1c Initial check-in.
uli authored
27
28 // -----------------------------------------------------------------------------
29 // Headers:
30 // -----------------------------------------------------------------------------
31
32 #import "UKNibOwner.h"
33
34
35 @implementation UKNibOwner
36
37 // -----------------------------------------------------------------------------
38 // init:
39 // Create this object and load NIB file. Note that for subclasses, this
40 // is called before your subclass has been fully constructed. I know this
41 // sucks, because awakeFromNib can't rely on stuff that's done in the
42 // constructor. I'll probably change this eventually.
43 //
44 // REVISIONS:
45 // 2004-12-23 UK Documented.
46 // -----------------------------------------------------------------------------
47
48 -(id) init
49 {
6290385 UKNibOwner can be created for different NIBs and owners. Can release top...
uli authored
50 return [self initWithNibName: [self nibFilename] owner: self];
51 }
52
53 -(id) initWithNibName: (NSString*)nibName
54 {
55 return [self initWithNibName: nibName owner: self];
56 }
57
58 -(id) initWithNibName: (NSString*)nibName owner: (id)owner
59 {
dc5be1c Initial check-in.
uli authored
60 if( (self = [super init]) )
61 {
62 topLevelObjects = [[NSMutableArray alloc] init];
63 NSDictionary* ent = [NSDictionary dictionaryWithObjectsAndKeys:
6290385 UKNibOwner can be created for different NIBs and owners. Can release top...
uli authored
64 owner, @"NSOwner",
dc5be1c Initial check-in.
uli authored
65 topLevelObjects, @"NSTopLevelObjects",
66 nil];
aad4c7f Uli Kusterer Make UKNibOwner work with classes in frameworks/plug-ins as well
authored
67 NSBundle* mainB = [NSBundle bundleForClass: [self class]];
6290385 UKNibOwner can be created for different NIBs and owners. Can release top...
uli authored
68 if( nibName )
69 [mainB loadNibFile: nibName externalNameTable: ent withZone: [self zone]]; // We're responsible for releasing the top-level objects in the NIB (our view, right now).
70 if( nibName && [topLevelObjects count] == 0 )
dc5be1c Initial check-in.
uli authored
71 {
aad4c7f Uli Kusterer Make UKNibOwner work with classes in frameworks/plug-ins as well
authored
72 mainB = [NSBundle mainBundle];
73 if( nibName )
74 [mainB loadNibFile: nibName externalNameTable: ent withZone: [self zone]]; // We're responsible for releasing the top-level objects in the NIB (our view, right now).
75 }
76 if( nibName && [topLevelObjects count] == 0 )
77 {
6290385 UKNibOwner can be created for different NIBs and owners. Can release top...
uli authored
78 NSLog(@"%@: Couldn't find NIB file \"%@.nib\".", NSStringFromClass([self class]), nibName);
dc5be1c Initial check-in.
uli authored
79 [self autorelease];
80 return nil;
81 }
6290385 UKNibOwner can be created for different NIBs and owners. Can release top...
uli authored
82
83 if( owner != self )
84 [self awakeFromNib];
dc5be1c Initial check-in.
uli authored
85 }
86
87 return self;
88 }
89
90
91 -(void) dealloc
92 {
93 [topLevelObjects release];
94 topLevelObjects = nil;
95
96 [super dealloc];
97 }
98
99
6290385 UKNibOwner can be created for different NIBs and owners. Can release top...
uli authored
100 -(void) releaseTopLevelObjects
101 {
1a03e3e Added a proxyController outlet so you can set up an NSObjectController t...
uli authored
102 [proxyController setContent: nil];
6290385 UKNibOwner can be created for different NIBs and owners. Can release top...
uli authored
103 [topLevelObjects release];
104 topLevelObjects = nil;
105 }
106
dc5be1c Initial check-in.
uli authored
107
108 // -----------------------------------------------------------------------------
109 // nibFilename:
110 // Return the filename (minus ".nib" suffix) for the NIB file to load.
111 // Note that, if you subclass this, it will use the subclass's name, and
112 // if you subclass that, the sub-subclass's name. So, you *may* want to
113 // override this to return a constant string if you don't expect subclasses
114 // to have their own similar-but-different NIB file.
115 //
116 // REVISIONS:
117 // 2004-12-23 UK Documented.
118 // -----------------------------------------------------------------------------
119
120 -(NSString*) nibFilename
121 {
122 return NSStringFromClass([self class]);
123 }
124
125 @end
Something went wrong with that request. Please try again.