1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxColour class
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/gdicmn.h"
17 #include "wx/colour.h"
19 #include "wx/cocoa/autorelease.h"
21 #import <AppKit/NSColor.h>
23 IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
27 m_cocoaNSColor = NULL;
33 wxColour::wxColour (const wxColour& col)
34 : m_cocoaNSColor(col.m_cocoaNSColor)
36 , m_green(col.m_green)
39 [m_cocoaNSColor retain];
42 wxColour::wxColour( WX_NSColor aColor )
48 wxColour& wxColour::operator =(const wxColour& col)
50 m_cocoaNSColor = col.m_cocoaNSColor;
52 m_green = col.m_green;
54 [m_cocoaNSColor retain];
58 void wxColour::InitFromName(const wxString& name)
60 if ( wxTheColourDatabase )
62 wxColour col = wxTheColourDatabase->Find(name);
74 wxColour::~wxColour ()
76 [m_cocoaNSColor release];
79 void wxColour::Set (unsigned char r, unsigned char g, unsigned char b)
81 wxAutoNSAutoreleasePool pool;
82 [m_cocoaNSColor release];
83 m_cocoaNSColor = [[NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0] retain];
89 void wxColour::Set( WX_NSColor aColor )
92 [m_cocoaNSColor release];
93 m_cocoaNSColor = aColor;
95 /* Make a temporary color in RGB format and get the values. Note that
96 unless the color was actually RGB to begin with it's likely that
97 these will be fairly bogus. Particulary if the color is a pattern. */
98 NSColor *rgbColor = [m_cocoaNSColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
99 m_red = (wxUint8) ([rgbColor redComponent] * 255.0);
100 m_green = (wxUint8) ([rgbColor greenComponent] * 255.0);
101 m_blue = (wxUint8) ([rgbColor blueComponent] * 255.0);