]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/colour.mm
Fix text input and completion in wxComboCtrl and wxOwnerDrawnComboBox.
[wxWidgets.git] / src / cocoa / colour.mm
CommitLineData
683b185d 1/////////////////////////////////////////////////////////////////////////////
edc536d3 2// Name: src/cococa/colour.mm
683b185d
DE
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
edc536d3 9// Licence: wxWidgets licence
683b185d
DE
10/////////////////////////////////////////////////////////////////////////////
11
449c5673 12#include "wx/wxprec.h"
40989e46
WS
13
14#include "wx/colour.h"
15
449c5673 16#ifndef WX_PRECOMP
dd05139a 17 #include "wx/gdicmn.h"
449c5673 18#endif //WX_PRECOMP
683b185d 19
7fc77f30 20#include "wx/cocoa/autorelease.h"
6a5c31c2 21#include "wx/cocoa/ObjcRef.h"
7fc77f30 22
449c5673
DE
23#import <AppKit/NSColor.h>
24
683b185d
DE
25IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
26
211436b6 27void wxColour::Init()
683b185d 28{
211436b6
VZ
29 m_cocoaNSColor = NULL;
30 m_red =
31 m_blue =
32 m_green = 0;
683b185d
DE
33}
34
35wxColour::wxColour (const wxColour& col)
36: m_cocoaNSColor(col.m_cocoaNSColor)
37, m_red(col.m_red)
38, m_green(col.m_green)
39, m_blue(col.m_blue)
71064979 40, m_alpha(col.m_alpha)
683b185d 41{
6a5c31c2 42 wxGCSafeRetain(m_cocoaNSColor);
683b185d
DE
43}
44
d8fdd58f
DE
45wxColour::wxColour( WX_NSColor aColor )
46: m_cocoaNSColor(nil)
47{
48 Set(aColor);
49}
50
683b185d
DE
51wxColour& wxColour::operator =(const wxColour& col)
52{
6a5c31c2 53 m_cocoaNSColor = wxGCSafeRetain(col.m_cocoaNSColor);
683b185d
DE
54 m_red = col.m_red;
55 m_green = col.m_green;
56 m_blue = col.m_blue;
71064979 57 m_alpha = col.m_alpha;
683b185d
DE
58 return *this;
59}
60
683b185d
DE
61wxColour::~wxColour ()
62{
6a5c31c2 63 wxGCSafeRelease(m_cocoaNSColor);
683b185d
DE
64}
65
aea95b1c 66void wxColour::InitRGBA(unsigned char r,
71064979
VZ
67 unsigned char g,
68 unsigned char b,
69 unsigned char a)
683b185d 70{
7fc77f30 71 wxAutoNSAutoreleasePool pool;
6a5c31c2
DE
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]);
683b185d
DE
74 m_red = r;
75 m_green = g;
76 m_blue = b;
71064979 77 m_alpha = a;
683b185d
DE
78}
79
d8fdd58f
DE
80void wxColour::Set( WX_NSColor aColor )
81{
6a5c31c2
DE
82 wxGCSafeRetain(aColor);
83 wxGCSafeRelease(m_cocoaNSColor);
d8fdd58f
DE
84 m_cocoaNSColor = aColor;
85
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];
edc536d3 90 m_red = (wxUint8) ([rgbColor redComponent] * 255.0);
2692aef4 91 m_green = (wxUint8) ([rgbColor greenComponent] * 255.0);
edc536d3 92 m_blue = (wxUint8) ([rgbColor blueComponent] * 255.0);
71064979 93 m_alpha = (wxUint8) ([rgbColor alphaComponent] * 255.0);
d8fdd58f 94}