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
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_CLRPICKER_H_BASE_
13 #define _WX_CLRPICKER_H_BASE_
18 #if wxUSE_COLOURPICKERCTRL
20 #include "wx/pickerbase.h"
23 class WXDLLIMPEXP_CORE wxColourPickerEvent
;
25 extern WXDLLEXPORT_DATA(const wxChar
) wxColourPickerWidgetNameStr
[];
26 extern WXDLLEXPORT_DATA(const wxChar
) wxColourPickerCtrlNameStr
[];
29 // ----------------------------------------------------------------------------
30 // wxColourPickerWidgetBase: a generic abstract interface which must be
31 // implemented by controls used by wxColourPickerCtrl
32 // ----------------------------------------------------------------------------
34 class WXDLLIMPEXP_CORE wxColourPickerWidgetBase
37 wxColourPickerWidgetBase() { m_colour
= *wxBLACK
; }
38 virtual ~wxColourPickerWidgetBase() {}
40 wxColour
GetColour() const
42 virtual void SetColour(const wxColour
&col
)
43 { m_colour
= col
; UpdateColour(); }
44 virtual void SetColour(const wxString
&col
)
45 { m_colour
.Set(col
); UpdateColour(); }
49 virtual void UpdateColour() = 0;
51 // the current colour (may be invalid if none)
56 // Styles which must be supported by all controls implementing wxColourPickerWidgetBase
57 // NB: these styles must be defined to carefully-chosen values to
58 // avoid conflicts with wxButton's styles
60 // show the colour in HTML form (#AABBCC) as colour button label
61 // (instead of no label at all)
62 // NOTE: this style is supported just by wxColourButtonGeneric and
63 // thus is not exposed in wxColourPickerCtrl
64 #define wxCLRP_SHOW_LABEL 0x0008
66 // map platform-dependent controls which implement the wxColourPickerWidgetBase
67 // under the name "wxColourPickerWidget".
68 // NOTE: wxColourPickerCtrl allocates a wxColourPickerWidget and relies on the
69 // fact that all classes being mapped as wxColourPickerWidget have the
70 // same prototype for their contructor (and also explains why we use
71 // define instead of a typedef)
72 // since GTK > 2.4, there is GtkColorButton
73 #if defined(__WXGTK24__) && !defined(__WXUNIVERSAL__)
74 #include "wx/gtk/clrpicker.h"
75 #define wxColourPickerWidget wxColourButton
77 #include "wx/generic/clrpickerg.h"
78 #define wxColourPickerWidget wxGenericColourButton
82 // ----------------------------------------------------------------------------
83 // wxColourPickerCtrl: platform-independent class which embeds a
84 // platform-dependent wxColourPickerWidget and, if wxCLRP_USE_TEXTCTRL style is
85 // used, a textctrl next to it.
86 // ----------------------------------------------------------------------------
88 #define wxCLRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
89 #define wxCLRP_DEFAULT_STYLE 0
91 class WXDLLIMPEXP_CORE wxColourPickerCtrl
: public wxPickerBase
94 wxColourPickerCtrl() : m_bIgnoreNextTextCtrlUpdate(false) {}
95 virtual ~wxColourPickerCtrl() {}
98 wxColourPickerCtrl(wxWindow
*parent
, wxWindowID id
,
99 const wxColour
& col
= *wxBLACK
, const wxPoint
& pos
= wxDefaultPosition
,
100 const wxSize
& size
= wxDefaultSize
, long style
= wxCLRP_DEFAULT_STYLE
,
101 const wxValidator
& validator
= wxDefaultValidator
,
102 const wxString
& name
= wxColourPickerCtrlNameStr
)
103 : m_bIgnoreNextTextCtrlUpdate(false)
104 { Create(parent
, id
, col
, pos
, size
, style
, validator
, name
); }
106 bool Create(wxWindow
*parent
, wxWindowID id
,
107 const wxColour
& col
= *wxBLACK
,
108 const wxPoint
& pos
= wxDefaultPosition
,
109 const wxSize
& size
= wxDefaultSize
,
110 long style
= wxCLRP_DEFAULT_STYLE
,
111 const wxValidator
& validator
= wxDefaultValidator
,
112 const wxString
& name
= wxColourPickerCtrlNameStr
);
115 public: // public API
117 // get the colour chosen
118 wxColour
GetColour() const
119 { return ((wxColourPickerWidget
*)m_picker
)->GetColour(); }
121 // set currently displayed color
122 void SetColour(const wxColour
& col
);
124 // set colour using RGB(r,g,b) syntax or considering given text as a colour name;
125 // returns true if the given text was successfully recognized.
126 bool SetColour(const wxString
& text
);
129 public: // internal functions
131 // update the button colour to match the text control contents
132 void UpdatePickerFromTextCtrl();
134 // update the text control to match the button's colour
135 void UpdateTextCtrlFromPicker();
137 // event handler for our picker
138 void OnColourChange(wxColourPickerEvent
&);
141 virtual long GetPickerStyle(long style
) const
142 { return (style
& wxCLRP_SHOW_LABEL
); }
144 // true if the next UpdateTextCtrl() call is to ignore
145 bool m_bIgnoreNextTextCtrlUpdate
;
148 DECLARE_DYNAMIC_CLASS(wxColourPickerCtrl
)
152 // ----------------------------------------------------------------------------
153 // wxColourPickerEvent: used by wxColourPickerCtrl only
154 // ----------------------------------------------------------------------------
156 BEGIN_DECLARE_EVENT_TYPES()
157 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE
, wxEVT_COMMAND_COLOURPICKER_CHANGED
, 1102)
158 END_DECLARE_EVENT_TYPES()
160 class WXDLLIMPEXP_CORE wxColourPickerEvent
: public wxCommandEvent
163 wxColourPickerEvent() {}
164 wxColourPickerEvent(wxObject
*generator
, int id
, const wxColour
&col
)
165 : wxCommandEvent(wxEVT_COMMAND_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 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxColourPickerEventFunction, &func)
193 #define EVT_COLOURPICKER_CHANGED(id, fn) \
194 wx__DECLARE_EVT1(wxEVT_COMMAND_COLOURPICKER_CHANGED, id, wxColourPickerEventHandler(fn))
197 #endif // wxUSE_COLOURPICKERCTRL
199 #endif // _WX_CLRPICKER_H_BASE_