]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/clrpickerg.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/clrpickerg.cpp
3 // Purpose: wxGenericColourButton class implementation
4 // Author: Francesco Montorsi (readapted code written by Vadim Zeitlin)
7 // Copyright: (c) Vadim Zeitlin, Francesco Montorsi
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #if wxUSE_COLOURPICKERCTRL
28 #include "wx/clrpicker.h"
29 #include "wx/colordlg.h"
30 #include "wx/dcmemory.h"
33 // ============================================================================
35 // ============================================================================
37 wxColourData
wxGenericColourButton::ms_data
;
38 IMPLEMENT_DYNAMIC_CLASS(wxGenericColourButton
, wxBitmapButton
)
40 // ----------------------------------------------------------------------------
41 // wxGenericColourButton
42 // ----------------------------------------------------------------------------
44 bool wxGenericColourButton::Create( wxWindow
*parent
, wxWindowID id
,
45 const wxColour
&col
, const wxPoint
&pos
,
46 const wxSize
&size
, long style
,
47 const wxValidator
& validator
, const wxString
&name
)
49 m_bitmap
= wxBitmap( 60, 13 );
52 if (!wxBitmapButton::Create( parent
, id
, m_bitmap
, pos
,
53 size
, style
| wxBU_AUTODRAW
, validator
, name
))
55 wxFAIL_MSG( wxT("wxGenericColourButton creation failed") );
59 // and handle user clicks on it
60 Connect(GetId(), wxEVT_BUTTON
,
61 wxCommandEventHandler(wxGenericColourButton::OnButtonClick
),
71 void wxGenericColourButton::InitColourData()
73 ms_data
.SetChooseFull(true);
74 unsigned char grey
= 0;
75 for (int i
= 0; i
< 16; i
++, grey
+= 16)
77 // fill with grey tones the custom colors palette
78 wxColour
colour(grey
, grey
, grey
);
79 ms_data
.SetCustomColour(i
, colour
);
83 void wxGenericColourButton::OnButtonClick(wxCommandEvent
& WXUNUSED(ev
))
85 // update the wxColouData to be shown in the dialog
86 ms_data
.SetColour(m_colour
);
88 // create the colour dialog and display it
89 wxColourDialog
dlg(this, &ms_data
);
90 if (dlg
.ShowModal() == wxID_OK
)
92 ms_data
= dlg
.GetColourData();
93 SetColour(ms_data
.GetColour());
96 wxColourPickerEvent
event(this, GetId(), m_colour
);
97 GetEventHandler()->ProcessEvent(event
);
101 void wxGenericColourButton::UpdateColour()
103 wxMemoryDC
dc(m_bitmap
);
104 dc
.SetPen( *wxTRANSPARENT_PEN
);
105 dc
.SetBrush( wxBrush(m_colour
) );
106 dc
.DrawRectangle( 0,0,m_bitmap
.GetWidth(),m_bitmap
.GetHeight() );
108 if ( HasFlag(wxCLRP_SHOW_LABEL
) )
110 wxColour
col( ~m_colour
.Red(), ~m_colour
.Green(), ~m_colour
.Blue() );
111 dc
.SetTextForeground( col
);
112 dc
.SetFont( GetFont() );
113 dc
.DrawText( m_colour
.GetAsString(wxC2S_HTML_SYNTAX
), 0, 0 );
116 dc
.SelectObject( wxNullBitmap
);
117 SetBitmapLabel( m_bitmap
);
120 wxSize
wxGenericColourButton::DoGetBestSize() const
122 wxSize
sz(wxBitmapButton::DoGetBestSize());
129 if ( HasFlag(wxCLRP_SHOW_LABEL
) )
132 // if we have no label, then make this button a square
133 // (like e.g. native GTK version of this control) ???
134 // sz.SetWidth(sz.GetHeight());
138 #endif // wxUSE_COLOURPICKERCTRL