]> git.saurik.com Git - wxWidgets.git/blob - include/wx/clrpicker.h
using Run of base class
[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 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_CLRPICKER_H_BASE_
12 #define _WX_CLRPICKER_H_BASE_
13
14 #include "wx/defs.h"
15
16
17 #if wxUSE_COLOURPICKERCTRL
18
19 #include "wx/pickerbase.h"
20
21
22 class WXDLLIMPEXP_FWD_CORE wxColourPickerEvent;
23
24 extern WXDLLIMPEXP_DATA_CORE(const char) wxColourPickerWidgetNameStr[];
25 extern WXDLLIMPEXP_DATA_CORE(const char) wxColourPickerCtrlNameStr[];
26
27 // show the colour in HTML form (#AABBCC) as colour button label
28 #define wxCLRBTN_SHOW_LABEL 100
29
30 // the default style
31 #define wxCLRBTN_DEFAULT_STYLE (wxCLRBTN_SHOW_LABEL)
32
33
34
35 // ----------------------------------------------------------------------------
36 // wxColourPickerWidgetBase: a generic abstract interface which must be
37 // implemented by controls used by wxColourPickerCtrl
38 // ----------------------------------------------------------------------------
39
40 class WXDLLIMPEXP_CORE wxColourPickerWidgetBase
41 {
42 public:
43 wxColourPickerWidgetBase() { m_colour = *wxBLACK; }
44 virtual ~wxColourPickerWidgetBase() {}
45
46 wxColour GetColour() const
47 { return m_colour; }
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(); }
52
53 protected:
54
55 virtual void UpdateColour() = 0;
56
57 // the current colour (may be invalid if none)
58 wxColour m_colour;
59 };
60
61
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
65
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
71
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
82 #else
83 #include "wx/generic/clrpickerg.h"
84 #define wxColourPickerWidget wxGenericColourButton
85 #endif
86
87
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 // ----------------------------------------------------------------------------
93
94 #define wxCLRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
95 #define wxCLRP_DEFAULT_STYLE 0
96
97 class WXDLLIMPEXP_CORE wxColourPickerCtrl : public wxPickerBase
98 {
99 public:
100 wxColourPickerCtrl() {}
101 virtual ~wxColourPickerCtrl() {}
102
103
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); }
110
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);
118
119
120 public: // public API
121
122 // get the colour chosen
123 wxColour GetColour() const
124 { return ((wxColourPickerWidget *)m_picker)->GetColour(); }
125
126 // set currently displayed color
127 void SetColour(const wxColour& col);
128
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);
132
133
134 public: // internal functions
135
136 // update the button colour to match the text control contents
137 void UpdatePickerFromTextCtrl();
138
139 // update the text control to match the button's colour
140 void UpdateTextCtrlFromPicker();
141
142 // event handler for our picker
143 void OnColourChange(wxColourPickerEvent &);
144
145 protected:
146 virtual long GetPickerStyle(long style) const
147 { return (style & wxCLRP_SHOW_LABEL); }
148
149 private:
150 DECLARE_DYNAMIC_CLASS(wxColourPickerCtrl)
151 };
152
153
154 // ----------------------------------------------------------------------------
155 // wxColourPickerEvent: used by wxColourPickerCtrl only
156 // ----------------------------------------------------------------------------
157
158 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COLOURPICKER_CHANGED, wxColourPickerEvent );
159
160 class WXDLLIMPEXP_CORE wxColourPickerEvent : public wxCommandEvent
161 {
162 public:
163 wxColourPickerEvent() {}
164 wxColourPickerEvent(wxObject *generator, int id, const wxColour &col)
165 : wxCommandEvent(wxEVT_COLOURPICKER_CHANGED, id),
166 m_colour(col)
167 {
168 SetEventObject(generator);
169 }
170
171 wxColour GetColour() const { return m_colour; }
172 void SetColour(const wxColour &c) { m_colour = c; }
173
174
175 // default copy ctor, assignment operator and dtor are ok
176 virtual wxEvent *Clone() const { return new wxColourPickerEvent(*this); }
177
178 private:
179 wxColour m_colour;
180
181 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxColourPickerEvent)
182 };
183
184 // ----------------------------------------------------------------------------
185 // event types and macros
186 // ----------------------------------------------------------------------------
187
188 typedef void (wxEvtHandler::*wxColourPickerEventFunction)(wxColourPickerEvent&);
189
190 #define wxColourPickerEventHandler(func) \
191 wxEVENT_HANDLER_CAST(wxColourPickerEventFunction, func)
192
193 #define EVT_COLOURPICKER_CHANGED(id, fn) \
194 wx__DECLARE_EVT1(wxEVT_COLOURPICKER_CHANGED, id, wxColourPickerEventHandler(fn))
195
196
197 // old wxEVT_COMMAND_* constant
198 #define wxEVT_COMMAND_COLOURPICKER_CHANGED wxEVT_COLOURPICKER_CHANGED
199
200 #endif // wxUSE_COLOURPICKERCTRL
201
202 #endif // _WX_CLRPICKER_H_BASE_
203