PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Frameworks/Debug/AppKit/browser.platform/CPImage.j

http://github.com/jfahrenkrug/MapKit-HelloWorld
Unknown | 312 lines | 311 code | 1 blank | 0 comment | 0 complexity | 40a20f90ab38a24a1a4a0d46acb86673 MD5 | raw file
  1I;21;Foundation/CPBundle.jI;33;Foundation/CPNotificationCenter.jI;21;Foundation/CPObject.jI;22;Foundation/CPRunLoop.jI;21;Foundation/CPString.ji;12;CPGeometry.jc;12167;
  2CPImageLoadStatusInitialized = 0;
  3CPImageLoadStatusLoading = 1;
  4CPImageLoadStatusCompleted = 2;
  5CPImageLoadStatusCancelled = 3;
  6CPImageLoadStatusInvalidData = 4;
  7CPImageLoadStatusUnexpectedEOF = 5;
  8CPImageLoadStatusReadError = 6;
  9CPImageDidLoadNotification = "CPImageDidLoadNotification";
 10CPImageInBundle= function(aFilename, aSize, aBundle)
 11{
 12    if (!aBundle)
 13        aBundle = objj_msgSend(CPBundle, "mainBundle");
 14    if (aSize)
 15        return objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(aBundle, "pathForResource:", aFilename), aSize);
 16    return objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:", objj_msgSend(aBundle, "pathForResource:", aFilename));
 17}
 18{
 19var the_class = objj_getClass("CPBundle")
 20if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"CPBundle\""));
 21var meta_class = the_class.isa;class_addMethods(the_class, [new objj_method(sel_getUid("pathForResource:"), function $CPBundle__pathForResource_(self, _cmd, aFilename)
 22{ with(self)
 23{
 24    return objj_msgSend(self, "resourcePath") + '/' + aFilename;
 25}
 26})]);
 27}
 28{var the_class = objj_allocateClassPair(CPObject, "CPImage"),
 29meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_size"), new objj_ivar("_filename"), new objj_ivar("_delegate"), new objj_ivar("_loadStatus"), new objj_ivar("_image")]);
 30objj_registerClassPair(the_class);
 31objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
 32class_addMethods(the_class, [new objj_method(sel_getUid("initByReferencingFile:size:"), function $CPImage__initByReferencingFile_size_(self, _cmd, aFilename, aSize)
 33{ with(self)
 34{
 35    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init");
 36    if (self)
 37    {
 38        _size = CPSizeCreateCopy(aSize);
 39        _filename = aFilename;
 40        _loadStatus = CPImageLoadStatusInitialized;
 41    }
 42    return self;
 43}
 44}), new objj_method(sel_getUid("initWithContentsOfFile:size:"), function $CPImage__initWithContentsOfFile_size_(self, _cmd, aFilename, aSize)
 45{ with(self)
 46{
 47    self = objj_msgSend(self, "initByReferencingFile:size:", aFilename, aSize);
 48    if (self)
 49        objj_msgSend(self, "load");
 50    return self;
 51}
 52}), new objj_method(sel_getUid("initWithContentsOfFile:"), function $CPImage__initWithContentsOfFile_(self, _cmd, aFilename)
 53{ with(self)
 54{
 55    self = objj_msgSend(self, "initByReferencingFile:size:", aFilename,  CGSizeMake(-1, -1));
 56    if (self)
 57        objj_msgSend(self, "load");
 58    return self;
 59}
 60}), new objj_method(sel_getUid("filename"), function $CPImage__filename(self, _cmd)
 61{ with(self)
 62{
 63    return _filename;
 64}
 65}), new objj_method(sel_getUid("setSize:"), function $CPImage__setSize_(self, _cmd, aSize)
 66{ with(self)
 67{
 68    _size = CGSizeMakeCopy(aSize);
 69}
 70}), new objj_method(sel_getUid("size"), function $CPImage__size(self, _cmd)
 71{ with(self)
 72{
 73    return _size;
 74}
 75}), new objj_method(sel_getUid("setDelegate:"), function $CPImage__setDelegate_(self, _cmd, aDelegate)
 76{ with(self)
 77{
 78    _delegate = aDelegate;
 79}
 80}), new objj_method(sel_getUid("delegate"), function $CPImage__delegate(self, _cmd)
 81{ with(self)
 82{
 83    return _delegate;
 84}
 85}), new objj_method(sel_getUid("loadStatus"), function $CPImage__loadStatus(self, _cmd)
 86{ with(self)
 87{
 88    return _loadStatus;
 89}
 90}), new objj_method(sel_getUid("load"), function $CPImage__load(self, _cmd)
 91{ with(self)
 92{
 93    if (_loadStatus == CPImageLoadStatusLoading || _loadStatus == CPImageLoadStatusCompleted)
 94        return;
 95    _loadStatus = CPImageLoadStatusLoading;
 96    _image = new Image();
 97    var isSynchronous = YES;
 98    _image.onload = function ()
 99        {
100            if (isSynchronous)
101                window.setTimeout(function() { objj_msgSend(self, "_imageDidLoad"); }, 0);
102            else
103            {
104                objj_msgSend(self, "_imageDidLoad");
105                objj_msgSend(objj_msgSend(CPRunLoop, "currentRunLoop"), "limitDateForMode:", CPDefaultRunLoopMode);
106            }
107            objj_msgSend(self, "_derefFromImage");
108        }
109    _image.onerror = function ()
110        {
111            if (isSynchronous)
112                window.setTimeout(function() { objj_msgSend(self, "_imageDidError"); }, 0);
113            else
114            {
115                objj_msgSend(self, "_imageDidError");
116                objj_msgSend(objj_msgSend(CPRunLoop, "currentRunLoop"), "limitDateForMode:", CPDefaultRunLoopMode);
117            }
118            objj_msgSend(self, "_derefFromImage");
119        }
120    _image.onabort = function ()
121        {
122            if (isSynchronous)
123                window.setTimeout(function() { objj_msgSend(self, "_imageDidAbort"); }, 0);
124            else
125            {
126                objj_msgSend(self, "_imageDidAbort");
127                objj_msgSend(objj_msgSend(CPRunLoop, "currentRunLoop"), "limitDateForMode:", CPDefaultRunLoopMode);
128            }
129            objj_msgSend(self, "_derefFromImage");
130        }
131    _image.src = _filename;
132    isSynchronous = NO;
133}
134}), new objj_method(sel_getUid("isThreePartImage"), function $CPImage__isThreePartImage(self, _cmd)
135{ with(self)
136{
137    return NO;
138}
139}), new objj_method(sel_getUid("isNinePartImage"), function $CPImage__isNinePartImage(self, _cmd)
140{ with(self)
141{
142    return NO;
143}
144}), new objj_method(sel_getUid("_derefFromImage"), function $CPImage___derefFromImage(self, _cmd)
145{ with(self)
146{
147    _image.onload = null;
148    _image.onerror = null;
149    _image.onabort = null;
150}
151}), new objj_method(sel_getUid("_imageDidLoad"), function $CPImage___imageDidLoad(self, _cmd)
152{ with(self)
153{
154    _loadStatus = CPImageLoadStatusCompleted;
155    if (!_size || (_size.width == -1 && _size.height == -1))
156        _size = CGSizeMake(_image.width, _image.height);
157    objj_msgSend(objj_msgSend(CPNotificationCenter, "defaultCenter"), "postNotificationName:object:", CPImageDidLoadNotification, self);
158    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("imageDidLoad:")))
159        objj_msgSend(_delegate, "imageDidLoad:", self);
160}
161}), new objj_method(sel_getUid("_imageDidError"), function $CPImage___imageDidError(self, _cmd)
162{ with(self)
163{
164    _loadStatus = CPImageLoadStatusReadError;
165    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("imageDidError:")))
166        objj_msgSend(_delegate, "imageDidError:", self);
167}
168}), new objj_method(sel_getUid("_imageDidAbort"), function $CPImage___imageDidAbort(self, _cmd)
169{ with(self)
170{
171    _loadStatus = CPImageLoadStatusCancelled;
172    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("imageDidAbort:")))
173        objj_msgSend(_delegate, "imageDidAbort:", self);
174}
175})]);
176}
177{
178var the_class = objj_getClass("CPImage")
179if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"CPImage\""));
180var meta_class = the_class.isa;class_addMethods(the_class, [new objj_method(sel_getUid("initWithCoder:"), function $CPImage__initWithCoder_(self, _cmd, aCoder)
181{ with(self)
182{
183    return objj_msgSend(self, "initWithContentsOfFile:size:", objj_msgSend(aCoder, "decodeObjectForKey:", "CPFilename"), objj_msgSend(aCoder, "decodeSizeForKey:", "CPSize"));
184}
185}), new objj_method(sel_getUid("encodeWithCoder:"), function $CPImage__encodeWithCoder_(self, _cmd, aCoder)
186{ with(self)
187{
188    objj_msgSend(aCoder, "encodeObject:forKey:", _filename, "CPFilename");
189    objj_msgSend(aCoder, "encodeSize:forKey:", _size, "CPSize");
190}
191})]);
192}
193{var the_class = objj_allocateClassPair(CPObject, "CPThreePartImage"),
194meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_imageSlices"), new objj_ivar("_isVertical")]);
195objj_registerClassPair(the_class);
196objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
197class_addMethods(the_class, [new objj_method(sel_getUid("initWithImageSlices:isVertical:"), function $CPThreePartImage__initWithImageSlices_isVertical_(self, _cmd, imageSlices, isVertical)
198{ with(self)
199{
200    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init");
201    if (self)
202    {
203        _imageSlices = imageSlices;
204        _isVertical = isVertical;
205    }
206    return self;
207}
208}), new objj_method(sel_getUid("filename"), function $CPThreePartImage__filename(self, _cmd)
209{ with(self)
210{
211    return "";
212}
213}), new objj_method(sel_getUid("imageSlices"), function $CPThreePartImage__imageSlices(self, _cmd)
214{ with(self)
215{
216    return _imageSlices;
217}
218}), new objj_method(sel_getUid("isVertical"), function $CPThreePartImage__isVertical(self, _cmd)
219{ with(self)
220{
221    return _isVertical;
222}
223}), new objj_method(sel_getUid("isThreePartImage"), function $CPThreePartImage__isThreePartImage(self, _cmd)
224{ with(self)
225{
226    return YES;
227}
228}), new objj_method(sel_getUid("isNinePartImage"), function $CPThreePartImage__isNinePartImage(self, _cmd)
229{ with(self)
230{
231    return NO;
232}
233})]);
234}
235var CPThreePartImageImageSlicesKey = "CPThreePartImageImageSlicesKey",
236    CPThreePartImageIsVerticalKey = "CPThreePartImageIsVerticalKey";
237{
238var the_class = objj_getClass("CPThreePartImage")
239if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"CPThreePartImage\""));
240var meta_class = the_class.isa;class_addMethods(the_class, [new objj_method(sel_getUid("initWithCoder:"), function $CPThreePartImage__initWithCoder_(self, _cmd, aCoder)
241{ with(self)
242{
243    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init");
244    if (self)
245    {
246        _imageSlices = objj_msgSend(aCoder, "decodeObjectForKey:", CPThreePartImageImageSlicesKey);
247        _isVertical = objj_msgSend(aCoder, "decodeBoolForKey:", CPThreePartImageIsVerticalKey);
248    }
249    return self;
250}
251}), new objj_method(sel_getUid("encodeWithCoder:"), function $CPThreePartImage__encodeWithCoder_(self, _cmd, aCoder)
252{ with(self)
253{
254    objj_msgSend(aCoder, "encodeObject:forKey:", _imageSlices, CPThreePartImageImageSlicesKey);
255    objj_msgSend(aCoder, "encodeBool:forKey:", _isVertical, CPThreePartImageIsVerticalKey);
256}
257})]);
258}
259{var the_class = objj_allocateClassPair(CPObject, "CPNinePartImage"),
260meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_imageSlices")]);
261objj_registerClassPair(the_class);
262objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
263class_addMethods(the_class, [new objj_method(sel_getUid("initWithImageSlices:"), function $CPNinePartImage__initWithImageSlices_(self, _cmd, imageSlices)
264{ with(self)
265{
266    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init");
267    if (self)
268        _imageSlices = imageSlices;
269    return self;
270}
271}), new objj_method(sel_getUid("filename"), function $CPNinePartImage__filename(self, _cmd)
272{ with(self)
273{
274    return "";
275}
276}), new objj_method(sel_getUid("imageSlices"), function $CPNinePartImage__imageSlices(self, _cmd)
277{ with(self)
278{
279    return _imageSlices;
280}
281}), new objj_method(sel_getUid("isThreePartImage"), function $CPNinePartImage__isThreePartImage(self, _cmd)
282{ with(self)
283{
284    return NO;
285}
286}), new objj_method(sel_getUid("isNinePartImage"), function $CPNinePartImage__isNinePartImage(self, _cmd)
287{ with(self)
288{
289    return YES;
290}
291})]);
292}
293var CPNinePartImageImageSlicesKey = "CPNinePartImageImageSlicesKey";
294{
295var the_class = objj_getClass("CPNinePartImage")
296if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"CPNinePartImage\""));
297var meta_class = the_class.isa;class_addMethods(the_class, [new objj_method(sel_getUid("initWithCoder:"), function $CPNinePartImage__initWithCoder_(self, _cmd, aCoder)
298{ with(self)
299{
300    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init");
301    if (self)
302        _imageSlices = objj_msgSend(aCoder, "decodeObjectForKey:", CPNinePartImageImageSlicesKey);
303    return self;
304}
305}), new objj_method(sel_getUid("encodeWithCoder:"), function $CPNinePartImage__encodeWithCoder_(self, _cmd, aCoder)
306{ with(self)
307{
308    objj_msgSend(aCoder, "encodeObject:forKey:", _imageSlices, CPNinePartImageImageSlicesKey);
309}
310})]);
311}
312