Move GTK3 wxNO_BORDER handling to wxControl

So wxNO_BORDER works with other controls, such as wxBitmapButton.
Also use GTK prefix on ApplyCssStyle(), and add an overload that
creates the GtkCssProvider.
This commit is contained in:
Paul Cornett
2017-11-15 10:51:38 -08:00
parent ef0309c141
commit 21620da3e5
5 changed files with 18 additions and 13 deletions

View File

@@ -412,7 +412,8 @@ protected:
#ifdef __WXGTK3__ #ifdef __WXGTK3__
// Use the given CSS string for styling the widget. The provider must be // Use the given CSS string for styling the widget. The provider must be
// allocated, and remains owned, by the caller. // allocated, and remains owned, by the caller.
void ApplyCssStyle(GtkCssProvider* provider, const char* style); void GTKApplyCssStyle(GtkCssProvider* provider, const char* style);
void GTKApplyCssStyle(const char* style);
#else // GTK+ < 3 #else // GTK+ < 3
// Called by ApplyWidgetStyle (which is called by SetFont() and // Called by ApplyWidgetStyle (which is called by SetFont() and
// SetXXXColour etc to apply style changed to native widgets) to create // SetXXXColour etc to apply style changed to native widgets) to create

View File

@@ -457,7 +457,8 @@ void ButtonWidgetsPage::CreateButton()
if ( m_chkUseBitmapClass->GetValue() ) if ( m_chkUseBitmapClass->GetValue() )
{ {
bbtn = new wxBitmapButton(this, ButtonPage_Button, bbtn = new wxBitmapButton(this, ButtonPage_Button,
CreateBitmap(wxT("normal"))); CreateBitmap(wxT("normal")),
wxDefaultPosition, wxDefaultSize, flags);
} }
else else
{ {

View File

@@ -97,6 +97,11 @@ void wxControl::PostCreation(const wxSize& size)
{ {
wxWindow::PostCreation(); wxWindow::PostCreation();
#ifdef __WXGTK3__
if (HasFlag(wxNO_BORDER))
GTKApplyCssStyle("*{ border:none; border-radius:0; padding:0 }");
#endif
#ifndef __WXGTK3__ #ifndef __WXGTK3__
// NB: GetBestSize needs to know the style, otherwise it will assume // NB: GetBestSize needs to know the style, otherwise it will assume
// default font and if the user uses a different font, determined // default font and if the user uses a different font, determined

View File

@@ -32,7 +32,6 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "wx/gtk/private.h" #include "wx/gtk/private.h"
#include "wx/gtk/private/gtk2-compat.h" #include "wx/gtk/private/gtk2-compat.h"
#include "wx/gtk/private/object.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// helpers // helpers
@@ -728,18 +727,10 @@ bool wxTextCtrl::Create( wxWindow *parent,
// new, empty control, see https://trac.wxwidgets.org/ticket/11409 // new, empty control, see https://trac.wxwidgets.org/ticket/11409
gtk_entry_get_text((GtkEntry*)m_text); gtk_entry_get_text((GtkEntry*)m_text);
#ifndef __WXGTK3__
if (style & wxNO_BORDER) if (style & wxNO_BORDER)
{
#ifdef __WXGTK3__
// this is sort of a workaround for when the builtin theme
// won't remove the frame by itself -- see
// https://bugzilla.gnome.org/show_bug.cgi?id=789732#c1
wxGtkObject<GtkCssProvider> provider(gtk_css_provider_new());
ApplyCssStyle(provider, "* { border: none; border-radius: 0; padding: 0 }");
#else
gtk_entry_set_has_frame((GtkEntry*)m_text, FALSE); gtk_entry_set_has_frame((GtkEntry*)m_text, FALSE);
#endif #endif
}
} }
g_object_ref(m_widget); g_object_ref(m_widget);

View File

@@ -4476,7 +4476,7 @@ PangoContext *wxWindowGTK::GTKGetPangoDefaultContext()
} }
#ifdef __WXGTK3__ #ifdef __WXGTK3__
void wxWindowGTK::ApplyCssStyle(GtkCssProvider* provider, const char* style) void wxWindowGTK::GTKApplyCssStyle(GtkCssProvider* provider, const char* style)
{ {
wxCHECK_RET(m_widget, "invalid window"); wxCHECK_RET(m_widget, "invalid window");
@@ -4489,6 +4489,13 @@ void wxWindowGTK::ApplyCssStyle(GtkCssProvider* provider, const char* style)
GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER(provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
} }
void wxWindowGTK::GTKApplyCssStyle(const char* style)
{
GtkCssProvider* provider = gtk_css_provider_new();
GTKApplyCssStyle(provider, style);
g_object_unref(provider);
}
#else // GTK+ < 3 #else // GTK+ < 3
GtkRcStyle* wxWindowGTK::GTKCreateWidgetStyle() GtkRcStyle* wxWindowGTK::GTKCreateWidgetStyle()
{ {