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_FWD_CORE wxColourPickerEvent
;
25 extern WXDLLIMPEXP_DATA_CORE(const char) wxColourPickerWidgetNameStr
[];
26 extern WXDLLIMPEXP_DATA_CORE(const char) wxColourPickerCtrlNameStr
[];
28 // show the colour in HTML form (#AABBCC) as colour button label
29 #define wxCLRBTN_SHOW_LABEL 100
32 #define wxCLRBTN_DEFAULT_STYLE (wxCLRBTN_SHOW_LABEL)
36 // ----------------------------------------------------------------------------
37 // wxColourPickerWidgetBase: a generic abstract interface which must be
38 // implemented by controls used by wxColourPickerCtrl
39 // ----------------------------------------------------------------------------
41 class WXDLLIMPEXP_CORE wxColourPickerWidgetBase
44 wxColourPickerWidgetBase() { m_colour
= *wxBLACK
; }
45 virtual ~wxColourPickerWidgetBase() {}
47 wxColour
GetColour() const
49 virtual void SetColour(const wxColour
&col
)
50 { m_colour
= col
; UpdateColour(); }
51 virtual void SetColour(const wxString
&col
)
52 { m_colour
.Set(col
); UpdateColour(); }
56 virtual void UpdateColour() = 0;
58 // the current colour (may be invalid if none)
63 // Styles which must be supported by all controls implementing wxColourPickerWidgetBase
64 // NB: these styles must be defined to carefully-chosen values to
65 // avoid conflicts with wxButton's styles
67 // show the colour in HTML form (#AABBCC) as colour button label
68 // (instead of no label at all)
69 // NOTE: this style is supported just by wxColourButtonGeneric and
70 // thus is not exposed in wxColourPickerCtrl
71 #define wxCLRP_SHOW_LABEL 0x0008
73 // map platform-dependent controls which implement the wxColourPickerWidgetBase
74 // under the name "wxColourPickerWidget".
75 // NOTE: wxColourPickerCtrl allocates a wxColourPickerWidget and relies on the
76 // fact that all classes being mapped as wxColourPickerWidget have the
77 // same prototype for their contructor (and also explains why we use
78 // define instead of a typedef)
79 // since GTK > 2.4, there is GtkColorButton
80 #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
81 #include "wx/gtk/clrpicker.h"
82 #define wxColourPickerWidget wxColourButton
84 #include "wx/generic/clrpickerg.h"
85 #define wxColourPickerWidget wxGenericColourButton
89 // ----------------------------------------------------------------------------
90 // wxColourPickerCtrl: platform-independent class which embeds a
91 // platform-dependent wxColourPickerWidget and, if wxCLRP_USE_TEXTCTRL style is
92 // used, a textctrl next to it.
93 // ----------------------------------------------------------------------------
95 #define wxCLRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
96 #define wxCLRP_DEFAULT_STYLE 0
98 class WXDLLIMPEXP_CORE wxColourPickerCtrl
: public wxPickerBase
101 wxColourPickerCtrl() {}
102 virtual ~wxColourPickerCtrl() {}
105 wxColourPickerCtrl(wxWindow
*parent
, wxWindowID id
,
106 const wxColour
& col
= *wxBLACK
, const wxPoint
& pos
= wxDefaultPosition
,
107 const wxSize
& size
= wxDefaultSize
, long style
= wxCLRP_DEFAULT_STYLE
,
108 const wxValidator
& validator
= wxDefaultValidator
,
109 const wxString
& name
= wxColourPickerCtrlNameStr
)
110 { Create(parent
, id
, col
, pos
, size
, style
, validator
, name
); }
112 bool Create(wxWindow
*parent
, wxWindowID id
,
113 const wxColour
& col
= *wxBLACK
,
114 const wxPoint
& pos
= wxDefaultPosition
,
115 const wxSize
& size
= wxDefaultSize
,
116 long style
= wxCLRP_DEFAULT_STYLE
,
117 const wxValidator
& validator
= wxDefaultValidator
,
118 const wxString
& name
= wxColourPickerCtrlNameStr
);
121 public: // public API
123 // get the colour chosen
124 wxColour
GetColour() const
125 { return ((wxColourPickerWidget
*)m_picker
)->GetColour(); }
127 // set currently displayed color
128 void SetColour(const wxColour
& col
);
130 // set colour using RGB(r,g,b) syntax or considering given text as a colour name;
131 // returns true if the given text was successfully recognized.
132 bool SetColour(const wxString
& text
);
135 public: // internal functions
137 // update the button colour to match the text control contents
138 void UpdatePickerFromTextCtrl();
140 // update the text control to match the button's colour
141 void UpdateTextCtrlFromPicker();
143 // event handler for our picker
144 void OnColourChange(wxColourPickerEvent
&);
147 virtual long GetPickerStyle(long style
) const
148 { return (style
& wxCLRP_SHOW_LABEL
); }
151 DECLARE_DYNAMIC_CLASS(wxColourPickerCtrl
)
155 // ----------------------------------------------------------------------------
156 // wxColourPickerEvent: used by wxColourPickerCtrl only
157 // ----------------------------------------------------------------------------
159 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_COMMAND_COLOURPICKER_CHANGED
, wxColourPickerEvent
);
161 class WXDLLIMPEXP_CORE wxColourPickerEvent
: public wxCommandEvent
164 wxColourPickerEvent() {}
165 wxColourPickerEvent(wxObject
*generator
, int id
, const wxColour
&col
)
166 : wxCommandEvent(wxEVT_COMMAND_COLOURPICKER_CHANGED
, id
),
169 SetEventObject(generator
);
172 wxColour
GetColour() const { return m_colour
; }
173 void SetColour(const wxColour
&c
) { m_colour
= c
; }
176 // default copy ctor, assignment operator and dtor are ok
177 virtual wxEvent
*Clone() const { return new wxColourPickerEvent(*this); }
182 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxColourPickerEvent
)
185 // ----------------------------------------------------------------------------
186 // event types and macros
187 // ----------------------------------------------------------------------------
189 typedef void (wxEvtHandler::*wxColourPickerEventFunction
)(wxColourPickerEvent
&);
191 #define wxColourPickerEventHandler(func) \
192 wxEVENT_HANDLER_CAST(wxColourPickerEventFunction, func)
194 #define EVT_COLOURPICKER_CHANGED(id, fn) \
195 wx__DECLARE_EVT1(wxEVT_COMMAND_COLOURPICKER_CHANGED, id, wxColourPickerEventHandler(fn))
198 #endif // wxUSE_COLOURPICKERCTRL
200 #endif // _WX_CLRPICKER_H_BASE_