I did not know that it works to bind twice at the same gadget and event...
Looks like it was designed as a stack.
Would that be an alternative?
Code: Select all
DeclareModule Canvas
  Declare Create(Gadget, Text.s = "CanvasGadget")
  Declare SetEvent(*EventFunction)
EndDeclareModule
Module Canvas
  Global *Event
 Procedure CanvasHandler()
    Select EventType()
      Case #PB_EventType_LeftClick
         Debug "Click event on gadget and set value - " + SetGadgetData(EventGadget(),@"set value = #PB_EventType_LeftClick")
    EndSelect
    
    If *Event
      CallFunctionFast(*Event)
    EndIf
    
  EndProcedure
 
  Procedure Create(Gadget, Text.s = "CanvasGadget")
    CanvasGadget(Gadget, 10, 10, 180, 30, #PB_Canvas_Border)
    If StartDrawing(CanvasOutput( Gadget ))
      DrawingMode(#PB_2DDrawing_Transparent)
      Box(0,0,OutputWidth(),OutputHeight())
      DrawText((GadgetWidth(Gadget)-TextWidth(Text))/2, (GadgetHeight(Gadget)-TextHeight(Text))/2, Text,0)
      StopDrawing()
    EndIf
   
    BindGadgetEvent(0, @CanvasHandler())
  EndProcedure
  
  Procedure SetEvent(*EventFunction)
    *Event = *EventFunction
  EndProcedure
  
EndModule
OpenWindow(0, 100, 100, 200, 90, "Click test", #PB_Window_SystemMenu)
Canvas::Create(0)
 
  Procedure CanvasHandler()
    Select EventType()
      Case #PB_EventType_LeftClick
        *Value = GetGadgetData(EventGadget())
        If *Value
          Debug "click event on gadget and get value - " + PeekS(*Value)
        Else
          Debug "We do not get value because it is not implemented properly bindevent "
          Debug "Event module must occur first , as in the module was bindevent was called first"
        EndIf
    EndSelect
  EndProcedure
 
     ;BindGadgetEvent(0, @CanvasHandler())
     Canvas::SetEvent(@CanvasHandler())
 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow