I am VERY interested in the following functions :
Notification_Observe (Object, NotificationName.s)
Notification_RemoveObserve (Object, NotificationName.s)
Notification_SetCallback (@NotificationCallback())
SetTargetActionCallback(Control, @Callback())
... but i would like not to have an external library to use. Can you please help me to implement them in pure PureBasic ?
I had a look at the sources, but i am sadly not very fiendly with Objective-C
Here is my first try for Notification_Observe()/Notification_RemoveObserve() (inspired from another post) :
Code: Select all
ImportC ""
sel_registerName(str.p-ascii)
class_addMethod(class, selector, imp, types.p-ascii)
EndImport
OpenWindow(0, 100, 100, 300, 200, "Test")
ProcedureC CallBack(obj, sel, notification)
Debug "Callback()"
EndProcedure
notificationCenter = CocoaMessage(0, 0, "NSNotificationCenter defaultCenter")
appDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
delegateClass = CocoaMessage(0, appDelegate, "class")
selector = sel_registerName("Callback:") ; Necessary ?
class_addMethod(delegateClass, selector, @Callback(), "v@:@")
CocoaMessage(0, notificationCenter, "addObserver:", appDelegate, "selector:", selector, "name:", #Null, "object:", WindowID(0))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
CocoaMessage(0, notificationCenter, "removeObserver:", appDelegate, "name:", #Null, "object:", WindowID(0))
... but how to do for SetTargetActionCallback() ?
And how to implement a RemoveTargetAction() ?
Regards.