]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/colour.mm
Rework modal dialog code to not depend on now obsolete wxDIALOG_MODAL flag.
[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 #include "wx/wxprec.h"
13 #ifndef WX_PRECOMP
14 #endif //WX_PRECOMP
15
16 #include "wx/gdicmn.h"
17 #include "wx/colour.h"
18
19 #include "wx/cocoa/autorelease.h"
20
21 #import <AppKit/NSColor.h>
22
23 IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
24
25 void wxColour::Init()
26 {
27 m_cocoaNSColor = NULL;
28 m_red =
29 m_blue =
30 m_green = 0;
31 }
32
33 wxColour::wxColour (const wxColour& col)
34 : m_cocoaNSColor(col.m_cocoaNSColor)
35 , m_red(col.m_red)
36 , m_green(col.m_green)
37 , m_blue(col.m_blue)
38 {
39 [m_cocoaNSColor retain];
40 }
41
42 wxColour& wxColour::operator =(const wxColour& col)
43 {
44 m_cocoaNSColor = col.m_cocoaNSColor;
45 m_red = col.m_red;
46 m_green = col.m_green;
47 m_blue = col.m_blue;
48 [m_cocoaNSColor retain];
49 return *this;
50 }
51
52 void wxColour::InitFromName(const wxString& name)
53 {
54 if ( wxTheColourDatabase )
55 {
56 wxColour col = wxTheColourDatabase->Find(name);
57 if ( col.Ok() )
58 {
59 *this = col;
60 return;
61 }
62 }
63
64 // leave invalid
65 Init();
66 }
67
68 wxColour::~wxColour ()
69 {
70 [m_cocoaNSColor release];
71 }
72
73 void wxColour::Set (unsigned char r, unsigned char g, unsigned char b)
74 {
75 wxAutoNSAutoreleasePool pool;
76 [m_cocoaNSColor release];
77 m_cocoaNSColor = [[NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0] retain];
78 m_red = r;
79 m_green = g;
80 m_blue = b;
81 }
82