]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/colour.mm
Use wxMarkupParser in wxStaticText for dealing with markup.
[wxWidgets.git] / src / cocoa / colour.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cococa/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
14 #include "wx/colour.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/gdicmn.h"
18 #endif //WX_PRECOMP
19
20 #include "wx/cocoa/autorelease.h"
21 #include "wx/cocoa/ObjcRef.h"
22
23 #import <AppKit/NSColor.h>
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 , m_alpha(col.m_alpha)
39 {
40 wxGCSafeRetain(m_cocoaNSColor);
41 }
42
43 wxColour::wxColour( WX_NSColor aColor )
44 : m_cocoaNSColor(nil)
45 {
46 Set(aColor);
47 }
48
49 wxColour& wxColour::operator =(const wxColour& col)
50 {
51 m_cocoaNSColor = wxGCSafeRetain(col.m_cocoaNSColor);
52 m_red = col.m_red;
53 m_green = col.m_green;
54 m_blue = col.m_blue;
55 m_alpha = col.m_alpha;
56 return *this;
57 }
58
59 wxColour::~wxColour ()
60 {
61 wxGCSafeRelease(m_cocoaNSColor);
62 }
63
64 void wxColour::InitRGBA(unsigned char r,
65 unsigned char g,
66 unsigned char b,
67 unsigned char a)
68 {
69 wxAutoNSAutoreleasePool pool;
70 wxGCSafeRelease(m_cocoaNSColor);
71 m_cocoaNSColor = wxGCSafeRetain([NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a/255.0]);
72 m_red = r;
73 m_green = g;
74 m_blue = b;
75 m_alpha = a;
76 }
77
78 void wxColour::Set( WX_NSColor aColor )
79 {
80 wxGCSafeRetain(aColor);
81 wxGCSafeRelease(m_cocoaNSColor);
82 m_cocoaNSColor = aColor;
83
84 /* Make a temporary color in RGB format and get the values. Note that
85 unless the color was actually RGB to begin with it's likely that
86 these will be fairly bogus. Particulary if the color is a pattern. */
87 NSColor *rgbColor = [m_cocoaNSColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
88 m_red = (wxUint8) ([rgbColor redComponent] * 255.0);
89 m_green = (wxUint8) ([rgbColor greenComponent] * 255.0);
90 m_blue = (wxUint8) ([rgbColor blueComponent] * 255.0);
91 m_alpha = (wxUint8) ([rgbColor alphaComponent] * 255.0);
92 }