]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/brush.mm
Don't use "Cancel" button in the about dialog of the listctrl sample.
[wxWidgets.git] / src / cocoa / brush.mm
CommitLineData
f162a338
DE
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/cocoa/brush.mm
3// Purpose: wxBrush
4// Author: David Elliott <dfe@cox.net>
5// Modified by:
6// Created: 2003/07/03
7// RCS-ID: $Id$
8// Copyright: (c) 2003 David Elliott
526954c5 9// Licence: wxWindows licence
f162a338
DE
10/////////////////////////////////////////////////////////////////////////////
11
449c5673 12#include "wx/wxprec.h"
c64755ed
WS
13
14#include "wx/brush.h"
15
449c5673
DE
16#ifndef WX_PRECOMP
17 #include "wx/utils.h"
7cf41a5d 18 #include "wx/colour.h"
449c5673 19#endif //WX_PRECOMP
c64755ed 20
f162a338
DE
21#import <AppKit/NSColor.h>
22
23class WXDLLEXPORT wxBrushRefData: public wxGDIRefData
24{
25public:
ae06f91b
VZ
26 wxBrushRefData(const wxColour& colour = wxNullColour,
27 wxBrushStyle style = wxBRUSHSTYLE_SOLID);
f162a338
DE
28 wxBrushRefData(const wxBitmap& stipple);
29 wxBrushRefData(const wxBrushRefData& data);
30 virtual ~wxBrushRefData();
31
32 WX_NSColor GetNSColor();
33 void Free();
34
35 bool operator==(const wxBrushRefData& data) const;
36
37 // accessors
38 const wxColour& GetColour() const { return m_colour; }
ae06f91b 39 wxBrushStyle GetStyle() const { return m_style; }
f162a338
DE
40 wxBitmap *GetStipple() { return &m_stipple; }
41
42 void SetColour(const wxColour& colour) { Free(); m_colour = colour; }
ae06f91b 43 void SetStyle(wxBrushStyle style) { Free(); m_style = style; }
f162a338
DE
44 void SetStipple(const wxBitmap& stipple) { Free(); DoSetStipple(stipple); }
45
46private:
47 void DoSetStipple(const wxBitmap& stipple);
48
49 WX_NSColor m_cocoaNSColor;
ae06f91b 50 wxBrushStyle m_style;
f162a338
DE
51 wxBitmap m_stipple;
52 wxColour m_colour;
53
54 // no assignment operator, the objects of this class are shared and never
55 // assigned after being created once
56 wxBrushRefData& operator=(const wxBrushRefData&);
57};
58
59#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
60IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
61
ae06f91b 62wxBrushRefData::wxBrushRefData(const wxColour& colour, wxBrushStyle style)
f162a338
DE
63{
64 m_cocoaNSColor = NULL;
6631a2a5 65 m_style = style;
f162a338
DE
66 m_colour = colour;
67}
68
69wxBrushRefData::wxBrushRefData(const wxBitmap& stipple)
70{
71 m_cocoaNSColor = NULL;
72 DoSetStipple(stipple);
73}
74
75wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
76{
77 m_cocoaNSColor = data.m_cocoaNSColor;
78 [m_cocoaNSColor retain];
79 m_style = data.m_style;
80 m_stipple = data.m_stipple;
81 m_colour = data.m_colour;
82}
83
84wxBrushRefData::~wxBrushRefData()
85{
86 Free();
87}
88
89void wxBrushRefData::Free()
90{
91 [m_cocoaNSColor release];
92 m_cocoaNSColor = NULL;
93}
94
95bool wxBrushRefData::operator==(const wxBrushRefData& data) const
96{
97 // don't compare our NSColor
98 return m_style == data.m_style &&
99 m_colour == data.m_colour &&
76690d5e 100 m_stipple.IsSameAs(data.m_stipple);
f162a338
DE
101}
102
103void wxBrushRefData::DoSetStipple(const wxBitmap& stipple)
104{
105 m_stipple = stipple;
ae06f91b
VZ
106 m_style = stipple.GetMask() ? wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
107 : wxBRUSHSTYLE_STIPPLE;
f162a338
DE
108}
109
110WX_NSColor wxBrushRefData::GetNSColor()
111{
112 if(!m_cocoaNSColor)
113 {
114 switch( m_style )
115 {
116 case wxTRANSPARENT:
117 m_cocoaNSColor = [[NSColor clearColor] retain];
118 break;
119 case wxSTIPPLE:
120// wxBitmap isn't implemented yet
121// m_cocoaNSColor = [[NSColor colorWithPatternImage: m_stipple.GetNSImage()] retain];
122// break;
123 case wxSTIPPLE_MASK_OPAQUE:
124 // This should be easy when wxBitmap works.
125// break;
126 // The hatch brushes are going to be tricky
127 case wxBDIAGONAL_HATCH:
128 case wxCROSSDIAG_HATCH:
129 case wxFDIAGONAL_HATCH:
130 case wxCROSS_HATCH:
131 case wxHORIZONTAL_HATCH:
132 case wxVERTICAL_HATCH:
133 default:
134 case wxSOLID:
135 NSColor *colour_NSColor = m_colour.GetNSColor();
136 if(!colour_NSColor)
137 colour_NSColor = [NSColor clearColor];
138 m_cocoaNSColor = [colour_NSColor copyWithZone:nil];
139 break;
140 }
141 }
142 return m_cocoaNSColor;
143}
144
145// Brushes
146wxBrush::wxBrush()
147{
f162a338
DE
148}
149
150wxBrush::~wxBrush()
151{
152}
153
ae06f91b 154wxBrush::wxBrush(const wxColour& col, wxBrushStyle style)
f162a338
DE
155{
156 m_refData = new wxBrushRefData(col, style);
157}
158
ae06f91b
VZ
159wxBrush::wxBrush(const wxColour& col, int style)
160{
161 m_refData = new wxBrushRefData(col, (wxBrushStyle)style);
162}
163
f162a338
DE
164wxBrush::wxBrush(const wxBitmap& stipple)
165{
166 m_refData = new wxBrushRefData(stipple);
167}
168
8f884a0d 169wxGDIRefData *wxBrush::CreateGDIRefData() const
f162a338
DE
170{
171 return new wxBrushRefData;
172}
173
8f884a0d 174wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const
f162a338
DE
175{
176 return new wxBrushRefData(*(wxBrushRefData *)data);
177}
178
179void wxBrush::SetColour(const wxColour& col)
180{
181 AllocExclusive();
182 M_BRUSHDATA->SetColour(col);
183}
184
1a1498c0 185void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
f162a338
DE
186{
187 AllocExclusive();
188 M_BRUSHDATA->SetColour(wxColour(r,g,b));
189}
190
ae06f91b 191void wxBrush::SetStyle(wxBrushStyle style)
f162a338
DE
192{
193 AllocExclusive();
194 M_BRUSHDATA->SetStyle(style);
195}
196
197void wxBrush::SetStipple(const wxBitmap& stipple)
198{
199 AllocExclusive();
200 M_BRUSHDATA->SetStipple(stipple);
201}
202
203wxColour wxBrush::GetColour() const
204{
a1b806b9 205 wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid brush") );
f162a338
DE
206 return M_BRUSHDATA->GetColour();
207}
208
ae06f91b 209wxBrushStyle wxBrush::GetStyle() const
f162a338 210{
a1b806b9 211 wxCHECK_MSG( IsOk(), wxBRUSHSTYLE_INVALID, wxT("invalid brush") );
f162a338
DE
212 return M_BRUSHDATA->GetStyle();
213}
214
215wxBitmap *wxBrush::GetStipple() const
216{
a1b806b9 217 wxCHECK_MSG( IsOk(), 0, wxT("invalid brush") );
f162a338
DE
218 return M_BRUSHDATA->GetStipple();
219}
220
221WX_NSColor wxBrush::GetNSColor()
222{
1a94b3d8
DE
223 if(!m_refData)
224 return [NSColor clearColor];
f162a338
DE
225 return M_BRUSHDATA->GetNSColor();
226}