]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/brush.cpp
Corrected wxRTTI for wxNotebook so dynamic casting to wxBookCtrlBase works
[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:
a01d9a25
SC
27 wxBrushRefData(const wxColour& colour = wxNullColour, int style = wxSOLID);
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
SC
34 const wxColour& GetColour() const { return m_colour; }
35 int GetStyle() const { return m_style; }
36 wxBitmap *GetStipple() { return &m_stipple; }
37
38 void SetColour(const wxColour& colour) { m_colour = colour; }
39 void SetStyle(int style) { m_style = style; }
40 void SetStipple(const wxBitmap& stipple) { DoSetStipple(stipple); }
41
76a5e5d2 42protected:
a01d9a25
SC
43 void DoSetStipple(const wxBitmap& stipple);
44
76a5e5d2
SC
45 wxBitmap m_stipple ;
46 wxColour m_colour;
a01d9a25 47 int m_style;
76a5e5d2
SC
48};
49
50#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
51
a01d9a25
SC
52wxBrushRefData::wxBrushRefData(const wxColour& colour, int style)
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
SC
83 m_stipple = stipple;
84 m_style = stipple.GetMask() ? wxSTIPPLE_MASK_OPAQUE : wxSTIPPLE;
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
a01d9a25 98wxBrush::wxBrush(const wxColour& col, int style)
e9576ca5 99{
a01d9a25 100 m_refData = new wxBrushRefData( col, style );
e9576ca5
SC
101}
102
a01d9a25 103wxBrush::wxBrush(const wxBitmap& stipple)
e9576ca5 104{
a01d9a25 105 m_refData = new wxBrushRefData( stipple );
e9576ca5
SC
106}
107
a01d9a25
SC
108// ----------------------------------------------------------------------------
109// wxBrush house keeping stuff
110// ----------------------------------------------------------------------------
e9576ca5 111
a01d9a25 112bool wxBrush::operator==(const wxBrush& brush) const
e9576ca5 113{
a01d9a25
SC
114 const wxBrushRefData *brushData = (wxBrushRefData *)brush.m_refData;
115
116 // an invalid brush is considered to be only equal to another invalid brush
117 return m_refData ? (brushData && *M_BRUSHDATA == *brushData) : !brushData;
e9576ca5
SC
118}
119
8f884a0d 120wxGDIRefData *wxBrush::CreateGDIRefData() const
e9576ca5 121{
a01d9a25 122 return new wxBrushRefData;
e9576ca5
SC
123}
124
8f884a0d 125wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const
1dcbbdcf 126{
a01d9a25 127 return new wxBrushRefData(*(const wxBrushRefData *)data);
1dcbbdcf
SC
128}
129
a01d9a25
SC
130// ----------------------------------------------------------------------------
131// wxBrush accessors
132// ----------------------------------------------------------------------------
1dcbbdcf 133
a01d9a25 134const wxColour& wxBrush::GetColour() const
e9576ca5 135{
a01d9a25
SC
136 wxCHECK_MSG( Ok(), wxNullColour, _T("invalid brush") );
137
138 return M_BRUSHDATA->GetColour();
e9576ca5 139}
78606adf 140
a01d9a25 141int wxBrush::GetStyle() const
7d9d1fd7 142{
a01d9a25
SC
143 wxCHECK_MSG( Ok(), 0, _T("invalid brush") );
144
145 return M_BRUSHDATA->GetStyle();
7d9d1fd7
SC
146}
147
a01d9a25 148wxBitmap *wxBrush::GetStipple() const
46562151 149{
a01d9a25
SC
150 wxCHECK_MSG( Ok(), NULL, _T("invalid brush") );
151
152 return M_BRUSHDATA->GetStipple();
e40298d5 153}
76a5e5d2 154
a01d9a25
SC
155// ----------------------------------------------------------------------------
156// wxBrush setters
157// ----------------------------------------------------------------------------
76a5e5d2 158
a01d9a25 159void wxBrush::SetColour(const wxColour& col)
46562151 160{
a01d9a25
SC
161 AllocExclusive();
162
163 M_BRUSHDATA->SetColour(col);
e40298d5 164}
76a5e5d2 165
a01d9a25 166void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
46562151 167{
a01d9a25
SC
168 AllocExclusive();
169
170 M_BRUSHDATA->SetColour(wxColour(r, g, b));
e40298d5 171}
76a5e5d2 172
a01d9a25 173void wxBrush::SetStyle(int style)
46562151 174{
a01d9a25
SC
175 AllocExclusive();
176
177 M_BRUSHDATA->SetStyle(style);
a8e9860d 178}
55ccdb93 179
a01d9a25 180void wxBrush::SetStipple(const wxBitmap& stipple)
55ccdb93 181{
a01d9a25
SC
182 AllocExclusive();
183
184 M_BRUSHDATA->SetStipple(stipple);
55ccdb93 185}