TreeGadget: Issues with EventTypes

Found an issue in SpiderBasic ? Please report it here !
blz
Posts: 7
Joined: Wed Apr 14, 2021 12:40 pm

TreeGadget: Issues with EventTypes

Post by blz »

Hi,

It seems there is an inconsistency in the order of TreeGadget EventTypes being sent.

ListIcon and ListView gadgets send them in below order when clicking on a new item:
#ListIcon... #PB_EventType_Change
#ListIcon... #PB_EventType_LeftClick

#ListView... #PB_EventType_Change
#ListView... #PB_EventType_LeftClick

TreeGadget triggers Click and Change events in reverse order:
#Tree... #PB_EventType_LeftClick
#Tree... #PB_EventType_Change

This makes, for example, giving the focus to other gadgets (SetActiveGadget()) quite a challenge. (I couldn't find a solution yet.)

Also with TreeGadget, LeftClick always generates a Change event, even if no new item was selected.
RightClick, however, never generates a Change event, even if a new item was selected. (This means SetActiveGadget() do work with RightClick.)

Please see below example with mentioned gadgets and their event types sent.

Code: Select all

; TreeGadget: Issues with EventTypes

#win = 0
Enumeration
  #Tree
  #ListView
  #ListIcon
  #Button = 10
  #String
EndEnumeration

Procedure GadgetEvent()
  Select EventGadget()
    Case #ListIcon
      Select EventType()
        Case #PB_EventType_LeftClick
          Debug "#ListIcon... #PB_EventType_LeftClick"   ; only sends Change when new item is selected  ->  OK
          SetActiveGadget(#String)
        Case #PB_EventType_RightClick
          Debug "#ListIcon... #PB_EventType_RightClick"  ; only sends Change when new item is selected  ->  OK
          SetActiveGadget(#String)
        Case #PB_EventType_LeftDoubleClick
          Debug "#ListIcon... #PB_EventType_LeftDoubleClick"
        Case #PB_EventType_RightDoubleClick
          Debug "#ListIcon... #PB_EventType_RightDoubleClick"
        Case #PB_EventType_Change
          Debug "#ListIcon... #PB_EventType_Change"  ; Change comes first, then the L/R Click  ->  OK
      EndSelect
      
    Case #ListView
      Select EventType()
        Case #PB_EventType_LeftClick
          Debug "#ListView... #PB_EventType_LeftClick"   ; only sends Change when new item is selected  ->  OK
          SetActiveGadget(#String)
        Case #PB_EventType_RightClick
          Debug "#ListView... #PB_EventType_RightClick"  ; only sends Change when new item is selected  ->  OK
          SetActiveGadget(#String)
        Case #PB_EventType_LeftDoubleClick
          Debug "#ListView... #PB_EventType_LeftDoubleClick"
        Case #PB_EventType_RightDoubleClick
          Debug "#ListView... #PB_EventType_RightDoubleClick"
        Case #PB_EventType_Change
          Debug "#ListView... #PB_EventType_Change"  ; Change comes first, then the L/R Click  ->  OK
      EndSelect
      
    Case #Tree
      Select EventType()
        Case #PB_EventType_LeftClick
          Debug "#Tree... #PB_EventType_LeftClick"   ; ALWAYS sends Change, even if clicked on the same, already selected item
          SetActiveGadget(#String)
        Case #PB_EventType_RightClick
          Debug "#Tree... #PB_EventType_RightClick"  ; NEVER sends Change, even if selected item is changed
          SetActiveGadget(#String)
        Case #PB_EventType_LeftDoubleClick
          Debug "#Tree... #PB_EventType_LeftDoubleClick"
        Case #PB_EventType_RightDoubleClick
          Debug "#Tree... #PB_EventType_RightDoubleClick"
        Case #PB_EventType_Change
          Debug "#Tree... #PB_EventType_Change"    ; -LeftClick comes first, then the Change  ->  it's not possible to not make #String active with LeftClick
                                                   ; -There is no Change event for RightClick
          SetActiveGadget(#String)
      EndSelect
      
    Case #button
      ClearDebugOutput()
      SetActiveGadget(#String)
      
  EndSelect
  
EndProcedure


BindEvent(#PB_Event_Gadget, @GadgetEvent())


If OpenWindow(#win, 0, 0, 610, 400, "TreeGadget EventTypes", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(#Button,  10, 10, 120, 25, "ClearDebugOutput")
  StringGadget(#String, 210, 10, 120, 25, "Keep this Active...", #PB_String_PlaceHolder)
  

  y = 50
  w = 190
  h = 340
  
  ListIconGadget(#ListIcon, 10, y, w, h, "Column", 100, #PB_ListIcon_AlwaysShowSelection)
  For i = 0 To 10
    AddGadgetItem (#ListIcon, -1, "Normal Item "+Str(i))
  Next
  
  ListViewGadget(#ListView, 210, y, w, h)
  For i = 0 To 10
    AddGadgetItem (#ListView, -1, "Normal Item "+Str(i))
  Next
  
  TreeGadget(#Tree, 410, y, w, h)
  For i = 0 To 10
    AddGadgetItem(ID, -1, "Normal Item "+Str(i), 0, 0)
    AddGadgetItem(ID, -1, "Node "+Str(i), 0, 0)
    AddGadgetItem(ID, -1, "Sub-Item 1", 0, 1)
    AddGadgetItem(ID, -1, "Sub-Item 2", 0, 1)
    AddGadgetItem(ID, -1, "Sub-Item 3", 0, 1)
    AddGadgetItem(ID, -1, "Sub-Item 4", 0, 1)
  Next
  
  SetActiveGadget(#String)
EndIf
Edit: fixed a bug in the bug report: Str(a) -> Str(i)