1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxColour class
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef __WX_COCOA_COLOUR_H__
13 #define __WX_COCOA_COLOUR_H__
15 #include "wx/object.h"
16 #include "wx/string.h"
18 // ========================================================================
20 // ========================================================================
21 class WXDLLEXPORT wxColour
: public wxObject
24 wxColour() { Init(); }
27 wxColour( unsigned char red
, unsigned char green
, unsigned char blue
)
28 : m_cocoaNSColor(NULL
)
29 { Set(red
,green
,blue
); }
30 wxColour( unsigned long colRGB
)
31 : m_cocoaNSColor(NULL
)
34 // implicit conversion from the colour name
35 wxColour( const wxString
&colourName
)
36 { InitFromName(colourName
); }
37 wxColour( const char *colourName
)
38 { InitFromName(wxString::FromAscii(colourName
)); }
40 // copy ctors and assignment operators
41 wxColour( const wxColour
& col
);
42 wxColour
& operator = ( const wxColour
& col
);
47 bool Ok() const { return m_cocoaNSColor
; }
48 WX_NSColor
GetNSColor() { return m_cocoaNSColor
; }
50 unsigned char Red() const { return m_red
; }
51 unsigned char Green() const { return m_green
; }
52 unsigned char Blue() const { return m_blue
; }
55 bool operator == (const wxColour
& colour
) const
57 // VZ: sure we want to compare NSColor objects for equality here?
58 return (m_cocoaNSColor
== colour
.m_cocoaNSColor
59 && m_red
== colour
.m_red
60 && m_green
== colour
.m_green
61 && m_blue
== colour
.m_blue
);
63 bool operator != (const wxColour
& colour
) const
64 { return !(*this == colour
); }
67 void Set( unsigned char red
, unsigned char green
, unsigned char blue
);
68 void Set( unsigned long colRGB
)
70 // we don't need to know sizeof(long) here because we assume that the three
71 // least significant bytes contain the R, G and B values
72 Set((unsigned char)colRGB
,
73 (unsigned char)(colRGB
>> 8),
74 (unsigned char)(colRGB
>> 16));
78 // puts the object in an invalid, uninitialized state
81 // create the object from name, leaves it uninitialized if it failed
82 void InitFromName(const wxString
& col
);
85 WX_NSColor m_cocoaNSColor
;
87 unsigned char m_green
;
90 DECLARE_DYNAMIC_CLASS(wxColour
)
93 #endif // __WX_COCOA_COLOUR_H__