]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/clrpickerg.cpp
9f855ca4857f0b2676f53fd9a18bd3b2b44b3877
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/clrpickerg.cpp
3 // Purpose: wxGenericColourButton class implementation
4 // Author: Francesco Montorsi (readapted code written by Vadim Zeitlin)
8 // Copyright: (c) Vadim Zeitlin, Francesco Montorsi
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_COLOURPICKERCTRL
29 #include "wx/clrpicker.h"
30 #include "wx/colordlg.h"
31 #include "wx/dcmemory.h"
34 // ============================================================================
36 // ============================================================================
38 wxColourData
wxGenericColourButton::ms_data
;
39 IMPLEMENT_DYNAMIC_CLASS(wxGenericColourButton
, wxBitmapButton
)
41 // ----------------------------------------------------------------------------
42 // wxGenericColourButton
43 // ----------------------------------------------------------------------------
45 bool wxGenericColourButton::Create( wxWindow
*parent
, wxWindowID id
,
46 const wxColour
&col
, const wxPoint
&pos
,
47 const wxSize
&size
, long style
,
48 const wxValidator
& validator
, const wxString
&name
)
50 m_bitmap
= wxBitmap( 60, 13 );
53 if (!wxBitmapButton::Create( parent
, id
, m_bitmap
, pos
,
54 size
, style
| wxBU_AUTODRAW
, validator
, name
))
56 wxFAIL_MSG( wxT("wxGenericColourButton creation failed") );
60 // and handle user clicks on it
61 Connect(GetId(), wxEVT_BUTTON
,
62 wxCommandEventHandler(wxGenericColourButton::OnButtonClick
),
72 void wxGenericColourButton::InitColourData()
74 ms_data
.SetChooseFull(true);
75 unsigned char grey
= 0;
76 for (int i
= 0; i
< 16; i
++, grey
+= 16)
78 // fill with grey tones the custom colors palette
79 wxColour
colour(grey
, grey
, grey
);
80 ms_data
.SetCustomColour(i
, colour
);
84 void wxGenericColourButton::OnButtonClick(wxCommandEvent
& WXUNUSED(ev
))
86 // update the wxColouData to be shown in the dialog
87 ms_data
.SetColour(m_colour
);
89 // create the colour dialog and display it
90 wxColourDialog
dlg(this, &ms_data
);
91 if (dlg
.ShowModal() == wxID_OK
)
93 ms_data
= dlg
.GetColourData();
94 SetColour(ms_data
.GetColour());
97 wxColourPickerEvent
event(this, GetId(), m_colour
);
98 GetEventHandler()->ProcessEvent(event
);
102 void wxGenericColourButton::UpdateColour()
104 wxMemoryDC
dc(m_bitmap
);
105 dc
.SetPen( *wxTRANSPARENT_PEN
);
106 dc
.SetBrush( wxBrush(m_colour
) );
107 dc
.DrawRectangle( 0,0,m_bitmap
.GetWidth(),m_bitmap
.GetHeight() );
109 if ( HasFlag(wxCLRP_SHOW_LABEL
) )
111 wxColour
col( ~m_colour
.Red(), ~m_colour
.Green(), ~m_colour
.Blue() );
112 dc
.SetTextForeground( col
);
113 dc
.SetFont( GetFont() );
114 dc
.DrawText( m_colour
.GetAsString(wxC2S_HTML_SYNTAX
), 0, 0 );
117 dc
.SelectObject( wxNullBitmap
);
118 SetBitmapLabel( m_bitmap
);
121 wxSize
wxGenericColourButton::DoGetBestSize() const
123 wxSize
sz(wxBitmapButton::DoGetBestSize());
130 if ( HasFlag(wxCLRP_SHOW_LABEL
) )
133 // if we have no label, then make this button a square
134 // (like e.g. native GTK version of this control) ???
135 // sz.SetWidth(sz.GetHeight());
139 #endif // wxUSE_COLOURPICKERCTRL