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 // initialization using existing NSColor
35 wxColour( WX_NSColor aColor
);
37 // implicit conversion from the colour name
38 wxColour( const wxString
&colourName
)
39 { InitFromName(colourName
); }
40 wxColour( const char *colourName
)
41 { InitFromName(wxString::FromAscii(colourName
)); }
43 wxColour( const wxChar
*colourName
) { InitFromName( wxString(colourName
) ); }
46 // copy ctors and assignment operators
47 wxColour( const wxColour
& col
);
48 wxColour
& operator = ( const wxColour
& col
);
53 bool Ok() const { return m_cocoaNSColor
; }
54 WX_NSColor
GetNSColor() { return m_cocoaNSColor
; }
56 unsigned char Red() const { return m_red
; }
57 unsigned char Green() const { return m_green
; }
58 unsigned char Blue() const { return m_blue
; }
61 bool operator == (const wxColour
& colour
) const
63 // TODO: Really compare the NSColor
64 return (m_cocoaNSColor
== colour
.m_cocoaNSColor
65 || (m_red
== colour
.m_red
66 && m_green
== colour
.m_green
67 && m_blue
== colour
.m_blue
));
69 bool operator != (const wxColour
& colour
) const
70 { return !(*this == colour
); }
73 void Set( unsigned char red
, unsigned char green
, unsigned char blue
);
74 void Set( unsigned long colRGB
)
76 // we don't need to know sizeof(long) here because we assume that the three
77 // least significant bytes contain the R, G and B values
78 Set((unsigned char)colRGB
,
79 (unsigned char)(colRGB
>> 8),
80 (unsigned char)(colRGB
>> 16));
82 void Set( WX_NSColor aColor
);
85 // puts the object in an invalid, uninitialized state
88 // create the object from name, leaves it uninitialized if it failed
89 void InitFromName(const wxString
& col
);
92 WX_NSColor m_cocoaNSColor
;
94 unsigned char m_green
;
97 DECLARE_DYNAMIC_CLASS(wxColour
)
100 #endif // __WX_COCOA_COLOUR_H__