From 8e4c2912462461f9a2133ac39475457d668d1686 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 28 Jun 2009 16:14:37 +0000 Subject: [PATCH] always use wxBU_NOTEXT and wxBU_EXACTFIT for wxBitmapButton under all platforms (which required some refactoring) (hopefully really closes #10927) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61232 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/bmpbuttn.h | 23 +++++++++++++++++++++++ src/gtk/bmpbuttn.cpp | 12 +++++++++--- src/msw/bmpbuttn.cpp | 4 +--- src/osx/bmpbuttn_osx.cpp | 4 ++-- src/osx/button_osx.cpp | 12 ++++++++++++ 5 files changed, 47 insertions(+), 8 deletions(-) diff --git a/include/wx/bmpbuttn.h b/include/wx/bmpbuttn.h index 62262cad41..a355111bc9 100644 --- a/include/wx/bmpbuttn.h +++ b/include/wx/bmpbuttn.h @@ -41,6 +41,29 @@ public: #endif // wxHAS_BUTTON_BITMAP } + bool Create(wxWindow *parent, + wxWindowID winid, + const wxBitmap& bitmap, + const wxPoint& pos, + const wxSize& size, + long style, + const wxValidator& validator, + const wxString& name) + { + // We use wxBU_NOTEXT to let the base class Create() know that we are + // not going to show the label: this is a hack needed for wxGTK where + // we can show both label and bitmap only with GTK 2.6+ but we always + // can show just one of them and this style allows us to choose which + // one we need. + // + // And we also use wxBU_EXACTFIT to avoid being resized up to the + // standard button size as this doesn't make sense for bitmap buttons + // which are not standard anyhow and should fit their bitmap size. + return wxButton::Create(parent, id, pos, size, + style | wxBU_NOTEXT | wxBU_EXACTFIT, + validator, name); + } + // set/get the margins around the button virtual void SetMargins(int x, int y) { diff --git a/src/gtk/bmpbuttn.cpp b/src/gtk/bmpbuttn.cpp index a3df929f8d..a99810f993 100644 --- a/src/gtk/bmpbuttn.cpp +++ b/src/gtk/bmpbuttn.cpp @@ -25,9 +25,15 @@ bool wxBitmapButton::Create(wxWindow *parent, const wxValidator& validator, const wxString& name) { - if ( !wxBitmapButtonBase::Create(parent, id, "", - pos, size, - style | wxBU_NOTEXT, + // we use wxBU_NOTEXT to let the base class Create() know that we are not + // going to show the label -- this is a hack, but like this it can support + // bitmaps with all GTK+ versions, not just 2.6+ which support both labels + // and bitmaps + // + // and we also use wxBU_EXACTFIT to avoid being resized up to the standard + // button size as this doesn't make sense for bitmap buttons which are not + // standard anyhow + if ( !wxBitmapButtonBase::Create(parent, id, pos, size, style, validator, name) ) return false; diff --git a/src/msw/bmpbuttn.cpp b/src/msw/bmpbuttn.cpp index 2627bf51cc..a77672cbfb 100644 --- a/src/msw/bmpbuttn.cpp +++ b/src/msw/bmpbuttn.cpp @@ -130,9 +130,7 @@ bool wxBitmapButton::Create(wxWindow *parent, const wxValidator& wxVALIDATOR_PARAM(validator), const wxString& name) { - if ( !wxBitmapButtonBase::Create(parent, id, "", - pos, size, - style | wxBU_NOTEXT, + if ( !wxBitmapButtonBase::Create(parent, id, pos, size, style, validator, name) ) return false; diff --git a/src/osx/bmpbuttn_osx.cpp b/src/osx/bmpbuttn_osx.cpp index c79f4fd47c..d22411f27e 100644 --- a/src/osx/bmpbuttn_osx.cpp +++ b/src/osx/bmpbuttn_osx.cpp @@ -37,8 +37,8 @@ bool wxBitmapButton::Create( wxWindow *parent, { m_macIsUserPane = false; - if ( !wxControl::Create( parent, id, pos, size, style | wxBU_NOTEXT, - validator, name ) ) + if ( !wxBitmapButtonBase::Create(parent, id, pos, size, style, + validator, name) ) return false; if ( style & wxBU_AUTODRAW ) diff --git a/src/osx/button_osx.cpp b/src/osx/button_osx.cpp index 12b630c412..29afcd3882 100644 --- a/src/osx/button_osx.cpp +++ b/src/osx/button_osx.cpp @@ -34,6 +34,18 @@ bool wxButton::Create(wxWindow *parent, const wxValidator& validator, const wxString& name) { + // FIXME: this hack is needed because we're called from + // wxBitmapButton::Create() with this style and we currently use a + // different wxWidgetImpl method (CreateBitmapButton() rather than + // CreateButton()) for creating bitmap buttons, but we really ought + // to unify the creation of buttons of all kinds and then remove + // this check + if ( style & wxBU_NOTEXT ) + { + return wxControl::Create(parent, id, lbl, pos, size, style, + validator, name); + } + wxString label(lbl); if (label.empty() && wxIsStockID(id) && !(id == wxID_HELP)) label = wxGetStockLabel(id); -- 2.45.2