]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/colour.mm
fixed variable shadowing icc warnings
[wxWidgets.git] / src / cocoa / colour.mm
CommitLineData
683b185d
DE
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
065e208e 9// Licence: wxWidgets licence
683b185d
DE
10/////////////////////////////////////////////////////////////////////////////
11
449c5673
DE
12#include "wx/wxprec.h"
13#ifndef WX_PRECOMP
14#endif //WX_PRECOMP
683b185d
DE
15
16#include "wx/gdicmn.h"
17#include "wx/colour.h"
18
7fc77f30
DE
19#include "wx/cocoa/autorelease.h"
20
449c5673
DE
21#import <AppKit/NSColor.h>
22
683b185d
DE
23IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
24
211436b6 25void wxColour::Init()
683b185d 26{
211436b6
VZ
27 m_cocoaNSColor = NULL;
28 m_red =
29 m_blue =
30 m_green = 0;
683b185d
DE
31}
32
33wxColour::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
d8fdd58f
DE
42wxColour::wxColour( WX_NSColor aColor )
43: m_cocoaNSColor(nil)
44{
45 Set(aColor);
46}
47
683b185d
DE
48wxColour& wxColour::operator =(const wxColour& col)
49{
50 m_cocoaNSColor = col.m_cocoaNSColor;
51 m_red = col.m_red;
52 m_green = col.m_green;
53 m_blue = col.m_blue;
54 [m_cocoaNSColor retain];
55 return *this;
56}
57
211436b6 58void wxColour::InitFromName(const wxString& name)
683b185d 59{
211436b6 60 if ( wxTheColourDatabase )
683b185d 61 {
211436b6
VZ
62 wxColour col = wxTheColourDatabase->Find(name);
63 if ( col.Ok() )
64 {
65 *this = col;
66 return;
67 }
683b185d 68 }
211436b6
VZ
69
70 // leave invalid
71 Init();
683b185d
DE
72}
73
74wxColour::~wxColour ()
75{
76 [m_cocoaNSColor release];
77}
78
79void wxColour::Set (unsigned char r, unsigned char g, unsigned char b)
80{
7fc77f30 81 wxAutoNSAutoreleasePool pool;
683b185d
DE
82 [m_cocoaNSColor release];
83 m_cocoaNSColor = [[NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0] retain];
84 m_red = r;
85 m_green = g;
86 m_blue = b;
87}
88
d8fdd58f
DE
89void wxColour::Set( WX_NSColor aColor )
90{
91 [aColor retain];
92 [m_cocoaNSColor release];
93 m_cocoaNSColor = aColor;
94
95 /* Make a temporary color in RGB format and get the values. Note that
96 unless the color was actually RGB to begin with it's likely that
97 these will be fairly bogus. Particulary if the color is a pattern. */
98 NSColor *rgbColor = [m_cocoaNSColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
2692aef4
RN
99 m_red = (wxUint8) ([rgbColor redComponent] * 255.0);
100 m_green = (wxUint8) ([rgbColor greenComponent] * 255.0);
101 m_blue = (wxUint8) ([rgbColor blueComponent] * 255.0);
d8fdd58f
DE
102}
103