Implement wxBitmapButon without inner border as wxPG editor button under wxGTK

Editor buttons with reduced padding will let us to display slightly bigger
bitmaps.
This commit is contained in:
Artur Wieczorek
2020-04-12 17:23:09 +02:00
parent c1bb80987f
commit f4ded62bc4

View File

@@ -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