adding bitmap button version for colour picker, used by setting wxCLRBTN_USES_BMP_BUTTON to 1, off by default also on Mac for binary compat reasons.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@58967 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -25,8 +25,18 @@
|
|||||||
// the default style
|
// the default style
|
||||||
#define wxCLRBTN_DEFAULT_STYLE (wxCLRBTN_SHOW_LABEL)
|
#define wxCLRBTN_DEFAULT_STYLE (wxCLRBTN_SHOW_LABEL)
|
||||||
|
|
||||||
|
#ifndef wxCLRBTN_USES_BMP_BUTTON
|
||||||
|
#define wxCLRBTN_USES_BMP_BUTTON 0
|
||||||
|
#endif
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxGenericColourButton : public wxButton,
|
#if wxCLRBTN_USES_BMP_BUTTON
|
||||||
|
#include "wx/bmpbutton.h"
|
||||||
|
#define wxCLRBTN_BASE_CLASS wxBitmapButton
|
||||||
|
#else
|
||||||
|
#define wxCLRBTN_BASE_CLASS wxButton
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class WXDLLIMPEXP_CORE wxGenericColourButton : public wxCLRBTN_BASE_CLASS,
|
||||||
public wxColourPickerWidgetBase
|
public wxColourPickerWidgetBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@@ -36,7 +36,7 @@
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
wxColourData wxGenericColourButton::ms_data;
|
wxColourData wxGenericColourButton::ms_data;
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxGenericColourButton, wxButton)
|
IMPLEMENT_DYNAMIC_CLASS(wxGenericColourButton, wxCLRBTN_BASE_CLASS)
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxGenericColourButton
|
// wxGenericColourButton
|
||||||
@@ -48,8 +48,14 @@ bool wxGenericColourButton::Create( wxWindow *parent, wxWindowID id,
|
|||||||
const wxValidator& validator, const wxString &name)
|
const wxValidator& validator, const wxString &name)
|
||||||
{
|
{
|
||||||
// create this button
|
// create this button
|
||||||
|
#if wxCLRBTN_USES_BMP_BUTTON
|
||||||
|
wxBitmap empty(1,1);
|
||||||
|
if (!wxBitmapButton::Create( parent, id, empty, pos,
|
||||||
|
size, style, validator, name ))
|
||||||
|
#else
|
||||||
if (!wxButton::Create( parent, id, wxEmptyString, pos,
|
if (!wxButton::Create( parent, id, wxEmptyString, pos,
|
||||||
size, style, validator, name ))
|
size, style, validator, name ))
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
wxFAIL_MSG( wxT("wxGenericColourButton creation failed") );
|
wxFAIL_MSG( wxT("wxGenericColourButton creation failed") );
|
||||||
return false;
|
return false;
|
||||||
@@ -101,8 +107,13 @@ void wxGenericColourButton::UpdateColour()
|
|||||||
{
|
{
|
||||||
if ( !m_colour.Ok() )
|
if ( !m_colour.Ok() )
|
||||||
{
|
{
|
||||||
|
#if wxCLRBTN_USES_BMP_BUTTON
|
||||||
|
wxBitmap empty(1,1);
|
||||||
|
SetBitmapLabel(empty);
|
||||||
|
#else
|
||||||
if ( HasFlag(wxCLRP_SHOW_LABEL) )
|
if ( HasFlag(wxCLRP_SHOW_LABEL) )
|
||||||
SetLabel(wxEmptyString);
|
SetLabel(wxEmptyString);
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,18 +121,63 @@ void wxGenericColourButton::UpdateColour()
|
|||||||
// the colour to make sure fg colour is different enough from m_colour
|
// the colour to make sure fg colour is different enough from m_colour
|
||||||
wxColour colFg(~m_colour.Red(), ~m_colour.Green(), ~m_colour.Blue());
|
wxColour colFg(~m_colour.Red(), ~m_colour.Green(), ~m_colour.Blue());
|
||||||
|
|
||||||
|
#if wxCLRBTN_USES_BMP_BUTTON
|
||||||
|
wxSize sz = GetSize();
|
||||||
|
sz.x -= 2*GetMarginX();
|
||||||
|
sz.y -= 2*GetMarginY();
|
||||||
|
|
||||||
|
wxPoint topleft;
|
||||||
|
|
||||||
|
if ( sz.x < 1 )
|
||||||
|
sz.x = 1;
|
||||||
|
else
|
||||||
|
if ( sz.y < 1 )
|
||||||
|
sz.y = 1;
|
||||||
|
|
||||||
|
wxBitmap bmp(sz.x, sz.y);
|
||||||
|
{
|
||||||
|
wxMemoryDC memdc(bmp);
|
||||||
|
memdc.SetPen(colFg);
|
||||||
|
memdc.SetBrush(m_colour);
|
||||||
|
memdc.DrawRectangle(topleft,sz);
|
||||||
|
if ( HasFlag(wxCLRP_SHOW_LABEL) )
|
||||||
|
{
|
||||||
|
int x, y, leading, desc;
|
||||||
|
wxString label = m_colour.GetAsString(wxC2S_HTML_SYNTAX);
|
||||||
|
memdc.GetTextExtent(label,&x,&y,&desc,&leading);
|
||||||
|
if ( x <= sz.x && y <= sz.y )
|
||||||
|
{
|
||||||
|
topleft.x += (sz.x-x)/2;
|
||||||
|
topleft.y += (sz.y-y)/2;
|
||||||
|
memdc.SetTextForeground(colFg);
|
||||||
|
memdc.DrawText(label,topleft);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SetBitmapLabel(bmp);
|
||||||
|
#else
|
||||||
SetForegroundColour(colFg);
|
SetForegroundColour(colFg);
|
||||||
SetBackgroundColour(m_colour);
|
SetBackgroundColour(m_colour);
|
||||||
|
|
||||||
if ( HasFlag(wxCLRP_SHOW_LABEL) )
|
if ( HasFlag(wxCLRP_SHOW_LABEL) )
|
||||||
SetLabel(m_colour.GetAsString(wxC2S_HTML_SYNTAX));
|
SetLabel(m_colour.GetAsString(wxC2S_HTML_SYNTAX));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize wxGenericColourButton::DoGetBestSize() const
|
wxSize wxGenericColourButton::DoGetBestSize() const
|
||||||
{
|
{
|
||||||
wxSize sz(wxButton::DoGetBestSize());
|
wxSize sz(wxButton::DoGetBestSize());
|
||||||
if ( HasFlag(wxCLRP_SHOW_LABEL) )
|
if ( HasFlag(wxCLRP_SHOW_LABEL) )
|
||||||
|
{
|
||||||
|
#if wxCLRBTN_USES_BMP_BUTTON
|
||||||
|
int x, y, leading, desc;
|
||||||
|
wxString label = m_colour.GetAsString(wxC2S_HTML_SYNTAX);
|
||||||
|
wxClientDC dc(const_cast<wxGenericColourButton*>(this));
|
||||||
|
dc.GetTextExtent(label,&x,&y,&desc,&leading);
|
||||||
|
sz.x = sz.y+x;
|
||||||
|
#endif
|
||||||
return sz;
|
return sz;
|
||||||
|
}
|
||||||
|
|
||||||
// if we have no label, then make this button a square
|
// if we have no label, then make this button a square
|
||||||
// (like e.g. native GTK version of this control)
|
// (like e.g. native GTK version of this control)
|
||||||
|
Reference in New Issue
Block a user