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 wxColour( const wxChar
*colourName
) { InitFromName( wxString(colourName
) ); }
43 // copy ctors and assignment operators
44 wxColour( const wxColour
& col
);
45 wxColour
& operator = ( const wxColour
& col
);
50 bool Ok() const { return m_cocoaNSColor
; }
51 WX_NSColor
GetNSColor() { return m_cocoaNSColor
; }
53 unsigned char Red() const { return m_red
; }
54 unsigned char Green() const { return m_green
; }
55 unsigned char Blue() const { return m_blue
; }
58 bool operator == (const wxColour
& colour
) const
60 // VZ: sure we want to compare NSColor objects for equality here?
61 return (m_cocoaNSColor
== colour
.m_cocoaNSColor
62 && m_red
== colour
.m_red
63 && m_green
== colour
.m_green
64 && m_blue
== colour
.m_blue
);
66 bool operator != (const wxColour
& colour
) const
67 { return !(*this == colour
); }
70 void Set( unsigned char red
, unsigned char green
, unsigned char blue
);
71 void Set( unsigned long colRGB
)
73 // we don't need to know sizeof(long) here because we assume that the three
74 // least significant bytes contain the R, G and B values
75 Set((unsigned char)colRGB
,
76 (unsigned char)(colRGB
>> 8),
77 (unsigned char)(colRGB
>> 16));
81 // puts the object in an invalid, uninitialized state
84 // create the object from name, leaves it uninitialized if it failed
85 void InitFromName(const wxString
& col
);
88 WX_NSColor m_cocoaNSColor
;
90 unsigned char m_green
;
93 DECLARE_DYNAMIC_CLASS(wxColour
)
96 #endif // __WX_COCOA_COLOUR_H__