Code: Select all
ImportC ""
sel_registerName(str.p-ascii)
class_addMethod(class, selector, imp, types.p-ascii)
EndImport
Global appDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
Global delegateClass = CocoaMessage(0, appDelegate, "class")
Global notificationCenter = CocoaMessage(0, 0, "NSNotificationCenter defaultCenter")
PrototypeC ProtoCallback(sender)
ProcedureC ForwardAction(obj, sel, sender)
Protected Callback.ProtoCallback = CocoaMessage(0, sender, "tag")
Callback(sender)
EndProcedure
Global selForwardAction = sel_registerName("forwardAction:")
Global selNotificationCallback = sel_registerName("notificationCallback:")
class_addMethod(delegateClass, selForwardAction, @ForwardAction(), "v@:@")
Procedure SetTargetActionCallback(control, *cbfunction)
CocoaMessage(0, control, "setTag:", *cbfunction)
CocoaMessage(0, control, "setTarget:", appDelegate)
CocoaMessage(0, control, "setAction:", selForwardAction)
EndProcedure
; *** demo ***
ProcedureC NotificationCallback(obj, sel, notification)
Protected notificationName = CocoaMessage(0, CocoaMessage(0, notification, "name"), "UTF8String")
Debug PeekS(notificationName, -1, #PB_UTF8)
EndProcedure
class_addMethod(delegateClass, selNotificationCallback, @NotificationCallback(), "v@:@")
ProcedureC Callback(sender)
Debug "TrackBarGadget 0"
EndProcedure
OpenWindow(0, 100, 100, 300, 200, "Test")
TrackBarGadget(0, 10, 10, 200, 20, 0, 100)
CocoaMessage(0, notificationCenter, "addObserver:", appDelegate, "selector:", selNotificationCallback, "name:", #Null, "object:", WindowID(0))
SetTargetActionCallback(GadgetID(0), @Callback())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
CocoaMessage(0, notificationCenter, "removeObserver:", appDelegate)
Code: Select all
Global appDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
Global delegateClass = CocoaMessage(0, appDelegate, "class")
Global notificationCenter = CocoaMessage(0, 0, "NSNotificationCenter defaultCenter")
PrototypeC ProtoCallback(sender)
ProcedureC ForwardAction(obj, sel, sender)
Protected Callback.ProtoCallback = CocoaMessage(0, sender, "tag")
Callback(sender)
EndProcedure
Global selForwardAction = sel_registerName_("forwardAction:")
Global selNotificationCallback = sel_registerName_("notificationCallback:")
class_addMethod_(delegateClass, selForwardAction, @ForwardAction(), "v@:@")
Procedure SetTargetActionCallback(control, *cbfunction)
CocoaMessage(0, control, "setTag:", *cbfunction)
CocoaMessage(0, control, "setTarget:", appDelegate)
CocoaMessage(0, control, "setAction:", selForwardAction)
EndProcedure
; *** demo ***
ProcedureC NotificationCallback(obj, sel, notification)
Protected notificationName = CocoaMessage(0, CocoaMessage(0, notification, "name"), "UTF8String")
Debug PeekS(notificationName, -1, #PB_UTF8)
EndProcedure
class_addMethod_(delegateClass, selNotificationCallback, @NotificationCallback(), "v@:@")
ProcedureC Callback(sender)
Debug "TrackBarGadget 0"
EndProcedure
OpenWindow(0, 100, 100, 300, 200, "Test")
TrackBarGadget(0, 10, 10, 200, 20, 0, 100)
CocoaMessage(0, notificationCenter, "addObserver:", appDelegate, "selector:", selNotificationCallback, "name:", #Null, "object:", WindowID(0))
SetTargetActionCallback(GadgetID(0), @Callback())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
CocoaMessage(0, notificationCenter, "removeObserver:", appDelegate)