]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/pen.cpp
Compile fix for filefn.cpp
[wxWidgets.git] / src / gtk / 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
17//-----------------------------------------------------------------------------
18// wxPen
19//-----------------------------------------------------------------------------
20
21class wxPenRefData: public wxObjectRefData
22{
907789a0 23public:
8bbe427f 24
907789a0
RR
25 wxPenRefData(void);
26 wxPenRefData(const wxPenRefData& data);
8bbe427f 27
907789a0
RR
28 int m_width;
29 int m_style;
30 int m_joinStyle;
31 int m_capStyle;
32 wxColour m_colour;
c801d85f
KB
33};
34
907789a0 35wxPenRefData::wxPenRefData()
c801d85f 36{
907789a0
RR
37 m_width = 1;
38 m_style = wxSOLID;
39 m_joinStyle = wxJOIN_ROUND;
40 m_capStyle = wxCAP_ROUND;
ff7b1510 41}
c801d85f 42
e55ad60e
RR
43wxPenRefData::wxPenRefData( const wxPenRefData& data )
44{
907789a0
RR
45 m_style = data.m_style;
46 m_width = data.m_width;
47 m_joinStyle = data.m_joinStyle;
48 m_capStyle = data.m_capStyle;
49 m_colour = data.m_colour;
e55ad60e
RR
50}
51
c801d85f
KB
52//-----------------------------------------------------------------------------
53
54#define M_PENDATA ((wxPenRefData *)m_refData)
55
56IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
57
8bbe427f 58wxPen::wxPen()
c801d85f 59{
907789a0 60 if (wxThePenList) wxThePenList->AddPen( this );
ff7b1510 61}
c801d85f
KB
62
63wxPen::wxPen( const wxColour &colour, int width, int style )
64{
907789a0
RR
65 m_refData = new wxPenRefData();
66 M_PENDATA->m_width = width;
67 M_PENDATA->m_style = style;
68 M_PENDATA->m_colour = colour;
8bbe427f 69
907789a0 70 if (wxThePenList) wxThePenList->AddPen( this );
ff7b1510 71}
c801d85f 72
c801d85f
KB
73wxPen::wxPen( const wxPen& pen )
74{
907789a0
RR
75 Ref( pen );
76 if (wxThePenList) wxThePenList->AddPen( this );
ff7b1510 77}
c801d85f 78
907789a0 79wxPen::~wxPen()
c801d85f 80{
907789a0 81 if (wxThePenList) wxThePenList->RemovePen( this );
ff7b1510 82}
c801d85f
KB
83
84wxPen& wxPen::operator = ( const wxPen& pen )
85{
8bbe427f
VZ
86 if (*this == pen) return (*this);
87 Ref( pen );
88 return *this;
ff7b1510 89}
c801d85f
KB
90
91bool wxPen::operator == ( const wxPen& pen )
92{
8bbe427f 93 return m_refData == pen.m_refData;
ff7b1510 94}
c801d85f
KB
95
96bool wxPen::operator != ( const wxPen& pen )
97{
8bbe427f 98 return m_refData != pen.m_refData;
ff7b1510 99}
c801d85f
KB
100
101void wxPen::SetColour( const wxColour &colour )
102{
907789a0
RR
103 Unshare();
104 M_PENDATA->m_colour = colour;
ff7b1510 105}
c801d85f 106
debe6624 107void wxPen::SetColour( int red, int green, int blue )
c801d85f 108{
907789a0
RR
109 Unshare();
110 M_PENDATA->m_colour.Set( red, green, blue );
ff7b1510 111}
c801d85f
KB
112
113void wxPen::SetCap( int capStyle )
114{
907789a0
RR
115 Unshare();
116 M_PENDATA->m_capStyle = capStyle;
ff7b1510 117}
c801d85f
KB
118
119void wxPen::SetJoin( int joinStyle )
120{
907789a0
RR
121 Unshare();
122 M_PENDATA->m_joinStyle = joinStyle;
ff7b1510 123}
c801d85f
KB
124
125void wxPen::SetStyle( int style )
126{
907789a0
RR
127 Unshare();
128 M_PENDATA->m_style = style;
ff7b1510 129}
c801d85f
KB
130
131void wxPen::SetWidth( int width )
132{
907789a0
RR
133 Unshare();
134 M_PENDATA->m_width = width;
ff7b1510 135}
c801d85f 136
907789a0 137int wxPen::GetCap() const
c801d85f 138{
907789a0 139 wxCHECK_MSG( Ok(), -1, "invalid pen" );
8bbe427f 140
907789a0 141 return M_PENDATA->m_capStyle;
ff7b1510 142}
c801d85f 143
907789a0 144int wxPen::GetJoin() const
c801d85f 145{
907789a0 146 wxCHECK_MSG( Ok(), -1, "invalid pen" );
8bbe427f 147
907789a0 148 return M_PENDATA->m_joinStyle;
ff7b1510 149}
c801d85f 150
907789a0 151int wxPen::GetStyle() const
c801d85f 152{
907789a0 153 wxCHECK_MSG( Ok(), -1, "invalid pen" );
8bbe427f 154
907789a0 155 return M_PENDATA->m_style;
ff7b1510 156}
c801d85f 157
907789a0 158int wxPen::GetWidth() const
c801d85f 159{
907789a0 160 wxCHECK_MSG( Ok(), -1, "invalid pen" );
8bbe427f 161
907789a0 162 return M_PENDATA->m_width;
ff7b1510 163}
c801d85f 164
907789a0 165wxColour &wxPen::GetColour() const
c801d85f 166{
907789a0 167 wxCHECK_MSG( Ok(), wxNullColour, "invalid pen" );
8bbe427f 168
907789a0 169 return M_PENDATA->m_colour;
ff7b1510 170}
c801d85f 171
907789a0 172bool wxPen::Ok() const
c801d85f 173{
907789a0 174 return (m_refData != NULL);
e55ad60e
RR
175}
176
907789a0 177void wxPen::Unshare()
e55ad60e 178{
907789a0
RR
179 if (!m_refData)
180 {
181 m_refData = new wxPenRefData();
182 }
183 else
184 {
185 wxPenRefData* ref = new wxPenRefData( *(wxPenRefData*)m_refData );
186 UnRef();
187 m_refData = ref;
188 }
ff7b1510 189}
c801d85f 190