]> git.saurik.com Git - wxWidgets.git/blame - include/wx/clrpicker.h
Deallocate wxThreadSpecificInfo when wxThread ends.
[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
ec376c8f
VZ
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
ec376c8f
VZ
19#include "wx/pickerbase.h"
20
21
b5dbe15d 22class WXDLLIMPEXP_FWD_CORE wxColourPickerEvent;
ec376c8f 23
53a2db12
FM
24extern WXDLLIMPEXP_DATA_CORE(const char) wxColourPickerWidgetNameStr[];
25extern WXDLLIMPEXP_DATA_CORE(const char) wxColourPickerCtrlNameStr[];
ec376c8f 26
ff654490
VZ
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
ec376c8f
VZ
34
35// ----------------------------------------------------------------------------
36// wxColourPickerWidgetBase: a generic abstract interface which must be
37// implemented by controls used by wxColourPickerCtrl
38// ----------------------------------------------------------------------------
39
40class WXDLLIMPEXP_CORE wxColourPickerWidgetBase
41{
42public:
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
53protected:
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)
82540105 78// since GTK > 2.4, there is GtkColorButton
ff654490 79#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
ec376c8f
VZ
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
556151f5 94#define wxCLRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
ec376c8f
VZ
95#define wxCLRP_DEFAULT_STYLE 0
96
97class WXDLLIMPEXP_CORE wxColourPickerCtrl : public wxPickerBase
98{
99public:
44b72116 100 wxColourPickerCtrl() {}
ec376c8f
VZ
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)
ec376c8f
VZ
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
120public: // 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
134public: // 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
c757b5fe 145protected:
ec376c8f
VZ
146 virtual long GetPickerStyle(long style) const
147 { return (style & wxCLRP_SHOW_LABEL); }
148
ec376c8f
VZ
149private:
150 DECLARE_DYNAMIC_CLASS(wxColourPickerCtrl)
151};
152
153
154// ----------------------------------------------------------------------------
155// wxColourPickerEvent: used by wxColourPickerCtrl only
156// ----------------------------------------------------------------------------
157
ce7fe42e 158wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COLOURPICKER_CHANGED, wxColourPickerEvent );
ec376c8f
VZ
159
160class WXDLLIMPEXP_CORE wxColourPickerEvent : public wxCommandEvent
161{
162public:
163 wxColourPickerEvent() {}
164 wxColourPickerEvent(wxObject *generator, int id, const wxColour &col)
ce7fe42e 165 : wxCommandEvent(wxEVT_COLOURPICKER_CHANGED, id),
ec376c8f
VZ
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
258b2ca6
RD
174
175 // default copy ctor, assignment operator and dtor are ok
176 virtual wxEvent *Clone() const { return new wxColourPickerEvent(*this); }
177
ec376c8f
VZ
178private:
179 wxColour m_colour;
180
258b2ca6 181 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxColourPickerEvent)
ec376c8f
VZ
182};
183
184// ----------------------------------------------------------------------------
185// event types and macros
186// ----------------------------------------------------------------------------
187
188typedef void (wxEvtHandler::*wxColourPickerEventFunction)(wxColourPickerEvent&);
189
190#define wxColourPickerEventHandler(func) \
3c778901 191 wxEVENT_HANDLER_CAST(wxColourPickerEventFunction, func)
ec376c8f
VZ
192
193#define EVT_COLOURPICKER_CHANGED(id, fn) \
ce7fe42e 194 wx__DECLARE_EVT1(wxEVT_COLOURPICKER_CHANGED, id, wxColourPickerEventHandler(fn))
ec376c8f 195
ec376c8f 196
ce7fe42e
VZ
197// old wxEVT_COMMAND_* constant
198#define wxEVT_COMMAND_COLOURPICKER_CHANGED wxEVT_COLOURPICKER_CHANGED
199
ec376c8f
VZ
200#endif // wxUSE_COLOURPICKERCTRL
201
202#endif // _WX_CLRPICKER_H_BASE_
203