1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cococa/colour.mm
3 // Purpose: wxColour class
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/colour.h"
17 #include "wx/gdicmn.h"
20 #include "wx/cocoa/autorelease.h"
22 #import <AppKit/NSColor.h>
24 IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
28 m_cocoaNSColor = NULL;
34 wxColour::wxColour (const wxColour& col)
35 : m_cocoaNSColor(col.m_cocoaNSColor)
37 , m_green(col.m_green)
40 [m_cocoaNSColor retain];
43 wxColour::wxColour( WX_NSColor aColor )
49 wxColour& wxColour::operator =(const wxColour& col)
51 m_cocoaNSColor = col.m_cocoaNSColor;
53 m_green = col.m_green;
55 [m_cocoaNSColor retain];
59 wxColour::~wxColour ()
61 [m_cocoaNSColor release];
64 void wxColour::InitWith (unsigned char r, unsigned char g, unsigned char b)
66 wxAutoNSAutoreleasePool pool;
67 [m_cocoaNSColor release];
68 m_cocoaNSColor = [[NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0] retain];
74 void wxColour::Set( WX_NSColor aColor )
77 [m_cocoaNSColor release];
78 m_cocoaNSColor = aColor;
80 /* Make a temporary color in RGB format and get the values. Note that
81 unless the color was actually RGB to begin with it's likely that
82 these will be fairly bogus. Particulary if the color is a pattern. */
83 NSColor *rgbColor = [m_cocoaNSColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
84 m_red = (wxUint8) ([rgbColor redComponent] * 255.0);
85 m_green = (wxUint8) ([rgbColor greenComponent] * 255.0);
86 m_blue = (wxUint8) ([rgbColor blueComponent] * 255.0);