walk icon indicating copy to clipboard operation
walk copied to clipboard

Radiobuttons are not working properly

Open lpintes opened this issue 4 years ago • 1 comments

I tested this with databinding example.

  1. Click Edit animal.
  2. Use the tab key to move through controls. You will see that the three radio buttons are checked one after other, but only the first time. The focus moves as I expect when some radiobutton is checked.
  3. I would expect to focus only one radio button in group, even if none is checked.

lpintes avatar Oct 02 '19 20:10 lpintes

This is a fix for that bug:

LXN/Walk -- bug -- RadiobButtonGroup may not set WS_TABSTOP for its buttons

Error = The tabstop style-property may only be set for a single button of the button group. Effect = On first visit the field value will change to something that was NOT selected and [tab] and [shift-tab] do not work properly. After kill-focus of the group the tabstops of the not selected buttons get cleared and (when cycling around with [tab] the next visit to the group tab and arrows work properly Reason = Windows uses the WS_GROUP and BS_AUTORADIOBUTTON to set and clear the tabstop by itself. Fix = Not set the tabstop property (this then gets corrected on the first Set() of the field.

Modify -> C:\Users\username\go\src\github.com\username\walk\radiobutton.go

func NewRadioButton(parent Container) (*RadioButton, error) {
	rb := new(RadioButton)

	if count := parent.Children().Len(); count > 0 {
		if prevRB, ok := parent.Children().At(count - 1).(radioButtonish); ok {
			rb.group = prevRB.radioButton().group
		}
	}
	var groupBit uint32
	if rb.group == nil {
		//groupBit = win.WS_GROUP
		groupBit = win.WS_GROUP|win.WS_TABSTOP
		rb.group = new(RadioButtonGroup)
	}

	if err := InitWidget(
		rb,
		parent,
		"BUTTON",
		//groupBit|win.WS_TABSTOP|win.WS_VISIBLE|win.BS_AUTORADIOBUTTON,
		groupBit|win.WS_VISIBLE|win.BS_AUTORADIOBUTTON,
		0); err != nil {
		return nil, err
	}

	...

https://docs.microsoft.com/en-us/windows/win32/winmsg/window-styles

  • WS_GROUP = 0x00020000L

    The window is the first control of a group of controls. The group consists of this first control and all controls defined after it, up to the next control with the WS_GROUP style. The first control in each group usually has the WS_TABSTOP style so that the user can move from group to group. The user can subsequently change the keyboard focus from one control in the group to the next control in the group by using the direction keys. You can turn this style on and off to change dialog box navigation. To change this style after a window has been created, use the SetWindowLong function.

  • BS_AUTORADIOBUTTON

    Creates a button that is the same as a radio button, except that when the user selects it, the system automatically sets the button's check state to checked and automatically sets the check state for all other buttons in the same group to cleared.

StephanVerbeeck avatar Jan 22 '21 14:01 StephanVerbeeck