X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ec376c8fd9ff813392030426acd2317c6fa6527e..245f96e890ee8912bb6b356239fa55b0706a769a:/src/generic/clrpickerg.cpp?ds=sidebyside diff --git a/src/generic/clrpickerg.cpp b/src/generic/clrpickerg.cpp index c6fc40bb4b..b17a9f38af 100644 --- a/src/generic/clrpickerg.cpp +++ b/src/generic/clrpickerg.cpp @@ -24,22 +24,19 @@ #pragma hdrstop #endif -#ifndef WX_PRECOMP - #include "wx/window.h" -#endif //WX_PRECOMP +#if wxUSE_COLOURPICKERCTRL #include "wx/clrpicker.h" #include "wx/colordlg.h" +#include "wx/dcmemory.h" // ============================================================================ // implementation // ============================================================================ -#if wxUSE_COLOURPICKERCTRL - wxColourData wxGenericColourButton::ms_data; -IMPLEMENT_DYNAMIC_CLASS(wxGenericColourButton, wxButton) +IMPLEMENT_DYNAMIC_CLASS(wxGenericColourButton, wxBitmapButton) // ---------------------------------------------------------------------------- // wxGenericColourButton @@ -50,16 +47,18 @@ bool wxGenericColourButton::Create( wxWindow *parent, wxWindowID id, 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; } // and handle user clicks on it - Connect(wxEVT_COMMAND_BUTTON_CLICKED, + Connect(GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxGenericColourButton::OnButtonClick), NULL, this); @@ -73,10 +72,11 @@ bool wxGenericColourButton::Create( wxWindow *parent, wxWindowID id, void wxGenericColourButton::InitColourData() { ms_data.SetChooseFull(true); - for (int i = 0; i < 16; i++) + unsigned char grey = 0; + for (int i = 0; i < 16; i++, grey += 16) { // fill with grey tones the custom colors palette - wxColour colour(i*16, i*16, i*16); + wxColour colour(grey, grey, grey); ms_data.SetCustomColour(i, colour); } } @@ -101,22 +101,39 @@ void wxGenericColourButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev)) 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); + dc.SelectObject( wxNullBitmap ); + SetBitmapLabel( m_bitmap ); +} +wxSize wxGenericColourButton::DoGetBestSize() const +{ + wxSize sz(wxBitmapButton::DoGetBestSize()); +#ifdef __WXMAC__ + sz.y += 6; +#else + sz.y += 2; +#endif + sz.x += 30; if ( HasFlag(wxCLRP_SHOW_LABEL) ) - SetLabel(m_colour.GetAsString(wxC2S_HTML_SYNTAX)); + 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()); + return sz; } #endif // wxUSE_COLOURPICKERCTRL