]> git.saurik.com Git - wxWidgets.git/blame - src/osx/brush.cpp
Make public headers compatible with Objective-C++ with ARC.
[wxWidgets.git] / src / osx / brush.cpp
CommitLineData
ad66316f 1/////////////////////////////////////////////////////////////////////////////
96dabe43 2// Name: src/osx/brush.cpp
ad66316f
SC
3// Purpose: wxBrush
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
ad66316f
SC
7// Copyright: (c) Stefan Csomor
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#include "wx/wxprec.h"
12
13#include "wx/brush.h"
14
15#ifndef WX_PRECOMP
16 #include "wx/utils.h"
17#endif
18
19#include "wx/osx/private.h"
20
21IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
22
23class WXDLLEXPORT wxBrushRefData: public wxGDIRefData
24{
25public:
26 wxBrushRefData(const wxColour& colour = wxNullColour, wxBrushStyle style = wxBRUSHSTYLE_SOLID);
27 wxBrushRefData(const wxBitmap& stipple);
28 wxBrushRefData(const wxBrushRefData& data);
29 virtual ~wxBrushRefData();
30
31 bool operator==(const wxBrushRefData& data) const;
32
33 const wxColour& GetColour() const { return m_colour; }
34 wxBrushStyle GetStyle() const { return m_style; }
35 wxBitmap *GetStipple() { return &m_stipple; }
36
37 void SetColour(const wxColour& colour) { m_colour = colour; }
38 void SetStyle(wxBrushStyle style) { m_style = style; }
39 void SetStipple(const wxBitmap& stipple) { DoSetStipple(stipple); }
40
41protected:
42 void DoSetStipple(const wxBitmap& stipple);
43
44 wxBitmap m_stipple;
45 wxColour m_colour;
46 wxBrushStyle m_style;
47};
48
49#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
50
51wxBrushRefData::wxBrushRefData(const wxColour& colour, wxBrushStyle style)
52 : m_colour(colour), m_style( style )
53{
54}
55
56wxBrushRefData::wxBrushRefData(const wxBitmap& stipple)
57{
58 DoSetStipple( stipple );
59}
60
61wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
62 : wxGDIRefData() ,
63 m_stipple(data.m_stipple),
64 m_colour(data.m_colour),
65 m_style(data.m_style)
66{
67}
68
69wxBrushRefData::~wxBrushRefData()
70{
71}
72
73bool wxBrushRefData::operator==(const wxBrushRefData& data) const
74{
75 return m_style == data.m_style &&
76 m_colour == data.m_colour &&
77 m_stipple.IsSameAs(data.m_stipple);
78}
79
80void wxBrushRefData::DoSetStipple(const wxBitmap& stipple)
81{
82 m_stipple = stipple;
83 m_style = stipple.GetMask() ? wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE : wxBRUSHSTYLE_STIPPLE;
84}
85//
86//
87//
88
89wxBrush::wxBrush()
90{
91}
92
93wxBrush::~wxBrush()
94{
95}
96
97wxBrush::wxBrush(const wxColour& col, wxBrushStyle style)
98{
99 m_refData = new wxBrushRefData( col, style );
100}
101
102#if FUTURE_WXWIN_COMPATIBILITY_3_0
103wxBrush::wxBrush(const wxColour& col, int style)
104{
105 m_refData = new wxBrushRefData(col, (wxBrushStyle)style);
106}
107#endif
108
109wxBrush::wxBrush(const wxBitmap& stipple)
110{
111 m_refData = new wxBrushRefData( stipple );
112}
113
114// ----------------------------------------------------------------------------
115// wxBrush house keeping stuff
116// ----------------------------------------------------------------------------
117
118bool wxBrush::operator==(const wxBrush& brush) const
119{
120 const wxBrushRefData *brushData = (wxBrushRefData *)brush.m_refData;
121
122 // an invalid brush is considered to be only equal to another invalid brush
123 return m_refData ? (brushData && *M_BRUSHDATA == *brushData) : !brushData;
124}
125
126wxGDIRefData *wxBrush::CreateGDIRefData() const
127{
128 return new wxBrushRefData;
129}
130
131wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const
132{
133 return new wxBrushRefData(*(const wxBrushRefData *)data);
134}
135
136// ----------------------------------------------------------------------------
137// wxBrush accessors
138// ----------------------------------------------------------------------------
139
140wxColour wxBrush::GetColour() const
141{
a1b806b9 142 wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid brush") );
ad66316f
SC
143
144 return M_BRUSHDATA->GetColour();
145}
146
147wxBrushStyle wxBrush::GetStyle() const
148{
a1b806b9 149 wxCHECK_MSG( IsOk(), wxBRUSHSTYLE_INVALID, wxT("invalid brush") );
ad66316f
SC
150
151 return M_BRUSHDATA->GetStyle();
152}
153
154wxBitmap *wxBrush::GetStipple() const
155{
a1b806b9 156 wxCHECK_MSG( IsOk(), NULL, wxT("invalid brush") );
ad66316f
SC
157
158 return M_BRUSHDATA->GetStipple();
159}
160
161// ----------------------------------------------------------------------------
162// wxBrush setters
163// ----------------------------------------------------------------------------
164
165void wxBrush::SetColour(const wxColour& col)
166{
167 AllocExclusive();
168
169 M_BRUSHDATA->SetColour(col);
170}
171
172void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
173{
174 AllocExclusive();
175
176 M_BRUSHDATA->SetColour(wxColour(r, g, b));
177}
178
179void wxBrush::SetStyle(wxBrushStyle style)
180{
181 AllocExclusive();
182
183 M_BRUSHDATA->SetStyle(style);
184}
185
186void wxBrush::SetStipple(const wxBitmap& stipple)
187{
188 AllocExclusive();
189
190 M_BRUSHDATA->SetStipple(stipple);
191}