1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
4 // Purpose: Shows wxColourPickerCtrl
5 // Author: Francesco Montorsi
8 // Copyright: (c) 2006 Francesco Montorsi
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_COLOURPICKERCTRL
29 // for all others, include the necessary headers
33 #include "wx/radiobox.h"
36 #include "wx/artprov.h"
38 #include "wx/stattext.h"
39 #include "wx/checkbox.h"
40 #include "wx/imaglist.h"
42 #include "wx/clrpicker.h"
45 #include "icons/clrpicker.xpm"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
54 PickerPage_Reset
= wxID_HIGHEST
,
59 // ----------------------------------------------------------------------------
60 // ColourPickerWidgetsPage
61 // ----------------------------------------------------------------------------
63 class ColourPickerWidgetsPage
: public WidgetsPage
66 ColourPickerWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
67 virtual ~ColourPickerWidgetsPage(){};
69 virtual wxControl
*GetWidget() const { return m_clrPicker
; }
70 virtual void RecreateWidget() { RecreatePicker(); }
72 // lazy creation of the content
73 virtual void CreateContent();
77 // called only once at first construction
80 // called to recreate an existing control
81 void RecreatePicker();
83 // restore the checkboxes state to the initial values
86 // get the initial style for the picker of the given kind
87 long GetPickerStyle();
90 void OnColourChange(wxColourPickerEvent
&ev
);
91 void OnCheckBox(wxCommandEvent
&ev
);
92 void OnButtonReset(wxCommandEvent
&ev
);
95 wxColourPickerCtrl
*m_clrPicker
;
101 wxCheckBox
*m_chkColourTextCtrl
,
102 *m_chkColourShowLabel
;
106 DECLARE_EVENT_TABLE()
107 DECLARE_WIDGETS_PAGE(ColourPickerWidgetsPage
)
110 // ----------------------------------------------------------------------------
112 // ----------------------------------------------------------------------------
114 BEGIN_EVENT_TABLE(ColourPickerWidgetsPage
, WidgetsPage
)
115 EVT_BUTTON(PickerPage_Reset
, ColourPickerWidgetsPage::OnButtonReset
)
117 EVT_COLOURPICKER_CHANGED(PickerPage_Colour
, ColourPickerWidgetsPage::OnColourChange
)
119 EVT_CHECKBOX(wxID_ANY
, ColourPickerWidgetsPage::OnCheckBox
)
122 // ============================================================================
124 // ============================================================================
126 #if defined(__WXGTK24__)
127 #define FAMILY_CTRLS NATIVE_CTRLS
129 #define FAMILY_CTRLS GENERIC_CTRLS
132 IMPLEMENT_WIDGETS_PAGE(ColourPickerWidgetsPage
, wxT("ColourPicker"),
133 PICKER_CTRLS
| FAMILY_CTRLS
);
135 ColourPickerWidgetsPage::ColourPickerWidgetsPage(WidgetsBookCtrl
*book
,
136 wxImageList
*imaglist
)
137 : WidgetsPage(book
, imaglist
, clrpicker_xpm
)
141 void ColourPickerWidgetsPage::CreateContent()
144 wxSizer
*boxleft
= new wxBoxSizer(wxVERTICAL
);
146 wxStaticBoxSizer
*clrbox
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("&ColourPicker style"));
147 m_chkColourTextCtrl
= CreateCheckBoxAndAddToSizer(clrbox
, wxT("With textctrl"), false);
148 m_chkColourShowLabel
= CreateCheckBoxAndAddToSizer(clrbox
, wxT("With label"), false);
149 boxleft
->Add(clrbox
, 0, wxALL
|wxGROW
, 5);
151 boxleft
->Add(new wxButton(this, PickerPage_Reset
, wxT("&Reset")),
152 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 15);
154 Reset(); // set checkboxes state
161 m_sizer
= new wxBoxSizer(wxVERTICAL
);
162 m_sizer
->Add(1, 1, 1, wxGROW
| wxALL
, 5); // spacer
163 m_sizer
->Add(m_clrPicker
, 0, wxALIGN_CENTER
|wxALL
, 5);
164 m_sizer
->Add(1, 1, 1, wxGROW
| wxALL
, 5); // spacer
167 wxSizer
*sz
= new wxBoxSizer(wxHORIZONTAL
);
168 sz
->Add(boxleft
, 0, wxGROW
|wxALL
, 5);
169 sz
->Add(m_sizer
, 1, wxGROW
|wxALL
, 5);
174 void ColourPickerWidgetsPage::CreatePicker()
178 m_clrPicker
= new wxColourPickerCtrl(this, PickerPage_Colour
, *wxRED
,
179 wxDefaultPosition
, wxDefaultSize
,
183 long ColourPickerWidgetsPage::GetPickerStyle()
187 if ( m_chkColourTextCtrl
->GetValue() )
188 style
|= wxCLRP_USE_TEXTCTRL
;
190 if ( m_chkColourShowLabel
->GetValue() )
191 style
|= wxCLRP_SHOW_LABEL
;
196 void ColourPickerWidgetsPage::RecreatePicker()
200 m_sizer
->Insert(1, m_clrPicker
, 0, wxALIGN_CENTER
|wxALL
, 5);
205 void ColourPickerWidgetsPage::Reset()
207 m_chkColourTextCtrl
->SetValue((wxCLRP_DEFAULT_STYLE
& wxCLRP_USE_TEXTCTRL
) != 0);
208 m_chkColourShowLabel
->SetValue((wxCLRP_DEFAULT_STYLE
& wxCLRP_SHOW_LABEL
) != 0);
212 // ----------------------------------------------------------------------------
214 // ----------------------------------------------------------------------------
216 void ColourPickerWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
222 void ColourPickerWidgetsPage::OnColourChange(wxColourPickerEvent
& event
)
224 wxLogMessage(wxT("The colour changed to '%s' !"),
225 event
.GetColour().GetAsString(wxC2S_CSS_SYNTAX
).c_str());
228 void ColourPickerWidgetsPage::OnCheckBox(wxCommandEvent
&event
)
230 if (event
.GetEventObject() == m_chkColourTextCtrl
||
231 event
.GetEventObject() == m_chkColourShowLabel
)
235 #endif // wxUSE_COLOURPICKERCTRL