From a21175918ecedbae7d04a58acca5e90a6b59633d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 17 Jun 2009 22:13:46 +0000 Subject: [PATCH] added wxBU_NOTEXT style to allow creating bitmap buttons with stock id not showing the label, as it was possible before git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61104 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/button.h | 20 ++++++++++++++++++++ include/wx/gtk/bmpbuttn.h | 3 ++- interface/wx/button.h | 19 ++++++++++++------- src/gtk/button.cpp | 11 ++++++++--- src/msw/bmpbuttn.cpp | 4 +++- src/msw/button.cpp | 12 +++++------- 6 files changed, 50 insertions(+), 19 deletions(-) diff --git a/include/wx/button.h b/include/wx/button.h index 53b164bbba..dfcf6610da 100644 --- a/include/wx/button.h +++ b/include/wx/button.h @@ -43,6 +43,13 @@ // small as possible #define wxBU_EXACTFIT 0x0001 +// this flag can be used to disable using the text label in the button: it is +// mostly useful when creating buttons showing bitmap and having stock id as +// without it both the standard label corresponding to the stock id and the +// bitmap would be shown +#define wxBU_NOTEXT 0x0002 + + #include "wx/bitmap.h" #include "wx/control.h" @@ -146,6 +153,19 @@ public: State_Max }; + // return true if this button shouldn't show the text label, either because + // it doesn't have it or because it was explicitly disabled with wxBU_NOTEXT + bool DontShowLabel() const + { + return HasFlag(wxBU_NOTEXT) || GetLabel().empty(); + } + + // return true if we do show the label + bool ShowsLabel() const + { + return !DontShowLabel(); + } + protected: // choose the default border for this window virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } diff --git a/include/wx/gtk/bmpbuttn.h b/include/wx/gtk/bmpbuttn.h index 47ee62fc2b..a0a17b3ac0 100644 --- a/include/wx/gtk/bmpbuttn.h +++ b/include/wx/gtk/bmpbuttn.h @@ -41,7 +41,8 @@ public: const wxString& name = wxButtonNameStr) { if ( !wxBitmapButtonBase::Create(parent, id, "", - pos, size, style, + pos, size, + style | wxBU_NOTEXT, validator, name) ) return false; diff --git a/interface/wx/button.h b/interface/wx/button.h index 0ad5d3482f..a36c8cacef 100644 --- a/interface/wx/button.h +++ b/interface/wx/button.h @@ -17,18 +17,23 @@ @beginStyleTable @style{wxBU_LEFT} - Left-justifies the label. Windows and GTK+ only. + Left-justifies the label. Windows and GTK+ only. @style{wxBU_TOP} - Aligns the label to the top of the button. Windows and GTK+ only. + Aligns the label to the top of the button. Windows and GTK+ only. @style{wxBU_RIGHT} - Right-justifies the bitmap label. Windows and GTK+ only. + Right-justifies the bitmap label. Windows and GTK+ only. @style{wxBU_BOTTOM} - Aligns the label to the bottom of the button. Windows and GTK+ only. + Aligns the label to the bottom of the button. Windows and GTK+ only. @style{wxBU_EXACTFIT} - Creates the button as small as possible instead of making it of the - standard size (which is the default behaviour ). + Creates the button as small as possible instead of making it of the + standard size (which is the default behaviour ). + @style{wxBU_NOTEXT} + Disables the display of the text label in the button even if it has one + or its id is one of the standard stock ids with an associated label: + without using this style a button which is only supposed to show a + bitmap but uses a standard id would display a label too. @style{wxBORDER_NONE} - Creates a flat button. Windows and GTK+ only. + Creates a flat button. Windows and GTK+ only. @endStyleTable By default, i.e. if none of the alignment styles are specified, the label diff --git a/src/gtk/button.cpp b/src/gtk/button.cpp index 198a46a72d..0a6a838f90 100644 --- a/src/gtk/button.cpp +++ b/src/gtk/button.cpp @@ -126,7 +126,8 @@ bool wxButton::Create(wxWindow *parent, // create either a standard button with text label (which may still contain // an image under GTK+ 2.6+) or a bitmap-only button if we don't have any // label - const bool useLabel = !label.empty() || wxIsStockID(id); + const bool + useLabel = !(style & wxBU_NOTEXT) && (!label.empty() || wxIsStockID(id)); if ( useLabel ) { m_widget = gtk_button_new_with_mnemonic(""); @@ -237,6 +238,10 @@ void wxButton::SetLabel( const wxString &lbl ) wxControl::SetLabel(label); + // don't use label if it was explicitly disabled + if ( HasFlag(wxBU_NOTEXT) ) + return; + if (wxIsStockID(m_windowId) && wxIsStockLabel(m_windowId, label)) { const char *stock = wxGetStockGtkID(m_windowId); @@ -410,7 +415,7 @@ void wxButton::GTKDoShowBitmap(const wxBitmap& bitmap) wxASSERT_MSG( bitmap.IsOk(), "invalid bitmap" ); GtkWidget *image; - if ( GetLabel().empty() ) + if ( DontShowLabel() ) { image = GTK_BIN(m_widget)->child; } @@ -450,7 +455,7 @@ void wxButton::DoSetBitmap(const wxBitmap& bitmap, State which) switch ( which ) { case State_Normal: - if ( GetLabel().empty() ) + if ( DontShowLabel() ) { // we only have the bitmap in this button, never remove it but // do invalidate the best size when the bitmap (and presumably diff --git a/src/msw/bmpbuttn.cpp b/src/msw/bmpbuttn.cpp index 1438b7cffa..2e2072d0a2 100644 --- a/src/msw/bmpbuttn.cpp +++ b/src/msw/bmpbuttn.cpp @@ -131,7 +131,9 @@ bool wxBitmapButton::Create(wxWindow *parent, const wxString& name) { if ( !wxBitmapButtonBase::Create(parent, id, "", - pos, size, style, validator, name) ) + pos, size, + style | wxBU_NOTEXT, + validator, name) ) return false; SetBitmapLabel(bitmap); diff --git a/src/msw/button.cpp b/src/msw/button.cpp index b789a6ccc2..70edb407a2 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -145,7 +145,7 @@ public: // we use margins when we have both bitmap and text, but when we have // only the bitmap it should take up the entire button area - if ( !btn->GetLabel().empty() ) + if ( btn->ShowsLabel() ) { m_margin.x = btn->GetCharWidth(); m_margin.y = btn->GetCharHeight() / 2; @@ -575,7 +575,7 @@ wxSize wxButton::DoGetBestSize() const wxSize size; // account for the text part - if ( !GetLabel().empty() ) + if ( ShowsLabel() ) { size = wxMSWButton::ComputeBestSize(const_cast(this)); } @@ -946,7 +946,7 @@ void wxButton::DoSetBitmap(const wxBitmap& bitmap, State which) // (even if we use BUTTON_IMAGELIST_ALIGN_CENTER alignment and // BS_BITMAP style), at least under Windows 2003 so use owner drawn // strategy for bitmap-only buttons - if ( !GetLabel().empty() && wxUxThemeEngine::GetIfActive() ) + if ( ShowsLabel() && wxUxThemeEngine::GetIfActive() ) { m_imageData = new wxXPButtonImageData(this, bitmap); } @@ -1262,8 +1262,6 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis) RECT rectBtn; CopyRect(&rectBtn, &lpDIS->rcItem); - const wxString label = GetLabel(); - // draw the button background #if wxUSE_UXTHEME if ( wxUxThemeEngine::GetIfActive() ) @@ -1364,7 +1362,7 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis) // finally draw the label - if ( !label.empty() ) + if ( ShowsLabel() ) { COLORREF colFg = state & ODS_DISABLED ? ::GetSysColor(COLOR_GRAYTEXT) @@ -1373,7 +1371,7 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis) // notice that DT_HIDEPREFIX doesn't work on old (pre-Windows 2000) // systems but by happy coincidence ODS_NOACCEL is not used under them // neither so DT_HIDEPREFIX should never be used there - DrawButtonText(hdc, &rectBtn, label, colFg, + DrawButtonText(hdc, &rectBtn, GetLabel(), colFg, state & ODS_NOACCEL ? DT_HIDEPREFIX : 0); } -- 2.45.2