Small example with Custom Events. Window and Linux. MacOS not Events for Buttons because Buttons have not keyboard focus
Code: Select all
;-TOP
Enumeration CustomEvent #PB_Event_FirstCustomValue
#MyEvent_GadgetFocus
#MyEvent_GadgetLostFocus
EndEnumeration
Procedure UpdateGadgetFocus()
Static LastGadget = -1
Protected ActiveGadget = GetActiveGadget()
If LastGadget <> ActiveGadget
If LastGadget <> -1
PostEvent(#MyEvent_GadgetLostFocus, GetActiveWindow(), LastGadget)
EndIf
If ActiveGadget <> -1
PostEvent(#MyEvent_GadgetFocus, GetActiveWindow(), ActiveGadget)
EndIf
LastGadget = ActiveGadget
EndIf
EndProcedure
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(0)
dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
; Resize Gadgets
EndProcedure
Procedure Main()
Protected dx, dy
#WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 400, "Small Window", #WinStyle)
; MenuBar
CreateMenu(0, WindowID(0))
MenuTitle("File")
; StatusBar
CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
; Gadgets
dx = WindowWidth(0)
dy - WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
ButtonGadget(0, 10, 10, 120, 30, "Button 1")
ButtonGadget(1, 140, 10, 120, 30, "Button 2")
StringGadget(2, 10, 50, 250, 25, "String 3")
EditorGadget(3, 10, 85, 250, 75)
SetGadgetText(3, "Edit 4")
; Bind Events
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
SetActiveGadget(3)
; Main Loop
Repeat
UpdateGadgetFocus()
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case 0
Break
EndSelect
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
Case #MyEvent_GadgetFocus
Debug "Focus " + GetGadgetText(EventGadget())
Case #MyEvent_GadgetLostFocus
Debug "LostFocus " + GetGadgetText(EventGadget())
EndSelect
ForEver
EndIf
EndProcedure : Main()