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