Fix displaying labels of wxRadioBox items

Labels containing mnemonic prefixes (&) and literal underscore characters
have to be converted to the proper GTK labels where underscore
characters act as mnemonic markers. If label contains mnemonic then
dedicated function gtk_radio_button_new_with_mnemonic() should be used
to create radio button item.

Closes #17419.
This commit is contained in:
Artur Wieczorek
2017-04-25 18:11:39 +02:00
parent 148e8971c7
commit 37ecd7b760
2 changed files with 43 additions and 6 deletions

View File

@@ -148,6 +148,7 @@ wxGTK:
- Fix wxDC::GetClippingBox() for transformed wxDC.
- Add support for affine transformation matrix in wxDC (GTK+ 3).
- Fix wxMemoryDC::Blit() with itself as source (GTK+ 3).
- Fix displaying labels of wxRadioBox items.
wxMSW:

View File

@@ -246,22 +246,58 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
gtk_widget_show( table );
gtk_container_add( GTK_CONTAINER(m_widget), table );
wxString label;
GSList *radio_button_group = NULL;
for (unsigned int i = 0; i < (unsigned int)n; i++)
{
if ( i != 0 )
radio_button_group = gtk_radio_button_get_group( GTK_RADIO_BUTTON(rbtn) );
label.Empty();
// Process mnemonic in the label
wxString label;
bool hasMnemonic = false;
for ( wxString::const_iterator pc = choices[i].begin();
pc != choices[i].end(); ++pc )
{
if ( *pc != wxT('&') )
label += *pc;
}
if ( *pc == wxS('_') )
{
// If we have a literal underscore character in the label
// containing mnemonic, two underscores should be used.
if ( hasMnemonic )
label += wxS('_');
}
else if ( *pc == wxS('&') )
{
++pc; // skip it
if ( pc == choices[i].end() )
{
break;
}
else if ( *pc != wxS('&') )
{
if ( !hasMnemonic )
{
hasMnemonic = true;
// So far we assumed that label doesn't contain mnemonic
// and therefore single underscore characters were not
// replaced by two underscores. Now we have to double
// all exisiting underscore characters.
label.Replace(wxS("_"), wxS("__"));
label += wxS('_');
}
else
{
wxFAIL_MSG(wxT("duplicate mnemonic char in radio button label"));
}
}
}
label += *pc;
}
if ( hasMnemonic )
rbtn = GTK_RADIO_BUTTON( gtk_radio_button_new_with_mnemonic( radio_button_group, wxGTK_CONV( label ) ) );
else
rbtn = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) );
rbtn = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) );
gtk_widget_show( GTK_WIDGET(rbtn) );
g_signal_connect (rbtn, "key_press_event",