Fix transitory visual glitch with wxBORDER_NONE on GTK3

Changing the CSS after adding child to already-showing parent
can cause a fleeting glimpse of the original style.
See #24105
This commit is contained in:
Paul Cornett 2023-12-10 09:10:42 -08:00
parent 375fd2c630
commit c3d1618cc8
6 changed files with 27 additions and 19 deletions

View file

@ -59,6 +59,8 @@ protected:
private:
typedef wxCheckBoxBase base_type;
virtual void GTKRemoveBorder() override;
GtkWidget *m_widgetCheckbox;
GtkWidget *m_widgetLabel;

View file

@ -87,6 +87,8 @@ protected:
wxSize GTKGetEntryMargins(GtkEntry* entry) const;
private:
virtual void GTKRemoveBorder() override;
wxDECLARE_DYNAMIC_CLASS(wxControl);
};

View file

@ -466,6 +466,7 @@ protected:
private:
void Init();
virtual void GTKRemoveBorder();
// return true if this window must have a non-null parent, false if it can
// be created without parent (normally only top level windows but in wxGTK

View file

@ -141,25 +141,17 @@ bool wxCheckBox::Create(wxWindow *parent,
m_parent->DoAddChild( this );
#ifdef __WXGTK3__
// CSS added if the window has wxNO_BORDER inside base class PostCreation()
// makes checkbox look broken in the default GTK 3 theme, so avoid doing
// this by temporarily turning this flag off.
if ( style & wxNO_BORDER )
ToggleWindowStyle(wxNO_BORDER);
#endif
PostCreation(size);
#ifdef __WXGTK3__
// Turn it back on if necessary.
if ( style & wxNO_BORDER )
ToggleWindowStyle(wxNO_BORDER);
#endif
return true;
}
void wxCheckBox::GTKRemoveBorder()
{
// CSS added if the window has wxBORDER_NONE makes
// checkbox look broken in the default GTK 3 theme
}
void wxCheckBox::GTKDisableEvents()
{
g_signal_handlers_block_by_func(m_widgetCheckbox,

View file

@ -92,11 +92,6 @@ void wxControl::PostCreation(const wxSize& size)
{
wxWindow::PostCreation();
#ifdef __WXGTK3__
if (HasFlag(wxNO_BORDER))
GTKApplyCssStyle("*{ border:none; border-radius:0; padding:0 }");
#endif
#ifndef __WXGTK3__
// NB: GetBestSize needs to know the style, otherwise it will assume
// default font and if the user uses a different font, determined
@ -109,6 +104,13 @@ void wxControl::PostCreation(const wxSize& size)
SetInitialSize(size);
}
void wxControl::GTKRemoveBorder()
{
#ifdef __WXGTK3__
GTKApplyCssStyle("*{ border:none; border-radius:0; padding:0 }");
#endif
}
// ----------------------------------------------------------------------------
// Work around a GTK+ bug whereby button is insensitive after being
// enabled

View file

@ -4913,11 +4913,20 @@ bool wxWindowGTK::Reparent( wxWindowBase *newParentBase )
return true;
}
void wxWindowGTK::GTKRemoveBorder()
{
}
void wxWindowGTK::DoAddChild(wxWindowGTK *child)
{
wxASSERT_MSG( (m_widget != nullptr), wxT("invalid window") );
wxASSERT_MSG( (child != nullptr), wxT("invalid child window") );
// If parent is already showing, changing CSS after adding child
// can cause transitory visual glitches, so change it here
if (HasFlag(wxBORDER_NONE))
GTKRemoveBorder();
/* add to list */
AddChild( child );