]> git.saurik.com Git - wxWidgets.git/blame - include/wx/colour.h
removed wxSTRING_TEXT() macro in favour of wxS()
[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"
53DECLARE_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLEXPORT)
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
6bf7d10b 61#if defined( __WXMAC__ ) || defined( __WXMSW__ )
c5ad4777
SC
62#define wxCOLOUR_IS_GDIOBJECT 0
63#else
64#define wxCOLOUR_IS_GDIOBJECT 1
65#endif
66
67class WXDLLEXPORT wxColourBase : public
68#if wxCOLOUR_IS_GDIOBJECT
69 wxGDIObject
70#else
71 wxObject
72#endif
40989e46 73{
40989e46 74public:
aea95b1c
VZ
75 // type of a single colour component
76 typedef unsigned char ChannelType;
77
40989e46
WS
78 wxColourBase() {}
79 virtual ~wxColourBase() {}
80
81
82 // Set() functions
83 // ---------------
84
aea95b1c
VZ
85 void Set(ChannelType red,
86 ChannelType green,
87 ChannelType blue,
88 ChannelType alpha = wxALPHA_OPAQUE)
89 { InitRGBA(red,green,blue, alpha); }
40989e46
WS
90
91 // implemented in colourcmn.cpp
40989e46 92 bool Set(const wxString &str)
aea95b1c 93 { return FromString(str); }
40989e46
WS
94
95 void Set(unsigned long colRGB)
96 {
97 // we don't need to know sizeof(long) here because we assume that the three
98 // least significant bytes contain the R, G and B values
8936f975
VZ
99 Set((ChannelType)(0xFF & colRGB),
100 (ChannelType)(0xFF & (colRGB >> 8)),
101 (ChannelType)(0xFF & (colRGB >> 16)));
40989e46
WS
102 }
103
104
105
106 // accessors
107 // ---------
108
aea95b1c
VZ
109 virtual ChannelType Red() const = 0;
110 virtual ChannelType Green() const = 0;
111 virtual ChannelType Blue() const = 0;
112 virtual ChannelType Alpha() const
a69aabc3 113 { return wxALPHA_OPAQUE ; }
40989e46
WS
114
115 // implemented in colourcmn.cpp
116 virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const;
117
c5ad4777
SC
118#if !wxCOLOUR_IS_GDIOBJECT
119 virtual bool IsOk() const= 0;
120
121 // older version, for backwards compatibility only (but not deprecated
122 // because it's still widely used)
123 bool Ok() const { return IsOk(); }
124#endif
40989e46
WS
125
126 // old, deprecated
127 // ---------------
128
7d01c54d
WS
129#if WXWIN_COMPATIBILITY_2_6
130 wxDEPRECATED( static wxColour CreateByName(const wxString& name) );
131 wxDEPRECATED( void InitFromName(const wxString& col) );
132#endif
aea95b1c
VZ
133
134protected:
9ef6890f
VZ
135 // Some ports need Init() and while we don't, provide a stub so that the
136 // ports which don't need it are not forced to define it
137 void Init() { }
138
aea95b1c
VZ
139 virtual void
140 InitRGBA(ChannelType r, ChannelType g, ChannelType b, ChannelType a) = 0;
141
e86d4e59 142 virtual bool FromString(const wxString& s);
8f884a0d 143
c5ad4777 144#if wxCOLOUR_IS_GDIOBJECT
8f884a0d
VZ
145 // wxColour doesn't use reference counted data (at least not in all ports)
146 // so provide stubs for the functions which need to be defined if we do use
147 // them
148 virtual wxGDIRefData *CreateGDIRefData() const
149 {
150 wxFAIL_MSG( "must be overridden if used" );
151
152 return NULL;
153 }
154
155 virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *WXUNUSED(data)) const
156 {
157 wxFAIL_MSG( "must be overridden if used" );
158
159 return NULL;
160 }
c5ad4777 161#endif
40989e46
WS
162};
163
164
8b51786f
VZ
165// wxColour <-> wxString utilities, used by wxConfig, defined in colourcmn.cpp
166WXDLLIMPEXP_CORE wxString wxToString(const wxColourBase& col);
167WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxColourBase* col);
168
169
e45689df 170
4055ed82 171#if defined(__WXPALMOS__)
aea95b1c 172 #include "wx/generic/colour.h"
ffecfa5a 173#elif defined(__WXMSW__)
aea95b1c 174 #include "wx/msw/colour.h"
34138703 175#elif defined(__WXMOTIF__)
aea95b1c 176 #include "wx/motif/colour.h"
1be7a35c 177#elif defined(__WXGTK20__)
aea95b1c 178 #include "wx/gtk/colour.h"
1be7a35c 179#elif defined(__WXGTK__)
aea95b1c 180 #include "wx/gtk1/colour.h"
1e6feb95 181#elif defined(__WXMGL__)
aea95b1c 182 #include "wx/generic/colour.h"
b3c86150 183#elif defined(__WXDFB__)
aea95b1c 184 #include "wx/generic/colour.h"
83df96d6 185#elif defined(__WXX11__)
aea95b1c 186 #include "wx/x11/colour.h"
34138703 187#elif defined(__WXMAC__)
aea95b1c 188 #include "wx/mac/colour.h"
e64df9bc 189#elif defined(__WXCOCOA__)
aea95b1c 190 #include "wx/cocoa/colour.h"
1777b9bb 191#elif defined(__WXPM__)
aea95b1c 192 #include "wx/os2/colour.h"
34138703
JS
193#endif
194
e4a81a2e
VZ
195#define wxColor wxColour
196
aea95b1c 197#endif // _WX_COLOUR_H_BASE_