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"
21 #include "wx/cocoa/ObjcRef.h"
23 #import <AppKit/NSColor.h>
25 IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
29 m_cocoaNSColor = NULL;
35 wxColour::wxColour (const wxColour& col)
36 : m_cocoaNSColor(col.m_cocoaNSColor)
38 , m_green(col.m_green)
40 , m_alpha(col.m_alpha)
42 wxGCSafeRetain(m_cocoaNSColor);
45 wxColour::wxColour( WX_NSColor aColor )
51 wxColour& wxColour::operator =(const wxColour& col)
53 m_cocoaNSColor = wxGCSafeRetain(col.m_cocoaNSColor);
55 m_green = col.m_green;
57 m_alpha = col.m_alpha;
61 wxColour::~wxColour ()
63 wxGCSafeRelease(m_cocoaNSColor);
66 void wxColour::InitRGBA(unsigned char r,
71 wxAutoNSAutoreleasePool pool;
72 wxGCSafeRelease(m_cocoaNSColor);
73 m_cocoaNSColor = wxGCSafeRetain([NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a/255.0]);
80 void wxColour::Set( WX_NSColor aColor )
82 wxGCSafeRetain(aColor);
83 wxGCSafeRelease(m_cocoaNSColor);
84 m_cocoaNSColor = aColor;
86 /* Make a temporary color in RGB format and get the values. Note that
87 unless the color was actually RGB to begin with it's likely that
88 these will be fairly bogus. Particulary if the color is a pattern. */
89 NSColor *rgbColor = [m_cocoaNSColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
90 m_red = (wxUint8) ([rgbColor redComponent] * 255.0);
91 m_green = (wxUint8) ([rgbColor greenComponent] * 255.0);
92 m_blue = (wxUint8) ([rgbColor blueComponent] * 255.0);
93 m_alpha = (wxUint8) ([rgbColor alphaComponent] * 255.0);