]>
Commit | Line | Data |
---|---|---|
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 | // the standard wxColour constructors; | |
20 | // this macro avoids to repeat these lines across all colour.h files, since | |
21 | // Set() is a virtual function and thus cannot be called by wxColourBase | |
22 | // constructors | |
23 | #define DEFINE_STD_WXCOLOUR_CONSTRUCTORS \ | |
24 | wxColour( unsigned char red, unsigned char green, unsigned char blue, \ | |
25 | unsigned char alpha = wxALPHA_OPAQUE ) \ | |
26 | { Set(red, green, blue, alpha); } \ | |
27 | wxColour( unsigned long colRGB ) { Set(colRGB); } \ | |
28 | wxColour(const wxString &colourName) { Set(colourName); } \ | |
29 | wxColour(const wxChar *colourName) { Set(colourName); } | |
30 | ||
31 | ||
32 | // flags for wxColour -> wxString conversion (see wxColour::GetAsString) | |
33 | #define wxC2S_NAME 1 // return colour name, when possible | |
34 | #define wxC2S_CSS_SYNTAX 2 // return colour in rgb(r,g,b) syntax | |
35 | #define wxC2S_HTML_SYNTAX 4 // return colour in #rrggbb syntax | |
36 | ||
37 | ||
38 | class WXDLLEXPORT wxColour; | |
39 | ||
40 | const unsigned char wxALPHA_TRANSPARENT = 0; | |
41 | const unsigned char wxALPHA_OPAQUE = 0xff; | |
42 | ||
43 | //----------------------------------------------------------------------------- | |
44 | // wxColourBase: this class has no data members, just some functions to avoid | |
45 | // code redundancy in all native wxColour implementations | |
46 | //----------------------------------------------------------------------------- | |
47 | ||
48 | class WXDLLEXPORT wxColourBase : public wxGDIObject | |
49 | { | |
50 | protected: | |
51 | ||
52 | virtual void InitWith(unsigned char red, unsigned char green, unsigned char blue) = 0; | |
53 | ||
54 | // this will be overridden in alpha supporting classes | |
55 | virtual void InitWith(unsigned char red, unsigned char green, unsigned char blue, unsigned char WXUNUSED(alpha)) | |
56 | { | |
57 | InitWith( red, green, blue ) ; | |
58 | } | |
59 | ||
60 | virtual bool FromString(const wxChar *); | |
61 | ||
62 | public: | |
63 | wxColourBase() {} | |
64 | virtual ~wxColourBase() {} | |
65 | ||
66 | ||
67 | // Set() functions | |
68 | // --------------- | |
69 | ||
70 | void Set(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = wxALPHA_OPAQUE) | |
71 | { InitWith(red,green,blue, alpha); } | |
72 | ||
73 | // implemented in colourcmn.cpp | |
74 | bool Set(const wxChar *str) | |
75 | { return FromString(str); } | |
76 | ||
77 | bool Set(const wxString &str) | |
78 | { return Set((const wxChar *)str); } | |
79 | ||
80 | void Set(unsigned long colRGB) | |
81 | { | |
82 | // we don't need to know sizeof(long) here because we assume that the three | |
83 | // least significant bytes contain the R, G and B values | |
84 | Set((unsigned char)colRGB, | |
85 | (unsigned char)(colRGB >> 8), | |
86 | (unsigned char)(colRGB >> 16)); | |
87 | } | |
88 | ||
89 | ||
90 | ||
91 | // accessors | |
92 | // --------- | |
93 | ||
94 | virtual bool Ok() const = 0; | |
95 | ||
96 | virtual unsigned char Red() const = 0; | |
97 | virtual unsigned char Green() const = 0; | |
98 | virtual unsigned char Blue() const = 0; | |
99 | virtual unsigned char Alpha() const | |
100 | { return wxALPHA_OPAQUE ; } | |
101 | ||
102 | // implemented in colourcmn.cpp | |
103 | virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const; | |
104 | ||
105 | ||
106 | ||
107 | // old, deprecated | |
108 | // --------------- | |
109 | ||
110 | #if WXWIN_COMPATIBILITY_2_6 | |
111 | wxDEPRECATED( static wxColour CreateByName(const wxString& name) ); | |
112 | wxDEPRECATED( void InitFromName(const wxString& col) ); | |
113 | #endif | |
114 | }; | |
115 | ||
116 | ||
117 | ||
118 | #if defined(__WXPALMOS__) | |
119 | #include "wx/generic/colour.h" | |
120 | #elif defined(__WXMSW__) | |
121 | #include "wx/msw/colour.h" | |
122 | #elif defined(__WXMOTIF__) | |
123 | #include "wx/motif/colour.h" | |
124 | #elif defined(__WXGTK20__) | |
125 | #include "wx/gtk/colour.h" | |
126 | #elif defined(__WXGTK__) | |
127 | #include "wx/gtk1/colour.h" | |
128 | #elif defined(__WXMGL__) | |
129 | #include "wx/generic/colour.h" | |
130 | #elif defined(__WXDFB__) | |
131 | #include "wx/generic/colour.h" | |
132 | #elif defined(__WXX11__) | |
133 | #include "wx/x11/colour.h" | |
134 | #elif defined(__WXMAC__) | |
135 | #include "wx/mac/colour.h" | |
136 | #elif defined(__WXCOCOA__) | |
137 | #include "wx/cocoa/colour.h" | |
138 | #elif defined(__WXPM__) | |
139 | #include "wx/os2/colour.h" | |
140 | #endif | |
141 | ||
142 | #define wxColor wxColour | |
143 | ||
144 | #endif | |
145 | // _WX_COLOUR_H_BASE_ |