Code: Select all
;{- Event Handler
Prototype ProtoEvents(Window, Event, Gadget, Type)
Structure VisualDesignerGadgets
  Gadget.l
  EventFunction.ProtoEvents
EndStructure
Global NewList EventProcedures.VisualDesignerGadgets()
Procedure RegisterGadgetEvent(Gadget, *Function)
 
  If IsGadget(Gadget)
    AddElement(EventProcedures())
    EventProcedures()\Gadget        = Gadget
    EventProcedures()\EventFunction = *Function
  EndIf
 
EndProcedure
Procedure CallEventFunction(Window, Event, Gadget, Type)
 
  ForEach EventProcedures()
    If EventProcedures()\Gadget = Gadget
      EventProcedures()\EventFunction(Window, Event, Gadget, Type)
      Break
    EndIf
  Next
 
EndProcedure
;}
;{- Form Constants
Enumeration
  #Window_MAIN
EndEnumeration
Enumeration
  #ListIcon_EVENT
  #Button_SHOWALL
  #Button_HIDEALL
  #Button_HIDE0
  #Button_HIDE1
  #Button_1
  #Button_0
  #Text_MESSAGE
EndEnumeration
;}
;{- Event Procedures
Procedure ListIcon_EVENT_Event(Window, Event, Gadget, Type)
  Debug "#ListIcon_EVENT"
  lineclick = GetGadgetState(#ListIcon_EVENT)
  SetGadgetText(#Text_MESSAGE, "You clicked line: "+Str(lineclick))
EndProcedure
Procedure Button_SHOWALL_Event(Window, Event, Gadget, Type)
  Debug "#Button_SHOWALL"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "A;; buttons now shown...")
  For X = #Button_1 To #Button_0
    HideGadget(X,0)
  Next
EndProcedure
Procedure Button_HIDEALL_Event(Window, Event, Gadget, Type)
  Debug "#Button_HIDEALL"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "ALL BUTTONS HIDDEN.")
  For X = #Button_1 To #Button_0
    HideGadget(X,1)
  Next
EndProcedure
Procedure Button_HIDE1_Event(Window, Event, Gadget, Type)
  Debug "#Button_HIDE1"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button HIDE event...")
  HideGadget(#Button_1,1)
EndProcedure
Procedure Button_HIDE0_Event(Window, Event, Gadget, Type)
  Debug "#Button_HIDE0"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button HIDE event...")
  HideGadget(#Button_0,1)
EndProcedure
Procedure Button_1_Event(Window, Event, Gadget, Type)
  Debug "#Button_1"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button 1 PRESSED!")
EndProcedure
Procedure Button_0_Event(Window, Event, Gadget, Type)
  Debug "#Button_0"
  last$ = GetGadgetText(#Text_MESSAGE)
  AddGadgetItem(#Listicon_EVENT, -1, last$)
  SetGadgetText(#Text_MESSAGE, "Button 0 PRESSED!")
EndProcedure
; UNLESS YOU NEED TO HANFLE SOMETHING HAPPENING WITH THE TEXT GADGET YOU REALLY DON't NEED THIS EVENT
;Procedure Text_MESSAGE_Event(Window, Event, Gadget, Type)
;  Debug "#Text_MESSAGE"
;EndProcedure
;}
;{- Build Form
Procedure Open_Window_MAIN()
 
  If OpenWindow(#Window_MAIN, 5, 5, 400, 277, "JILES EXAMPLE 1.0",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar )
    TextGadget(#Text_MESSAGE, 5, 255, 390, 20, "", #PB_Text_Center | #PB_Text_Border)
    ; RegisterGadgetEvent(#Text_MESSAGE, @Text_MESSAGE_Event()) ; not necessary unless something happens when we click it
    ButtonGadget(#Button_0, 5, 10, 120, 30, "Button 0")
    RegisterGadgetEvent(#Button_0, @Button_0_Event())
    ButtonGadget(#Button_1, 5, 45, 120, 30, "Button 1")
    RegisterGadgetEvent(#Button_1, @Button_1_Event())
    ButtonGadget(#Button_HIDE0, 5, 80, 120, 30, "HIDE BUTTON 0")
    RegisterGadgetEvent(#Button_HIDE0, @Button_HIDE0_Event())
    ButtonGadget(#Button_HIDE1, 5, 115, 120, 30, "HIDE BUTTON 1")
    RegisterGadgetEvent(#Button_HIDE1, @Button_HIDE1_Event())
    ButtonGadget(#Button_HIDEALL, 5, 150, 120, 30, "HIDE ALL BUTTONS")
    RegisterGadgetEvent(#Button_HIDEALL, @Button_HIDEALL_Event())
    ButtonGadget(#Button_SHOWALL, 5, 220, 120, 30, "SHOW ALL BUTTONS")
    RegisterGadgetEvent(#Button_SHOWALL, @Button_SHOWALL_Event())
    ListIconGadget(#ListIcon_EVENT, 140, 10, 250, 240, "EVENT", 130, #PB_ListIcon_GridLines)
    RegisterGadgetEvent(#ListIcon_EVENT, @ListIcon_EVENT_Event())
  EndIf
EndProcedure
;}
;{- Main Program Loop
Open_Window_MAIN()
SetGadgetText(#Text_MESSAGE, "PROGRAM START")
Repeat
 
  Event  = WaitWindowEvent()
  Gadget = EventGadget()
  Type   = EventType()
  Window = EventWindow()
 
  Select Event
  Case #PB_Event_Gadget
    CallEventFunction(Window, Event, Gadget, Type)
   
  EndSelect
 
Until Event = #PB_Event_CloseWindow
End
;}