Page 1 of 1
TreeGadget #PB_Tree_ThreeState - user can select "in between" state
Posted: Thu Dec 21, 2023 1:51 pm
by 868Mhz
Hi, the help file for TreeGadget states:
The #PB_Tree_ThreeState flag can be used in combination with the #PB_Tree_CheckBoxes flag to get checkboxes that can have an "on", "off" and "in between" state. The user can only select the "on" or "off" states. The "in between" state can be set programmatically using the SetGadgetItemState() function.
But on Mac, the “in between” state is also selectable by the user (on Windows it is as described in the help).
Is this an error in the help file or a bug in PB?
My system:
MacBook Pro with M1 Pro, Sonoma 14.12, BT Keyboard MX MCHNCL, Purebasic 6.04LTS
Code: Select all
EnableExplicit
#wndMain = 0
#tree = 0
Define a.i
If OpenWindow(#wndMain, 0, 0, 400, 300, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TreeGadget(#tree, 0, 0, 400, 300, #PB_Tree_CheckBoxes | #PB_Tree_ThreeState)
For a = 0 To 10
AddGadgetItem(#tree, -1, "Normal Item "+Str(a), 0, 0)
AddGadgetItem(#tree, -1, "Node "+Str(a), 0, 0)
AddGadgetItem(#tree, -1, "Sub-Item 1", 0, 1)
AddGadgetItem(#tree, -1, "Sub-Item 2", 0, 1)
AddGadgetItem(#tree, -1, "Sub-Item 3", 0, 1)
AddGadgetItem(#tree, -1, "Sub-Item 4", 0, 1)
AddGadgetItem(#tree, -1, "File "+Str(a), 0, 0)
Next
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Re: TreeGadget #PB_Tree_ThreeState - user can select "in between" state
Posted: Thu Dec 21, 2023 2:24 pm
by Mindphazer
Hi,
I guess it's an error in the help, as the "in-between" state can be selected on MacOS, even in a no-Purebasic application...
Re: TreeGadget #PB_Tree_ThreeState - user can select "in between" state
Posted: Fri Dec 22, 2023 4:03 pm
by 868Mhz
Thanks Mindphazer.
I tried to suppress the “in between” state in my program below, but it won’t work.
Every now and then a checkbox will show the in between state. If this is the case, the checkbox
will change to checked if I select another item in the tree and then click once again the wrong one
(not on the checkbox, but on the items text).
Any idea what’s wrong with my code?
Code: Select all
EnableExplicit
#wndMain = 0
#tree = 0
Define a, event, value, item
If OpenWindow(#wndMain, 0, 0, 400, 800, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TreeGadget(#tree, 0, 0, 400, 800, #PB_Tree_CheckBoxes | #PB_Tree_ThreeState)
For a = 0 To 10
AddGadgetItem(#tree, -1, "Normal Item "+Str(a), 0, 0)
AddGadgetItem(#tree, -1, "Node "+Str(a), 0, 0)
AddGadgetItem(#tree, -1, "Sub-Item 1", 0, 1)
AddGadgetItem(#tree, -1, "Sub-Item 2", 0, 1)
AddGadgetItem(#tree, -1, "Sub-Item 3", 0, 1)
AddGadgetItem(#tree, -1, "Sub-Item 4", 0, 1)
AddGadgetItem (#tree, -1, "File "+Str(a), 0, 0)
Next
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case #tree
Select EventType()
Case #PB_EventType_LeftClick
item = GetGadgetState(#tree)
value = GetGadgetItemState(#tree, item)
If value & #PB_Tree_Inbetween
value = value & ~#PB_Tree_Inbetween
SetGadgetItemState(#tree, item, value | #PB_Tree_Checked)
SetGadgetState(#tree, item)
EndIf
EndSelect
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
EndIf
Re: TreeGadget #PB_Tree_ThreeState - user can select "in between" state
Posted: Fri Dec 22, 2023 5:58 pm
by Piero
868Mhz wrote: Fri Dec 22, 2023 4:03 pm
I tried to suppress the “in between” state in my program
Any idea what’s wrong with my code?
While keeping | #PB_Tree_ThreeState?
This seems to work here:
Code: Select all
If value & #PB_Tree_Inbetween
value = value & ~#PB_Tree_Inbetween
If value & #PB_Tree_Checked
value = 0
Else
value = #PB_Tree_Checked
EndIf
SetGadgetItemState(#tree, item, value)
SetGadgetState(#tree, item)
EndIf
Re: TreeGadget #PB_Tree_ThreeState - user can select "in between" state
Posted: Fri Dec 22, 2023 6:55 pm
by 868Mhz
Thanks Piero, but I get the same result with your code.
If you click multiple times e.g. on the first items checkbox in the tree (Normal Item 0), after a while (sometimes after 7 clicks, sometimes after the 20. click, it differs and is not constant), the checkbox shows the "-" for in between. The user should only get the checkbox checked or unchecked when he clicks the box.
I like to set the in between state for the node via program (all subnotes unchecked -> node checkbox unchecked, all subnotes checked -> node checkbox checked, all else -> node checkbox in between). But to do this, first the "user action" has to be reliable restricted to checked/unchecked without in between.
Re: TreeGadget #PB_Tree_ThreeState - user can select "in between" state
Posted: Fri Dec 22, 2023 8:59 pm
by Piero
868Mhz wrote: Fri Dec 22, 2023 6:55 pm
Thanks Piero, but I get the same result with your code.
Grrr...
And with this?
Code: Select all
EnableExplicit
#wndMain = 0
#tree = 0
Define a, event, value, item
If OpenWindow(#wndMain, 0, 0, 400, 800, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TreeGadget(#tree, 0, 0, 400, 800, #PB_Tree_CheckBoxes | #PB_Tree_ThreeState)
For a = 0 To 10
AddGadgetItem(#tree, -1, "Normal Item "+Str(a), 0, 0)
AddGadgetItem(#tree, -1, "Node "+Str(a), 0, 0)
AddGadgetItem(#tree, -1, "Sub-Item 1", 0, 1)
AddGadgetItem(#tree, -1, "Sub-Item 2", 0, 1)
AddGadgetItem(#tree, -1, "Sub-Item 3", 0, 1)
AddGadgetItem(#tree, -1, "Sub-Item 4", 0, 1)
AddGadgetItem (#tree, -1, "File "+Str(a), 0, 0)
Next
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case #tree
Select EventType()
Case #PB_EventType_LeftDoubleClick
item = GetGadgetState(#tree)
value = GetGadgetItemState(#tree, item)
If value & #PB_Tree_Inbetween
value = value & ~#PB_Tree_Inbetween
SetGadgetItemState(#tree, item, value | #PB_Tree_Checked)
SetGadgetState(#tree, item)
EndIf
Case #PB_EventType_LeftClick
item = GetGadgetState(#tree)
value = GetGadgetItemState(#tree, item)
If value & #PB_Tree_Inbetween
value = value & ~#PB_Tree_Inbetween
SetGadgetItemState(#tree, item, value | #PB_Tree_Checked)
SetGadgetState(#tree, item)
EndIf
EndSelect
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
EndIf
Re: TreeGadget #PB_Tree_ThreeState - user can select "in between" state
Posted: Sat Dec 23, 2023 12:06 pm
by 868Mhz
Ah, that's it.
Some of the clicks come through as double clicks.
I would never have thought of that. Thank you very much, Piero.
Re: TreeGadget #PB_Tree_ThreeState - user can select "in between" state
Posted: Wed Jan 03, 2024 5:02 pm
by Piero
I wish I could tell you: "You are very welcome!", but my right index finger doesn't want to agree
Gotta go now: the top models are calling me!