1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/cocoa/colour.h
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
28 wxColour() { Init(); }
31 wxColour( unsigned char red
, unsigned char green
, unsigned char blue
)
32 : m_cocoaNSColor(NULL
)
33 { Set(red
,green
,blue
); }
36 wxColour( unsigned long colRGB
)
37 : m_cocoaNSColor(NULL
)
40 // initialization using existing NSColor
41 wxColour( WX_NSColor aColor
);
43 // implicit conversion from the colour name
44 wxColour( const wxString
&colourName
)
45 { InitFromName(colourName
); }
46 wxColour( const char *colourName
)
47 { InitFromName(wxString::FromAscii(colourName
)); }
49 wxColour( const wxChar
*colourName
) { InitFromName( wxString(colourName
) ); }
52 // copy ctors and assignment operators
53 wxColour( const wxColour
& col
);
54 wxColour
& operator = ( const wxColour
& col
);
59 bool Ok() const { return m_cocoaNSColor
; }
60 WX_NSColor
GetNSColor() { return m_cocoaNSColor
; }
62 unsigned char Red() const { return m_red
; }
63 unsigned char Green() const { return m_green
; }
64 unsigned char Blue() const { return m_blue
; }
67 bool operator == (const wxColour
& colour
) const
69 // TODO: Really compare the NSColor
70 return (m_cocoaNSColor
== colour
.m_cocoaNSColor
71 || (m_red
== colour
.m_red
72 && m_green
== colour
.m_green
73 && m_blue
== colour
.m_blue
));
75 bool operator != (const wxColour
& colour
) const
76 { return !(*this == colour
); }
79 void Set( unsigned char red
, unsigned char green
, unsigned char blue
);
80 void Set( unsigned long colRGB
)
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));
88 void Set( WX_NSColor aColor
);
91 // puts the object in an invalid, uninitialized state
94 // create the object from name, leaves it uninitialized if it failed
95 void InitFromName(const wxString
& col
);
98 WX_NSColor m_cocoaNSColor
;
100 unsigned char m_green
;
101 unsigned char m_blue
;
103 DECLARE_DYNAMIC_CLASS(wxColour
)
106 #endif // __WX_COCOA_COLOUR_H__