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