]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/pen.cpp
Add support for the Windows Testdrive machines, and other improvments.
[wxWidgets.git] / src / mac / carbon / pen.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
46562151 2// Name: src/mac/carbon/pen.cpp
e9576ca5 3// Purpose: wxPen
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
3d1a4878
SC
12#include "wx/wxprec.h"
13
e9576ca5
SC
14#include "wx/pen.h"
15
de6185e2
WS
16#ifndef WX_PRECOMP
17 #include "wx/utils.h"
18#endif
19
e9576ca5 20IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
e9576ca5 21
46623e91
SC
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
e9576ca5
SC
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 ;
2f1ae414 67 m_dash = 0 ;
e9576ca5
SC
68}
69
70wxPenRefData::wxPenRefData(const wxPenRefData& data)
e40298d5 71: wxGDIRefData()
e9576ca5
SC
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;
e9576ca5
SC
80}
81
82wxPenRefData::~wxPenRefData()
83{
e9576ca5
SC
84}
85
86// Pens
87
46623e91
SC
88#define M_PENDATA ((wxPenRefData *)m_refData)
89
e9576ca5
SC
90wxPen::wxPen()
91{
e9576ca5
SC
92}
93
94wxPen::~wxPen()
95{
e9576ca5
SC
96}
97
98// Should implement Create
99wxPen::wxPen(const wxColour& col, int Width, int Style)
100{
101 m_refData = new wxPenRefData;
46562151 102
e9576ca5
SC
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 ;
2f1ae414 109 M_PENDATA->m_dash = 0 ;
46562151 110
e9576ca5 111 RealizeResource();
e9576ca5
SC
112}
113
114wxPen::wxPen(const wxBitmap& stipple, int Width)
115{
116 m_refData = new wxPenRefData;
46562151 117
e9576ca5
SC
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 ;
2f1ae414 124 M_PENDATA->m_dash = 0 ;
46562151 125
e9576ca5 126 RealizeResource();
e9576ca5
SC
127}
128
46623e91
SC
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
83dcd781 172void wxPen::Unshare()
e9576ca5 173{
83dcd781
PC
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 }
e9576ca5
SC
185}
186
187void wxPen::SetColour(const wxColour& col)
188{
83dcd781 189 Unshare();
46562151 190
e9576ca5 191 M_PENDATA->m_colour = col;
46562151 192
e9576ca5
SC
193 RealizeResource();
194}
195
1a1498c0 196void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b)
e9576ca5 197{
83dcd781 198 Unshare();
46562151 199
e9576ca5 200 M_PENDATA->m_colour.Set(r, g, b);
46562151 201
e9576ca5
SC
202 RealizeResource();
203}
204
205void wxPen::SetWidth(int Width)
206{
83dcd781 207 Unshare();
46562151 208
e9576ca5 209 M_PENDATA->m_width = Width;
46562151 210
e9576ca5
SC
211 RealizeResource();
212}
213
214void wxPen::SetStyle(int Style)
215{
83dcd781 216 Unshare();
46562151 217
e9576ca5 218 M_PENDATA->m_style = Style;
46562151 219
e9576ca5
SC
220 RealizeResource();
221}
222
223void wxPen::SetStipple(const wxBitmap& Stipple)
224{
83dcd781 225 Unshare();
46562151 226
e9576ca5
SC
227 M_PENDATA->m_stipple = Stipple;
228 M_PENDATA->m_style = wxSTIPPLE;
46562151 229
e9576ca5
SC
230 RealizeResource();
231}
232
233void wxPen::SetDashes(int nb_dashes, const wxDash *Dash)
234{
83dcd781 235 Unshare();
46562151 236
e9576ca5 237 M_PENDATA->m_nbDash = nb_dashes;
2f1ae414 238 M_PENDATA->m_dash = (wxDash *)Dash;
46562151 239
e9576ca5
SC
240 RealizeResource();
241}
242
243void wxPen::SetJoin(int Join)
244{
83dcd781 245 Unshare();
46562151 246
e9576ca5 247 M_PENDATA->m_join = Join;
46562151 248
e9576ca5
SC
249 RealizeResource();
250}
251
252void wxPen::SetCap(int Cap)
253{
83dcd781 254 Unshare();
46562151 255
e9576ca5 256 M_PENDATA->m_cap = Cap;
46562151 257
e9576ca5
SC
258 RealizeResource();
259}
260
261bool wxPen::RealizeResource()
262{
e40298d5 263 // nothing to do here for mac
46562151 264 return true;
e9576ca5 265}