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