]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/x11/pen.cpp
can't pass objects through ... (please don't ever ignore this gcc warning)
[wxWidgets.git] / src / x11 / pen.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/x11/pen.cpp
3// Purpose: wxPen
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// for compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#include "wx/utils.h"
16#include "wx/pen.h"
17#include "wx/colour.h"
18#include "wx/bitmap.h"
19
20//-----------------------------------------------------------------------------
21// wxPen
22//-----------------------------------------------------------------------------
23
24class wxPenRefData: public wxObjectRefData
25{
26public:
27 wxPenRefData()
28 {
29 m_width = 1;
30 m_style = wxSOLID;
31 m_joinStyle = wxJOIN_ROUND;
32 m_capStyle = wxCAP_ROUND;
33 m_dash = (wxX11Dash*) NULL;
34 m_countDashes = 0;
35 }
36
37 wxPenRefData( const wxPenRefData& data )
38 {
39 m_style = data.m_style;
40 m_width = data.m_width;
41 m_joinStyle = data.m_joinStyle;
42 m_capStyle = data.m_capStyle;
43 m_colour = data.m_colour;
44 m_countDashes = data.m_countDashes;
45/*
46 if (data.m_dash) TODO
47 m_dash = new
48*/
49 m_dash = data.m_dash;
50 m_stipple = data.m_stipple;
51 }
52
53 bool operator == (const wxPenRefData& data) const
54 {
55 return (m_style == data.m_style &&
56 m_width == data.m_width &&
57 m_joinStyle == data.m_joinStyle &&
58 m_capStyle == data.m_capStyle &&
59 m_colour == data.m_colour);
60 }
61
62 int m_width;
63 int m_style;
64 int m_joinStyle;
65 int m_capStyle;
66 wxColour m_colour;
67 int m_countDashes;
68 wxBitmap m_stipple;
69 wxX11Dash *m_dash;
70};
71
72//-----------------------------------------------------------------------------
73
74#define M_PENDATA ((wxPenRefData *)m_refData)
75
76IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
77
78wxPen::wxPen( const wxColour &colour, int width, int style )
79{
80 m_refData = new wxPenRefData();
81 M_PENDATA->m_width = width;
82 M_PENDATA->m_style = style;
83 M_PENDATA->m_colour = colour;
84}
85
86wxPen::~wxPen()
87{
88 // m_refData unrefed in ~wxObject
89}
90
91wxObjectRefData *wxPen::CreateRefData() const
92{
93 return new wxPenRefData;
94}
95
96wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
97{
98 return new wxPenRefData(*(wxPenRefData *)data);
99}
100
101bool wxPen::operator == ( const wxPen& pen ) const
102{
103 if (m_refData == pen.m_refData) return true;
104
105 if (!m_refData || !pen.m_refData) return false;
106
107 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
108}
109
110void wxPen::SetColour( const wxColour &colour )
111{
112 AllocExclusive();
113
114 M_PENDATA->m_colour = colour;
115}
116
117void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
118{
119 AllocExclusive();
120
121 M_PENDATA->m_countDashes = number_of_dashes;
122 M_PENDATA->m_dash = (wxX11Dash *)dash; // TODO
123}
124
125void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue )
126{
127 AllocExclusive();
128
129 M_PENDATA->m_colour.Set( red, green, blue );
130}
131
132void wxPen::SetCap( int capStyle )
133{
134 AllocExclusive();
135
136 M_PENDATA->m_capStyle = capStyle;
137}
138
139void wxPen::SetJoin( int joinStyle )
140{
141 AllocExclusive();
142
143 M_PENDATA->m_joinStyle = joinStyle;
144}
145
146void wxPen::SetStipple( wxBitmap *stipple )
147{
148 AllocExclusive();
149
150 M_PENDATA->m_stipple = *stipple;
151}
152
153void wxPen::SetStyle( int style )
154{
155 AllocExclusive();
156
157 M_PENDATA->m_style = style;
158}
159
160void wxPen::SetWidth( int width )
161{
162 AllocExclusive();
163
164 M_PENDATA->m_width = width;
165}
166
167int wxPen::GetDashes( wxDash **ptr ) const
168{
169 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
170 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
171}
172
173int wxPen::GetDashCount() const
174{
175 return (M_PENDATA->m_countDashes);
176}
177
178wxDash* wxPen::GetDash() const
179{
180 return (wxDash*)M_PENDATA->m_dash;
181}
182
183int wxPen::GetCap() const
184{
185 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
186
187 return M_PENDATA->m_capStyle;
188}
189
190int wxPen::GetJoin() const
191{
192 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
193
194 return M_PENDATA->m_joinStyle;
195}
196
197int wxPen::GetStyle() const
198{
199 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
200
201 return M_PENDATA->m_style;
202}
203
204int wxPen::GetWidth() const
205{
206 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
207
208 return M_PENDATA->m_width;
209}
210
211wxColour &wxPen::GetColour() const
212{
213 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
214
215 return M_PENDATA->m_colour;
216}
217
218wxBitmap *wxPen::GetStipple() const
219{
220 wxCHECK_MSG( Ok(), &wxNullBitmap, wxT("invalid pen") );
221
222 return &M_PENDATA->m_stipple;
223}