12 // //todo implement objc functionality
18 var <dataptr=nil, <> className, < nsAction=nil, < nsDelegate=nil;
22 ^this.primitiveFailed;
27 ^this.primitiveFailed;
30 *new{|classname, initname, args, defer=false|
31 ^super.new.init(classname.asString, initname, args, defer)
34 *getClass{|classname| //return only the class id, the object is not allocated yet ...
35 ^super.new.initClass(classname);
38 invoke{|method, args, defer=false|
40 if(dataptr.isNil, {^nil;});
41 args = args ? []; //todo: fix that in the primitive ...
42 result = this.prInvoke(method, args, defer);
52 _ObjC_IsSubclassOfNSClass
53 ^this.primitiveFailed;
57 if(nsAction.notNil, {nsAction.release; nsAction=nil;});
58 if(nsDelegate.notNil, {nsDelegate.release; nsDelegate=nil;});
71 initAction{|actionName = "doFloatAction:"|
73 out = CocoaAction.newClear;
74 this.prSetActionForControl(out, actionName);
77 nsAction.object = this;
82 out = CocoaAction.newClear;
83 this.prSetDelegate(out);
86 nsDelegate.object = this;
90 sendMessage{|msgname, args|
91 this.prSendMsg(msgname, args)
94 prSendMsg{|msgname, args|
98 *newFromRawPointer{|ptr|
99 ^super.new.initFromRawPointer(ptr)
106 *newWith{| classname, initname,args|
107 ^super.new.initWith( classname, initname,args)
110 initWith{| cn, initname,args|
112 this.prAllocWith( cn, initname,args);
115 initFromRawPointer{|ptr|
117 className = this.prGetClassName;
121 className = this.prGetClassName;
124 init{|cn, in, args, defer|
126 // className = cn; // set upon return
127 if(cn.isKindOf(String) and:{in.isKindOf(String)}, {
128 result = this.prAllocInit(cn, in, args, defer);
133 prAllocInit { arg classname, initname,args;
135 ^this.primitiveFailed;
140 ^this.primitiveFailed;
143 prInvoke { arg initname,args, defer=true;
145 ^this.primitiveFailed;
150 // ^this.primitiveFailed;
153 prAllocWith { arg classname, initname,args;
155 ^this.primitiveFailed;
157 prGetClass{arg classname;
159 ^this.primitiveFailed;
169 prSetActionForControl{|control|
170 _ObjC_SetActionForControl
172 prSetDelegate{|control|
176 // sendMsg{|initname,args|
177 // ^this.prSendMsg(className, initname, args, 0)
185 asArray {arg arrayType;
187 requestedLength = this.invoke("length").asInteger;
188 if(this.isSubclassOf("NSData"), {
189 if(arrayType.isKindOf(String), {arrayType = arrayType.asSymbol});
190 if(arrayType.isKindOf(Symbol), {
192 { arrayType == \string } { String.newClear(requestedLength) }
193 { arrayType == \int8 } { Int8Array.newClear(requestedLength) }
194 { arrayType == \int16 } { Int16Array.newClear(requestedLength >> 1) }
195 { arrayType == \int32 } { Int32Array.newClear(requestedLength >> 2) }
196 { arrayType == \double } { DoubleArray.newClear(requestedLength >> 3) }
197 { arrayType == \float } { FloatArray.newClear(requestedLength >> 2) };
198 ^this.prAsArray(arrayType, requestedLength);
204 prAsArray {|type, len|
205 _ObjC_NSDataToSCArray
206 ^this.primitiveFailed;
211 _ObjC_NSStringToPyrString
212 ^this.primitiveFailed;
216 registerNotification {
217 |aNotificationName, aFunc, obj=1|
218 if(nsDelegate.isNil, {
221 nsDelegate.prRegisterNotification(aNotificationName, aFunc);
222 if (obj.notNil and:{ obj == 1 }) { obj = this };
223 this.prRegisterNotification(aNotificationName, obj);
226 prRegisterNotification {|aNotificationName, obj|
227 _ObjC_RegisterNotification
231 //this is usually noy created directly. call SCNSObject-initAction instead.
232 CocoaAction : SCNSObjectAbstract{
233 var <>action, notificationActions=nil, delegateActions=nil, <>object;
236 action.value(this, it);
239 doNotificationAction {
240 |notif, nsNotification, obj|
242 func = notificationActions.at(notif.asSymbol);
244 func.value(notif, nsNotification, obj, this);
251 func = delegateActions.at(method.asSymbol);
253 result = func.value(method, arguments);
259 |selectorName, returntype, objctypes, aFunc|
261 if(selectorName.notNil and:{aFunc.isKindOf(Function)}, {
262 if(delegateActions.isNil, {delegateActions = IdentityDictionary.new(16)});
263 if(returntype.isNil, {returntype = "v"});
264 types = returntype ++ "@:" ++ objctypes; // first and second types are always ID and _cmd
265 this.praddMethod(selectorName, types);
266 delegateActions.add(selectorName.asSymbol -> aFunc);
270 prRegisterNotification {
272 if(aNotName.notNil, {
273 if(notificationActions.isNil, {notificationActions = IdentityDictionary.new(16);});
274 notificationActions.add(aNotName.asSymbol -> aFunc);
279 |selectorName, objctypesAsString|
280 _ObjC_DelegateAddSelector
281 ^this.primitiveFailed;
285 _ObjC_DelegateRemoveSelector
286 ^this.primitiveFailed;
290 SCNSObject : SCNSObjectAbstract{
294 NSBundle : SCNSObject {
298 ^super.newClear.loadBundle(path);
302 ^SCNSObject.newFromRawPointer(this.prAllocPrincipalClass);
305 allocClassNamed{|name, initname, args, defer=false|
307 ptr = this.prAllocClassNamed(name, initname, args, defer);
308 if(ptr.isNil){"could not alloc class: %".format(name).warn; ^nil};
309 ^SCNSObject.newFromRawPointer(ptr);
316 this.prLoadBundle(path);
317 if(this.isAllocated){
326 prAllocPrincipalClass{
327 _ObjcBundleAllocPrincipalClass
330 prAllocClassNamed{|name, initname, args, defer|
331 _ObjcBundleAllocClassNamed
336 /* cocoa-bridge by Jan Trutzschler 2005 */
347 primitive {^dataptr;}
348 *newFromRawPointer {|nsptr|