1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxColourBase definition
4 // Author: Julian Smart
5 // Modified by: Francesco Montorsi
8 // Copyright: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_COLOUR_H_BASE_
13 #define _WX_COLOUR_H_BASE_
16 #include "wx/gdiobj.h"
19 class WXDLLIMPEXP_FWD_CORE wxColour
;
21 // the standard wxColour constructors;
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
25 #define DEFINE_STD_WXCOLOUR_CONSTRUCTORS \
26 wxColour( ChannelType red, ChannelType green, ChannelType blue, \
27 ChannelType alpha = wxALPHA_OPAQUE ) \
28 { Set(red, green, blue, alpha); } \
29 wxColour( unsigned long colRGB ) { Set(colRGB); } \
30 wxColour(const wxString& colourName) { Set(colourName); } \
31 wxColour(const char *colourName) { Set(colourName); } \
32 wxColour(const wchar_t *colourName) { Set(colourName); }
35 // flags for wxColour -> wxString conversion (see wxColour::GetAsString)
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
41 const unsigned char wxALPHA_TRANSPARENT
= 0;
42 const unsigned char wxALPHA_OPAQUE
= 0xff;
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
49 #include "wx/variant.h"
50 DECLARE_VARIANT_OBJECT_EXPORTED(wxColour
,WXDLLEXPORT
)
53 //-----------------------------------------------------------------------------
54 // wxColourBase: this class has no data members, just some functions to avoid
55 // code redundancy in all native wxColour implementations
56 //-----------------------------------------------------------------------------
58 class WXDLLEXPORT wxColourBase
: public wxGDIObject
61 // type of a single colour component
62 typedef unsigned char ChannelType
;
65 virtual ~wxColourBase() {}
71 void Set(ChannelType red
,
74 ChannelType alpha
= wxALPHA_OPAQUE
)
75 { InitRGBA(red
,green
,blue
, alpha
); }
77 // implemented in colourcmn.cpp
78 bool Set(const wxString
&str
)
79 { return FromString(str
); }
81 void Set(unsigned long colRGB
)
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
85 Set((ChannelType
)(0xFF & colRGB
),
86 (ChannelType
)(0xFF & (colRGB
>> 8)),
87 (ChannelType
)(0xFF & (colRGB
>> 16)));
95 virtual bool Ok() const { return IsOk(); }
96 virtual bool IsOk() const = 0;
98 virtual ChannelType
Red() const = 0;
99 virtual ChannelType
Green() const = 0;
100 virtual ChannelType
Blue() const = 0;
101 virtual ChannelType
Alpha() const
102 { return wxALPHA_OPAQUE
; }
104 // implemented in colourcmn.cpp
105 virtual wxString
GetAsString(long flags
= wxC2S_NAME
| wxC2S_CSS_SYNTAX
) const;
112 #if WXWIN_COMPATIBILITY_2_6
113 wxDEPRECATED( static wxColour
CreateByName(const wxString
& name
) );
114 wxDEPRECATED( void InitFromName(const wxString
& col
) );
119 InitRGBA(ChannelType r
, ChannelType g
, ChannelType b
, ChannelType a
) = 0;
121 virtual bool FromString(const wxString
& s
);
125 // wxColour <-> wxString utilities, used by wxConfig, defined in colourcmn.cpp
126 WXDLLIMPEXP_CORE wxString
wxToString(const wxColourBase
& col
);
127 WXDLLIMPEXP_CORE
bool wxFromString(const wxString
& str
, wxColourBase
* col
);
131 #if defined(__WXPALMOS__)
132 #include "wx/generic/colour.h"
133 #elif defined(__WXMSW__)
134 #include "wx/msw/colour.h"
135 #elif defined(__WXMOTIF__)
136 #include "wx/motif/colour.h"
137 #elif defined(__WXGTK20__)
138 #include "wx/gtk/colour.h"
139 #elif defined(__WXGTK__)
140 #include "wx/gtk1/colour.h"
141 #elif defined(__WXMGL__)
142 #include "wx/generic/colour.h"
143 #elif defined(__WXDFB__)
144 #include "wx/generic/colour.h"
145 #elif defined(__WXX11__)
146 #include "wx/x11/colour.h"
147 #elif defined(__WXMAC__)
148 #include "wx/mac/colour.h"
149 #elif defined(__WXCOCOA__)
150 #include "wx/cocoa/colour.h"
151 #elif defined(__WXPM__)
152 #include "wx/os2/colour.h"
155 #define wxColor wxColour
157 #endif // _WX_COLOUR_H_BASE_