Page 1 of 1
#PB_EventType_Changed for PanelGadget
Posted: Tue Nov 20, 2012 11:28 am
by uwekel
Hi,
it would be nice if the PanelGadget was able to fire a Changed-Event when a new page is selected (like the other gadgets which contain items). It should be occur every time the GetGadgetState() value got changed. The available Clicked-Event is not suitable, because it will also be fired if the page is clicked but not changed.
Best Regards
Uwe
Re: #PB_EventType_Changed for PanelGadget
Posted: Thu Nov 22, 2012 11:04 am
by Shardik
uwekel wrote:The available Clicked-Event is not suitable, because it will also be fired if the page is clicked but not changed.
I can't confirm your statement for PB 5.00 and
Linux (Kubuntu 9.04, Ubuntu 12.04 LTS and Fedora 17, all 32 bit) with the following code example. Only a click onto a previously inactive tab is reported:
Code: Select all
OpenWindow(0, 1400, 100, 300, 200, "PanelGadget", #PB_Window_SystemMenu)
PanelGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20)
AddGadgetItem(0, -1, "Panel 1")
AddGadgetItem(0, -1, "Panel 2")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 0
Debug "Click onto tab " + #DQUOTE$ + GetGadgetItemText(0, GetGadgetState(0)) + #DQUOTE$
EndIf
EndSelect
ForEver
For
Windows you are right: the above code example even reports clicking onto an already activated tab. But it is very easy to eliminate this if you simply keep the index of the last active tab in a variable and compare it with the index of the newly clicked tab (this works even cross-platform in Windows and Linux):
Code: Select all
OpenWindow(0, 1400, 100, 300, 200, "PanelGadget", #PB_Window_SystemMenu)
PanelGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20)
AddGadgetItem(0, -1, "Panel 1")
AddGadgetItem(0, -1, "Panel 2")
LastTab = GetGadgetState(0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 0
NewTab = GetGadgetState(0)
If NewTab <> LastTab
Debug "Click onto tab " + #DQUOTE$ + GetGadgetItemText(0, GetGadgetState(0)) + #DQUOTE$
LastTab = NewTab
EndIf
EndIf
EndSelect
ForEver
Re: #PB_EventType_Changed for PanelGadget
Posted: Thu Nov 22, 2012 8:13 pm
by nospam
uwekel wrote:The available Clicked-Event is not suitable, because it will also be fired if the page is clicked but not changed.
Shardik's first code sample works fine in PB 5 on Linux. I didn't bother checking the second piece of code because the 1st worked.
Re: #PB_EventType_Changed for PanelGadget
Posted: Fri Nov 23, 2012 9:02 am
by uwekel
Hi,
thank you for your comments! I just did some further testing with the following code:
Code: Select all
If OpenWindow(0, 0, 0, 300, 200, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
PanelGadget(0, 10, 10, 280, 140)
AddGadgetItem(0, -1, "Panel 1")
AddGadgetItem(0, -1, "Panel 2")
CloseGadgetList()
ButtonGadget(1, 10, 154, 280, 36, "Click to remove panel 2")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Debug "Event " + Str(EventType()) + " on tab " + Str(GetGadgetState(0))
Case 1
RemoveGadgetItem(0, 1)
EndSelect
EndSelect
ForEver
EndIf
My conclusion:
- The event type should be #PB_EventType_Changed instead of #PB_EventType_LeftMouseClick, because in both OS this event is also fired if you change the current tab with your keyboard and not with the mouse.
- In Windows there is also a mouse up event, but not so in Linux. For better cross platform function it should match to all OS.
- In Windows there is no event if the current tab will be closed. You can check it with a click on the button (see my code above).
- Windows does not fire an event when creating the first tab, but Linux do, what is correct because the value GetGadgetState() is changed.
Best regards
Uwe