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
This commit is contained in:
@@ -43,6 +43,13 @@
|
|||||||
// small as possible
|
// small as possible
|
||||||
#define wxBU_EXACTFIT 0x0001
|
#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/bitmap.h"
|
||||||
#include "wx/control.h"
|
#include "wx/control.h"
|
||||||
|
|
||||||
@@ -146,6 +153,19 @@ public:
|
|||||||
State_Max
|
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:
|
protected:
|
||||||
// choose the default border for this window
|
// choose the default border for this window
|
||||||
virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
|
virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
|
||||||
|
@@ -41,7 +41,8 @@ public:
|
|||||||
const wxString& name = wxButtonNameStr)
|
const wxString& name = wxButtonNameStr)
|
||||||
{
|
{
|
||||||
if ( !wxBitmapButtonBase::Create(parent, id, "",
|
if ( !wxBitmapButtonBase::Create(parent, id, "",
|
||||||
pos, size, style,
|
pos, size,
|
||||||
|
style | wxBU_NOTEXT,
|
||||||
validator, name) )
|
validator, name) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@@ -27,6 +27,11 @@
|
|||||||
@style{wxBU_EXACTFIT}
|
@style{wxBU_EXACTFIT}
|
||||||
Creates the button as small as possible instead of making it of the
|
Creates the button as small as possible instead of making it of the
|
||||||
standard size (which is the default behaviour ).
|
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}
|
@style{wxBORDER_NONE}
|
||||||
Creates a flat button. Windows and GTK+ only.
|
Creates a flat button. Windows and GTK+ only.
|
||||||
@endStyleTable
|
@endStyleTable
|
||||||
|
@@ -126,7 +126,8 @@ bool wxButton::Create(wxWindow *parent,
|
|||||||
// create either a standard button with text label (which may still contain
|
// 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
|
// an image under GTK+ 2.6+) or a bitmap-only button if we don't have any
|
||||||
// label
|
// label
|
||||||
const bool useLabel = !label.empty() || wxIsStockID(id);
|
const bool
|
||||||
|
useLabel = !(style & wxBU_NOTEXT) && (!label.empty() || wxIsStockID(id));
|
||||||
if ( useLabel )
|
if ( useLabel )
|
||||||
{
|
{
|
||||||
m_widget = gtk_button_new_with_mnemonic("");
|
m_widget = gtk_button_new_with_mnemonic("");
|
||||||
@@ -237,6 +238,10 @@ void wxButton::SetLabel( const wxString &lbl )
|
|||||||
|
|
||||||
wxControl::SetLabel(label);
|
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))
|
if (wxIsStockID(m_windowId) && wxIsStockLabel(m_windowId, label))
|
||||||
{
|
{
|
||||||
const char *stock = wxGetStockGtkID(m_windowId);
|
const char *stock = wxGetStockGtkID(m_windowId);
|
||||||
@@ -410,7 +415,7 @@ void wxButton::GTKDoShowBitmap(const wxBitmap& bitmap)
|
|||||||
wxASSERT_MSG( bitmap.IsOk(), "invalid bitmap" );
|
wxASSERT_MSG( bitmap.IsOk(), "invalid bitmap" );
|
||||||
|
|
||||||
GtkWidget *image;
|
GtkWidget *image;
|
||||||
if ( GetLabel().empty() )
|
if ( DontShowLabel() )
|
||||||
{
|
{
|
||||||
image = GTK_BIN(m_widget)->child;
|
image = GTK_BIN(m_widget)->child;
|
||||||
}
|
}
|
||||||
@@ -450,7 +455,7 @@ void wxButton::DoSetBitmap(const wxBitmap& bitmap, State which)
|
|||||||
switch ( which )
|
switch ( which )
|
||||||
{
|
{
|
||||||
case State_Normal:
|
case State_Normal:
|
||||||
if ( GetLabel().empty() )
|
if ( DontShowLabel() )
|
||||||
{
|
{
|
||||||
// we only have the bitmap in this button, never remove it but
|
// we only have the bitmap in this button, never remove it but
|
||||||
// do invalidate the best size when the bitmap (and presumably
|
// do invalidate the best size when the bitmap (and presumably
|
||||||
|
@@ -131,7 +131,9 @@ bool wxBitmapButton::Create(wxWindow *parent,
|
|||||||
const wxString& name)
|
const wxString& name)
|
||||||
{
|
{
|
||||||
if ( !wxBitmapButtonBase::Create(parent, id, "",
|
if ( !wxBitmapButtonBase::Create(parent, id, "",
|
||||||
pos, size, style, validator, name) )
|
pos, size,
|
||||||
|
style | wxBU_NOTEXT,
|
||||||
|
validator, name) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
SetBitmapLabel(bitmap);
|
SetBitmapLabel(bitmap);
|
||||||
|
@@ -145,7 +145,7 @@ public:
|
|||||||
|
|
||||||
// we use margins when we have both bitmap and text, but when we have
|
// 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
|
// 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.x = btn->GetCharWidth();
|
||||||
m_margin.y = btn->GetCharHeight() / 2;
|
m_margin.y = btn->GetCharHeight() / 2;
|
||||||
@@ -575,7 +575,7 @@ wxSize wxButton::DoGetBestSize() const
|
|||||||
wxSize size;
|
wxSize size;
|
||||||
|
|
||||||
// account for the text part
|
// account for the text part
|
||||||
if ( !GetLabel().empty() )
|
if ( ShowsLabel() )
|
||||||
{
|
{
|
||||||
size = wxMSWButton::ComputeBestSize(const_cast<wxButton *>(this));
|
size = wxMSWButton::ComputeBestSize(const_cast<wxButton *>(this));
|
||||||
}
|
}
|
||||||
@@ -946,7 +946,7 @@ void wxButton::DoSetBitmap(const wxBitmap& bitmap, State which)
|
|||||||
// (even if we use BUTTON_IMAGELIST_ALIGN_CENTER alignment and
|
// (even if we use BUTTON_IMAGELIST_ALIGN_CENTER alignment and
|
||||||
// BS_BITMAP style), at least under Windows 2003 so use owner drawn
|
// BS_BITMAP style), at least under Windows 2003 so use owner drawn
|
||||||
// strategy for bitmap-only buttons
|
// strategy for bitmap-only buttons
|
||||||
if ( !GetLabel().empty() && wxUxThemeEngine::GetIfActive() )
|
if ( ShowsLabel() && wxUxThemeEngine::GetIfActive() )
|
||||||
{
|
{
|
||||||
m_imageData = new wxXPButtonImageData(this, bitmap);
|
m_imageData = new wxXPButtonImageData(this, bitmap);
|
||||||
}
|
}
|
||||||
@@ -1262,8 +1262,6 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis)
|
|||||||
RECT rectBtn;
|
RECT rectBtn;
|
||||||
CopyRect(&rectBtn, &lpDIS->rcItem);
|
CopyRect(&rectBtn, &lpDIS->rcItem);
|
||||||
|
|
||||||
const wxString label = GetLabel();
|
|
||||||
|
|
||||||
// draw the button background
|
// draw the button background
|
||||||
#if wxUSE_UXTHEME
|
#if wxUSE_UXTHEME
|
||||||
if ( wxUxThemeEngine::GetIfActive() )
|
if ( wxUxThemeEngine::GetIfActive() )
|
||||||
@@ -1364,7 +1362,7 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis)
|
|||||||
|
|
||||||
|
|
||||||
// finally draw the label
|
// finally draw the label
|
||||||
if ( !label.empty() )
|
if ( ShowsLabel() )
|
||||||
{
|
{
|
||||||
COLORREF colFg = state & ODS_DISABLED
|
COLORREF colFg = state & ODS_DISABLED
|
||||||
? ::GetSysColor(COLOR_GRAYTEXT)
|
? ::GetSysColor(COLOR_GRAYTEXT)
|
||||||
@@ -1373,7 +1371,7 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis)
|
|||||||
// notice that DT_HIDEPREFIX doesn't work on old (pre-Windows 2000)
|
// notice that DT_HIDEPREFIX doesn't work on old (pre-Windows 2000)
|
||||||
// systems but by happy coincidence ODS_NOACCEL is not used under them
|
// systems but by happy coincidence ODS_NOACCEL is not used under them
|
||||||
// neither so DT_HIDEPREFIX should never be used there
|
// 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);
|
state & ODS_NOACCEL ? DT_HIDEPREFIX : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user