use wxColourDatabase::Find(), not obsolete FindColour(), in wxColour::InitFromName()
[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 wxColour() { Init(); }
25
26 // from RGB
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)
32 { Set(colRGB); }
33
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)); }
39
40 // copy ctors and assignment operators
41 wxColour( const wxColour& col );
42 wxColour& operator = ( const wxColour& col );
43
44 virtual ~wxColour();
45
46 // accessors
47 bool Ok() const { return m_cocoaNSColor; }
48 WX_NSColor GetNSColor() { return m_cocoaNSColor; }
49
50 unsigned char Red() const { return m_red; }
51 unsigned char Green() const { return m_green; }
52 unsigned char Blue() const { return m_blue; }
53
54 // comparison
55 bool operator == (const wxColour& colour) const
56 {
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);
62 }
63 bool operator != (const wxColour& colour) const
64 { return !(*this == colour); }
65
66 // Set() functions
67 void Set( unsigned char red, unsigned char green, unsigned char blue );
68 void Set( unsigned long colRGB )
69 {
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));
75 }
76
77 protected:
78 // puts the object in an invalid, uninitialized state
79 void Init();
80
81 // create the object from name, leaves it uninitialized if it failed
82 void InitFromName(const wxString& col);
83
84 private:
85 WX_NSColor m_cocoaNSColor;
86 unsigned char m_red;
87 unsigned char m_green;
88 unsigned char m_blue;
89
90 DECLARE_DYNAMIC_CLASS(wxColour)
91 };
92
93 #endif // __WX_COCOA_COLOUR_H__