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