]> git.saurik.com Git - wxWidgets.git/blob - include/wx/cocoa/colour.h
added link to wxFileHistory
[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 // initialization using existing NSColor
35 wxColour( WX_NSColor aColor );
36
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)); }
42 #if wxUSE_UNICODE
43 wxColour( const wxChar *colourName ) { InitFromName( wxString(colourName) ); }
44 #endif
45
46 // copy ctors and assignment operators
47 wxColour( const wxColour& col );
48 wxColour& operator = ( const wxColour& col );
49
50 virtual ~wxColour();
51
52 // accessors
53 bool Ok() const { return m_cocoaNSColor; }
54 WX_NSColor GetNSColor() { return m_cocoaNSColor; }
55
56 unsigned char Red() const { return m_red; }
57 unsigned char Green() const { return m_green; }
58 unsigned char Blue() const { return m_blue; }
59
60 // comparison
61 bool operator == (const wxColour& colour) const
62 {
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));
68 }
69 bool operator != (const wxColour& colour) const
70 { return !(*this == colour); }
71
72 // Set() functions
73 void Set( unsigned char red, unsigned char green, unsigned char blue );
74 void Set( unsigned long colRGB )
75 {
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));
81 }
82 void Set( WX_NSColor aColor );
83
84 protected:
85 // puts the object in an invalid, uninitialized state
86 void Init();
87
88 // create the object from name, leaves it uninitialized if it failed
89 void InitFromName(const wxString& col);
90
91 private:
92 WX_NSColor m_cocoaNSColor;
93 unsigned char m_red;
94 unsigned char m_green;
95 unsigned char m_blue;
96
97 DECLARE_DYNAMIC_CLASS(wxColour)
98 };
99
100 #endif // __WX_COCOA_COLOUR_H__