1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
4 // Purpose: Shows wxColourPickerCtrl
5 // Author: Francesco Montorsi
7 // Copyright: (c) 2006 Francesco Montorsi
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
26 #if wxUSE_COLOURPICKERCTRL
28 // for all others, include the necessary headers
32 #include "wx/radiobox.h"
35 #include "wx/artprov.h"
37 #include "wx/stattext.h"
38 #include "wx/checkbox.h"
39 #include "wx/imaglist.h"
41 #include "wx/clrpicker.h"
44 #include "icons/clrpicker.xpm"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
53 PickerPage_Reset
= wxID_HIGHEST
,
58 // ----------------------------------------------------------------------------
59 // ColourPickerWidgetsPage
60 // ----------------------------------------------------------------------------
62 class ColourPickerWidgetsPage
: public WidgetsPage
65 ColourPickerWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
66 virtual ~ColourPickerWidgetsPage(){};
68 virtual wxControl
*GetWidget() const { return m_clrPicker
; }
69 virtual void RecreateWidget() { RecreatePicker(); }
71 // lazy creation of the content
72 virtual void CreateContent();
76 // called only once at first construction
79 // called to recreate an existing control
80 void RecreatePicker();
82 // restore the checkboxes state to the initial values
85 // get the initial style for the picker of the given kind
86 long GetPickerStyle();
89 void OnColourChange(wxColourPickerEvent
&ev
);
90 void OnCheckBox(wxCommandEvent
&ev
);
91 void OnButtonReset(wxCommandEvent
&ev
);
94 wxColourPickerCtrl
*m_clrPicker
;
100 wxCheckBox
*m_chkColourTextCtrl
,
101 *m_chkColourShowLabel
;
105 DECLARE_EVENT_TABLE()
106 DECLARE_WIDGETS_PAGE(ColourPickerWidgetsPage
)
109 // ----------------------------------------------------------------------------
111 // ----------------------------------------------------------------------------
113 BEGIN_EVENT_TABLE(ColourPickerWidgetsPage
, WidgetsPage
)
114 EVT_BUTTON(PickerPage_Reset
, ColourPickerWidgetsPage::OnButtonReset
)
116 EVT_COLOURPICKER_CHANGED(PickerPage_Colour
, ColourPickerWidgetsPage::OnColourChange
)
118 EVT_CHECKBOX(wxID_ANY
, ColourPickerWidgetsPage::OnCheckBox
)
121 // ============================================================================
123 // ============================================================================
125 #if defined(__WXGTK24__)
126 #define FAMILY_CTRLS NATIVE_CTRLS
128 #define FAMILY_CTRLS GENERIC_CTRLS
131 IMPLEMENT_WIDGETS_PAGE(ColourPickerWidgetsPage
, wxT("ColourPicker"),
132 PICKER_CTRLS
| FAMILY_CTRLS
);
134 ColourPickerWidgetsPage::ColourPickerWidgetsPage(WidgetsBookCtrl
*book
,
135 wxImageList
*imaglist
)
136 : WidgetsPage(book
, imaglist
, clrpicker_xpm
)
140 void ColourPickerWidgetsPage::CreateContent()
143 wxSizer
*boxleft
= new wxBoxSizer(wxVERTICAL
);
145 wxStaticBoxSizer
*clrbox
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("&ColourPicker style"));
146 m_chkColourTextCtrl
= CreateCheckBoxAndAddToSizer(clrbox
, wxT("With textctrl"));
147 m_chkColourShowLabel
= CreateCheckBoxAndAddToSizer(clrbox
, wxT("With label"));
148 boxleft
->Add(clrbox
, 0, wxALL
|wxGROW
, 5);
150 boxleft
->Add(new wxButton(this, PickerPage_Reset
, wxT("&Reset")),
151 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 15);
153 Reset(); // set checkboxes state
160 m_sizer
= new wxBoxSizer(wxVERTICAL
);
161 m_sizer
->Add(1, 1, 1, wxGROW
| wxALL
, 5); // spacer
162 m_sizer
->Add(m_clrPicker
, 0, wxALIGN_CENTER
|wxALL
, 5);
163 m_sizer
->Add(1, 1, 1, wxGROW
| wxALL
, 5); // spacer
166 wxSizer
*sz
= new wxBoxSizer(wxHORIZONTAL
);
167 sz
->Add(boxleft
, 0, wxGROW
|wxALL
, 5);
168 sz
->Add(m_sizer
, 1, wxGROW
|wxALL
, 5);
173 void ColourPickerWidgetsPage::CreatePicker()
177 m_clrPicker
= new wxColourPickerCtrl(this, PickerPage_Colour
, *wxRED
,
178 wxDefaultPosition
, wxDefaultSize
,
182 long ColourPickerWidgetsPage::GetPickerStyle()
186 if ( m_chkColourTextCtrl
->GetValue() )
187 style
|= wxCLRP_USE_TEXTCTRL
;
189 if ( m_chkColourShowLabel
->GetValue() )
190 style
|= wxCLRP_SHOW_LABEL
;
195 void ColourPickerWidgetsPage::RecreatePicker()
199 m_sizer
->Insert(1, m_clrPicker
, 0, wxALIGN_CENTER
|wxALL
, 5);
204 void ColourPickerWidgetsPage::Reset()
206 m_chkColourTextCtrl
->SetValue((wxCLRP_DEFAULT_STYLE
& wxCLRP_USE_TEXTCTRL
) != 0);
207 m_chkColourShowLabel
->SetValue((wxCLRP_DEFAULT_STYLE
& wxCLRP_SHOW_LABEL
) != 0);
211 // ----------------------------------------------------------------------------
213 // ----------------------------------------------------------------------------
215 void ColourPickerWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
221 void ColourPickerWidgetsPage::OnColourChange(wxColourPickerEvent
& event
)
223 wxLogMessage(wxT("The colour changed to '%s' !"),
224 event
.GetColour().GetAsString(wxC2S_CSS_SYNTAX
).c_str());
227 void ColourPickerWidgetsPage::OnCheckBox(wxCommandEvent
&event
)
229 if (event
.GetEventObject() == m_chkColourTextCtrl
||
230 event
.GetEventObject() == m_chkColourShowLabel
)
234 #endif // wxUSE_COLOURPICKERCTRL