]> git.saurik.com Git - wxWidgets.git/blob - include/wx/clrpicker.h
Applied Patch #1502801: Missing Clone() functions from some events
[wxWidgets.git] / include / wx / clrpicker.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/clrpicker.h
3 // Purpose: wxColourPickerCtrl base header
4 // Author: Francesco Montorsi (based on Vadim Zeitlin's code)
5 // Modified by:
6 // Created: 14/4/2006
7 // Copyright: (c) Vadim Zeitlin, Francesco Montorsi
8 // RCS-ID: $Id$
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_CLRPICKER_H_BASE_
13 #define _WX_CLRPICKER_H_BASE_
14
15 #include "wx/defs.h"
16
17
18 #if wxUSE_COLOURPICKERCTRL
19
20 #include "wx/pickerbase.h"
21
22
23 class WXDLLIMPEXP_CORE wxColourPickerEvent;
24
25 extern WXDLLEXPORT_DATA(const wxChar) wxColourPickerWidgetNameStr[];
26 extern WXDLLEXPORT_DATA(const wxChar) wxColourPickerCtrlNameStr[];
27
28
29 // ----------------------------------------------------------------------------
30 // wxColourPickerWidgetBase: a generic abstract interface which must be
31 // implemented by controls used by wxColourPickerCtrl
32 // ----------------------------------------------------------------------------
33
34 class WXDLLIMPEXP_CORE wxColourPickerWidgetBase
35 {
36 public:
37 wxColourPickerWidgetBase() { m_colour = *wxBLACK; }
38 virtual ~wxColourPickerWidgetBase() {}
39
40 wxColour GetColour() const
41 { return m_colour; }
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(); }
46
47 protected:
48
49 virtual void UpdateColour() = 0;
50
51 // the current colour (may be invalid if none)
52 wxColour m_colour;
53 };
54
55
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
59
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
65
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 #if defined(__WXGTK24__) // since GTK > 2.4, there is GtkColorButton
73 #include "wx/gtk/clrpicker.h"
74 #define wxColourPickerWidget wxColourButton
75 #else
76 #include "wx/generic/clrpickerg.h"
77 #define wxColourPickerWidget wxGenericColourButton
78 #endif
79
80
81 // ----------------------------------------------------------------------------
82 // wxColourPickerCtrl: platform-independent class which embeds a
83 // platform-dependent wxColourPickerWidget and, if wxCLRP_USE_TEXTCTRL style is
84 // used, a textctrl next to it.
85 // ----------------------------------------------------------------------------
86
87 #define wxCLRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
88 #define wxCLRP_DEFAULT_STYLE 0
89
90 class WXDLLIMPEXP_CORE wxColourPickerCtrl : public wxPickerBase
91 {
92 public:
93 wxColourPickerCtrl() : m_bIgnoreNextTextCtrlUpdate(false) {}
94 virtual ~wxColourPickerCtrl() {}
95
96
97 wxColourPickerCtrl(wxWindow *parent, wxWindowID id,
98 const wxColour& col = *wxBLACK, const wxPoint& pos = wxDefaultPosition,
99 const wxSize& size = wxDefaultSize, long style = wxCLRP_DEFAULT_STYLE,
100 const wxValidator& validator = wxDefaultValidator,
101 const wxString& name = wxColourPickerCtrlNameStr)
102 : m_bIgnoreNextTextCtrlUpdate(false)
103 { Create(parent, id, col, pos, size, style, validator, name); }
104
105 bool Create(wxWindow *parent, wxWindowID id,
106 const wxColour& col = *wxBLACK,
107 const wxPoint& pos = wxDefaultPosition,
108 const wxSize& size = wxDefaultSize,
109 long style = wxCLRP_DEFAULT_STYLE,
110 const wxValidator& validator = wxDefaultValidator,
111 const wxString& name = wxColourPickerCtrlNameStr);
112
113
114 public: // public API
115
116 // get the colour chosen
117 wxColour GetColour() const
118 { return ((wxColourPickerWidget *)m_picker)->GetColour(); }
119
120 // set currently displayed color
121 void SetColour(const wxColour& col);
122
123 // set colour using RGB(r,g,b) syntax or considering given text as a colour name;
124 // returns true if the given text was successfully recognized.
125 bool SetColour(const wxString& text);
126
127
128 public: // internal functions
129
130 // update the button colour to match the text control contents
131 void UpdatePickerFromTextCtrl();
132
133 // update the text control to match the button's colour
134 void UpdateTextCtrlFromPicker();
135
136 // event handler for our picker
137 void OnColourChange(wxColourPickerEvent &);
138
139 protected:
140 virtual long GetPickerStyle(long style) const
141 { return (style & wxCLRP_SHOW_LABEL); }
142
143 // true if the next UpdateTextCtrl() call is to ignore
144 bool m_bIgnoreNextTextCtrlUpdate;
145
146 private:
147 DECLARE_DYNAMIC_CLASS(wxColourPickerCtrl)
148 };
149
150
151 // ----------------------------------------------------------------------------
152 // wxColourPickerEvent: used by wxColourPickerCtrl only
153 // ----------------------------------------------------------------------------
154
155 BEGIN_DECLARE_EVENT_TYPES()
156 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, wxEVT_COMMAND_COLOURPICKER_CHANGED, 1102)
157 END_DECLARE_EVENT_TYPES()
158
159 class WXDLLIMPEXP_CORE wxColourPickerEvent : public wxCommandEvent
160 {
161 public:
162 wxColourPickerEvent() {}
163 wxColourPickerEvent(wxObject *generator, int id, const wxColour &col)
164 : wxCommandEvent(wxEVT_COMMAND_COLOURPICKER_CHANGED, id),
165 m_colour(col)
166 {
167 SetEventObject(generator);
168 }
169
170 wxColour GetColour() const { return m_colour; }
171 void SetColour(const wxColour &c) { m_colour = c; }
172
173
174 // default copy ctor, assignment operator and dtor are ok
175 virtual wxEvent *Clone() const { return new wxColourPickerEvent(*this); }
176
177 private:
178 wxColour m_colour;
179
180 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxColourPickerEvent)
181 };
182
183 // ----------------------------------------------------------------------------
184 // event types and macros
185 // ----------------------------------------------------------------------------
186
187 typedef void (wxEvtHandler::*wxColourPickerEventFunction)(wxColourPickerEvent&);
188
189 #define wxColourPickerEventHandler(func) \
190 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxColourPickerEventFunction, &func)
191
192 #define EVT_COLOURPICKER_CHANGED(id, fn) \
193 wx__DECLARE_EVT1(wxEVT_COMMAND_COLOURPICKER_CHANGED, id, wxColourPickerEventHandler(fn))
194
195 #ifdef _WX_DEFINE_DATE_EVENTS_
196 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COLOURPICKER_CHANGED)
197
198 IMPLEMENT_DYNAMIC_CLASS(wxColourPickerEvent, wxCommandEvent)
199 #endif
200
201
202
203 #endif // wxUSE_COLOURPICKERCTRL
204
205 #endif // _WX_CLRPICKER_H_BASE_
206