Fix setting wxBU_EXACTFIT style for wxButton under wxGTK2
The way wxBU_EXACTFIT is implemented in commit c1bb80987f
("Improve implementation of wxBU_EXACTFIT style for wxButton under wxGTK2",
2020-04-12) is too intrusive and disrupts button's appearance in some
themes. It should work better with themes if we reduce inner border in
a more GTK-compliant way by applying a dedicated GTK style to the button.
Closes #19081.
This commit is contained in:
@@ -67,6 +67,12 @@ private:
|
|||||||
// Return the GtkLabel used by this button.
|
// Return the GtkLabel used by this button.
|
||||||
GtkLabel *GTKGetLabel() const;
|
GtkLabel *GTKGetLabel() const;
|
||||||
|
|
||||||
|
#ifndef __WXGTK3__
|
||||||
|
// To mark if special GTK style for buttons with wxBU_EXACTFIT flag
|
||||||
|
// was already defined.
|
||||||
|
static bool m_exactFitStyleDefined;
|
||||||
|
#endif // !__WXGTK3__
|
||||||
|
|
||||||
wxDECLARE_DYNAMIC_CLASS(wxButton);
|
wxDECLARE_DYNAMIC_CLASS(wxButton);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -70,6 +70,10 @@ wxgtk_button_style_set_callback(GtkWidget* widget, GtkStyle*, wxButton* win)
|
|||||||
// wxButton
|
// wxButton
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef __WXGTK3__
|
||||||
|
bool wxButton::m_exactFitStyleDefined = false;
|
||||||
|
#endif // !__WXGTK3__
|
||||||
|
|
||||||
bool wxButton::Create(wxWindow *parent,
|
bool wxButton::Create(wxWindow *parent,
|
||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
const wxString &label,
|
const wxString &label,
|
||||||
@@ -141,7 +145,20 @@ bool wxButton::Create(wxWindow *parent,
|
|||||||
#ifdef __WXGTK3__
|
#ifdef __WXGTK3__
|
||||||
GTKApplyCssStyle("* { padding:0 }");
|
GTKApplyCssStyle("* { padding:0 }");
|
||||||
#else
|
#else
|
||||||
GTKApplyWidgetStyle(true); // To enforce call to DoApplyWidgetStyle()
|
// Define a special button style without inner border
|
||||||
|
// if it's not yet done.
|
||||||
|
if ( !m_exactFitStyleDefined )
|
||||||
|
{
|
||||||
|
gtk_rc_parse_string(
|
||||||
|
"style \"wxButton_wxBU_EXACTFIT_style\"\n"
|
||||||
|
"{ GtkButton::inner-border = { 0, 0, 0, 0 } }\n"
|
||||||
|
"widget \"*wxButton_wxBU_EXACTFIT*\" style \"wxButton_wxBU_EXACTFIT_style\"\n"
|
||||||
|
);
|
||||||
|
m_exactFitStyleDefined = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign the button to the GTK style without inner border.
|
||||||
|
gtk_widget_set_name(m_widget, "wxButton_wxBU_EXACTFIT");
|
||||||
#endif // __WXGTK3__ / !__WXGTK3__
|
#endif // __WXGTK3__ / !__WXGTK3__
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,11 +329,6 @@ GtkLabel *wxButton::GTKGetLabel() const
|
|||||||
|
|
||||||
void wxButton::DoApplyWidgetStyle(GtkRcStyle *style)
|
void wxButton::DoApplyWidgetStyle(GtkRcStyle *style)
|
||||||
{
|
{
|
||||||
if ( style && HasFlag(wxBU_EXACTFIT) )
|
|
||||||
{
|
|
||||||
style->xthickness = 0;
|
|
||||||
style->ythickness = 0;
|
|
||||||
}
|
|
||||||
GTKApplyStyle(m_widget, style);
|
GTKApplyStyle(m_widget, style);
|
||||||
GtkWidget* child = gtk_bin_get_child(GTK_BIN(m_widget));
|
GtkWidget* child = gtk_bin_get_child(GTK_BIN(m_widget));
|
||||||
GTKApplyStyle(child, style);
|
GTKApplyStyle(child, style);
|
||||||
|
Reference in New Issue
Block a user