]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/pen.cpp
fix for a fatal bug in wxMGL's wxDir
[wxWidgets.git] / src / gtk1 / pen.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: pen.cpp
3// Purpose:
4// Author: Robert Roebling
a81258be
RR
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
8bbe427f 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifdef __GNUG__
12#pragma implementation "pen.h"
13#endif
14
15#include "wx/pen.h"
16
5e7e9e1b 17#include <gdk/gdk.h>
83624f79 18
c801d85f
KB
19//-----------------------------------------------------------------------------
20// wxPen
21//-----------------------------------------------------------------------------
22
23class wxPenRefData: public wxObjectRefData
24{
907789a0 25public:
8bbe427f 26
112c5086
RR
27 wxPenRefData();
28 wxPenRefData( const wxPenRefData& data );
8bbe427f 29
907789a0
RR
30 int m_width;
31 int m_style;
32 int m_joinStyle;
33 int m_capStyle;
34 wxColour m_colour;
112c5086 35 int m_countDashes;
2eca425d 36 wxGTKDash *m_dash;
c801d85f
KB
37};
38
907789a0 39wxPenRefData::wxPenRefData()
c801d85f 40{
907789a0
RR
41 m_width = 1;
42 m_style = wxSOLID;
43 m_joinStyle = wxJOIN_ROUND;
44 m_capStyle = wxCAP_ROUND;
2eca425d 45 m_dash = (wxGTKDash*) NULL;
112c5086 46 m_countDashes = 0;
ff7b1510 47}
c801d85f 48
e55ad60e
RR
49wxPenRefData::wxPenRefData( const wxPenRefData& data )
50{
907789a0
RR
51 m_style = data.m_style;
52 m_width = data.m_width;
53 m_joinStyle = data.m_joinStyle;
54 m_capStyle = data.m_capStyle;
55 m_colour = data.m_colour;
112c5086
RR
56 m_countDashes = data.m_countDashes;
57/*
58 if (data.m_dash) TODO
7ecb8b06 59 m_dash = new
112c5086
RR
60*/
61 m_dash = data.m_dash;
e55ad60e
RR
62}
63
c801d85f
KB
64//-----------------------------------------------------------------------------
65
66#define M_PENDATA ((wxPenRefData *)m_refData)
67
68IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
69
8bbe427f 70wxPen::wxPen()
c801d85f 71{
ff7b1510 72}
c801d85f
KB
73
74wxPen::wxPen( const wxColour &colour, int width, int style )
75{
907789a0
RR
76 m_refData = new wxPenRefData();
77 M_PENDATA->m_width = width;
78 M_PENDATA->m_style = style;
79 M_PENDATA->m_colour = colour;
ff7b1510 80}
c801d85f 81
c801d85f
KB
82wxPen::wxPen( const wxPen& pen )
83{
907789a0 84 Ref( pen );
ff7b1510 85}
c801d85f 86
907789a0 87wxPen::~wxPen()
c801d85f 88{
ff7b1510 89}
c801d85f
KB
90
91wxPen& wxPen::operator = ( const wxPen& pen )
92{
7ecb8b06
VZ
93 if ( m_refData != pen.m_refData )
94 Ref( pen );
95
8bbe427f 96 return *this;
ff7b1510 97}
c801d85f 98
f6bcfd97 99bool wxPen::operator == ( const wxPen& pen ) const
c801d85f 100{
8bbe427f 101 return m_refData == pen.m_refData;
ff7b1510 102}
c801d85f 103
f6bcfd97 104bool wxPen::operator != ( const wxPen& pen ) const
c801d85f 105{
8bbe427f 106 return m_refData != pen.m_refData;
ff7b1510 107}
c801d85f
KB
108
109void wxPen::SetColour( const wxColour &colour )
110{
907789a0
RR
111 Unshare();
112 M_PENDATA->m_colour = colour;
ff7b1510 113}
c801d85f 114
112c5086
RR
115void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
116{
117 Unshare();
118 M_PENDATA->m_countDashes = number_of_dashes;
2eca425d 119 M_PENDATA->m_dash = (wxGTKDash *)dash; /* TODO */
112c5086
RR
120}
121
debe6624 122void wxPen::SetColour( int red, int green, int blue )
c801d85f 123{
907789a0
RR
124 Unshare();
125 M_PENDATA->m_colour.Set( red, green, blue );
ff7b1510 126}
c801d85f
KB
127
128void wxPen::SetCap( int capStyle )
129{
907789a0
RR
130 Unshare();
131 M_PENDATA->m_capStyle = capStyle;
ff7b1510 132}
c801d85f
KB
133
134void wxPen::SetJoin( int joinStyle )
135{
907789a0
RR
136 Unshare();
137 M_PENDATA->m_joinStyle = joinStyle;
ff7b1510 138}
c801d85f
KB
139
140void wxPen::SetStyle( int style )
141{
907789a0
RR
142 Unshare();
143 M_PENDATA->m_style = style;
ff7b1510 144}
c801d85f
KB
145
146void wxPen::SetWidth( int width )
147{
907789a0
RR
148 Unshare();
149 M_PENDATA->m_width = width;
ff7b1510 150}
c801d85f 151
7ecb8b06 152int wxPen::GetDashes( wxDash **ptr ) const
112c5086 153{
7ecb8b06 154 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
112c5086
RR
155 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
156}
157
7ecb8b06
VZ
158int wxPen::GetDashCount() const
159{
160 return (M_PENDATA->m_countDashes);
112c5086
RR
161}
162
7ecb8b06
VZ
163wxDash* wxPen::GetDash() const
164{
165 return (wxDash*)M_PENDATA->m_dash;
112c5086
RR
166}
167
907789a0 168int wxPen::GetCap() const
c801d85f 169{
223d09f6 170 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
8bbe427f 171
907789a0 172 return M_PENDATA->m_capStyle;
ff7b1510 173}
c801d85f 174
907789a0 175int wxPen::GetJoin() const
c801d85f 176{
223d09f6 177 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
8bbe427f 178
907789a0 179 return M_PENDATA->m_joinStyle;
ff7b1510 180}
c801d85f 181
907789a0 182int wxPen::GetStyle() const
c801d85f 183{
223d09f6 184 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
8bbe427f 185
907789a0 186 return M_PENDATA->m_style;
ff7b1510 187}
c801d85f 188
907789a0 189int wxPen::GetWidth() const
c801d85f 190{
223d09f6 191 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
8bbe427f 192
907789a0 193 return M_PENDATA->m_width;
ff7b1510 194}
c801d85f 195
907789a0 196wxColour &wxPen::GetColour() const
c801d85f 197{
223d09f6 198 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
8bbe427f 199
907789a0 200 return M_PENDATA->m_colour;
ff7b1510 201}
c801d85f 202
907789a0 203bool wxPen::Ok() const
c801d85f 204{
907789a0 205 return (m_refData != NULL);
e55ad60e
RR
206}
207
907789a0 208void wxPen::Unshare()
e55ad60e 209{
907789a0
RR
210 if (!m_refData)
211 {
212 m_refData = new wxPenRefData();
213 }
214 else
215 {
216 wxPenRefData* ref = new wxPenRefData( *(wxPenRefData*)m_refData );
217 UnRef();
218 m_refData = ref;
219 }
ff7b1510 220}
c801d85f 221