added support for GTK2 label mnemonics (patch #689573)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19484 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
53eff2a282
commit
eaafd2f8b7
@ -69,6 +69,7 @@ Unix:
|
||||
|
||||
wxGTK:
|
||||
|
||||
- added support for label mnemonics to GTK+2 build (Michael Moss)
|
||||
- added native wxMessageDialog implementation for GTK+2 build
|
||||
- fixed wxMenu::Remove (John Skiff and Benjamin Williams)
|
||||
- made wxTextCtrl::EmulateKeyPress() work for Delete and Backspace
|
||||
|
@ -55,6 +55,9 @@ public:
|
||||
|
||||
protected:
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
#ifdef __WXGTK20__
|
||||
wxString PrepareLabelMnemonics( const wxString &label ) const;
|
||||
#endif
|
||||
|
||||
wxString m_label;
|
||||
char m_chAccel; // enabled to avoid breaking binary compatibility later on
|
||||
|
@ -55,6 +55,9 @@ public:
|
||||
|
||||
protected:
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
#ifdef __WXGTK20__
|
||||
wxString PrepareLabelMnemonics( const wxString &label ) const;
|
||||
#endif
|
||||
|
||||
wxString m_label;
|
||||
char m_chAccel; // enabled to avoid breaking binary compatibility later on
|
||||
|
@ -175,7 +175,12 @@ void wxButton::SetLabel( const wxString &label )
|
||||
|
||||
wxControl::SetLabel( label );
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
wxString label2 = PrepareLabelMnemonics( label );
|
||||
gtk_label_set_text_with_mnemonic( GTK_LABEL( BUTTON_CHILD(m_widget) ), wxGTK_CONV( label2 ) );
|
||||
#else
|
||||
gtk_label_set( GTK_LABEL( BUTTON_CHILD(m_widget) ), wxGTK_CONV( GetLabel() ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
bool wxButton::Enable( bool enable )
|
||||
|
@ -85,8 +85,6 @@ bool wxCheckBox::Create(wxWindow *parent,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wxControl::SetLabel( label );
|
||||
|
||||
if ( style & wxALIGN_RIGHT )
|
||||
{
|
||||
// VZ: as I don't know a way to create a right aligned checkbox with
|
||||
@ -94,7 +92,7 @@ bool wxCheckBox::Create(wxWindow *parent,
|
||||
// left of it
|
||||
m_widgetCheckbox = gtk_check_button_new();
|
||||
|
||||
m_widgetLabel = gtk_label_new( wxGTK_CONV( m_label ) );
|
||||
m_widgetLabel = gtk_label_new("");
|
||||
gtk_misc_set_alignment(GTK_MISC(m_widgetLabel), 0.0, 0.5);
|
||||
|
||||
m_widget = gtk_hbox_new(FALSE, 0);
|
||||
@ -106,10 +104,11 @@ bool wxCheckBox::Create(wxWindow *parent,
|
||||
}
|
||||
else
|
||||
{
|
||||
m_widgetCheckbox = gtk_check_button_new_with_label( wxGTK_CONV( m_label ) );
|
||||
m_widgetCheckbox = gtk_check_button_new_with_label("");
|
||||
m_widgetLabel = BUTTON_CHILD( m_widgetCheckbox );
|
||||
m_widget = m_widgetCheckbox;
|
||||
}
|
||||
SetLabel( label );
|
||||
|
||||
gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox),
|
||||
"clicked",
|
||||
@ -166,7 +165,12 @@ void wxCheckBox::SetLabel( const wxString& label )
|
||||
|
||||
wxControl::SetLabel( label );
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
wxString label2 = PrepareLabelMnemonics( label );
|
||||
gtk_label_set_text_with_mnemonic( GTK_LABEL(m_widgetLabel), wxGTK_CONV( label2 ) );
|
||||
#else
|
||||
gtk_label_set( GTK_LABEL(m_widgetLabel), wxGTK_CONV( GetLabel() ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
bool wxCheckBox::Enable( bool enable )
|
||||
|
@ -83,5 +83,47 @@ wxSize wxControl::DoGetBestSize() const
|
||||
return wxSize(req.width, req.height);
|
||||
}
|
||||
|
||||
wxString wxControl::PrepareLabelMnemonics( const wxString &label ) const
|
||||
{
|
||||
//Format mnemonics properly for GTK2. This can be called from GTK1.x, but
|
||||
//it's not very useful because mnemonics don't exist prior to GTK2.
|
||||
wxString label2;
|
||||
for (size_t i = 0; i < label.Len(); i++)
|
||||
{
|
||||
if (label.GetChar(i) == wxT('&'))
|
||||
{
|
||||
//Mnemonic escape sequence "&&" is a literal "&" in the output.
|
||||
if (label.GetChar(i + 1) == wxT('&'))
|
||||
{
|
||||
label2 << wxT('&');
|
||||
i++;
|
||||
}
|
||||
//Handle special case of "&_" (i.e. "_" is the mnemonic).
|
||||
//FIXME - Is it possible to use "_" as a GTK mnemonic? Just use a
|
||||
//dash for now.
|
||||
else if (label.GetChar(i + 1) == wxT('_'))
|
||||
{
|
||||
label2 << wxT("_-");
|
||||
i++;
|
||||
}
|
||||
//Replace WX mnemonic indicator "&" with GTK indicator "_".
|
||||
else
|
||||
{
|
||||
label2 << wxT('_');
|
||||
}
|
||||
}
|
||||
else if (label.GetChar(i) == wxT('_'))
|
||||
{
|
||||
//Escape any underlines in the string so GTK doesn't use them.
|
||||
label2 << wxT("__");
|
||||
}
|
||||
else
|
||||
{
|
||||
label2 << label.GetChar(i);
|
||||
}
|
||||
}
|
||||
return label2;
|
||||
}
|
||||
|
||||
#endif // wxUSE_CONTROLS
|
||||
|
||||
|
@ -154,7 +154,12 @@ void wxRadioButton::SetLabel( const wxString& label )
|
||||
|
||||
wxControl::SetLabel( label );
|
||||
GtkLabel *g_label = GTK_LABEL( BUTTON_CHILD(m_widget) );
|
||||
#ifdef __WXGTK20__
|
||||
wxString label2 = PrepareLabelMnemonics( label );
|
||||
gtk_label_set_text_with_mnemonic( g_label, wxGTK_CONV( label2 ) );
|
||||
#else
|
||||
gtk_label_set( g_label, wxGTK_CONV( GetLabel() ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxRadioButton::SetValue( bool val )
|
||||
|
@ -175,7 +175,12 @@ void wxButton::SetLabel( const wxString &label )
|
||||
|
||||
wxControl::SetLabel( label );
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
wxString label2 = PrepareLabelMnemonics( label );
|
||||
gtk_label_set_text_with_mnemonic( GTK_LABEL( BUTTON_CHILD(m_widget) ), wxGTK_CONV( label2 ) );
|
||||
#else
|
||||
gtk_label_set( GTK_LABEL( BUTTON_CHILD(m_widget) ), wxGTK_CONV( GetLabel() ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
bool wxButton::Enable( bool enable )
|
||||
|
@ -85,8 +85,6 @@ bool wxCheckBox::Create(wxWindow *parent,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wxControl::SetLabel( label );
|
||||
|
||||
if ( style & wxALIGN_RIGHT )
|
||||
{
|
||||
// VZ: as I don't know a way to create a right aligned checkbox with
|
||||
@ -94,7 +92,7 @@ bool wxCheckBox::Create(wxWindow *parent,
|
||||
// left of it
|
||||
m_widgetCheckbox = gtk_check_button_new();
|
||||
|
||||
m_widgetLabel = gtk_label_new( wxGTK_CONV( m_label ) );
|
||||
m_widgetLabel = gtk_label_new("");
|
||||
gtk_misc_set_alignment(GTK_MISC(m_widgetLabel), 0.0, 0.5);
|
||||
|
||||
m_widget = gtk_hbox_new(FALSE, 0);
|
||||
@ -106,10 +104,11 @@ bool wxCheckBox::Create(wxWindow *parent,
|
||||
}
|
||||
else
|
||||
{
|
||||
m_widgetCheckbox = gtk_check_button_new_with_label( wxGTK_CONV( m_label ) );
|
||||
m_widgetCheckbox = gtk_check_button_new_with_label("");
|
||||
m_widgetLabel = BUTTON_CHILD( m_widgetCheckbox );
|
||||
m_widget = m_widgetCheckbox;
|
||||
}
|
||||
SetLabel( label );
|
||||
|
||||
gtk_signal_connect( GTK_OBJECT(m_widgetCheckbox),
|
||||
"clicked",
|
||||
@ -166,7 +165,12 @@ void wxCheckBox::SetLabel( const wxString& label )
|
||||
|
||||
wxControl::SetLabel( label );
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
wxString label2 = PrepareLabelMnemonics( label );
|
||||
gtk_label_set_text_with_mnemonic( GTK_LABEL(m_widgetLabel), wxGTK_CONV( label2 ) );
|
||||
#else
|
||||
gtk_label_set( GTK_LABEL(m_widgetLabel), wxGTK_CONV( GetLabel() ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
bool wxCheckBox::Enable( bool enable )
|
||||
|
@ -83,5 +83,47 @@ wxSize wxControl::DoGetBestSize() const
|
||||
return wxSize(req.width, req.height);
|
||||
}
|
||||
|
||||
wxString wxControl::PrepareLabelMnemonics( const wxString &label ) const
|
||||
{
|
||||
//Format mnemonics properly for GTK2. This can be called from GTK1.x, but
|
||||
//it's not very useful because mnemonics don't exist prior to GTK2.
|
||||
wxString label2;
|
||||
for (size_t i = 0; i < label.Len(); i++)
|
||||
{
|
||||
if (label.GetChar(i) == wxT('&'))
|
||||
{
|
||||
//Mnemonic escape sequence "&&" is a literal "&" in the output.
|
||||
if (label.GetChar(i + 1) == wxT('&'))
|
||||
{
|
||||
label2 << wxT('&');
|
||||
i++;
|
||||
}
|
||||
//Handle special case of "&_" (i.e. "_" is the mnemonic).
|
||||
//FIXME - Is it possible to use "_" as a GTK mnemonic? Just use a
|
||||
//dash for now.
|
||||
else if (label.GetChar(i + 1) == wxT('_'))
|
||||
{
|
||||
label2 << wxT("_-");
|
||||
i++;
|
||||
}
|
||||
//Replace WX mnemonic indicator "&" with GTK indicator "_".
|
||||
else
|
||||
{
|
||||
label2 << wxT('_');
|
||||
}
|
||||
}
|
||||
else if (label.GetChar(i) == wxT('_'))
|
||||
{
|
||||
//Escape any underlines in the string so GTK doesn't use them.
|
||||
label2 << wxT("__");
|
||||
}
|
||||
else
|
||||
{
|
||||
label2 << label.GetChar(i);
|
||||
}
|
||||
}
|
||||
return label2;
|
||||
}
|
||||
|
||||
#endif // wxUSE_CONTROLS
|
||||
|
||||
|
@ -154,7 +154,12 @@ void wxRadioButton::SetLabel( const wxString& label )
|
||||
|
||||
wxControl::SetLabel( label );
|
||||
GtkLabel *g_label = GTK_LABEL( BUTTON_CHILD(m_widget) );
|
||||
#ifdef __WXGTK20__
|
||||
wxString label2 = PrepareLabelMnemonics( label );
|
||||
gtk_label_set_text_with_mnemonic( g_label, wxGTK_CONV( label2 ) );
|
||||
#else
|
||||
gtk_label_set( g_label, wxGTK_CONV( GetLabel() ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxRadioButton::SetValue( bool val )
|
||||
|
Loading…
Reference in New Issue
Block a user