PageRenderTime 15ms CodeModel.GetById 10ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/AppKit/Cib/_CPCibObjectData.j

http://github.com/cacaodev/cappuccino
Unknown | 292 lines | 210 code | 82 blank | 0 comment | 0 complexity | eda2bb47a16a3fc60deab80ba8beec28 MD5 | raw file
  1/*
  2 * _CPCibObjectData.j
  3 * AppKit
  4 *
  5 * Created by Francisco Tolmasky.
  6 * Copyright 2008, 280 North, Inc.
  7 *
  8 * This library is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU Lesser General Public
 10 * License as published by the Free Software Foundation; either
 11 * version 2.1 of the License, or (at your option) any later version.
 12 *
 13 * This library is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 16 * Lesser General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU Lesser General Public
 19 * License along with this library; if not, write to the Free Software
 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 21 */
 22
 23@import <Foundation/CPArray.j>
 24@import <Foundation/CPObject.j>
 25@import <Foundation/CPString.j>
 26
 27@import "CPCibBindingConnector.j"
 28@import "CPCibConnector.j"
 29@import "CPCibControlConnector.j"
 30@import "CPCibHelpConnector.j"
 31@import "CPCibOutletConnector.j"
 32@import "CPCibRuntimeAttributesConnector.j"
 33@import "CPClipView.j"
 34
 35@class CPScrollView
 36
 37
 38@implementation _CPCibObjectData : CPObject
 39{
 40    CPArray             _namesKeys;
 41    CPArray             _namesValues;
 42
 43    CPArray             _accessibilityConnectors;
 44    CPArray             _accessibilityOidsKeys;
 45    CPArray             _accessibilityOidsValues;
 46
 47    CPArray             _classesKeys;
 48    CPArray             _classesValues;
 49
 50    CPArray             _connections;
 51
 52    id                  _fontManager;
 53
 54    CPString            _framework;
 55
 56    int                 _nextOid;
 57
 58    CPArray             _objectsKeys;
 59    CPArray             _objectsValues;
 60
 61    CPArray             _oidKeys;
 62    CPArray             _oidValues;
 63
 64    _CPCibCustomObject  _fileOwner;
 65
 66    CPSet               _visibleWindows;
 67
 68    JSObject            _replacementObjects;
 69}
 70
 71- (id)init
 72{
 73    self = [super init];
 74
 75    if (self)
 76    {
 77        _namesKeys = [];
 78        _namesValues = [];
 79
 80        //CPArray         _accessibilityConnectors;
 81        //CPArray         _accessibilityOidsKeys;
 82        //CPArray         _accessibilityOidsValues;
 83
 84        _classesKeys = [];
 85        _classesValues = [];
 86
 87        _connections = [];
 88        //id              _fontManager;
 89
 90        _framework = @"";
 91
 92        _nextOid = [];
 93
 94        _objectsKeys = [];
 95        _objectsValues = [];
 96
 97        _oidKeys = [];
 98        _oidValues = [];
 99
100        _fileOwner = nil;
101
102        _visibleWindows = [CPSet set];
103    }
104
105    return self;
106}
107
108- (void)displayVisibleWindows
109{
110    var object = nil,
111        objectEnumerator = [_visibleWindows objectEnumerator];
112
113    while ((object = [objectEnumerator nextObject]) !== nil)
114        [_replacementObjects[[object UID]] makeKeyAndOrderFront:self];
115}
116
117@end
118
119var _CPCibObjectDataNamesKeysKey                = @"_CPCibObjectDataNamesKeysKey",
120    _CPCibObjectDataNamesValuesKey              = @"_CPCibObjectDataNamesValuesKey",
121
122    _CPCibObjectDataAccessibilityConnectorsKey  = @"_CPCibObjectDataAccessibilityConnectors",
123    _CPCibObjectDataAccessibilityOidsKeysKey    = @"_CPCibObjectDataAccessibilityOidsKeys",
124    _CPCibObjectDataAccessibilityOidsValuesKey  = @"_CPCibObjectDataAccessibilityOidsValues",
125
126    _CPCibObjectDataClassesKeysKey              = @"_CPCibObjectDataClassesKeysKey",
127    _CPCibObjectDataClassesValuesKey            = @"_CPCibObjectDataClassesValuesKey",
128
129    _CPCibObjectDataConnectionsKey              = @"_CPCibObjectDataConnectionsKey",
130
131    _CPCibObjectDataFontManagerKey              = @"_CPCibObjectDataFontManagerKey",
132
133    _CPCibObjectDataFrameworkKey                = @"_CPCibObjectDataFrameworkKey",
134
135    _CPCibObjectDataNextOidKey                  = @"_CPCibObjectDataNextOidKey",
136
137    _CPCibObjectDataObjectsKeysKey              = @"_CPCibObjectDataObjectsKeysKey",
138    _CPCibObjectDataObjectsValuesKey            = @"_CPCibObjectDataObjectsValuesKey",
139
140    _CPCibObjectDataOidKeysKey                  = @"_CPCibObjectDataOidKeysKey",
141    _CPCibObjectDataOidValuesKey                = @"_CPCibObjectDataOidValuesKey",
142
143    _CPCibObjectDataFileOwnerKey                = @"_CPCibObjectDataFileOwnerKey",
144    _CPCibObjectDataVisibleWindowsKey           = @"_CPCibObjectDataVisibleWindowsKey";
145
146@implementation _CPCibObjectData (CPCoding)
147
148- (id)initWithCoder:(CPCoder)aCoder
149{
150    self = [super init];
151
152    if (self)
153    {
154        _replacementObjects = {};
155
156        _namesKeys = [aCoder decodeObjectForKey:_CPCibObjectDataNamesKeysKey];
157        _namesValues = [aCoder decodeObjectForKey:_CPCibObjectDataNamesValuesKey];
158
159        //CPArray         _accessibilityConnectors;
160        //CPArray         _accessibilityOidsKeys;
161        //CPArray         _accessibilityOidsValues;
162
163        _classesKeys = [aCoder decodeObjectForKey:_CPCibObjectDataClassesKeysKey];
164        _classesValues = [aCoder decodeObjectForKey:_CPCibObjectDataClassesValuesKey];
165
166        _connections = [aCoder decodeObjectForKey:_CPCibObjectDataConnectionsKey];
167        //id              _fontManager;
168
169        _framework = [aCoder decodeObjectForKey:_CPCibObjectDataFrameworkKey];
170
171        _nextOid = [aCoder decodeIntForKey:_CPCibObjectDataNextOidKey];
172
173        _objectsKeys = [aCoder decodeObjectForKey:_CPCibObjectDataObjectsKeysKey];
174        _objectsValues = [aCoder decodeObjectForKey:_CPCibObjectDataObjectsValuesKey];
175
176        _oidKeys = [aCoder decodeObjectForKey:_CPCibObjectDataOidKeysKey];
177        _oidValues = [aCoder decodeObjectForKey:_CPCibObjectDataOidValuesKey];
178
179        _fileOwner = [aCoder decodeObjectForKey:_CPCibObjectDataFileOwnerKey];
180
181        _visibleWindows = [aCoder decodeObjectForKey:_CPCibObjectDataVisibleWindowsKey];
182    }
183
184    return self;
185}
186
187- (void)encodeWithCoder:(CPCoder)aCoder
188{
189    [aCoder encodeObject:_namesKeys forKey:_CPCibObjectDataNamesKeysKey];
190    [aCoder encodeObject:_namesValues forKey:_CPCibObjectDataNamesValuesKey];
191
192    //CPArray         _accessibilityConnectors;
193    //CPArray         _accessibilityOidsKeys;
194    //CPArray         _accessibilityOidsValues;
195
196    [aCoder encodeObject:_classesKeys forKey:_CPCibObjectDataClassesKeysKey];
197    [aCoder encodeObject:_classesValues forKey:_CPCibObjectDataClassesValuesKey];
198
199    [aCoder encodeObject:_connections forKey:_CPCibObjectDataConnectionsKey];
200
201    //id              _fontManager;
202
203    [aCoder encodeObject:_framework forKey:_CPCibObjectDataFrameworkKey];
204
205    [aCoder encodeInt:_nextOid forKey:_CPCibObjectDataNextOidKey];
206
207    [aCoder encodeObject:_objectsKeys forKey:_CPCibObjectDataObjectsKeysKey];
208    [aCoder encodeObject:_objectsValues forKey:_CPCibObjectDataObjectsValuesKey];
209
210    [aCoder encodeObject:_oidKeys forKey:_CPCibObjectDataOidKeysKey];
211    [aCoder encodeObject:_oidValues forKey:_CPCibObjectDataOidValuesKey];
212
213    [aCoder encodeObject:_fileOwner forKey:_CPCibObjectDataFileOwnerKey];
214//    CPCustomObject  _fileOwner;
215
216    [aCoder encodeObject:_visibleWindows forKey:_CPCibObjectDataVisibleWindowsKey];
217}
218
219- (void)instantiateWithOwner:(id)anOwner topLevelObjects:(CPMutableArray)topLevelObjects
220{
221    // _objectsValues -> parent
222    // _objectsKeys -> child
223    var count = [_objectsKeys count];
224
225    while (count--)
226    {
227        var object = _objectsKeys[count],
228            parent = _objectsValues[count],
229            instantiatedObject = object;
230
231        if ([object respondsToSelector:@selector(_cibInstantiate)])
232        {
233            var instantiatedObject = [object _cibInstantiate];
234
235            if (instantiatedObject !== object)
236            {
237                _replacementObjects[[object UID]] = instantiatedObject;
238
239                if ([instantiatedObject isKindOfClass:CPView])
240                {
241                    var clipView = [instantiatedObject superview];
242
243                    if ([clipView isKindOfClass:CPClipView])
244                    {
245                        var scrollView = [clipView superview];
246
247                        if ([scrollView isKindOfClass:CPScrollView])
248                            [scrollView setDocumentView:instantiatedObject];
249                    }
250                }
251            }
252        }
253
254        if (topLevelObjects && parent === _fileOwner && object !== _fileOwner)
255            topLevelObjects.push(instantiatedObject);
256    }
257}
258
259- (void)establishConnectionsWithOwner:(id)anOwner topLevelObjects:(CPMutableArray)topLevelObjects
260{
261    _replacementObjects[[_fileOwner UID]] = anOwner;
262
263    for (var i = 0, count = _connections.length; i < count; ++i)
264    {
265        var connection = _connections[i];
266        [connection replaceObjects:_replacementObjects];
267        [connection establishConnection];
268    }
269}
270
271- (void)awakeWithOwner:(id)anOwner topLevelObjects:(CPMutableArray)topLevelObjects
272{
273    var count = [_objectsKeys count];
274
275    while (count--)
276    {
277        var object = _objectsKeys[count],
278            instantiatedObject = _replacementObjects[[object UID]];
279
280        if (instantiatedObject)
281            object = instantiatedObject;
282
283        // Don't use _fileOwner, by this point its been replaced with anOwner.
284        if (object !== anOwner && [object respondsToSelector:@selector(awakeFromCib)])
285            [object awakeFromCib];
286    }
287
288    if ([anOwner respondsToSelector:@selector(awakeFromCib)])
289        [anOwner awakeFromCib];
290}
291
292@end