1. changed wxControl::GetLabel() to return the originally provided label and
not the one stripped from mnemonics (this was inconsistent with the other ports and resulted in problems when using wxUpdateUIEvent::SetText()) 2. added wxControl::GTKConvertMnemonics(), GTKRemoveMnemonics() and also helper GTKSetLabelForLabel() and GTKSetLabelForFrame() wrappers 3. use them instead of duplicating their code in different derived controls git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36435 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxControl;
|
class WXDLLIMPEXP_CORE wxControl;
|
||||||
|
|
||||||
|
typedef struct _GtkLabel GtkLabel;
|
||||||
|
typedef struct _GtkFrame GtkFrame;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxControl
|
// wxControl
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -51,8 +54,6 @@ public:
|
|||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
const wxString& name = wxControlNameStr);
|
const wxString& name = wxControlNameStr);
|
||||||
|
|
||||||
// this function will filter out '&' characters and will put the accelerator
|
|
||||||
// char (the one immediately after '&') into m_chAccel (TODO not yet)
|
|
||||||
virtual void SetLabel( const wxString &label );
|
virtual void SetLabel( const wxString &label );
|
||||||
virtual wxString GetLabel() const;
|
virtual wxString GetLabel() const;
|
||||||
|
|
||||||
@@ -62,9 +63,20 @@ protected:
|
|||||||
virtual wxSize DoGetBestSize() const;
|
virtual wxSize DoGetBestSize() const;
|
||||||
void PostCreation(const wxSize& size);
|
void PostCreation(const wxSize& size);
|
||||||
|
|
||||||
#ifdef __WXGTK20__
|
// sets the label to the given string and also sets it for the given widget
|
||||||
wxString PrepareLabelMnemonics( const wxString &label ) const;
|
void GTKSetLabelForLabel(GtkLabel *w, const wxString& label);
|
||||||
#endif
|
|
||||||
|
// as GTKSetLabelForLabel() but for a GtkFrame widget
|
||||||
|
void GTKSetLabelForFrame(GtkFrame *w, const wxString& label);
|
||||||
|
|
||||||
|
// remove mnemonics ("&"s) from the label
|
||||||
|
static wxString GTKRemoveMnemonics(const wxString& label);
|
||||||
|
|
||||||
|
// converts wx label to GTK+ label, i.e. basically replace "&"s with "_"s
|
||||||
|
//
|
||||||
|
// for GTK+ 1 (which doesn't support mnemonics) this is the same as
|
||||||
|
// GTKRemoveMnemonics()
|
||||||
|
static wxString GTKConvertMnemonics(const wxString &label);
|
||||||
|
|
||||||
// These are used by GetDefaultAttributes
|
// These are used by GetDefaultAttributes
|
||||||
static wxVisualAttributes
|
static wxVisualAttributes
|
||||||
@@ -89,8 +101,8 @@ protected:
|
|||||||
// override this and return true.
|
// override this and return true.
|
||||||
virtual bool UseGTKStyleBase() const { return false; }
|
virtual bool UseGTKStyleBase() const { return false; }
|
||||||
|
|
||||||
|
// this field contains the label in wx format, i.e. with "&" mnemonics
|
||||||
wxString m_label;
|
wxString m_label;
|
||||||
char m_chAccel; // enabled to avoid breaking binary compatibility later on
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_DYNAMIC_CLASS(wxControl)
|
DECLARE_DYNAMIC_CLASS(wxControl)
|
||||||
|
@@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxControl;
|
class WXDLLIMPEXP_CORE wxControl;
|
||||||
|
|
||||||
|
typedef struct _GtkLabel GtkLabel;
|
||||||
|
typedef struct _GtkFrame GtkFrame;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxControl
|
// wxControl
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -51,8 +54,6 @@ public:
|
|||||||
const wxValidator& validator = wxDefaultValidator,
|
const wxValidator& validator = wxDefaultValidator,
|
||||||
const wxString& name = wxControlNameStr);
|
const wxString& name = wxControlNameStr);
|
||||||
|
|
||||||
// this function will filter out '&' characters and will put the accelerator
|
|
||||||
// char (the one immediately after '&') into m_chAccel (TODO not yet)
|
|
||||||
virtual void SetLabel( const wxString &label );
|
virtual void SetLabel( const wxString &label );
|
||||||
virtual wxString GetLabel() const;
|
virtual wxString GetLabel() const;
|
||||||
|
|
||||||
@@ -62,9 +63,20 @@ protected:
|
|||||||
virtual wxSize DoGetBestSize() const;
|
virtual wxSize DoGetBestSize() const;
|
||||||
void PostCreation(const wxSize& size);
|
void PostCreation(const wxSize& size);
|
||||||
|
|
||||||
#ifdef __WXGTK20__
|
// sets the label to the given string and also sets it for the given widget
|
||||||
wxString PrepareLabelMnemonics( const wxString &label ) const;
|
void GTKSetLabelForLabel(GtkLabel *w, const wxString& label);
|
||||||
#endif
|
|
||||||
|
// as GTKSetLabelForLabel() but for a GtkFrame widget
|
||||||
|
void GTKSetLabelForFrame(GtkFrame *w, const wxString& label);
|
||||||
|
|
||||||
|
// remove mnemonics ("&"s) from the label
|
||||||
|
static wxString GTKRemoveMnemonics(const wxString& label);
|
||||||
|
|
||||||
|
// converts wx label to GTK+ label, i.e. basically replace "&"s with "_"s
|
||||||
|
//
|
||||||
|
// for GTK+ 1 (which doesn't support mnemonics) this is the same as
|
||||||
|
// GTKRemoveMnemonics()
|
||||||
|
static wxString GTKConvertMnemonics(const wxString &label);
|
||||||
|
|
||||||
// These are used by GetDefaultAttributes
|
// These are used by GetDefaultAttributes
|
||||||
static wxVisualAttributes
|
static wxVisualAttributes
|
||||||
@@ -89,8 +101,8 @@ protected:
|
|||||||
// override this and return true.
|
// override this and return true.
|
||||||
virtual bool UseGTKStyleBase() const { return false; }
|
virtual bool UseGTKStyleBase() const { return false; }
|
||||||
|
|
||||||
|
// this field contains the label in wx format, i.e. with "&" mnemonics
|
||||||
wxString m_label;
|
wxString m_label;
|
||||||
char m_chAccel; // enabled to avoid breaking binary compatibility later on
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_DYNAMIC_CLASS(wxControl)
|
DECLARE_DYNAMIC_CLASS(wxControl)
|
||||||
|
@@ -130,28 +130,6 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
wxString label2( label );
|
|
||||||
for (size_t i = 0; i < label2.Len(); i++)
|
|
||||||
{
|
|
||||||
if (label2.GetChar(i) == wxT('&'))
|
|
||||||
label2.SetChar(i,wxT('_'));
|
|
||||||
}
|
|
||||||
|
|
||||||
GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() );
|
|
||||||
gtk_widget_show( accel_label );
|
|
||||||
|
|
||||||
m_widget = gtk_button_new();
|
|
||||||
gtk_container_add( GTK_CONTAINER(m_widget), accel_label );
|
|
||||||
|
|
||||||
gtk_accel_label_set_accel_widget( GTK_ACCEL_LABEL(accel_label), m_widget );
|
|
||||||
|
|
||||||
guint accel_key = gtk_label_parse_uline (GTK_LABEL(accel_label), label2.mb_str() );
|
|
||||||
gtk_accel_label_refetch( GTK_ACCEL_LABEL(accel_label) );
|
|
||||||
|
|
||||||
wxControl::SetLabel( label );
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __WXGTK20__
|
#ifdef __WXGTK20__
|
||||||
m_widget = gtk_button_new_with_mnemonic("");
|
m_widget = gtk_button_new_with_mnemonic("");
|
||||||
#else
|
#else
|
||||||
@@ -266,6 +244,8 @@ void wxButton::SetLabel( const wxString &lbl )
|
|||||||
|
|
||||||
wxControl::SetLabel(label);
|
wxControl::SetLabel(label);
|
||||||
|
|
||||||
|
const wxString labelGTK = GTKConvertMnemonics(label);
|
||||||
|
|
||||||
#ifdef __WXGTK20__
|
#ifdef __WXGTK20__
|
||||||
if (wxIsStockID(m_windowId) && wxIsStockLabel(m_windowId, label))
|
if (wxIsStockID(m_windowId) && wxIsStockLabel(m_windowId, label))
|
||||||
{
|
{
|
||||||
@@ -278,15 +258,13 @@ void wxButton::SetLabel( const wxString &lbl )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString label2 = PrepareLabelMnemonics(label);
|
gtk_button_set_label(GTK_BUTTON(m_widget), wxGTK_CONV(labelGTK));
|
||||||
gtk_button_set_label(GTK_BUTTON(m_widget), wxGTK_CONV(label2));
|
|
||||||
gtk_button_set_use_stock(GTK_BUTTON(m_widget), FALSE);
|
gtk_button_set_use_stock(GTK_BUTTON(m_widget), FALSE);
|
||||||
|
|
||||||
ApplyWidgetStyle( false );
|
ApplyWidgetStyle( false );
|
||||||
|
#else // GTK+ 1
|
||||||
#else
|
gtk_label_set(GTK_LABEL(BUTTON_CHILD(m_widget)), wxGTK_CONV(labelGTK));
|
||||||
gtk_label_set(GTK_LABEL(BUTTON_CHILD(m_widget)), wxGTK_CONV(GetLabel()));
|
#endif // GTK+ 2/1
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxButton::Enable( bool enable )
|
bool wxButton::Enable( bool enable )
|
||||||
|
@@ -229,14 +229,7 @@ void wxCheckBox::SetLabel( const wxString& label )
|
|||||||
{
|
{
|
||||||
wxCHECK_RET( m_widgetLabel != NULL, wxT("invalid checkbox") );
|
wxCHECK_RET( m_widgetLabel != NULL, wxT("invalid checkbox") );
|
||||||
|
|
||||||
wxControl::SetLabel( label );
|
GTKSetLabelForLabel(GTK_LABEL(m_widgetLabel), 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 )
|
bool wxCheckBox::Enable( bool enable )
|
||||||
|
@@ -17,8 +17,7 @@
|
|||||||
#include "wx/control.h"
|
#include "wx/control.h"
|
||||||
#include "wx/fontutil.h"
|
#include "wx/fontutil.h"
|
||||||
#include "wx/settings.h"
|
#include "wx/settings.h"
|
||||||
|
#include "wx/gtk/private.h"
|
||||||
#include <gtk/gtk.h>
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxControl
|
// wxControl
|
||||||
@@ -48,29 +47,6 @@ bool wxControl::Create( wxWindow *parent,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxControl::SetLabel( const wxString &label )
|
|
||||||
{
|
|
||||||
m_label.Empty();
|
|
||||||
for ( const wxChar *pc = label; *pc != wxT('\0'); pc++ )
|
|
||||||
{
|
|
||||||
if ( *pc == wxT('&') )
|
|
||||||
{
|
|
||||||
pc++; // skip it
|
|
||||||
#if 0 // it would be unused anyhow for now - kbd interface not done yet
|
|
||||||
if ( *pc != wxT('&') ) m_chAccel = *pc;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
m_label << *pc;
|
|
||||||
}
|
|
||||||
InvalidateBestSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString wxControl::GetLabel() const
|
|
||||||
{
|
|
||||||
return m_label;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
wxSize wxControl::DoGetBestSize() const
|
wxSize wxControl::DoGetBestSize() const
|
||||||
{
|
{
|
||||||
// Do not return any arbitrary default value...
|
// Do not return any arbitrary default value...
|
||||||
@@ -103,51 +79,138 @@ void wxControl::PostCreation(const wxSize& size)
|
|||||||
SetInitialBestSize(size);
|
SetInitialBestSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxControl dealing with labels
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void wxControl::SetLabel( const wxString &label )
|
||||||
|
{
|
||||||
|
// keep the original string internally to be able to return it later (for
|
||||||
|
// consistency with the other ports)
|
||||||
|
m_label = label;
|
||||||
|
|
||||||
|
InvalidateBestSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString wxControl::GetLabel() const
|
||||||
|
{
|
||||||
|
return m_label;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxControl::GTKSetLabelForLabel(GtkLabel *w, const wxString& label)
|
||||||
|
{
|
||||||
|
// don't call the virtual function which might call this one back again
|
||||||
|
wxControl::SetLabel(label);
|
||||||
|
|
||||||
|
const wxString labelGTK = GTKConvertMnemonics(label);
|
||||||
|
|
||||||
#ifdef __WXGTK20__
|
#ifdef __WXGTK20__
|
||||||
wxString wxControl::PrepareLabelMnemonics( const wxString &label ) const
|
gtk_label_set_text_with_mnemonic(w, wxGTK_CONV(labelGTK));
|
||||||
{
|
#else
|
||||||
//Format mnemonics properly for GTK2. This can be called from GTK1.x, but
|
gtk_label_set(w, wxGTK_CONV(labelGTK));
|
||||||
//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
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxControl::GTKSetLabelForFrame(GtkFrame *w, const wxString& label)
|
||||||
|
{
|
||||||
|
wxControl::SetLabel(label);
|
||||||
|
|
||||||
|
// frames don't support mnemonics even under GTK+ 2
|
||||||
|
const wxString labelGTK = GTKRemoveMnemonics(label);
|
||||||
|
|
||||||
|
gtk_frame_set_label(w, labelGTK.empty() ? (char *)NULL
|
||||||
|
: wxGTK_CONV(labelGTK));
|
||||||
|
}
|
||||||
|
|
||||||
|
// worker function implementing both GTKConvert/RemoveMnemonics()
|
||||||
|
//
|
||||||
|
// notice that under GTK+ 1 we only really need to support MNEMONICS_REMOVE as
|
||||||
|
// it doesn't support mnemonics anyhow but this would make the code so ugly
|
||||||
|
// that we do the same thing for GKT+ 1 and 2
|
||||||
|
enum MnemonicsFlag
|
||||||
|
{
|
||||||
|
MNEMONICS_REMOVE,
|
||||||
|
MNEMONICS_CONVERT
|
||||||
|
};
|
||||||
|
|
||||||
|
static wxString GTKProcessMnemonics(const wxString& label, MnemonicsFlag flag)
|
||||||
|
{
|
||||||
|
const size_t len = label.length();
|
||||||
|
wxString labelGTK;
|
||||||
|
labelGTK.reserve(len);
|
||||||
|
for ( size_t i = 0; i < len; i++ )
|
||||||
|
{
|
||||||
|
wxChar ch = label[i];
|
||||||
|
|
||||||
|
switch ( ch )
|
||||||
|
{
|
||||||
|
case wxT('&'):
|
||||||
|
if ( i == len - 1 )
|
||||||
|
{
|
||||||
|
// "&" at the end of string is an error
|
||||||
|
wxLogDebug(wxT("Invalid label \"%s\"."), label.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ch = label[++i]; // skip '&' itself
|
||||||
|
switch ( ch )
|
||||||
|
{
|
||||||
|
case wxT('&'):
|
||||||
|
// special case: "&&" is not a mnemonic at all but just
|
||||||
|
// an escaped "&"
|
||||||
|
labelGTK += wxT('&');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxT('_'):
|
||||||
|
if ( flag == MNEMONICS_CONVERT )
|
||||||
|
{
|
||||||
|
// '_' can't be a GTK mnemonic apparently so
|
||||||
|
// replace it with something similar
|
||||||
|
labelGTK += wxT("_-");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//else: fall through
|
||||||
|
|
||||||
|
default:
|
||||||
|
if ( flag == MNEMONICS_CONVERT )
|
||||||
|
labelGTK += wxT('_');
|
||||||
|
labelGTK += ch;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxT('_'):
|
||||||
|
if ( flag == MNEMONICS_CONVERT )
|
||||||
|
{
|
||||||
|
// escape any existing underlines in the string so that
|
||||||
|
// they don't become mnemonics accidentally
|
||||||
|
labelGTK += wxT("__");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//else: fall through
|
||||||
|
|
||||||
|
default:
|
||||||
|
labelGTK += ch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return labelGTK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
wxString wxControl::GTKRemoveMnemonics(const wxString& label)
|
||||||
|
{
|
||||||
|
return GTKProcessMnemonics(label, MNEMONICS_REMOVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
wxString wxControl::GTKConvertMnemonics(const wxString& label)
|
||||||
|
{
|
||||||
|
return GTKProcessMnemonics(label, MNEMONICS_CONVERT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxControl styles (a.k.a. attributes)
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxVisualAttributes wxControl::GetDefaultAttributes() const
|
wxVisualAttributes wxControl::GetDefaultAttributes() const
|
||||||
{
|
{
|
||||||
|
@@ -198,7 +198,8 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_widget = gtk_frame_new( wxGTK_CONV( title ) );
|
m_widget = gtk_frame_new(NULL);
|
||||||
|
SetLabel(title);
|
||||||
|
|
||||||
// majorDim may be 0 if all trailing parameters were omitted, so don't
|
// majorDim may be 0 if all trailing parameters were omitted, so don't
|
||||||
// assert here but just use the correct value for it
|
// assert here but just use the correct value for it
|
||||||
@@ -273,8 +274,6 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
|
|||||||
|
|
||||||
m_parent->DoAddChild( this );
|
m_parent->DoAddChild( this );
|
||||||
|
|
||||||
SetLabel( title );
|
|
||||||
|
|
||||||
PostCreation(size);
|
PostCreation(size);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -399,9 +398,7 @@ void wxRadioBox::SetLabel( const wxString& label )
|
|||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
|
wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
|
||||||
|
|
||||||
wxControl::SetLabel( label );
|
GTKSetLabelForFrame(GTK_FRAME(m_widget), label);
|
||||||
|
|
||||||
gtk_frame_set_label( GTK_FRAME(m_widget), wxGTK_CONV( wxControl::GetLabel() ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxRadioBox::SetString( int item, const wxString& label )
|
void wxRadioBox::SetString( int item, const wxString& label )
|
||||||
|
@@ -125,14 +125,7 @@ void wxRadioButton::SetLabel( const wxString& label )
|
|||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid radiobutton") );
|
wxCHECK_RET( m_widget != NULL, wxT("invalid radiobutton") );
|
||||||
|
|
||||||
wxControl::SetLabel( label );
|
GTKSetLabelForLabel(GTK_LABEL(BUTTON_CHILD(m_widget)), 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 )
|
void wxRadioButton::SetValue( bool val )
|
||||||
|
@@ -56,9 +56,8 @@ bool wxStaticBox::Create( wxWindow *parent,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxControl::SetLabel(label);
|
m_widget = gtk_frame_new(NULL);
|
||||||
|
SetLabel(label);
|
||||||
m_widget = gtk_frame_new(m_label.empty() ? (char *)NULL : (const char*) wxGTK_CONV( m_label ) );
|
|
||||||
|
|
||||||
m_parent->DoAddChild( this );
|
m_parent->DoAddChild( this );
|
||||||
|
|
||||||
@@ -81,10 +80,9 @@ bool wxStaticBox::Create( wxWindow *parent,
|
|||||||
|
|
||||||
void wxStaticBox::SetLabel( const wxString& label )
|
void wxStaticBox::SetLabel( const wxString& label )
|
||||||
{
|
{
|
||||||
wxControl::SetLabel( label );
|
wxCHECK_RET( m_widget != NULL, wxT("invalid staticbox") );
|
||||||
|
|
||||||
gtk_frame_set_label( GTK_FRAME( m_widget ),
|
GTKSetLabelForFrame(GTK_FRAME(m_widget), label);
|
||||||
m_label.empty() ? (char *)NULL : (const char*) wxGTK_CONV( m_label ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle *style)
|
void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle *style)
|
||||||
|
@@ -130,28 +130,6 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
wxString label2( label );
|
|
||||||
for (size_t i = 0; i < label2.Len(); i++)
|
|
||||||
{
|
|
||||||
if (label2.GetChar(i) == wxT('&'))
|
|
||||||
label2.SetChar(i,wxT('_'));
|
|
||||||
}
|
|
||||||
|
|
||||||
GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() );
|
|
||||||
gtk_widget_show( accel_label );
|
|
||||||
|
|
||||||
m_widget = gtk_button_new();
|
|
||||||
gtk_container_add( GTK_CONTAINER(m_widget), accel_label );
|
|
||||||
|
|
||||||
gtk_accel_label_set_accel_widget( GTK_ACCEL_LABEL(accel_label), m_widget );
|
|
||||||
|
|
||||||
guint accel_key = gtk_label_parse_uline (GTK_LABEL(accel_label), label2.mb_str() );
|
|
||||||
gtk_accel_label_refetch( GTK_ACCEL_LABEL(accel_label) );
|
|
||||||
|
|
||||||
wxControl::SetLabel( label );
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __WXGTK20__
|
#ifdef __WXGTK20__
|
||||||
m_widget = gtk_button_new_with_mnemonic("");
|
m_widget = gtk_button_new_with_mnemonic("");
|
||||||
#else
|
#else
|
||||||
@@ -266,6 +244,8 @@ void wxButton::SetLabel( const wxString &lbl )
|
|||||||
|
|
||||||
wxControl::SetLabel(label);
|
wxControl::SetLabel(label);
|
||||||
|
|
||||||
|
const wxString labelGTK = GTKConvertMnemonics(label);
|
||||||
|
|
||||||
#ifdef __WXGTK20__
|
#ifdef __WXGTK20__
|
||||||
if (wxIsStockID(m_windowId) && wxIsStockLabel(m_windowId, label))
|
if (wxIsStockID(m_windowId) && wxIsStockLabel(m_windowId, label))
|
||||||
{
|
{
|
||||||
@@ -278,15 +258,13 @@ void wxButton::SetLabel( const wxString &lbl )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString label2 = PrepareLabelMnemonics(label);
|
gtk_button_set_label(GTK_BUTTON(m_widget), wxGTK_CONV(labelGTK));
|
||||||
gtk_button_set_label(GTK_BUTTON(m_widget), wxGTK_CONV(label2));
|
|
||||||
gtk_button_set_use_stock(GTK_BUTTON(m_widget), FALSE);
|
gtk_button_set_use_stock(GTK_BUTTON(m_widget), FALSE);
|
||||||
|
|
||||||
ApplyWidgetStyle( false );
|
ApplyWidgetStyle( false );
|
||||||
|
#else // GTK+ 1
|
||||||
#else
|
gtk_label_set(GTK_LABEL(BUTTON_CHILD(m_widget)), wxGTK_CONV(labelGTK));
|
||||||
gtk_label_set(GTK_LABEL(BUTTON_CHILD(m_widget)), wxGTK_CONV(GetLabel()));
|
#endif // GTK+ 2/1
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxButton::Enable( bool enable )
|
bool wxButton::Enable( bool enable )
|
||||||
|
@@ -229,14 +229,7 @@ void wxCheckBox::SetLabel( const wxString& label )
|
|||||||
{
|
{
|
||||||
wxCHECK_RET( m_widgetLabel != NULL, wxT("invalid checkbox") );
|
wxCHECK_RET( m_widgetLabel != NULL, wxT("invalid checkbox") );
|
||||||
|
|
||||||
wxControl::SetLabel( label );
|
GTKSetLabelForLabel(GTK_LABEL(m_widgetLabel), 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 )
|
bool wxCheckBox::Enable( bool enable )
|
||||||
|
@@ -17,8 +17,7 @@
|
|||||||
#include "wx/control.h"
|
#include "wx/control.h"
|
||||||
#include "wx/fontutil.h"
|
#include "wx/fontutil.h"
|
||||||
#include "wx/settings.h"
|
#include "wx/settings.h"
|
||||||
|
#include "wx/gtk/private.h"
|
||||||
#include <gtk/gtk.h>
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxControl
|
// wxControl
|
||||||
@@ -48,29 +47,6 @@ bool wxControl::Create( wxWindow *parent,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxControl::SetLabel( const wxString &label )
|
|
||||||
{
|
|
||||||
m_label.Empty();
|
|
||||||
for ( const wxChar *pc = label; *pc != wxT('\0'); pc++ )
|
|
||||||
{
|
|
||||||
if ( *pc == wxT('&') )
|
|
||||||
{
|
|
||||||
pc++; // skip it
|
|
||||||
#if 0 // it would be unused anyhow for now - kbd interface not done yet
|
|
||||||
if ( *pc != wxT('&') ) m_chAccel = *pc;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
m_label << *pc;
|
|
||||||
}
|
|
||||||
InvalidateBestSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString wxControl::GetLabel() const
|
|
||||||
{
|
|
||||||
return m_label;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
wxSize wxControl::DoGetBestSize() const
|
wxSize wxControl::DoGetBestSize() const
|
||||||
{
|
{
|
||||||
// Do not return any arbitrary default value...
|
// Do not return any arbitrary default value...
|
||||||
@@ -103,51 +79,138 @@ void wxControl::PostCreation(const wxSize& size)
|
|||||||
SetInitialBestSize(size);
|
SetInitialBestSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxControl dealing with labels
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void wxControl::SetLabel( const wxString &label )
|
||||||
|
{
|
||||||
|
// keep the original string internally to be able to return it later (for
|
||||||
|
// consistency with the other ports)
|
||||||
|
m_label = label;
|
||||||
|
|
||||||
|
InvalidateBestSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString wxControl::GetLabel() const
|
||||||
|
{
|
||||||
|
return m_label;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxControl::GTKSetLabelForLabel(GtkLabel *w, const wxString& label)
|
||||||
|
{
|
||||||
|
// don't call the virtual function which might call this one back again
|
||||||
|
wxControl::SetLabel(label);
|
||||||
|
|
||||||
|
const wxString labelGTK = GTKConvertMnemonics(label);
|
||||||
|
|
||||||
#ifdef __WXGTK20__
|
#ifdef __WXGTK20__
|
||||||
wxString wxControl::PrepareLabelMnemonics( const wxString &label ) const
|
gtk_label_set_text_with_mnemonic(w, wxGTK_CONV(labelGTK));
|
||||||
{
|
#else
|
||||||
//Format mnemonics properly for GTK2. This can be called from GTK1.x, but
|
gtk_label_set(w, wxGTK_CONV(labelGTK));
|
||||||
//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
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxControl::GTKSetLabelForFrame(GtkFrame *w, const wxString& label)
|
||||||
|
{
|
||||||
|
wxControl::SetLabel(label);
|
||||||
|
|
||||||
|
// frames don't support mnemonics even under GTK+ 2
|
||||||
|
const wxString labelGTK = GTKRemoveMnemonics(label);
|
||||||
|
|
||||||
|
gtk_frame_set_label(w, labelGTK.empty() ? (char *)NULL
|
||||||
|
: wxGTK_CONV(labelGTK));
|
||||||
|
}
|
||||||
|
|
||||||
|
// worker function implementing both GTKConvert/RemoveMnemonics()
|
||||||
|
//
|
||||||
|
// notice that under GTK+ 1 we only really need to support MNEMONICS_REMOVE as
|
||||||
|
// it doesn't support mnemonics anyhow but this would make the code so ugly
|
||||||
|
// that we do the same thing for GKT+ 1 and 2
|
||||||
|
enum MnemonicsFlag
|
||||||
|
{
|
||||||
|
MNEMONICS_REMOVE,
|
||||||
|
MNEMONICS_CONVERT
|
||||||
|
};
|
||||||
|
|
||||||
|
static wxString GTKProcessMnemonics(const wxString& label, MnemonicsFlag flag)
|
||||||
|
{
|
||||||
|
const size_t len = label.length();
|
||||||
|
wxString labelGTK;
|
||||||
|
labelGTK.reserve(len);
|
||||||
|
for ( size_t i = 0; i < len; i++ )
|
||||||
|
{
|
||||||
|
wxChar ch = label[i];
|
||||||
|
|
||||||
|
switch ( ch )
|
||||||
|
{
|
||||||
|
case wxT('&'):
|
||||||
|
if ( i == len - 1 )
|
||||||
|
{
|
||||||
|
// "&" at the end of string is an error
|
||||||
|
wxLogDebug(wxT("Invalid label \"%s\"."), label.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ch = label[++i]; // skip '&' itself
|
||||||
|
switch ( ch )
|
||||||
|
{
|
||||||
|
case wxT('&'):
|
||||||
|
// special case: "&&" is not a mnemonic at all but just
|
||||||
|
// an escaped "&"
|
||||||
|
labelGTK += wxT('&');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxT('_'):
|
||||||
|
if ( flag == MNEMONICS_CONVERT )
|
||||||
|
{
|
||||||
|
// '_' can't be a GTK mnemonic apparently so
|
||||||
|
// replace it with something similar
|
||||||
|
labelGTK += wxT("_-");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//else: fall through
|
||||||
|
|
||||||
|
default:
|
||||||
|
if ( flag == MNEMONICS_CONVERT )
|
||||||
|
labelGTK += wxT('_');
|
||||||
|
labelGTK += ch;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxT('_'):
|
||||||
|
if ( flag == MNEMONICS_CONVERT )
|
||||||
|
{
|
||||||
|
// escape any existing underlines in the string so that
|
||||||
|
// they don't become mnemonics accidentally
|
||||||
|
labelGTK += wxT("__");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//else: fall through
|
||||||
|
|
||||||
|
default:
|
||||||
|
labelGTK += ch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return labelGTK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
wxString wxControl::GTKRemoveMnemonics(const wxString& label)
|
||||||
|
{
|
||||||
|
return GTKProcessMnemonics(label, MNEMONICS_REMOVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
wxString wxControl::GTKConvertMnemonics(const wxString& label)
|
||||||
|
{
|
||||||
|
return GTKProcessMnemonics(label, MNEMONICS_CONVERT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxControl styles (a.k.a. attributes)
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxVisualAttributes wxControl::GetDefaultAttributes() const
|
wxVisualAttributes wxControl::GetDefaultAttributes() const
|
||||||
{
|
{
|
||||||
|
@@ -198,7 +198,8 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_widget = gtk_frame_new( wxGTK_CONV( title ) );
|
m_widget = gtk_frame_new(NULL);
|
||||||
|
SetLabel(title);
|
||||||
|
|
||||||
// majorDim may be 0 if all trailing parameters were omitted, so don't
|
// majorDim may be 0 if all trailing parameters were omitted, so don't
|
||||||
// assert here but just use the correct value for it
|
// assert here but just use the correct value for it
|
||||||
@@ -273,8 +274,6 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
|
|||||||
|
|
||||||
m_parent->DoAddChild( this );
|
m_parent->DoAddChild( this );
|
||||||
|
|
||||||
SetLabel( title );
|
|
||||||
|
|
||||||
PostCreation(size);
|
PostCreation(size);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -399,9 +398,7 @@ void wxRadioBox::SetLabel( const wxString& label )
|
|||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
|
wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
|
||||||
|
|
||||||
wxControl::SetLabel( label );
|
GTKSetLabelForFrame(GTK_FRAME(m_widget), label);
|
||||||
|
|
||||||
gtk_frame_set_label( GTK_FRAME(m_widget), wxGTK_CONV( wxControl::GetLabel() ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxRadioBox::SetString( int item, const wxString& label )
|
void wxRadioBox::SetString( int item, const wxString& label )
|
||||||
|
@@ -125,14 +125,7 @@ void wxRadioButton::SetLabel( const wxString& label )
|
|||||||
{
|
{
|
||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid radiobutton") );
|
wxCHECK_RET( m_widget != NULL, wxT("invalid radiobutton") );
|
||||||
|
|
||||||
wxControl::SetLabel( label );
|
GTKSetLabelForLabel(GTK_LABEL(BUTTON_CHILD(m_widget)), 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 )
|
void wxRadioButton::SetValue( bool val )
|
||||||
|
@@ -56,9 +56,8 @@ bool wxStaticBox::Create( wxWindow *parent,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxControl::SetLabel(label);
|
m_widget = gtk_frame_new(NULL);
|
||||||
|
SetLabel(label);
|
||||||
m_widget = gtk_frame_new(m_label.empty() ? (char *)NULL : (const char*) wxGTK_CONV( m_label ) );
|
|
||||||
|
|
||||||
m_parent->DoAddChild( this );
|
m_parent->DoAddChild( this );
|
||||||
|
|
||||||
@@ -81,10 +80,9 @@ bool wxStaticBox::Create( wxWindow *parent,
|
|||||||
|
|
||||||
void wxStaticBox::SetLabel( const wxString& label )
|
void wxStaticBox::SetLabel( const wxString& label )
|
||||||
{
|
{
|
||||||
wxControl::SetLabel( label );
|
wxCHECK_RET( m_widget != NULL, wxT("invalid staticbox") );
|
||||||
|
|
||||||
gtk_frame_set_label( GTK_FRAME( m_widget ),
|
GTKSetLabelForFrame(GTK_FRAME(m_widget), label);
|
||||||
m_label.empty() ? (char *)NULL : (const char*) wxGTK_CONV( m_label ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle *style)
|
void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle *style)
|
||||||
|
Reference in New Issue
Block a user