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