]> git.saurik.com Git - wxWidgets.git/blob - include/wx/colour.h
wxMimeTypesManagerImpl and wxFileTypeImpl are in base, not core
[wxWidgets.git] / include / wx / colour.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/colour.h
3 // Purpose: wxColourBase definition
4 // Author: Julian Smart
5 // Modified by: Francesco Montorsi
6 // Created:
7 // RCS-ID: $Id$
8 // Copyright: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_COLOUR_H_BASE_
13 #define _WX_COLOUR_H_BASE_
14
15 #include "wx/defs.h"
16 #include "wx/gdiobj.h"
17
18
19 class WXDLLIMPEXP_FWD_CORE wxColour;
20
21 // A macro to define the standard wxColour constructors:
22 //
23 // It avoids the need to repeat these lines across all colour.h files, since
24 // Set() is a virtual function and thus cannot be called by wxColourBase ctors
25 #define DEFINE_STD_WXCOLOUR_CONSTRUCTORS \
26 wxColour() { Init(); } \
27 wxColour(ChannelType red, \
28 ChannelType green, \
29 ChannelType blue, \
30 ChannelType alpha = wxALPHA_OPAQUE) \
31 { Init(); Set(red, green, blue, alpha); } \
32 wxColour(unsigned long colRGB) { Init(); Set(colRGB ); } \
33 wxColour(const wxString& colourName) { Init(); Set(colourName); } \
34 wxColour(const char *colourName) { Init(); Set(colourName); } \
35 wxColour(const wchar_t *colourName) { Init(); Set(colourName); }
36
37
38 // flags for wxColour -> wxString conversion (see wxColour::GetAsString)
39 #define wxC2S_NAME 1 // return colour name, when possible
40 #define wxC2S_CSS_SYNTAX 2 // return colour in rgb(r,g,b) syntax
41 #define wxC2S_HTML_SYNTAX 4 // return colour in #rrggbb syntax
42
43
44 const unsigned char wxALPHA_TRANSPARENT = 0;
45 const unsigned char wxALPHA_OPAQUE = 0xff;
46
47 // ----------------------------------------------------------------------------
48 // wxVariant support
49 // ----------------------------------------------------------------------------
50
51 #if wxUSE_VARIANT
52 #include "wx/variant.h"
53 DECLARE_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLIMPEXP_CORE)
54 #endif
55
56 //-----------------------------------------------------------------------------
57 // wxColourBase: this class has no data members, just some functions to avoid
58 // code redundancy in all native wxColour implementations
59 //-----------------------------------------------------------------------------
60
61 /* Transition from wxGDIObject to wxObject is incomplete. If your port does
62 not need the wxGDIObject machinery to handle colors, please add it to the
63 list of ports which do not need it.
64 */
65 #if defined( __WXMAC__ ) || defined( __WXMSW__ ) || defined( __WXPM__ ) || defined( __WXCOCOA__ )
66 #define wxCOLOUR_IS_GDIOBJECT 0
67 #else
68 #define wxCOLOUR_IS_GDIOBJECT 1
69 #endif
70
71 class WXDLLIMPEXP_CORE wxColourBase : public
72 #if wxCOLOUR_IS_GDIOBJECT
73 wxGDIObject
74 #else
75 wxObject
76 #endif
77 {
78 public:
79 // type of a single colour component
80 typedef unsigned char ChannelType;
81
82 wxColourBase() {}
83 virtual ~wxColourBase() {}
84
85
86 // Set() functions
87 // ---------------
88
89 void Set(ChannelType red,
90 ChannelType green,
91 ChannelType blue,
92 ChannelType alpha = wxALPHA_OPAQUE)
93 { InitRGBA(red,green,blue, alpha); }
94
95 // implemented in colourcmn.cpp
96 bool Set(const wxString &str)
97 { return FromString(str); }
98
99 void Set(unsigned long colRGB)
100 {
101 // we don't need to know sizeof(long) here because we assume that the three
102 // least significant bytes contain the R, G and B values
103 Set((ChannelType)(0xFF & colRGB),
104 (ChannelType)(0xFF & (colRGB >> 8)),
105 (ChannelType)(0xFF & (colRGB >> 16)));
106 }
107
108
109
110 // accessors
111 // ---------
112
113 virtual ChannelType Red() const = 0;
114 virtual ChannelType Green() const = 0;
115 virtual ChannelType Blue() const = 0;
116 virtual ChannelType Alpha() const
117 { return wxALPHA_OPAQUE ; }
118
119 // implemented in colourcmn.cpp
120 virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const;
121
122 #if !wxCOLOUR_IS_GDIOBJECT
123 virtual bool IsOk() const= 0;
124
125 // older version, for backwards compatibility only (but not deprecated
126 // because it's still widely used)
127 bool Ok() const { return IsOk(); }
128 #endif
129
130 // old, deprecated
131 // ---------------
132
133 #if WXWIN_COMPATIBILITY_2_6
134 wxDEPRECATED( static wxColour CreateByName(const wxString& name) );
135 wxDEPRECATED( void InitFromName(const wxString& col) );
136 #endif
137
138 protected:
139 // Some ports need Init() and while we don't, provide a stub so that the
140 // ports which don't need it are not forced to define it
141 void Init() { }
142
143 virtual void
144 InitRGBA(ChannelType r, ChannelType g, ChannelType b, ChannelType a) = 0;
145
146 virtual bool FromString(const wxString& s);
147
148 #if wxCOLOUR_IS_GDIOBJECT
149 // wxColour doesn't use reference counted data (at least not in all ports)
150 // so provide stubs for the functions which need to be defined if we do use
151 // them
152 virtual wxGDIRefData *CreateGDIRefData() const
153 {
154 wxFAIL_MSG( "must be overridden if used" );
155
156 return NULL;
157 }
158
159 virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *WXUNUSED(data)) const
160 {
161 wxFAIL_MSG( "must be overridden if used" );
162
163 return NULL;
164 }
165 #endif
166 };
167
168
169 // wxColour <-> wxString utilities, used by wxConfig, defined in colourcmn.cpp
170 WXDLLIMPEXP_CORE wxString wxToString(const wxColourBase& col);
171 WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxColourBase* col);
172
173
174
175 #if defined(__WXPALMOS__)
176 #include "wx/generic/colour.h"
177 #elif defined(__WXMSW__)
178 #include "wx/msw/colour.h"
179 #elif defined(__WXMOTIF__)
180 #include "wx/motif/colour.h"
181 #elif defined(__WXGTK20__)
182 #include "wx/gtk/colour.h"
183 #elif defined(__WXGTK__)
184 #include "wx/gtk1/colour.h"
185 #elif defined(__WXMGL__)
186 #include "wx/generic/colour.h"
187 #elif defined(__WXDFB__)
188 #include "wx/generic/colour.h"
189 #elif defined(__WXX11__)
190 #include "wx/x11/colour.h"
191 #elif defined(__WXMAC__)
192 #include "wx/mac/colour.h"
193 #elif defined(__WXCOCOA__)
194 #include "wx/cocoa/colour.h"
195 #elif defined(__WXPM__)
196 #include "wx/os2/colour.h"
197 #endif
198
199 #define wxColor wxColour
200
201 #endif // _WX_COLOUR_H_BASE_