]>
Commit | Line | Data |
---|---|---|
ec376c8f VZ |
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 | ||
ec376c8f VZ |
20 | #include "wx/pickerbase.h" |
21 | ||
22 | ||
b5dbe15d | 23 | class WXDLLIMPEXP_FWD_CORE wxColourPickerEvent; |
ec376c8f | 24 | |
f36e602b VZ |
25 | extern WXDLLEXPORT_DATA(const char) wxColourPickerWidgetNameStr[]; |
26 | extern WXDLLEXPORT_DATA(const char) wxColourPickerCtrlNameStr[]; | |
ec376c8f | 27 | |
ff654490 VZ |
28 | // show the colour in HTML form (#AABBCC) as colour button label |
29 | #define wxCLRBTN_SHOW_LABEL 100 | |
30 | ||
31 | // the default style | |
32 | #define wxCLRBTN_DEFAULT_STYLE (wxCLRBTN_SHOW_LABEL) | |
33 | ||
34 | ||
ec376c8f VZ |
35 | |
36 | // ---------------------------------------------------------------------------- | |
37 | // wxColourPickerWidgetBase: a generic abstract interface which must be | |
38 | // implemented by controls used by wxColourPickerCtrl | |
39 | // ---------------------------------------------------------------------------- | |
40 | ||
41 | class WXDLLIMPEXP_CORE wxColourPickerWidgetBase | |
42 | { | |
43 | public: | |
44 | wxColourPickerWidgetBase() { m_colour = *wxBLACK; } | |
45 | virtual ~wxColourPickerWidgetBase() {} | |
46 | ||
47 | wxColour GetColour() const | |
48 | { return m_colour; } | |
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(); } | |
53 | ||
54 | protected: | |
55 | ||
56 | virtual void UpdateColour() = 0; | |
57 | ||
58 | // the current colour (may be invalid if none) | |
59 | wxColour m_colour; | |
60 | }; | |
61 | ||
62 | ||
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 | |
66 | ||
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 | |
72 | ||
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) | |
82540105 | 79 | // since GTK > 2.4, there is GtkColorButton |
ff654490 | 80 | #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__) |
ec376c8f VZ |
81 | #include "wx/gtk/clrpicker.h" |
82 | #define wxColourPickerWidget wxColourButton | |
83 | #else | |
84 | #include "wx/generic/clrpickerg.h" | |
85 | #define wxColourPickerWidget wxGenericColourButton | |
86 | #endif | |
87 | ||
88 | ||
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 | // ---------------------------------------------------------------------------- | |
94 | ||
556151f5 | 95 | #define wxCLRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL) |
ec376c8f VZ |
96 | #define wxCLRP_DEFAULT_STYLE 0 |
97 | ||
98 | class WXDLLIMPEXP_CORE wxColourPickerCtrl : public wxPickerBase | |
99 | { | |
100 | public: | |
101 | wxColourPickerCtrl() : m_bIgnoreNextTextCtrlUpdate(false) {} | |
102 | virtual ~wxColourPickerCtrl() {} | |
103 | ||
104 | ||
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 | : m_bIgnoreNextTextCtrlUpdate(false) | |
111 | { Create(parent, id, col, pos, size, style, validator, name); } | |
112 | ||
113 | bool Create(wxWindow *parent, wxWindowID id, | |
114 | const wxColour& col = *wxBLACK, | |
115 | const wxPoint& pos = wxDefaultPosition, | |
116 | const wxSize& size = wxDefaultSize, | |
117 | long style = wxCLRP_DEFAULT_STYLE, | |
118 | const wxValidator& validator = wxDefaultValidator, | |
119 | const wxString& name = wxColourPickerCtrlNameStr); | |
120 | ||
121 | ||
122 | public: // public API | |
123 | ||
124 | // get the colour chosen | |
125 | wxColour GetColour() const | |
126 | { return ((wxColourPickerWidget *)m_picker)->GetColour(); } | |
127 | ||
128 | // set currently displayed color | |
129 | void SetColour(const wxColour& col); | |
130 | ||
131 | // set colour using RGB(r,g,b) syntax or considering given text as a colour name; | |
132 | // returns true if the given text was successfully recognized. | |
133 | bool SetColour(const wxString& text); | |
134 | ||
135 | ||
136 | public: // internal functions | |
137 | ||
138 | // update the button colour to match the text control contents | |
139 | void UpdatePickerFromTextCtrl(); | |
140 | ||
141 | // update the text control to match the button's colour | |
142 | void UpdateTextCtrlFromPicker(); | |
143 | ||
144 | // event handler for our picker | |
145 | void OnColourChange(wxColourPickerEvent &); | |
146 | ||
c757b5fe | 147 | protected: |
ec376c8f VZ |
148 | virtual long GetPickerStyle(long style) const |
149 | { return (style & wxCLRP_SHOW_LABEL); } | |
150 | ||
ec376c8f VZ |
151 | // true if the next UpdateTextCtrl() call is to ignore |
152 | bool m_bIgnoreNextTextCtrlUpdate; | |
153 | ||
154 | private: | |
155 | DECLARE_DYNAMIC_CLASS(wxColourPickerCtrl) | |
156 | }; | |
157 | ||
158 | ||
159 | // ---------------------------------------------------------------------------- | |
160 | // wxColourPickerEvent: used by wxColourPickerCtrl only | |
161 | // ---------------------------------------------------------------------------- | |
162 | ||
163 | BEGIN_DECLARE_EVENT_TYPES() | |
164 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, wxEVT_COMMAND_COLOURPICKER_CHANGED, 1102) | |
165 | END_DECLARE_EVENT_TYPES() | |
166 | ||
167 | class WXDLLIMPEXP_CORE wxColourPickerEvent : public wxCommandEvent | |
168 | { | |
169 | public: | |
170 | wxColourPickerEvent() {} | |
171 | wxColourPickerEvent(wxObject *generator, int id, const wxColour &col) | |
172 | : wxCommandEvent(wxEVT_COMMAND_COLOURPICKER_CHANGED, id), | |
173 | m_colour(col) | |
174 | { | |
175 | SetEventObject(generator); | |
176 | } | |
177 | ||
178 | wxColour GetColour() const { return m_colour; } | |
179 | void SetColour(const wxColour &c) { m_colour = c; } | |
180 | ||
258b2ca6 RD |
181 | |
182 | // default copy ctor, assignment operator and dtor are ok | |
183 | virtual wxEvent *Clone() const { return new wxColourPickerEvent(*this); } | |
184 | ||
ec376c8f VZ |
185 | private: |
186 | wxColour m_colour; | |
187 | ||
258b2ca6 | 188 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxColourPickerEvent) |
ec376c8f VZ |
189 | }; |
190 | ||
191 | // ---------------------------------------------------------------------------- | |
192 | // event types and macros | |
193 | // ---------------------------------------------------------------------------- | |
194 | ||
195 | typedef void (wxEvtHandler::*wxColourPickerEventFunction)(wxColourPickerEvent&); | |
196 | ||
197 | #define wxColourPickerEventHandler(func) \ | |
198 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxColourPickerEventFunction, &func) | |
199 | ||
200 | #define EVT_COLOURPICKER_CHANGED(id, fn) \ | |
201 | wx__DECLARE_EVT1(wxEVT_COMMAND_COLOURPICKER_CHANGED, id, wxColourPickerEventHandler(fn)) | |
202 | ||
ec376c8f VZ |
203 | |
204 | #endif // wxUSE_COLOURPICKERCTRL | |
205 | ||
206 | #endif // _WX_CLRPICKER_H_BASE_ | |
207 |