]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/colour.mm
don't hang forever in Dispatch() if there is no event loop
[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 wxColour::wxColour ()
26 : m_cocoaNSColor(NULL)
27 {
28 m_red = m_blue = m_green = 0;
29 }
30
31 wxColour::wxColour (const wxColour& col)
32 : m_cocoaNSColor(col.m_cocoaNSColor)
33 , m_red(col.m_red)
34 , m_green(col.m_green)
35 , m_blue(col.m_blue)
36 {
37 [m_cocoaNSColor retain];
38 }
39
40 wxColour& wxColour::operator =(const wxColour& col)
41 {
42 m_cocoaNSColor = col.m_cocoaNSColor;
43 m_red = col.m_red;
44 m_green = col.m_green;
45 m_blue = col.m_blue;
46 [m_cocoaNSColor retain];
47 return *this;
48 }
49
50 void wxColour::InitFromName(const wxString& col)
51 {
52 wxColour *the_colour = wxTheColourDatabase->FindColour (col);
53 if (the_colour)
54 {
55 *this = *the_colour;
56 }
57 else
58 {
59 [m_cocoaNSColor release];
60 m_cocoaNSColor = NULL;
61 m_red = 0;
62 m_green = 0;
63 m_blue = 0;
64 }
65 }
66
67 wxColour::~wxColour ()
68 {
69 [m_cocoaNSColor release];
70 }
71
72 void wxColour::Set (unsigned char r, unsigned char g, unsigned char b)
73 {
74 wxAutoNSAutoreleasePool pool;
75 [m_cocoaNSColor release];
76 m_cocoaNSColor = [[NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0] retain];
77 m_red = r;
78 m_green = g;
79 m_blue = b;
80 }
81