Page 1 of 1
Automatic handling of ThreeState checkboxes
Posted: Fri Apr 13, 2012 6:47 pm
by Michael Vogel
Maybe there's a simple approach to handle checkboxes using the #PB_CheckBox_ThreeState flag, but I don't think so.
Wouldn't it be fine, if PB would be able to handle also three state boxes automatically?
Code: Select all
Procedure SetGadgetThreeState(Gadget,Value,*State.Integer=0)
If Value=2
Value=-1
EndIf
SetGadgetState(Gadget,Value)
If *State
*State\i=Value
EndIf
ProcedureReturn value
EndProcedure
*** Initialization ***
OptFatLineState=0
SetGadgetState(#OptFatLine,OptFatLineState)
*** Event-Handling ***
Case #PB_Event_Gadget,#PB_Event_Menu
Select EventGadget()
:
Case #OptFatLine
OptFatLineState=(OptFatLineState+1)%3
SetGadgetThreeState(#OptFatLine,OptFatLineState)
Re: Automatic handling of ThreeState checkboxes
Posted: Sun Apr 15, 2012 12:37 am
by Danilo
Michael Vogel wrote:Wouldn't it be fine, if PB would be able to handle also three state boxes automatically?
Like the following on Windows?
Code: Select all
If OpenWindow(0, 0, 0, 270, 160, "CheckBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(1, 10, 10, 250, 20, "CheckBox three state", #BS_AUTO3STATE)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow : End
Case #PB_Event_Gadget : Debug SendMessage_(GadgetID(1),#BM_GETSTATE,0,0)&3
EndSelect
ForEver
EndIf
Makes sense for cross-platform #PB_CheckBox_ThreeState.
BS_AUTO3STATE wrote:Creates a button that is the same as a three-state check box, except that the box changes its state when the user selects it.
The state cycles through checked, indeterminate, and cleared.
Re: Automatic handling of ThreeState checkboxes
Posted: Sun Apr 15, 2012 6:10 pm
by Shardik
PB help for CheckBoxGadget() wrote:By clicking on the checkbox, the user can bring it back to either the "on" or "off" state to apply this to all the items. Therefore the "inbetween" state can only be set by the program via SetGadgetState() and not by the user by clicking on the checkbox.
As a workaround for cycling through all 3 states when clicking onto the
CheckBoxGadget it's not necessary to use API functions. The following
example works cross-platform (tested on Windows 7 x86, Kubuntu 9.04,
Xubuntu 10.04 and MacOS X 10.6.8 ):
Code: Select all
OpenWindow(0, 270, 100, 270, 40, "Cycle through CheckBox states")
CheckBoxGadget(0, 10, 10, 250, 20, "3-state CheckBox", #PB_CheckBox_ThreeState)
CheckBoxState = 1
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 0
CheckBoxState = (CheckBoxState + 1) % 3
If CheckBoxState = 2
SetGadgetState(0, #PB_Checkbox_Inbetween)
EndIf
EndIf
EndSelect
ForEver
Re: Automatic handling of ThreeState checkboxes
Posted: Tue Apr 17, 2012 10:01 am
by Michael Vogel
Danilo wrote:Michael Vogel wrote:Wouldn't it be fine, if PB would be able to handle also three state boxes automatically?
Like the following on Windows?
Code: Select all
If OpenWindow(0, 0, 0, 270, 160, "CheckBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(1, 10, 10, 250, 20, "CheckBox three state", #BS_AUTO3STATE)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow : End
Case #PB_Event_Gadget : Debug SendMessage_(GadgetID(1),#BM_GETSTATE,0,0)&3
EndSelect
ForEver
EndIf
Makes sense for cross-platform #PB_CheckBox_ThreeState.
BS_AUTO3STATE wrote:Creates a button that is the same as a three-state check box, except that the box changes its state when the user selects it.
The state cycles through checked, indeterminate, and cleared.
Exactly, thanks
PS: I believe, BM_GETCHECK and BM_SETCHECK should be used for windows