From f4ded62bc4c4e7ab40e2f911f11a338192ac0591 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 12 Apr 2020 17:23:09 +0200 Subject: [PATCH] Implement wxBitmapButon without inner border as wxPG editor button under wxGTK Editor buttons with reduced padding will let us to display slightly bigger bitmaps. --- src/propgrid/editors.cpp | 51 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/src/propgrid/editors.cpp b/src/propgrid/editors.cpp index d2b1097a73..fc1d9cc6d7 100644 --- a/src/propgrid/editors.cpp +++ b/src/propgrid/editors.cpp @@ -2134,6 +2134,46 @@ int wxPGMultiButton::GenId( int itemid ) const } #if wxUSE_BMPBUTTON + +#if defined(__WXGTK__) +// Dedicated wxBitmapButton with reduced internal borders +#include "wx/gtk/private.h" + +class wxPGEditorBitmapButton : public wxBitmapButton +{ +public: + wxPGEditorBitmapButton(wxWindow *parent, wxWindowID id, + const wxBitmap& bitmap, const wxPoint& pos, + const wxSize& size, long style = 0) + : wxBitmapButton(parent, id, bitmap, pos, size, style) + { +#if defined(__WXGTK3__) + GTKApplyCssStyle("*{ padding:0 }"); +#else + GTKApplyWidgetStyle(true); // To enforce call to DoApplyWidgetStyle() +#endif + } + + virtual ~wxPGEditorBitmapButton() { } + +protected: + virtual void DoApplyWidgetStyle(GtkRcStyle *style) wxOVERRIDE + { + if ( style ) + { + style->xthickness = 0; + style->ythickness = 0; + } + wxBitmapButton::DoApplyWidgetStyle(style); + } +}; + +#else // !__WXGTK__ + +typedef wxBitmapButton wxPGEditorBitmapButton; + +#endif // __WXGTK__ / !__WXGTK__ + void wxPGMultiButton::Add( const wxBitmap& bitmap, int itemid ) { itemid = GenId(itemid); @@ -2144,9 +2184,9 @@ void wxPGMultiButton::Add( const wxBitmap& bitmap, int itemid ) #if defined(__WXMSW__) 2*4; #elif defined(__WXGTK3__) - 2*4; + 2*2; #elif defined(__WXGTK__) - 2*8; + 2*6; #elif defined(__WXOSX__) 2*3; #else @@ -2167,8 +2207,13 @@ void wxPGMultiButton::Add( const wxBitmap& bitmap, int itemid ) scaledBmp = bitmap; } - wxBitmapButton* button = new wxBitmapButton(this, itemid, scaledBmp, + wxBitmapButton* button = new wxPGEditorBitmapButton(this, itemid, scaledBmp, wxPoint(sz.x, 0), wxSize(wxDefaultCoord, sz.y)); + // If button is narrow make it a square + wxSize szBtn = button->GetSize(); + if ( szBtn.x < szBtn.y ) + button->SetSize(wxSize(szBtn.y, szBtn.y)); + DoAddButton( button, sz ); } #endif