]>
Commit | Line | Data |
---|---|---|
a24aff65 | 1 | ///////////////////////////////////////////////////////////////////////////// |
edc536d3 | 2 | // Name: wx/cocoa/colour.h |
a24aff65 | 3 | // Purpose: wxColour class |
683b185d | 4 | // Author: David Elliott |
a24aff65 | 5 | // Modified by: |
683b185d | 6 | // Created: 2003/06/17 |
a24aff65 | 7 | // RCS-ID: $Id$ |
683b185d | 8 | // Copyright: (c) 2003 David Elliott |
65571936 | 9 | // Licence: wxWindows licence |
a24aff65 DE |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
683b185d DE |
12 | #ifndef __WX_COCOA_COLOUR_H__ |
13 | #define __WX_COCOA_COLOUR_H__ | |
a24aff65 DE |
14 | |
15 | #include "wx/object.h" | |
16 | #include "wx/string.h" | |
17 | ||
683b185d DE |
18 | // ======================================================================== |
19 | // wxColour | |
20 | // ======================================================================== | |
a24aff65 DE |
21 | class WXDLLEXPORT wxColour: public wxObject |
22 | { | |
23 | public: | |
edc536d3 WS |
24 | // constructors |
25 | // ------------ | |
26 | ||
27 | // default | |
211436b6 VZ |
28 | wxColour() { Init(); } |
29 | ||
edc536d3 | 30 | // from separate RGB |
683b185d DE |
31 | wxColour( unsigned char red, unsigned char green, unsigned char blue ) |
32 | : m_cocoaNSColor(NULL) | |
33 | { Set(red,green,blue); } | |
edc536d3 WS |
34 | |
35 | // from packed RGB | |
683b185d DE |
36 | wxColour( unsigned long colRGB ) |
37 | : m_cocoaNSColor(NULL) | |
38 | { Set(colRGB); } | |
aad6765c | 39 | |
d8fdd58f DE |
40 | // initialization using existing NSColor |
41 | wxColour( WX_NSColor aColor ); | |
42 | ||
a24aff65 | 43 | // implicit conversion from the colour name |
683b185d | 44 | wxColour( const wxString &colourName ) |
683b185d DE |
45 | { InitFromName(colourName); } |
46 | wxColour( const char *colourName ) | |
683b185d | 47 | { InitFromName(wxString::FromAscii(colourName)); } |
c58ae5f2 RN |
48 | #if wxUSE_UNICODE |
49 | wxColour( const wxChar *colourName ) { InitFromName( wxString(colourName) ); } | |
50 | #endif | |
a24aff65 DE |
51 | |
52 | // copy ctors and assignment operators | |
683b185d DE |
53 | wxColour( const wxColour& col ); |
54 | wxColour& operator = ( const wxColour& col ); | |
a24aff65 | 55 | |
211436b6 | 56 | virtual ~wxColour(); |
a24aff65 | 57 | |
683b185d DE |
58 | // accessors |
59 | bool Ok() const { return m_cocoaNSColor; } | |
211436b6 | 60 | WX_NSColor GetNSColor() { return m_cocoaNSColor; } |
a24aff65 | 61 | |
683b185d DE |
62 | unsigned char Red() const { return m_red; } |
63 | unsigned char Green() const { return m_green; } | |
64 | unsigned char Blue() const { return m_blue; } | |
a24aff65 | 65 | |
683b185d DE |
66 | // comparison |
67 | bool operator == (const wxColour& colour) const | |
68 | { | |
d8fdd58f | 69 | // TODO: Really compare the NSColor |
aad6765c | 70 | return (m_cocoaNSColor == colour.m_cocoaNSColor |
d8fdd58f | 71 | || (m_red == colour.m_red |
aad6765c | 72 | && m_green == colour.m_green |
d8fdd58f | 73 | && m_blue == colour.m_blue)); |
683b185d DE |
74 | } |
75 | bool operator != (const wxColour& colour) const | |
76 | { return !(*this == colour); } | |
a24aff65 | 77 | |
683b185d DE |
78 | // Set() functions |
79 | void Set( unsigned char red, unsigned char green, unsigned char blue ); | |
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 | } | |
d8fdd58f | 88 | void Set( WX_NSColor aColor ); |
a24aff65 | 89 | |
211436b6 VZ |
90 | protected: |
91 | // puts the object in an invalid, uninitialized state | |
92 | void Init(); | |
93 | ||
94 | // create the object from name, leaves it uninitialized if it failed | |
683b185d | 95 | void InitFromName(const wxString& col); |
a24aff65 DE |
96 | |
97 | private: | |
683b185d DE |
98 | WX_NSColor m_cocoaNSColor; |
99 | unsigned char m_red; | |
100 | unsigned char m_green; | |
101 | unsigned char m_blue; | |
211436b6 VZ |
102 | |
103 | DECLARE_DYNAMIC_CLASS(wxColour) | |
a24aff65 DE |
104 | }; |
105 | ||
683b185d | 106 | #endif // __WX_COCOA_COLOUR_H__ |