I'm trying to "connect" an event handler to a Gadget using Carbon API (thanks to lexvictory !)
The code below works fine if the event handler is applied to a window (the commented line), but it is not working when applied to a Gadget
Does the GadgetID() returns the expected ID ?
If a guru of PB & MacOS is around ... it would be appreciated
Code: Select all
#kEventClassMouse = 'mous'
#kEventMouseDown = 1
#kEventMouseUp = 2
#kEventMouseMoved = 5
Structure EventTypeSpec
eventClass.l
eventKind.l
EndStructure
OpenWindow(0, 100,100, 300, 200, "Test Window")
ButtonGadget(0, 100, 100, 50, 50, "Test")
ProcedureCDLL CallBackEventsHandler(*nextHandler, theEvent, *CallBackProc)
Debug "*** CallBackEventsHandler !!! ***"
If *nexthandler : CallNextEventHandler_(*nextHandler, theEvent) : EndIf
EndProcedure
Define *EventHandlerUPP = NewEventHandlerUPP_(@CallBackEventsHandler())
Define eventTypes.EventTypeSpec
eventTypes\eventClass = #kEventClassMouse
eventtypes\eventKind = #kEventMouseDown
;InstallEventHandler_(GetWindowEventTarget_(WindowID(0)), *EventHandlerUPP, 1, @eventTypes, 0, @handlerref.l)
InstallEventHandler_(GetControlEventTarget_(GadgetID(0)), *EventHandlerUPP, 1, @eventTypes, 0, @handlerref.l)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver