1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/clrpicker.h
3 // Purpose: wxColourPickerCtrl base header
4 // Author: Francesco Montorsi (based on Vadim Zeitlin's code)
7 // Copyright: (c) Vadim Zeitlin, Francesco Montorsi
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_CLRPICKER_H_BASE_
12 #define _WX_CLRPICKER_H_BASE_
17 #if wxUSE_COLOURPICKERCTRL
19 #include "wx/pickerbase.h"
22 class WXDLLIMPEXP_FWD_CORE wxColourPickerEvent
;
24 extern WXDLLIMPEXP_DATA_CORE(const char) wxColourPickerWidgetNameStr
[];
25 extern WXDLLIMPEXP_DATA_CORE(const char) wxColourPickerCtrlNameStr
[];
27 // show the colour in HTML form (#AABBCC) as colour button label
28 #define wxCLRBTN_SHOW_LABEL 100
31 #define wxCLRBTN_DEFAULT_STYLE (wxCLRBTN_SHOW_LABEL)
35 // ----------------------------------------------------------------------------
36 // wxColourPickerWidgetBase: a generic abstract interface which must be
37 // implemented by controls used by wxColourPickerCtrl
38 // ----------------------------------------------------------------------------
40 class WXDLLIMPEXP_CORE wxColourPickerWidgetBase
43 wxColourPickerWidgetBase() { m_colour
= *wxBLACK
; }
44 virtual ~wxColourPickerWidgetBase() {}
46 wxColour
GetColour() const
48 virtual void SetColour(const wxColour
&col
)
49 { m_colour
= col
; UpdateColour(); }
50 virtual void SetColour(const wxString
&col
)
51 { m_colour
.Set(col
); UpdateColour(); }
55 virtual void UpdateColour() = 0;
57 // the current colour (may be invalid if none)
62 // Styles which must be supported by all controls implementing wxColourPickerWidgetBase
63 // NB: these styles must be defined to carefully-chosen values to
64 // avoid conflicts with wxButton's styles
66 // show the colour in HTML form (#AABBCC) as colour button label
67 // (instead of no label at all)
68 // NOTE: this style is supported just by wxColourButtonGeneric and
69 // thus is not exposed in wxColourPickerCtrl
70 #define wxCLRP_SHOW_LABEL 0x0008
72 // map platform-dependent controls which implement the wxColourPickerWidgetBase
73 // under the name "wxColourPickerWidget".
74 // NOTE: wxColourPickerCtrl allocates a wxColourPickerWidget and relies on the
75 // fact that all classes being mapped as wxColourPickerWidget have the
76 // same prototype for their contructor (and also explains why we use
77 // define instead of a typedef)
78 // since GTK > 2.4, there is GtkColorButton
79 #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
80 #include "wx/gtk/clrpicker.h"
81 #define wxColourPickerWidget wxColourButton
83 #include "wx/generic/clrpickerg.h"
84 #define wxColourPickerWidget wxGenericColourButton
88 // ----------------------------------------------------------------------------
89 // wxColourPickerCtrl: platform-independent class which embeds a
90 // platform-dependent wxColourPickerWidget and, if wxCLRP_USE_TEXTCTRL style is
91 // used, a textctrl next to it.
92 // ----------------------------------------------------------------------------
94 #define wxCLRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
95 #define wxCLRP_DEFAULT_STYLE 0
97 class WXDLLIMPEXP_CORE wxColourPickerCtrl
: public wxPickerBase
100 wxColourPickerCtrl() {}
101 virtual ~wxColourPickerCtrl() {}
104 wxColourPickerCtrl(wxWindow
*parent
, wxWindowID id
,
105 const wxColour
& col
= *wxBLACK
, const wxPoint
& pos
= wxDefaultPosition
,
106 const wxSize
& size
= wxDefaultSize
, long style
= wxCLRP_DEFAULT_STYLE
,
107 const wxValidator
& validator
= wxDefaultValidator
,
108 const wxString
& name
= wxColourPickerCtrlNameStr
)
109 { Create(parent
, id
, col
, pos
, size
, style
, validator
, name
); }
111 bool Create(wxWindow
*parent
, wxWindowID id
,
112 const wxColour
& col
= *wxBLACK
,
113 const wxPoint
& pos
= wxDefaultPosition
,
114 const wxSize
& size
= wxDefaultSize
,
115 long style
= wxCLRP_DEFAULT_STYLE
,
116 const wxValidator
& validator
= wxDefaultValidator
,
117 const wxString
& name
= wxColourPickerCtrlNameStr
);
120 public: // public API
122 // get the colour chosen
123 wxColour
GetColour() const
124 { return ((wxColourPickerWidget
*)m_picker
)->GetColour(); }
126 // set currently displayed color
127 void SetColour(const wxColour
& col
);
129 // set colour using RGB(r,g,b) syntax or considering given text as a colour name;
130 // returns true if the given text was successfully recognized.
131 bool SetColour(const wxString
& text
);
134 public: // internal functions
136 // update the button colour to match the text control contents
137 void UpdatePickerFromTextCtrl();
139 // update the text control to match the button's colour
140 void UpdateTextCtrlFromPicker();
142 // event handler for our picker
143 void OnColourChange(wxColourPickerEvent
&);
146 virtual long GetPickerStyle(long style
) const
147 { return (style
& wxCLRP_SHOW_LABEL
); }
150 DECLARE_DYNAMIC_CLASS(wxColourPickerCtrl
)
154 // ----------------------------------------------------------------------------
155 // wxColourPickerEvent: used by wxColourPickerCtrl only
156 // ----------------------------------------------------------------------------
158 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_COLOURPICKER_CHANGED
, wxColourPickerEvent
);
160 class WXDLLIMPEXP_CORE wxColourPickerEvent
: public wxCommandEvent
163 wxColourPickerEvent() {}
164 wxColourPickerEvent(wxObject
*generator
, int id
, const wxColour
&col
)
165 : wxCommandEvent(wxEVT_COLOURPICKER_CHANGED
, id
),
168 SetEventObject(generator
);
171 wxColour
GetColour() const { return m_colour
; }
172 void SetColour(const wxColour
&c
) { m_colour
= c
; }
175 // default copy ctor, assignment operator and dtor are ok
176 virtual wxEvent
*Clone() const { return new wxColourPickerEvent(*this); }
181 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxColourPickerEvent
)
184 // ----------------------------------------------------------------------------
185 // event types and macros
186 // ----------------------------------------------------------------------------
188 typedef void (wxEvtHandler::*wxColourPickerEventFunction
)(wxColourPickerEvent
&);
190 #define wxColourPickerEventHandler(func) \
191 wxEVENT_HANDLER_CAST(wxColourPickerEventFunction, func)
193 #define EVT_COLOURPICKER_CHANGED(id, fn) \
194 wx__DECLARE_EVT1(wxEVT_COLOURPICKER_CHANGED, id, wxColourPickerEventHandler(fn))
197 // old wxEVT_COMMAND_* constant
198 #define wxEVT_COMMAND_COLOURPICKER_CHANGED wxEVT_COLOURPICKER_CHANGED
200 #endif // wxUSE_COLOURPICKERCTRL
202 #endif // _WX_CLRPICKER_H_BASE_