// 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"
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; }
const wxString& name = wxButtonNameStr)
{
if ( !wxBitmapButtonBase::Create(parent, id, "",
- pos, size, style,
+ pos, size,
+ style | wxBU_NOTEXT,
validator, name) )
return false;
@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
// 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("");
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);
wxASSERT_MSG( bitmap.IsOk(), "invalid bitmap" );
GtkWidget *image;
- if ( GetLabel().empty() )
+ if ( DontShowLabel() )
{
image = GTK_BIN(m_widget)->child;
}
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
const wxString& name)
{
if ( !wxBitmapButtonBase::Create(parent, id, "",
- pos, size, style, validator, name) )
+ pos, size,
+ style | wxBU_NOTEXT,
+ validator, name) )
return false;
SetBitmapLabel(bitmap);
// 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;
wxSize size;
// account for the text part
- if ( !GetLabel().empty() )
+ if ( ShowsLabel() )
{
size = wxMSWButton::ComputeBestSize(const_cast<wxButton *>(this));
}
// (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);
}
RECT rectBtn;
CopyRect(&rectBtn, &lpDIS->rcItem);
- const wxString label = GetLabel();
-
// draw the button background
#if wxUSE_UXTHEME
if ( wxUxThemeEngine::GetIfActive() )
// finally draw the label
- if ( !label.empty() )
+ if ( ShowsLabel() )
{
COLORREF colFg = state & ODS_DISABLED
? ::GetSysColor(COLOR_GRAYTEXT)
// 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);
}