#15233 closed defect (fixed)

wxRadioBox::SetSelection(-1) is documented to work but doesn't

Reported by: derik.schroeter@… Owned by:
Priority: low Milestone:
Component: GUI-all Version:
Keywords: Cc:
Blocked By: Blocking:
Patch: no

Description

Documentation reads: "Sets the selection to the given item n or removes the selection entirely if n == wxNOT_FOUND."

The latter part, although sensible and in my case desired, doesn't work. It allows to initialize the radiobox without selection, and also return to that state at any later point.

That's what it is:

void wxRadioBox::SetSelection(int N)
{

wxCHECK_RET( IsValid(N), wxT("invalid radiobox index") );

unselect the old button
if ( m_selectedButton != wxNOT_FOUND )

::SendMessage((*m_radioButtons)[m_selectedButton], BM_SETCHECK, 0, 0L);

and select the new one
::SendMessage((*m_radioButtons)[N], BM_SETCHECK, 1, 0L);

m_selectedButton = N;

}

That's what, I think, it should be:
void wxRadioBox::SetSelection(int N)
{

wxCHECK_RET( IsValid(N), wxT("invalid radiobox index") );

unselect the old button
if ( m_selectedButton != wxNOT_FOUND )

::SendMessage((*m_radioButtons)[m_selectedButton], BM_SETCHECK, 0, 0L);

and select the new one
if ( IsValid(N) )

::SendMessage((*m_radioButtons)[N], BM_SETCHECK, 1, 0L);

m_selectedButton = N;

}

Change History (3)

comment:1 Changed 14 months ago by vadz

  • Component changed from wxMSW to GUI-all
  • Priority changed from normal to low
  • Summary changed from msw/radiobox.cpp to wxRadioBox::SetSelection(-1) is documented to work but doesn't

I'm not sure if it really makes sense to not have any selection in wxRadioBox, normally a group of radio items is always supposed to have exactly one button selected. And I don't think we can avoid having it in generic implementation used by e.g. wxOSX anyhow.

So I'd rather change the documentation to say that the selection can't be unset.

Any other thoughts about this?

comment:2 Changed 14 months ago by derik.schroeter@…

I think, no selection can very well make sense, for example, if making any selection would imply a considerable amount of initialization and possibly specific GUI-adjustment. I understand, we could use a popup-menu, selection-list or similar, where the initial selection is "None", but it would be nice to have the radiobox as an option, well, I guess, I could also put "None" as an option in the radiobox, but still... :-) Well, it's not really a big issue, and I honestly don't know, how this would effect other ports etc.

comment:3 Changed 14 months ago by VZ

  • Resolution set to fixed
  • Status changed from new to closed

(In [74073]) Document that wxRadioBox::SetSelection() doesn't accept wxNOT_FOUND.

A radio box always has selection and it can't be unset (at least not under all
platforms), so document that the item passed to its SetSelection() must be
valid, unlike with SetSelection() methods in some other classes.

Closes #15233.

Note: See TracTickets for help on using tickets.