]> git.saurik.com Git - wxWidgets.git/blob - src/osx/brush.cpp
Set missing Language: headers in PO files.
[wxWidgets.git] / src / osx / brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/brush.cpp
3 // Purpose: wxBrush
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
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
21 IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
22
23 class WXDLLEXPORT wxBrushRefData: public wxGDIRefData
24 {
25 public:
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
41 protected:
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
51 wxBrushRefData::wxBrushRefData(const wxColour& colour, wxBrushStyle style)
52 : m_colour(colour), m_style( style )
53 {
54 }
55
56 wxBrushRefData::wxBrushRefData(const wxBitmap& stipple)
57 {
58 DoSetStipple( stipple );
59 }
60
61 wxBrushRefData::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
69 wxBrushRefData::~wxBrushRefData()
70 {
71 }
72
73 bool 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
80 void 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
89 wxBrush::wxBrush()
90 {
91 }
92
93 wxBrush::~wxBrush()
94 {
95 }
96
97 wxBrush::wxBrush(const wxColour& col, wxBrushStyle style)
98 {
99 m_refData = new wxBrushRefData( col, style );
100 }
101
102 #if FUTURE_WXWIN_COMPATIBILITY_3_0
103 wxBrush::wxBrush(const wxColour& col, int style)
104 {
105 m_refData = new wxBrushRefData(col, (wxBrushStyle)style);
106 }
107 #endif
108
109 wxBrush::wxBrush(const wxBitmap& stipple)
110 {
111 m_refData = new wxBrushRefData( stipple );
112 }
113
114 // ----------------------------------------------------------------------------
115 // wxBrush house keeping stuff
116 // ----------------------------------------------------------------------------
117
118 bool 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
126 wxGDIRefData *wxBrush::CreateGDIRefData() const
127 {
128 return new wxBrushRefData;
129 }
130
131 wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const
132 {
133 return new wxBrushRefData(*(const wxBrushRefData *)data);
134 }
135
136 // ----------------------------------------------------------------------------
137 // wxBrush accessors
138 // ----------------------------------------------------------------------------
139
140 wxColour wxBrush::GetColour() const
141 {
142 wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid brush") );
143
144 return M_BRUSHDATA->GetColour();
145 }
146
147 wxBrushStyle wxBrush::GetStyle() const
148 {
149 wxCHECK_MSG( IsOk(), wxBRUSHSTYLE_INVALID, wxT("invalid brush") );
150
151 return M_BRUSHDATA->GetStyle();
152 }
153
154 wxBitmap *wxBrush::GetStipple() const
155 {
156 wxCHECK_MSG( IsOk(), NULL, wxT("invalid brush") );
157
158 return M_BRUSHDATA->GetStipple();
159 }
160
161 // ----------------------------------------------------------------------------
162 // wxBrush setters
163 // ----------------------------------------------------------------------------
164
165 void wxBrush::SetColour(const wxColour& col)
166 {
167 AllocExclusive();
168
169 M_BRUSHDATA->SetColour(col);
170 }
171
172 void 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
179 void wxBrush::SetStyle(wxBrushStyle style)
180 {
181 AllocExclusive();
182
183 M_BRUSHDATA->SetStyle(style);
184 }
185
186 void wxBrush::SetStipple(const wxBitmap& stipple)
187 {
188 AllocExclusive();
189
190 M_BRUSHDATA->SetStipple(stipple);
191 }