diff --git a/include/wx/gtk/checkbox.h b/include/wx/gtk/checkbox.h index c98615db7b..fdfa4a7b1e 100644 --- a/include/wx/gtk/checkbox.h +++ b/include/wx/gtk/checkbox.h @@ -59,6 +59,8 @@ protected: private: typedef wxCheckBoxBase base_type; + virtual void GTKRemoveBorder() override; + GtkWidget *m_widgetCheckbox; GtkWidget *m_widgetLabel; diff --git a/include/wx/gtk/control.h b/include/wx/gtk/control.h index 684c3a5f41..d6a7721955 100644 --- a/include/wx/gtk/control.h +++ b/include/wx/gtk/control.h @@ -87,6 +87,8 @@ protected: wxSize GTKGetEntryMargins(GtkEntry* entry) const; private: + virtual void GTKRemoveBorder() override; + wxDECLARE_DYNAMIC_CLASS(wxControl); }; diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index f0c94d8d2a..0b26076a09 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -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 diff --git a/src/gtk/checkbox.cpp b/src/gtk/checkbox.cpp index e11a1144aa..06722a437f 100644 --- a/src/gtk/checkbox.cpp +++ b/src/gtk/checkbox.cpp @@ -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, diff --git a/src/gtk/control.cpp b/src/gtk/control.cpp index 66be1fde65..5787a26774 100644 --- a/src/gtk/control.cpp +++ b/src/gtk/control.cpp @@ -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 diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index f6c7899c64..05f62a87da 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -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 );