Make wxGenericColourButton derive from wxBitmapButton
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50571 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
// wxGenericColourButton: a button which brings up a wxColourDialog
|
// wxGenericColourButton: a button which brings up a wxColourDialog
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxGenericColourButton : public wxButton,
|
class WXDLLIMPEXP_CORE wxGenericColourButton : public wxBitmapButton,
|
||||||
public wxColourPickerWidgetBase
|
public wxColourPickerWidgetBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -63,6 +63,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
wxBitmap m_bitmap;
|
||||||
|
|
||||||
wxSize DoGetBestSize() const;
|
wxSize DoGetBestSize() const;
|
||||||
|
|
||||||
|
@@ -36,7 +36,7 @@
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
wxColourData wxGenericColourButton::ms_data;
|
wxColourData wxGenericColourButton::ms_data;
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxGenericColourButton, wxButton)
|
IMPLEMENT_DYNAMIC_CLASS(wxGenericColourButton, wxBitmapButton)
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxGenericColourButton
|
// wxGenericColourButton
|
||||||
@@ -47,8 +47,10 @@ bool wxGenericColourButton::Create( wxWindow *parent, wxWindowID id,
|
|||||||
const wxSize &size, long style,
|
const wxSize &size, long style,
|
||||||
const wxValidator& validator, const wxString &name)
|
const wxValidator& validator, const wxString &name)
|
||||||
{
|
{
|
||||||
|
m_bitmap = wxBitmap( 60, 13 );
|
||||||
|
|
||||||
// create this button
|
// create this button
|
||||||
if (!wxButton::Create( parent, id, wxEmptyString, pos,
|
if (!wxBitmapButton::Create( parent, id, m_bitmap, pos,
|
||||||
size, style, validator, name ))
|
size, style, validator, name ))
|
||||||
{
|
{
|
||||||
wxFAIL_MSG( wxT("wxGenericColourButton creation failed") );
|
wxFAIL_MSG( wxT("wxGenericColourButton creation failed") );
|
||||||
@@ -99,33 +101,30 @@ void wxGenericColourButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev))
|
|||||||
|
|
||||||
void wxGenericColourButton::UpdateColour()
|
void wxGenericColourButton::UpdateColour()
|
||||||
{
|
{
|
||||||
if ( !m_colour.Ok() )
|
wxMemoryDC dc(m_bitmap);
|
||||||
{
|
dc.SetPen( *wxTRANSPARENT_PEN );
|
||||||
if ( HasFlag(wxCLRP_SHOW_LABEL) )
|
dc.SetBrush( wxBrush(m_colour) );
|
||||||
SetLabel(wxEmptyString);
|
dc.DrawRectangle( 0,0,m_bitmap.GetWidth(),m_bitmap.GetHeight() );
|
||||||
return;
|
dc.SelectObject( wxNullBitmap );
|
||||||
}
|
SetBitmapLabel( m_bitmap );
|
||||||
|
|
||||||
// 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 0
|
||||||
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(wxBitmapButton::DoGetBestSize());
|
||||||
|
sz.y += 6;
|
||||||
|
sz.x += 30;
|
||||||
if ( HasFlag(wxCLRP_SHOW_LABEL) )
|
if ( HasFlag(wxCLRP_SHOW_LABEL) )
|
||||||
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) ???
|
||||||
sz.SetWidth(sz.GetHeight());
|
// sz.SetWidth(sz.GetHeight());
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user