Added GetNSColor() accessor
[wxWidgets.git] / include / wx / cocoa / colour.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: colour.h
3 // Purpose: wxColour class
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2003/06/17
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __WX_COCOA_COLOUR_H__
13 #define __WX_COCOA_COLOUR_H__
14
15 #include "wx/object.h"
16 #include "wx/string.h"
17
18 // ========================================================================
19 // wxColour
20 // ========================================================================
21 class WXDLLEXPORT wxColour: public wxObject
22 {
23 public:
24 DECLARE_DYNAMIC_CLASS(wxColour)
25 // ------------------------------------------------------------------------
26 // initialization
27 // ------------------------------------------------------------------------
28 wxColour();
29 // from RGB
30 wxColour( unsigned char red, unsigned char green, unsigned char blue )
31 : m_cocoaNSColor(NULL)
32 { Set(red,green,blue); }
33 wxColour( unsigned long colRGB )
34 : m_cocoaNSColor(NULL)
35 { Set(colRGB); }
36
37 // implicit conversion from the colour name
38 wxColour( const wxString &colourName )
39 : m_cocoaNSColor(NULL)
40 { InitFromName(colourName); }
41 wxColour( const char *colourName )
42 : m_cocoaNSColor(NULL)
43 { InitFromName(wxString::FromAscii(colourName)); }
44
45 // copy ctors and assignment operators
46 wxColour( const wxColour& col );
47 wxColour& operator = ( const wxColour& col );
48
49 ~wxColour();
50
51 // ------------------------------------------------------------------------
52 // Implementation
53 // ------------------------------------------------------------------------
54 // accessors
55 bool Ok() const { return m_cocoaNSColor; }
56 inline WX_NSColor GetNSColor() { return m_cocoaNSColor; }
57
58 unsigned char Red() const { return m_red; }
59 unsigned char Green() const { return m_green; }
60 unsigned char Blue() const { return m_blue; }
61
62 // comparison
63 bool operator == (const wxColour& colour) const
64 {
65 return (m_cocoaNSColor == colour.m_cocoaNSColor &&
66 m_red == colour.m_red &&
67 m_green == colour.m_green &&
68 m_blue == colour.m_blue);
69 }
70 bool operator != (const wxColour& colour) const
71 { return !(*this == colour); }
72
73 // const WXCOLORREF& GetPixel() const { return m_pixel; };
74
75 // Set() functions
76 void Set( unsigned char red, unsigned char green, unsigned char blue );
77 void Set( unsigned long colRGB )
78 {
79 // we don't need to know sizeof(long) here because we assume that the three
80 // least significant bytes contain the R, G and B values
81 Set((unsigned char)colRGB,
82 (unsigned char)(colRGB >> 8),
83 (unsigned char)(colRGB >> 16));
84 }
85
86 protected:
87 void InitFromName(const wxString& col);
88
89 private:
90 WX_NSColor m_cocoaNSColor;
91 unsigned char m_red;
92 unsigned char m_green;
93 unsigned char m_blue;
94 };
95
96 #endif // __WX_COCOA_COLOUR_H__