]> git.saurik.com Git - wxWidgets.git/blame - include/wx/clrpicker.h
Build fix for OW regarding & operator needing full class specs.
[wxWidgets.git] / include / wx / clrpicker.h
CommitLineData
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
20#include "wx/control.h"
21#include "wx/pickerbase.h"
22
23
24class WXDLLIMPEXP_CORE wxColourPickerEvent;
25
26extern WXDLLEXPORT_DATA(const wxChar) wxColourPickerWidgetNameStr[];
27extern WXDLLEXPORT_DATA(const wxChar) wxColourPickerCtrlNameStr[];
28
29
30// ----------------------------------------------------------------------------
31// wxColourPickerWidgetBase: a generic abstract interface which must be
32// implemented by controls used by wxColourPickerCtrl
33// ----------------------------------------------------------------------------
34
35class WXDLLIMPEXP_CORE wxColourPickerWidgetBase
36{
37public:
38 wxColourPickerWidgetBase() { m_colour = *wxBLACK; }
39 virtual ~wxColourPickerWidgetBase() {}
40
41 wxColour GetColour() const
42 { return m_colour; }
43 virtual void SetColour(const wxColour &col)
44 { m_colour = col; UpdateColour(); }
45 virtual void SetColour(const wxString &col)
46 { m_colour.Set(col); UpdateColour(); }
47
48protected:
49
50 virtual void UpdateColour() = 0;
51
52 // the current colour (may be invalid if none)
53 wxColour m_colour;
54};
55
56
57// Styles which must be supported by all controls implementing wxColourPickerWidgetBase
58// NB: these styles must be defined to carefully-chosen values to
59// avoid conflicts with wxButton's styles
60
61// show the colour in HTML form (#AABBCC) as colour button label
62// (instead of no label at all)
63// NOTE: this style is supported just by wxColourButtonGeneric and
64// thus is not exposed in wxColourPickerCtrl
65#define wxCLRP_SHOW_LABEL 0x0008
66
67// map platform-dependent controls which implement the wxColourPickerWidgetBase
68// under the name "wxColourPickerWidget".
69// NOTE: wxColourPickerCtrl allocates a wxColourPickerWidget and relies on the
70// fact that all classes being mapped as wxColourPickerWidget have the
71// same prototype for their contructor (and also explains why we use
72// define instead of a typedef)
73#if defined(__WXGTK24__) // since GTK > 2.4, there is GtkColorButton
74 #include "wx/gtk/clrpicker.h"
75 #define wxColourPickerWidget wxColourButton
76#else
77 #include "wx/generic/clrpickerg.h"
78 #define wxColourPickerWidget wxGenericColourButton
79#endif
80
81
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// ----------------------------------------------------------------------------
87
88#define wxCLRP_USE_TEXTCTRL wxPB_USE_TEXTCTRL
89#define wxCLRP_DEFAULT_STYLE 0
90
91class WXDLLIMPEXP_CORE wxColourPickerCtrl : public wxPickerBase
92{
93public:
94 wxColourPickerCtrl() : m_bIgnoreNextTextCtrlUpdate(false) {}
95 virtual ~wxColourPickerCtrl() {}
96
97
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); }
105
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);
113
114
115public: // public API
116
117 // get the colour chosen
118 wxColour GetColour() const
119 { return ((wxColourPickerWidget *)m_picker)->GetColour(); }
120
121 // set currently displayed color
122 void SetColour(const wxColour& col);
123
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);
127
128
129public: // internal functions
130
131 // update the button colour to match the text control contents
132 void UpdatePickerFromTextCtrl();
133
134 // update the text control to match the button's colour
135 void UpdateTextCtrlFromPicker();
136
137 // event handler for our picker
138 void OnColourChange(wxColourPickerEvent &);
139
140 virtual long GetPickerStyle(long style) const
141 { return (style & wxCLRP_SHOW_LABEL); }
142
143protected:
144
145 // true if the next UpdateTextCtrl() call is to ignore
146 bool m_bIgnoreNextTextCtrlUpdate;
147
148private:
149 DECLARE_DYNAMIC_CLASS(wxColourPickerCtrl)
150};
151
152
153// ----------------------------------------------------------------------------
154// wxColourPickerEvent: used by wxColourPickerCtrl only
155// ----------------------------------------------------------------------------
156
157BEGIN_DECLARE_EVENT_TYPES()
158 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, wxEVT_COMMAND_COLOURPICKER_CHANGED, 1102)
159END_DECLARE_EVENT_TYPES()
160
161class WXDLLIMPEXP_CORE wxColourPickerEvent : public wxCommandEvent
162{
163public:
164 wxColourPickerEvent() {}
165 wxColourPickerEvent(wxObject *generator, int id, const wxColour &col)
166 : wxCommandEvent(wxEVT_COMMAND_COLOURPICKER_CHANGED, id),
167 m_colour(col)
168 {
169 SetEventObject(generator);
170 }
171
172 wxColour GetColour() const { return m_colour; }
173 void SetColour(const wxColour &c) { m_colour = c; }
174
175private:
176 wxColour m_colour;
177
178 DECLARE_DYNAMIC_CLASS_NO_COPY(wxColourPickerEvent)
179};
180
181// ----------------------------------------------------------------------------
182// event types and macros
183// ----------------------------------------------------------------------------
184
185typedef void (wxEvtHandler::*wxColourPickerEventFunction)(wxColourPickerEvent&);
186
187#define wxColourPickerEventHandler(func) \
188 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxColourPickerEventFunction, &func)
189
190#define EVT_COLOURPICKER_CHANGED(id, fn) \
191 wx__DECLARE_EVT1(wxEVT_COMMAND_COLOURPICKER_CHANGED, id, wxColourPickerEventHandler(fn))
192
193#ifdef _WX_DEFINE_DATE_EVENTS_
194 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COLOURPICKER_CHANGED)
195
196 IMPLEMENT_DYNAMIC_CLASS(wxColourPickerEvent, wxCommandEvent)
197#endif
198
199
200
201#endif // wxUSE_COLOURPICKERCTRL
202
203#endif // _WX_CLRPICKER_H_BASE_
204