]> git.saurik.com Git - wxWidgets.git/blame - include/wx/colour.h
wxDateTime timezone functions now dynamic (no caching).
[wxWidgets.git] / include / wx / colour.h
CommitLineData
99d80019
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/colour.h
40989e46 3// Purpose: wxColourBase definition
99d80019 4// Author: Julian Smart
40989e46 5// Modified by: Francesco Montorsi
99d80019
JS
6// Created:
7// RCS-ID: $Id$
8// Copyright: Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_COLOUR_H_BASE_
13#define _WX_COLOUR_H_BASE_
14
e45689df 15#include "wx/defs.h"
40989e46
WS
16#include "wx/gdiobj.h"
17
18
b5dbe15d 19class WXDLLIMPEXP_FWD_CORE wxColour;
6f5d7825 20
9ef6890f
VZ
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
3d4424f7 25#define DEFINE_STD_WXCOLOUR_CONSTRUCTORS \
9ef6890f
VZ
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); }
40989e46
WS
36
37
7d01c54d 38// flags for wxColour -> wxString conversion (see wxColour::GetAsString)
40989e46
WS
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
a69aabc3
SC
44const unsigned char wxALPHA_TRANSPARENT = 0;
45const unsigned char wxALPHA_OPAQUE = 0xff;
40989e46 46
6f5d7825
RR
47// ----------------------------------------------------------------------------
48// wxVariant support
49// ----------------------------------------------------------------------------
50
51#if wxUSE_VARIANT
52#include "wx/variant.h"
53a2db12 53DECLARE_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLIMPEXP_CORE)
6f5d7825
RR
54#endif
55
40989e46
WS
56//-----------------------------------------------------------------------------
57// wxColourBase: this class has no data members, just some functions to avoid
58// code redundancy in all native wxColour implementations
59//-----------------------------------------------------------------------------
60
7234425b
DE
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__ )
c5ad4777
SC
66#define wxCOLOUR_IS_GDIOBJECT 0
67#else
68#define wxCOLOUR_IS_GDIOBJECT 1
69#endif
70
53a2db12 71class WXDLLIMPEXP_CORE wxColourBase : public
c5ad4777
SC
72#if wxCOLOUR_IS_GDIOBJECT
73 wxGDIObject
74#else
75 wxObject
76#endif
40989e46 77{
40989e46 78public:
aea95b1c
VZ
79 // type of a single colour component
80 typedef unsigned char ChannelType;
81
40989e46
WS
82 wxColourBase() {}
83 virtual ~wxColourBase() {}
84
85
86 // Set() functions
87 // ---------------
88
aea95b1c
VZ
89 void Set(ChannelType red,
90 ChannelType green,
91 ChannelType blue,
92 ChannelType alpha = wxALPHA_OPAQUE)
b0edecea 93 { InitRGBA(red, green, blue, alpha); }
40989e46
WS
94
95 // implemented in colourcmn.cpp
40989e46 96 bool Set(const wxString &str)
aea95b1c 97 { return FromString(str); }
40989e46
WS
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
8936f975
VZ
103 Set((ChannelType)(0xFF & colRGB),
104 (ChannelType)(0xFF & (colRGB >> 8)),
105 (ChannelType)(0xFF & (colRGB >> 16)));
40989e46
WS
106 }
107
108
109
110 // accessors
111 // ---------
112
aea95b1c
VZ
113 virtual ChannelType Red() const = 0;
114 virtual ChannelType Green() const = 0;
115 virtual ChannelType Blue() const = 0;
116 virtual ChannelType Alpha() const
a69aabc3 117 { return wxALPHA_OPAQUE ; }
40989e46
WS
118
119 // implemented in colourcmn.cpp
120 virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const;
121
b0edecea
VZ
122 void SetRGB(wxUint32 colRGB)
123 {
124 Set((ChannelType)(0xFF & colRGB),
125 (ChannelType)(0xFF & (colRGB >> 8)),
126 (ChannelType)(0xFF & (colRGB >> 16)));
127 }
128
129 void SetRGBA(wxUint32 colRGBA)
130 {
131 Set((ChannelType)(0xFF & colRGBA),
132 (ChannelType)(0xFF & (colRGBA >> 8)),
133 (ChannelType)(0xFF & (colRGBA >> 16)),
134 (ChannelType)(0xFF & (colRGBA >> 24)));
135 }
136
137 wxUint32 GetRGB() const
138 { return Red() | (Green() << 8) | (Blue() << 16); }
139
140 wxUint32 GetRGBA() const
141 { return Red() | (Green() << 8) | (Blue() << 16) | (Alpha() << 24); }
142
c5ad4777
SC
143#if !wxCOLOUR_IS_GDIOBJECT
144 virtual bool IsOk() const= 0;
53a2db12 145
c5ad4777
SC
146 // older version, for backwards compatibility only (but not deprecated
147 // because it's still widely used)
148 bool Ok() const { return IsOk(); }
149#endif
40989e46
WS
150
151 // old, deprecated
152 // ---------------
153
7d01c54d
WS
154#if WXWIN_COMPATIBILITY_2_6
155 wxDEPRECATED( static wxColour CreateByName(const wxString& name) );
156 wxDEPRECATED( void InitFromName(const wxString& col) );
157#endif
aea95b1c
VZ
158
159protected:
9ef6890f
VZ
160 // Some ports need Init() and while we don't, provide a stub so that the
161 // ports which don't need it are not forced to define it
162 void Init() { }
163
aea95b1c
VZ
164 virtual void
165 InitRGBA(ChannelType r, ChannelType g, ChannelType b, ChannelType a) = 0;
166
e86d4e59 167 virtual bool FromString(const wxString& s);
8f884a0d 168
c5ad4777 169#if wxCOLOUR_IS_GDIOBJECT
8f884a0d
VZ
170 // wxColour doesn't use reference counted data (at least not in all ports)
171 // so provide stubs for the functions which need to be defined if we do use
172 // them
173 virtual wxGDIRefData *CreateGDIRefData() const
174 {
175 wxFAIL_MSG( "must be overridden if used" );
176
177 return NULL;
178 }
179
180 virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *WXUNUSED(data)) const
181 {
182 wxFAIL_MSG( "must be overridden if used" );
183
184 return NULL;
185 }
c5ad4777 186#endif
40989e46
WS
187};
188
189
8b51786f
VZ
190// wxColour <-> wxString utilities, used by wxConfig, defined in colourcmn.cpp
191WXDLLIMPEXP_CORE wxString wxToString(const wxColourBase& col);
192WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxColourBase* col);
193
194
e45689df 195
4055ed82 196#if defined(__WXPALMOS__)
aea95b1c 197 #include "wx/generic/colour.h"
ffecfa5a 198#elif defined(__WXMSW__)
aea95b1c 199 #include "wx/msw/colour.h"
34138703 200#elif defined(__WXMOTIF__)
aea95b1c 201 #include "wx/motif/colour.h"
1be7a35c 202#elif defined(__WXGTK20__)
aea95b1c 203 #include "wx/gtk/colour.h"
1be7a35c 204#elif defined(__WXGTK__)
aea95b1c 205 #include "wx/gtk1/colour.h"
1e6feb95 206#elif defined(__WXMGL__)
aea95b1c 207 #include "wx/generic/colour.h"
b3c86150 208#elif defined(__WXDFB__)
aea95b1c 209 #include "wx/generic/colour.h"
83df96d6 210#elif defined(__WXX11__)
aea95b1c 211 #include "wx/x11/colour.h"
34138703 212#elif defined(__WXMAC__)
ef0e9220 213 #include "wx/osx/colour.h"
e64df9bc 214#elif defined(__WXCOCOA__)
aea95b1c 215 #include "wx/cocoa/colour.h"
1777b9bb 216#elif defined(__WXPM__)
aea95b1c 217 #include "wx/os2/colour.h"
34138703
JS
218#endif
219
e4a81a2e
VZ
220#define wxColor wxColour
221
aea95b1c 222#endif // _WX_COLOUR_H_BASE_