]>
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 | ||
6f5d7825 RR |
19 | class WXDLLEXPORT wxColour; |
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); } \ | |
30 | wxColour(const wxString &colourName) { Set(colourName); } \ | |
40989e46 WS |
31 | wxColour(const wxChar *colourName) { Set(colourName); } |
32 | ||
33 | ||
7d01c54d | 34 | // flags for wxColour -> wxString conversion (see wxColour::GetAsString) |
40989e46 WS |
35 | #define wxC2S_NAME 1 // return colour name, when possible |
36 | #define wxC2S_CSS_SYNTAX 2 // return colour in rgb(r,g,b) syntax | |
37 | #define wxC2S_HTML_SYNTAX 4 // return colour in #rrggbb syntax | |
38 | ||
39 | ||
a69aabc3 SC |
40 | const unsigned char wxALPHA_TRANSPARENT = 0; |
41 | const unsigned char wxALPHA_OPAQUE = 0xff; | |
40989e46 | 42 | |
6f5d7825 RR |
43 | // ---------------------------------------------------------------------------- |
44 | // wxVariant support | |
45 | // ---------------------------------------------------------------------------- | |
46 | ||
47 | #if wxUSE_VARIANT | |
48 | #include "wx/variant.h" | |
49 | DECLARE_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLEXPORT) | |
50 | #endif | |
51 | ||
40989e46 WS |
52 | //----------------------------------------------------------------------------- |
53 | // wxColourBase: this class has no data members, just some functions to avoid | |
54 | // code redundancy in all native wxColour implementations | |
55 | //----------------------------------------------------------------------------- | |
56 | ||
57 | class WXDLLEXPORT wxColourBase : public wxGDIObject | |
58 | { | |
40989e46 | 59 | public: |
aea95b1c VZ |
60 | // type of a single colour component |
61 | typedef unsigned char ChannelType; | |
62 | ||
40989e46 WS |
63 | wxColourBase() {} |
64 | virtual ~wxColourBase() {} | |
65 | ||
66 | ||
67 | // Set() functions | |
68 | // --------------- | |
69 | ||
aea95b1c VZ |
70 | void Set(ChannelType red, |
71 | ChannelType green, | |
72 | ChannelType blue, | |
73 | ChannelType alpha = wxALPHA_OPAQUE) | |
74 | { InitRGBA(red,green,blue, alpha); } | |
40989e46 WS |
75 | |
76 | // implemented in colourcmn.cpp | |
77 | bool Set(const wxChar *str) | |
78 | { return FromString(str); } | |
79 | ||
80 | bool Set(const wxString &str) | |
aea95b1c | 81 | { return FromString(str); } |
40989e46 WS |
82 | |
83 | void Set(unsigned long colRGB) | |
84 | { | |
85 | // we don't need to know sizeof(long) here because we assume that the three | |
86 | // least significant bytes contain the R, G and B values | |
aea95b1c VZ |
87 | Set((ChannelType)colRGB, |
88 | (ChannelType)(colRGB >> 8), | |
89 | (ChannelType)(colRGB >> 16)); | |
40989e46 WS |
90 | } |
91 | ||
92 | ||
93 | ||
94 | // accessors | |
95 | // --------- | |
96 | ||
b7cacb43 VZ |
97 | virtual bool Ok() const { return IsOk(); } |
98 | virtual bool IsOk() const = 0; | |
40989e46 | 99 | |
aea95b1c VZ |
100 | virtual ChannelType Red() const = 0; |
101 | virtual ChannelType Green() const = 0; | |
102 | virtual ChannelType Blue() const = 0; | |
103 | virtual ChannelType Alpha() const | |
a69aabc3 | 104 | { return wxALPHA_OPAQUE ; } |
40989e46 WS |
105 | |
106 | // implemented in colourcmn.cpp | |
107 | virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const; | |
108 | ||
109 | ||
110 | ||
111 | // old, deprecated | |
112 | // --------------- | |
113 | ||
7d01c54d WS |
114 | #if WXWIN_COMPATIBILITY_2_6 |
115 | wxDEPRECATED( static wxColour CreateByName(const wxString& name) ); | |
116 | wxDEPRECATED( void InitFromName(const wxString& col) ); | |
117 | #endif | |
aea95b1c VZ |
118 | |
119 | protected: | |
120 | virtual void | |
121 | InitRGBA(ChannelType r, ChannelType g, ChannelType b, ChannelType a) = 0; | |
122 | ||
123 | virtual bool FromString(const wxChar *s); | |
40989e46 WS |
124 | }; |
125 | ||
126 | ||
e45689df | 127 | |
4055ed82 | 128 | #if defined(__WXPALMOS__) |
aea95b1c | 129 | #include "wx/generic/colour.h" |
ffecfa5a | 130 | #elif defined(__WXMSW__) |
aea95b1c | 131 | #include "wx/msw/colour.h" |
34138703 | 132 | #elif defined(__WXMOTIF__) |
aea95b1c | 133 | #include "wx/motif/colour.h" |
1be7a35c | 134 | #elif defined(__WXGTK20__) |
aea95b1c | 135 | #include "wx/gtk/colour.h" |
1be7a35c | 136 | #elif defined(__WXGTK__) |
aea95b1c | 137 | #include "wx/gtk1/colour.h" |
1e6feb95 | 138 | #elif defined(__WXMGL__) |
aea95b1c | 139 | #include "wx/generic/colour.h" |
b3c86150 | 140 | #elif defined(__WXDFB__) |
aea95b1c | 141 | #include "wx/generic/colour.h" |
83df96d6 | 142 | #elif defined(__WXX11__) |
aea95b1c | 143 | #include "wx/x11/colour.h" |
34138703 | 144 | #elif defined(__WXMAC__) |
aea95b1c | 145 | #include "wx/mac/colour.h" |
e64df9bc | 146 | #elif defined(__WXCOCOA__) |
aea95b1c | 147 | #include "wx/cocoa/colour.h" |
1777b9bb | 148 | #elif defined(__WXPM__) |
aea95b1c | 149 | #include "wx/os2/colour.h" |
34138703 JS |
150 | #endif |
151 | ||
e4a81a2e VZ |
152 | #define wxColor wxColour |
153 | ||
aea95b1c | 154 | #endif // _WX_COLOUR_H_BASE_ |