#if wxUSE_COLOURPICKERCTRL
#include "wx/clrpicker.h"
-
#include "wx/colordlg.h"
+#include "wx/dcmemory.h"
// ============================================================================
// ============================================================================
wxColourData wxGenericColourButton::ms_data;
-IMPLEMENT_DYNAMIC_CLASS(wxGenericColourButton, wxButton)
+IMPLEMENT_DYNAMIC_CLASS(wxGenericColourButton, wxBitmapButton)
// ----------------------------------------------------------------------------
// wxGenericColourButton
const wxSize &size, long style,
const wxValidator& validator, const wxString &name)
{
+ m_bitmap = wxBitmap( 60, 13 );
+
// create this button
- if (!wxButton::Create( parent, id, wxEmptyString, pos,
- size, style, validator, name ))
+ if (!wxBitmapButton::Create( parent, id, m_bitmap, pos,
+ size, style | wxBU_AUTODRAW, validator, name ))
{
wxFAIL_MSG( wxT("wxGenericColourButton creation failed") );
return false;
void wxGenericColourButton::UpdateColour()
{
- if ( !m_colour.Ok() )
+ wxMemoryDC dc(m_bitmap);
+ dc.SetPen( *wxTRANSPARENT_PEN );
+ dc.SetBrush( wxBrush(m_colour) );
+ dc.DrawRectangle( 0,0,m_bitmap.GetWidth(),m_bitmap.GetHeight() );
+
+ if ( HasFlag(wxCLRP_SHOW_LABEL) )
{
- if ( HasFlag(wxCLRP_SHOW_LABEL) )
- SetLabel(wxEmptyString);
- return;
+ wxColour col( ~m_colour.Red(), ~m_colour.Green(), ~m_colour.Blue() );
+ dc.SetTextForeground( col );
+ dc.SetFont( GetFont() );
+ dc.DrawText( m_colour.GetAsString(wxC2S_HTML_SYNTAX), 0, 0 );
}
-
- // some combinations of the fg/bg colours may be unreadable, so we invert
- // the colour to make sure fg colour is different enough from m_colour
- wxColour colFg(~m_colour.Red(), ~m_colour.Green(), ~m_colour.Blue());
-
- SetForegroundColour(colFg);
- SetBackgroundColour(m_colour);
-
- if ( HasFlag(wxCLRP_SHOW_LABEL) )
- SetLabel(m_colour.GetAsString(wxC2S_HTML_SYNTAX));
+
+ dc.SelectObject( wxNullBitmap );
+ SetBitmapLabel( m_bitmap );
}
wxSize wxGenericColourButton::DoGetBestSize() const
{
- wxSize sz(wxButton::DoGetBestSize());
+ wxSize sz(wxBitmapButton::DoGetBestSize());
+#ifdef __WXMAC__
+ sz.y += 6;
+#else
+ sz.y += 2;
+#endif
+ sz.x += 30;
if ( HasFlag(wxCLRP_SHOW_LABEL) )
return sz;
// if we have no label, then make this button a square
- // (like e.g. native GTK version of this control)
- sz.SetWidth(sz.GetHeight());
+ // (like e.g. native GTK version of this control) ???
+ // sz.SetWidth(sz.GetHeight());
return sz;
}