]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/colour.mm
unicode compilation fix
[wxWidgets.git] / src / cocoa / colour.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: colour.mm
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 #import <AppKit/NSColor.h>
13
14 #include "wx/gdicmn.h"
15 #include "wx/colour.h"
16
17 #include "wx/cocoa/autorelease.h"
18
19 IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
20
21 wxColour::wxColour ()
22 : m_cocoaNSColor(NULL)
23 {
24 m_red = m_blue = m_green = 0;
25 }
26
27 wxColour::wxColour (const wxColour& col)
28 : m_cocoaNSColor(col.m_cocoaNSColor)
29 , m_red(col.m_red)
30 , m_green(col.m_green)
31 , m_blue(col.m_blue)
32 {
33 [m_cocoaNSColor retain];
34 }
35
36 wxColour& wxColour::operator =(const wxColour& col)
37 {
38 m_cocoaNSColor = col.m_cocoaNSColor;
39 m_red = col.m_red;
40 m_green = col.m_green;
41 m_blue = col.m_blue;
42 [m_cocoaNSColor retain];
43 return *this;
44 }
45
46 void wxColour::InitFromName(const wxString& col)
47 {
48 wxColour *the_colour = wxTheColourDatabase->FindColour (col);
49 if (the_colour)
50 {
51 *this = *the_colour;
52 }
53 else
54 {
55 [m_cocoaNSColor release];
56 m_cocoaNSColor = NULL;
57 m_red = 0;
58 m_green = 0;
59 m_blue = 0;
60 }
61 }
62
63 wxColour::~wxColour ()
64 {
65 [m_cocoaNSColor release];
66 }
67
68 void wxColour::Set (unsigned char r, unsigned char g, unsigned char b)
69 {
70 wxAutoNSAutoreleasePool pool;
71 [m_cocoaNSColor release];
72 m_cocoaNSColor = [[NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0] retain];
73 m_red = r;
74 m_green = g;
75 m_blue = b;
76 }
77