Toolbox button set state
Aleksey Murushkin (Cloverleaf) (8233) 41 posts |
Hi. I have created a custom checkbox using toolbox like this: |
Chris Johns (8262) 242 posts |
I don’t think the ‘Button’ has a ‘selected’ state. It just tells you (via a wimp event) when it’s been pressed. Thinking off the top of my head, could you arrange it to change the sprite whenever it’s been clicked? If you set the validation to Soptongr it will show as “on”. If the user then clicks it, you can change the validation to Soptoffgr and flag in the code that it’s been turned off. |
Rick Murray (539) 13890 posts |
There’s no access to icon flags bit 21 (icon is selected)? Usually initial selection state should be programmatically set at the start, as it is bad practice to embed such things in the window definitions. |
Rick Murray (539) 13890 posts |
Okay, that’s… a bit anal. Just played around with ResEd. One can ‘select’ the state of Option and Radio “gadgets” but the style cannot be changed, so it’s hardwired to whatever the system default is. Conversely, one can set up all sorts of attributes of Button gadgets, except for the selected state. It looks (reading the StrongHelp info) that this could be done on-the-fly using button_set_flags() with the Clear word and EOR word mapping pretty much directly onto Wimp_SetIconState, so set Clear/EOR both to 1<<21 to set the button as selected, or Clear to 1<<21 and EOR to 0 to set the button as unselected. You will likely need to handle all select/deselect behaviour yourself - I note that you haven’t set the icon type as Radio, so the Wimp won’t do it for you. Thank you for this question. It reminds me why I still use Templates. Sometimes less is more. :-) |
Aleksey Murushkin (Cloverleaf) (8233) 41 posts |
I set the button type to radio so wimp does it for me. it works perfect select/deselect. I just wanted to know how to set the initial state and then read it when needed. so now i know that i was correct that i need to use button_set_flags. I did not find info which bit to use. so now i know that i need to set bit 21. Thanks |
Rick Murray (539) 13890 posts |
Glad to have been of help. |
Chris Johns (8262) 242 posts |
For reference, the icon flags are listed here https://www.riscosopen.org/wiki/documentation/show/Icon%20Flags although a note in the toolbox docs suggest that not all are supported by the toolbox button. Looks like the one you want is though, so that’s good :) |