]>
Commit | Line | Data |
---|---|---|
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 | 19 | class WXDLLIMPEXP_FWD_CORE wxColour; |
6f5d7825 | 20 | |
7d01c54d | 21 | // the standard wxColour constructors; |
40989e46 WS |
22 | // this macro avoids to repeat these lines across all colour.h files, since |
23 | // Set() is a virtual function and thus cannot be called by wxColourBase | |
24 | // constructors | |
3d4424f7 | 25 | #define DEFINE_STD_WXCOLOUR_CONSTRUCTORS \ |
aea95b1c VZ |
26 | wxColour( ChannelType red, ChannelType green, ChannelType blue, \ |
27 | ChannelType alpha = wxALPHA_OPAQUE ) \ | |
3d4424f7 VS |
28 | { Set(red, green, blue, alpha); } \ |
29 | wxColour( unsigned long colRGB ) { Set(colRGB); } \ | |
ccfc7127 VS |
30 | wxColour(const wxString& colourName) { Set(colourName); } \ |
31 | wxColour(const char *colourName) { Set(colourName); } \ | |
32 | wxColour(const wchar_t *colourName) { Set(colourName); } | |
40989e46 WS |
33 | |
34 | ||
7d01c54d | 35 | // flags for wxColour -> wxString conversion (see wxColour::GetAsString) |
40989e46 WS |
36 | #define wxC2S_NAME 1 // return colour name, when possible |
37 | #define wxC2S_CSS_SYNTAX 2 // return colour in rgb(r,g,b) syntax | |
38 | #define wxC2S_HTML_SYNTAX 4 // return colour in #rrggbb syntax | |
39 | ||
40 | ||
a69aabc3 SC |
41 | const unsigned char wxALPHA_TRANSPARENT = 0; |
42 | const unsigned char wxALPHA_OPAQUE = 0xff; | |
40989e46 | 43 | |
6f5d7825 RR |
44 | // ---------------------------------------------------------------------------- |
45 | // wxVariant support | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
48 | #if wxUSE_VARIANT | |
49 | #include "wx/variant.h" | |
50 | DECLARE_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLEXPORT) | |
51 | #endif | |
52 | ||
40989e46 WS |
53 | //----------------------------------------------------------------------------- |
54 | // wxColourBase: this class has no data members, just some functions to avoid | |
55 | // code redundancy in all native wxColour implementations | |
56 | //----------------------------------------------------------------------------- | |
57 | ||
6bf7d10b | 58 | #if defined( __WXMAC__ ) || defined( __WXMSW__ ) |
c5ad4777 SC |
59 | #define wxCOLOUR_IS_GDIOBJECT 0 |
60 | #else | |
61 | #define wxCOLOUR_IS_GDIOBJECT 1 | |
62 | #endif | |
63 | ||
64 | class WXDLLEXPORT wxColourBase : public | |
65 | #if wxCOLOUR_IS_GDIOBJECT | |
66 | wxGDIObject | |
67 | #else | |
68 | wxObject | |
69 | #endif | |
40989e46 | 70 | { |
40989e46 | 71 | public: |
aea95b1c VZ |
72 | // type of a single colour component |
73 | typedef unsigned char ChannelType; | |
74 | ||
40989e46 WS |
75 | wxColourBase() {} |
76 | virtual ~wxColourBase() {} | |
77 | ||
78 | ||
79 | // Set() functions | |
80 | // --------------- | |
81 | ||
aea95b1c VZ |
82 | void Set(ChannelType red, |
83 | ChannelType green, | |
84 | ChannelType blue, | |
85 | ChannelType alpha = wxALPHA_OPAQUE) | |
86 | { InitRGBA(red,green,blue, alpha); } | |
40989e46 WS |
87 | |
88 | // implemented in colourcmn.cpp | |
40989e46 | 89 | bool Set(const wxString &str) |
aea95b1c | 90 | { return FromString(str); } |
40989e46 WS |
91 | |
92 | void Set(unsigned long colRGB) | |
93 | { | |
94 | // we don't need to know sizeof(long) here because we assume that the three | |
95 | // least significant bytes contain the R, G and B values | |
8936f975 VZ |
96 | Set((ChannelType)(0xFF & colRGB), |
97 | (ChannelType)(0xFF & (colRGB >> 8)), | |
98 | (ChannelType)(0xFF & (colRGB >> 16))); | |
40989e46 WS |
99 | } |
100 | ||
101 | ||
102 | ||
103 | // accessors | |
104 | // --------- | |
105 | ||
aea95b1c VZ |
106 | virtual ChannelType Red() const = 0; |
107 | virtual ChannelType Green() const = 0; | |
108 | virtual ChannelType Blue() const = 0; | |
109 | virtual ChannelType Alpha() const | |
a69aabc3 | 110 | { return wxALPHA_OPAQUE ; } |
40989e46 WS |
111 | |
112 | // implemented in colourcmn.cpp | |
113 | virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const; | |
114 | ||
c5ad4777 SC |
115 | #if !wxCOLOUR_IS_GDIOBJECT |
116 | virtual bool IsOk() const= 0; | |
117 | ||
118 | // older version, for backwards compatibility only (but not deprecated | |
119 | // because it's still widely used) | |
120 | bool Ok() const { return IsOk(); } | |
121 | #endif | |
40989e46 WS |
122 | |
123 | // old, deprecated | |
124 | // --------------- | |
125 | ||
7d01c54d WS |
126 | #if WXWIN_COMPATIBILITY_2_6 |
127 | wxDEPRECATED( static wxColour CreateByName(const wxString& name) ); | |
128 | wxDEPRECATED( void InitFromName(const wxString& col) ); | |
129 | #endif | |
aea95b1c VZ |
130 | |
131 | protected: | |
132 | virtual void | |
133 | InitRGBA(ChannelType r, ChannelType g, ChannelType b, ChannelType a) = 0; | |
134 | ||
e86d4e59 | 135 | virtual bool FromString(const wxString& s); |
8f884a0d | 136 | |
c5ad4777 | 137 | #if wxCOLOUR_IS_GDIOBJECT |
8f884a0d VZ |
138 | // wxColour doesn't use reference counted data (at least not in all ports) |
139 | // so provide stubs for the functions which need to be defined if we do use | |
140 | // them | |
141 | virtual wxGDIRefData *CreateGDIRefData() const | |
142 | { | |
143 | wxFAIL_MSG( "must be overridden if used" ); | |
144 | ||
145 | return NULL; | |
146 | } | |
147 | ||
148 | virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *WXUNUSED(data)) const | |
149 | { | |
150 | wxFAIL_MSG( "must be overridden if used" ); | |
151 | ||
152 | return NULL; | |
153 | } | |
c5ad4777 | 154 | #endif |
40989e46 WS |
155 | }; |
156 | ||
157 | ||
8b51786f VZ |
158 | // wxColour <-> wxString utilities, used by wxConfig, defined in colourcmn.cpp |
159 | WXDLLIMPEXP_CORE wxString wxToString(const wxColourBase& col); | |
160 | WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxColourBase* col); | |
161 | ||
162 | ||
e45689df | 163 | |
4055ed82 | 164 | #if defined(__WXPALMOS__) |
aea95b1c | 165 | #include "wx/generic/colour.h" |
ffecfa5a | 166 | #elif defined(__WXMSW__) |
aea95b1c | 167 | #include "wx/msw/colour.h" |
34138703 | 168 | #elif defined(__WXMOTIF__) |
aea95b1c | 169 | #include "wx/motif/colour.h" |
1be7a35c | 170 | #elif defined(__WXGTK20__) |
aea95b1c | 171 | #include "wx/gtk/colour.h" |
1be7a35c | 172 | #elif defined(__WXGTK__) |
aea95b1c | 173 | #include "wx/gtk1/colour.h" |
1e6feb95 | 174 | #elif defined(__WXMGL__) |
aea95b1c | 175 | #include "wx/generic/colour.h" |
b3c86150 | 176 | #elif defined(__WXDFB__) |
aea95b1c | 177 | #include "wx/generic/colour.h" |
83df96d6 | 178 | #elif defined(__WXX11__) |
aea95b1c | 179 | #include "wx/x11/colour.h" |
34138703 | 180 | #elif defined(__WXMAC__) |
aea95b1c | 181 | #include "wx/mac/colour.h" |
e64df9bc | 182 | #elif defined(__WXCOCOA__) |
aea95b1c | 183 | #include "wx/cocoa/colour.h" |
1777b9bb | 184 | #elif defined(__WXPM__) |
aea95b1c | 185 | #include "wx/os2/colour.h" |
34138703 JS |
186 | #endif |
187 | ||
e4a81a2e VZ |
188 | #define wxColor wxColour |
189 | ||
aea95b1c | 190 | #endif // _WX_COLOUR_H_BASE_ |