]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/pen.cpp
Add support for the Windows Testdrive machines, and other improvments.
[wxWidgets.git] / src / mac / carbon / pen.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/mac/carbon/pen.cpp
3// Purpose: wxPen
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/pen.h"
15
16#ifndef WX_PRECOMP
17 #include "wx/utils.h"
18#endif
19
20IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
21
22class WXDLLEXPORT wxPenRefData: public wxGDIRefData
23{
24 friend class WXDLLIMPEXP_FWD_CORE wxPen;
25public:
26 wxPenRefData();
27 wxPenRefData(const wxPenRefData& data);
28 virtual ~wxPenRefData();
29
30 wxPenRefData& operator=(const wxPenRefData& data);
31
32 bool operator==(const wxPenRefData& data) const
33 {
34 // we intentionally don't compare m_hPen fields here
35 return m_style == data.m_style &&
36 m_width == data.m_width &&
37 m_join == data.m_join &&
38 m_cap == data.m_cap &&
39 m_colour == data.m_colour &&
40 (m_style != wxSTIPPLE || m_stipple.IsSameAs(data.m_stipple)) &&
41 (m_style != wxUSER_DASH ||
42 (m_nbDash == data.m_nbDash &&
43 memcmp(m_dash, data.m_dash, m_nbDash*sizeof(wxDash)) == 0));
44 }
45
46protected:
47 int m_width;
48 int m_style;
49 int m_join ;
50 int m_cap ;
51 wxBitmap m_stipple ;
52 int m_nbDash ;
53 wxDash * m_dash ;
54 wxColour m_colour;
55/* TODO: implementation
56 WXHPEN m_hPen;
57*/
58};
59
60wxPenRefData::wxPenRefData()
61{
62 m_style = wxSOLID;
63 m_width = 1;
64 m_join = wxJOIN_ROUND ;
65 m_cap = wxCAP_ROUND ;
66 m_nbDash = 0 ;
67 m_dash = 0 ;
68}
69
70wxPenRefData::wxPenRefData(const wxPenRefData& data)
71: wxGDIRefData()
72{
73 m_style = data.m_style;
74 m_width = data.m_width;
75 m_join = data.m_join;
76 m_cap = data.m_cap;
77 m_nbDash = data.m_nbDash;
78 m_dash = data.m_dash;
79 m_colour = data.m_colour;
80}
81
82wxPenRefData::~wxPenRefData()
83{
84}
85
86// Pens
87
88#define M_PENDATA ((wxPenRefData *)m_refData)
89
90wxPen::wxPen()
91{
92}
93
94wxPen::~wxPen()
95{
96}
97
98// Should implement Create
99wxPen::wxPen(const wxColour& col, int Width, int Style)
100{
101 m_refData = new wxPenRefData;
102
103 M_PENDATA->m_colour = col;
104 M_PENDATA->m_width = Width;
105 M_PENDATA->m_style = Style;
106 M_PENDATA->m_join = wxJOIN_ROUND ;
107 M_PENDATA->m_cap = wxCAP_ROUND ;
108 M_PENDATA->m_nbDash = 0 ;
109 M_PENDATA->m_dash = 0 ;
110
111 RealizeResource();
112}
113
114wxPen::wxPen(const wxBitmap& stipple, int Width)
115{
116 m_refData = new wxPenRefData;
117
118 M_PENDATA->m_stipple = stipple;
119 M_PENDATA->m_width = Width;
120 M_PENDATA->m_style = wxSTIPPLE;
121 M_PENDATA->m_join = wxJOIN_ROUND ;
122 M_PENDATA->m_cap = wxCAP_ROUND ;
123 M_PENDATA->m_nbDash = 0 ;
124 M_PENDATA->m_dash = 0 ;
125
126 RealizeResource();
127}
128
129bool wxPen::operator == (const wxPen& pen) const
130{
131 const wxPenRefData *penData = (wxPenRefData *)pen.m_refData;
132
133 // an invalid pen is only equal to another invalid pen
134 return m_refData ? penData && *M_PENDATA == *penData : !penData;
135}
136
137wxColour& wxPen::GetColour() const
138{
139 return (M_PENDATA ? M_PENDATA->m_colour : wxNullColour);
140}
141
142int wxPen::GetWidth() const
143{
144 return (M_PENDATA ? M_PENDATA->m_width : 0);
145}
146
147int wxPen::GetStyle() const
148{
149 return (M_PENDATA ? M_PENDATA->m_style : 0);
150}
151
152int wxPen::GetJoin() const
153{
154 return (M_PENDATA ? M_PENDATA->m_join : 0);
155}
156
157int wxPen::GetCap() const
158{
159 return (M_PENDATA ? M_PENDATA->m_cap : 0);
160}
161
162int wxPen::GetDashes(wxDash **ptr) const
163{
164 *ptr = (M_PENDATA ? M_PENDATA->m_dash : (wxDash*) NULL); return (M_PENDATA ? M_PENDATA->m_nbDash : 0);
165}
166
167wxBitmap *wxPen::GetStipple() const
168{
169 return (M_PENDATA ? (& M_PENDATA->m_stipple) : (wxBitmap*) NULL);
170}
171
172void wxPen::Unshare()
173{
174 // Don't change shared data
175 if (!m_refData)
176 {
177 m_refData = new wxPenRefData();
178 }
179 else
180 {
181 wxPenRefData* ref = new wxPenRefData(*(wxPenRefData*)m_refData);
182 UnRef();
183 m_refData = ref;
184 }
185}
186
187void wxPen::SetColour(const wxColour& col)
188{
189 Unshare();
190
191 M_PENDATA->m_colour = col;
192
193 RealizeResource();
194}
195
196void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b)
197{
198 Unshare();
199
200 M_PENDATA->m_colour.Set(r, g, b);
201
202 RealizeResource();
203}
204
205void wxPen::SetWidth(int Width)
206{
207 Unshare();
208
209 M_PENDATA->m_width = Width;
210
211 RealizeResource();
212}
213
214void wxPen::SetStyle(int Style)
215{
216 Unshare();
217
218 M_PENDATA->m_style = Style;
219
220 RealizeResource();
221}
222
223void wxPen::SetStipple(const wxBitmap& Stipple)
224{
225 Unshare();
226
227 M_PENDATA->m_stipple = Stipple;
228 M_PENDATA->m_style = wxSTIPPLE;
229
230 RealizeResource();
231}
232
233void wxPen::SetDashes(int nb_dashes, const wxDash *Dash)
234{
235 Unshare();
236
237 M_PENDATA->m_nbDash = nb_dashes;
238 M_PENDATA->m_dash = (wxDash *)Dash;
239
240 RealizeResource();
241}
242
243void wxPen::SetJoin(int Join)
244{
245 Unshare();
246
247 M_PENDATA->m_join = Join;
248
249 RealizeResource();
250}
251
252void wxPen::SetCap(int Cap)
253{
254 Unshare();
255
256 M_PENDATA->m_cap = Cap;
257
258 RealizeResource();
259}
260
261bool wxPen::RealizeResource()
262{
263 // nothing to do here for mac
264 return true;
265}