]> git.saurik.com Git - wxWidgets.git/blob - include/wx/cocoa/colour.h
updated to derive from wxEventLoopManual
[wxWidgets.git] / include / wx / cocoa / colour.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/cocoa/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 // constructors
25 // ------------
26
27 // default
28 wxColour() { Init(); }
29
30 // from separate RGB
31 wxColour( unsigned char red, unsigned char green, unsigned char blue )
32 : m_cocoaNSColor(NULL)
33 { Set(red,green,blue); }
34
35 // from packed RGB
36 wxColour( unsigned long colRGB )
37 : m_cocoaNSColor(NULL)
38 { Set(colRGB); }
39
40 // initialization using existing NSColor
41 wxColour( WX_NSColor aColor );
42
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)); }
48 #if wxUSE_UNICODE
49 wxColour( const wxChar *colourName ) { InitFromName( wxString(colourName) ); }
50 #endif
51
52 // copy ctors and assignment operators
53 wxColour( const wxColour& col );
54 wxColour& operator = ( const wxColour& col );
55
56 virtual ~wxColour();
57
58 // accessors
59 bool Ok() const { return m_cocoaNSColor; }
60 WX_NSColor GetNSColor() { return m_cocoaNSColor; }
61
62 unsigned char Red() const { return m_red; }
63 unsigned char Green() const { return m_green; }
64 unsigned char Blue() const { return m_blue; }
65
66 // comparison
67 bool operator == (const wxColour& colour) const
68 {
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));
74 }
75 bool operator != (const wxColour& colour) const
76 { return !(*this == colour); }
77
78 // Set() functions
79 void Set( unsigned char red, unsigned char green, unsigned char blue );
80 void Set( unsigned long colRGB )
81 {
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));
87 }
88 void Set( WX_NSColor aColor );
89
90 protected:
91 // puts the object in an invalid, uninitialized state
92 void Init();
93
94 // create the object from name, leaves it uninitialized if it failed
95 void InitFromName(const wxString& col);
96
97 private:
98 WX_NSColor m_cocoaNSColor;
99 unsigned char m_red;
100 unsigned char m_green;
101 unsigned char m_blue;
102
103 DECLARE_DYNAMIC_CLASS(wxColour)
104 };
105
106 #endif // __WX_COCOA_COLOUR_H__