[REPLIED] Event priorities with a ListIconGadget()
Posted: Fri Sep 20, 2024 9:03 am
This is not so much a question as a surprising observation, probably related to Windows.
OR certainly my lack of knowledge!
Consider the following code:
I'm rather surprised to find that when a StringGadget that has focus loses it to a ListIconGadget, the event priority is:
Because my StringGadget displays the data of a ListIconGadget item, and I want to retrieve the contents of this field when the focus is lost, and use GetGadgetState(ListIconGadget) to find out which ListIcon item it corresponds to.
However, as #PB_EventType_Change occurs before #PB_EventType_LostFocus, I don't get the right item number...
My current solution is to use the same procedure for Focus and LostFocus events, storing the ListIcon item number in a Static variable.
(Note: I could also use a SetGadgetData to store the current item no.)
OR certainly my lack of knowledge!
Consider the following code:
Code: Select all
If OpenWindow(0, 0, 0, 322, 300, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(0, 8, 10, 306, 20, "StringGadget 1")
StringGadget(1, 8, 40, 306, 20, "StringGadget 2")
ListIconGadget(2, 8, 60, 306, 100, "ListIcon",200)
AddGadgetItem(2,-1,"Item 1")
AddGadgetItem(2,-1,"Item 2")
AddGadgetItem(2,-1,"Item 3")
EditorGadget(3, 8, 170, 306, 100, #PB_Editor_ReadOnly)
SetActiveGadget(0)
Repeat
Evenmt=WaitWindowEvent()
Select Evenmt
Case #PB_Event_Gadget
Select EventType()
Case #PB_EventType_Change
Select EventGadget()
Case 0,2:AddGadgetItem(3,-1,"Change "+Str(EventGadget()))
EndSelect
Case #PB_EventType_Focus
Select EventGadget()
Case 0,1:AddGadgetItem(3,-1,"Enter "+Str(EventGadget()))
EndSelect
Case #PB_EventType_LostFocus
Select EventGadget()
Case 0,1:AddGadgetItem(3,-1,"Exit "+Str(EventGadget()))
EndSelect
EndSelect
EndSelect
Until Evenmt = #PB_Event_CloseWindow
EndIf
I'm rather surprised to find that when a StringGadget that has focus loses it to a ListIconGadget, the event priority is:
I would logically have expected it to be:#PB_EventType_Change (ListIcon)
#PB_EventType_LostFocus (StringGadget)
as in the case of a StringGadget to another StringGadget where we have#PB_EventType_LostFocus (StringGadget)
#PB_EventType_Change (ListIcon)
Why do I have a problem with this?#PB_EventType_LostFocus (StringGadget 1)
#PB_EventType_Focus (StringGadget 2)
Because my StringGadget displays the data of a ListIconGadget item, and I want to retrieve the contents of this field when the focus is lost, and use GetGadgetState(ListIconGadget) to find out which ListIcon item it corresponds to.
However, as #PB_EventType_Change occurs before #PB_EventType_LostFocus, I don't get the right item number...
My current solution is to use the same procedure for Focus and LostFocus events, storing the ListIcon item number in a Static variable.
(Note: I could also use a SetGadgetData to store the current item no.)