]> git.saurik.com Git - wxWidgets.git/blob - include/wx/colour.h
derive wxColourBase from wxObject on msw as well
[wxWidgets.git] / include / wx / colour.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/colour.h
3 // Purpose: wxColourBase definition
4 // Author: Julian Smart
5 // Modified by: Francesco Montorsi
6 // Created:
7 // RCS-ID: $Id$
8 // Copyright: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_COLOUR_H_BASE_
13 #define _WX_COLOUR_H_BASE_
14
15 #include "wx/defs.h"
16 #include "wx/gdiobj.h"
17
18
19 class WXDLLIMPEXP_FWD_CORE wxColour;
20
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
24 // constructors
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); }
33
34
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
39
40
41 const unsigned char wxALPHA_TRANSPARENT = 0;
42 const unsigned char wxALPHA_OPAQUE = 0xff;
43
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
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 #if defined( __WXMAC__ ) || defined( __WXMSW__ )
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
70 {
71 public:
72 // type of a single colour component
73 typedef unsigned char ChannelType;
74
75 wxColourBase() {}
76 virtual ~wxColourBase() {}
77
78
79 // Set() functions
80 // ---------------
81
82 void Set(ChannelType red,
83 ChannelType green,
84 ChannelType blue,
85 ChannelType alpha = wxALPHA_OPAQUE)
86 { InitRGBA(red,green,blue, alpha); }
87
88 // implemented in colourcmn.cpp
89 bool Set(const wxString &str)
90 { return FromString(str); }
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
96 Set((ChannelType)(0xFF & colRGB),
97 (ChannelType)(0xFF & (colRGB >> 8)),
98 (ChannelType)(0xFF & (colRGB >> 16)));
99 }
100
101
102
103 // accessors
104 // ---------
105
106 virtual ChannelType Red() const = 0;
107 virtual ChannelType Green() const = 0;
108 virtual ChannelType Blue() const = 0;
109 virtual ChannelType Alpha() const
110 { return wxALPHA_OPAQUE ; }
111
112 // implemented in colourcmn.cpp
113 virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const;
114
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
122
123 // old, deprecated
124 // ---------------
125
126 #if WXWIN_COMPATIBILITY_2_6
127 wxDEPRECATED( static wxColour CreateByName(const wxString& name) );
128 wxDEPRECATED( void InitFromName(const wxString& col) );
129 #endif
130
131 protected:
132 virtual void
133 InitRGBA(ChannelType r, ChannelType g, ChannelType b, ChannelType a) = 0;
134
135 virtual bool FromString(const wxString& s);
136
137 #if wxCOLOUR_IS_GDIOBJECT
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 }
154 #endif
155 };
156
157
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
163
164 #if defined(__WXPALMOS__)
165 #include "wx/generic/colour.h"
166 #elif defined(__WXMSW__)
167 #include "wx/msw/colour.h"
168 #elif defined(__WXMOTIF__)
169 #include "wx/motif/colour.h"
170 #elif defined(__WXGTK20__)
171 #include "wx/gtk/colour.h"
172 #elif defined(__WXGTK__)
173 #include "wx/gtk1/colour.h"
174 #elif defined(__WXMGL__)
175 #include "wx/generic/colour.h"
176 #elif defined(__WXDFB__)
177 #include "wx/generic/colour.h"
178 #elif defined(__WXX11__)
179 #include "wx/x11/colour.h"
180 #elif defined(__WXMAC__)
181 #include "wx/mac/colour.h"
182 #elif defined(__WXCOCOA__)
183 #include "wx/cocoa/colour.h"
184 #elif defined(__WXPM__)
185 #include "wx/os2/colour.h"
186 #endif
187
188 #define wxColor wxColour
189
190 #endif // _WX_COLOUR_H_BASE_